Skip to content

Commit

Permalink
useXsd removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Diederich committed Dec 1, 2023
1 parent fd62d4f commit 25cc518
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
<extendedInfo>true</extendedInfo>
<writeCalcFile>true</writeCalcFile>
<writeExcelFile>true</writeExcelFile>
<useXsd>true</useXsd>
<licenseMerges>
<licenseMerge>The Apache Software License, Version 2.0|Apache License, Version 2.0|Apache Public License
2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,4 @@ try (OdfSpreadsheetDocument spreadsheet = OdfSpreadsheetDocument.loadDocument(ca
List<OdfTable> tableList = spreadsheet.getTableList()
OdfTable table = tableList.get(0)
assert table.getRowCount() >= 3
}

// ----------- Check for XSD file ----------------
licensesXsd = new File(basedir, 'target/generated-resources/licenses.xsd')
assert licensesXsd.exists()
}
Original file line number Diff line number Diff line change
Expand Up @@ -614,15 +614,6 @@ public abstract class AbstractDownloadLicensesMojo extends AbstractLicensesXmlMo
@Parameter(property = "license.writeVersions", defaultValue = "true")
private boolean writeVersions;

/**
* If {@code true}, a <code>licenses.xsd</code> file will be written in the same directory as the
* XML file, and be referenced in the XML file.
*
* @since 2.4
*/
@Parameter(property = "license.useXsd", defaultValue = "false")
private boolean useXsd;

/**
* Connect timeout in milliseconds passed to the HTTP client when downloading licenses from remote URLs.
*
Expand Down Expand Up @@ -933,7 +924,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
private void writeLicenseSummaries(
List<ProjectLicenseInfo> depProjectLicenses, File outputFile, File excelOutputFile, File calcOutputFile)
throws ParserConfigurationException, TransformerException, IOException {
writeLicenseSummary(depProjectLicenses, outputFile, writeVersions, useXsd);
writeLicenseSummary(depProjectLicenses, outputFile, writeVersions);
if (writeExcelFile) {
ExcelFileWriter.write(depProjectLicenses, excelOutputFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,10 @@ protected Path[] getAutodetectEolFiles() {
return new Path[] {licensesOutputFile.toPath()};
}

protected void writeLicenseSummary(
List<ProjectLicenseInfo> deps, File licensesOutputFile, boolean writeVersions, boolean useXsd)
protected void writeLicenseSummary(List<ProjectLicenseInfo> deps, File licensesOutputFile, boolean writeVersions)
throws ParserConfigurationException, TransformerException, IOException {
initEncoding();
LicenseSummaryWriter.writeLicenseSummary(
deps, licensesOutputFile, charset, licensesOutputFileEol, writeVersions, useXsd);
deps, licensesOutputFile, charset, licensesOutputFileEol, writeVersions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ public class LicensesXmlInsertVersionsMojo extends AbstractLicensesXmlMojo {
@Parameter(property = "license.skipDownloadLicenses", defaultValue = "false")
private boolean skipDownloadLicenses;

/**
* If {@code true}, a <code>licenses.xsd</code> file will be written in the same directory as the
* XML file, and be referenced in the XML file.
*
* @since 2.4
*/
@Parameter(property = "license.useXsd", defaultValue = "false")
private boolean useXsd;

public void execute() throws MojoExecutionException, MojoFailureException {

if (skipDownloadLicenses) {
Expand Down Expand Up @@ -161,7 +152,7 @@ public ArtifactFilters getArtifactFilters() {
dependencyLicenseInfo.setVersion(dependency.getVersion());
}

writeLicenseSummary(projectLicenseInfos, licensesOutputFile, true, useXsd);
writeLicenseSummary(projectLicenseInfos, licensesOutputFile, true);
} catch (MojoFailureException e) {
throw e;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
Expand All @@ -55,8 +51,6 @@
import org.codehaus.mojo.license.Eol;
import org.codehaus.mojo.license.extended.ExtendedInfo;
import org.codehaus.mojo.license.extended.InfoFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand All @@ -70,43 +64,19 @@
*/
public class LicenseSummaryWriter {

private static final Logger LOG = LoggerFactory.getLogger(LicenseSummaryWriter.class);

static final String LICENSES_XSD_FILE = "licenses.xsd";
private static final String LICENSE_FOLDER = "/org/codehaus/mojo/license/";
static final String LICENSE_PATH = LICENSE_FOLDER + LICENSES_XSD_FILE;

public static void writeLicenseSummary(
List<ProjectLicenseInfo> dependencies,
File outputFile,
Charset charset,
Eol eol,
boolean writeVersions,
boolean useXsd)
List<ProjectLicenseInfo> dependencies, File outputFile, Charset charset, Eol eol, boolean writeVersions)
throws ParserConfigurationException, TransformerException, IOException {
DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = fact.newDocumentBuilder();
Document doc = parser.newDocument();

Element root = doc.createElement("licenseSummary");

if (useXsd) {
root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
root.setAttribute("xsi:noNamespaceSchemaLocation", LICENSES_XSD_FILE);
Path targetXsd = Paths.get(outputFile.toPath().getParent().toFile().getAbsolutePath(), LICENSES_XSD_FILE);
File targetFile = targetXsd.toFile();
if (targetFile.exists()) {
LOG.debug("Target XSD file {} already does exist", targetXsd);
} else {
try (InputStream inputStream = LicenseSummaryWriter.class.getResourceAsStream(LICENSE_PATH)) {
if (inputStream == null) {
throw new NoSuchFileException(LICENSE_PATH);
}
Files.copy(inputStream, targetXsd);
}
}
}

doc.appendChild(root);
Node dependenciesNode = doc.createElement("dependencies");
root.appendChild(dependenciesNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
Expand All @@ -40,7 +39,6 @@
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;

import static org.codehaus.mojo.license.download.LicenseSummaryWriter.LICENSES_XSD_FILE;
import static org.codehaus.mojo.license.download.LicenseSummaryWriter.LICENSE_PATH;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -120,7 +118,7 @@ public void testWriteReadLicenseSummary()
{
File licenseSummaryFile = File.createTempFile("licSummary", "tmp");
LicenseSummaryWriter.writeLicenseSummary(
licSummary, licenseSummaryFile, StandardCharsets.UTF_8, Eol.LF, true, true);
licSummary, licenseSummaryFile, StandardCharsets.UTF_8, Eol.LF, true);

assertTrue(licenseSummaryFile.exists());
FileInputStream fis = new FileInputStream(licenseSummaryFile);
Expand All @@ -140,18 +138,12 @@ public void testWriteReadLicenseSummary()
Assert.assertEquals("lgpl version 3.0", lic0.getComments());

validateXml(licenseSummaryFile);

// Check if the LICENSES_XSD_FILE was copied to the target directory.
Path targetXsd =
Paths.get(licenseSummaryFile.toPath().getParent().toFile().getAbsolutePath(), LICENSES_XSD_FILE);
File targetFile = targetXsd.toFile();
assertTrue(targetFile.exists());
}

{
File licenseSummaryFile = File.createTempFile("licSummaryNoVersionNoXsd", "tmp");
LicenseSummaryWriter.writeLicenseSummary(
licSummary, licenseSummaryFile, StandardCharsets.UTF_8, Eol.LF, false, false);
licSummary, licenseSummaryFile, StandardCharsets.UTF_8, Eol.LF, false);

assertTrue(licenseSummaryFile.exists());
FileInputStream fis = new FileInputStream(licenseSummaryFile);
Expand Down

0 comments on commit 25cc518

Please sign in to comment.