use of com.sun.enterprise.glassfish.bootstrap.OSGiFrameworkLauncher in project Payara by payara.
the class UberJarOSGiGlassFishRuntimeBuilder method build.
public GlassFishRuntime build(BootstrapProperties bsOptions) throws GlassFishException {
// Get all the properties in the Bootstrap options and then manipulate the Properties object.
Properties props = bsOptions.getProperties();
String uberJarURI = bsOptions.getProperties().getProperty(UBER_JAR_URI);
logger.finer("EmbeddedOSGIRuntimeBuilder.build, uberJarUri = " + uberJarURI);
URI jar = null;
try {
jar = uberJarURI != null ? new URI(uberJarURI) : Util.whichJar(GlassFishRuntime.class);
} catch (URISyntaxException ex) {
logger.log(Level.SEVERE, null, ex);
}
// XXX : Commented out by Prasad , we are again looking for instance root here. Why ?
// String instanceRoot = props.getProperty(Constants.INSTALL_ROOT_PROP_NAME);
String installRoot = bsOptions.getInstallRoot();
if (installRoot == null) {
installRoot = getDefaultInstallRoot();
props.setProperty(BootstrapProperties.INSTALL_ROOT_PROP_NAME, installRoot);
props.setProperty(BootstrapProperties.INSTALL_ROOT_URI_PROP_NAME, new File(installRoot).toURI().toString());
}
// XXX : Assuming that this property will be set along with Bootstrap options.
// This is a temporary hack, we need to separate the properties out between bootstrap and newGlassfish methods clearly
// and not mix them in the code.
String instanceRoot = props.getProperty(GlassFishProperties.INSTANCE_ROOT_PROP_NAME);
if (instanceRoot == null) {
instanceRoot = getDefaultInstanceRoot();
props.setProperty(GlassFishProperties.INSTANCE_ROOT_PROP_NAME, instanceRoot);
props.setProperty(GlassFishProperties.INSTANCE_ROOT_URI_PROP_NAME, new File(instanceRoot).toURI().toString());
}
try {
copyConfigFile(props.getProperty(GlassFishProperties.CONFIG_FILE_URI_PROP_NAME), instanceRoot);
} catch (Exception ex) {
throw new GlassFishException(ex);
}
String platform = props.getProperty(BootstrapProperties.PLATFORM_PROPERTY_KEY);
if (platform == null) {
platform = BootstrapProperties.Platform.Felix.toString();
props.setProperty(BootstrapProperties.PLATFORM_PROPERTY_KEY, platform);
}
// readConfigProperties(installRoot, props);
// embedded-osgi-main module will need this to extract the modules.
System.setProperty(UBER_JAR_URI, jar.toString());
String osgiMainModule = "jar:" + jar.toString() + "!/uber-osgi-main.jar";
props.setProperty("glassfish.auto.start", osgiMainModule);
String autoStartBundleLocation = "jar:" + jar.toString() + "!/modules/installroot-builder_jar/," + "jar:" + jar.toString() + "!/modules/instanceroot-builder_jar/," + "jar:" + jar.toString() + // TODO :: was modules/glassfish_jar
"!/modules/kernel_jar/";
if (isOSGiEnv()) {
autoStartBundleLocation = autoStartBundleLocation + ",jar:" + jar.toString() + "!/modules/osgi-modules-uninstaller_jar/";
}
props.setProperty(AUTO_START_BUNDLES_PROP, autoStartBundleLocation);
System.setProperty(AUTO_START_BUNDLES_PROP, autoStartBundleLocation);
System.setProperty(BootstrapProperties.INSTALL_ROOT_PROP_NAME, installRoot);
System.setProperty(GlassFishProperties.INSTANCE_ROOT_PROP_NAME, instanceRoot);
props.setProperty("org.osgi.framework.system.packages.extra", "org.glassfish.simpleglassfishapi; version=3.1");
// props.setProperty(org.osgi.framework.Constants.FRAMEWORK_BUNDLE_PARENT,
// org.osgi.framework.Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK);
// props.setProperty("org.osgi.framework.bootdelegation", "org.jvnet.hk2.component, " +
// "org.jvnet.hk2.component.*," +
// "org.jvnet.hk2.annotations," +
// "org.jvnet.hk2.annotations.*");
// props.setProperty("org.osgi.framework.bootdelegation", "*");
props.setProperty("org.osgi.framework.storage", instanceRoot + "/osgi-cache/Felix");
// }
logger.logp(Level.FINER, "EmbeddedOSGIRuntimeBuilder", "build", "Building file system {0}", props);
try {
if (!isOSGiEnv()) {
final OSGiFrameworkLauncher fwLauncher = new OSGiFrameworkLauncher(props);
framework = fwLauncher.launchOSGiFrameWork();
return fwLauncher.getService(GlassFishRuntime.class);
} else {
BundleContext context = ((BundleReference) (getClass().getClassLoader())).getBundle().getBundleContext();
Bundle autostartBundle = context.installBundle(props.getProperty("glassfish.auto.start"));
autostartBundle.start(Bundle.START_TRANSIENT);
logger.finer("Started autostartBundle " + autostartBundle);
return getService(GlassFishRuntime.class, context);
}
} catch (Throwable t) {
t.printStackTrace();
throw new GlassFishException(new Exception(t));
// return null;
}
}
Aggregations