diff options
| author | Robert Gemmell <robbie@apache.org> | 2011-08-21 15:30:31 +0000 |
|---|---|---|
| committer | Robert Gemmell <robbie@apache.org> | 2011-08-21 15:30:31 +0000 |
| commit | 8a24b483936828f60279576b3093016e62128461 (patch) | |
| tree | ed123b2ffcbe0a2e242627018d4367d071e83f52 /qpid/java | |
| parent | acfc50e9a15f0a25b2f9eff1b2c83a643e9691ca (diff) | |
| download | qpid-python-8a24b483936828f60279576b3093016e62128461.tar.gz | |
QPID-3414: Refactoring. List of packages to be exported as OSGi system packages now held in separate properties file.
Applied patch by Keith Wall
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1159999 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
5 files changed, 333 insertions, 48 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java new file mode 100644 index 0000000000..644f714c8c --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java @@ -0,0 +1,91 @@ +/* + * 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.qpid.server.plugins; + +import java.util.Iterator; +import java.util.Map; + +import org.osgi.framework.Version; + +/** + * Utility class to convert a map of package name to version numbers into the string + * with the format expected of a OSGi system package declaration: + * + * <code> + * org.xyz; version=1.0.0, org.xyz.xyz; version=1.0.0,... + * </code> + * + * Additionally, if the caller has provided a qpidPackageReleaseNumber and the package + * begins org.apache.qpid, this release number will be used, in preference to the one + * found in the Map. + * + * @see org.osgi.framework.Constants#FRAMEWORK_SYSTEMPACKAGES + * + */ +public class OsgiSystemPackageUtil +{ + private static final String APACHE_QPID_PKG_PREFIX = "org.apache.qpid"; + + private final Map<String, String> _packageNameVersionMap; + private final Version _qpidPackageReleaseNumber; + + public OsgiSystemPackageUtil(final Version qpidPackageReleaseNumber, final Map<String, String> packageNameVersionMap) + { + _qpidPackageReleaseNumber = qpidPackageReleaseNumber; + _packageNameVersionMap = packageNameVersionMap; + } + + public String getFormattedSystemPackageString() + { + if (_packageNameVersionMap == null || _packageNameVersionMap.size() == 0) + { + return null; + } + + final StringBuilder packages = new StringBuilder(); + + for(Iterator<String> itr = _packageNameVersionMap.keySet().iterator(); itr.hasNext();) + { + final String packageName = itr.next(); + final String packageVersion; + + if (_qpidPackageReleaseNumber != null && packageName.startsWith(APACHE_QPID_PKG_PREFIX)) + { + packageVersion = _qpidPackageReleaseNumber.toString(); + } + else + { + packageVersion = _packageNameVersionMap.get(packageName); + } + + packages.append(packageName); + packages.append("; "); + packages.append("version="); + packages.append(packageVersion); + + if (itr.hasNext()) + { + packages.append(", "); + } + } + + return packages.toString(); + } + +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties new file mode 100644 index 0000000000..aaab4f76cc --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties @@ -0,0 +1,93 @@ +# +# 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. +# + +# +# OSGi framework system package list +# +# PluginManager uses these properties to construct the FRAMEWORK_SYSTEMPACKAGES list +# + +# Format is: +# <package>=<version> +# and PluginManager will convert this into: +# <package>; version=<version> +# e.g. org.osgi.framework; version=1.3.0 + +javax.management.openmbean=1.0.0 +javax.management=1.0.0 + +javax.security.auth=1.0.0 +javax.security.auth.callback=1.0.0 +javax.security.sasl=1.0.0 +javax.security=1.0.0 + +org.xml.sax=1.0.0 +org.xml.sax.helpers=1.0.0 + +org.osgi.framework=1.3.0 +org.osgi.service.packageadmin=1.2.0 +org.osgi.service.startlevel=1.0.0 +org.osgi.service.url=1.0.0 +org.osgi.util.tracker=1.0.0 + +org.apache.commons.configuration=1.0.0 + +org.apache.commons.lang=1.0.0 +org.apache.commons.lang.builder=1.0.0 +org.apache.commons.logging=1.0.0 + +org.apache.log4j=1.2.12 + +org.slf4j=1.6.1 + +# For Qpid packages (org.apache.qpid), the version number is automatically overridden by QpidPropertis#getReleaseVersion() + +org.apache.qpid.junit.extensions.util=0.0.0 +org.apache.qpid=0.0.0 +org.apache.qpid.common=0.0.0 +org.apache.qpid.exchange=0.0.0 +org.apache.qpid.framing=0.0.0 +org.apache.qpid.management.common.mbeans.annotations=0.0.0 +org.apache.qpid.protocol=0.0.0 +org.apache.qpid.transport=0.0.0 +org.apache.qpid.transport.codec=0.0.0 +org.apache.qpid.server.binding=0.0.0 +org.apache.qpid.server.configuration=0.0.0 +org.apache.qpid.server.configuration.plugins=0.0.0 +org.apache.qpid.server.configuration.management=0.0.0 +org.apache.qpid.server.exchange=0.0.0 +org.apache.qpid.server.logging=0.0.0 +org.apache.qpid.server.logging.actors=0.0.0 +org.apache.qpid.server.logging.subjects=0.0.0 +org.apache.qpid.server.management=0.0.0 +org.apache.qpid.server.persistent=0.0.0 +org.apache.qpid.server.plugins=0.0.0 +org.apache.qpid.server.protocol=0.0.0 +org.apache.qpid.server.queue=0.0.0 +org.apache.qpid.server.registry=0.0.0 +org.apache.qpid.server.security=0.0.0 +org.apache.qpid.server.security.access=0.0.0 +org.apache.qpid.server.security.access.plugins=0.0.0 +org.apache.qpid.server.security.auth=0.0.0 +org.apache.qpid.server.security.auth.sasl=0.0.0 +org.apache.qpid.server.security.auth.manager=0.0.0 +org.apache.qpid.server.virtualhost=0.0.0 +org.apache.qpid.server.virtualhost.plugins=0.0.0 +org.apache.qpid.util=0.0.0 + diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java index c8a7b56ccb..bb3e4a61d1 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java @@ -30,18 +30,22 @@ import static org.osgi.framework.Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT; import static org.osgi.framework.Constants.FRAMEWORK_SYSTEMPACKAGES; import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.IdentityHashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import org.apache.commons.configuration.ConfigurationException; import org.apache.felix.framework.Felix; import org.apache.felix.framework.util.StringMap; import org.apache.log4j.Logger; import org.apache.qpid.common.Closeable; +import org.apache.qpid.common.QpidProperties; import org.apache.qpid.server.configuration.TopicConfiguration; import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionConfiguration.SlowConsumerDetectionConfigurationFactory; @@ -59,8 +63,10 @@ import org.apache.qpid.server.virtualhost.plugins.SlowConsumerDetection; import org.apache.qpid.server.virtualhost.plugins.VirtualHostPluginFactory; import org.apache.qpid.server.virtualhost.plugins.policies.TopicDeletePolicy; import org.apache.qpid.slowconsumerdetection.policies.SlowConsumerPolicyPluginFactory; +import org.apache.qpid.util.FileUtils; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleException; +import org.osgi.framework.Version; import org.osgi.framework.launch.Framework; import org.osgi.util.tracker.ServiceTracker; @@ -73,7 +79,6 @@ public class PluginManager implements Closeable private static final Logger _logger = Logger.getLogger(PluginManager.class); private static final int FELIX_STOP_TIMEOUT = 30000; - private static final String QPID_VER_SUFFIX = "version=0.13,"; private Framework _felix; @@ -92,6 +97,49 @@ public class PluginManager implements Closeable private Map<String, SlowConsumerPolicyPluginFactory> _policyPlugins = new HashMap<String, SlowConsumerPolicyPluginFactory>(); private Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> _authenticationManagerPlugins = new HashMap<String, AuthenticationManagerPluginFactory<? extends Plugin>>(); + /** The default name of the OSGI system package list. */ + private static final String DEFAULT_RESOURCE_NAME = "org/apache/qpid/server/plugins/OsgiSystemPackages.properties"; + + /** The name of the override system property that holds the name of the OSGI system package list. */ + private static final String FILE_PROPERTY = "qpid.osgisystempackages.properties"; + + private static final String OSGI_SYSTEM_PACKAGES; + + static + { + final String filename = System.getProperty(FILE_PROPERTY); + final InputStream is = FileUtils.openFileOrDefaultResource(filename, DEFAULT_RESOURCE_NAME, + PluginManager.class.getClassLoader()); + + try + { + Version qpidReleaseVersion; + try + { + qpidReleaseVersion = Version.parseVersion(QpidProperties.getReleaseVersion()); + } + catch (IllegalArgumentException iae) + { + qpidReleaseVersion = null; + } + + final Properties p = new Properties(); + p.load(is); + + final OsgiSystemPackageUtil osgiSystemPackageUtil = new OsgiSystemPackageUtil(qpidReleaseVersion, (Map)p); + + OSGI_SYSTEM_PACKAGES = osgiSystemPackageUtil.getFormattedSystemPackageString(); + + _logger.debug("List of OSGi system packages to be added: " + OSGI_SYSTEM_PACKAGES); + } + catch (IOException e) + { + _logger.error("Error reading OSGI system package list", e); + throw new ExceptionInInitializerError(e); + } + } + + public PluginManager(String pluginPath, String cachePath) throws Exception { // Store all non-OSGi plugins @@ -134,62 +182,23 @@ public class PluginManager implements Closeable // Check the plugin directory path is set and exist if (pluginPath == null) { + _logger.info("No plugin path specified, no plugins will be loaded."); return; } File pluginDir = new File(pluginPath); if (!pluginDir.exists()) { + _logger.warn("Plugin dir : " + pluginDir + " does not exist."); return; } - // Setup OSGi configuration propery map - StringMap configMap = new StringMap(false); - // Add the bundle provided service interface package and the core OSGi // packages to be exported from the class path via the system bundle. - configMap.put(FRAMEWORK_SYSTEMPACKAGES, - "org.osgi.framework; version=1.3.0," + - "org.osgi.service.packageadmin; version=1.2.0," + - "org.osgi.service.startlevel; version=1.0.0," + - "org.osgi.service.url; version=1.0.0," + - "org.osgi.util.tracker; version=1.0.0," + - "org.apache.qpid.junit.extensions.util; " + QPID_VER_SUFFIX + - "org.apache.qpid; " + QPID_VER_SUFFIX + - "org.apache.qpid.common; " + QPID_VER_SUFFIX + - "org.apache.qpid.exchange; " + QPID_VER_SUFFIX + - "org.apache.qpid.framing; " + QPID_VER_SUFFIX + - "org.apache.qpid.management.common.mbeans.annotations; " + QPID_VER_SUFFIX + - "org.apache.qpid.protocol; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.binding; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.configuration; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.configuration.plugins; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.configuration.management; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.exchange; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.logging; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.logging.actors; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.logging.subjects; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.management; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.persistent; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.plugins; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.protocol; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.queue; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.registry; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.security; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.security.access; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.security.access.plugins; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.virtualhost; " + QPID_VER_SUFFIX + - "org.apache.qpid.server.virtualhost.plugins; " + QPID_VER_SUFFIX + - "org.apache.qpid.util; " + QPID_VER_SUFFIX + - "org.apache.commons.configuration; version=1.0.0," + - "org.apache.commons.lang; version=1.0.0," + - "org.apache.commons.lang.builder; version=1.0.0," + - "org.apache.commons.logging; version=1.0.0," + - "org.apache.log4j; version=1.2.12," + - "javax.management.openmbean; version=1.0.0," + - "javax.management; version=1.0.0," + - "javax.security.auth; version=1.0.0" - ); + // Setup OSGi configuration property map + final StringMap configMap = new StringMap(false); + configMap.put(FRAMEWORK_SYSTEMPACKAGES, OSGI_SYSTEM_PACKAGES); + // No automatic shutdown hook configMap.put("felix.shutdown.hook", "false"); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/JCAProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/JCAProvider.java index d6a09d8217..d6f6c714e2 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/JCAProvider.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/JCAProvider.java @@ -21,12 +21,11 @@ package org.apache.qpid.server.security.auth.sasl; import java.security.Provider; -import java.security.Security; import java.util.Map; import javax.security.sasl.SaslServerFactory; -public final class JCAProvider extends Provider +public class JCAProvider extends Provider { public JCAProvider(String name, Map<String, Class<? extends SaslServerFactory>> providerMap) { diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java new file mode 100644 index 0000000000..4a03445357 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java @@ -0,0 +1,93 @@ +/* + * + * 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.qpid.server.plugins; + +import java.util.Map; +import java.util.TreeMap; + +import org.apache.qpid.test.utils.QpidTestCase; +import org.osgi.framework.Version; + +/** + * + */ +public class OsgiSystemPackageUtilTest extends QpidTestCase +{ + private OsgiSystemPackageUtil _util = null; // Object under test + + private Map<String, String> _map = new TreeMap<String, String>(); // Use a TreeMap for unit test in order for determinstic results. + + public void testWithOnePackage() throws Exception + { + _map.put("org.xyz", "1.0.0"); + + _util = new OsgiSystemPackageUtil(null, _map); + + final String systemPackageString = _util.getFormattedSystemPackageString(); + + assertEquals("org.xyz; version=1.0.0", systemPackageString); + } + + public void testWithTwoPackages() throws Exception + { + _map.put("org.xyz", "1.0.0"); + _map.put("org.abc", "1.2.3"); + + _util = new OsgiSystemPackageUtil(null, _map); + + final String systemPackageString = _util.getFormattedSystemPackageString(); + + assertEquals("org.abc; version=1.2.3, org.xyz; version=1.0.0", systemPackageString); + } + + public void testWithNoPackages() throws Exception + { + _util = new OsgiSystemPackageUtil(null, _map); + + final String systemPackageString = _util.getFormattedSystemPackageString(); + + assertNull(systemPackageString); + } + + public void testWithQpidPackageWithQpidReleaseNumberSet() throws Exception + { + _map.put("org.apache.qpid.xyz", "1.0.0"); + _map.put("org.abc", "1.2.3"); + + _util = new OsgiSystemPackageUtil(new Version("0.13"), _map); + + final String systemPackageString = _util.getFormattedSystemPackageString(); + + assertEquals("org.abc; version=1.2.3, org.apache.qpid.xyz; version=0.13.0", systemPackageString); + } + + public void testWithQpidPackageWithoutQpidReleaseNumberSet() throws Exception + { + _map.put("org.apache.qpid.xyz", "1.0.0"); + _map.put("org.abc", "1.2.3"); + + _util = new OsgiSystemPackageUtil(null, _map); + + final String systemPackageString = _util.getFormattedSystemPackageString(); + + assertEquals("org.abc; version=1.2.3, org.apache.qpid.xyz; version=1.0.0", systemPackageString); + } +} |
