Skip to content

Commit

Permalink
Removed dependencies on Guice
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Jul 27, 2023
1 parent 9723c52 commit 07f59eb
Show file tree
Hide file tree
Showing 586 changed files with 4,830 additions and 4,626 deletions.
52 changes: 26 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<hamcrest.version>2.2</hamcrest.version>
<!-- <slf4j.version>1.7.30</slf4j.version>-->
<slf4j.version>2.0.7</slf4j.version>
<guice.version>5.1.0</guice.version>
<!-- <guice.version>5.1.0</guice.version>-->
<cucumber.version>7.12.1</cucumber.version>
<gson.version>2.10.1</gson.version>
<junit5.version>5.9.3</junit5.version>
Expand Down Expand Up @@ -81,7 +81,7 @@
<filters.version>2.0.235</filters.version>
<ngwebdriver.version>1.1.6</ngwebdriver.version>
<spring.version>5.3.25</spring.version>
<spring.boot.version>2.7.5</spring.boot.version>
<spring.boot.version>2.7.14</spring.boot.version>
<jimfs.version>1.2</jimfs.version>
<jbehave.version>4.8.3</jbehave.version>
<ant.version>1.10.12</ant.version>
Expand All @@ -93,7 +93,7 @@
<xchart.version>3.5.2</xchart.version>
<ehcache.version>3.10.8</ehcache.version>
<!-- Kotlin config -->
<kotlin.version>1.8.10</kotlin.version>
<kotlin.version>1.9.0</kotlin.version>
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
</properties>
<dependencyManagement>
Expand Down Expand Up @@ -211,29 +211,29 @@
</dependency>

<!-- Guice dependencies -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guice.version}</version>
<exclusions>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
<exclusion>
<groupId>org.sonatype.sisu.inject</groupId>
<artifactId>cglib</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.google.inject</groupId>-->
<!-- <artifactId>guice</artifactId>-->
<!-- <version>${guice.version}</version>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.ow2.asm</groupId>-->
<!-- <artifactId>asm</artifactId>-->
<!-- </exclusion>-->
<!-- <exclusion>-->
<!-- <groupId>asm</groupId>-->
<!-- <artifactId>asm</artifactId>-->
<!-- </exclusion>-->
<!-- <exclusion>-->
<!-- <groupId>com.google.guava</groupId>-->
<!-- <artifactId>guava</artifactId>-->
<!-- </exclusion>-->
<!-- <exclusion>-->
<!-- <groupId>org.sonatype.sisu.inject</groupId>-->
<!-- <artifactId>cglib</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->

<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
13 changes: 3 additions & 10 deletions serenity-core/src/main/java/net/serenitybdd/core/Serenity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.serenitybdd.core.collect.NewList;
import net.serenitybdd.core.configurers.WebDriverConfigurer;
import net.serenitybdd.core.di.DependencyInjector;
import net.serenitybdd.core.di.WebDriverInjectors;
import net.serenitybdd.core.di.SerenityInfrastructure;
import net.serenitybdd.core.environment.ConfiguredEnvironment;
import net.serenitybdd.core.injectors.EnvironmentDependencyInjector;
import net.serenitybdd.core.lifecycle.LifecycleRegister;
Expand All @@ -12,7 +12,6 @@
import net.serenitybdd.core.sessions.TestSessionVariables;
import net.thucydides.core.annotations.TestCaseAnnotations;
import net.thucydides.core.environment.SystemEnvironmentVariables;
import net.thucydides.core.guice.Injectors;
import net.thucydides.core.pages.Pages;
import net.thucydides.core.screenshots.ScreenshotAndHtmlSource;
import net.thucydides.core.steps.*;
Expand All @@ -37,7 +36,6 @@
*/
public class Serenity {

private static final ThreadLocal<WebDriverFactory> factoryThreadLocal = new ThreadLocal<>();
private static final ThreadLocal<StepListener> stepListenerThreadLocal = new ThreadLocal<>();
private static final ThreadLocal<TestSessionVariables> testSessionThreadLocal = ThreadLocal.withInitial(TestSessionVariables::new);
private static final ThreadLocal<FirefoxProfile> firefoxProfileThreadLocal = new ThreadLocal<>();
Expand All @@ -51,7 +49,6 @@ public class Serenity {
public static void initialize(final Object testCase) {
ThucydidesWebDriverSupport.initialize();

setupWebDriverFactory();
setupWebdriverManager();

ThucydidesWebDriverSupport.initializeFieldsIn(testCase);
Expand Down Expand Up @@ -85,7 +82,8 @@ private static List<DependencyInjector> getDependencyInjectors() {
}

private static DependencyInjectorService getDependencyInjectorService() {
return Injectors.getInjector().getInstance(DependencyInjectorService.class);
return SerenityInfrastructure.getDependencyInjectorService();
// return Injectors.getInjector().getInstance(DependencyInjectorService.class);
}

private static List<DependencyInjector> getDefaultDependencyInjectors() {
Expand All @@ -101,7 +99,6 @@ private static List<DependencyInjector> getDefaultDependencyInjectors() {
* @param testCase any object (testcase or other) containing injectable Serenity components
*/
public static SerenityConfigurer initializeWithNoStepListener(final Object testCase) {
setupWebDriverFactory();
setupWebdriverManager();

ThucydidesWebDriverSupport.initialize();
Expand All @@ -124,10 +121,6 @@ public static void initStepListener() {
getStepEventBus().registerListener(getStepListener());
}

private static void setupWebDriverFactory() {
factoryThreadLocal.set(WebDriverInjectors.getInjector().getInstance(WebDriverFactory.class));
}

/**
* Instantiate the @Managed-annotated WebDriver instance with current WebDriver.
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@
*/
public class ClasspathCustomFindByAnnotationProviderService implements CustomFindByAnnotationProviderService {

private List<CustomFindByAnnotationService> findByAnnotationServices;
private volatile List<CustomFindByAnnotationService> findByAnnotationServices;

@Override
public List<CustomFindByAnnotationService> getCustomFindByAnnotationServices() {
if (findByAnnotationServices == null) {
findByAnnotationServices = new ArrayList<>();
List<CustomFindByAnnotationService> result = findByAnnotationServices;
if (result == null) {
synchronized (this) {
result = findByAnnotationServices;
if (result == null) {
result = new ArrayList<>();

ServiceLoader<CustomFindByAnnotationService> seleniumAnnotationServiceLoader = ServiceLoader.load(CustomFindByAnnotationService.class);
ServiceLoader<CustomFindByAnnotationService> seleniumAnnotationServiceLoader = ServiceLoader.load(CustomFindByAnnotationService.class);

for (CustomFindByAnnotationService findByAnnotationService : seleniumAnnotationServiceLoader) {
findByAnnotationServices.add(findByAnnotationService);
for (CustomFindByAnnotationService findByAnnotationService : seleniumAnnotationServiceLoader) {
result.add(findByAnnotationService);
}
findByAnnotationServices = result;
}
}
}
return findByAnnotationServices;
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.serenitybdd.core.annotations.findby.FindBy;
import net.serenitybdd.core.annotations.findby.How;
import net.serenitybdd.core.annotations.findby.di.CustomFindByAnnotationProviderService;
import net.serenitybdd.core.di.WebDriverInjectors;
import net.serenitybdd.core.di.SerenityInfrastructure;
import net.thucydides.core.webdriver.MobilePlatform;
import org.openqa.selenium.support.ByIdOrName;
import org.openqa.selenium.support.FindBys;
Expand Down Expand Up @@ -163,7 +163,8 @@ org.openqa.selenium.By getBy(Annotation annotation) {
}

public SmartAnnotations(Field field, MobilePlatform platform) {
this(field, platform, WebDriverInjectors.getInjector().getInstance(CustomFindByAnnotationProviderService.class));
// this(field, platform, WebDriverInjectors.getInjector().getInstance(CustomFindByAnnotationProviderService.class));
this(field, platform, SerenityInfrastructure.getCustomFindByAnnotationProviderService());
}

public SmartAnnotations(Field field, MobilePlatform platform,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package net.serenitybdd.core.di;

import net.serenitybdd.core.annotations.findby.di.ClasspathCustomFindByAnnotationProviderService;
import net.serenitybdd.core.annotations.findby.di.CustomFindByAnnotationProviderService;
import net.serenitybdd.core.buildinfo.DriverCapabilityRecord;
import net.serenitybdd.core.buildinfo.PropertyBasedDriverCapabilityRecord;
import net.serenitybdd.core.environment.EnvironmentSpecificConfiguration;
import net.serenitybdd.core.time.SystemClock;
import net.thucydides.core.ThucydidesSystemProperty;
import net.thucydides.core.annotations.locators.SmartElementProxyCreator;
import net.thucydides.core.annotations.locators.SmartWidgetProxyCreator;
import net.thucydides.core.batches.BatchManager;
import net.thucydides.core.batches.BatchStrategy;
import net.thucydides.core.batches.SystemVariableBasedBatchManager;
import net.thucydides.core.configuration.SystemPropertiesConfiguration;
import net.thucydides.core.configuration.WebDriverConfiguration;
import net.thucydides.core.environment.SystemEnvironmentVariables;
import net.thucydides.core.fixtureservices.ClasspathFixtureProviderService;
import net.thucydides.core.fixtureservices.FixtureProviderService;
import net.thucydides.core.logging.ConsoleLoggingListener;
import net.thucydides.core.reports.html.Formatter;
import net.thucydides.core.statistics.AtomicTestCount;
import net.thucydides.core.statistics.TestCount;
import net.thucydides.core.steps.StepListener;
import net.thucydides.core.steps.di.ClasspathDependencyInjectorService;
import net.thucydides.core.steps.di.DependencyInjectorService;
import net.thucydides.core.util.EnvironmentVariables;
import net.thucydides.core.webdriver.*;

import java.lang.reflect.InvocationTargetException;
import java.util.Optional;

/**
* Maintain thread-local or thread-safe static instances of key infrastructure classes.
* This class uses the Singleton design pattern to ensure that the same instance
* of key classes are used throughout the application.
*/
public class SerenityInfrastructure {

// Maintain a thread-safe static instance of the dependency injector service
private static final DependencyInjectorService dependencyInjectorService = new ClasspathDependencyInjectorService();

private static final ThreadLocal<CloseBrowser> closeBrowser
= ThreadLocal.withInitial(() -> new WebdriverCloseBrowser(getEnvironmentVariables()));

private static final CustomFindByAnnotationProviderService customFindByAnnotationProviderService
= new ClasspathCustomFindByAnnotationProviderService();

private static final FixtureProviderService fixtureProviderService = new ClasspathFixtureProviderService();

private static final ThreadLocal<ConsoleLoggingListener> consoleLoggingListener = ThreadLocal.withInitial(() -> new ConsoleLoggingListener(getEnvironmentVariables()));

private static Configuration configuration;

private static final ThreadLocal<Formatter> formatter = ThreadLocal.withInitial(() -> new Formatter(getEnvironmentVariables()));

private static final ElementProxyCreator elementProxyCreator = new SmartElementProxyCreator();

private static final WidgetProxyCreator widgetProxyCreator = new SmartWidgetProxyCreator();

private static final TestCount testCount = new AtomicTestCount();

private static BatchManager batchManager;

/**
* Returns the application-wide {@link DependencyInjectorService} instance.
*
* @return the singleton {@link DependencyInjectorService} instance
*/
public static DependencyInjectorService getDependencyInjectorService() {
return dependencyInjectorService;
}

public static SystemClock getClock() {
return ModelInfrastructure.getClock();
}

public static EnvironmentVariables getEnvironmentVariables() {
return SystemEnvironmentVariables.currentEnvironmentVariables();
}

public static Configuration getConfiguration() {
if (configuration == null) {
configuration = new SystemPropertiesConfiguration(getEnvironmentVariables());
}
return configuration;
}

public static DriverCapabilityRecord getDriverCapabilityRecord() {
return new PropertyBasedDriverCapabilityRecord(getConfiguration());
}

public static DriverConfiguration getDriverConfiguration() {
return new WebDriverConfiguration(getEnvironmentVariables());
}

public static CustomFindByAnnotationProviderService getCustomFindByAnnotationProviderService() {
return customFindByAnnotationProviderService;
}

public static WebDriverFactory getWebDriverFactory() {
return new WebDriverFactory(getEnvironmentVariables(),
fixtureProviderService,
closeBrowser.get());
}

public static FixtureProviderService getFixtureProviderService() {
return fixtureProviderService;
}

public static CloseBrowser getCloseBrowser() {
return closeBrowser.get();
}

public static StepListener getLoggingListener() {
return consoleLoggingListener.get();
}

public static ElementProxyCreator getElementProxyCreator() {
return elementProxyCreator;
}

public static WidgetProxyCreator getWidgetProxyCreator() {
return widgetProxyCreator;
}

public static TestCount getTestCount() {
return testCount;
}

public static Formatter getFormatter() {
return formatter.get();
}

public static BatchManager getBatchManager() {
if (batchManager == null) {
Optional<String> batchStrategy = EnvironmentSpecificConfiguration.from(getEnvironmentVariables()).getOptionalProperty(ThucydidesSystemProperty.SERENITY_BATCH_STRATEGY);
if (batchStrategy.isPresent()) {
try {
batchManager = BatchStrategy.valueOf(batchStrategy.get()).instance(getEnvironmentVariables());
} catch (Throwable e) {
throw new RuntimeException(e);
}
} else {
batchManager = new SystemVariableBasedBatchManager(getEnvironmentVariables());
}
}
return batchManager;
}

public static void resetBatchManager() {
batchManager = null;
}
}

This file was deleted.

Loading

0 comments on commit 07f59eb

Please sign in to comment.