Compare commits
43 Commits
Author | SHA1 | Date | |
---|---|---|---|
5dbfaa1bfd | |||
bde2594a61 | |||
846112de99 | |||
b4a616c25f | |||
1a59a81e61 | |||
77ff3490f0 | |||
cb5ec112dd | |||
713812b8fe | |||
5513875653 | |||
bcc5751c9b | |||
cf59715356 | |||
b085d83c97 | |||
d46c9533fe | |||
27e764ef11 | |||
2f222bb305 | |||
4b6f7dcd84 | |||
bc644fe2f0 | |||
7abf98d9cb | |||
7d70c0562e | |||
a130da9f91 | |||
16597aebd2 | |||
c50b0f6fb4 | |||
caae59207f | |||
13249271fb | |||
4deea3aa3f | |||
41dae5442f | |||
6cfca087f7 | |||
11e67b1c18 | |||
3e7c100982 | |||
3e720c380d | |||
8e79e74c0b | |||
f83a3b235f | |||
9bda2b6a56 | |||
5dc69b034f | |||
59ce9db326 | |||
1eb1cdc53a | |||
cbfedf3aad | |||
91a40cdd14 | |||
4563ce2c4e | |||
e759449bc6 | |||
|
9f41dde9ec | ||
|
6d707cf8c8 | ||
|
ed5d5bd91f |
111
.drone.yml
Normal file
111
.drone.yml
Normal file
@ -0,0 +1,111 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: snapshot-publish
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- develop
|
||||
|
||||
volumes:
|
||||
- name: m2
|
||||
host:
|
||||
path: /drone/volume/m2
|
||||
|
||||
image_pull_secrets:
|
||||
- DOCKER_AUTH
|
||||
|
||||
steps:
|
||||
- name: publish
|
||||
image: hub.docker.struchkov.dev/maven:3.9-eclipse-temurin-17-alpine
|
||||
privileged: true
|
||||
volumes:
|
||||
- name: m2
|
||||
path: /root/.m2/repository
|
||||
environment:
|
||||
MAVEN_SETTINGS:
|
||||
from_secret: MAVEN_SETTINGS
|
||||
commands:
|
||||
- echo "$MAVEN_SETTINGS" >> maven-settings.xml
|
||||
- mvn --settings maven-settings.xml -U -P snapshot clean deploy
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: release-maven-central
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/tags/v.*.*.*
|
||||
|
||||
volumes:
|
||||
- name: m2
|
||||
host:
|
||||
path: /drone/volume/m2
|
||||
|
||||
image_pull_secrets:
|
||||
- DOCKER_AUTH
|
||||
|
||||
steps:
|
||||
- name: publish maven central
|
||||
image: hub.docker.struchkov.dev/maven:3.9-eclipse-temurin-17-alpine
|
||||
privileged: true
|
||||
volumes:
|
||||
- name: m2
|
||||
path: /root/.m2/repository
|
||||
environment:
|
||||
GPG_PRIVATE_KEY:
|
||||
from_secret: GPG_PRIVATE_KEY
|
||||
MAVEN_SETTINGS:
|
||||
from_secret: MAVEN_SETTINGS
|
||||
GPG_PASSPHRASE:
|
||||
from_secret: GPG_PASSPHRASE
|
||||
commands:
|
||||
- apk add gnupg
|
||||
- echo "$GPG_PRIVATE_KEY" >> gpg.key
|
||||
- echo "$MAVEN_SETTINGS" >> maven-settings.xml
|
||||
- gpg --pinentry-mode loopback --passphrase $GPG_PASSPHRASE --import gpg.key
|
||||
- mvn --settings maven-settings.xml -U -P ossrh,release clean deploy
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: release-struchkov-nexus
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/tags/v.*.*.*
|
||||
|
||||
volumes:
|
||||
- name: m2
|
||||
host:
|
||||
path: /drone/volume/m2
|
||||
|
||||
image_pull_secrets:
|
||||
- DOCKER_AUTH
|
||||
|
||||
steps:
|
||||
- name: publish struchkov nexus
|
||||
image: hub.docker.struchkov.dev/maven:3.9-eclipse-temurin-17-alpine
|
||||
privileged: true
|
||||
volumes:
|
||||
- name: m2
|
||||
path: /root/.m2/repository
|
||||
environment:
|
||||
GPG_PRIVATE_KEY:
|
||||
from_secret: GPG_PRIVATE_KEY
|
||||
MAVEN_SETTINGS:
|
||||
from_secret: MAVEN_SETTINGS
|
||||
GPG_PASSPHRASE:
|
||||
from_secret: GPG_PASSPHRASE
|
||||
commands:
|
||||
- apk add gnupg
|
||||
- echo "$GPG_PRIVATE_KEY" >> gpg.key
|
||||
- echo "$MAVEN_SETTINGS" >> maven-settings.xml
|
||||
- gpg --pinentry-mode loopback --passphrase $GPG_PASSPHRASE --import gpg.key
|
||||
- mvn --settings maven-settings.xml -U -P ossrh,release-struchkov-nexus clean deploy
|
||||
---
|
||||
kind: signature
|
||||
hmac: 62899422b538523cb09e3756b7bebe1658e4093f6c6a3e2dd8c9c8f872558e54
|
||||
|
||||
...
|
21
.gitignore
vendored
21
.gitignore
vendored
@ -20,34 +20,16 @@ dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
.idea/**/contentModel.xml
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
.idea/
|
||||
cmake-build-*/
|
||||
.idea/**/mongoSettings.xml
|
||||
*.iws
|
||||
out/
|
||||
.idea_modules/
|
||||
atlassian-ide-plugin.xml
|
||||
.idea/replstate.xml
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
.idea/httpRequests
|
||||
.idea/caches/build_file_checksums.ser
|
||||
*~
|
||||
.fuse_hidden*
|
||||
.directory
|
||||
@ -83,3 +65,4 @@ Icon
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
/haiti-field-constants-utils.iml
|
||||
|
@ -1,17 +0,0 @@
|
||||
image: maven:3.8.4-openjdk-11
|
||||
variables:
|
||||
MAVEN_OPTS: "-Dmaven.repo.local=./.m2/repository"
|
||||
|
||||
stages:
|
||||
- deploy
|
||||
|
||||
deploy:
|
||||
stage: deploy
|
||||
only:
|
||||
- /^v.*$/
|
||||
except:
|
||||
- branches
|
||||
before_script:
|
||||
- gpg --pinentry-mode loopback --passphrase $GPG_PASSPHRASE --import $GPG_PRIVATE_KEY
|
||||
script:
|
||||
- 'mvn --settings $MAVEN_SETTINGS -U -P ossrh,release clean deploy'
|
29
pom.xml
29
pom.xml
@ -1,17 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>dev.struchkov.haiti</groupId>
|
||||
<artifactId>haiti</artifactId>
|
||||
<version>0.0.4</version>
|
||||
<artifactId>haiti-dependencies</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</parent>
|
||||
|
||||
<groupId>dev.struchkov.haiti.utils</groupId>
|
||||
<artifactId>haiti-utils-field-constants</artifactId>
|
||||
<version>0.0.4</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
|
||||
<name>Haiti Field Name Constants Utils</name>
|
||||
<description>Generating class field names</description>
|
||||
@ -22,7 +20,7 @@
|
||||
</issueManagement>
|
||||
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
<java.version>17</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@ -35,8 +33,8 @@
|
||||
<artifactId>haiti-utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>javax.persistence-api</artifactId>
|
||||
<groupId>jakarta.persistence</groupId>
|
||||
<artifactId>jakarta.persistence-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.auto.service</groupId>
|
||||
@ -54,9 +52,11 @@
|
||||
<path>
|
||||
<groupId>com.google.auto.service</groupId>
|
||||
<artifactId>auto-service</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>${google.auto.service.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
@ -71,9 +71,10 @@
|
||||
</build>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/haiti-projects/haiti-utils-field-constants.git</connection>
|
||||
<url>https://github.com/haiti-projects/haiti-utils-field-constants</url>
|
||||
<developerConnection>scm:git:https://github.com/haiti-projects/haiti-utils-field-constants.git</developerConnection>
|
||||
</scm>
|
||||
<connection>scm:git:https://git.struchkov.dev/Haiti/haiti-utils-field-constants.git</connection>
|
||||
<url>https://git.struchkov.dev/Haiti/haiti-utils-field-constants</url>
|
||||
<developerConnection>scm:git:https://git.struchkov.dev/Haiti/haiti-utils-field-constants.git</developerConnection>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
</project>
|
@ -0,0 +1,59 @@
|
||||
package dev.struchkov.haiti.utils.fieldconstants.creator;
|
||||
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.simple.ClassSimpleDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.simple.SimpleFieldDto;
|
||||
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.tools.JavaFileObject;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
/**
|
||||
* // TODO: 20.06.2021 Добавить описание.
|
||||
*
|
||||
* @author upagge 20.06.2021
|
||||
*/
|
||||
public final class CreatorClassSimpleMode {
|
||||
|
||||
private CreatorClassSimpleMode() {
|
||||
utilityClass();
|
||||
}
|
||||
|
||||
public static void record(ClassSimpleDto classDto, ProcessingEnvironment environment) {
|
||||
JavaFileObject builderFile = null;
|
||||
try {
|
||||
builderFile = environment.getFiler().createSourceFile(classDto.getNewClassName());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try (PrintWriter out = new PrintWriter(builderFile.openWriter())) {
|
||||
out.println("package " + classDto.getClassPackage() + ";");
|
||||
out.println();
|
||||
out.println();
|
||||
out.println(format("public class {0} '{'", classDto.getNewClassName()));
|
||||
out.println();
|
||||
out.println(format(" public static final String CLASS_NAME = \"{0}\";", classDto.getOldClassName()));
|
||||
out.println(format(" public static final String PACKAGE_AND_CLASS_NAME = \"{0}\";", classDto.getClassPackage() + "." + classDto.getOldClassName()));
|
||||
out.println();
|
||||
generateSimpleNames(classDto.getSimpleFields(), out);
|
||||
out.println("}");
|
||||
out.println();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void generateSimpleNames(Collection<SimpleFieldDto> fields, PrintWriter out) {
|
||||
for (SimpleFieldDto field : fields) {
|
||||
out.println(format(" public static final String {0} = \"{1}\";", field.getFieldName(), field.getFieldName()));
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package dev.struchkov.haiti.utils.fieldconstants;
|
||||
package dev.struchkov.haiti.utils.fieldconstants.creator;
|
||||
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.ClassTableDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinElemCollectionDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinFieldDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinTableContainer;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.SimpleFieldTableDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.SimpleTableFieldDto;
|
||||
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.tools.JavaFileObject;
|
||||
@ -13,6 +13,7 @@ import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
|
||||
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
@ -26,6 +27,11 @@ public final class CreatorClassTableMode {
|
||||
private static final String TABLE_NAME_DEFAULT = "TABLE_NAME";
|
||||
private static final String TABLE_NAME_DB = "DB_TABLE_NAME";
|
||||
|
||||
private static final String SCHEMA_NAME_DEFAULT = "SCHEMA_NAME";
|
||||
private static final String SCHEMA_NAME_DB = "DB_SCHEMA_NAME";
|
||||
|
||||
private static final String SCHEMA_AND_TABLE = "SCHEMA_AND_TABLE";
|
||||
|
||||
private CreatorClassTableMode() {
|
||||
utilityClass();
|
||||
}
|
||||
@ -33,7 +39,7 @@ public final class CreatorClassTableMode {
|
||||
public static void record(ClassTableDto classDto, ProcessingEnvironment environment) {
|
||||
JavaFileObject builderFile = null;
|
||||
try {
|
||||
builderFile = environment.getFiler().createSourceFile(classDto.getClassName());
|
||||
builderFile = environment.getFiler().createSourceFile(classDto.getClassPackage() + "." + classDto.getClassName());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -47,6 +53,8 @@ public final class CreatorClassTableMode {
|
||||
out.println();
|
||||
out.println();
|
||||
generateTableName(classDto.getTableName(), classDto.getSimpleFields(), out);
|
||||
generateTableSchema(classDto.getTableSchema(), classDto.getSimpleFields(), out);
|
||||
generateTableSchemaAndTable(classDto.getTableSchema(), classDto.getTableName(), out);
|
||||
generateSimpleNames(classDto.getSimpleFields(), out);
|
||||
generateJoinNames(classDto.getJoinFields(), out);
|
||||
generateElementCollectionNames(classDto.getJoinElemCollections(), out);
|
||||
@ -63,22 +71,42 @@ public final class CreatorClassTableMode {
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateTableName(String tableName, Collection<SimpleFieldTableDto> fields, PrintWriter out) {
|
||||
private static void generateTableName(String tableName, Collection<SimpleTableFieldDto> fields, PrintWriter out) {
|
||||
if (tableName != null) {
|
||||
final boolean isTableNameField = fields.stream().anyMatch(simpleFieldTableDto -> simpleFieldTableDto.getFieldStringName().equalsIgnoreCase(TABLE_NAME_DEFAULT));
|
||||
out.println(format(" public static final String {0} = \"{1}\";", isTableNameField ? TABLE_NAME_DB : TABLE_NAME_DEFAULT, tableName));
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
|
||||
private static void generateSimpleNames(Collection<SimpleFieldTableDto> fields, PrintWriter out) {
|
||||
for (SimpleFieldTableDto field : fields) {
|
||||
private static void generateTableSchema(String tableSchema, Collection<SimpleTableFieldDto> fields, PrintWriter out) {
|
||||
if (tableSchema != null && !"".equals(tableSchema)) {
|
||||
final boolean isTableSchemaField = fields.stream().anyMatch(simpleFieldTableDto -> simpleFieldTableDto.getFieldStringName().equalsIgnoreCase(TABLE_NAME_DEFAULT));
|
||||
out.println(format(" public static final String {0} = \"{1}\";", isTableSchemaField ? SCHEMA_NAME_DB : SCHEMA_NAME_DEFAULT, tableSchema));
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateTableSchemaAndTable(String tableSchema, String tableName, PrintWriter out) {
|
||||
if (tableSchema != null && tableName != null && !"".equals(tableSchema)) {
|
||||
out.println(format(" public static final String {0} = \"{1}\";", SCHEMA_AND_TABLE, tableSchema + "." + tableName));
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateSimpleNames(Collection<SimpleTableFieldDto> fields, PrintWriter out) {
|
||||
if (checkNotEmpty(fields)) {
|
||||
out.println();
|
||||
}
|
||||
for (SimpleTableFieldDto field : fields) {
|
||||
out.println(format(" public static final String {0} = \"{1}\";", field.getFieldStringName(), field.getFieldName()));
|
||||
}
|
||||
out.println();
|
||||
if (checkNotEmpty(fields)) {
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateJoinNames(List<JoinFieldDto> joinFields, PrintWriter out) {
|
||||
if (checkNotEmpty(joinFields)) {
|
||||
out.println();
|
||||
}
|
||||
for (JoinFieldDto joinField : joinFields) {
|
||||
final JoinTableContainer container = joinField.getContainer();
|
||||
out.println(
|
||||
@ -88,10 +116,15 @@ public final class CreatorClassTableMode {
|
||||
)
|
||||
);
|
||||
}
|
||||
out.println();
|
||||
if (checkNotEmpty(joinFields)) {
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateElementCollectionNames(List<JoinElemCollectionDto> joinElemCollections, PrintWriter out) {
|
||||
if (checkNotEmpty(joinElemCollections)) {
|
||||
out.println();
|
||||
}
|
||||
for (JoinElemCollectionDto element : joinElemCollections) {
|
||||
final String fieldName = element.getFieldName();
|
||||
final JoinTableContainer firstContainer = element.getFirstContainer();
|
||||
@ -101,7 +134,9 @@ public final class CreatorClassTableMode {
|
||||
out.println(format(" JoinTable.ofLeft(\"{0}\", \"{1}\", \"{2}\")", secondContainer.getTable(), secondContainer.getBaseId(), secondContainer.getReference()));
|
||||
out.println(" };");
|
||||
}
|
||||
out.println();
|
||||
if (checkNotEmpty(joinElemCollections)) {
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package dev.struchkov.haiti.utils.fieldconstants.domain.mode.simple;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ClassSimpleDto {
|
||||
|
||||
private String classPackage;
|
||||
private String newClassName;
|
||||
private String oldClassName;
|
||||
private List<SimpleFieldDto> simpleFields;
|
||||
|
||||
public String getClassPackage() {
|
||||
return classPackage;
|
||||
}
|
||||
|
||||
public void setClassPackage(String classPackage) {
|
||||
this.classPackage = classPackage;
|
||||
}
|
||||
|
||||
public String getNewClassName() {
|
||||
return newClassName;
|
||||
}
|
||||
|
||||
public void setNewClassName(String newClassName) {
|
||||
this.newClassName = newClassName;
|
||||
}
|
||||
|
||||
public String getOldClassName() {
|
||||
return oldClassName;
|
||||
}
|
||||
|
||||
public void setOldClassName(String oldClassName) {
|
||||
this.oldClassName = oldClassName;
|
||||
}
|
||||
|
||||
public List<SimpleFieldDto> getSimpleFields() {
|
||||
return simpleFields;
|
||||
}
|
||||
|
||||
public void setSimpleFields(List<SimpleFieldDto> simpleFields) {
|
||||
this.simpleFields = simpleFields;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package dev.struchkov.haiti.utils.fieldconstants.domain.mode.simple;
|
||||
|
||||
/**
|
||||
* // TODO: 07.06.2021 Добавить описание.
|
||||
*
|
||||
* @author upagge 07.06.2021
|
||||
*/
|
||||
public class SimpleFieldDto {
|
||||
|
||||
private final String fieldName;
|
||||
|
||||
private SimpleFieldDto(String fieldName) {
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
public static SimpleFieldDto of(String fieldName) {
|
||||
return new SimpleFieldDto(fieldName);
|
||||
}
|
||||
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
}
|
@ -7,7 +7,8 @@ public class ClassTableDto {
|
||||
private String classPackage;
|
||||
private String className;
|
||||
private String tableName;
|
||||
private List<SimpleFieldTableDto> simpleFields;
|
||||
private String tableSchema;
|
||||
private List<SimpleTableFieldDto> simpleFields;
|
||||
private List<JoinFieldDto> joinFields;
|
||||
private List<JoinElemCollectionDto> joinElemCollections;
|
||||
|
||||
@ -35,11 +36,19 @@ public class ClassTableDto {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public List<SimpleFieldTableDto> getSimpleFields() {
|
||||
public String getTableSchema() {
|
||||
return tableSchema;
|
||||
}
|
||||
|
||||
public void setTableSchema(String tableSchema) {
|
||||
this.tableSchema = tableSchema;
|
||||
}
|
||||
|
||||
public List<SimpleTableFieldDto> getSimpleFields() {
|
||||
return simpleFields;
|
||||
}
|
||||
|
||||
public void setSimpleFields(List<SimpleFieldTableDto> simpleFields) {
|
||||
public void setSimpleFields(List<SimpleTableFieldDto> simpleFields) {
|
||||
this.simpleFields = simpleFields;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.haiti.utils.fieldconstants.domain.mode.table;
|
||||
|
||||
import dev.struchkov.haiti.utils.Assert;
|
||||
import dev.struchkov.haiti.utils.Inspector;
|
||||
|
||||
public class JoinElemCollectionDto {
|
||||
|
||||
@ -15,7 +15,7 @@ public class JoinElemCollectionDto {
|
||||
}
|
||||
|
||||
public static JoinElemCollectionDto of(String fieldName, JoinTableContainer firstContainer, JoinTableContainer secondContainer) {
|
||||
Assert.isNotNull(fieldName, firstContainer, secondContainer);
|
||||
Inspector.isNotNull(fieldName, firstContainer, secondContainer);
|
||||
return new JoinElemCollectionDto(fieldName, firstContainer, secondContainer);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.haiti.utils.fieldconstants.domain.mode.table;
|
||||
|
||||
import dev.struchkov.haiti.utils.Assert;
|
||||
import dev.struchkov.haiti.utils.Inspector;
|
||||
|
||||
public class JoinFieldDto {
|
||||
|
||||
@ -13,7 +13,7 @@ public class JoinFieldDto {
|
||||
}
|
||||
|
||||
public static JoinFieldDto of(String fieldName, JoinTableContainer container) {
|
||||
Assert.isNotNull(fieldName, container);
|
||||
Inspector.isNotNull(fieldName, container);
|
||||
return new JoinFieldDto(fieldName, container);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.haiti.utils.fieldconstants.domain.mode.table;
|
||||
|
||||
import dev.struchkov.haiti.utils.Assert;
|
||||
import dev.struchkov.haiti.utils.Inspector;
|
||||
|
||||
public class JoinTableContainer {
|
||||
|
||||
@ -15,7 +15,7 @@ public class JoinTableContainer {
|
||||
}
|
||||
|
||||
public static JoinTableContainer of(String table, String baseId, String reference) {
|
||||
Assert.isNotNull(table, baseId, reference);
|
||||
Inspector.isNotNull(table, baseId, reference);
|
||||
return new JoinTableContainer(table, baseId, reference);
|
||||
}
|
||||
|
||||
|
@ -5,18 +5,18 @@ package dev.struchkov.haiti.utils.fieldconstants.domain.mode.table;
|
||||
*
|
||||
* @author upagge 07.06.2021
|
||||
*/
|
||||
public class SimpleFieldTableDto {
|
||||
public class SimpleTableFieldDto {
|
||||
|
||||
private final String fieldStringName;
|
||||
private final String fieldName;
|
||||
|
||||
private SimpleFieldTableDto(String fieldStringName, String fieldName) {
|
||||
private SimpleTableFieldDto(String fieldStringName, String fieldName) {
|
||||
this.fieldStringName = fieldStringName;
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
public static SimpleFieldTableDto of(String fieldStringName, String fieldName) {
|
||||
return new SimpleFieldTableDto(fieldStringName, fieldName);
|
||||
public static SimpleTableFieldDto of(String fieldStringName, String fieldName) {
|
||||
return new SimpleTableFieldDto(fieldStringName, fieldName);
|
||||
}
|
||||
|
||||
public String getFieldStringName() {
|
@ -0,0 +1,46 @@
|
||||
package dev.struchkov.haiti.utils.fieldconstants.generator;
|
||||
|
||||
import dev.struchkov.haiti.utils.fieldconstants.creator.CreatorClassSimpleMode;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.Mode;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.simple.ClassSimpleDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.simple.SimpleFieldDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.util.Generator;
|
||||
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.Element;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static dev.struchkov.haiti.utils.fieldconstants.util.Generator.getPackage;
|
||||
|
||||
public class GeneratorSimpleMode {
|
||||
|
||||
public static void generate(ProcessingEnvironment processingEnv, Element annotatedElement) {
|
||||
final String oldClassName = annotatedElement.getSimpleName().toString();
|
||||
|
||||
final List<? extends Element> allFields = annotatedElement.getEnclosedElements().stream()
|
||||
.filter(Generator::isField)
|
||||
.filter(Generator::isNotIgnoreField)
|
||||
.toList();
|
||||
|
||||
final List<SimpleFieldDto> simpleFields = getSimpleFields(allFields);
|
||||
|
||||
final ClassSimpleDto newClass = new ClassSimpleDto();
|
||||
newClass.setNewClassName(oldClassName + Mode.SIMPLE.getDefaultPostfix());
|
||||
newClass.setOldClassName(oldClassName);
|
||||
newClass.setSimpleFields(simpleFields);
|
||||
newClass.setClassPackage(getPackage(annotatedElement));
|
||||
|
||||
CreatorClassSimpleMode.record(newClass, processingEnv);
|
||||
}
|
||||
|
||||
private static List<SimpleFieldDto> getSimpleFields(List<? extends Element> allFields) {
|
||||
final List<SimpleFieldDto> resultList = new ArrayList<>();
|
||||
for (Element field : allFields) {
|
||||
final String fieldName = field.getSimpleName().toString();
|
||||
resultList.add(SimpleFieldDto.of(fieldName));
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package dev.struchkov.haiti.utils.fieldconstants.generator;
|
||||
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.field.ElementCollectionField;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.field.JoinField;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.setting.TableModeSettings;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.creator.CreatorClassTableMode;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.Mode;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.ClassTableDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinElemCollectionDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinFieldDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinTableContainer;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.SimpleTableFieldDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.util.Generator;
|
||||
import jakarta.persistence.CollectionTable;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.Element;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
|
||||
public class GeneratorTableMode {
|
||||
|
||||
public static void generate(ProcessingEnvironment processingEnv, TableModeSettings tableSettings, Element annotatedElement) {
|
||||
final String annotatedElementName = annotatedElement.getSimpleName().toString();
|
||||
|
||||
final Table anTable = annotatedElement.getAnnotation(Table.class);
|
||||
final String newClassName = annotatedElementName + Mode.TABLE.getDefaultPostfix();
|
||||
|
||||
final List<? extends Element> allFields = annotatedElement.getEnclosedElements().stream()
|
||||
.filter(Generator::isField)
|
||||
.filter(Generator::isNotIgnoreField)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final List<SimpleTableFieldDto> simpleFields = getSimpleFields(allFields, anTable, tableSettings);
|
||||
final List<JoinFieldDto> joinFields = getJoinFields(allFields);
|
||||
final List<JoinElemCollectionDto> elementCollectionFields = getElementCollectionsFields(anTable, allFields);
|
||||
|
||||
final ClassTableDto newClass = new ClassTableDto();
|
||||
newClass.setClassName(newClassName);
|
||||
newClass.setSimpleFields(simpleFields);
|
||||
newClass.setJoinFields(joinFields);
|
||||
newClass.setJoinElemCollections(elementCollectionFields);
|
||||
newClass.setClassPackage(Generator.getPackage(annotatedElement));
|
||||
newClass.setTableName(checkNotNull(anTable) ? anTable.name() : null);
|
||||
newClass.setTableSchema(checkNotNull(anTable) ? anTable.schema() : null);
|
||||
CreatorClassTableMode.record(newClass, processingEnv);
|
||||
}
|
||||
|
||||
private static List<JoinElemCollectionDto> getElementCollectionsFields(Table tableName, List<? extends Element> allFields) {
|
||||
if (checkNotNull(tableName)) {
|
||||
return allFields.stream()
|
||||
.filter(
|
||||
field -> field.getAnnotation(ElementCollectionField.class) != null &&
|
||||
field.getAnnotation(CollectionTable.class) != null &&
|
||||
field.getAnnotation(Column.class) != null
|
||||
)
|
||||
.map(field -> {
|
||||
final String fieldName = field.getSimpleName().toString();
|
||||
final ElementCollectionField elementCollectionField = field.getAnnotation(ElementCollectionField.class);
|
||||
final CollectionTable collectionTable = field.getAnnotation(CollectionTable.class);
|
||||
final Column column = field.getAnnotation(Column.class);
|
||||
|
||||
final JoinTableContainer firstContainer = JoinTableContainer.of(collectionTable.name(), tableName + "." + elementCollectionField.parentId(), collectionTable.joinColumns()[0].name());
|
||||
final JoinTableContainer secondContainer = JoinTableContainer.of(elementCollectionField.childTable(), column.name(), elementCollectionField.childReference());
|
||||
return JoinElemCollectionDto.of(fieldName, firstContainer, secondContainer);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static List<JoinFieldDto> getJoinFields(List<? extends Element> allFields) {
|
||||
return allFields.stream()
|
||||
.filter(
|
||||
field -> field.getAnnotation(JoinField.class) != null &&
|
||||
field.getAnnotation(ElementCollection.class) == null
|
||||
)
|
||||
.map(field -> {
|
||||
final String fieldName = field.getSimpleName().toString();
|
||||
final JoinField joinField = field.getAnnotation(JoinField.class);
|
||||
final JoinTableContainer joinContainer = JoinTableContainer.of(joinField.table(), joinField.baseId(), joinField.reference());
|
||||
return JoinFieldDto.of(fieldName, joinContainer);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static List<SimpleTableFieldDto> getSimpleFields(List<? extends Element> allFields, Table anTable, TableModeSettings tableSettings) {
|
||||
final boolean prefixTableForColumn = tableSettings.prefixTableForColumn();
|
||||
final List<SimpleTableFieldDto> resultList = new ArrayList<>();
|
||||
allFields.stream()
|
||||
.filter(
|
||||
field -> field.getAnnotation(Column.class) != null &&
|
||||
field.getAnnotation(ElementCollection.class) == null
|
||||
)
|
||||
.forEach(
|
||||
field -> {
|
||||
final String fieldName = field.getSimpleName().toString();
|
||||
final String columnName = field.getAnnotation(Column.class).name();
|
||||
if (prefixTableForColumn && checkNotNull(anTable)) {
|
||||
final String tableNameAndColumnName = anTable.name() + "." + columnName;
|
||||
resultList.add(SimpleTableFieldDto.of("t_" + fieldName, tableNameAndColumnName));
|
||||
}
|
||||
resultList.add(SimpleTableFieldDto.of(fieldName, columnName));
|
||||
}
|
||||
);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +1,11 @@
|
||||
package dev.struchkov.haiti.utils.fieldconstants.processor;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.CreatorClassTableMode;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.field.ElementCollectionField;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.field.IgnoreField;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.field.JoinField;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.setting.TableModeSettings;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.Mode;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.ClassTableDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinElemCollectionDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinFieldDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinTableContainer;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.SimpleFieldTableDto;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.generator.GeneratorSimpleMode;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.generator.GeneratorTableMode;
|
||||
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
import javax.annotation.processing.Processor;
|
||||
@ -22,19 +15,10 @@ import javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Table;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SupportedAnnotationTypes("dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames")
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_11)
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_17)
|
||||
@AutoService(Processor.class)
|
||||
public class FieldNameProcessor extends AbstractProcessor {
|
||||
|
||||
@ -43,110 +27,20 @@ public class FieldNameProcessor extends AbstractProcessor {
|
||||
for (TypeElement annotation : set) {
|
||||
Set<? extends Element> annotatedElements = roundEnvironment.getElementsAnnotatedWith(annotation);
|
||||
for (Element annotatedElement : annotatedElements) {
|
||||
final TypeMirror mirror = annotatedElement.asType();
|
||||
final String annotatedElementName = annotatedElement.getSimpleName().toString();
|
||||
final FieldNames settings = annotatedElement.getAnnotation(FieldNames.class);
|
||||
|
||||
final Set<Mode> modes = Arrays.stream(settings.mode()).collect(Collectors.toUnmodifiableSet());
|
||||
final Set<Mode> modes = Set.of(settings.mode());
|
||||
if (modes.contains(Mode.TABLE)) {
|
||||
final TableModeSettings tableSettings = settings.tableSettings();
|
||||
generateTableMode(tableSettings, annotatedElement, mirror, annotatedElementName);
|
||||
GeneratorTableMode.generate(processingEnv, tableSettings, annotatedElement);
|
||||
}
|
||||
if (modes.contains(Mode.SIMPLE)) {
|
||||
GeneratorSimpleMode.generate(processingEnv, annotatedElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void generateTableMode(TableModeSettings tableSettings, Element annotatedElement, TypeMirror mirror, String annotatedElementName) {
|
||||
final Table anTable = annotatedElement.getAnnotation(Table.class);
|
||||
final String newClassName = annotatedElementName + Mode.TABLE.getDefaultPostfix();
|
||||
|
||||
final List<? extends Element> allFields = annotatedElement.getEnclosedElements().stream()
|
||||
.filter(this::isField)
|
||||
.filter(this::isNotIgnoreField)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final List<SimpleFieldTableDto> simpleFields = getSimpleFields(allFields, anTable, tableSettings);
|
||||
final List<JoinFieldDto> joinFields = getJoinFields(allFields);
|
||||
final List<JoinElemCollectionDto> elementCollectionFields = getElementCollectionsFields(anTable.name(), allFields);
|
||||
|
||||
final ClassTableDto newClass = new ClassTableDto();
|
||||
newClass.setClassName(newClassName);
|
||||
newClass.setSimpleFields(simpleFields);
|
||||
newClass.setJoinFields(joinFields);
|
||||
newClass.setJoinElemCollections(elementCollectionFields);
|
||||
newClass.setClassPackage(getPackage(mirror));
|
||||
newClass.setTableName(anTable.name());
|
||||
CreatorClassTableMode.record(newClass, processingEnv);
|
||||
}
|
||||
|
||||
private List<JoinElemCollectionDto> getElementCollectionsFields(String tableName, List<? extends Element> allFields) {
|
||||
return allFields.stream()
|
||||
.filter(
|
||||
field -> field.getAnnotation(ElementCollectionField.class) != null &&
|
||||
field.getAnnotation(CollectionTable.class) != null &&
|
||||
field.getAnnotation(Column.class) != null
|
||||
)
|
||||
.map(field -> {
|
||||
final String fieldName = field.getSimpleName().toString();
|
||||
final ElementCollectionField elementCollectionField = field.getAnnotation(ElementCollectionField.class);
|
||||
final CollectionTable collectionTable = field.getAnnotation(CollectionTable.class);
|
||||
final Column column = field.getAnnotation(Column.class);
|
||||
|
||||
final JoinTableContainer firstContainer = JoinTableContainer.of(collectionTable.name(), tableName + "." + elementCollectionField.parentId(), collectionTable.joinColumns()[0].name());
|
||||
final JoinTableContainer secondContainer = JoinTableContainer.of(elementCollectionField.childTable(), column.name(), elementCollectionField.childReference());
|
||||
return JoinElemCollectionDto.of(fieldName, firstContainer, secondContainer);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<JoinFieldDto> getJoinFields(List<? extends Element> allFields) {
|
||||
return allFields.stream()
|
||||
.filter(
|
||||
field -> field.getAnnotation(JoinField.class) != null &&
|
||||
field.getAnnotation(ElementCollection.class) == null
|
||||
)
|
||||
.map(field -> {
|
||||
final String fieldName = field.getSimpleName().toString();
|
||||
final JoinField joinField = field.getAnnotation(JoinField.class);
|
||||
final JoinTableContainer joinContainer = JoinTableContainer.of(joinField.table(), joinField.baseId(), joinField.reference());
|
||||
return JoinFieldDto.of(fieldName, joinContainer);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<SimpleFieldTableDto> getSimpleFields(List<? extends Element> allFields, Table anTable, TableModeSettings tableSettings) {
|
||||
final boolean prefixTableForColumn = tableSettings.prefixTableForColumn();
|
||||
final List<SimpleFieldTableDto> resultList = new ArrayList<>();
|
||||
allFields.stream()
|
||||
.filter(
|
||||
field -> field.getAnnotation(Column.class) != null &&
|
||||
field.getAnnotation(ElementCollection.class) == null
|
||||
)
|
||||
.forEach(
|
||||
field -> {
|
||||
final String fieldName = field.getSimpleName().toString();
|
||||
final String columnName = field.getAnnotation(Column.class).name();
|
||||
if (prefixTableForColumn) {
|
||||
final String tableNameAndColumnName = anTable.name() + "." + columnName;
|
||||
resultList.add(SimpleFieldTableDto.of("t_" + fieldName, tableNameAndColumnName));
|
||||
}
|
||||
resultList.add(SimpleFieldTableDto.of(fieldName, columnName));
|
||||
}
|
||||
);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
private boolean isNotIgnoreField(Element element) {
|
||||
return element.getAnnotation(IgnoreField.class) == null;
|
||||
}
|
||||
|
||||
public boolean isField(Element element) {
|
||||
return element != null && element.getKind().isField();
|
||||
}
|
||||
|
||||
public static String getPackage(TypeMirror typeMirror) {
|
||||
final String[] split = typeMirror.toString().split("\\.");
|
||||
return String.join(".", Arrays.copyOf(split, split.length - 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
package dev.struchkov.haiti.utils.fieldconstants.util;
|
||||
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.field.IgnoreField;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
|
||||
public class Generator {
|
||||
|
||||
public static boolean isNotIgnoreField(Element element) {
|
||||
return element.getAnnotation(IgnoreField.class) == null;
|
||||
}
|
||||
|
||||
public static boolean isField(Element element) {
|
||||
return element != null && element.getKind().isField();
|
||||
}
|
||||
|
||||
public static String getPackage(Element element) {
|
||||
Element packageElem = element.getEnclosingElement();
|
||||
while (!ElementKind.PACKAGE.equals(packageElem.getKind())) {
|
||||
packageElem = packageElem.getEnclosingElement();
|
||||
}
|
||||
return packageElem.asType().toString();
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,6 @@ module haiti.utils.fieldconstants {
|
||||
|
||||
requires java.compiler;
|
||||
requires com.google.auto.service;
|
||||
requires java.persistence;
|
||||
requires jakarta.persistence;
|
||||
requires haiti.utils;
|
||||
}
|
Loading…
Reference in New Issue
Block a user