From 725e208ecde51b0137f8f9a7518e0fcb7f8fd467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Wed, 10 Apr 2024 17:22:10 +0200 Subject: [PATCH] chore: Ensure LICENSE file is present in Jar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- CHANGELOG.md | 2 + LICENSE | 2 +- checks/spotbugs-exclude.xml | 13 +++- .../java/test/nameprep/JarFileCheckIT.java | 71 +++++++++++++++++++ parent/pom.xml | 33 +++++++++ .../java/test/saslprep/JarFileCheckIT.java | 71 +++++++++++++++++++ .../java/test/stringprep/JarFileCheckIT.java | 71 +++++++++++++++++++ 7 files changed, 261 insertions(+), 2 deletions(-) create mode 100644 nameprep/src/test/java/test/nameprep/JarFileCheckIT.java create mode 100644 saslprep/src/test/java/test/saslprep/JarFileCheckIT.java create mode 100644 stringprep/src/test/java/test/stringprep/JarFileCheckIT.java diff --git a/CHANGELOG.md b/CHANGELOG.md index d0c0a3a..369bab2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### :building_construction: Improvements +- Ensure the LICENSE file is included in the Jar file. ## [2.1] - 2024-04-01 ### :bug: Bug Fixes diff --git a/LICENSE b/LICENSE index 809c9ff..d816533 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2019, OnGres, Inc. +Copyright (c) 2019 OnGres, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/checks/spotbugs-exclude.xml b/checks/spotbugs-exclude.xml index 708a899..cab6350 100644 --- a/checks/spotbugs-exclude.xml +++ b/checks/spotbugs-exclude.xml @@ -1,5 +1,8 @@ - + @@ -17,4 +20,12 @@ + + + + + + + + \ No newline at end of file diff --git a/nameprep/src/test/java/test/nameprep/JarFileCheckIT.java b/nameprep/src/test/java/test/nameprep/JarFileCheckIT.java new file mode 100644 index 0000000..1c63638 --- /dev/null +++ b/nameprep/src/test/java/test/nameprep/JarFileCheckIT.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2019 OnGres, Inc. + * SPDX-License-Identifier: BSD-2-Clause + */ + +package test.nameprep; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.module.ModuleDescriptor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.jar.Attributes; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +class JarFileCheckIT { + + private static JarFile jarFile; + private static Path buildJarPath; + + @BeforeAll + static void beforeAll() throws IOException { + buildJarPath = Paths.get(System.getProperty("buildJar")); + assertTrue(Files.exists(buildJarPath)); + jarFile = new JarFile(buildJarPath.toFile(), true); + } + + @AfterAll + static void afterAll() throws IOException { + jarFile.close(); + } + + @Test + void checkLicense() throws IOException { + JarEntry jarLicense = jarFile.getJarEntry("META-INF/LICENSE"); + assertNotNull(jarLicense, "LICENSE file should be present in the final JAR file"); + try (InputStream is = jarFile.getInputStream(jarLicense); + BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { + String line = reader.readLine(); + assertEquals("Copyright (c) 2019 OnGres, Inc.", line); + } + } + + @Test + void checkMultiReleaseManifest() throws IOException { + Attributes mainAttributes = jarFile.getManifest().getMainAttributes(); + String multiReleaseValue = mainAttributes.getValue(new Attributes.Name("Multi-Release")); + assertNotNull(multiReleaseValue); + assertEquals("true", multiReleaseValue); + } + + @Test + void checkModuleInfoPresent() throws IOException { + JarEntry jarModuleInfo = jarFile.getJarEntry("META-INF/versions/9/module-info.class"); + ModuleDescriptor moduleDescriptor = ModuleDescriptor.read(jarFile.getInputStream(jarModuleInfo)); + assertNotNull(moduleDescriptor); + assertEquals("com.ongres.nameprep", moduleDescriptor.name()); + } +} diff --git a/parent/pom.xml b/parent/pom.xml index 12b3c2b..3b46ba4 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -161,6 +161,15 @@ true + + default-testCompile + + testCompile + + + 11 + + @@ -232,6 +241,27 @@ org.apache.maven.plugins maven-resources-plugin ${resources-plugin.version} + + + add-license + + copy-resources + + generate-resources + + ${project.build.outputDirectory}/META-INF + + + ${maven.multiModuleProjectDirectory} + + LICENSE + + false + + + + + org.apache.maven.plugins @@ -249,6 +279,9 @@ **/*Test.java **/*IT.java + + ${project.build.directory}/${project.build.finalName}.jar + diff --git a/saslprep/src/test/java/test/saslprep/JarFileCheckIT.java b/saslprep/src/test/java/test/saslprep/JarFileCheckIT.java new file mode 100644 index 0000000..2fcbbef --- /dev/null +++ b/saslprep/src/test/java/test/saslprep/JarFileCheckIT.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2019 OnGres, Inc. + * SPDX-License-Identifier: BSD-2-Clause + */ + +package test.saslprep; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.module.ModuleDescriptor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.jar.Attributes; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +class JarFileCheckIT { + + private static JarFile jarFile; + private static Path buildJarPath; + + @BeforeAll + static void beforeAll() throws IOException { + buildJarPath = Paths.get(System.getProperty("buildJar")); + assertTrue(Files.exists(buildJarPath)); + jarFile = new JarFile(buildJarPath.toFile(), true); + } + + @AfterAll + static void afterAll() throws IOException { + jarFile.close(); + } + + @Test + void checkLicense() throws IOException { + JarEntry jarLicense = jarFile.getJarEntry("META-INF/LICENSE"); + assertNotNull(jarLicense, "LICENSE file should be present in the final JAR file"); + try (InputStream is = jarFile.getInputStream(jarLicense); + BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { + String line = reader.readLine(); + assertEquals("Copyright (c) 2019 OnGres, Inc.", line); + } + } + + @Test + void checkMultiReleaseManifest() throws IOException { + Attributes mainAttributes = jarFile.getManifest().getMainAttributes(); + String multiReleaseValue = mainAttributes.getValue(new Attributes.Name("Multi-Release")); + assertNotNull(multiReleaseValue); + assertEquals("true", multiReleaseValue); + } + + @Test + void checkModuleInfoPresent() throws IOException { + JarEntry jarModuleInfo = jarFile.getJarEntry("META-INF/versions/9/module-info.class"); + ModuleDescriptor moduleDescriptor = ModuleDescriptor.read(jarFile.getInputStream(jarModuleInfo)); + assertNotNull(moduleDescriptor); + assertEquals("com.ongres.saslprep", moduleDescriptor.name()); + } +} diff --git a/stringprep/src/test/java/test/stringprep/JarFileCheckIT.java b/stringprep/src/test/java/test/stringprep/JarFileCheckIT.java new file mode 100644 index 0000000..0edee66 --- /dev/null +++ b/stringprep/src/test/java/test/stringprep/JarFileCheckIT.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2019 OnGres, Inc. + * SPDX-License-Identifier: BSD-2-Clause + */ + +package test.stringprep; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.module.ModuleDescriptor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.jar.Attributes; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +class JarFileCheckIT { + + private static JarFile jarFile; + private static Path buildJarPath; + + @BeforeAll + static void beforeAll() throws IOException { + buildJarPath = Paths.get(System.getProperty("buildJar")); + assertTrue(Files.exists(buildJarPath)); + jarFile = new JarFile(buildJarPath.toFile(), true); + } + + @AfterAll + static void afterAll() throws IOException { + jarFile.close(); + } + + @Test + void checkLicense() throws IOException { + JarEntry jarLicense = jarFile.getJarEntry("META-INF/LICENSE"); + assertNotNull(jarLicense, "LICENSE file should be present in the final JAR file"); + try (InputStream is = jarFile.getInputStream(jarLicense); + BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { + String line = reader.readLine(); + assertEquals("Copyright (c) 2019 OnGres, Inc.", line); + } + } + + @Test + void checkMultiReleaseManifest() throws IOException { + Attributes mainAttributes = jarFile.getManifest().getMainAttributes(); + String multiReleaseValue = mainAttributes.getValue(new Attributes.Name("Multi-Release")); + assertNotNull(multiReleaseValue); + assertEquals("true", multiReleaseValue); + } + + @Test + void checkModuleInfoPresent() throws IOException { + JarEntry jarModuleInfo = jarFile.getJarEntry("META-INF/versions/9/module-info.class"); + ModuleDescriptor moduleDescriptor = ModuleDescriptor.read(jarFile.getInputStream(jarModuleInfo)); + assertNotNull(moduleDescriptor); + assertEquals("com.ongres.stringprep", moduleDescriptor.name()); + } +}