Skip to content

Commit

Permalink
Fix #557: add direct use of module-info.java (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Jan 17, 2025
1 parent c7f91fb commit e0ca2d6
Show file tree
Hide file tree
Showing 30 changed files with 1,081 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java_version: ['17', '21']
java_version: ['17', '21', '23']
include:
- java_version: '17'
release_build: 'R'
Expand Down
7 changes: 0 additions & 7 deletions avro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ abstractions.
</execution>
</executions>
</plugin>
<!-- 19-Mar-2019, tatu: Add rudimentary JDK9+ module info. To build with JDK 8
will have to use `moduleInfoFile` as anything else requires JDK 9+
-->
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module tools.jackson.dataformat.avro {
// Avro Main artifact Module descriptor
module tools.jackson.dataformat.avro
{
requires transitive com.fasterxml.jackson.annotation;
requires tools.jackson.core;
requires tools.jackson.databind;

// silly avro Apache impl, its deps:
requires static avro;
requires static jackson.core.asl;
requires static jackson.mapper.asl;
requires org.apache.avro;

exports tools.jackson.dataformat.avro;
exports tools.jackson.dataformat.avro.annotation;
Expand Down
35 changes: 35 additions & 0 deletions avro/src/test/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Avro unit test Module descriptor
module tools.jackson.dataformat.avro
{
// Since we are not split from Main artifact, will not
// need to depend on Main artifact -- but need its dependencies

requires tools.jackson.core;
requires tools.jackson.databind;

requires org.apache.avro;

// Additional test lib/framework dependencies
requires org.assertj.core;
requires org.junit.jupiter.api;
requires org.junit.jupiter.params;

// Further, need to open up some packages for JUnit et al

opens tools.jackson.dataformat.avro;
opens tools.jackson.dataformat.avro.annotation;
opens tools.jackson.dataformat.avro.dos;
opens tools.jackson.dataformat.avro.fuzz;
opens tools.jackson.dataformat.avro.gen;
opens tools.jackson.dataformat.avro.interop;
opens tools.jackson.dataformat.avro.interop.annotations;
opens tools.jackson.dataformat.avro.interop.arrays;
opens tools.jackson.dataformat.avro.interop.maps;
opens tools.jackson.dataformat.avro.interop.records;
opens tools.jackson.dataformat.avro.jsr310;
opens tools.jackson.dataformat.avro.schema;
opens tools.jackson.dataformat.avro.schemaev;
opens tools.jackson.dataformat.avro.testsupport;
opens tools.jackson.dataformat.avro.testutil.failure;
opens tools.jackson.dataformat.avro.tofix;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testSchemaCreation_withLogicalTypesDisabled_onBigDecimalWithAvroDeci
// because logical types are disabled by default.
final Schema actualSchema = gen.getGeneratedSchema().getAvroSchema();

System.out.println(BigDecimalWithAvroDecimalAnnotationWrapper.class.getSimpleName() + " schema:" + actualSchema.toString(true));
//System.out.println(BigDecimalWithAvroDecimalAnnotationWrapper.class.getSimpleName() + " schema:" + actualSchema.toString(true));

// THEN
assertThat(actualSchema.getField("bigDecimalValue")).isNotNull();
Expand All @@ -64,7 +64,7 @@ public void testSchemaCreation_withLogicalTypesEnabled_onBigDecimalWithAvroDecim
MAPPER.acceptJsonFormatVisitor(BigDecimalWithAvroDecimalAnnotationWrapper.class, gen);
final Schema actualSchema = gen.getGeneratedSchema().getAvroSchema();

System.out.println(BigDecimalWithAvroDecimalAnnotationWrapper.class.getSimpleName() + " schema:" + actualSchema.toString(true));
//System.out.println(BigDecimalWithAvroDecimalAnnotationWrapper.class.getSimpleName() + " schema:" + actualSchema.toString(true));

// THEN
assertThat(actualSchema.getField("bigDecimalValue")).isNotNull();
Expand Down Expand Up @@ -97,7 +97,7 @@ public void testSchemaCreation_withLogicalTypesEnabled_onBigDecimalWithAvroDecim
MAPPER.acceptJsonFormatVisitor(BigDecimalWithAvroDecimalAnnotationToFixedWrapper.class, gen);
final Schema actualSchema = gen.getGeneratedSchema().getAvroSchema();

System.out.println(BigDecimalWithAvroDecimalAnnotationToFixedWrapper.class.getSimpleName() + " schema:" + actualSchema.toString(true));
//System.out.println(BigDecimalWithAvroDecimalAnnotationToFixedWrapper.class.getSimpleName() + " schema:" + actualSchema.toString(true));

// THEN
assertThat(actualSchema.getField("bigDecimalValue")).isNotNull();
Expand Down
7 changes: 0 additions & 7 deletions cbor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ encoded data using Jackson abstractions (streaming API, data binding, tree model
</execution>
</executions>
</plugin>
<!-- 19-Mar-2019, tatu: Add rudimentary JDK9+ module info. To build with JDK 8
will have to use `moduleInfoFile` as anything else requires JDK 9+
-->
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module tools.jackson.dataformat.cbor {
// CBOR Main artifact Module descriptor
module tools.jackson.dataformat.cbor
{
requires tools.jackson.core;
requires tools.jackson.databind;

Expand Down
27 changes: 27 additions & 0 deletions cbor/src/test/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// CBOR unit test Module descriptor
module tools.jackson.dataformat.cbor
{
// Since we are not split from Main artifact, will not
// need to depend on Main artifact -- but need its dependencies

requires tools.jackson.core;
requires tools.jackson.databind;

// Additional test lib/framework dependencies
requires org.junit.jupiter.api;
requires org.junit.jupiter.params;

// Further, need to open up some packages for JUnit et al
opens tools.jackson.dataformat.cbor;
opens tools.jackson.dataformat.cbor.constraints;
opens tools.jackson.dataformat.cbor.dos;
opens tools.jackson.dataformat.cbor.filter;
opens tools.jackson.dataformat.cbor.fuzz;
opens tools.jackson.dataformat.cbor.gen;
opens tools.jackson.dataformat.cbor.gen.dos;
opens tools.jackson.dataformat.cbor.mapper;
opens tools.jackson.dataformat.cbor.parse;
opens tools.jackson.dataformat.cbor.seq;
opens tools.jackson.dataformat.cbor.testutil;
opens tools.jackson.dataformat.cbor.testutil.failure;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ public void testSimpleDefault() throws Exception
assertTrue(syms.isCanonicalizing()); // added in 2.13

assertEquals(0, syms.size());
assertEquals(0, _findParent(syms).size());
//assertEquals(0, _findParent(syms).size());

assertToken(JsonToken.START_OBJECT, p.nextToken());
assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
assertEquals("a", p.currentName());
assertEquals(1, syms.size());
// not yet synced to parent
assertEquals(0, _findParent(syms).size());
//assertEquals(0, _findParent(syms).size());

while (p.nextToken() != null) { ; }
assertEquals(2, syms.size());
// but after closing, should sync
assertEquals(2, _findParent(syms).size());
//assertEquals(2, _findParent(syms).size());
}

// by default, should canonicalize etc:
try (JsonParser p = vanillaMapper.createParser(doc)) {
ByteQuadsCanonicalizer syms = _findSymbols(p);
assertEquals(2, syms.size());
// also check that parent (root) has it all?
assertEquals(2, _findParent(syms).size());
//assertEquals(2, _findParent(syms).size());

// but no additions second time around
while (p.nextToken() != null) { ; }
Expand Down Expand Up @@ -118,7 +118,7 @@ public void testSimpleNoCanonicalize() throws Exception
assertFalse(syms.isCanonicalizing()); // added in 2.13
assertEquals(-1, syms.size());
// also, should not have parent:
assertNull(_findParent(syms));
//assertNull(_findParent(syms));

assertToken(JsonToken.START_OBJECT, p.nextToken());
assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
Expand Down Expand Up @@ -227,10 +227,13 @@ private ByteQuadsCanonicalizer _findSymbols(JsonParser p) throws Exception
return (ByteQuadsCanonicalizer) f.get(p);
}

// Cannot access under JPMS, alas
/*
private ByteQuadsCanonicalizer _findParent(ByteQuadsCanonicalizer sym) throws Exception
{
Field f = ByteQuadsCanonicalizer.class.getDeclaredField("_parent");
f.setAccessible(true);
return (ByteQuadsCanonicalizer) f.get(sym);
}
*/
}
7 changes: 0 additions & 7 deletions ion/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ tree model)
</execution>
</executions>
</plugin>
<!-- 19-Mar-2019, tatu: Add rudimentary JDK9+ module info. To build with JDK 8
will have to use `moduleInfoFile` as anything else requires JDK 9+
-->
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Generated 15-Mar-2019 using Moditect maven plugin
module tools.jackson.dataformat.ion {
requires transitive com.fasterxml.jackson.annotation;
// Ion Main artifact Module descriptor
module tools.jackson.dataformat.ion
{
requires tools.jackson.core;
requires tools.jackson.databind;

requires static ion.java;

requires java.sql;

// ion-java has no explicit module-info; but automatic name is:
requires com.amazon.ion;

exports tools.jackson.dataformat.ion;
exports tools.jackson.dataformat.ion.ionvalue;
exports tools.jackson.dataformat.ion.jsr310;
exports tools.jackson.dataformat.ion.polymorphism;
exports tools.jackson.dataformat.ion.util;

provides tools.jackson.core.TokenStreamFactory with
tools.jackson.dataformat.ion.IonFactory;
Expand Down
28 changes: 28 additions & 0 deletions ion/src/test/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Ion unit test Module descriptor
module tools.jackson.dataformat.ion
{
// Since we are not split from Main artifact, will not
// need to depend on Main artifact -- but need its dependencies

requires tools.jackson.core;
requires tools.jackson.databind;
requires java.sql;

requires com.amazon.ion;

// Additional test lib/framework dependencies
requires org.junit.jupiter.api;
requires org.junit.jupiter.params;

// Further, need to open up some packages for JUnit et al
opens tools.jackson.dataformat.ion;
opens tools.jackson.dataformat.ion.dos;
opens tools.jackson.dataformat.ion.fuzz;
opens tools.jackson.dataformat.ion.ionvalue;
opens tools.jackson.dataformat.ion.jsr310;
opens tools.jackson.dataformat.ion.misc;
opens tools.jackson.dataformat.ion.polymorphism;
opens tools.jackson.dataformat.ion.sequence;
opens tools.jackson.dataformat.ion.testutil.failure;
opens tools.jackson.dataformat.ion.tofix;
}
44 changes: 0 additions & 44 deletions protobuf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ abstractions.
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<!-- and for testing, JUnit is needed; as well as annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -73,43 +66,6 @@ abstractions.
</executions>
</plugin>

<plugin>
<!-- We will shade proto-parser, to simplify deployment, avoid version conflicts -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<!-- the bundle plugin already did the pulling-in, all we need is the renaming! -->
<!--
<include>com.squareup:protoparser</include>
-->
<include>null:null</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.squareup</pattern>
<shadedPattern>tools.jackson.dataformat.protobuf.protoparser</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
<!-- 19-Mar-2019, tatu: Add rudimentary JDK9+ module info. To build with JDK 8
will have to use `moduleInfoFile` as anything else requires JDK 9+
-->
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

Expand Down
21 changes: 21 additions & 0 deletions protobuf/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Protobuf Main artifact Module descriptor
module tools.jackson.dataformat.protobuf
{
requires transitive tools.jackson.core;
requires transitive tools.jackson.databind;

// No module-info nor Automatic-Module-Name; relies on jar name:
requires protoparser;

exports tools.jackson.dataformat.protobuf;
exports tools.jackson.dataformat.protobuf.schema;
exports tools.jackson.dataformat.protobuf.schemagen;

// Need to "opens" to allow reading resource `descriptor.proto`
opens tools.jackson.dataformat.protobuf.schema;

provides tools.jackson.core.TokenStreamFactory with
tools.jackson.dataformat.protobuf.ProtobufFactory;
provides tools.jackson.databind.ObjectMapper with
tools.jackson.dataformat.protobuf.ProtobufMapper;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Objects;
import java.util.concurrent.locks.ReentrantLock;

import tools.jackson.core.Version;
Expand Down Expand Up @@ -34,6 +35,13 @@ public Builder(ProtobufFactory f) {
super(f);
}

/**
* NOTE: while technically public, not intended for external use
* (since {@code StateImpl} is not public type)
*
* @param state State to restore to initialize constructed Builder
*/
@SuppressWarnings("exports")
public Builder(StateImpl state) {
super(state);
}
Expand Down Expand Up @@ -209,15 +217,15 @@ public ProtobufSchema generateSchemaFor(TypeReference<?> type) {
*/

public FileDescriptorSet loadDescriptorSet(URL src) throws IOException {
return descriptorLoader().load(src);
return descriptorLoader().load(Objects.requireNonNull(src));
}

public FileDescriptorSet loadDescriptorSet(File src) throws IOException {
return descriptorLoader().load(src);
return descriptorLoader().load(Objects.requireNonNull(src));
}

public FileDescriptorSet loadDescriptorSet(InputStream src) throws IOException {
return descriptorLoader().load(src);
return descriptorLoader().load(Objects.requireNonNull(src));
}

/**
Expand Down
Loading

0 comments on commit e0ca2d6

Please sign in to comment.