|
a/tool/src/spdxlib/DocumentCreate.java |
|
b/tool/src/spdxlib/DocumentCreate.java |
|
... |
|
... |
10 |
* FileComment: <text> Creates an SPDX document from a given source </text>
|
10 |
* FileComment: <text> Creates an SPDX document from a given source </text>
|
11 |
*/
|
11 |
*/
|
12 |
|
12 |
|
13 |
package spdxlib;
|
13 |
package spdxlib;
|
14 |
|
14 |
|
|
|
15 |
import definitions.is;
|
15 |
import java.io.File;
|
16 |
import java.io.File;
|
16 |
import java.io.IOException;
|
17 |
import java.io.IOException;
|
17 |
import java.text.DateFormat;
|
18 |
import java.text.DateFormat;
|
18 |
import java.text.SimpleDateFormat;
|
19 |
import java.text.SimpleDateFormat;
|
19 |
import java.util.ArrayList;
|
20 |
import java.util.ArrayList;
|
20 |
import java.util.Date;
|
21 |
import java.util.Date;
|
21 |
import script.License;
|
22 |
import script.License;
|
22 |
import ssdeep.ssdeep;
|
23 |
import ssdeep.ssdeep;
|
23 |
import main.core;
|
24 |
import main.core;
|
|
|
25 |
import script.log;
|
24 |
|
26 |
|
25 |
|
27 |
|
26 |
/**
|
28 |
/**
|
27 |
*
|
29 |
*
|
28 |
* @author Nuno Brito, 1st of November 2013 in Darmstadt, Germany.
|
30 |
* @author Nuno Brito, 1st of November 2013 in Darmstadt, Germany.
|
|
... |
|
... |
47 |
UID
|
49 |
UID
|
48 |
;
|
50 |
;
|
49 |
|
51 |
|
50 |
boolean isOk = false;
|
52 |
boolean isOk = false;
|
51 |
|
53 |
|
|
|
54 |
public ArrayList<File> files;
|
52 |
|
55 |
|
53 |
public boolean isProcessing;
|
56 |
public boolean isProcessing;
|
54 |
public int
|
57 |
public int
|
55 |
filesToProcess = 0,
|
58 |
filesToProcess = 0,
|
56 |
filesProcessed = 0,
|
59 |
filesProcessed = 0,
|
|
... |
|
... |
80 |
System.err.println("ND01 - No folder defined as source for SPDX");
|
83 |
System.err.println("ND01 - No folder defined as source for SPDX");
|
81 |
isProcessing = false;
|
84 |
isProcessing = false;
|
82 |
return null;
|
85 |
return null;
|
83 |
}
|
86 |
}
|
84 |
// get the files from the target source code folder
|
87 |
// get the files from the target source code folder
|
85 |
ArrayList<File> files = utils.files.findFiles(folderSourceCode);
|
88 |
files = utils.files.findFiles(folderSourceCode);
|
86 |
// no need to continue if no files were found
|
89 |
// no need to continue if no files were found
|
87 |
if((files == null) || (files.isEmpty())){
|
90 |
if((files == null) || (files.isEmpty())){
|
88 |
System.err.println("ND02 - No files were found for creating SPDX");
|
91 |
System.err.println("ND02 - No files were found for creating SPDX");
|
89 |
isProcessing = false;
|
92 |
isProcessing = false;
|
90 |
return null;
|
93 |
return null;
|
|
... |
|
... |
100 |
filename = PackageName;
|
103 |
filename = PackageName;
|
101 |
}
|
104 |
}
|
102 |
|
105 |
|
103 |
String textDate = getDateSPDX();
|
106 |
String textDate = getDateSPDX();
|
104 |
|
107 |
|
105 |
// save this title as UID
|
|
|
106 |
UID = ">> " + filename + " >> Products ";
|
|
|
107 |
|
108 |
|
108 |
filename = filename + ".spdx";
|
109 |
filename = filename + ".spdx";
|
109 |
|
110 |
|
110 |
output =
|
111 |
output =
|
111 |
addParagraph("SPDX Document Information")
|
112 |
addParagraph("SPDX Document Information")
|
|
... |
|
... |
127 |
+ "\n"
|
128 |
+ "\n"
|
128 |
+ "\n"
|
129 |
+ "\n"
|
129 |
+ addParagraph("File Information")
|
130 |
+ addParagraph("File Information")
|
130 |
;
|
131 |
;
|
131 |
|
132 |
|
|
|
133 |
|
|
|
134 |
log.write(is.INFO, "Preparing to process %1 files", "" + files.size());
|
132 |
|
135 |
|
133 |
// iterate through each file
|
136 |
// iterate through each file
|
134 |
for(File thisFile : files){
|
137 |
for(File thisFile : files){
|
135 |
// compute our SSDEEP hashes
|
138 |
// compute our SSDEEP hashes
|
136 |
ssdeep test = new ssdeep();
|
139 |
ssdeep test = new ssdeep();
|
|
... |
|
... |
199 |
+ utils.Checksum.generateFileChecksum("SHA-256", thisFile))
|
202 |
+ utils.Checksum.generateFileChecksum("SHA-256", thisFile))
|
200 |
+ addText("FileChecksum: MD5: "
|
203 |
+ addText("FileChecksum: MD5: "
|
201 |
+ utils.Checksum.generateFileChecksum("MD5", thisFile))
|
204 |
+ utils.Checksum.generateFileChecksum("MD5", thisFile))
|
202 |
+ addText("FileChecksum: SSDEEP: " + ssdeep)
|
205 |
+ addText("FileChecksum: SSDEEP: " + ssdeep)
|
203 |
+ addText("FileSize: " + fileSize)
|
206 |
+ addText("FileSize: " + fileSize)
|
|
|
207 |
// + addText("FileModified: " + getFileDateSPDX(thisFile))
|
|
|
208 |
|
204 |
+ addText(LOC)
|
209 |
+ addText(LOC)
|
205 |
//+ addText("FileLastModified: " + fileModified)
|
210 |
//+ addText("FileLastModified: " + fileModified)
|
206 |
+ licenseInfoInFile
|
211 |
+ licenseInfoInFile
|
207 |
//+ "\nLicenseConcluded: NOASSERTION"
|
212 |
//+ "\nLicenseConcluded: NOASSERTION"
|
208 |
//+ "\nLicenseInfoInFile: NONE"
|
213 |
//+ "\nLicenseInfoInFile: NONE"
|
|
... |
|
... |
269 |
Date date = new Date();
|
274 |
Date date = new Date();
|
270 |
String textDate = dateFormat.format(date);
|
275 |
String textDate = dateFormat.format(date);
|
271 |
//TODO for some reason "T" and "Z" are not accepted as parameters
|
276 |
//TODO for some reason "T" and "Z" are not accepted as parameters
|
272 |
return textDate.replace(" ", "T") + "Z";
|
277 |
return textDate.replace(" ", "T") + "Z";
|
273 |
}
|
278 |
}
|
|
|
279 |
|
|
|
280 |
|
|
|
281 |
/**
|
|
|
282 |
* Get the current time and date in SPDX format from a file
|
|
|
283 |
* @param file the file from where we want the date
|
|
|
284 |
* @return the properly formatted SPDX time format
|
|
|
285 |
*/
|
|
|
286 |
public static String getFileDateSPDX(File file) {
|
|
|
287 |
// do the time calculation such as 2012-09-03T13:32:12Z
|
|
|
288 |
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
289 |
Date date = new Date(file.lastModified());
|
|
|
290 |
String textDate = dateFormat.format(date);
|
|
|
291 |
//TODO for some reason "T" and "Z" are not accepted as parameters
|
|
|
292 |
return textDate.replace(" ", "T") + "Z";
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
|
274 |
}
|
296 |
}
|