Skip to content

Commit b012f75

Browse files
authored
116 java9 module support (#141)
* Add module-info for annotation and processor * Add module descriptor to released jars * Test jpms in ci and update docs
1 parent a174fb0 commit b012f75

40 files changed

Lines changed: 210 additions & 68 deletions

.github/workflows/ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ jobs:
4444
with:
4545
path: ~/.m2/repository
4646
key: build_maven
47-
- name: Build
47+
- name: Build And Test
4848
run: ./mvnw install -e --ntp -B
49+
- name: Test JPMS
50+
run: ./mvnw clean verify -pl it/java8 -P it-jpms -e --ntp -B
4951
- name: Javadoc
5052
run: ./mvnw -P release javadoc:javadoc --ntp -B
5153
- name: Upload generated sources

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ pub struct User {
3636
```
3737

3838
## Features
39-
* Java8 support.
39+
* Java8 compatible; Java 9 module (Jigsaw) compatible.
4040
* Generics support.
41-
* Constant support.
41+
* Compile-time constant support.
4242
* Client source dependency is only `@SharedType` retained at source code level.
43-
* SharedType AP has only 2 small dependencies: jsr305 annotations and [mustache](https://github.com/spullara/mustache.java).
43+
* SharedType annotation processor has only 1 dependency: [mustache](https://github.com/spullara/mustache.java).
4444
* Parsing takes milliseconds with `-proc:only`.
4545
* Intuitive defaults, put `@SharedType` and there you go. Global + class level options.
4646

annotation/pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,32 @@
1414
<description>
1515
SharedType is an annotation processor to generate type information from Java source code into different target languages or schemas.
1616
</description>
17+
18+
<build>
19+
<plugins>
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-compiler-plugin</artifactId>
23+
<executions>
24+
<execution>
25+
<id>default-compile</id>
26+
<configuration>
27+
<release>9</release>
28+
</configuration>
29+
</execution>
30+
<execution>
31+
<id>base-compile</id>
32+
<goals>
33+
<goal>compile</goal>
34+
</goals>
35+
<configuration>
36+
<excludes>
37+
<exclude>module-info.java</exclude>
38+
</excludes>
39+
</configuration>
40+
</execution>
41+
</executions>
42+
</plugin>
43+
</plugins>
44+
</build>
1745
</project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module online.sharedtype.annotation {
2+
exports online.sharedtype;
3+
requires java.base;
4+
}

doc/Development.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ Optionally mount tmpfs to save your disk by:
2929
```
3030
Optionally setup `MVND_HOME` to use [maven daemon](https://github.com/apache/maven-mvnd) by `./mvnd`
3131

32+
Choose maven profiles in IDE accordingly as below.
33+
3234
### Maven profiles
3335
* `dev` and `release` - control whether to include test maven modules during build.
3436
* `it` - enable integration test profile. `internal` folder is shared source between `processor` and `it`,
3537
IDE may not able to properly resolve classes in `internal` folder for both modules.
3638
Enable this profile to enable `it` modules in IDE, and disable it when developing against `processor` module.
39+
* `it-no-jpms` and `it-jpms` - control whether to enable Java 9 Jigsaw module test in `it`. `it/java8` sources are reused to test on jdk9. Turn on `it-jpms` for IDE to correctly resolve `it/java8` classes.
3740

3841
## Development
3942
### Run test
@@ -53,6 +56,11 @@ Setup `JAVA8_HOME` to point to your Java8 installation. Open a new terminal and
5356
. setenv 8
5457
./mvnw verify -pl it/java8
5558
```
59+
#### Verify JDK9 JPMS compatibility locally:
60+
```bash
61+
./mvnw verify -pl it/java8 -P it-jpms
62+
```
63+
5664
#### Run client tests locally:
5765
Client tests are run in target languages in respective dir inside `./client-test`. They do basic type checking.
5866
* Typescript - `. setenv && npm i && npm run test`

internal/src/main/java/online/sharedtype/processor/domain/MappableType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import online.sharedtype.SharedType;
44

5-
import javax.annotation.Nullable;
5+
import online.sharedtype.processor.support.annotation.Nullable;
66

77
public interface MappableType {
88
String qualifiedName();

internal/src/main/java/online/sharedtype/processor/domain/type/ConcreteTypeInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import online.sharedtype.processor.domain.MappableType;
99
import online.sharedtype.processor.domain.def.TypeDef;
1010

11-
import javax.annotation.Nullable;
11+
import online.sharedtype.processor.support.annotation.Nullable;
1212
import java.util.Collections;
1313
import java.util.EnumMap;
1414
import java.util.List;

internal/src/main/java/online/sharedtype/processor/domain/type/DateTimeInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import online.sharedtype.SharedType;
66
import online.sharedtype.processor.domain.MappableType;
77

8-
import javax.annotation.Nullable;
8+
import online.sharedtype.processor.support.annotation.Nullable;
99
import java.util.EnumMap;
1010
import java.util.Map;
1111

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package online.sharedtype.processor.domain.type;
2+
3+
import online.sharedtype.processor.domain.def.TypeDef;
4+
5+
/**
6+
* Present no type info.
7+
* @see online.sharedtype.processor.parser.type.TypeInfoParser
8+
* @author Cause Chung
9+
*/
10+
final class NoTypeInfo implements TypeInfo {
11+
private static final long serialVersionUID = 1773678739237108430L;
12+
13+
static final NoTypeInfo INSTANCE = new NoTypeInfo();
14+
private NoTypeInfo() {}
15+
16+
@Override
17+
public void addReferencingType(TypeDef typeDef) {
18+
}
19+
}

internal/src/main/java/online/sharedtype/processor/domain/type/TypeInfo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ default boolean resolved() {
3131

3232
/**
3333
* Replace type variables with type arguments.
34+
*
3435
* @param mappings key is a type variable e.g. T
3536
* value is a type argument, a concrete type e.g. Integer, or a generic type with concrete type parameter, e.g. {@code Tuple<String, String>}
3637
* @return a newly created type info if updated.
@@ -41,7 +42,14 @@ default TypeInfo reify(Map<TypeVariableInfo, TypeInfo> mappings) {
4142

4243
/**
4344
* Mark this type as referenced by another type. Used for e.g. cyclic reference detection.
45+
*
4446
* @param typeDef type that references this type
4547
*/
4648
void addReferencingType(TypeDef typeDef);
49+
50+
/**
51+
* Represents no type. This can happen when a type is not visible, e.g. not on module path.
52+
* @see online.sharedtype.processor.parser.type.TypeInfoParser
53+
*/
54+
TypeInfo NO_TYPE_INFO = NoTypeInfo.INSTANCE;
4755
}

0 commit comments

Comments
 (0)