Skip to content

Commit

Permalink
Dynamically generate native image config (apache#11795)
Browse files Browse the repository at this point in the history
* ADD dubbo-maven-plugin

* add dubbo-maven-plugin module

Signed-off-by: crazyhzm <[email protected]>

* fix license and compiler error

Signed-off-by: crazyhzm <[email protected]>

* fix license and ci error

Signed-off-by: crazyhzm <[email protected]>

* fix ci error

Signed-off-by: crazyhzm <[email protected]>

* Remove proxy-config, hard code

Signed-off-by: crazyhzm <[email protected]>

* ignoredModulesInDubboAll

Signed-off-by: crazyhzm <[email protected]>

* throw exception for generated adaptive class sources

Signed-off-by: crazyhzm <[email protected]>

* remove useless reflect config

Signed-off-by: crazyhzm <[email protected]>

* Dynamically generate native image config for graalvm, and remove the original native image config

Signed-off-by: crazyhzm <[email protected]>

* fix conflict

Signed-off-by: crazyhzm <[email protected]>

* remove .git.exec.error

Signed-off-by: crazyhzm <[email protected]>

* remove .git.exec.error

Signed-off-by: crazyhzm <[email protected]>

* remove useless import

Signed-off-by: crazyhzm <[email protected]>

---------

Signed-off-by: crazyhzm <[email protected]>
Co-authored-by: Albumen Kevin <[email protected]>
  • Loading branch information
CrazyHZM and AlbumenJ authored Mar 14, 2023
1 parent e6ee608 commit 69edf4e
Show file tree
Hide file tree
Showing 36 changed files with 1,827 additions and 3,378 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ dubbo-demo/dubbo-demo-triple/build/*
# global registry center
.tmp

.git.exec.error

3 changes: 3 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ header:
- 'dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/aot/MatchingGroupIdFilter.java'
- 'dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/aot/RunArguments.java'
- 'dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/aot/RunProcess.java'
- 'dubbo-native/src/main/java/org/apache/dubbo/aot/generate/BasicJsonWriter.java'
- 'dubbo-native/src/main/java/org/apache/dubbo/aot/generate/ExecutableMode.java'
- 'dubbo-native/src/main/java/org/apache/dubbo/aot/generate/MemberCategory.java'

comment: on-failure

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class ScopeBeanFactory {
private final List<BeanInfo> registeredBeanInfos = new CopyOnWriteArrayList<>();
private InstantiationStrategy instantiationStrategy;
private final AtomicBoolean destroyed = new AtomicBoolean();
private List<Class<?>> registeredClasses = new ArrayList<>();

public ScopeBeanFactory(ScopeBeanFactory parent, ExtensionAccessor extensionAccessor) {
this.parent = parent;
Expand Down Expand Up @@ -131,6 +132,7 @@ public <T> T getOrRegisterBean(String name, Class<T> type) {
}
}
}
registeredClasses.add(type);
return bean;
}

Expand Down Expand Up @@ -281,4 +283,8 @@ public BeanInfo(String name, Object instance) {
this.instance = instance;
}
}

public List<Class<?>> getRegisteredClasses() {
return registeredClasses;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"name": "org.apache.zookeeper.ClientCnxnSocketNIO",
"methods": [
{
"name": "<init>",
"parameterTypes": [
"org.apache.zookeeper.client.ZKClientConfig"
]
},
{
"name": "<init>",
"parameterTypes": []
}
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
#


log4j.rootLogger=error, console

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%-12d{HH\:mm\:ss.SS}] [%p] %l %m%n
###set log levels###
log4j.rootLogger=info, stdout
###output to the console###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{
"name": "org.apace.dubbo.graalvm.demo.DemoService",
"allPublicMethods": true
},
{
"name": "org.apache.dubbo.demo.graalvm.provider.DemoServiceImpl",
"allDeclaredMethods": true
},
{
"name": "org.apache.zookeeper.ClientCnxnSocketNIO",
"methods": [
{
"name": "<init>",
"parameterTypes": [
"org.apache.zookeeper.client.ZKClientConfig"
]
},
{
"name": "<init>",
"parameterTypes": []
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"resources": {
"includes": [
{
"pattern": "\\Qdubbo.properties\\E"
},
{
"pattern": "\\Qlog4j.properties\\E"
}
]
},
"bundles": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,22 @@
package org.apache.dubbo.maven.plugin.aot;


import org.apache.commons.io.FileUtils;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;

import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Mojo(name = "dubbo-process-aot", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, threadSafe = true,
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
public class DubboProcessAotMojo extends AbstractAotMojo {

private static final String AOT_PROCESSOR_CLASS_NAME = "org.apache.dubbo.aot.generate.CodeGenerator";
private static final String AOT_PROCESSOR_CLASS_NAME = "org.apache.dubbo.aot.generate.AotProcessor";

/**
* Directory containing the classes and resource files that should be packaged into
Expand Down Expand Up @@ -83,7 +79,6 @@ protected void executeAot() throws Exception {
URL[] classPath = getClassPath().toArray(new URL[0]);
generateAotAssets(classPath, AOT_PROCESSOR_CLASS_NAME, getAotArguments(mainClass));
compileSourceFiles(classPath, this.generatedSources, this.classesDirectory);
copyNativeConfigFile(project);
copyAll(this.generatedResources.toPath(), this.classesDirectory.toPath());
copyAll(this.generatedClasses.toPath(), this.classesDirectory.toPath());
}
Expand All @@ -104,35 +99,4 @@ private List<URL> getClassPath() throws Exception {
File[] directories = new File[]{this.classesDirectory, this.generatedClasses};
return getClassPath(directories, new ExcludeTestScopeArtifactFilter());
}

private void copyNativeConfigFile(MavenProject project) {
String[] nativeFiles = {"META-INF/native-image/reflect-config.json",
"META-INF/native-image/jni-config.json",
"META-INF/native-image/proxy-config.json",
"META-INF/native-image/resource-config.json",
"META-INF/native-image/serialization-config.json"};

Arrays.stream(nativeFiles).forEach(nativeFile -> {
InputStream is = this.getClass().getClassLoader().getResourceAsStream(nativeFile);
project.getResources().stream().findFirst().ifPresent(resource -> {
try {
String path = generatedResources + File.separator + "META-INF" + File.separator + "native-image" + File.separator
+ File.separator + this.project.getGroupId() + File.separator + this.project.getArtifactId();
FileUtils.forceMkdir(new File(path));
String[] str = nativeFile.split("/");
File file = new File(path + File.separator + str[str.length - 1]);
if (!file.exists()) {
FileUtils.copyInputStreamToFile(is, file);
getLog().info("Copy native config file:" + file);
} else {
getLog().info("Skip copy config file:" + file);
}
} catch (Throwable ex) {
getLog().error("Copy native config file error:" + ex.getMessage());
}
});
});
}


}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 69edf4e

Please sign in to comment.