Skip to content

Commit

Permalink
chore: Ensure LICENSE file is present in Jar
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Solórzano <[email protected]>
  • Loading branch information
jorsol committed Apr 10, 2024
1 parent 394e1fe commit 725e208
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
13 changes: 12 additions & 1 deletion checks/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<FindBugsFilter
xmlns="https://github.com/spotbugs/filter/3.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/4.3.0/spotbugs/etc/findbugsfilter.xsd">
<!-- Ignore spotbugs reports from generated sources -->
<Match>
<Package name="~.*\.generated\..*" />
Expand All @@ -17,4 +20,12 @@
<Match>
<Bug pattern="IMPROPER_UNICODE" />
</Match>

<Match>
<Bug pattern="EI_EXPOSE_REP" />
</Match>

<Match>
<Bug pattern="CT_CONSTRUCTOR_THROW" />
</Match>
</FindBugsFilter>
71 changes: 71 additions & 0 deletions nameprep/src/test/java/test/nameprep/JarFileCheckIT.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
33 changes: 33 additions & 0 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<release>11</release>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -232,6 +241,27 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${resources-plugin.version}</version>
<executions>
<execution>
<id>add-license</id>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<outputDirectory>${project.build.outputDirectory}/META-INF</outputDirectory>
<resources>
<resource>
<directory>${maven.multiModuleProjectDirectory}</directory>
<includes>
<include>LICENSE</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -249,6 +279,9 @@
<include>**/*Test.java</include>
<include>**/*IT.java</include>
</includes>
<systemPropertyVariables>
<buildJar>${project.build.directory}/${project.build.finalName}.jar</buildJar>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
Expand Down
71 changes: 71 additions & 0 deletions saslprep/src/test/java/test/saslprep/JarFileCheckIT.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
71 changes: 71 additions & 0 deletions stringprep/src/test/java/test/stringprep/JarFileCheckIT.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 725e208

Please sign in to comment.