|
a/tool/src/spdxlib/FileInfo.java |
|
b/tool/src/spdxlib/FileInfo.java |
|
... |
|
... |
68 |
}
|
68 |
}
|
69 |
|
69 |
|
70 |
/**
|
70 |
/**
|
71 |
* Each file can have one or more license applicable.
|
71 |
* Each file can have one or more license applicable.
|
72 |
* This method adds them up as needed.
|
72 |
* This method adds them up as needed.
|
|
|
73 |
* @param tag
|
73 |
*/
|
74 |
*/
|
74 |
public void addLicense(TagValue tag){
|
75 |
public void addLicense(TagValue tag){
|
75 |
licenseInfoInFile.add(tag);
|
76 |
licenseInfoInFile.add(tag);
|
76 |
}
|
77 |
}
|
77 |
|
78 |
|
78 |
@Override
|
79 |
@Override
|
79 |
public String toString(){
|
80 |
public String toString(){
|
|
|
81 |
String fileName = getName();
|
|
|
82 |
|
|
|
83 |
String licenseText = getLicense();
|
|
|
84 |
|
|
|
85 |
if(licenseText.isEmpty() == false){
|
|
|
86 |
fileName += " (" + licenseText + ")";
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
// output the final result
|
|
|
90 |
return fileName;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
/**
|
|
|
94 |
* Returns the file name without unwanted chars
|
|
|
95 |
* @return the file name of this object
|
|
|
96 |
*/
|
|
|
97 |
public String getName(){
|
|
|
98 |
// get the name in un-processed state (still with slashes)
|
|
|
99 |
String fileName = tagFileName.toString();
|
|
|
100 |
// remove slashes from the file name
|
|
|
101 |
if(fileName.contains("/")){
|
|
|
102 |
return fileName.substring(fileName.lastIndexOf("/")+1);
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
// all done
|
|
|
106 |
return fileName;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
/**
|
|
|
112 |
* This method will pick on a given FileInfo object and extract the relevant
|
|
|
113 |
* licensing details.
|
|
|
114 |
* @return A string text with a list of licenses when available. If no
|
|
|
115 |
* license was found, it will return null
|
|
|
116 |
*/
|
|
|
117 |
public String getLicense(){
|
|
|
118 |
// where we store the results from this analysis
|
80 |
String licenseOutput = "";
|
119 |
String licenseOutput = "";
|
|
|
120 |
|
81 |
// priority is the case where a human concludes a license
|
121 |
// priority is the case where a human concludes a license
|
82 |
if((this.tagLicenseConcluded != null)
|
122 |
if((this.tagLicenseConcluded != null)
|
83 |
&&(tagLicenseConcluded.toString().equals("NOASSERTION")!=true)){
|
123 |
&&(tagLicenseConcluded.toString().equals("NOASSERTION")!=true)){
|
84 |
// no need to proceed
|
124 |
// no need to proceed
|
85 |
return tagFileName.toString()
|
125 |
return tagLicenseConcluded.toString();
|
86 |
+ " ("+ tagLicenseConcluded.toString() +")";
|
|
|
87 |
}
|
|
|
88 |
|
126 |
}
|
|
|
127 |
|
|
|
128 |
|
89 |
// second priority are licenses detected inside the code
|
129 |
// second priority are licenses detected inside the code
|
90 |
if(licenseInfoInFile.size()>0){
|
130 |
if(licenseInfoInFile.size()>0){
|
91 |
|
131 |
// we need to count the valid licenses
|
|
|
132 |
int counterLicense = 0;
|
|
|
133 |
// go through all licenses listed
|
92 |
for(TagValue tag : licenseInfoInFile){
|
134 |
for(TagValue tag : licenseInfoInFile){
|
|
|
135 |
// should this license be ignored?
|
|
|
136 |
if(tag.toString().equalsIgnoreCase("none")){
|
|
|
137 |
continue;
|
|
|
138 |
}
|
|
|
139 |
// valid license, increase the counter
|
|
|
140 |
counterLicense++;
|
|
|
141 |
// add the license to the printable text viewed by user
|
93 |
licenseOutput = licenseOutput.concat(", " + tag.toString());
|
142 |
licenseOutput = licenseOutput.concat(", " + tag.toString());
|
94 |
}
|
143 |
}
|
|
|
144 |
// don't display text if no license was accounted
|
|
|
145 |
if(counterLicense == 0){
|
|
|
146 |
licenseOutput = "";
|
|
|
147 |
}else{
|
95 |
// remove the first comma added throught our loop
|
148 |
// remove the first comma added throught our loop
|
|
|
149 |
licenseOutput = licenseOutput.substring(2);
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
return licenseOutput;
|
|
|
153 |
}
|
|
|
154 |
// String licenseOutput = "";
|
|
|
155 |
// // priority is the case where a human concludes a license
|
|
|
156 |
// if((tagLicenseConcluded != null)
|
|
|
157 |
// &&(tagLicenseConcluded.toString().equals("NOASSERTION")!=true)){
|
|
|
158 |
// // no need to proceed
|
|
|
159 |
// return
|
|
|
160 |
// //file.tagFileName.toString()
|
|
|
161 |
// //+ " ("+
|
|
|
162 |
// tagLicenseConcluded.toString()
|
|
|
163 |
// //+")"
|
|
|
164 |
// ;
|
|
|
165 |
// }
|
|
|
166 |
//
|
|
|
167 |
// // second priority are licenses detected inside the code
|
|
|
168 |
// if(licenseInfoInFile.size()>0){
|
|
|
169 |
//
|
|
|
170 |
// for(TagValue tag : licenseInfoInFile){
|
|
|
171 |
// licenseOutput = licenseOutput.concat(", " + tag.toString());
|
|
|
172 |
// }
|
|
|
173 |
// // remove the first comma added throught our loop
|
96 |
licenseOutput = " (" + licenseOutput.substring(2) + ")";
|
174 |
// licenseOutput = " (" + licenseOutput.substring(2) + ")";
|
|
|
175 |
// }
|
|
|
176 |
// return licenseOutput;
|
|
|
177 |
// }
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
/**
|
|
|
181 |
* When given a file, this method checks if it has either a reported or
|
|
|
182 |
* concluded license. The method is necessary since sometimes one of these
|
|
|
183 |
* fields is present using infomation like "NOASSERTION" which really
|
|
|
184 |
* becomes a problem to normalize.
|
|
|
185 |
* @param file A FileInfo object with the information that we will analyze
|
|
|
186 |
* @return
|
|
|
187 |
*/
|
|
|
188 |
public Boolean hasLicense(){
|
97 |
}
|
189 |
|
|
|
190 |
// do we have a license concluded for this file?
|
|
|
191 |
if(tagLicenseConcluded != null){
|
|
|
192 |
// get the text from the license that was concluded
|
|
|
193 |
String licenseText = tagLicenseConcluded.toString();
|
|
|
194 |
// a lot of trouble, but necessary to find out what is happening
|
|
|
195 |
if( (licenseText.equals("NONE")== false)
|
|
|
196 |
&& (licenseText.equals("NOASSERTION")== false)){
|
|
|
197 |
// we have at least one license concluded. Good enough
|
|
|
198 |
return true;
|
|
|
199 |
}
|
98 |
|
200 |
}
|
99 |
// output the final result
|
201 |
|
100 |
return tagFileName.toString() + licenseOutput;
|
202 |
// are there any licenses inside this file?
|
|
|
203 |
for(TagValue licenseTag : licenseInfoInFile){
|
|
|
204 |
String licenseText = licenseTag.toString();
|
|
|
205 |
// excluse the cases that shouldn't count for this metric
|
|
|
206 |
if(licenseText.equals("NONE")){
|
|
|
207 |
continue;
|
|
|
208 |
}
|
|
|
209 |
if(licenseText.equals("NOASSERTION")){
|
|
|
210 |
continue;
|
|
|
211 |
}
|
|
|
212 |
// we just need to find one license to make our day happy! :-)
|
|
|
213 |
return true;
|
101 |
}
|
214 |
}
|
|
|
215 |
// no licenses, let's leave
|
|
|
216 |
return false;
|
102 |
|
217 |
}
|
103 |
/**
|
|
|
104 |
* Returns the file name without unwanted chars
|
|
|
105 |
* @return the file name of this object
|
|
|
106 |
*/
|
|
|
107 |
public String getName(){
|
|
|
108 |
return tagFileName.toString();
|
|
|
109 |
}
|
218 |
|
110 |
|
219 |
|
111 |
}
|
220 |
}
|