--- a/tool/run/plugins/spdx/show.java
+++ b/tool/run/plugins/spdx/show.java
@@ -84,13 +84,22 @@
// + "% in total)" + html.br;
+ String warnings = "";
+
+ // we don't like SPDX documents without declared licenses
+ if(counterLicensesDeclared == 00){
+ warnings = ""
+ + html.getIcon("exclamation.png", request)
+ + "No licenses declared";
+ }
+
String summary =
"<h2>"
- //+ html.getCommonFolderIcon("wooden-box-label.png")
+ "SPDX summary"
+ "</h2>"
+ html._div
+ html.div(20)
+ + warnings
//+ html.getCommonFolderIcon("documents-stack.png")
+ core.products.size() + " documents"
+ html.br
@@ -245,27 +254,7 @@
return result;
}
- /**
- * Verifies if a given SPDX document exists inside our archive or or not
- * @param spdxTarget The file inside the SPDX Archive
- * @return null if the file does not exists, otherwise return a pointer
- */
- private File getFile(String spdxTarget, WebRequest request){
- if(spdxTarget == null){
- request.setAnswer("No file specified");
- return null;
- }
- // does this file exists?
- File file = new File(core.getProductsFolder(), spdxTarget);
- // this file needs to exist
- if((file.exists() == false) || (file.isDirectory())){
- request.setAnswer("Sorry, the file was not found: " + spdxTarget);
- return null;
- }
- // all done
- return file;
- }
-
+
/**
* Shows the full text of an SPDX document
* @param request
@@ -274,7 +263,7 @@
// we need the "file" parameter to tell us what to detail
String spdxTarget = request.getParameter(param.spdx);
// does this file exists?
- File file = getFile(spdxTarget, request);
+ File file = tools.getFile(spdxTarget, request);
if(file == null){
return;
}
@@ -300,7 +289,7 @@
// we need the "file" parameter to tell us what to detail
String spdxTarget = request.getParameter(param.spdx);
// does this file exists?
- File file = getFile(spdxTarget, request);
+ File file = tools.getFile(spdxTarget, request);
if(file == null){
return;
}
@@ -337,7 +326,18 @@
String evaluation = doEvaluation(spdx);
-
+ // prepare our list of warnings about things we don't particularly enjoy
+ String warnings = "";
+ // we don't like SPDX documents without declared licenses
+ if(counterLicensesDeclared == 00){
+ warnings = ""
+ + html.br
+ + html.br
+ + Table.simple(
+ html.getIcon("exclamation.png", request), 10,
+ "No licenses declared", 150)
+ ;
+ }
// the header when showing summary about a specific SPDX file
@@ -350,7 +350,9 @@
//+ html.getCommonFolderIcon("calculator.png")
+ counterLicensesDeclared + " files with declared licenses"
//+ percentage
+ + warnings
+ evaluation
+ + html.br
;
// generate the nice graph
@@ -367,6 +369,8 @@
summary = Table.alignedTable(header, values);
+
+
// prepare the answer
String result = ""
//swingUtils.getBreadcrumb(node)
@@ -430,7 +434,7 @@
// we need the "file" parameter to tell us what to detail
String spdxTarget = request.getParameter(param.spdx);
// does this file exists?
- File file = getFile(spdxTarget, request);
+ File file = tools.getFile(spdxTarget, request);
if(file == null){
return;
}
@@ -453,7 +457,7 @@
// iterate through all files
for(FileInfo fileInfo : spdx.fileSection.files){
// if there is a license, no need to continue
- if(tools.hasLicense(fileInfo)){
+ if(fileInfo.hasLicense()){
continue;
}
list.add(fileInfo);
@@ -464,7 +468,7 @@
// iterate through all files
for(FileInfo fileInfo : spdx.fileSection.files){
// if there is a license, no need to continue
- if(tools.hasLicense(fileInfo)==false){
+ if(fileInfo.hasLicense()==false){
continue;
}
list.add(fileInfo);
@@ -510,375 +514,7 @@
- /**
- * list some information according to a filter
- * @param request
- */
- public void specific(WebRequest request) {
- // we need the "file" parameter to tell us what to detail
- String spdxTarget = request.getParameter(param.spdx);
- // does this file exists?
- File spdxFile = getFile(spdxTarget, request);
- if(spdxFile == null){
- return;
- }
- // get what we want to show
- String targetFile = request.getParameter(param.file);
- // value can't be empty
- if(targetFile == null){
- request.setAnswer("No filter specified");
- return;
- }
- // start the processing
- SPDXfile spdx = new SPDXfile(spdxFile);
- // go through all files inside the document
- for(FileInfo file : spdx.fileSection.files){
- // have we (finally) found a match?
- if(targetFile.equals(file.getName())){
- String result = getFileDetails(file);
- request.setAnswer(result);
- return;
- }
- }
- request.setAnswer("Didn't found " + targetFile);
- }
-
-
- /**
- * Show the specific file details about a given file name
- * @param file
- */
- private String getFileDetails(FileInfo file){
-
- String googleTerm;
- String filename = file.tagFileName.toString();
- // get the file extension if available
- //String extension = getFileExtension(filename);
-
- try{
-
- // we need to remove misleading terms from the filename
- String filteredName = file.getName().toLowerCase();
- filteredName = filteredName.replace(".tar.gz", "");
- filteredName = filteredName.replace(".zip", "");
- filteredName = filteredName.replace(".jar", "");
- filteredName = filteredName.replace(".7z", "");
- filteredName = filteredName.replace(".tar", "");
- filteredName = filteredName.replace(".bz2", "");
-
- // build up our google query
- googleTerm = filteredName
- + " %22"
- + filename
- + "%22 "
- //+ extension
- ;
-
- } catch (Exception e){
- return log.write(is.ERROR, "SFD01 - Error occurred when trying to build"
- + " a search keyword for google");
-
- }
-
- // do the introduction of this file with a breadcrumb
-// String[] fields = node.getUID().split(">>");
-// String breadCrumb =
-// fields[4]
-// + ">"
-// + fields[3]
-// + ">"
-// + fields[1]
-// ;
- // add a short summary about the file
- String summary = "";
- if(file.tagFileSize != null){
- summary += "This file is sized in " + file.tagFileSize.toString();
- }
- if(file.tagFileLOC != null){
- summary += " and has " + file.tagFileLOC + " lines of code"
- + html.br + html.br;
- }
-
- if(spdxlib.tools.hasLicense(file)){
- summary += "Applicable license(s): " + spdxlib.tools.getLicense(file);
- }
-
- // do the date creation
- //TODO We need to archive file date information
- //summary += "Created in " + file.;
-
-
- String resultIntroduction = ""
- + html.h2(filename)
-// + "<h2>"
-// + breadCrumb
-// + "</h2>"
- + html.div()
- + summary
- + html._div
- // + html.br
- ;
-
- // Add links to find more info on the Internet about the file name
- String resultFilename =
- html.div()
- + html.linkToSearchYandex("\"" + filename + "\"")
- + html.divider
- + html.linkToSearchGoogle(googleTerm)
-// + html.divider
-// + html.linkToSearchOhloh(file.tagFileName.toString())
- + html.divider
- + html.linkToSearchGitHub(file.tagFileName.toString())
- + html._div;
-
- String resultSHA1 = "";
- if(file.tagFileChecksumSHA1!= null){
- resultSHA1 = file.tagFileChecksumSHA1.toString()
- + html.br
- + html.div()
- + html.linkSearch("Find duplicates", "SHA1: "
- + file.tagFileChecksumSHA1.toString())
- + html.divider
- + html.linkToSearchGoogle(
- "%22"+ file.tagFileChecksumSHA1.toString() + "%22" )
- + html._div;
- }
-
- String resultSHA256 = "";
- if(file.tagFileChecksumSHA256!= null){
- resultSHA256 = file.tagFileChecksumSHA256.toString()
- + html.div()
- // only possible when we have SHA256 hashes available
- + html.linkToSearchVirusTotal(file.tagFileChecksumSHA256.toString())
- + html._div;
- }
-
- String resultMD5 = "";
- if(file.tagFileChecksumMD5!= null){
- resultMD5 = file.tagFileChecksumMD5.toString()
- + html.div()
- // We might be lucky and find an MD5 with info
- + html.linkToSearchGoogle(
- "%22"+ file.tagFileChecksumMD5.toString() + "%22" )
- + html._div;
- }
-
-
- String resultSSDEEP = "";
- if(file.tagFileChecksumSSDEEP!= null){
- String text = file.tagFileChecksumSSDEEP.raw;
- // remove the tag header
- text = text.replace("FileChecksum: SSDEEP: ", "");
-
- resultSSDEEP = text
- + html.div()
- // only possible when we have SHA256 hashes available
- + html.linkSearch("Find similar files", "SSDEEP: "
- + text)
- + html._div;
- }
-
- String result = html.div()
- + resultIntroduction
- + html.br
- + swingUtils.addIfNotEmpty("SHA1", resultSHA1)
- + swingUtils.addIfNotEmpty("SHA256", resultSHA256)
- + swingUtils.addIfNotEmpty("MD5",resultMD5)
- //+ html.br
- + swingUtils.addIfNotEmpty("SSDEEP", resultSSDEEP)
- + swingUtils.addIfNotEmpty("Look for \""
- +filename
- +"\" in search engines"
- , resultFilename)
- + html._div
-// + swingUtils.addSSDEEP("SSDEEP", file)
-// + swingUtils.addIfNotEmpty("Copyright text",file.tagFileCopyrightText.toString())
- ;
-
- /** missing to add:
- * - File path
- * - Applicable licenses (when available)
- */
- return result;
- }
-
-// /**
-// * This operation might take a while, so we first launch a menu asking
-// * people to wait for a while and then launch a thread with the results
-// */
-// void showFilesWithoutLicense(){
-// String inProgress = ""
-// + html.div()
-// + "<h2>"
-// + html.getCommonFolderIcon("wand.png")
-// + "In progress!</h2>"
-// + ""
-// + "We are creating a list, please wait.."
-// + html.br
-// + html._div;
-// // update the text box
-// core.studio.editorPane(is.contentHTML, false, 0, inProgress);
-// Thread thread = new Thread(){
-// @Override
-// public void run(){
-// processFilesWithoutLicense();
-// }
-// };
-// thread.start();
-// }
-//
-// /**
-// * This operation might take a while, so we first launch a menu asking
-// * people to wait for a while and then launch a thread with the results
-// */
-// void showFilesWithLicense(){
-// String inProgress = ""
-// + html.div()
-// + "<h2>"
-// + html.getCommonFolderIcon("wand.png")
-// + "In progress!</h2>"
-// + ""
-// + "We are creating a list, please wait.."
-// + html.br
-// + html._div;
-// // update the text box
-// core.studio.editorPane(is.contentHTML, false, 0, inProgress);
-// Thread thread = new Thread(){
-// @Override
-// public void run(){
-// processFilesWithLicense();
-// }
-// };
-// thread.start();
-// }
-//
-//
-//
-//
-// /**
-// * Shows a list of files for the selected package that do not have a license
-// */
-// void processFilesWithoutLicense(){
-//
-// //node = swingUtils.getSelectedNode();
-// node = (TreeNodeSPDX) core.temp.get("showPackageDetails");
-// // no need to continue if there is nothing selected
-// if(node == null){
-// return;
-// }
-// // get the SPDX file from the root node
-// SPDXfile spdx = (SPDXfile) node.getUserObject();
-//
-// // create the HTML data where our info will be placed
-// String[] columns = new String[]{"File name", "Path", ""};
-// Table table = new Table(columns);
-//
-//
-// // iterate through all files
-// for(FileInfo file : spdx.fileSection.files){
-//
-// // if there is a license, no need to continue
-// if(tools.hasLicense(file)){
-// continue;
-// }
-//
-// // create a column with our file information
-// String[] column = new String[]{
-// utils.text.shortText(file.toString(), 25),
-// utils.text.shortText(file.tagFilePath.toString(), 30),
-// //file.tagFilePath.toString(),
-// html.linkNode("details", ">> "
-// + file.tagFileName.toString()
-// + " >> Files >> "
-// + node.id
-// + " >> Products ")
-// };
-// table.add(column);
-// }
-//
-// // do the output that is displayed to the end-user
-// String result = swingUtils.getBreadcrumb(node)
-// + html.div(20)
-// + table.output()
-// + html._div
-// ;
-//
-// // write everything on our UI text area
-// core.studio.editorPane(is.contentHTML, false, 0, result, false, null);
-// }
-//
-// /**
-// * Shows a list of files for the selected package that do not have a license
-// */
-// void processFilesWithLicense(){
-//
-// //node = swingUtils.getSelectedNode();
-// node = (TreeNodeSPDX) core.temp.get("showPackageDetails");
-// // no need to continue if there is nothing selected
-// if(node == null){
-// return;
-// }
-// // get the SPDX file from the root node
-// SPDXfile spdx = (SPDXfile) node.getUserObject();
-//
-// // create the HTML data where our info will be placed
-// String[] columns = new String[]{"File name", "Path", ""};
-// Table table = new Table(columns);
-//
-//
-// // iterate through all files
-// for(FileInfo file : spdx.fileSection.files){
-//
-// // if there is a license, no need to continue
-// if(tools.hasLicense(file) == false){
-// continue;
-// }
-//
-// // create a column with our file information
-// String[] column = new String[]{
-// utils.text.shortText(file.toString(), 25),
-// utils.text.shortText(file.tagFilePath.toString(), 30),
-// //file.tagFilePath.toString(),
-// html.linkNode("details", ">> "
-// + file.tagFileName.toString()
-// + " >> Files >> "
-// + node.id
-// + " >> Products ")
-// };
-// table.add(column);
-// }
-//
-// // do the output that is displayed to the end-user
-// String result = swingUtils.getBreadcrumb(node)
-// + html.div(20)
-// + table.output()
-// + html._div
-// ;
-//
-// // write everything on our UI text area
-// core.studio.editorPane(is.contentHTML, false, 0, result, false, null);
-// }
-//
-//
-// /**
-// * Show the SPDX document on the text area
-// */
-// public void showSPDX(){
-// node = swingUtils.getSelectedNode();
-// // no need to continue if there is nothing selected
-// if(node == null){
-// return;
-// }
-// // get the SPDX file from the root node
-// SPDXfile spdx = (SPDXfile) node.getUserObject();
-//
-//
-// // write everything on our UI text area
-// String content = spdx.rawText;
-// core.studio.editorPane(is.contentText, true, 0, content);
-// }
-//
-//
+
/**
* When given a SPDX object, provide some statistics
@@ -890,7 +526,7 @@
for(Object fileObject : spdx.fileSection.files){
FileInfo file = (FileInfo) fileObject;
// go deep into the license information
- if(tools.hasLicense(file)){
+ if(file.hasLicense()){
counterLicensesDeclared++;
}
}
@@ -905,6 +541,8 @@
*/
private String doEvaluation(SPDXfile spdx) {
String result = "";
+
+
Boolean hasSVNfiles = false;
ArrayList<FileInfo> list = spdx.fileSection.files;
for(FileInfo file : list){