Initialize repository 🚀
This commit is contained in:
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/libraries/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
10
.idea/.gitignore
generated
vendored
Normal file
10
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Environment-dependent path to Maven home directory
|
||||||
|
/mavenHomeManager.xml
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
43
pom.xml
Normal file
43
pom.xml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?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">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>dev.tulis</groupId>
|
||||||
|
<artifactId>TuliAutoInitializer</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>gitea</id>
|
||||||
|
<url>https://git.tulisiowice.top/api/packages/Tulis/maven</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>gitea</id>
|
||||||
|
<url>https://git.tulisiowice.top/api/packages/Tulis/maven</url>
|
||||||
|
</repository>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>gitea</id>
|
||||||
|
<url>https://git.tulisiowice.top/api/packages/Tulis/maven</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.reflections</groupId>
|
||||||
|
<artifactId>reflections</artifactId>
|
||||||
|
<version>0.10.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,11 @@
|
|||||||
|
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 GenericInitializer {
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
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();
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
package dev.tulis.autoinitializer;
|
||||||
|
|
||||||
|
import dev.tulis.autoinitializer.Annotations.GenericInitializer;
|
||||||
|
import dev.tulis.autoinitializer.Annotations.InitializeCommand;
|
||||||
|
import org.reflections.Reflections;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class AutomaticInitializer {
|
||||||
|
String packageName;
|
||||||
|
Class<?> mainClass;
|
||||||
|
Object mainClassObject;
|
||||||
|
private final Logger logger = Logger.getLogger("dev.tulis.autoinitializer");
|
||||||
|
private boolean loggerEnabled = true;
|
||||||
|
|
||||||
|
public AutomaticInitializer(String packageName, Class<?> mainClass, Object mainClassObject) {
|
||||||
|
this.packageName = packageName;
|
||||||
|
this.mainClass = mainClass;
|
||||||
|
this.mainClassObject = mainClassObject;
|
||||||
|
|
||||||
|
Logger.getLogger("org.reflections").setLevel(Level.OFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> T castObject(Object obj, Class<T> clazz) {
|
||||||
|
return clazz.cast(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoggerEnabled(boolean enabled) {
|
||||||
|
loggerEnabled = enabled;
|
||||||
|
if(!enabled) logger.setLevel(Level.OFF); else logger.setLevel(Level.WARNING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLoggerEnabled() {
|
||||||
|
return loggerEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeCommands() {
|
||||||
|
Reflections reflections = new Reflections(packageName);
|
||||||
|
Set<Class<?>> autoInitClasses = reflections.getTypesAnnotatedWith(InitializeCommand.class);
|
||||||
|
|
||||||
|
for (Class<?> clazz : autoInitClasses) {
|
||||||
|
try {
|
||||||
|
Constructor<?> ctor = clazz.getDeclaredConstructor(mainClass);
|
||||||
|
ctor.newInstance(castObject(mainClassObject, mainClass));
|
||||||
|
|
||||||
|
InitializeCommand annotation = clazz.getAnnotation(InitializeCommand.class);
|
||||||
|
|
||||||
|
logger.info("Zainicjalizowano komendę: " + annotation.commandName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warning(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeGenerics() {
|
||||||
|
Reflections reflections = new Reflections(packageName);
|
||||||
|
Set<Class<?>> autoInitClasses = reflections.getTypesAnnotatedWith(GenericInitializer.class);
|
||||||
|
|
||||||
|
for (Class<?> clazz : autoInitClasses) {
|
||||||
|
try {
|
||||||
|
Constructor<?> ctor = clazz.getDeclaredConstructor(mainClass);
|
||||||
|
ctor.newInstance(castObject(mainClassObject, mainClass));
|
||||||
|
|
||||||
|
logger.info("Zainicjalizowano klasę ogólną: " + clazz.getSimpleName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warning(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user