Skip to content

Commit

Permalink
Framework updates for some smoother controls
Browse files Browse the repository at this point in the history
  • Loading branch information
GedMarc committed Aug 1, 2024
1 parent d13eedf commit 1777712
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 52 deletions.
23 changes: 0 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@
<scope>provided</scope>
</dependency>

<!-- <dependency>
<groupId>com.guicedee</groupId>
<artifactId>guiced-log-master</artifactId>
</dependency>
-->

<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
Expand All @@ -113,11 +107,6 @@
<artifactId>jackson-core</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand All @@ -143,18 +132,6 @@
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
71 changes: 62 additions & 9 deletions src/main/java/com/guicedee/guicedinjection/GuiceContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
import io.github.classgraph.ResourceList;
import io.github.classgraph.ScanResult;
import lombok.extern.java.Log;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
Expand Down Expand Up @@ -85,12 +92,54 @@ public class GuiceContext<J extends GuiceContext<J>> implements IGuiceContext

private CompletableFuture<Void> loadingFinished = new CompletableFuture<>();


private ConfigurationBuilder<BuiltConfiguration> logBuilder;

/**
* Creates a new Guice context. Not necessary
*/
private GuiceContext()
{
//No config required
try
{
// String cn = "org.apache.logging.log4j.jul.LogManager";
// System.setProperty("java.util.logging.manager", cn);

ConfigurationBuilder<BuiltConfiguration> builder =
ConfigurationBuilderFactory.newConfigurationBuilder();

builder.setStatusLevel(org.apache.logging.log4j.Level.DEBUG);
builder.setConfigurationName("GuicedEE");

// create the console appender
AppenderComponentBuilder appenderBuilder = builder.newAppender("Stdout", "CONSOLE")
.addAttribute("target",
ConsoleAppender.Target.SYSTEM_ERR)
//.addAttribute("additivity", "true")
;
appenderBuilder.add(builder.newLayout("PatternLayout").
addAttribute("pattern", "%d{ABSOLUTE} %-5level: %msg%n"));
builder.add(appenderBuilder);



RootLoggerComponentBuilder rootLogger = builder.newRootLogger(org.apache.logging.log4j.Level.DEBUG);
ServiceLoader<Log4JConfigurator> log4JConfigurators = ServiceLoader.load(Log4JConfigurator.class);
for (Log4JConfigurator log4jConfigurator : log4JConfigurators)
{
builder = log4jConfigurator.configure(builder, rootLogger);
}

rootLogger.add(builder.newAppenderRef("Stdout"));
builder.add(rootLogger);

builder.writeXmlConfiguration(System.out);
Configurator.initialize(builder.build());
}
catch (Throwable T)
{
log.log(Level.SEVERE, "Failed to configure Log4JConfigurator", T);
}
}

/**
Expand Down Expand Up @@ -142,15 +191,18 @@ public Injector inject()
log.config("Modules - " + Arrays.toString(cModules.toArray()));
GuiceContext.instance().injector = Guice.createInjector(cModules);
GuiceContext.buildingInjector = false;
GuiceContext.instance().loadPostStartups();
GuiceContext.instance().loadPreDestroyServices();
GuiceContext.instance()
.loadPostStartups();
GuiceContext.instance()
.loadPreDestroyServices();
Runtime
.getRuntime()
.addShutdownHook(new Thread()
{
public void run()
{
GuiceContext.instance().destroy();
GuiceContext.instance()
.destroy();
}
});
LocalDateTime end = LocalDateTime.now();
Expand Down Expand Up @@ -786,20 +838,21 @@ private void loadPostStartups()
Integer key = entry.getKey();
Set<IGuicePostStartup<?>> value = entry.getValue();
List<CompletableFuture<Boolean>> futures = new ArrayList<>();
// log.info("Starting Post Startup Group [" + key + "]");
// log.info("Starting Post Startup Group [" + key + "]");
ExecutorService ex = null;
for (IGuicePostStartup<?> iGuicePostStartup : value)
{
log.info("Starting Post Load [" + iGuicePostStartup.getClass()
.getSimpleName() + "] - Start Order [" + key + "]");
ex= iGuicePostStartup.getExecutorService();
.getSimpleName() + "] - Start Order [" + key + "]");
ex = iGuicePostStartup.getExecutorService();
futures.addAll(iGuicePostStartup.postLoad());
}
try
{
if(!futures.isEmpty())
if (!futures.isEmpty())
{
CompletableFuture.allOf(futures.toArray(new CompletableFuture[]{})).join();
CompletableFuture.allOf(futures.toArray(new CompletableFuture[]{}))
.join();
if (ex != null)
{
ex.shutdown();
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import com.guicedee.guicedinjection.JobService;
import com.guicedee.guicedinjection.implementations.*;
import com.guicedee.guicedinjection.interfaces.*;
import com.guicedee.guicedinjection.implementations.GuiceContextProvision;
import com.guicedee.guicedinjection.implementations.JobServiceProvision;
import com.guicedee.guicedinjection.interfaces.IGuicePreDestroy;
import com.guicedee.guicedinjection.interfaces.IGuiceProvider;
import com.guicedee.guicedinjection.interfaces.IJobServiceProvider;

module com.guicedee.guicedinjection {
requires transitive com.guicedee.client;
Expand All @@ -11,11 +14,11 @@
//requires transitive com.guicedee.logmaster;

requires transitive org.apache.commons.lang3;

requires static org.slf4j;

requires static lombok;

exports com.guicedee.guicedinjection;
requires org.apache.logging.log4j.core;

exports com.guicedee.guicedinjection;
//exports com.guicedee.guicedinjection.exceptions;
//exports com.guicedee.guicedinjection.abstractions;
//exports com.guicedee.guicedinjection.pairing;
Expand All @@ -40,8 +43,9 @@
uses com.guicedee.guicedinjection.interfaces.IPackageRejectListScanner;
uses com.guicedee.guicedinjection.interfaces.IGuiceScanJarExclusions;
uses com.guicedee.guicedinjection.interfaces.IGuiceScanJarInclusions;

provides com.guicedee.guicedinjection.interfaces.IGuiceScanModuleExclusions with com.guicedee.guicedinjection.implementations.GuiceDefaultModuleExclusions;
uses com.guicedee.guicedinjection.interfaces.Log4JConfigurator;

provides com.guicedee.guicedinjection.interfaces.IGuiceScanModuleExclusions with com.guicedee.guicedinjection.implementations.GuiceDefaultModuleExclusions;
provides com.guicedee.guicedinjection.interfaces.IGuiceScanJarExclusions with com.guicedee.guicedinjection.implementations.GuiceDefaultModuleExclusions;

provides com.guicedee.guicedinjection.interfaces.IGuiceModule with com.guicedee.guicedinjection.injections.ContextBinderGuice;
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/com/guicedee/tests/FileSearchTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.guicedee.tests;

import com.guicedee.client.*;
import com.guicedee.client.IGuiceContext;
import com.guicedee.guicedinjection.GuiceContext;
import com.guicedee.guicedinjection.interfaces.IPathContentsRejectListScanner;
import io.github.classgraph.ResourceList;
import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.regex.Pattern;

public class FileSearchTest {
Expand All @@ -32,6 +30,7 @@ public void findJSFiles()

IGuiceContext
.getContext().inject();

ResourceList resourceswithPattern = GuiceContext.instance().getScanResult()
.getResourcesMatchingPattern(Pattern.compile("(.*)\\/resources\\/testResourceFind\\.js"));
System.out.println("Resource List found : " + resourceswithPattern);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
requires static lombok;

requires org.junit.jupiter.api;
requires org.slf4j;
requires org.slf4j.simple;
//requires org.slf4j;
//requires org.apache.logging.log4j.slf4j2.impl;

opens com.guicedee.tests to org.junit.platform.commons;

Expand Down
7 changes: 0 additions & 7 deletions src/test/resources/logback.xml

This file was deleted.

0 comments on commit 1777712

Please sign in to comment.