remove dubbo-native-plugin module (#12358)

Signed-off-by: crazyhzm <crazyhzm@gmail.com>
This commit is contained in:
huazhongming 2023-05-21 21:00:46 +08:00 committed by GitHub
parent 71cc51bf69
commit 52e4e4e301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 0 additions and 3665 deletions

View File

@ -66,7 +66,6 @@ dubbo-monitor
dubbo-monitor-api
dubbo-monitor-default
dubbo-native
dubbo-native-plugin
dubbo-parent
dubbo-plugin
dubbo-qos

View File

@ -29,7 +29,6 @@ ignore:
- "**/dubbo-test/**"
- "**/dubbo-compatible/**"
- "**/dubbo-native/**"
- "**/dubbo-native-plugin/**"
- "**/dubbo-common/src/main/java/org/apache/dubbo/common/json/*.java" # internal JSON impl is deprecate, ignore test coverage for them
- "**/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java" # Deprecated
- "**/dubbo-rpc/dubbo-rpc-thrift/**"

View File

@ -286,13 +286,6 @@
<version>${project.version}</version>
</dependency>
<!-- native-plugin -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-native-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-maven-plugin</artifactId>

View File

@ -1,103 +0,0 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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">
<parent>
<artifactId>dubbo-parent</artifactId>
<groupId>org.apache.dubbo</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dubbo-native-plugin</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<packaging>maven-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.9.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.8.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-default</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<id>default-addPluginArtifactMetadata</id>
<phase>package</phase>
<goals>
<goal>addPluginArtifactMetadata</goal>
</goals>
</execution>
<execution>
<id>default-descriptor</id>
<phase>process-classes</phase>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,93 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.maven.plugin;
import java.io.File;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class ClassFinder {
public Set<String> findClassSet(String packageName, Consumer<String> consumer) {
packageName = packageName.replace(".", "/");
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Enumeration resources = classLoader.getResources(packageName);
Set<String> result = new HashSet<>();
while (resources.hasMoreElements()) {
URL resource = (URL) resources.nextElement();
if (resource != null) {
String protocol = resource.getProtocol();
if ("file".equals(protocol)) {
findClassesByFile(packageName, resource.getPath(), result);
} else if ("jar".equals(protocol)) {
JarFile jar = ((JarURLConnection) resource.openConnection()).getJarFile();
consumer.accept("findClassSet jar:" + jar.getName());
findClassesByJar(packageName, jar, result);
}
}
}
return result;
} catch (Throwable ex) {
throw new RuntimeException(ex);
}
}
private void findClassesByFile(String packageName, String resource, Set<String> result) {
File directory = new File(resource);
File[] listFiles = directory.listFiles();
// null check
if (listFiles != null) {
for (File file : listFiles) {
if (file.isDirectory()) {
findClassesByFile(packageName, file.getPath(), result);
} else {
String path = file.getPath();
if (path.endsWith(".class")) {
int packageIndex = path.indexOf(packageName.replace("/", File.separator));
String classPath = path.substring(packageIndex, path.length() - 6);
result.add(classPath.replace(File.separator, "."));
}
}
}
}
}
private static void findClassesByJar(String packageName, JarFile jar, Set<String> classes) {
Enumeration<JarEntry> entry = jar.entries();
JarEntry jarEntry;
String name;
while (entry.hasMoreElements()) {
jarEntry = entry.nextElement();
name = jarEntry.getName();
if (name.charAt(0) == '/') {
name = name.substring(1);
}
if (jarEntry.isDirectory() || !name.startsWith(packageName) || !name.endsWith(".class")) {
continue;
}
String className = name.substring(0, name.length() - 6);
classes.add(className.replace("/", "."));
}
}
}

View File

@ -1,122 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.maven.plugin;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.common.extension.AdaptiveClassCodeGenerator;
import org.apache.dubbo.common.extension.SPI;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.logging.SystemStreamLog;
import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
/**
* generate related self-adaptive code (native image does not support dynamic code generation. Therefore, code needs to be generated before compilation)
*/
public class CodeGenerator {
public static void execute(String p, Log log) {
log.info("Start generating code:" + p);
List<Class<?>> classes = new ClassFinder().findClassSet("org.apache.dubbo", msg -> {
log.info(msg);
}).stream().map(it -> {
try {
return Class.forName(it);
} catch (Throwable e) {
}
return null;
}).collect(Collectors.toList());
new ArrayList<>(classes).stream().filter(it -> {
if (null == it) {
return false;
}
Annotation anno = it.getAnnotation(SPI.class);
if (null == anno) {
return false;
}
try {
Optional<Method> optional = Arrays.stream(it.getMethods()).filter(it2 -> it2.getAnnotation(Adaptive.class) != null).findAny();
return optional.isPresent();
} catch (Throwable ex) {
log.warn(ex.getMessage());
return false;
}
}).forEach(it -> {
try {
SPI spi = it.getAnnotation(SPI.class);
String value = spi.value();
if (StringUtils.isEmpty(value)) {
value = "adaptive";
}
AdaptiveClassCodeGenerator codeGenerator = new AdaptiveClassCodeGenerator(it, value);
String code = codeGenerator.generate();
String file = p + File.separator + it.getName().replaceAll("\\.", Matcher.quoteReplacement(File.separator));
String dir = Paths.get(file).getParent().toString();
FileUtils.forceMkdir(new File(dir));
code = licensedStr + code + "\n";
File tmpFile = new File(file + "$Adaptive.java");
FileUtils.write(tmpFile, code, Charset.defaultCharset());
log.info("Generate file:" + tmpFile);
} catch (Throwable e) {
log.error("error:" + it.getPackage());
}
});
log.info("End of code generation");
}
public static void main(String[] args) {
URL r = Thread.currentThread().getContextClassLoader().getResource("");
String targetClassPath = new File(r.getFile()).getAbsolutePath();
String p = Paths.get(targetClassPath).getParent().getParent().toString() + File.separator + "src" + File.separator + "main" + File.separator + "java";
execute(p, new SystemStreamLog());
}
private static String licensedStr = "/*\n" +
" * Licensed to the Apache Software Foundation (ASF) under one or more\n" +
" * contributor license agreements. See the NOTICE file distributed with\n" +
" * this work for additional information regarding copyright ownership.\n" +
" * The ASF licenses this file to You under the Apache License, Version 2.0\n" +
" * (the \"License\"); you may not use this file except in compliance with\n" +
" * the License. You may obtain a copy of the License at\n" +
" *\n" +
" * http://www.apache.org/licenses/LICENSE-2.0\n" +
" *\n" +
" * Unless required by applicable law or agreed to in writing, software\n" +
" * distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
" * See the License for the specific language governing permissions and\n" +
" * limitations under the License.\n" +
" */\n";
}

View File

@ -1,88 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.maven.plugin;
import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
/**
* generate related self-adaptive code (native image does not support dynamic code generation. Therefore, code needs to be generated before compilation)
*/
@Mojo(name = "generate")
public class DubboNativeCodeGeneratorMojo extends AbstractMojo {
@Override
public void execute() {
Log log = getLog();
log.info("dubbo native code generator mojo execute");
MavenProject project = (MavenProject) this.getPluginContext().get("project");
copyNativeConfigFile(log, project);
try {
generateCode(log, project);
} catch (Exception ignored) {
}
}
private void generateCode(Log log, MavenProject project) throws IOException {
String baseDir = project.getBasedir().getPath();
File source = new File(baseDir + File.separator + "src" + File.separator + "main" + File.separator + "generated");
FileUtils.forceMkdir(source);
project.addCompileSourceRoot(source.getAbsolutePath());
log.info("Source directory: " + source + " added.");
List<String> list = project.getCompileSourceRoots();
log.info(list.toString());
CodeGenerator.execute(source.getPath(), log);
}
private void copyNativeConfigFile(Log log, 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 = DubboNativeCodeGeneratorMojo.class.getClassLoader().getResourceAsStream(nativeFile);
project.getResources().stream().findFirst().ifPresent(resource -> {
String directory = resource.getDirectory();
try {
FileUtils.forceMkdir(new File(directory + File.separator + "META-INF" + File.separator + "native-image" + File.separator));
File file = new File(directory + File.separator + nativeFile);
if (!file.exists()) {
FileUtils.copyInputStreamToFile(is, file);
log.info("Copy native config file:" + file);
} else {
log.info("Skip copy config file:" + file);
}
} catch (Throwable ex) {
log.error("Copy native config file error:" + ex.getMessage());
}
});
});
}
}

View File

@ -1,30 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.maven.plugin;
import java.util.Set;
public class Test {
public static void main(String[] args) {
ClassFinder finder = new ClassFinder();
Set<String> set = finder.findClassSet("org.apache.dubbo", msg -> {
});
System.out.println(set.size());
}
}

View File

@ -1,7 +0,0 @@
[
[
"org.apace.dubbo.graalvm.demo.DemoService",
"org.apache.dubbo.rpc.service.EchoService",
"org.apache.dubbo.rpc.service.Destroyable"
]
]

View File

@ -1,169 +0,0 @@
{
"resources": {
"includes": [
{
"pattern": "\\QDENY_CLASS\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.compiler.Compiler\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.context.ApplicationExt\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.context.ModuleExt\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.extension.ExtensionInjector\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.infra.InfraAdapter\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.logger.LoggerAdapter\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.threadpool.ThreadPool\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.threadpool.manager.ExecutorRepository\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.url.component.param.DynamicParamSource\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.metadata.MetadataServiceExporter\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.metadata.ServiceNameMapping\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.registry.AddressListener\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.registry.ProviderFirstParams\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.registry.client.RegistryClusterIdentifier\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceInstanceCustomizer\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.registry.client.migration.MigrationAddressComparator\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.registry.integration.RegistryProtocolListener\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.remoting.Codec2\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.remoting.Dispatcher\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.remoting.Transporter\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.remoting.exchange.Exchanger\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.Filter\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.InvokerListener\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.ProxyFactory\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.Cluster\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.ConfiguratorFactory\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.LoadBalance\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.ProviderURLMergeProcessor\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.RouterFactory\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.governance.GovernanceRuleRepository\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.router.state.StateRouterFactory\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.model.BuiltinServiceDetector\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer\\E"
},
{
"pattern": "\\QMETA-INF/services/org.apache.dubbo.common.extension.LoadingStrategy\\E"
},
{
"pattern": "\\Qdubbo.properties\\E"
},
{
"pattern": "\\Qlog4j.properties\\E"
},
{
"pattern": "\\Qorg/apache/dubbo/common/Version.class\\E"
},
{
"pattern": "\\Qorg/apache/dubbo/remoting/RemotingException.class\\E"
},
{
"pattern": "\\Qorg/apache/dubbo/remoting/Transporters.class\\E"
},
{
"pattern": "\\Qorg/apache/dubbo/remoting/exchange/Exchangers.class\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.store.DataStore\\E"
},
{
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.metrics.service.MetricsServiceExporter\\E"
},
{
"pattern": "\\Qsecurity/serialize.blockedlist\\E"
},
{
"pattern": "\\Qsecurity/serialize.allowlist\\E"
}
]
},
"bundles": []
}

View File

@ -218,13 +218,6 @@
<version>${project.version}</version>
</dependency>
<!-- native-plugin -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-native-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-maven-plugin</artifactId>

View File

@ -168,7 +168,6 @@
<module>dubbo-test</module>
<module>dubbo-kubernetes</module>
<module>dubbo-xds</module>
<module>dubbo-native-plugin</module>
<module>dubbo-maven-plugin</module>
</modules>