Skip to content

Commit

Permalink
Merge pull request #25 from aloubyansky/maven-3.9.6-java-11
Browse files Browse the repository at this point in the history
Upgrade to the latest Maven core and resolver versions, target Java 11
  • Loading branch information
geoand committed Feb 16, 2024
2 parents 905f88a + abd140e commit f3cb1eb
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 36 deletions.
118 changes: 103 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@
<commons-io.version>2.7</commons-io.version>
<jaxb.version>2.3.1</jaxb.version>
<json.version>1.1.4</json.version>
<jtwig.version>5.87.0.RELEASE</jtwig.version>
<junit.version>4.12</junit.version>
<maven-core.version>3.9.6</maven-core.version>
<maven-embedder.version>3.15</maven-embedder.version>
<maven-resolver.version>1.9.18</maven-resolver.version>
<maven-wagon.version>3.5.3</maven-wagon.version>
<mockito.version>3.11.0</mockito.version>
<qute.version>2.16.12.Final</qute.version>
<resteasy.version>4.5.12.Final</resteasy.version>
<slf4j.version>1.7.30</slf4j.version>
<undertow.version>2.2.8.Final</undertow.version>
Expand Down Expand Up @@ -100,17 +103,11 @@
</repositories>

<dependencies>
<!-- Twig -->
<!-- Qute -->
<dependency>
<groupId>org.jtwig</groupId>
<artifactId>jtwig-core</artifactId>
<version>${jtwig.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
<groupId>io.quarkus.qute</groupId>
<artifactId>qute-core</artifactId>
<version>${qute.version}</version>
</dependency>

<!-- JSON -->
Expand All @@ -130,17 +127,108 @@
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven-core.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${maven-core.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven-core.version}</version>
<exclusions>
<exclusion>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>${maven-core.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<!-- let's prefer the plexus-utils pulled by maven-resolver-provider -->
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</exclusion>
<exclusion>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
<version>${maven-resolver.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-wagon</artifactId>
<version>${maven-resolver.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
<version>${maven-resolver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-spi</artifactId>
<version>${maven-resolver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-impl</artifactId>
<version>${maven-resolver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
<version>${maven-resolver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<version>3.3.2</version>
<version>${maven-wagon.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>3.3.2</version>
<version>${maven-wagon.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -271,8 +359,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
Expand Down
39 changes: 31 additions & 8 deletions src/main/java/me/snowdrop/licenses/LicensesFileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package me.snowdrop.licenses;

import io.quarkus.qute.Qute;
import me.snowdrop.licenses.xml.DependencyElement;
import me.snowdrop.licenses.xml.LicenseElement;
import me.snowdrop.licenses.xml.LicenseSummary;
Expand All @@ -27,16 +28,19 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.jtwig.JtwigModel;
import org.jtwig.JtwigTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.bind.JAXBException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.AbstractMap;
import java.util.List;
Expand All @@ -54,6 +58,7 @@ public class LicensesFileManager {
private static final int DOWNLOAD_TIMEOUT = 60_000;

private static final String CONTENTS_DIR = "contents";
private static final String LICENSES_QUTE = "licenses.qute";

private final Logger logger = LoggerFactory.getLogger(LicensesFileManager.class);

Expand Down Expand Up @@ -96,18 +101,36 @@ public void createLicensesHtml(LicenseSummary licenseSummary, String directoryPa
Map<String, String> licenseFiles = downloadLicenseFiles(licenseSummary.getDependencies(), directoryPath);

File file = new File(directoryPath, "licenses.html");
JtwigTemplate template = JtwigTemplate.classpathTemplate("licenses.twig");
JtwigModel model = JtwigModel.newModel()
.with("dependencies", licenseSummary.getDependencies())
.with("licenseFiles", licenseFiles);

try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
template.render(model, fileOutputStream);
try (FileWriter fileOutputStream = new FileWriter(file)) {
fileOutputStream.write(
Qute.fmt(loadTemplate())
.data("dependencies", licenseSummary.getDependencies())
.data("licenseFiles", licenseFiles)
.render());
} catch (IOException e) {
throw new LicensesGeneratorException("Failed to create licenses.html", e);
}
}

private static String loadTemplate() {
final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(LICENSES_QUTE);
if(is == null) {
throw new IllegalStateException("Failed to locate " + LICENSES_QUTE + " on the classpath");
}
try(BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
StringBuilder sb = new StringBuilder();
String line = reader.readLine();
while(line != null) {
sb.append(line).append(System.lineSeparator());
line = reader.readLine();
}
return sb.toString();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private Map<String, String> downloadLicenseFiles(List<DependencyElement> dependencies, String directoryPath) {
final File licenseContentsDirectory = new File(directoryPath, CONTENTS_DIR);
licenseContentsDirectory.mkdirs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@
<tr>
<th>Package Group</th><th>Package Artifact</th><th>Package Version</th><th>Remote Licenses</th><th>Local Licenses</th>
</tr>
{% for dependency in dependencies %}
{#for dependency in dependencies}
<tr>
<td>{{ dependency.getGroupId() }}</td>
<td>{{ dependency.getArtifactId() }}</td>
<td>{{ dependency.getVersion() }}</td>
<td>{dependency.groupId}</td>
<td>{dependency.artifactId}</td>
<td>{dependency.version}</td>
<td>
{% for license in dependency.getLicenses() %}
<a href="{{ license.getUrl() }}">{{ license.getName() }}</a>
{#for license in dependency.licenses}
<a href="{license.url}">{license.name}</a>
<br/>
{% endfor %}
{/for}
</td>
<td>
{% for license in dependency.getLicenses() %}
{% if licenseFiles.containsKey(license.getName()) %}
<a href="{{ licenseFiles.get(license.getName()) }}">{{ license.getName() }}</a>
{#for license in dependency.licenses}
{#if licenseFiles.containsKey(license.name)}
<a href="{licenseFiles.get(license.name)}">{license.name}</a>
<br/>
{% endif %}
{% endfor %}
{/if}
{/for}
</td>
</tr>
{% endfor %}
{/for}
</table>
</body>
</html>

0 comments on commit f3cb1eb

Please sign in to comment.