Skip to content

Commit

Permalink
Guiced Persistence, Test Modules configuration, Add dynamic register …
Browse files Browse the repository at this point in the history
…modules to Guice Context
  • Loading branch information
GedMarc committed Dec 30, 2023
1 parent e12b1a9 commit 2a56104
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 228 deletions.
8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
<artifactId>commons-lang3</artifactId>
</dependency>


<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand Down Expand Up @@ -149,6 +148,12 @@
<artifactId>jcl-over-slf4j</artifactId>
</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 Expand Up @@ -177,7 +182,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<inherited>true</inherited>
<configuration>
<annotationProcessorPaths>
Expand Down
41 changes: 21 additions & 20 deletions src/main/java/com/guicedee/guicedinjection/GuiceContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import jakarta.validation.constraints.*;
import lombok.extern.java.Log;

import java.lang.Module;
import java.lang.annotation.*;
import java.util.*;
import java.util.concurrent.*;
Expand Down Expand Up @@ -60,14 +59,6 @@ public class GuiceContext<J extends GuiceContext<J>>
* The building injector
*/
public static boolean buildingInjector = false;
/**
* A standard default waiting time for threads
*/
public static long defaultWaitTime = 2;
/**
* The default wait unit for the thread time
*/
public static TimeUnit defaultWaitUnit = TimeUnit.SECONDS;
/**
* The configuration object
*/
Expand Down Expand Up @@ -101,7 +92,8 @@ private GuiceContext()
//No config required
}

private Set<String> registerModules = new LinkedHashSet<>();
private static Set<String> registerModuleForScanning = new LinkedHashSet<>();
private static List<com.google.inject.Module> modules = new ArrayList<>();

/**
* Reference the Injector Directly
Expand All @@ -118,7 +110,6 @@ public static synchronized Injector inject()
}
if (GuiceContext.instance().injector == null)
{
SysStreamsLogger.bindSystemStreams();
try
{
GuiceContext.buildingInjector = true;
Expand All @@ -138,8 +129,11 @@ public static synchronized Injector inject()
GuiceContext.instance()
.loadPreStartups();

List<com.google.inject.Module> cModules = new ArrayList<>();
cModules.add(new GuiceInjectorModule());
List<com.google.inject.Module> cModules = new ArrayList<>(modules);
Set iGuiceModules = GuiceContext.instance().loadIGuiceModules();
cModules.addAll(iGuiceModules);

//cModules.add(new GuiceInjectorModule());
GuiceContext.instance().injector = Guice.createInjector(cModules);
GuiceContext.buildingInjector = false;
GuiceContext.instance()
Expand Down Expand Up @@ -765,10 +759,15 @@ private String[] getModulesExclusionList()
* @return This instance
*/
@SuppressWarnings("unchecked")
public J registerModule(String javaModuleName)
public static void registerModule(String javaModuleName)
{
this.registerModules.add(javaModuleName);
return (J) this;
instance().registerModuleForScanning.add(javaModuleName);
instance().getConfig().setIncludeModuleAndJars(true);
}

public static void registerModule(com.google.inject.Module module)
{
instance().modules.add(module);
}

/**
Expand All @@ -780,7 +779,7 @@ public J registerModule(String javaModuleName)
private String[] getModulesInclusionsList()
{
Set<String> strings = new TreeSet<>();
strings.addAll(registerModules);
strings.addAll(registerModuleForScanning);
Set<IGuiceScanModuleInclusions> exclusions = getLoader(IGuiceScanModuleInclusions.class, true, ServiceLoader.load(IGuiceScanModuleInclusions.class));
if (exclusions.iterator()
.hasNext())
Expand Down Expand Up @@ -1240,7 +1239,10 @@ public <T> Set<T> loaderToSetNoInjection(ServiceLoader<T> loader)
output.add(newInstance);
completed.add((Class<T>) newInstance.getClass());
}
} catch (Throwable T)
} catch (java.util.ServiceConfigurationError T)
{
log.log(Level.WARNING, "Cannot load services - ", T);
}catch (Throwable T)
{
log.log(Level.SEVERE, "Cannot load services - ", T);
}
Expand All @@ -1255,8 +1257,7 @@ public <T> Set<T> loaderToSetNoInjection(ServiceLoader<T> loader)
output.add((T) newInstance.getDeclaredConstructor());
} catch (NoSuchMethodException e)
{
log
.log(Level.SEVERE, "Cannot load a service through default constructor", e);
log.log(Level.SEVERE, "Cannot load a service through default constructor", e);
}
}
return output;
Expand Down
188 changes: 0 additions & 188 deletions src/main/java/com/guicedee/guicedinjection/SysStreamsLogger.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.guicedee.guicedinjection;
package com.guicedee.tests;

import com.guicedee.guicedinjection.interfaces.IFileContentsScanner;
import io.github.classgraph.ResourceList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.guicedee.guicedinjection;
package com.guicedee.tests;

import com.guicedee.guicedinjection.GuiceContext;
import com.guicedee.guicedinjection.interfaces.IPathContentsRejectListScanner;
import io.github.classgraph.ResourceList;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.guicedee.guicedinjection;
package com.guicedee.tests;

import com.guicedee.guicedinjection.GuiceContext;
import com.guicedee.guicedinjection.properties.GlobalProperties;

import org.junit.jupiter.api.Assertions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.guicedee.guicedinjection;
package com.guicedee.tests;

import com.guicedee.guicedinjection.GuiceContext;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.guicedee.guicedinjection;
package com.guicedee.tests;

import com.guicedee.guicedinjection.GuiceConfig;
import com.guicedee.guicedinjection.GuiceContext;
import com.guicedee.guicedinjection.interfaces.IGuiceConfig;
import com.guicedee.guicedinjection.interfaces.IGuiceConfigurator;
import lombok.extern.java.Log;
import org.junit.jupiter.api.Test;

import java.util.logging.Level;

import static org.junit.jupiter.api.Assertions.*;

@Log
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.guicedee.guicedinjection;
package com.guicedee.tests;

import com.guicedee.guicedinjection.interfaces.IGuiceConfig;
import com.guicedee.guicedinjection.interfaces.IGuiceConfigurator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.guicedee.guicedinjection;
package com.guicedee.tests;

import com.guicedee.guicedinjection.GuiceContext;
import com.guicedee.guicedinjection.pairing.OptionalPair;
import com.guicedee.guicedinjection.properties.GlobalProperties;
import org.junit.jupiter.api.Assertions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.guicedee.guicedinjection;
package com.guicedee.tests;

import com.guicedee.guicedinjection.GuiceContext;
import com.guicedee.guicedinjection.pairing.Pair;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down
Loading

0 comments on commit 2a56104

Please sign in to comment.