Search in sources :

Example 1 with ClassLoaderResourceProvider

use of org.apache.sling.launchpad.base.impl.ClassLoaderResourceProvider in project sling by apache.

the class MainDelegate method start.

@Override
public boolean start() {
    Map<String, String> props = new HashMap<String, String>();
    // parse the command line (exit in case of failure)
    if (commandLine == null) {
        setCommandLine(new HashMap<String, String>());
    }
    // if sling.home was set on the command line, set it in the properties
    if (slingHome != null) {
        props.put(SharedConstants.SLING_HOME, slingHome);
    } else if (commandLine.containsKey(SharedConstants.SLING_HOME)) {
        props.put(SharedConstants.SLING_HOME, commandLine.get(SharedConstants.SLING_HOME));
    }
    // ensure sling.launchpad is set
    if (!commandLine.containsKey(SharedConstants.SLING_LAUNCHPAD)) {
        commandLine.put(SharedConstants.SLING_LAUNCHPAD, slingHome);
    }
    // check sling.properties in the command line
    final String slingPropertiesProp = commandLine.remove(SharedConstants.SLING_PROPERTIES);
    if (slingPropertiesProp != null) {
        props.put(SharedConstants.SLING_PROPERTIES, slingPropertiesProp);
    }
    // set up and configure Felix Logger
    int logLevel;
    if (!commandLine.containsKey(PROP_LOG_LEVEL)) {
        logLevel = DEFAULT_LOG_LEVEL;
    } else {
        logLevel = toLogLevelInt(commandLine.get(PROP_LOG_LEVEL), DEFAULT_LOG_LEVEL);
        commandLine.put(LOG_LEVEL_PROP, String.valueOf(logLevel));
    }
    final Logger logger = new SlingLogger();
    // default log level: prevent tons of needless WARN from the framework
    logger.setLogLevel(Logger.LOG_ERROR);
    if (System.getProperty(PROP_BOOT_LOG_LEVEL) != null) {
        try {
            logger.setLogLevel(Integer.parseInt(System.getProperty(PROP_BOOT_LOG_LEVEL)));
        } catch (final NumberFormatException ex) {
        // just ignore
        }
    }
    try {
        LaunchpadContentProvider resProvider = new ClassLoaderResourceProvider(getClass().getClassLoader());
        // creating the instance launches the framework and we are done here
        // ..
        sling = new Sling(notifiable, logger, resProvider, props) {

            // overwrite the loadPropertiesOverride method to inject the
            // command line arguments unconditionally. These will not be
            // persisted in any properties file, though
            @Override
            protected void loadPropertiesOverride(Map<String, String> properties) {
                if (commandLine != null) {
                    properties.putAll(commandLine);
                }
                // Display port number on console, in case HttpService doesn't. This is logged as late as
                // possible in order to pick up defaults from the Sling property files, although system
                // property substitutions will be missed.
                info("HTTP server port: " + properties.get(PROP_PORT), null);
            }
        };
        // we successfully started it
        return true;
    } catch (BundleException be) {
        error("Failed to Start OSGi framework", be);
    }
    // we failed to start
    return false;
}
Also used : HashMap(java.util.HashMap) Logger(org.apache.felix.framework.Logger) Sling(org.apache.sling.launchpad.base.impl.Sling) LaunchpadContentProvider(org.apache.sling.launchpad.api.LaunchpadContentProvider) ClassLoaderResourceProvider(org.apache.sling.launchpad.base.impl.ClassLoaderResourceProvider) BundleException(org.osgi.framework.BundleException)

Aggregations

HashMap (java.util.HashMap)1 Logger (org.apache.felix.framework.Logger)1 LaunchpadContentProvider (org.apache.sling.launchpad.api.LaunchpadContentProvider)1 ClassLoaderResourceProvider (org.apache.sling.launchpad.base.impl.ClassLoaderResourceProvider)1 Sling (org.apache.sling.launchpad.base.impl.Sling)1 BundleException (org.osgi.framework.BundleException)1