+
+## What is it?
+It's a Java project for initializing classes automatically,
+a little like Spring uses Beans. You can avoid a mess like this:
+
+```java
+new Command();
+new Command2();
+
+new Event();
+new Event2();
+```
+
+and instead use `@Init` annotation to initialize the class (using your constructor configuration) automatically:
+
+```java
+new AutomaticInitializer.Builder()
+ .setPackageName("(the main package to look for classes)")
+ .addInitVariable(Integer.class, 123) // You can add as many as you want
+ .addInitVariable(MyMainClass.class, mainClassObject) // Or none if you want the default constructor
+ .run();
+```
+
+and for the class:
+
+```java
+@Init
+public class Test {
+ public Test(Integer i, MyMainClass myMainClass) {
+ System.out.println("Hi from test! My int value: " + i);
+ myMainClass.registerEvent(this); // You can initialize the event here for example!
+ }
+}
+```
+
+## Installation
+Install TuliAutoInitializer by Maven or Gradle using Jitpack, or my self-hosted gitea (on git.tulisiowice.top):
+
+### Repos:
+
+```xml
+
+
+ jitpack.io
+ https://jitpack.io
+
+
+```
+
+```xml
+
+
+ gitea
+ https://git.tulisiowice.top/api/packages/Tulis/maven
+
+
+```
+
+### The package:
+
+```xml
+ // Jitpack
+ com.github.Tulis12
+ TuliAutoInitializer
+ latest-version // If you don't know it, check the Jitpack badge!
+
+```
+
+```xml
+ // Gitea
+ dev.tulis
+ TuliAutoInitializer
+ latest-version
+
+```
+
+## All annotation's parameters
+
+### `initializeWithoutParameters = true`
+Tries to use the default constructor of class (the one without parameters), defaults to false (using the configuration of the builder).
+
+```java
+@Init(initializeWithoutParameters = true)
+public class Test {
+ public Test() {
+ System.out.println("Will use this instead!");
+ }
+
+ public Test(Integer i1, Integer i2) {
+ System.out.println("Won't use this!");
+ }
+}
+```
+
+The Initializer won't force use of default constructor (for example, if its private), will instead throw `NoSuchMethodException`, `IllegalAccessException` respectively.
+
+### `initializeOnlyWith = { Integer.class, MyMainClass.class }`
+Will use only those two, even if there are more. In case of multiple values with the same class, will take the one first added in the builder, defaults to an empty array (will use the configuration of builder).
+
+```java
+@Init(initializeOnlyWith = { Integer.class, MyMainClass.class })
+public class Test {
+ public Test(Integer integer, MyMainClass myMainClass) {
+ System.out.println("Will use this, even if in builder there is more.");
+ }
+
+ public Test(Integer integer, String string, MyMainClass myMainClass) {
+ System.out.println("Won't use this!");
+ }
+}
+```
+
+Remember, if there is no class (with a value) provided in the builder, but you will try to use it here, the builder will throw `MissingParameterException`.
+
+## License
+Released under the MIT license.
\ No newline at end of file
diff --git a/img.png b/img.png
new file mode 100644
index 0000000..89472b8
Binary files /dev/null and b/img.png differ
diff --git a/pom.xml b/pom.xml
index c42e5cc..2dbbd6e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,8 +5,8 @@
4.0.0dev.tulis
- TuliAutoInitializer
- 1.0-SNAPSHOT
+ tuliautoinitializer
+ 1.121
@@ -38,6 +38,10 @@
reflections0.10.2
+
+ org.slf4j
+ slf4j-api
+ 2.0.17
+
-
\ No newline at end of file
diff --git a/src/main/java/dev/tulis/autoinitializer/Annotations/GenericInitializer.java b/src/main/java/dev/tulis/autoinitializer/Annotations/Init.java
similarity index 67%
rename from src/main/java/dev/tulis/autoinitializer/Annotations/GenericInitializer.java
rename to src/main/java/dev/tulis/autoinitializer/Annotations/Init.java
index 0ffa563..f1c62a9 100644
--- a/src/main/java/dev/tulis/autoinitializer/Annotations/GenericInitializer.java
+++ b/src/main/java/dev/tulis/autoinitializer/Annotations/Init.java
@@ -7,5 +7,7 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
-public @interface GenericInitializer {
+public @interface Init {
+ boolean initializeWithoutParameters() default false;
+ Class>[] initializeOnlyWith() default {};
}
\ No newline at end of file
diff --git a/src/main/java/dev/tulis/autoinitializer/Annotations/InitializeCommand.java b/src/main/java/dev/tulis/autoinitializer/Annotations/InitializeCommand.java
deleted file mode 100644
index c4f8c14..0000000
--- a/src/main/java/dev/tulis/autoinitializer/Annotations/InitializeCommand.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package dev.tulis.autoinitializer.Annotations;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-public @interface InitializeCommand {
- String commandName();
-}
\ No newline at end of file
diff --git a/src/main/java/dev/tulis/autoinitializer/AutomaticInitializer.java b/src/main/java/dev/tulis/autoinitializer/AutomaticInitializer.java
index c473017..b730cf0 100644
--- a/src/main/java/dev/tulis/autoinitializer/AutomaticInitializer.java
+++ b/src/main/java/dev/tulis/autoinitializer/AutomaticInitializer.java
@@ -1,73 +1,169 @@
package dev.tulis.autoinitializer;
-import dev.tulis.autoinitializer.Annotations.GenericInitializer;
-import dev.tulis.autoinitializer.Annotations.InitializeCommand;
+import dev.tulis.autoinitializer.Annotations.Init;
import org.reflections.Reflections;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.lang.reflect.Constructor;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import java.lang.reflect.InvocationTargetException;
+import java.util.*;
public class AutomaticInitializer {
- String packageName;
- Class> mainClass;
- Object mainClassObject;
- private final Logger logger = Logger.getLogger("dev.tulis.autoinitializer");
- private boolean loggerEnabled = true;
+ private final String packageName;
+ private final LinkedHashMap, List