Skip to content

Commit

Permalink
Extract common logic to one class.
Browse files Browse the repository at this point in the history
Signed-off-by: Łukasz Dywicki <luke@code-house.org>
  • Loading branch information
splatch committed Jan 9, 2022
1 parent 8ba04b7 commit eddca79
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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 @@ -274,8 +275,7 @@ private void cleanup(Properties props) {
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);
props.put(key, ConfigPropertyUtil.cleanupEmptyCommas(propertyValue));
}
}

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.trim().replaceAll(",\\s*", ",").replaceAll(",+", ",").replaceAll(",+$", "");
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.trim().replaceAll(",\\s*", ",").replaceAll(",+", ",").replaceAll(",+$", "");
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(",+$", "");
}

}

0 comments on commit eddca79

Please sign in to comment.