Skip to content

Commit

Permalink
refactor: move restx.config from core to factory
Browse files Browse the repository at this point in the history
- ConfigLoader is no more annotated with @component, a FactoryMachine have been implemented to provides ConfigLoader components:
ConfigLoaderFactoryMachine
- new FactoryMachine in restx-factory have been declared in META-INF/services/restx.factory.FactoryMachine
(ConsolidatedConfigFactoryMachine, ElementsFromConfigFactoryMachine and ConfigLoaderFactoryMachine)
- In FactoryTest ElementsFromConfig component is deactivated, it can not be build because of "missing.dependency" injected
in "mandatory.dep.result1" component (from TestMandatoryDependency module).

This commit don't change the fact that restx-core-annotation-processor and restx-core should be used as dependencies in order to use
@Settings, @SettingsKey and ConfigSupplier.

Next thing to do is to move SettingsAnnotationProcessor in restx-factory.
  • Loading branch information
a-peyrard committed Dec 14, 2014
1 parent 1a48982 commit ffbda71
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 19 deletions.
19 changes: 16 additions & 3 deletions restx-factory-testing/src/test/java/restx/factory/FactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package restx.factory;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;


import com.google.common.base.Optional;
import org.junit.BeforeClass;
import org.junit.Test;
import restx.factory.TestComponentPriorities.V;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import restx.factory.TestComponentPriorities.V;

/**
* @author fcamblor
*/
public class FactoryTest {

/**
* ElementsFromConfig component can not be build, because of module TestMandatoryDependency
* which use a missing dependency.
*/
@BeforeClass
public static void deactivateElementsFromConfig() {
System.setProperty("restx.activation::restx.factory.FactoryMachine::ElementsFromConfig", "false");
}

@Test
public void should_optional_dependency_works_and_not_be_injected_when_absent(){
// check that we don't get a stack overflow error due to box closing the factory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,26 @@
import com.google.common.io.Resources;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import restx.common.ConfigElement;
import restx.common.RestxConfig;
import restx.common.StdRestxConfig;
import restx.factory.Component;

import javax.inject.Named;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import restx.common.ConfigElement;
import restx.common.RestxConfig;
import restx.common.StdRestxConfig;

/**
* User: xavierhanin
* Date: 9/24/13
* Time: 11:54 PM
*/
@Component
public class ConfigLoader {
private final static Logger logger = LoggerFactory.getLogger(ConfigLoader.class);

private final String env;

public ConfigLoader(@Named("env") Optional<String> env) {
public ConfigLoader(Optional<String> env) {
this.env = env.or("default");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package restx.config;

import com.google.common.collect.ImmutableSet;

import restx.factory.BillOfMaterials;
import restx.factory.BoundlessComponentBox;
import restx.factory.Factory;
import restx.factory.Machine;
import restx.factory.Name;
import restx.factory.SatisfiedBOM;
import restx.factory.SingleNameFactoryMachine;
import restx.factory.StdMachineEngine;

/**
* Machine for {@link ConfigLoader}.
*/
@Machine
public class ConfigLoaderFactoryMachine extends SingleNameFactoryMachine<ConfigLoader> {
public static final Name<ConfigLoader> NAME = Name.of(ConfigLoader.class, "ConfigLoader");

public ConfigLoaderFactoryMachine() {
super(0, new StdMachineEngine<ConfigLoader>(NAME, 0, BoundlessComponentBox.FACTORY) {
private final Factory.Query<String> env = Factory.Query.byName(Name.of(String.class, "env")).optional();

@Override
public BillOfMaterials getBillOfMaterial() {
return new BillOfMaterials(ImmutableSet.<Factory.Query<?>>of(
env
));
}

@Override
protected ConfigLoader doNewComponent(SatisfiedBOM satisfiedBOM) {
return new ConfigLoader(
satisfiedBOM.getOneAsComponent(env)
);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
package restx.config;

import static com.google.common.collect.Iterables.addAll;


import com.google.common.base.Optional;
import com.google.common.collect.Iterables;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import restx.common.ConfigElement;
import restx.common.RestxConfig;
import restx.common.StdRestxConfig;
import restx.factory.*;

import java.util.*;

import static com.google.common.collect.Iterables.addAll;
import restx.factory.BillOfMaterials;
import restx.factory.BoundlessComponentBox;
import restx.factory.Factory;
import restx.factory.FactoryMachine;
import restx.factory.Machine;
import restx.factory.MachineEngine;
import restx.factory.Name;
import restx.factory.NamedComponent;
import restx.factory.SatisfiedBOM;
import restx.factory.StdMachineEngine;

/**
* User: xavierhanin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import restx.common.ConfigElement;
import restx.common.RestxConfig;
import restx.factory.*;

import java.util.Collections;
import java.util.Set;
import restx.common.ConfigElement;
import restx.common.RestxConfig;
import restx.factory.BillOfMaterials;
import restx.factory.BoundlessComponentBox;
import restx.factory.DefaultFactoryMachine;
import restx.factory.Factory;
import restx.factory.FactoryMachine;
import restx.factory.Machine;
import restx.factory.MachineEngine;
import restx.factory.Name;
import restx.factory.NoDepsMachineEngine;
import restx.factory.SatisfiedBOM;
import restx.factory.StdMachineEngine;

/**
* User: xavierhanin
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
restx.factory.SystemPropertyFactoryMachine
restx.factory.SystemPropertyFactoryMachine
restx.config.ConfigLoaderFactoryMachine
restx.config.ConsolidatedConfigFactoryMachine
restx.config.ElementsFromConfigFactoryMachine

0 comments on commit ffbda71

Please sign in to comment.