diff --git a/pom.xml b/pom.xml index 36772ff..60fd254 100644 --- a/pom.xml +++ b/pom.xml @@ -50,10 +50,13 @@ 2.7 2.3.1 1.1.4 - 5.87.0.RELEASE 4.12 + 3.9.6 3.15 + 1.9.18 + 3.5.3 3.11.0 + 2.16.12.Final 4.5.12.Final 1.7.30 2.2.8.Final @@ -100,17 +103,11 @@ - + - org.jtwig - jtwig-core - ${jtwig.version} - - - com.google.guava - guava - - + io.quarkus.qute + qute-core + ${qute.version} @@ -130,17 +127,108 @@ javax.annotation jsr250-api + + org.apache.maven + * + + + + + org.apache.maven + maven-artifact + ${maven-core.version} + + + org.apache.maven + maven-compat + ${maven-core.version} + + + org.apache.maven + maven-core + ${maven-core.version} + + + org.checkerframework + checker-qual + + + org.slf4j + slf4j-api + + + + + org.apache.maven + maven-embedder + ${maven-core.version} + + + org.slf4j + slf4j-api + + + + org.codehaus.plexus + plexus-utils + + + org.checkerframework + checker-qual + + + + + org.apache.maven.resolver + maven-resolver-connector-basic + ${maven-resolver.version} + + + org.slf4j + slf4j-api + + + + + org.apache.maven.resolver + maven-resolver-transport-wagon + ${maven-resolver.version} + + + org.slf4j + slf4j-api + + + org.apache.maven.resolver + maven-resolver-api + ${maven-resolver.version} + + + org.apache.maven.resolver + maven-resolver-spi + ${maven-resolver.version} + + + org.apache.maven.resolver + maven-resolver-impl + ${maven-resolver.version} + + + org.apache.maven.resolver + maven-resolver-util + ${maven-resolver.version} + org.apache.maven.wagon wagon-file - 3.3.2 + ${maven-wagon.version} org.apache.maven.wagon wagon-http - 3.3.2 + ${maven-wagon.version} org.slf4j @@ -271,8 +359,8 @@ maven-compiler-plugin ${maven-compiler-plugin.version} - 1.8 - 1.8 + 11 + 11 diff --git a/src/main/java/me/snowdrop/licenses/LicensesFileManager.java b/src/main/java/me/snowdrop/licenses/LicensesFileManager.java index 7fa25a2..1ee0329 100644 --- a/src/main/java/me/snowdrop/licenses/LicensesFileManager.java +++ b/src/main/java/me/snowdrop/licenses/LicensesFileManager.java @@ -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; @@ -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; @@ -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); @@ -96,18 +101,36 @@ public void createLicensesHtml(LicenseSummary licenseSummary, String directoryPa Map 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 downloadLicenseFiles(List dependencies, String directoryPath) { final File licenseContentsDirectory = new File(directoryPath, CONTENTS_DIR); licenseContentsDirectory.mkdirs(); diff --git a/src/main/resources/licenses.twig b/src/main/resources/licenses.qute similarity index 57% rename from src/main/resources/licenses.twig rename to src/main/resources/licenses.qute index 0e5d346..6f37409 100644 --- a/src/main/resources/licenses.twig +++ b/src/main/resources/licenses.qute @@ -31,27 +31,27 @@ Package GroupPackage ArtifactPackage VersionRemote LicensesLocal Licenses - {% for dependency in dependencies %} + {#for dependency in dependencies} - {{ dependency.getGroupId() }} - {{ dependency.getArtifactId() }} - {{ dependency.getVersion() }} + {dependency.groupId} + {dependency.artifactId} + {dependency.version} - {% for license in dependency.getLicenses() %} - {{ license.getName() }} + {#for license in dependency.licenses} + {license.name}
- {% endfor %} + {/for} - {% for license in dependency.getLicenses() %} - {% if licenseFiles.containsKey(license.getName()) %} - {{ license.getName() }} + {#for license in dependency.licenses} + {#if licenseFiles.containsKey(license.name)} + {license.name}
- {% endif %} - {% endfor %} + {/if} + {/for} - {% endfor %} + {/for}