Skip to content

Commit

Permalink
Merge branch 'modularize' into equalsverifier-4
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Jan 20, 2025
2 parents d905b5e + 2a1faf4 commit 6763182
Show file tree
Hide file tree
Showing 26 changed files with 527 additions and 37 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,18 @@ To build EqualsVerifier, you need [Maven](https://maven.apache.org/). Just call

There are several Maven profiles that can be enabled or disabled:

| profile | activation | purpose |
| ---------------------- | ---------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `modules-jdk8` | JDK 8 up to but not including 11 | Build only the modules that are compatible with Java 8 and up. |
| `modules-jdk11` | JDK 11 up to but not including 16 | Build only the modules that are compatible with Java 11 and up. |
| `modules-jdk16` | JDK 16 | Build only the modules that are compatible with Java 16 and up. |
| `modules-jdk17` | JDK 17 and up | Build all modules and build releaseable artifacts. |
| `static-analysis` | JDK 17 and up, _and_ `disableStaticAnalysis` property must be off | Run static analysis checks. This only happens on a recent JDK. Can be disabled by running `mvn verify -DdisableStaticAnalysis` |
| `release-verification` | JDK 17 and up, _and_ `disableReleaseVerification` property must be off | Run release verification checks. This only happens on a recent JDK. Can be disabled by running `mvn verify -DdisableReleaseVerification` |
| `argline-preview` | `preview` property must be on | Enable Java preview features. Can be activated by running `mvn verify -Dpreview` |
| `argline-experimental` | `experimental` property must be on | Enables ByteBuddy experimental features; useful for testing EqualsVerifier on Early Access JDK builds. Can be activated by running `mvn verify -Dexperimental` |
| `pitest` | `pitest` property must be on | Used by PITest integration on GitHub. Can be activated by running `mvn verify -Dpitest` |
| profile | activation | purpose |
| ------------------------------ | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `modules-jdk11` | JDK 11 up to but not including 16 | Build only the modules that are compatible with Java 11 and up. |
| `modules-jdk16` | JDK 16 | Build only the modules that are compatible with Java 16 and up. |
| `modules-jdk17` | JDK 17 up to but not including 21 | Build only the modules that are compatible with Java 17 and up. |
| `modules-jdk21` | JDK 21 and up | Build all modules and build releaseable artifacts. |
| `modules-jdk21-without-pitest` | JDK 21 and up, but `pitest` property must be off | Run release verification checks (which are incompatible with PITest) |
| `static-analysis` | `disableStaticAnalysis` property must be off | Run static analysis checks. Can be disabled by running `mvn verify -DdisableStaticAnalysis` |
| `static-analysis-checkstyle` | `disableStaticAnalysis` property must be off | Used by the Checkstyle project for their regression tests - see ([Issue 586](https://github.com/jqno/equalsverifier/issues/586)) |
| `argline-preview` | `preview` property must be on | Enable Java preview features. Can be activated by running `mvn verify -Dpreview` |
| `argline-experimental` | `experimental` property must be on | Enables ByteBuddy experimental features; useful for testing EqualsVerifier on Early Access JDK builds. Can be activated by running `mvn verify -Dexperimental` |
| `pitest` | `pitest` property must be on | Used by PITest integration on GitHub. Can be activated by running `mvn verify -Dpitest` |

## Formatting

Expand All @@ -109,6 +110,7 @@ Here's a description of the modules:
| equalsverifier-release-main | release assembly for jar with dependencies |
| equalsverifier-release-nodep | release assembly for fat jar (with dependencies shaded in) |
| equalsverifier-release-verify | validation tests for the releases |
| equalsverifier-test-jpms | tests for the Java Platform Module System |
| equalsverifier-test-kotlin | tests for Kotlin classes |

## Signed JAR
Expand All @@ -129,8 +131,8 @@ The signed JAR itself can be found in [this repo](https://github.com/jqno/equals

To generate the website

- Using Docker: start the server by running `docker-compose up` or `docker compose run jekyll serve`.
- Using Jekyll: install the Ruby 3.x toolchain and run `bundle exec jekyll serve --watch`
- Using Docker: start the server by running `docker-compose up` or `docker compose run jekyll serve`.
- Using Jekyll: install the Ruby 3.x toolchain and run `bundle exec jekyll serve --watch`

Note that thepage uses the [TilburgsAns](https://www.tilburgsans.nl/) font but references it from the main site at [jqno.nl](https://jqno.nl). In development, it will fall back to a `sans-serif` font. See the font license [here](assets/tilburgsans/Ans%20Font%20License-AFL.pdf).

Expand Down
4 changes: 4 additions & 0 deletions build/checkstyle-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<property name="charset" value="UTF-8"/>
<property name="severity" value="error"/>

<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>

<module name="FileLength"/>
<module name="FileTabCharacter"/>
<module name="NewlineAtEndOfFile">
Expand Down
4 changes: 2 additions & 2 deletions docs/_manual/14-jpms.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ module my.module {
}
{% endhighlight %}

Note that the line `requires net.bytebuddy` is not necessary if you use the uberjar dependency `equalsverifier-nodep`.
Note that the line `requires net.bytebuddy` is not necessary (and in fact will give a compilation error) if you use the uberjar dependency `equalsverifier-nodep`.

Note that if you do this, and you have model classes or dependencies for model classes in other packages, you will have to open these packages as well, or provide prefab values for these dependencies:
Also note that if you do this, and you have model classes or dependencies for model classes in other packages, you will have to open these packages as well, or provide prefab values for these dependencies:

{% highlight java %}
import my.module.package.somewhere.inaccessible.Bar;
Expand Down
1 change: 1 addition & 0 deletions docs/_pages/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: Additional resources
permalink: /resources/
---
* [Javadoc](https://javadoc.io/doc/nl.jqno.equalsverifier/equalsverifier/latest/index.html)
* [FAQ](/equalsverifier/faq)
* [Changelog](https://github.com/jqno/equalsverifier/blob/main/CHANGELOG.md)
* Migration guides: [[2.x to 3.x](/equalsverifier/migration2to3)] [[1.x to 2.x](/equalsverifier/migration1to2)]
Expand Down
19 changes: 19 additions & 0 deletions equalsverifier-core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// When making changes to this file, make sure they are
// reflected in equalsverifier-release-nodep/../module-info.java!
module nl.jqno.equalsverifier {
exports nl.jqno.equalsverifier;
exports nl.jqno.equalsverifier.api;

// Direct dependencies
requires net.bytebuddy;
requires org.objenesis;

// Built-in prefab values
requires static com.google.common;
requires static java.desktop;
requires static java.naming;
requires static java.rmi;
requires static java.sql;
requires static javafx.base;
requires static org.joda.time;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package nl.jqno.equalsverifier.internal.reflection;

import static nl.jqno.equalsverifier.internal.reflection.Util.classForName;
import static nl.jqno.equalsverifier.internal.reflection.Util.classes;
import static nl.jqno.equalsverifier.internal.reflection.Util.objects;

import java.lang.invoke.MethodHandles;
import java.lang.reflect.Modifier;
Expand Down Expand Up @@ -121,19 +119,13 @@ private static String getPackageName(Class<?> type) {
}

private static <S> ClassLoadingStrategy<ClassLoader> getClassLoadingStrategy(Class<S> context) {
if (System.getProperty("java.version").startsWith("1.")) {
return ClassLoadingStrategy.Default.INJECTION.with(context.getProtectionDomain());
}
else {
ConditionalInstantiator ci = new ConditionalInstantiator("java.lang.invoke.MethodHandles$Lookup");
Object lookup = ci
.callFactory(
"java.lang.invoke.MethodHandles",
"privateLookupIn",
classes(Class.class, MethodHandles.Lookup.class),
objects(context, MethodHandles.lookup()));
try {
var lookup = MethodHandles.privateLookupIn(context, MethodHandles.lookup());
return ClassLoadingStrategy.UsingLookup.of(lookup);
}
catch (IllegalAccessException e) {
return ClassLoadingStrategy.Default.INJECTION.with(context.getProtectionDomain());
}
}

private static boolean isSystemClass(String className) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package nl.jqno.equalsverifier.integration.operational;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

public class ModuleTest {
@Test
void sanity() {
// We want the tests in this module to be run on the class path, not the module path.
assertThat(getClass().getModule().isNamed()).isFalse();
}
}
1 change: 0 additions & 1 deletion equalsverifier-release-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Automatic-Module-Name>nl.jqno.equalsverifier</Automatic-Module-Name>
<Multi-Release>true</Multi-Release>
<Implementation-Title>EqualsVerifier</Implementation-Title>
<Website>${project.url}</Website>
Expand Down
4 changes: 2 additions & 2 deletions equalsverifier-release-nodep/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>equalsverifier-parent</artifactId>
<version>3.18.2-SNAPSHOT</version>
</parent>
<packaging>pom</packaging>
<packaging>jar</packaging>

<artifactId>equalsverifier-nodep</artifactId>
<name>EqualsVerifier | release fat jar</name>
Expand All @@ -22,6 +22,7 @@
</scm>

<properties>
<maven.compiler.release>9</maven.compiler.release>
<maven.install.skip>false</maven.install.skip>
<maven.deploy.skip>false</maven.deploy.skip>

Expand Down Expand Up @@ -61,7 +62,6 @@
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Automatic-Module-Name>nl.jqno.equalsverifier</Automatic-Module-Name>
<Multi-Release>true</Multi-Release>
<Implementation-Title>EqualsVerifier (no dependencies)</Implementation-Title>
<Website>${project.url}</Website>
Expand Down
8 changes: 8 additions & 0 deletions equalsverifier-release-nodep/src/main/assembly/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
<componentDescriptors>
<componentDescriptor>assemblies/assembly.xml</componentDescriptor>
</componentDescriptors>
<files>
<file>
<!-- Override the existing module-info.class with the one from this module -->
<source>${project.build.outputDirectory}/module-info.class</source>
<outputDirectory>.</outputDirectory>
<destName>module-info.class</destName>
</file>
</files>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
Expand Down
13 changes: 13 additions & 0 deletions equalsverifier-release-nodep/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module nl.jqno.equalsverifier {
exports nl.jqno.equalsverifier;
exports nl.jqno.equalsverifier.api;

// Built-in prefab values
requires static com.google.common;
requires static java.desktop;
requires static java.naming;
requires static java.rmi;
requires static java.sql;
requires static javafx.base;
requires static org.joda.time;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package nl.jqno.equalsverifier;

// A file needs to exist in this package in order to be able to compile the module-info.java
public class Placeholder {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package nl.jqno.equalsverifier.api;

// A file needs to exist in this package in order to be able to compile the module-info.java
public class Placeholder {}
12 changes: 11 additions & 1 deletion equalsverifier-release-verify/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
<name>EqualsVerifier | release verify</name>

<properties>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.release>21</maven.compiler.release>

<artifact.src.main>${project.basedir}/../equalsverifier-release-main/target</artifact.src.main>
<artifact.src.nodep>${project.basedir}/../equalsverifier-release-nodep/target</artifact.src.nodep>
<artifact.src.core>${project.basedir}/../equalsverifier-core/target</artifact.src.core>
<artifact.dst>${project.basedir}/src/test/resources</artifact.dst>
</properties>

Expand Down Expand Up @@ -76,6 +77,10 @@
<sourceFile>${artifact.src.nodep}/equalsverifier-nodep-${project.version}-sources.jar</sourceFile>
<destinationFile>${artifact.dst}/equalsverifier-nodep-sources.jar</destinationFile>
</fileSet>
<fileSet>
<sourceFile>${artifact.src.core}/equalsverifier-core-${project.version}.jar</sourceFile>
<destinationFile>${artifact.dst}/equalsverifier-core.jar</destinationFile>
</fileSet>
</fileSets>
</configuration>
</execution>
Expand Down Expand Up @@ -108,6 +113,11 @@
<version>${version.assertj}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${version.bytebuddy}</version>
</dependency>
</dependencies>
</profile>
</profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package nl.jqno.equalsverifier.verify_release.jar;

import static org.assertj.core.api.Assertions.assertThat;

import nl.jqno.equalsverifier.verify_release.jar.helper.JarAsserter;
import nl.jqno.equalsverifier.verify_release.jar.helper.JarReader;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -47,4 +49,18 @@ void contentOfManifest() {
void versionsOfClassFiles() {
jar.assertVersionsOfClassFiles();
}

@Test
void presenceOfModuleInfoWithDependencies() {
jar.assertModuleInfoWithDependencies();
}

@Test
void moduleInfoIsIdenticalToCore() throws Exception {
try (var coreReader = new JarReader("equalsverifier-core.jar")) {
var coreModuleinfo = coreReader.getContentOf("module-info.class");
var mainModuleinfo = reader.getContentOf("module-info.class");
assertThat(mainModuleinfo).containsExactly(coreModuleinfo);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ static void clean() throws Exception {
}

@Test
void presenceOfCoreSources() {
jar.assertPresenceOf("/index.html", EV + "/EqualsVerifier.html");
void presenceOfCoreFiles() {
jar.assertPresenceOf("/index.html", "/nl.jqno.equalsverifier" + EV + "/EqualsVerifier.html");
}

@Test
void absenceOfNonExportedPackages() {
jar.assertAbsenceOf("/nl.jqno.equalsverifier" + EV + "/internal");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ void versionsOfClassFiles() {
void versionsOfEmbeddedDependencies() {
jar.assertVersionsOfEmbeddedClassFiles();
}

@Test
void presenceOfModuleInfoWithoutDependencies() {
jar.assertModuleInfoWithoutDependencies();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ static void clean() throws Exception {
}

@Test
void presenceOfCoreSources() {
jar.assertPresenceOf("/index.html", EV + "/EqualsVerifier.html");
void presenceOfCoreFiles() {
jar.assertPresenceOf("/index.html", "/nl.jqno.equalsverifier" + EV + "/EqualsVerifier.html");
}

@Test
void absenceOfNonExportedPackages() {
jar.assertAbsenceOf("/nl.jqno.equalsverifier" + EV + "/internal");
}
}
Loading

0 comments on commit 6763182

Please sign in to comment.