aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/main/java/com/yahoo/jdisc/core/Main.java
diff options
context:
space:
mode:
authorArne Juul <arnej@yahoo-inc.com>2016-06-16 16:22:46 +0200
committerArne Juul <arnej@yahoo-inc.com>2016-06-16 16:22:46 +0200
commit480d2e9bb5bd52cf08b3ad28e2dce5862b45e8d6 (patch)
treed4e817c24da77509b57c2e23ea40622a976da360 /jdisc_core/src/main/java/com/yahoo/jdisc/core/Main.java
parent88b8aa1f8ddb13994f3f1e356d2687e346909b11 (diff)
add main() for running without jsvc.
* add StandaloneMain class * move common code to new Main class
Diffstat (limited to 'jdisc_core/src/main/java/com/yahoo/jdisc/core/Main.java')
-rw-r--r--jdisc_core/src/main/java/com/yahoo/jdisc/core/Main.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/Main.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/Main.java
new file mode 100644
index 00000000000..1fd5cad04db
--- /dev/null
+++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/Main.java
@@ -0,0 +1,45 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.core;
+
+import com.google.inject.Module;
+import com.yahoo.jdisc.application.ContainerBuilder;
+import com.yahoo.jdisc.application.OsgiFramework;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+
+/**
+ * @author simon
+ */
+public class Main {
+
+ static OsgiFramework newOsgiFramework() {
+ String cachePath = System.getProperty("jdisc.cache.path");
+ if (cachePath == null) {
+ throw new IllegalStateException("System property 'jdisc.cache.path' not set.");
+ }
+ FelixParams params = new FelixParams()
+ .setCachePath(cachePath)
+ .setLoggerEnabled(Boolean.valueOf(System.getProperty("jdisc.logger.enabled", "true")));
+ for (String str : ContainerBuilder.safeStringSplit(System.getProperty("jdisc.export.packages"), ",")) {
+ params.exportPackage(str);
+ }
+ return new FelixFramework(params);
+ }
+
+ static Iterable<Module> newConfigModule() {
+ String configFile = System.getProperty("jdisc.config.file");
+ if (configFile == null) {
+ return Collections.emptyList();
+ }
+ Module configModule;
+ try {
+ configModule = ApplicationConfigModule.newInstanceFromFile(configFile);
+ } catch (IOException e) {
+ throw new IllegalStateException("Exception thrown while reading config file '" + configFile + "'.", e);
+ }
+ return Arrays.asList(configModule);
+ }
+
+}