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 <jorsol@gmail.com>
  • Loading branch information
jorsol committed Apr 10, 2024
1 parent 07192ff commit 9a38829
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 4 deletions.
3 changes: 3 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.

## 3.0 - 2024-04-03
### :boom: Breaking changes
Expand All @@ -24,6 +26,7 @@ All notable changes to this project will be documented in this file.

### :ghost: Maintenance
- Migrate the main repo back to GitHub.
- Remove the shaded Bouncy Castle pbkdf2 and base64 implementation used for Java 7 support.

# 2.1

Expand Down
22 changes: 18 additions & 4 deletions scram-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,25 @@
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>run-its</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
71 changes: 71 additions & 0 deletions scram-client/src/test/java/com/ongres/scram/JarFileCheckIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2017 OnGres, Inc.
* SPDX-License-Identifier: BSD-2-Clause
*/

package com.ongres.scram;

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) 2017 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.scram.client", moduleDescriptor.name());
}
}
18 changes: 18 additions & 0 deletions scram-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,22 @@
</plugins>
</build>

<profiles>
<profile>
<id>run-its</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
71 changes: 71 additions & 0 deletions scram-common/src/test/java/com/ongres/scram/JarFileCheckIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2017 OnGres, Inc.
* SPDX-License-Identifier: BSD-2-Clause
*/

package com.ongres.scram;

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) 2017 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.scram.common", moduleDescriptor.name());
}
}
12 changes: 12 additions & 0 deletions scram-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,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 @@ -298,6 +307,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

0 comments on commit 9a38829

Please sign in to comment.