From caebbc59a0ac7123972ea5042f9db1ae1dd89b54 Mon Sep 17 00:00:00 2001 From: Braydon Date: Sat, 16 Dec 2023 17:47:22 -0500 Subject: [PATCH] Update workflow and make the checkstyle less strict --- .../{publish-release.yml => build.yml} | 21 ++++++++++--- checkstyle.xml | 8 ----- .../braydon/feather/annotation/RawData.java | 20 +++++++++++++ .../me/braydon/feather/data/Document.java | 30 +++++++++++-------- 4 files changed, 55 insertions(+), 24 deletions(-) rename .gitea/workflows/{publish-release.yml => build.yml} (90%) create mode 100644 src/main/java/me/braydon/feather/annotation/RawData.java diff --git a/.gitea/workflows/publish-release.yml b/.gitea/workflows/build.yml similarity index 90% rename from .gitea/workflows/publish-release.yml rename to .gitea/workflows/build.yml index a782108..20df16e 100644 --- a/.gitea/workflows/publish-release.yml +++ b/.gitea/workflows/build.yml @@ -1,14 +1,15 @@ -name: Publish Release +name: Maven Build on: push: - branches: [master] + branches: [master, develop] tags: - '*' jobs: - publish: - name: Publish Release + # Maven Build Job + build: + name: Maven Build strategy: matrix: arch: [ubuntu-latest] @@ -60,6 +61,18 @@ jobs: - name: Publish to Maven run: mvn deploy -Pgen-javadocs -B -Dstyle.color=always --update-snapshots -T6C -e + # Publish Job + publish: + name: Maven Build + strategy: + matrix: + arch: [ ubuntu-latest ] + java-version: [ 8 ] + maven-version: [ 3.9.4 ] + runs-on: ${{ matrix.arch }} + + # Steps + steps: # Generate changelog - name: Generate Changelog id: changelog diff --git a/checkstyle.xml b/checkstyle.xml index 2c82ad4..de77473 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -91,9 +91,6 @@ - - - @@ -215,11 +212,6 @@ - - - - - diff --git a/src/main/java/me/braydon/feather/annotation/RawData.java b/src/main/java/me/braydon/feather/annotation/RawData.java new file mode 100644 index 0000000..89d8abe --- /dev/null +++ b/src/main/java/me/braydon/feather/annotation/RawData.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 Braydon (Rainnny). All rights reserved. + * + * For inquiries, please contact braydonrainnny@gmail.com + */ +package me.braydon.feather.annotation; + +import java.lang.annotation.*; + +/** + * {@link Field}'s tagged with this annotation + * will be set to the raw data from the document + * it is in. + * + * @author Braydon + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@Documented @Inherited +public @interface RawData { } \ No newline at end of file diff --git a/src/main/java/me/braydon/feather/data/Document.java b/src/main/java/me/braydon/feather/data/Document.java index 227f33b..fd515a5 100644 --- a/src/main/java/me/braydon/feather/data/Document.java +++ b/src/main/java/me/braydon/feather/data/Document.java @@ -7,10 +7,12 @@ package me.braydon.feather.data; import lombok.Getter; import lombok.NonNull; +import lombok.SneakyThrows; import lombok.ToString; import me.braydon.feather.FeatherSettings; import me.braydon.feather.annotation.Field; import me.braydon.feather.annotation.Id; +import me.braydon.feather.annotation.RawData; import me.braydon.feather.annotation.Serializable; import me.braydon.feather.common.FieldUtils; import me.braydon.feather.common.Tuple; @@ -55,15 +57,20 @@ public class Document { */ private final Map> mappedData = Collections.synchronizedMap(new LinkedHashMap<>()); + @SneakyThrows public Document(@NonNull Object element) { Class clazz = element.getClass(); // Get the element class String idKey = null; // The key for the id field + java.lang.reflect.Field rawDataField = null; for (java.lang.reflect.Field field : clazz.getDeclaredFields()) { // Field is missing the @Field annotation, skip it if (!field.isAnnotationPresent(Field.class)) { continue; } field.setAccessible(true); // Make our field accessible + if (field.isAnnotationPresent(RawData.class)) { // Raw data field, save it for later + rawDataField = field; + } String key = FieldUtils.extractKey(field); // The key of the database field // The field is annotated with @Id, save it for later @@ -71,21 +78,20 @@ public class Document { idKey = key; } Class fieldType = field.getType(); // The type of the field - try { - Object value = field.get(element); // The value of the field - - if (field.isAnnotationPresent(Serializable.class)) { // Serialize the field if @Serializable is present - value = FeatherSettings.getGson().toJson(field.get(element)); - } else if (fieldType == UUID.class) { // Convert UUIDs into strings - value = value.toString(); - } - - mappedData.put(key, new Tuple<>(field, (V) value)); // Store in our map - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); + Object value = field.get(element); // The value of the field + + if (field.isAnnotationPresent(Serializable.class)) { // Serialize the field if @Serializable is present + value = FeatherSettings.getGson().toJson(field.get(element)); + } else if (fieldType == UUID.class) { // Convert UUIDs into strings + value = value.toString(); } + + mappedData.put(key, new Tuple<>(field, (V) value)); // Store in our map } assert idKey != null; // We need an id key + if (rawDataField != null) { // We have a raw data field, set it + rawDataField.set(element, mappedData); + } this.idKey = idKey; // Set our id key Tuple key = mappedData.get(idKey); // Get the id from the data map