--- a/tool/src/spdxlib/tools.java
+++ b/tool/src/spdxlib/tools.java
@@ -13,6 +13,10 @@
package spdxlib;
+import java.io.File;
+import main.core;
+import www.WebRequest;
+
/**
*
@@ -21,78 +25,27 @@
*/
public class tools {
-
/**
- * This method will pick on a given FileInfo object and extract the relevant
- * licensing details.
- * @param file The FileInfo object, cannot be null
- * @return A string text with a list of licenses when available. If no
- * license was found, it will return null
+ * Verifies if a given SPDX document exists inside our archive or or not
+ * @param spdxTarget The file inside the SPDX Archive
+ * @param request
+ * @return null if the file does not exists, otherwise return a pointer
*/
- public static String getLicense(FileInfo file){
- String licenseOutput = "";
- // priority is the case where a human concludes a license
- if((file.tagLicenseConcluded != null)
- &&(file.tagLicenseConcluded.toString().equals("NOASSERTION")!=true)){
- // no need to proceed
- return file.tagFileName.toString()
- + " ("+ file.tagLicenseConcluded.toString() +")";
+ public static File getFile(String spdxTarget, WebRequest request){
+ if(spdxTarget == null){
+ request.setAnswer("No file specified");
+ return null;
}
-
- // second priority are licenses detected inside the code
- if(file.licenseInfoInFile.size()>0){
-
- for(TagValue tag : file.licenseInfoInFile){
- licenseOutput = licenseOutput.concat(", " + tag.toString());
- }
- // remove the first comma added throught our loop
- licenseOutput = " (" + licenseOutput.substring(2) + ")";
+ // 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;
}
- return licenseOutput;
+ // all done
+ return file;
}
-
- /**
- * When given a file, this method checks if it has either a reported or
- * concluded license. The method is necessary since sometimes one of these
- * fields is present using infomation like "NOASSERTION" which really
- * becomes a problem to normalize.
- * @param file A FileInfo object with the information that we will analyze
- * @return
- */
- public static Boolean hasLicense(FileInfo file){
-
- // do we have a license concluded for this file?
- if(file.tagLicenseConcluded != null){
- // get the text from the license that was concluded
- String licenseText = file.tagLicenseConcluded.toString();
- // a lot of trouble, but necessary to find out what is happening
- if( (licenseText.equals("NONE")== false)
- && (licenseText.equals("NOASSERTION")== false)){
- // we have at least one license concluded. Good enough
- return true;
- }
- }
-
- // are there any licenses inside this file?
- for(TagValue licenseTag : file.licenseInfoInFile){
- String licenseText = licenseTag.toString();
- // excluse the cases that shouldn't count for this metric
- if(licenseText.equals("NONE")){
- continue;
- }
- if(licenseText.equals("NOASSERTION")){
- continue;
- }
- // we just need to find one license to make our day valid! :-)
- return true;
- }
-
-
-
-
- // no licenses, let's leave
- return false;
- }
-
+
}