Skip to content

Commit

Permalink
Write Excel files with extensive License Information (inc. infos from…
Browse files Browse the repository at this point in the history
… the JARs) (#527)

Co-authored-by: Jan-Hendrik Diederich <jan-hendrik.diederich@cstx.de>
Co-authored-by: Jan-Hendrik Diederich <jan-hendrik.diederich@cstx-mi.de>
Co-authored-by: Jan Diederich <ms.config@hotmai.com>
  • Loading branch information
4 people committed Dec 10, 2023
1 parent 6b6e0e6 commit fe0747a
Show file tree
Hide file tree
Showing 31 changed files with 3,665 additions and 166 deletions.
43 changes: 42 additions & 1 deletion pom.xml
Expand Up @@ -316,6 +316,28 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<!-- Needed for extended constants in JARs MANIFEST.MF -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
</dependency>

<!-- Microsoft Excel XLSX export -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.4</version>
</dependency>

<!-- LibreOffice Calc ODT export -->
<dependency>
<groupId>org.odftoolkit</groupId>
<artifactId>odfdom-java</artifactId>
<!-- There are later versions, but that versions need JDKs after version 8 -->
<version>0.9.0</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -363,7 +385,7 @@
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java17</artifactId>
<artifactId>java18</artifactId>
<version>1.0</version>
</signature>
</configuration>
Expand Down Expand Up @@ -492,6 +514,25 @@
<projectVersion>${project.version}</projectVersion>
</scriptVariables>
</configuration>
<dependencies>
<!-- Microsoft Excel XLSX export -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.4</version>
</dependency>
<!-- LibreOffice Calc ODT export -->
<dependency>
<groupId>org.odftoolkit</groupId>
<artifactId>odfdom-java</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.13.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>all-integration-test</id>
Expand Down
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%L
License Maven Plugin
%%
Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
%%
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Lesser Public License for more details.
You should have received a copy of the GNU General Lesser Public
License along with this program. If not, see
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>test-aggregate-download-licenses-extended-excel</artifactId>
<version>@project.version@</version>
</parent>
<artifactId>test-aggregate-download-licenses-extended-spreadsheet-child1</artifactId>

<name>License Test :: aggregate-download-licenses - Extended Spreadsheet — child 1</name>

<dependencies>

<!-- use license 'The Apache Software License, Version 2.0' -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.35.0</version>
</dependency>
</dependencies>

</project>


@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%L
License Maven Plugin
%%
Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
%%
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Lesser Public License for more details.
You should have received a copy of the GNU General Lesser Public
License along with this program. If not, see
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>test-aggregate-download-licenses-extended-excel</artifactId>
<version>@project.version@</version>
</parent>
<artifactId>test-aggregate-download-licenses-extended-spreadsheet-child2</artifactId>

<name>License Test :: aggregate-download-licenses - Extended Spreadsheet — child 2</name>

<dependencies>

<!-- use license 'Apache License, Version 2.0' -->
<dependency>
<groupId>com.jhlabs</groupId>
<artifactId>filters</artifactId>
<version>2.0.235</version>
</dependency>

<!-- use license 'Apache Public License 2.0' -->
<dependency>
<groupId>org.sonatype.plexus</groupId>
<artifactId>plexus-cipher</artifactId>
<version>1.7</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.0</version>
</dependency>
</dependencies>

</project>


@@ -0,0 +1,23 @@
###
# #%L
# License Maven Plugin
# %%
# Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
# %%
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Lesser Public License for more details.
#
# You should have received a copy of the GNU General Lesser Public
# License along with this program. If not, see
# <http://www.gnu.org/licenses/lgpl-3.0.html>.
# #L%
###
invoker.goals=clean license:aggregate-download-licenses
invoker.failureBehavior=fail-fast
77 changes: 77 additions & 0 deletions src/it/aggregate-download-licenses-extended-spreadsheet/pom.xml
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%L
License Maven Plugin
%%
Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
%%
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Lesser Public License for more details.
You should have received a copy of the GNU General Lesser Public
License along with this program. If not, see
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>test-aggregate-download-licenses-extended-excel</artifactId>
<version>@project.version@</version>

<modules>
<module>child1</module>
<module>child2</module>
</modules>

<name>License Test :: aggregate-download-licenses - Extended Spreadsheet</name>

<packaging>pom</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<license.verbose>true</license.verbose>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<extendedInfo>true</extendedInfo>
<writeCalcFile>true</writeCalcFile>
<writeExcelFile>true</writeExcelFile>
<licenseMerges>
<licenseMerge>The Apache Software License, Version 2.0|Apache License, Version 2.0|Apache Public License
2.0
</licenseMerge>
</licenseMerges>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<dependencies>
<dependency>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core</artifactId>
<version>9.2.0.74516</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,86 @@
/*
* #%L
* License Maven Plugin
* %%
* Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/

import org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument
import org.odftoolkit.odfdom.doc.table.OdfTable

import java.util.logging.Level
import java.util.logging.Logger

import org.apache.poi.ss.usermodel.Cell
import org.apache.poi.ss.usermodel.CellType
import org.apache.poi.ss.usermodel.Row
import org.apache.poi.ss.usermodel.Sheet
import org.apache.poi.ss.usermodel.Workbook
import org.apache.poi.ss.usermodel.WorkbookFactory

log = Logger.getLogger("test-aggregate-download-licenses-extended-spreadsheet")

static boolean searchTextInExcel(Sheet sheet, String searchText) {
def log2 = Logger.getLogger("test-aggregate-download-licenses-extended-spreadsheet-search")

for (Iterator<Row> rowIterator = sheet.rowIterator(); rowIterator.hasNext();) {
Row row = rowIterator.next()
for (Iterator<Cell> cellIterator = row.cellIterator(); cellIterator.hasNext();) {
Cell cell = cellIterator.next()
if (cell.cellType == CellType.STRING || cell.cellType == CellType.BLANK) {
def cellValue = cell.stringCellValue
if (cellValue == searchText) {
return true
} else {
log2.log(Level.FINEST, "Cell Value: {0}", cellValue)
}
}
}
}
return false
}

// -------------- Excel ----------------------
excelFile = new File(basedir, 'target/generated-resources/licenses.xlsx')
assert excelFile.exists()
assert excelFile.length() > 100

try (InputStream input = new FileInputStream(excelFile)) {
// So it can be easily opened and inspected manually. In a modern IDE it's just a (double-)click in the log output.
log.log(Level.FINE, "Excel export at: {}", excelFile.absolutePath)
Workbook workbook = WorkbookFactory.create(input)
Sheet sheet = workbook.getSheetAt(0)

assert searchTextInExcel(sheet, "Maven information")
assert searchTextInExcel(sheet, "The Apache Software License, Version 2.0")
assert searchTextInExcel(sheet, "The Apache Software Foundation")
}

// -------------- Calc -----------------

calcFile = new File(basedir, 'target/generated-resources/licenses.ods')
assert calcFile.exists()
assert calcFile.length() > 100

try (OdfSpreadsheetDocument spreadsheet = OdfSpreadsheetDocument.loadDocument(calcFile)) {
// So it can be easily opened and inspected manually. In a modern IDE it's just a (double-)click in the log output.
log.log(Level.FINE, "Calc export at: {}", calcFile.absolutePath)
List<OdfTable> tableList = spreadsheet.getTableList()
OdfTable table = tableList.get(0)
assert table.getRowCount() >= 3
}
Expand Up @@ -352,7 +352,7 @@ public abstract class AbstractAddThirdPartyMojo extends AbstractLicenseMojo {
/**
* A URL prepared either our of {@link #overrideFile} or {@link #overrideUrl} or the default value.
*
* @see LicenseMojoUtils#prepareThirdPartyOverrideUrl(URL, File, String, File)
* @see LicenseMojoUtils#prepareThirdPartyOverrideUrl(String, File, String, File)
*/
protected String resolvedOverrideUrl;

Expand Down

0 comments on commit fe0747a

Please sign in to comment.