diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java index a809c35..b904eec 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java @@ -652,6 +652,12 @@ public class FeaturesServiceImpl implements FeaturesService, FrameworkListener { throw new BundleException("Manifest not present in the first entry of the zip " + bundleLocation); } String sn = m.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); + //Remove attribute for sn which has its like org.apache.karaf.deployer.spring;blueprint.graceperiod:=false + int index_sep = sn.indexOf(';'); + if (index_sep != -1) { + sn = sn.substring(0, index_sep); + } + String vStr = m.getMainAttributes().getValue(Constants.BUNDLE_VERSION); Version v = vStr == null ? Version.emptyVersion : Version.parseVersion(vStr); for (Bundle b : bundleContext.getBundles()) { diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java b/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java index cdd9f5a..8d12d9d 100644 --- a/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java +++ b/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java @@ -22,17 +22,25 @@ import java.io.File; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; +import java.util.Dictionary; import java.util.HashMap; +import java.util.Hashtable; import java.util.List; import java.util.Map; import junit.framework.TestCase; import org.apache.felix.utils.manifest.Clause; +import org.apache.karaf.features.BundleInfo; import org.apache.karaf.features.Feature; +import org.apache.karaf.features.internal.FeaturesServiceImpl.InstallationState; import org.easymock.EasyMock; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.framework.Constants; import org.osgi.framework.FrameworkListener; +import org.osgi.framework.Version; /** * Test cases for {@link FeaturesServiceImpl} @@ -175,4 +183,33 @@ public class FeaturesServiceImplTest extends TestCase { assertNotNull(result); assertEquals("No optional imports expected", 0, result.size()); } + + // check not install twice a bundle with the symbolic name has attribute like + //org.apache.karaf.deployer.spring;blueprint.graceperiod:=false + public void testNotInstallSameSNWithAttribute() throws IOException, BundleException { + FeaturesServiceImpl service = new FeaturesServiceImpl(); + BundleContext bundleContext = EasyMock.createMock(BundleContext.class); + Bundle goodBundle = EasyMock.createMock(Bundle.class); + BundleInfo bundleInfo = EasyMock.createMock(BundleInfo.class); + String location = getClass().getClassLoader().getResource("testNotInstallSameSNWithAttribute.jar").toString(); + InstallationState state = new InstallationState(); + + expect(bundleInfo.getLocation()).andReturn(location).atLeastOnce(); + replay(bundleInfo); + expect(bundleContext.getBundles()).andReturn(new Bundle[] { goodBundle }); + replay(bundleContext); + expect(goodBundle.getSymbolicName()).andReturn("org.apache.karaf.deployer.spring").atLeastOnce(); + expect(goodBundle.getHeaders()).andReturn(map(Constants.BUNDLE_VERSION,"2.1.0")).atLeastOnce(); + replay(goodBundle); + + service.setBundleContext(bundleContext); + service.installBundleIfNeeded(state, bundleInfo, false); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private Dictionary map(String cst, String value) { + Dictionary ret = new Hashtable(); + ret.put(cst, value); + return ret; + } }