SLING-9648 do not throw exception in case 'sling.properties.url' is not (#3)
used
'sling.properties.url' is only used for the Sling Launchpad but no
longer with the Feature Model Launcher
diff --git a/pom.xml b/pom.xml
index 62ffe7c..61de8b2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,6 +76,11 @@
<artifactId>org.osgi.annotation.versioning</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.annotation.bundle</artifactId>
+ <scope>provided</scope>
+ </dependency>
<!-- https://osgi.org/javadoc/osgi.cmpn/7.0.0/org/osgi/service/component/annotations/package-frame.html -->
<dependency>
<groupId>org.osgi</groupId>
diff --git a/src/main/java/org/apache/sling/settings/impl/Activator.java b/src/main/java/org/apache/sling/settings/impl/Activator.java
new file mode 100644
index 0000000..ef219a5
--- /dev/null
+++ b/src/main/java/org/apache/sling/settings/impl/Activator.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.settings.impl;
+
+import org.osgi.annotation.bundle.Header;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+
+@Header(name = Constants.BUNDLE_ACTIVATOR, value = "${@class}")
+public class Activator implements BundleActivator {
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ SlingPropertiesPrinter.init(context);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ // no need to unregister services registered at start(...) as this happens implicitly
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java b/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java
index 3864e05..cafe764 100644
--- a/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java
+++ b/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java
@@ -23,25 +23,29 @@
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.URL;
+import java.util.Dictionary;
+import java.util.Hashtable;
import java.util.Iterator;
import java.util.Properties;
import java.util.SortedSet;
import java.util.TreeSet;
import org.osgi.framework.BundleContext;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This is a configuration printer for the web console which
* prints out the Sling properties from Launchpad if available.
*/
-@Component(service = SlingPropertiesPrinter.class, property= {"felix.webconsole.label=slingprops","felix.webconsole.title=Sling Properties","felix.webconsole.configprinter.modes=always"})
public class SlingPropertiesPrinter {
- @Activate
- public SlingPropertiesPrinter(BundleContext bundleContext) throws IOException {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SlingPropertiesPrinter.class);
+
+ // Called from bundle activator
+ public static void init(BundleContext bundleContext) throws IOException {
// if the properties are available, we register the sling properties plugin
+ Properties props;
final String propUrl = bundleContext.getProperty("sling.properties.url");
if ( propUrl != null ) {
// try to read properties
@@ -58,17 +62,35 @@
props = tmp;
} catch (IOException ioe) {
- throw new IOException("Unable to read sling properties from " + propUrl, ioe);
+ LOGGER.error("Unable to read sling properties from '{}'", propUrl, ioe);
+ return;
}
} else {
- throw new IllegalStateException("No bundle context property 'sling.properties.url' provided");
+ LOGGER.debug("No bundle context property 'sling.properties.url' provided, not starting 'slingprops' webconsole plugin!");
+ return;
}
+ final SlingPropertiesPrinter propertiesPrinter = new SlingPropertiesPrinter(props);
+ final Dictionary<String, String> serviceProps = new Hashtable<>();
+ serviceProps.put("felix.webconsole.label", "slingprops");
+ serviceProps.put("felix.webconsole.title", "Sling Properties");
+ serviceProps.put("felix.webconsole.configprinter.modes", "always");
+
+ // no need to keep serviceregistration return value as deregistration only happens automatically once bundle stops
+ bundleContext.registerService(SlingPropertiesPrinter.class.getName(),
+ propertiesPrinter,
+ serviceProps);
}
+
private static String HEADLINE = "Apache Sling Launchpad Properties";
private final Properties props;
+ public SlingPropertiesPrinter(Properties props) throws IOException {
+ this.props = props;
+ }
+
+
/**
* Print out the servlet filter chains.
* @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)