Skip to content

Commit

Permalink
Merge pull request ctco#38 from viktor-yengovatov/master
Browse files Browse the repository at this point in the history
ctco#34 Support for configuration profiles
  • Loading branch information
AlexeyBuzdin authored Jun 20, 2016
2 parents 2a322d3 + 7ce5848 commit 6689a2a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static lv.ctco.cukesrest.internal.AssertionFacade.*;

public class GuiceModule extends AbstractModule {

@Override
protected void configure() {
bindInterceptor(new InflateContextInterceptor(), InflateContext.class);
Expand Down Expand Up @@ -56,7 +55,7 @@ private void bindPlugins() {
Multibinder<CukesRestPlugin> multibinder = Multibinder.newSetBinder(binder(), CukesRestPlugin.class);
ClassLoader classLoader = GuiceModule.class.getClassLoader();
Properties prop = new Properties();
URL url = classLoader.getResource("cukes.properties");
URL url = createCukesPropertyFileUrl(classLoader);
if (url == null) return;
prop.load(url.openStream());
String pluginsArr = prop.getProperty(CukesOptions.PROPERTIES_PREFIX + CukesOptions.PLUGINS);
Expand All @@ -70,4 +69,15 @@ private void bindPlugins() {
throw new CukesRuntimeException("Binding of CukesRest plugins failed");
}
}

/**
* @see GlobalWorld#createCukesPropertyFileUrl(ClassLoader)
*/
private URL createCukesPropertyFileUrl(final ClassLoader classLoader) {
String cukesProfile = System.getProperty("cukes.profile");
String propertiesFileName = cukesProfile == null || cukesProfile.isEmpty()
? "cukes.properties"
: "cukes-" + cukesProfile + ".properties";
return classLoader.getResource(propertiesFileName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@

@Singleton
class GlobalWorld {

private Map<String, String> context;

@Inject
public void reconstruct() {
/* User Specified Values */
context = new ConcurrentHashMap<String, String>();
Properties prop = new Properties();
String cukesProfile = System.getProperty("cukes.profile");
String propertiesFileName = cukesProfile != null ? "cukes-" + cukesProfile + ".properties" : "cukes.properties";
URL url = GlobalWorld.class.getClassLoader().getResource(propertiesFileName);
URL url = createCukesPropertyFileUrl(GlobalWorld.class.getClassLoader());
if (url != null) {
try {
prop.load(url.openStream());
Expand Down Expand Up @@ -74,4 +71,15 @@ public Set<String> keys() {
public void remove(String key) {
context.remove(key);
}

/**
* @see lv.ctco.cukesrest.internal.GuiceModule#createCukesPropertyFileUrl(ClassLoader)
*/
private URL createCukesPropertyFileUrl(final ClassLoader classLoader) {
String cukesProfile = System.getProperty("cukes.profile");
String propertiesFileName = cukesProfile == null || cukesProfile.isEmpty()
? "cukes.properties"
: "cukes-" + cukesProfile + ".properties";
return classLoader.getResource(propertiesFileName);
}
}

0 comments on commit 6689a2a

Please sign in to comment.