mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 09:38:26 +08:00
fix: 兼容 gradle 项目。
This commit is contained in:
parent
3e08f85aca
commit
f9049765f4
@ -16,11 +16,17 @@
|
|||||||
|
|
||||||
package com.mybatisflex.processor.config;
|
package com.mybatisflex.processor.config;
|
||||||
|
|
||||||
|
import com.mybatisflex.processor.util.FileUtil;
|
||||||
|
|
||||||
import javax.annotation.processing.Filer;
|
import javax.annotation.processing.Filer;
|
||||||
import javax.tools.FileObject;
|
import javax.tools.FileObject;
|
||||||
import javax.tools.StandardLocation;
|
import javax.tools.StandardLocation;
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@ -49,8 +55,16 @@ public class MybatisFlexConfig {
|
|||||||
FileObject aptConfigFileObject = filer.getResource(StandardLocation.CLASS_OUTPUT, "", APT_FILE_NAME);
|
FileObject aptConfigFileObject = filer.getResource(StandardLocation.CLASS_OUTPUT, "", APT_FILE_NAME);
|
||||||
|
|
||||||
List<File> aptConfigFiles = new ArrayList<>();
|
List<File> aptConfigFiles = new ArrayList<>();
|
||||||
|
|
||||||
File moduleRoot = new File(aptConfigFileObject.toUri()).getParentFile().getParentFile().getParentFile();
|
File moduleRoot = new File(aptConfigFileObject.toUri()).getParentFile().getParentFile().getParentFile();
|
||||||
while (new File(moduleRoot, "pom.xml").exists()) {
|
|
||||||
|
// pom.xml -> Maven 项目
|
||||||
|
// build.gradle -> Gradle 项目
|
||||||
|
if (new File(moduleRoot, "build.gradle").exists()) {
|
||||||
|
FileUtil.setBuildFile("build.gradle");
|
||||||
|
}
|
||||||
|
|
||||||
|
while (FileUtil.existsBuildFile(moduleRoot)) {
|
||||||
File aptConfig = new File(moduleRoot, APT_FILE_NAME);
|
File aptConfig = new File(moduleRoot, APT_FILE_NAME);
|
||||||
if (aptConfig.exists()) {
|
if (aptConfig.exists()) {
|
||||||
aptConfigFiles.add(aptConfig);
|
aptConfigFiles.add(aptConfig);
|
||||||
@ -59,7 +73,7 @@ public class MybatisFlexConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (File aptConfigFile : aptConfigFiles) {
|
for (File aptConfigFile : aptConfigFiles) {
|
||||||
try (InputStream stream = new FileInputStream(aptConfigFile);
|
try (InputStream stream = Files.newInputStream(aptConfigFile.toPath());
|
||||||
Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
||||||
|
|
||||||
Properties config = new Properties();
|
Properties config = new Properties();
|
||||||
@ -71,7 +85,7 @@ public class MybatisFlexConfig {
|
|||||||
properties.put(key, config.getProperty((String) key));
|
properties.put(key, config.getProperty((String) key));
|
||||||
}
|
}
|
||||||
if ("processor.stopBubbling".equalsIgnoreCase((String) key)
|
if ("processor.stopBubbling".equalsIgnoreCase((String) key)
|
||||||
&& "true".equalsIgnoreCase(String.valueOf(config.getProperty((String) key)))) {
|
&& "true".equalsIgnoreCase(String.valueOf(config.getProperty((String) key)))) {
|
||||||
stopBubbling = true;
|
stopBubbling = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,16 @@ public class FileUtil {
|
|||||||
private FileUtil() {
|
private FileUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String buildFile = "pom.xml";
|
||||||
|
|
||||||
|
public static void setBuildFile(String buildFile) {
|
||||||
|
FileUtil.buildFile = buildFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean existsBuildFile(File file) {
|
||||||
|
return new File(file, buildFile).exists();
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isFromTestSource(String path) {
|
public static boolean isFromTestSource(String path) {
|
||||||
return path.contains("test-sources") || path.contains("test-annotations");
|
return path.contains("test-sources") || path.contains("test-annotations");
|
||||||
}
|
}
|
||||||
@ -53,7 +63,7 @@ public class FileUtil {
|
|||||||
if (file.isFile()) {
|
if (file.isFile()) {
|
||||||
return getProjectRootPath(file.getParentFile(), --count);
|
return getProjectRootPath(file.getParentFile(), --count);
|
||||||
} else {
|
} else {
|
||||||
if (new File(file, "pom.xml").exists() && !new File(file.getParentFile(), "pom.xml").exists()) {
|
if (new File(file, buildFile).exists() && !new File(file.getParentFile(), buildFile).exists()) {
|
||||||
return file.getAbsolutePath();
|
return file.getAbsolutePath();
|
||||||
} else {
|
} else {
|
||||||
return getProjectRootPath(file.getParentFile(), --count);
|
return getProjectRootPath(file.getParentFile(), --count);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user