Child: [r15] (diff)

Download this file

FileInfo.java    112 lines (92 with data), 3.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* SPDXVersion: SPDX-1.1
* Person: Person: Nuno Brito (nuno.brito@triplecheck.de)
* Person: Organization: TripleCheck (contact@triplecheck.de)
* Created: 2013-08-29T00:00:00Z
* LicenseName: NOASSERTION
* FileName: FileInfo.java
* FileType: SOURCE
* FileCopyrightText: <text> Copyright 2013 Nuno Brito, TripleCheck </text>
* FileComment: <text> Holds all info collected about each individual
* file of the package </text>
*/
package spdxlib;
import java.util.ArrayList;
public class FileInfo {
public TagValue
tagFileName, // full path and name of the file, mandatory, one
tagFiletype, // kind of file that is referenced here
tagFileChecksumSHA1,
tagLicenseConcluded; // result of audit, mandatory, one
public ArrayList<TagValue>
// list all the licenses collected from the files included
licenseInfoInFile = new ArrayList(); // mandatory, one or many
public TagValue
tagLicenseComments, // other info about the origin, optional, one
tagFileCopyrightText, // copyright text found in file, mandatory, one
tagArtifactOfProjectName, // identify origin of file, optional, one
tagArtifactOfProjectHomePage, // identify origin of file, optional, one
tagArtifactOfProjectURI, // direct link to file, optional, one
tagComment; // generic comment about file, optional, one
// non-standard tags
public TagValue
tagFilePath,
tagFileSize,
tagFileLOC,
tagFileChecksumSHA256,
tagFileChecksumSSDEEP,
tagFileChecksumMD5;
/**
* Prints the data from this object for debugging the result
*/
public void print(){
System.out.println(""
+ "---" + add("Filename", tagFileName)
+ add("LOC", tagFileLOC)
+ add("Size", tagFileSize)
+ "-----------------"
);
}
String add(String title, TagValue tag){
String result = "";
if(tag !=null){
result = title + ":" + tag.toString() + "\n";
}
return result;
}
/**
* Each file can have one or more license applicable.
* This method adds them up as needed.
*/
public void addLicense(TagValue tag){
licenseInfoInFile.add(tag);
}
@Override
public String toString(){
String licenseOutput = "";
// priority is the case where a human concludes a license
if((this.tagLicenseConcluded != null)
&&(tagLicenseConcluded.toString().equals("NOASSERTION")!=true)){
// no need to proceed
return tagFileName.toString()
+ " ("+ tagLicenseConcluded.toString() +")";
}
// second priority are licenses detected inside the code
if(licenseInfoInFile.size()>0){
for(TagValue tag : licenseInfoInFile){
licenseOutput = licenseOutput.concat(", " + tag.toString());
}
// remove the first comma added throught our loop
licenseOutput = " (" + licenseOutput.substring(2) + ")";
}
// output the final result
return tagFileName.toString() + licenseOutput;
}
/**
* Returns the file name without unwanted chars
* @return the file name of this object
*/
public String getName(){
return tagFileName.toString();
}
}