add support for language configuration by system property

This commit is contained in:
Pid ster
2013-01-19 11:40:59 +00:00
parent 0adfb012ca
commit 2bf6930e5e
6 changed files with 126 additions and 0 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.DS_Store
.gradle
.idea
.classpath

View File

@@ -137,6 +137,15 @@ public class VerticleManager implements ModuleReloader {
}
}
}
Set<String> propertyNames = System.getProperties().stringPropertyNames();
for (String propertyName : propertyNames) {
if (propertyName.startsWith("vertx.langs.")) {
String lang = propertyName.replaceFirst("vertx.langs.", "");
String value = System.getProperty(propertyName);
factoryNames.put(lang, value);
}
}
}
public void block() {

View File

@@ -0,0 +1,38 @@
package org.vertx.java.tests.deploy;
import org.vertx.java.core.json.JsonObject;
import org.vertx.java.deploy.Verticle;
import org.vertx.java.deploy.impl.VerticleFactory;
import org.vertx.java.deploy.impl.VerticleManager;
public class FooLangVerticleFactory implements VerticleFactory {
private VerticleManager manager;
@Override
public void init(VerticleManager manager) {
this.manager = manager;
}
@Override
public Verticle createVerticle(String main, ClassLoader parentCL)
throws Exception {
return new Verticle() {
@Override
public void start() throws Exception {
JsonObject config = manager.getConfig();
String foo = config.getString("foo", "bar");
if (foo.equalsIgnoreCase("bar")) {
throw new Exception("foo must not be bar!");
}
}};
}
@Override
public void reportException(Throwable t) {
t.printStackTrace();
}
}

View File

@@ -0,0 +1,76 @@
package org.vertx.java.tests.deploy;
import java.io.File;
import java.net.URL;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.vertx.java.core.Handler;
import org.vertx.java.core.impl.DefaultVertx;
import org.vertx.java.core.impl.VertxInternal;
import org.vertx.java.core.json.JsonObject;
import org.vertx.java.deploy.impl.VerticleManager;
public class SystemPropertyLanguageImplementationTest {
private VerticleManager verticleManager;
private VertxInternal vertxInternal;
@BeforeClass
public static void beforeClass() {
System.setProperty("vertx.langs.foo", "org.vertx.java.tests.deploy.FooLangVerticleFactory");
}
@Before
public void before() throws Exception {
vertxInternal = new DefaultVertx();
verticleManager = new VerticleManager(vertxInternal);
}
@Test
public void deployFooVerticle() {
String main = "test.foo";
JsonObject config = new JsonObject();
config.putString("foo", "foo");
URL[] urls = new URL[0];
File currentModDir = new File(System.getProperty("java.io.tmpdir"));
String includes = null;
final CountDownLatch latch = new CountDownLatch(1);
Handler<String> doneHandler = new Handler<String>() {
@Override
public void handle(String event) {
// TODO Auto-generated method stub
latch.countDown();
}
};
verticleManager.deployVerticle(false, main, config, urls, 1, currentModDir, includes, doneHandler);
boolean await = false;
try {
await = latch.await(5000L, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (!await) {
Assert.fail("Probably not deployed");
}
}
@AfterClass
public static void cleanup() {
System.clearProperty("vertx.langs.foo");
}
}

View File

@@ -0,0 +1 @@
org.vertx.java.tests.deploy.FooLangVerticleFactory

View File

@@ -0,0 +1 @@
// hello