RegisterPackages -> ignore other files in compiled runtime directory

This commit is contained in:
jeffcheasey88 2024-09-23 03:33:05 +02:00
parent c06cc46787
commit 9f11825f97

View file

@ -5,17 +5,14 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.net.ServerSocket;
import java.net.Socket;
import java.security.Key;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.regex.Pattern;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
@ -34,7 +31,7 @@ import org.jose4j.lang.JoseException;
public class Router<U extends User>{
public static void main(String[] args) {
public static void main(String[] args){
}
@ -106,6 +103,7 @@ public class Router<U extends User>{
Route route = method.getAnnotation(Route.class);
this.mappers[route.type().ordinal()].register(response, method, route);
System.out.println("Registered route "+method+" ["+route.type()+" "+route.path()+"]");
}catch(Exception e){
throw new IllegalArgumentException(e);
}
@ -117,13 +115,16 @@ public class Router<U extends User>{
}
public Router<U> registerClass(Class<?> clazz, DependencyInjector injector) throws Exception{
Constructor<?>[] constructors = clazz.getDeclaredConstructors();
if(constructors.length != 1) throw new IllegalArgumentException("Class with multiple constructor. Not supported by this framework for the moment.");
Object instance = constructors[0].newInstance(injector.apply(constructors[0]));
Object instance = null;
for(Method method : clazz.getDeclaredMethods()){
Route route = method.getAnnotation(Route.class);
if(route == null) continue;
if(instance == null){
Constructor<?>[] constructors = clazz.getDeclaredConstructors();
if(constructors.length != 1) throw new IllegalArgumentException("Class with multiple constructor. Not supported by this framework for the moment.");
instance = constructors[0].newInstance(injector.apply(constructors[0]));
}
this.mappers[route.type().ordinal()].register(instance, method, route);
System.out.println("Registered route "+method+" ["+route.type()+" "+route.path()+"]");
@ -153,11 +154,11 @@ public class Router<U extends User>{
String line;
while((line = reader.readLine()) != null){
if(line.endsWith(".class")){
Class<?> clazz = Class.forName(name+"."+line.substring(0, line.lastIndexOf('.')));
Class<?> clazz = Class.forName(name+"."+line.substring(0, line.length()-6));
registerClass(clazz, injector);
}else{
registerPackages(name+"."+line, injector);
continue;
}
if(!line.contains(".")) registerPackages(name+"."+line, injector);
}
reader.close();
}catch(Exception e){