Skip to content

Commit

Permalink
Support for additional custom properties which can be injected via op…
Browse files Browse the repository at this point in the history
…tional files.

Signed-off-by: Łukasz Dywicki <luke@code-house.org>
  • Loading branch information
splatch committed Jan 9, 2022
1 parent 8135ca6 commit 8ba04b7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ org.osgi.framework.system.packages= \
org.apache.karaf.jaas.boot.principal;uses:=javax.security.auth;version="@@karaf.osgi.version@@",\
org.apache.karaf.jaas.boot;uses:="javax.security.auth,javax.security.auth.callback,javax.security.auth.login,javax.security.auth.spi,org.osgi.framework";version="@@karaf.osgi.version@@",\
org.apache.karaf.info;version="@@karaf.osgi.version@@",\
${jre-${java.specification.version}}
${jre-${java.specification.version}},\
${custom.org.osgi.framework.system.packages}

#
# Extra packages appended after standard packages
Expand All @@ -91,12 +92,14 @@ org.osgi.framework.system.packages.extra= \
org.apache.karaf.branding, \
sun.misc, \
com.sun.jmx.remote.protocol, \
com.sun.jmx.remote.protocol.jmxmp
com.sun.jmx.remote.protocol.jmxmp, \
${custom.org.osgi.framework.system.packages.extra}

org.osgi.framework.system.capabilities= \
${eecap-${java.specification.version}}, \
${${karaf.framework}-capabilities}, \
${karaf-capabilities}
${karaf-capabilities}, \
${custom-capabilities}

karaf-capabilities= \
osgi.service;objectClass:List<String>=org.apache.karaf.info.ServerInfo
Expand Down Expand Up @@ -185,7 +188,8 @@ org.osgi.framework.bootdelegation=\
jdk.nashorn.*, \
sun.*, \
jdk.internal.reflect, \
jdk.internal.reflect.*
jdk.internal.reflect.*, \
${custom.org.osgi.framework.bootdelegation}

# jVisualVM support
# in order to use Karaf with jvisualvm, the org.osgi.framework.bootdelegation property has to contain the org.netbeans.lib.profiler.server package
Expand All @@ -195,7 +199,7 @@ org.osgi.framework.bootdelegation=\
#
# YourKit support
# in order to use Karaf with YourKit, the org.osgi.framework.bootdelegation property has to contain the com.yourkit.* packages
# and, so, it should look like:
# and, so, it should look like:
#
# org.osgi.framework.bootdelegation=org.apache.karaf.jaas.boot,org.apache.karaf.jaas.boot.principal,sun.*,com.sun.*,javax.transaction,javax.transaction.*,javax.xml.crypto,javax.xml.crypto.*,org.apache.xerces.jaxp.datatype,org.apache.xerces.stax,org.apache.xerces.parsers,org.apache.xerces.jaxp,org.apache.xerces.jaxp.validation,org.apache.xerces.dom,com.yourkit.*
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#
################################################################################

${optionals} = custom.jre.properties

#
# Java platform package export properties.
#
Expand Down Expand Up @@ -182,7 +184,8 @@ jre-1.6= \
org.w3c.dom.xpath, \
org.xml.sax, \
org.xml.sax.ext, \
org.xml.sax.helpers
org.xml.sax.helpers, \
${custom.jre-1.6}

# Standard package set. Note that:
# - javax.transaction* is exported with a mandatory attribute
Expand Down Expand Up @@ -338,7 +341,8 @@ jre-1.7= \
org.xml.sax, \
org.xml.sax.ext, \
org.xml.sax.helpers, \
com.sun.nio.sctp
com.sun.nio.sctp, \
${custom.jre-1.7}

#
# A note about javax.transaction and javax.transaction.xa packages in JDK8 and JDK9+
Expand Down Expand Up @@ -571,7 +575,8 @@ jre-1.8= \
org.xml.sax, \
org.xml.sax.ext, \
org.xml.sax.helpers, \
com.sun.nio.sctp
com.sun.nio.sctp, \
${custom.jre-8}

jre-9= \
javax.accessibility, \
Expand Down Expand Up @@ -734,10 +739,11 @@ jre-9= \
com.sun.security.sasl, \
com.sun.security.sasl.digest, \
com.sun.security.sasl.ntlm, \
com.sun.security.sasl.util
com.sun.security.sasl.util, \
${custom.jre-9}

jre-10 = ${jre-9}
jre-11 = ${jre-10}
jre-13 = ${jre-11}
jre-14 = ${jre-13}
jre-15 = ${jre-14}
jre-10 = ${jre-9}, ${custom.jre-10}
jre-11 = ${jre-10}, ${custom.jre-11}
jre-13 = ${jre-11}, ${custom.jre-13}
jre-14 = ${jre-13}, ${custom.jre-14}
jre-15 = ${jre-14}, ${custom.jre-15}
21 changes: 21 additions & 0 deletions main/src/main/java/org/apache/karaf/main/ConfigProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Arrays;
import java.util.UUID;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.felix.utils.properties.Properties;

import org.apache.karaf.main.lock.SimpleFileLock;
Expand Down Expand Up @@ -230,6 +232,7 @@ public ConfigProperties() throws Exception {
PropertiesLoader.loadSystemProperties(new File(karafEtc, SYSTEM_PROPERTIES_FILE_NAME));

this.props = PropertiesLoader.loadConfigProperties(new File(karafEtc, CONFIG_PROPERTIES_FILE_NAME));
cleanup(this.props);

this.securityProviders = getSecurityProviders();
this.defaultStartLevel = Integer.parseInt(props.getProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL));
Expand Down Expand Up @@ -258,6 +261,24 @@ public ConfigProperties() throws Exception {
System.setProperty(KARAF_DELAY_CONSOLE, Boolean.toString(this.delayConsoleStart));
}

private void cleanup(Properties props) {
cleanup(props, "org.osgi.framework.system.packages.extra");
cleanup(props, "org.osgi.framework.system.packages");
for (String key : props.keySet()) {
if (key.startsWith("jre-")) {
cleanup(props, key);
}
}
}

private void cleanup(Properties props, String key) {
String propertyValue = props.get(key);
if (propertyValue != null) {
String cleanedUp = propertyValue.trim().replaceAll(",\\s*", ",").replaceAll(",+", ",").replaceAll(",+$", "");
props.put(key, cleanedUp);
}
}

public void performInit() throws Exception {
File cleanAllIndicatorFile = new File(karafData, "clean_all");
File cleanCacheIndicatorFile = new File(karafData, "clean_cache");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,7 @@ private BundleRevision getSystemBundle() throws Exception {
if (configProps.containsKey(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA)) {
exportPackages += "," + configProps.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
}
exportPackages = exportPackages.replaceAll(",\\s*,", ",");
exportPackages = exportPackages.trim().replaceAll(",\\s*", ",").replaceAll(",+", ",").replaceAll(",+$", "");
attributes.putValue(Constants.EXPORT_PACKAGE, exportPackages);

String systemCaps = configProps.getProperty(Constants.FRAMEWORK_SYSTEMCAPABILITIES, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ private Bundle getSystemBundle(Map<String, Map<VersionRange, Map<String, String>
if (configProps.containsKey("org.osgi.framework.system.packages.extra")) {
exportPackages += "," + configProps.getProperty("org.osgi.framework.system.packages.extra");
}
exportPackages = exportPackages.replaceAll(",\\s*,", ",");
exportPackages = exportPackages.trim().replaceAll(",\\s*", ",").replaceAll(",+", ",").replaceAll(",+$", "");
attributes.putValue(Constants.EXPORT_PACKAGE, exportPackages);

String systemCaps = configProps.getProperty("org.osgi.framework.system.capabilities");
Expand Down

0 comments on commit 8ba04b7

Please sign in to comment.