mirror of
https://github.com/jlengrand/vert.x.git
synced 2026-03-10 08:51:19 +00:00
add support for language configuration by system property
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.DS_Store
|
||||
.gradle
|
||||
.idea
|
||||
.classpath
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.vertx.java.tests.deploy.FooLangVerticleFactory
|
||||
1
vertx-testsuite/src/test/resources/test.foo
Normal file
1
vertx-testsuite/src/test/resources/test.foo
Normal file
@@ -0,0 +1 @@
|
||||
// hello
|
||||
Reference in New Issue
Block a user