log added

This commit is contained in:
lucio 2024-02-21 12:05:21 +01:00
parent a7dcafd4a3
commit c46ddc6ae0
5 changed files with 56 additions and 22 deletions

View File

@ -11,5 +11,18 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/> <attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View File

@ -3,12 +3,19 @@
<wb-module deploy-name="common-smartgears-app"> <wb-module deploy-name="common-smartgears-app">
<wb-resource deploy-path="/" source-path="/src/main/resources"/> <wb-resource deploy-path="/" source-path="/src/main/resources"/>
<wb-resource deploy-path="/" source-path="/src/main/java"/>
@ -18,4 +25,6 @@
</project-modules> </project-modules>

View File

@ -3,6 +3,8 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v3.0.1-SNAPSHOT] - [2024-02-02]
## [v3.0.0] - [2022-05-13] ## [v3.0.0] - [2022-05-13]
porting to new IAM porting to new IAM

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
<artifactId>common-smartgears-app</artifactId> <artifactId>common-smartgears-app</artifactId>
<version>3.0.0</version> <version>3.0.1-SNAPSHOT</version>
<name>Smartgears Application</name> <name>Smartgears Application</name>
@ -33,7 +33,7 @@
<dependency> <dependency>
<groupId>org.gcube.distribution</groupId> <groupId>org.gcube.distribution</groupId>
<artifactId>gcube-smartgears-bom</artifactId> <artifactId>gcube-smartgears-bom</artifactId>
<version>3.0.0</version> <version>3.0.1-SNAPSHOT</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
@ -50,8 +50,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.reflections</groupId> <groupId>io.github.classgraph</groupId>
<artifactId>reflections</artifactId> <artifactId>classgraph</artifactId>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.javassist/javassist --> <!-- https://mvnrepository.com/artifact/org.javassist/javassist -->

View File

@ -1,9 +1,9 @@
package org.gcube.smartgears; package org.gcube.smartgears;
import java.net.URL;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener; import javax.servlet.annotation.WebListener;
@ -11,14 +11,14 @@ import javax.servlet.annotation.WebListener;
import org.gcube.smartgears.annotations.ManagedBy; import org.gcube.smartgears.annotations.ManagedBy;
import org.gcube.smartgears.application.manager.AppManagerObserver; import org.gcube.smartgears.application.manager.AppManagerObserver;
import org.gcube.smartgears.context.application.ApplicationContext; import org.gcube.smartgears.context.application.ApplicationContext;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.scanners.TypeAnnotationsScanner;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfo;
import io.github.classgraph.ClassInfoList;
import io.github.classgraph.ScanResult;
@WebListener @WebListener
public class ContextListener implements ServletContextListener { public class ContextListener implements ServletContextListener {
@ -38,26 +38,36 @@ public class ContextListener implements ServletContextListener {
log.info("configuring context provider for {}",context.name()); log.info("configuring context provider for {}",context.name());
ContextProvider.set(context); ContextProvider.set(context);
retrieveAndRegisterManagers(context); retrieveAndRegisterManagers(context);
} }
private void retrieveAndRegisterManagers(ApplicationContext context) { private void retrieveAndRegisterManagers(ApplicationContext context) {
ApplicationManagerProvider.init(context); ApplicationManagerProvider.init(context);
Collection<URL> urls = ClasspathHelper.forClassLoader(); Set<Class<?>> annotatedManaged;
try (ScanResult result = new ClassGraph().enableClassInfo().enableAnnotationInfo().scan()) {
ClassInfoList classInfos = result.getClassesWithAnnotation(ManagedBy.class.getName());
annotatedManaged = classInfos.stream().map(ClassInfo::loadClass)
.collect(Collectors.toSet());
}
/*
Collection<URL> urls = ClasspathHelper.forJavaClassPath();
urls.removeIf(url -> url.toString().endsWith(".so") || url.toString().endsWith(".zip") ); urls.removeIf(url -> url.toString().endsWith(".so") || url.toString().endsWith(".zip") );
ConfigurationBuilder reflectionConf = new ConfigurationBuilder().addUrls(urls).setScanners(new TypeAnnotationsScanner(), new SubTypesScanner()); ConfigurationBuilder reflectionConf = new ConfigurationBuilder().addUrls(urls).addClassLoaders(Thread.currentThread().getContextClassLoader()).setScanners(new TypeAnnotationsScanner(), new SubTypesScanner());
Reflections reflection = new Reflections(reflectionConf); Reflections reflection = new Reflections(reflectionConf);
Set<Class<?>> toInitialize = reflection.getTypesAnnotatedWith(ManagedBy.class); Set<Class<?>> toInitialize = reflection.getTypesAnnotatedWith(ManagedBy.class);
*/
Set<Class<? extends ApplicationManager>> managers = new HashSet<Class<? extends ApplicationManager>>(); Set<Class<? extends ApplicationManager>> managers = new HashSet<Class<? extends ApplicationManager>>();
for (Class<?> initializer: toInitialize ){ for (Class<?> initializer: annotatedManaged ){
ManagedBy manageBy = initializer.getAnnotation(ManagedBy.class); ManagedBy manageBy = initializer.getAnnotation(ManagedBy.class);
log.info("ApplicationManager added {} to {} @ {}", manageBy.value().getSimpleName(), initializer.getSimpleName(), context.name()); log.info("ApplicationManager added {} to {} @ {}", manageBy.value().getSimpleName(), initializer.getSimpleName(), context.name());
managers.add(manageBy.value()); managers.add(manageBy.value());