+The "root" {@link PluginConfig} implementations must have the version field set to a positive number. The version + format is "major +.minor" +and "number.number". The semantics are equal to schematic versioning. +
+Major version bumps should only be made if +breaking changes are applied, for example removing an option, renaming or changing the purpose. For every major +version update a {@link ConfigMigration} must be provided. +
+Minor version bumps should only be made if non-breaking changes are applied, for example adding a new option or +changing the default value. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.FIELD}) +@ConfigurationProperties(PluginConfig.PLUGIN_PREFIX) +@AccessorsStyle(readPrefixes = "") +public @interface PluginConfig { + + /** + The prefix used to store plugin config properties + */ + String PLUGIN_PREFIX = "plugin"; + + // @formatter:off + /** + The value field holds the subcategory of the plugin config. "" (default) means the root config "plugin". +
+ @PluginConfig
+ class PluginConfigFile {
+ @PluginConfig("foo")
+ class FooSection {
+ // entries
+ }
+ }
+
+ In this example FooSection corresponds to "plugin.foo".
+ @return The subcategory
+ */
+ // @formatter:on
+ @AliasFor(annotation = ConfigurationProperties.class, member = "value")
+ String value() default "";
+
+ /**
+ @return the version of this config, this field must be set at the root level
+ */
+ double version() default -1;
+
+ /**
+ The value of this field will be mapped to {@link AccessorsStyle#readPrefixes()}
+
+ @return The read prefix
+ */
+ @AliasFor(annotation = AccessorsStyle.class, member = "readPrefixes")
+ String[] readPrefixes() default "";
+}
diff --git a/mayflower/src/main/java/io/github/madethoughts/mayflower/configuration/internal/Configs.java b/mayflower/src/main/java/io/github/madethoughts/mayflower/configuration/internal/Configs.java
new file mode 100644
index 0000000..274cb3c
--- /dev/null
+++ b/mayflower/src/main/java/io/github/madethoughts/mayflower/configuration/internal/Configs.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2023 original authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.github.madethoughts.mayflower.configuration.internal;
+
+import io.github.madethoughts.mayflower.configuration.PluginConfig;
+import io.micronaut.core.annotation.AnnotationSource;
+
+/**
+ Configuration utility classes
+ */
+public final class Configs {
+ private Configs() {
+ }
+
+ /**
+ This method assumes, that the annotation source contains a {@link PluginConfig}
+
+ @param metadata The {@link AnnotationSource}
+ @return the version, specified by {@link PluginConfig}
+ */
+ public static double version(AnnotationSource metadata) {
+ return metadata.getAnnotation(PluginConfig.class).getRequiredValue("version", double.class);
+ }
+
+ /**
+ @param source The {@link AnnotationSource}
+ @return whether this is the root interface
+ */
+ public static boolean isRoot(AnnotationSource source) {
+ return source.getAnnotation(PluginConfig.class)
+ .isTrue("root");
+ }
+}
diff --git a/mayflower/src/main/java/io/github/madethoughts/mayflower/configuration/internal/package-info.java b/mayflower/src/main/java/io/github/madethoughts/mayflower/configuration/internal/package-info.java
new file mode 100644
index 0000000..e6ccdf2
--- /dev/null
+++ b/mayflower/src/main/java/io/github/madethoughts/mayflower/configuration/internal/package-info.java
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2023 original authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.github.madethoughts.mayflower.configuration.internal;
\ No newline at end of file
diff --git a/mayflower/src/main/java/io/github/madethoughts/mayflower/configuration/internal/visitors/DefaultConfigGenerator.java b/mayflower/src/main/java/io/github/madethoughts/mayflower/configuration/internal/visitors/DefaultConfigGenerator.java
new file mode 100644
index 0000000..9527913
--- /dev/null
+++ b/mayflower/src/main/java/io/github/madethoughts/mayflower/configuration/internal/visitors/DefaultConfigGenerator.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2023 original authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.github.madethoughts.mayflower.configuration.internal.visitors;
+
+import io.github.madethoughts.mayflower.configuration.PluginConfig;
+import io.github.madethoughts.mayflower.configuration.internal.Configs;
+import io.github.madethoughts.mayflower.internal.FileUtils;
+import io.micronaut.core.annotation.AnnotationValue;
+import io.micronaut.core.bind.annotation.Bindable;
+import io.micronaut.inject.ast.ClassElement;
+import io.micronaut.inject.ast.MemberElement;
+import io.micronaut.inject.ast.MethodElement;
+import io.micronaut.inject.visitor.TypeElementVisitor;
+import io.micronaut.inject.visitor.VisitorContext;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import java.lang.annotation.RetentionPolicy;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+
+/**
+ This TypeElementVisitors generates a default config at compile time, consuming interfaces annotated with
+ {@link PluginConfig}.
+ */
+
+// service
+@SuppressWarnings("unused")
+public class DefaultConfigGenerator implements TypeElementVisitor