From 9058f99dfda4ee65e5dddf91fdde632c33e29312 Mon Sep 17 00:00:00 2001
From: Benjamin Marwell <bmarwell@apache.org>
Date: Tue, 19 Apr 2022 22:04:44 +0200
Subject: [PATCH] [#519] Add moditect-generated module-info.java files and a
 simple IT.

- uses lots of more profiles
- requires Java 8+ for a release
- requires Java 9+ for running the integration test
- does not deploy integration tests
- maven.compiler.release is set instead of source and target for Java9+
- maven.compiler.source/target is now only set on Java7 and Java8 so the javadoc and sources plugin will work correctly.
- Does not contain ITs for neither GSON nor org.json.
- Ugly workaround for the fact that the old bundle-plugin crashes on Java9+ module-info.java files,
  had to provide an empty static MANIFEST.MF file and disable the bundle-plugin on ITs.
- I found it odd that the extensions do not reference their correct parent pom as parent pom, instead the root is chosen.
  This is probably a maven anti-pattern and was corrected by khmarbaise for Shiro.
- parentLocation = ../pom.xml is redundant for /api and /impl, but did not bother to correct it here
- some pom.xml files were missing a final line break as required by unix spec.
---
 api/pom.xml                                   | 39 ++++++++++-
 extensions/gson/pom.xml                       | 35 +++++++++-
 extensions/jackson/pom.xml                    | 35 +++++++++-
 extensions/orgjson/pom.xml                    | 35 +++++++++-
 impl/pom.xml                                  | 42 ++++++++++-
 integration-tests/pom.xml                     | 25 +++++++
 integration-tests/unsigned-jackson/pom.xml    | 70 +++++++++++++++++++
 .../it/unsigned/UnsignedJwtCreator.java       | 32 +++++++++
 .../src/main/java/module-info.java            |  4 ++
 .../src/main/resources/META-INF/MANIFEST.MF   |  0
 .../it/unsigned/UnsignedJwtCreatorTest.java   | 31 ++++++++
 pom.xml                                       | 11 ++-
 12 files changed, 352 insertions(+), 7 deletions(-)
 create mode 100644 integration-tests/pom.xml
 create mode 100644 integration-tests/unsigned-jackson/pom.xml
 create mode 100644 integration-tests/unsigned-jackson/src/main/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreator.java
 create mode 100644 integration-tests/unsigned-jackson/src/main/java/module-info.java
 create mode 100644 integration-tests/unsigned-jackson/src/main/resources/META-INF/MANIFEST.MF
 create mode 100644 integration-tests/unsigned-jackson/src/test/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreatorTest.java

diff --git a/api/pom.xml b/api/pom.xml
index fac58aa6e..156d0b319 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -50,4 +50,41 @@
         </plugins>
     </build>
 
-</project>
\ No newline at end of file
+    <profiles>
+        <profile>
+            <id>nonJDK7</id>
+            <activation>
+                <jdk>[1.8,)</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.moditect</groupId>
+                        <artifactId>moditect-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>add-module-infos</id>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>add-module-info</goal>
+                                </goals>
+                                <configuration>
+                                    <module>
+                                        <moduleInfo>
+                                            <name>io.jsonwebtoken.jjwt.api</name>
+                                            <exports>
+                                                io.jsonwebtoken;
+                                                io.jsonwebtoken.*;
+                                            </exports>
+                                        </moduleInfo>
+                                    </module>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>
diff --git a/extensions/gson/pom.xml b/extensions/gson/pom.xml
index 35e458e27..1677ab9bf 100644
--- a/extensions/gson/pom.xml
+++ b/extensions/gson/pom.xml
@@ -53,4 +53,37 @@
         </plugins>
     </build>
 
-</project>
\ No newline at end of file
+    <profiles>
+        <profile>
+            <id>nonJDK7</id>
+            <activation>
+                <jdk>[1.8,)</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.moditect</groupId>
+                        <artifactId>moditect-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>add-module-infos</id>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>add-module-info</goal>
+                                </goals>
+                                <configuration>
+                                    <module>
+                                        <moduleInfo>
+                                            <name>io.jsonwebtoken.jjwt.ext.gson</name>
+                                        </moduleInfo>
+                                    </module>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>
diff --git a/extensions/jackson/pom.xml b/extensions/jackson/pom.xml
index 469789f61..dcfa00fea 100644
--- a/extensions/jackson/pom.xml
+++ b/extensions/jackson/pom.xml
@@ -69,4 +69,37 @@
             </plugin>
         </plugins>
     </build>
-</project>
\ No newline at end of file
+
+    <profiles>
+        <profile>
+            <id>nonJDK7</id>
+            <activation>
+                <jdk>[1.8,)</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.moditect</groupId>
+                        <artifactId>moditect-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>add-module-infos</id>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>add-module-info</goal>
+                                </goals>
+                                <configuration>
+                                    <module>
+                                        <moduleInfo>
+                                            <name>io.jsonwebtoken.jjwt.ext.jackson</name>
+                                        </moduleInfo>
+                                    </module>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+</project>
diff --git a/extensions/orgjson/pom.xml b/extensions/orgjson/pom.xml
index 5d9da307f..da6bd1e76 100644
--- a/extensions/orgjson/pom.xml
+++ b/extensions/orgjson/pom.xml
@@ -69,4 +69,37 @@
             </plugin>
         </plugins>
     </build>
-</project>
\ No newline at end of file
+
+    <profiles>
+        <profile>
+            <id>nonJDK7</id>
+            <activation>
+                <jdk>[1.8,)</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.moditect</groupId>
+                        <artifactId>moditect-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>add-module-infos</id>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>add-module-info</goal>
+                                </goals>
+                                <configuration>
+                                    <module>
+                                        <moduleInfo>
+                                            <name>io.jsonwebtoken.jjwt.ext.orgjson</name>
+                                        </moduleInfo>
+                                    </module>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+</project>
diff --git a/impl/pom.xml b/impl/pom.xml
index 4d10f5581..b2980da7b 100644
--- a/impl/pom.xml
+++ b/impl/pom.xml
@@ -68,4 +68,44 @@
         </dependency>
     </dependencies>
 
-</project>
\ No newline at end of file
+    <profiles>
+        <profile>
+            <id>nonJDK7</id>
+            <activation>
+                <jdk>[1.8,)</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.moditect</groupId>
+                        <artifactId>moditect-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>add-module-infos</id>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>add-module-info</goal>
+                                </goals>
+                                <configuration>
+                                    <module>
+                                        <moduleInfo>
+                                            <name>io.jsonwebtoken.jjwt.impl</name>
+                                            <requires>
+                                                io.jsonwebtoken.jjwt.api;
+                                            </requires>
+                                            <uses>
+                                                io.jsonwebtoken.CompressionCodec;
+                                                io.jsonwebtoken.io.Deserializer;
+                                                io.jsonwebtoken.io.Serializer;
+                                            </uses>
+                                        </moduleInfo>
+                                    </module>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+</project>
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
new file mode 100644
index 000000000..e41ba0562
--- /dev/null
+++ b/integration-tests/pom.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>io.jsonwebtoken</groupId>
+        <artifactId>jjwt-root</artifactId>
+        <version>0.11.3-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>jjwt-integration-tests</artifactId>
+    <name>JJWT :: Integration-Tests</name>
+    <packaging>pom</packaging>
+
+    <properties>
+        <maven.deploy.skip>true</maven.deploy.skip>
+    </properties>
+
+    <modules>
+        <module>unsigned-jackson</module>
+    </modules>
+    
+</project>
diff --git a/integration-tests/unsigned-jackson/pom.xml b/integration-tests/unsigned-jackson/pom.xml
new file mode 100644
index 000000000..b69f264cf
--- /dev/null
+++ b/integration-tests/unsigned-jackson/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>io.jsonwebtoken</groupId>
+        <artifactId>jjwt-integration-tests</artifactId>
+        <version>0.11.3-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>jjwt-integration-tests-unsigned-jackson</artifactId>
+    <name>JJWT :: Integration-Tests :: unsigned-jackson</name>
+    <description>Create and parse an unsigned JWT using Jackson and JPMS.</description>
+    <packaging>jar</packaging>
+
+    <properties>
+        <maven.compiler.release>9</maven.compiler.release>
+        <maven.deploy.skip>true</maven.deploy.skip>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>io.jsonwebtoken</groupId>
+            <artifactId>jjwt-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.jsonwebtoken</groupId>
+            <artifactId>jjwt-impl</artifactId>
+            <version>0.11.3-SNAPSHOT</version>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.jsonwebtoken</groupId>
+            <artifactId>jjwt-jackson</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-javadoc-plugin</artifactId>
+                <configuration>
+                    <skip>true</skip>
+                    <detectJavaApiLink>false</detectJavaApiLink>
+                </configuration>
+            </plugin>
+            <!--
+                this plugin needs to be disabled as long as we are stuck with plugin version 3.3.0, as it cannot
+                handle Java 9 module-info.class files.
+                This will also use an empty MANIFEST.MF file, since there is no way in maven to unsetting
+                an entry (like archive/manifestFile for the jar plugin).
+            -->
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>bundle-manifest</id>
+                        <phase>none</phase>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+    
+</project>
diff --git a/integration-tests/unsigned-jackson/src/main/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreator.java b/integration-tests/unsigned-jackson/src/main/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreator.java
new file mode 100644
index 000000000..6f3740f15
--- /dev/null
+++ b/integration-tests/unsigned-jackson/src/main/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreator.java
@@ -0,0 +1,32 @@
+package io.jsonwebtoken.it.unsigned;
+
+import io.jsonwebtoken.*;
+
+import java.time.Instant;
+import java.util.Date;
+import java.util.List;
+
+public class UnsignedJwtCreator {
+
+    public UnsignedJwtCreator() {
+        // explicit
+    }
+
+    public String create() {
+        return Jwts.builder()
+                .claim("roles", List.of("admin"))
+                .setSubject("jjwt")
+                .setId("jjwt-0")
+                .setIssuedAt(Date.from(Instant.now()))
+                .setNotBefore(Date.from(Instant.now()))
+                .compact();
+    }
+
+    public Jwt<Header, Claims> read(String jwt) {
+        final JwtParser jwtParser = Jwts.parserBuilder()
+                .requireSubject("jjwt")
+                .build();
+
+        return jwtParser.parseClaimsJwt(jwt);
+    }
+}
diff --git a/integration-tests/unsigned-jackson/src/main/java/module-info.java b/integration-tests/unsigned-jackson/src/main/java/module-info.java
new file mode 100644
index 000000000..71d5b72a0
--- /dev/null
+++ b/integration-tests/unsigned-jackson/src/main/java/module-info.java
@@ -0,0 +1,4 @@
+module io.jsonwebtoken.jjwt.it.unsigned {
+    requires io.jsonwebtoken.jjwt.api;
+
+}
diff --git a/integration-tests/unsigned-jackson/src/main/resources/META-INF/MANIFEST.MF b/integration-tests/unsigned-jackson/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..e69de29bb
diff --git a/integration-tests/unsigned-jackson/src/test/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreatorTest.java b/integration-tests/unsigned-jackson/src/test/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreatorTest.java
new file mode 100644
index 000000000..a651c4b43
--- /dev/null
+++ b/integration-tests/unsigned-jackson/src/test/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreatorTest.java
@@ -0,0 +1,31 @@
+package io.jsonwebtoken.it.unsigned;
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.Header;
+import io.jsonwebtoken.Jwt;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+
+public class UnsignedJwtCreatorTest {
+
+    @Test
+    public void testUnsignedJwt() {
+        // given:
+        final UnsignedJwtCreator jwtCreator = new UnsignedJwtCreator();
+        final String jwtString = jwtCreator.create();
+
+        // when
+        final Jwt<Header, Claims> readBackJwt = jwtCreator.read(jwtString);
+
+        // then
+        final Claims jwtBody = readBackJwt.getBody();
+        assertEquals("jjwt-0", jwtBody.getId());
+        assertEquals("jjwt", jwtBody.getSubject());
+        assertTrue(jwtBody.get("roles", List.class).contains("admin"));
+    }
+
+}
diff --git a/pom.xml b/pom.xml
index 9827e61e6..f24d52242 100644
--- a/pom.xml
+++ b/pom.xml
@@ -103,6 +103,7 @@
         <maven.gpg.version>1.6</maven.gpg.version> <!-- max version allowed for JDK 7 builds -->
         <maven.japicmp.version>0.13.1</maven.japicmp.version> <!-- max version allowed for JDK 7 builds -->
         <gmavenplus.version>1.6.1</gmavenplus.version> <!-- higher version used in jdk8AndLater profile below -->
+        <moditect.version>1.0.0.RC2</moditect.version>
         <maven.license.version>4.2.rc3</maven.license.version>
         <maven.license.skipExistingHeaders>true</maven.license.skipExistingHeaders>
 
@@ -555,8 +556,6 @@
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>${maven.compiler.version}</version>
                 <configuration>
-                    <source>${jdk.version}</source>
-                    <target>${jdk.version}</target>
                     <encoding>${project.build.sourceEncoding}</encoding>
                 </configuration>
             </plugin>
@@ -667,6 +666,11 @@
                 <artifactId>coveralls-maven-plugin</artifactId>
                 <version>4.4.1</version>
             </plugin>
+          <plugin>
+            <groupId>org.moditect</groupId>
+            <artifactId>moditect-maven-plugin</artifactId>
+            <version>${moditect.version}</version>
+          </plugin>
         </plugins>
     </build>
     <profiles>
@@ -734,6 +738,9 @@
                 <maven.javadoc.additionalOptions>-html5</maven.javadoc.additionalOptions>
                 <surefire.argLine>${test.addOpens}, --illegal-access=debug</surefire.argLine>
             </properties>
+            <modules>
+                <module>integration-tests</module>
+            </modules>
         </profile>
         <profile>
             <id>jdk17AndLater</id>