Skip to content

Commit

Permalink
Undo change: Add back print statement
Browse files Browse the repository at this point in the history
  • Loading branch information
tjasmith authored and goneall committed Jul 1, 2020
1 parent 589b862 commit 9a4cd45
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions src/org/spdx/licenselistpublisher/LicenseRDFAGenerator.java
Expand Up @@ -67,11 +67,11 @@

/**
* Converts input license text and metadata into various output formats.
*
*
* Supported input formats:
* - License XML file - File following the SPDX legal team license format
* - Directory of XML files - Directory of files following the SPDX legal team license format
*
*
* Supported output formats:
* - Text - license text
* - Templates - license templates as defined by the SPDX legal team matching guidelines
Expand All @@ -81,20 +81,20 @@
* - RDF XML - RDF XML format defined by the SPDX Spec
* - RDF Turtle - RDF Turtle format defined by the SPDX Spec
* - Website - the content for the website available at https://spdx.org/licenses
*
* Output generated by this tool can be found at https://github.com/spdx/license-list-data and on the
*
* Output generated by this tool can be found at https://github.com/spdx/license-list-data and on the
* spdx.org licenses website
*
*
* To add a new output format, create a class supporting the ILicenseFormatWriter interface and add it
* to the writers list.
*
*
* @author Gary O'Neall
*
*/
public class LicenseRDFAGenerator {

static final Set<Character> INVALID_TEXT_CHARS = Sets.newHashSet();

static {
INVALID_TEXT_CHARS.add('\uFFFD');
}
Expand All @@ -118,7 +118,7 @@ public class LicenseRDFAGenerator {
private static final String RDFNT_FOLDER_NAME = "rdfnt";
private static final String TABLE_OF_CONTENTS_FILE_NAME = "licenses.md";
private static final String RDF_JSON_LD_FOLDER_NAME = "jsonld";

/**
* @param args Arg 0 is either a license XML file or a directory of licenses in XML format, arg 1 is the directory for the output html files
*/
Expand Down Expand Up @@ -226,7 +226,7 @@ public static void main(String[] args) {
* @param releaseDate Release data string for the license
* @param testFileDir Directory of license text to test the generated licenses against
* @return warnings
* @throws LicenseGeneratorException
* @throws LicenseGeneratorException
*/
public static List<String> generateLicenseData(File licenseXml, File dir,
String version, String releaseDate, File testFileDir) throws LicenseGeneratorException {
Expand Down Expand Up @@ -335,19 +335,19 @@ public static List<String> generateLicenseData(File licenseXml, File dir,
throw new LicenseGeneratorException("\nUnhandled exception generating html: "+e.getMessage(),e);
}
}

/**
* @param version License list version
* @param releaseDate release date for the license list
* @param licenseProvider Provides the licensing information
* @param warnings Populated with any warnings if they occur
* @param writers License Format Writers to handle the writing for the different formats
* @param tester License tester used to test the results of licenses
* @throws IOException
* @throws SpreadsheetException
* @throws LicenseRestrictionException
* @throws LicenseGeneratorException
* @throws InvalidLicenseTemplateException
* @throws IOException
* @throws SpreadsheetException
* @throws LicenseRestrictionException
* @throws LicenseGeneratorException
* @throws InvalidLicenseTemplateException
*/
private static void writeExceptionList(String version, String releaseDate,
ISpdxListedLicenseProvider licenseProvider, List<String> warnings, List<ILicenseFormatWriter> writers,
Expand All @@ -358,11 +358,11 @@ private static void writeExceptionList(String version, String releaseDate,
Iterator<SpdxListedLicense> licIter = licenseProvider.getLicenseIterator();
while (licIter.hasNext()) {
licenseIds.add(licIter.next().getLicenseId());
}
}
} catch (SpdxListedLicenseException e) {
System.out.println("Warning - Not able to check for duplicate license and exception ID's");
}

Iterator<ListedLicenseException> exceptionIter = licenseProvider.getExceptionIterator();
Map<String, String> addedExceptionsMap = Maps.newHashMap();
while (exceptionIter.hasNext()) {
Expand All @@ -380,13 +380,13 @@ private static void writeExceptionList(String version, String releaseDate,
}
}
// check for a license ID with the same ID as the exception

addedExceptionsMap.put(nextException.getLicenseExceptionId(), nextException.getLicenseExceptionText());
}
if (licenseIds.contains(nextException.getLicenseExceptionId())) {
warnings.add("A license ID exists with the same ID as an exception ID: "+nextException.getLicenseExceptionId());
}
checkText(nextException.getLicenseExceptionText(),
checkText(nextException.getLicenseExceptionText(),
"License Exception Text for "+nextException.getLicenseExceptionId(), warnings);
for (ILicenseFormatWriter writer:writers) {
writer.writeException(nextException);
Expand All @@ -399,19 +399,19 @@ private static void writeExceptionList(String version, String releaseDate,
}
}
}

}
}
}

/**
* Add any additional data to a license exception from external sources
* @param exception Exception with fields updated from external sources
*/
private static void addExternalMetaData(LicenseException exception) {
// Currently, there is no data to add
}

/**
* Check text for invalid characters
* @param text Text to check
Expand All @@ -428,7 +428,7 @@ private static void checkText(String text, String textDescription,
for (int i = 0; i < line.length(); i++) {
if (INVALID_TEXT_CHARS.contains(line.charAt(i))) {
warnings.add("Invalid character in " + textDescription +
" at line number " + String.valueOf(lineNumber) +
" at line number " + String.valueOf(lineNumber) +
" \"" +line + "\" at character location "+String.valueOf(i));
}
}
Expand All @@ -445,7 +445,7 @@ private static void checkText(String text, String textDescription,
}
}
}

/**
* Formats and writes the license list data
* @param version License list version
Expand All @@ -466,6 +466,7 @@ private static void writeLicenseList(String version, String releaseDate,
Iterator<SpdxListedLicense> licenseIter = licenseProvider.getLicenseIterator();
Map<String, String> addedLicIdTextMap = Maps.newHashMap(); // keep track for duplicate checking
while (licenseIter.hasNext()) {
System.out.print(".");
SpdxListedLicense license = licenseIter.next();
addExternalMetaData(license);
if (license.getLicenseId() != null && !license.getLicenseId().isEmpty()) {
Expand Down Expand Up @@ -499,17 +500,17 @@ private static void writeLicenseList(String version, String releaseDate,
/**
* Update license fields based on information from external metadata
* @param license
* @throws LicenseGeneratorException
* @throws LicenseGeneratorException
*/
private static void addExternalMetaData(SpdxListedLicense license) throws LicenseGeneratorException {
license.setFsfLibre(FsfLicenseDataParser.getFsfLicenseDataParser().isSpdxLicenseFsfLibre(license.getLicenseId()));
}

/**
* Copy a file from the resources directory to a destination file
* @param resourceFileName filename of the file in the resources directory
* @param destination target file - warning, this will be overwritten
* @throws IOException
* @throws IOException
*/
private static void copyResourceFile(String resourceFileName, File destination) throws IOException {
File resourceFile = new File(resourceFileName);
Expand Down Expand Up @@ -544,15 +545,15 @@ private static void writeCssFile(File dir) throws IOException {
}
copyResourceFile(CSS_TEMPLATE_FILE, cssFile);
}

private static void writeSortTableFile(File dir) throws IOException {
File sortTableFile = new File(dir.getPath()+ File.separator + SORTTABLE_FILE_NAME);
if (sortTableFile.exists()) {
return; // assume we don't need to create it
}
copyResourceFile(SORTTABLE_JS_FILE, sortTableFile);
}

private static void usage() {
System.out.println("Usage:");
System.out.println("LicenseRDFAGenerator licencenseXmlFileOrDir outputDirectory [version] [releasedate] [testfiles] [ignoredwarnings]");
Expand Down

0 comments on commit 9a4cd45

Please sign in to comment.