Skip to content

Commit

Permalink
Put module-info.class into Multi-Release JAR folder
Browse files Browse the repository at this point in the history
Uses ModiTect to place module-info.class under Multi-Release JAR folder
`META-INF/versions/9`.
  • Loading branch information
Marcono1234 committed Nov 8, 2021
1 parent ca2ed74 commit 2d656a1
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 60 deletions.
50 changes: 28 additions & 22 deletions gson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,48 @@
<executions>
<execution>
<id>default-compile</id>
<configuration>
<jdkToolchain>
<version>9</version>
</jdkToolchain>
<release>9</release>
</configuration>
</execution>
<execution>
<id>base-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<excludes>
<!-- module-info.java is compiled using ModiTect -->
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
<configuration>
<jdkToolchain>
<version>[1.5,9)</version>
</jdkToolchain>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- Note: Javadoc plugin has to be run in combination with >= `package`
phase, e.g. `mvn package javadoc:javadoc`, otherwise it fails with
"Aggregator report contains named and unnamed modules" -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<excludePackageNames>com.google.gson.internal:com.google.gson.internal.bind</excludePackageNames>
<links>
<link>https://docs.oracle.com/javase/6/docs/api/</link>
</links>
</configuration>
</plugin>
<!-- Add module-info to JAR, see https://github.com/moditect/moditect#adding-module-descriptors-to-existing-jar-files -->
<!-- Uses ModiTect instead of separate maven-compiler-plugin executions
for better Eclipse IDE support, see https://github.com/eclipse-m2e/m2e-core/issues/393 -->
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>1.0.0.RC2</version>
<executions>
<execution>
<id>add-module-info</id>
<phase>package</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<jvmVersion>9</jvmVersion>
<module>
<moduleInfoFile>${project.build.sourceDirectory}/module-info.java</moduleInfoFile>
</module>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
Expand All @@ -91,6 +96,7 @@
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<!-- Use existing manifest generated by BND plugin -->
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void setUp() {
.registerTypeAdapter(Id.class, new IdTreeTypeAdapter())
.create();
course = new Course<HistoryCourse>(COURSE_ID, 4,
new Assignment<HistoryCourse>(null, null), createList(STUDENT1, STUDENT2));
new Assignment<HistoryCourse>(null, null), Arrays.asList(STUDENT1, STUDENT2));
}

public void testSerializeId() {
Expand Down Expand Up @@ -171,9 +171,4 @@ public Assignment(Id<Assignment<T>> id, T data) {
private static class HistoryCourse {
int numClasses;
}

@SafeVarargs
private static <T> List<T> createList(T ...items) {
return Arrays.asList(items);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public void testJavaSerialization() throws IOException, ClassNotFoundException {
assertEquals(Collections.singletonMap("a", 1), deserialized);
}

@SafeVarargs
private <T> void assertIterationOrder(Iterable<T> actual, T... expected) {
ArrayList<T> actualList = new ArrayList<T>();
for (T t : actual) {
Expand Down
55 changes: 29 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.6</java.version>
<javaVersion>6</javaVersion>
</properties>

<scm>
Expand Down Expand Up @@ -68,23 +68,45 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>${javaVersion}</release>
<jdkToolchain>
<!-- Require at most JDK 11 because it is the last version
supporting compiling Java 1.6, see https://bugs.openjdk.java.net/browse/JDK-8028563 -->
<!-- When Gson increases lowest supported Java version, can
change this to an open version range (e.g. `[11,)`) -->
<version>[9,11]</version>
</jdkToolchain>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<jdkToolchain>
<version>[11,)</version>
</jdkToolchain>
<doclint>none</doclint>
<!-- Link against newer Java API Javadoc because most users likely
use a newer Java version than the one used for building this project -->
<detectJavaApiLink>false</detectJavaApiLink>
<links>
<link>https://docs.oracle.com/en/java/javase/11/docs/api/</link>
</links>
<!-- Disable detection of offline links between Maven modules:
(1) Only `gson` module is published, so for other modules Javadoc links don't
matter much at the moment; (2) The derived URL for the modules is based on
the project URL (= Gson GitHub repo) which is incorrect because it is not
hosting the Javadoc (3) It might fail due to https://bugs.openjdk.java.net/browse/JDK-8212233 -->
<detectOfflineLinks>false</detectOfflineLinks>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.2</version>
<inherited>true</inherited>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand All @@ -110,23 +132,4 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>doclint-java8-disable</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.google.protobuf.DynamicMessage;
import com.google.protobuf.Extension;
import com.google.protobuf.Message;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -192,7 +191,7 @@ public static Builder newBuilder() {
private static final com.google.protobuf.Descriptors.FieldDescriptor.Type ENUM_TYPE =
com.google.protobuf.Descriptors.FieldDescriptor.Type.ENUM;

private static final ConcurrentMap<String, Map<Class<?>, Method>> mapOfMapOfMethods =
private static final ConcurrentMap<String, ConcurrentMap<Class<?>, Method>> mapOfMapOfMethods =
new MapMaker().makeMap();

private final EnumSerialization enumSerialization;
Expand Down Expand Up @@ -309,7 +308,7 @@ public Message deserialize(JsonElement json, Type typeOfT,
}
}
}
return (Message) protoBuilder.build();
return protoBuilder.build();
} catch (SecurityException e) {
throw new JsonParseException(e);
} catch (NoSuchMethodException e) {
Expand Down Expand Up @@ -397,10 +396,10 @@ private EnumValueDescriptor findValueByNameAndExtension(EnumDescriptor desc,

private static Method getCachedMethod(Class<?> clazz, String methodName,
Class<?>... methodParamTypes) throws NoSuchMethodException {
Map<Class<?>, Method> mapOfMethods = mapOfMapOfMethods.get(methodName);
ConcurrentMap<Class<?>, Method> mapOfMethods = mapOfMapOfMethods.get(methodName);
if (mapOfMethods == null) {
mapOfMethods = new MapMaker().makeMap();
Map<Class<?>, Method> previous =
ConcurrentMap<Class<?>, Method> previous =
mapOfMapOfMethods.putIfAbsent(methodName, mapOfMethods);
mapOfMethods = previous == null ? mapOfMethods : previous;
}
Expand Down

0 comments on commit 2d656a1

Please sign in to comment.