Skip to content

Commit

Permalink
support jdk11
Browse files Browse the repository at this point in the history
  • Loading branch information
harbby committed Aug 6, 2020
1 parent db98c8a commit dce73b1
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 23 deletions.
19 changes: 15 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
language: java
jdk:
- openjdk8
#jdk:
#- openjdk8
sudo: required
dist: xenial
dist: trusty

services:
- docker

script: "./gradlew clean checkstyle licenseMain licenseTest assemble --no-daemon"
matrix:
include:
- jdk: openjdk8
env: jdk=java8
script: ./gradlew clean checkstyle licenseMain licenseTest --no-daemon
- jdk: openjdk8
env: jdk=java8
script: ./gradlew clean assemble --no-daemon
- jdk: openjdk11
env: jdk=java11
script: ./gradlew clean assemble --no-daemon

env:
- CI=false
Expand Down
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ allprojects {
apply plugin: 'checkstyle'
apply plugin: 'jacoco'

sourceCompatibility = 1.8
targetCompatibility = 1.8
def jdk = project.hasProperty('jdk') ? project.jdk : 'java8' //or java11 use -Pjdk=java8
//def jdk = System.getProperty("jdk") ?: "java8" //or java11 use -Djdk=java8
apply from: "$rootProject.projectDir/profile-${jdk}.gradle"

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
Expand All @@ -33,7 +34,7 @@ allprojects {
joda_time : '2.9.3',
slf4j : '1.7.25',
guice : '4.2.1',
gadtry : '1.7.1',
gadtry : '1.7.2',
guava : '27.0-jre',
jackson : '2.9.5',
jersey : '2.28',
Expand Down Expand Up @@ -126,7 +127,7 @@ subprojects {
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
//javadoc.failOnError = false
javadoc.failOnError = false
}

artifacts {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jdk=java11
28 changes: 28 additions & 0 deletions profile-java11.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//java 11

sourceCompatibility = 11
targetCompatibility = 11

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs << "--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED"
options.compilerArgs << "--add-exports=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED"
options.compilerArgs << "--add-exports=java.base/sun.reflect.generics.tree=ALL-UNNAMED"
options.compilerArgs << "--add-exports=java.base/sun.reflect.generics.repository=ALL-UNNAMED"
options.compilerArgs << "--add-exports=java.base/sun.nio.cs=ALL-UNNAMED"
options.compilerArgs << "--add-exports=java.base/jdk.internal.vm.annotation=ALL-UNNAMED"
}

tasks.withType(Test) {
jvmArgs += "--add-modules=jdk.unsupported"
jvmArgs += "--add-opens=java.base/jdk.internal.ref=ALL-UNNAMED"
jvmArgs += "--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED"
jvmArgs += "--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED"
}

tasks.withType(JavaExec) {
jvmArgs += "--add-modules=jdk.unsupported"
jvmArgs += "--add-opens=java.base/jdk.internal.ref=ALL-UNNAMED"
jvmArgs += "--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED"
jvmArgs += "--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED"
}
7 changes: 7 additions & 0 deletions profile-java8.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

sourceCompatibility = 1.8
targetCompatibility = 1.8

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
2 changes: 0 additions & 2 deletions sylph-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
ext.moduleName = 'ideal.sylph.api'

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile group: 'com.github.harbby', name: 'gadtry', version: deps.gadtry
Expand Down
3 changes: 0 additions & 3 deletions sylph-connectors/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ subprojects {
serviceInterface 'ideal.sylph.etl.Plugin'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

configurations.all {
resolutionStrategy { preferProjectModules() }
}
Expand Down
14 changes: 4 additions & 10 deletions sylph-spi/src/main/java/ideal/sylph/spi/PluginConfigFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.harbby.gadtry.collection.mutable.MutableMap;
import com.github.harbby.gadtry.memory.UnsafeHelper;
import ideal.sylph.annotation.Description;
import ideal.sylph.annotation.Name;
import ideal.sylph.etl.PluginConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.reflect.ReflectionFactory;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand All @@ -46,7 +46,7 @@ private PluginConfigFactory() {}
public <T extends PluginConfig> T createPluginConfig(Class<T> type, Map<String, Object> config)
throws Exception
{
T pluginConfig = pluginConfigInstance(type.asSubclass(PluginConfig.class));
T pluginConfig = pluginConfigInstance(type);
//--- inject map config
injectConfig(pluginConfig, config);
return pluginConfig;
Expand All @@ -59,21 +59,15 @@ public static <T extends PluginConfig> T pluginConfigInstance(Class<T> type)

//Ignore the constructor in the configuration class
try {
Constructor<T> pluginConfigConstructor = type.getDeclaredConstructor();
Constructor<? extends T> pluginConfigConstructor = type.getDeclaredConstructor();
logger.debug("find 'no parameter' constructor with [{}]", type);
pluginConfigConstructor.setAccessible(true);
return pluginConfigConstructor.newInstance();
}
catch (NoSuchMethodException e) {
logger.warn("Not find 'no parameter' constructor, use javassist inject with [{}]", type);
// copy proxyConfig field value to pluginConfig ...
Constructor superCons = Object.class.getConstructor();
ReflectionFactory reflFactory = ReflectionFactory.getReflectionFactory();
Constructor<?> c = reflFactory.newConstructorForSerialization(type, superCons);
// or use unsafe, demo: PluginConfig pluginConfig = (PluginConfig) unsafe.allocateInstance(type)
@SuppressWarnings("unchecked")
T pluginConfig = (T) c.newInstance();
return pluginConfig;
return UnsafeHelper.allocateInstance2(type);
}
}

Expand Down

0 comments on commit dce73b1

Please sign in to comment.