Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KARAF-7325] Support custom properties to simplify adjustment of assemblies #1484

Open
wants to merge 2 commits into
base: karaf-4.2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
19 changes: 19 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 @@ -32,6 +32,7 @@

import org.apache.karaf.main.lock.SimpleFileLock;
import org.apache.karaf.main.util.Utils;
import org.apache.karaf.util.config.ConfigPropertyUtil;
import org.apache.karaf.util.config.PropertiesLoader;
import org.osgi.framework.Constants;

Expand Down Expand Up @@ -230,6 +231,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 +260,23 @@ 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) {
props.put(key, ConfigPropertyUtil.cleanupEmptyCommas(propertyValue));
}
}

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 @@ -97,6 +97,7 @@
import org.apache.karaf.tools.utils.model.KarafPropertyEdits;
import org.apache.karaf.util.ThreadUtils;
import org.apache.karaf.util.Version;
import org.apache.karaf.util.config.ConfigPropertyUtil;
import org.apache.karaf.util.config.PropertiesLoader;
import org.apache.karaf.util.maven.Parser;
import org.ops4j.pax.url.mvn.MavenResolver;
Expand Down Expand Up @@ -2207,7 +2208,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 = ConfigPropertyUtil.cleanupEmptyCommas(exportPackages);
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 @@ -91,6 +91,7 @@
import org.apache.karaf.tooling.utils.MavenUtil;
import org.apache.karaf.tooling.utils.MojoSupport;
import org.apache.karaf.tooling.utils.ReactorMavenResolver;
import org.apache.karaf.util.config.ConfigPropertyUtil;
import org.apache.karaf.util.config.PropertiesLoader;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -576,7 +577,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 = ConfigPropertyUtil.cleanupEmptyCommas(exportPackages);
attributes.putValue(Constants.EXPORT_PACKAGE, exportPackages);

String systemCaps = configProps.getProperty("org.osgi.framework.system.capabilities");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.karaf.util.config;

/**
* A small helper to cut off messy configuration properties which need to stay clean.
*/
public class ConfigPropertyUtil {

/**
* Make sure property value does not have empty values nor extra comma at the end.
*/
public static String cleanupEmptyCommas(String propertyValue) {
if (propertyValue == null) {
return null;
}

return propertyValue.trim()
.replaceAll(",\\s*", ",")
.replaceAll(",+", ",")
.replaceAll(",+$", "");
}

}