[3.0]Fix native-image plugin not compatible with Windows OS (#9756)
This commit is contained in:
parent
bd5c620946
commit
0d453ad146
|
|
@ -127,7 +127,7 @@
|
|||
<encoding>UTF-8</encoding>
|
||||
<compilerArguments>
|
||||
<sourcepath>
|
||||
${project.basedir}/src/main/java
|
||||
${project.basedir}${file.separator}src${file.separator}main${file.separator}java
|
||||
</sourcepath>
|
||||
</compilerArguments>
|
||||
</configuration>
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@
|
|||
<encoding>UTF-8</encoding>
|
||||
<compilerArguments>
|
||||
<sourcepath>
|
||||
${project.basedir}/src/main/java
|
||||
${project.basedir}${file.separator}src${file.separator}main${file.separator}java
|
||||
</sourcepath>
|
||||
</compilerArguments>
|
||||
</configuration>
|
||||
|
|
|
|||
|
|
@ -23,16 +23,19 @@ 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;
|
||||
|
||||
/**
|
||||
|
|
@ -76,12 +79,12 @@ public class CodeGenerator {
|
|||
}
|
||||
AdaptiveClassCodeGenerator codeGenerator = new AdaptiveClassCodeGenerator(it, value);
|
||||
String code = codeGenerator.generate();
|
||||
String file = p + File.separator + it.getName().replaceAll("\\.", File.separator);
|
||||
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);
|
||||
FileUtils.write(tmpFile, code, Charset.defaultCharset());
|
||||
log.info("Generate file:" + tmpFile);
|
||||
} catch (Throwable e) {
|
||||
log.error("error:" + it.getPackage());
|
||||
|
|
@ -93,8 +96,9 @@ public class CodeGenerator {
|
|||
|
||||
public static void main(String[] args) {
|
||||
URL r = Thread.currentThread().getContextClassLoader().getResource("");
|
||||
String p = Paths.get(r.getFile()).getParent().getParent().toString() + File.separator + "src" + File.separator + "main" + File.separator + "java";
|
||||
execute(p, null);
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class DubboNativeCodeGeneratorMojo extends AbstractMojo {
|
|||
|
||||
private void generateCode(Log log, MavenProject project) throws IOException {
|
||||
String baseDir = project.getBasedir().getPath();
|
||||
File source = new File(baseDir + "/src/main/generated");
|
||||
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.");
|
||||
|
|
@ -71,8 +71,8 @@ public class DubboNativeCodeGeneratorMojo extends AbstractMojo {
|
|||
project.getResources().stream().findFirst().ifPresent(resource -> {
|
||||
String directory = resource.getDirectory();
|
||||
try {
|
||||
FileUtils.forceMkdir(new File(directory + "/META-INF/native-image/"));
|
||||
File file = new File(directory + "/" + nativeFile);
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -28,11 +28,13 @@ import java.io.IOException;
|
|||
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;
|
||||
|
||||
/**
|
||||
|
|
@ -42,7 +44,8 @@ public class CodeGenerator {
|
|||
|
||||
public static void main(String[] args) {
|
||||
URL r = Thread.currentThread().getContextClassLoader().getResource("");
|
||||
String p = Paths.get(r.getFile()).getParent().getParent().toString() + File.separator + "src" + File.separator + "main" + File.separator + "java";
|
||||
String targetClassPath = new File(r.getFile()).getAbsolutePath();
|
||||
String p = Paths.get(targetClassPath).getParent().getParent().toString() + File.separator + "src" + File.separator + "main" + File.separator + "java";
|
||||
System.out.println(p);
|
||||
|
||||
List<Class<?>> classes = new ClassFinder().findClassSet("org.apache.dubbo").stream().map(it -> {
|
||||
|
|
@ -73,11 +76,11 @@ public class CodeGenerator {
|
|||
System.out.println(code);
|
||||
System.out.println("-----:" + it.getPackage());
|
||||
try {
|
||||
String file = p + File.separator + it.getName().replaceAll("\\.", File.separator);
|
||||
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";
|
||||
FileUtils.write(new File(file + "$Adaptive.java"), code);
|
||||
FileUtils.write(new File(file + "$Adaptive.java"), code, Charset.defaultCharset());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue