use of org.osgi.framework.launch.FrameworkFactory in project karaf by apache.
the class Main method launch.
public void launch() throws Exception {
boolean clean = Arrays.asList(args).contains("clean");
boolean cleanall = Arrays.asList(args).contains("cleanall");
if (clean || cleanall) {
// clean instance
final Path dataDir = new File(System.getProperty(ConfigProperties.PROP_KARAF_DATA)).toPath();
final Path logDir = new File(System.getProperty(ConfigProperties.PROP_KARAF_LOG)).toPath();
if (Files.exists(dataDir)) {
try {
Files.walkFileTree(dataDir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attributes) throws IOException {
if (cleanall || (clean && !file.startsWith(logDir))) {
Files.delete(file);
}
return super.visitFile(file, attributes);
}
@Override
public FileVisitResult postVisitDirectory(final Path dir, final IOException exception) throws IOException {
if (cleanall || (clean && dir.compareTo(logDir) != 0)) {
Files.delete(dir);
}
return super.postVisitDirectory(dir, exception);
}
});
} catch (final IOException ioException) {
LOG.log(Level.WARNING, "Can't delete " + dataDir + " (" + ioException.getMessage() + ")", ioException);
}
Files.createDirectories(dataDir.resolve("tmp"));
}
}
if (config == null) {
config = new ConfigProperties();
}
config.performInit();
if (config.delayConsoleStart) {
System.out.println(config.startupMessage);
}
String log4jConfigPath = System.getProperty("karaf.etc") + "/org.ops4j.pax.logging.cfg";
BootstrapLogManager.setProperties(config.props, log4jConfigPath);
/* KARAF-5798: write the PID whether or not the lock has been acquired */
InstanceHelper.writePid(config.pidFile);
BootstrapLogManager.configureLogger(LOG);
for (String provider : config.securityProviders) {
addSecurityProvider(provider);
}
List<File> bundleDirs = getBundleRepos();
ArtifactResolver resolver = new SimpleMavenResolver(bundleDirs);
// Start up the OSGI framework
classLoader = createClassLoader(resolver);
FrameworkFactory factory = loadFrameworkFactory(classLoader);
framework = factory.newFramework(config.props);
setLogger();
framework.init();
framework.getBundleContext().addFrameworkListener(lockCallback);
framework.start();
FrameworkStartLevel sl = framework.adapt(FrameworkStartLevel.class);
sl.setInitialBundleStartLevel(config.defaultBundleStartlevel);
// If we have a clean state, install everything
if (framework.getBundleContext().getBundles().length == 1) {
LOG.info("Installing and starting initial bundles");
File startupPropsFile = new File(config.karafEtc, STARTUP_PROPERTIES_FILE_NAME);
List<BundleInfo> bundles = readBundlesFromStartupProperties(startupPropsFile);
installAndStartBundles(resolver, framework.getBundleContext(), bundles);
LOG.info("All initial bundles installed and set to start");
}
ServerInfo serverInfo = new ServerInfoImpl(args, config);
framework.getBundleContext().registerService(ServerInfo.class, serverInfo, null);
activatorManager = new KarafActivatorManager(classLoader, framework);
activatorManager.startKarafActivators();
setStartLevel(config.lockStartLevel);
// Progress bar
if (config.delayConsoleStart) {
new StartupListener(LOG, framework.getBundleContext());
}
monitorThread = monitor();
registerSignalHandler();
watchdog();
}
Aggregations