!125 bug:apt 不支持 gradle 项目

Merge pull request !125 from 王帅/main
This commit is contained in:
Michael Yang 2023-07-12 02:34:18 +00:00 committed by Gitee
commit 0f65bb324b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 118 additions and 76 deletions

View File

@ -18,6 +18,8 @@ package com.mybatisflex.annotation;
import java.lang.annotation.*; import java.lang.annotation.*;
/** /**
* 多对多映射
*
* @author michael * @author michael
*/ */
@Inherited @Inherited
@ -26,43 +28,42 @@ import java.lang.annotation.*;
public @interface RelationManyToMany { public @interface RelationManyToMany {
/** /**
* 当前 entity 的属性 * 当前实体类的属性
* *
* @return 属性名称 * @return 属性名称
*/ */
String selfField() default ""; String selfField() default "";
/** /**
* 目标对象的关联属性 * 目标实体类的关联属性
* *
* @return 属性名称 * @return 属性名称
*/ */
String targetField() default ""; String targetField() default "";
/** /**
* 中间表 * 中间表名称
* *
* @return 中间表名称 * @return 中间表名称
*/ */
String joinTable(); String joinTable();
/** /**
* 中间表与当前表的关联字段 * 中间表与当前表的关联字段
* *
* @return 字段名称列名 * @return 字段名称列名
*/ */
String joinSelfColumn(); String joinSelfColumn();
/** /**
* 目标表的关联字段名称 * 目标表的关联字段名称
* *
* @return 字段名称和表 * @return 字段名称和表
*/ */
String joinTargetColumn(); String joinTargetColumn();
/** /**
* 查询排序 * 查询排序
* *
* @return 排序方式 * @return 排序方式
*/ */
@ -70,6 +71,8 @@ public @interface RelationManyToMany {
/** /**
* 默认使用哪个数据源若系统找不到该指定的数据源时默认使用第一个数据源 * 默认使用哪个数据源若系统找不到该指定的数据源时默认使用第一个数据源
*
* @return 数据源
*/ */
String dataSource() default ""; String dataSource() default "";

View File

@ -18,6 +18,8 @@ package com.mybatisflex.annotation;
import java.lang.annotation.*; import java.lang.annotation.*;
/** /**
* 多对一映射
*
* @author michael * @author michael
*/ */
@Inherited @Inherited
@ -26,14 +28,14 @@ import java.lang.annotation.*;
public @interface RelationManyToOne { public @interface RelationManyToOne {
/** /**
* 当前 entity 的属性 * 当前实体类的属性
* *
* @return 属性名称 * @return 属性名称
*/ */
String selfField(); String selfField();
/** /**
* 目标对象的关联属性 * 目标实体类的关联属性
* *
* @return 属性名称 * @return 属性名称
*/ */
@ -41,6 +43,8 @@ public @interface RelationManyToOne {
/** /**
* 默认使用哪个数据源若系统找不到该指定的数据源时默认使用第一个数据源 * 默认使用哪个数据源若系统找不到该指定的数据源时默认使用第一个数据源
*
* @return 数据源
*/ */
String dataSource() default ""; String dataSource() default "";

View File

@ -18,6 +18,8 @@ package com.mybatisflex.annotation;
import java.lang.annotation.*; import java.lang.annotation.*;
/** /**
* 一对多映射
*
* @author michael * @author michael
*/ */
@Inherited @Inherited
@ -26,28 +28,28 @@ import java.lang.annotation.*;
public @interface RelationOneToMany { public @interface RelationOneToMany {
/** /**
* 当前 entity 的属性 * 当前实体类的属性
* *
* @return 属性名称 * @return 属性名称
*/ */
String selfField() default ""; String selfField() default "";
/** /**
* 目标对象的关联属性 * 目标实体类的关联属性
* *
* @return 属性名称 * @return 属性名称
*/ */
String targetField(); String targetField();
/** /**
* 查询排序 * 查询排序
* *
* @return 排序方式 * @return 排序方式
*/ */
String orderBy() default ""; String orderBy() default "";
/** /**
* 现在查询的数据量 * 现在查询的数据量
* *
* @return 数据量 * @return 数据量
*/ */
@ -55,6 +57,8 @@ public @interface RelationOneToMany {
/** /**
* 默认使用哪个数据源若系统找不到该指定的数据源时默认使用第一个数据源 * 默认使用哪个数据源若系统找不到该指定的数据源时默认使用第一个数据源
*
* @return 数据源
*/ */
String dataSource() default ""; String dataSource() default "";

View File

@ -18,6 +18,8 @@ package com.mybatisflex.annotation;
import java.lang.annotation.*; import java.lang.annotation.*;
/** /**
* 一对一映射
*
* @author michael * @author michael
*/ */
@Inherited @Inherited
@ -26,14 +28,14 @@ import java.lang.annotation.*;
public @interface RelationOneToOne { public @interface RelationOneToOne {
/** /**
* 当前 entity 的属性 * 当前实体类的属性
* *
* @return 属性名称 * @return 属性名称
*/ */
String selfField() default ""; String selfField() default "";
/** /**
* 目标对象的关联属性 * 目标实体类的关联属性
* *
* @return 属性名称 * @return 属性名称
*/ */
@ -41,6 +43,8 @@ public @interface RelationOneToOne {
/** /**
* 默认使用哪个数据源若系统找不到该指定的数据源时默认使用第一个数据源 * 默认使用哪个数据源若系统找不到该指定的数据源时默认使用第一个数据源
*
* @return 数据源
*/ */
String dataSource() default ""; String dataSource() default "";

View File

@ -36,6 +36,9 @@ import java.util.concurrent.ConcurrentHashMap;
*/ */
public class RelationManager { public class RelationManager {
private RelationManager() {
}
private static Map<Class<?>, List<AbstractRelation>> classRelations = new ConcurrentHashMap<>(); private static Map<Class<?>, List<AbstractRelation>> classRelations = new ConcurrentHashMap<>();
private static List<AbstractRelation> getRelations(Class<?> clazz) { private static List<AbstractRelation> getRelations(Class<?> clazz) {

View File

@ -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();

View File

@ -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);