Use simpler StaticInstallSupport, remove BundleContexts from FeatureServiceImpl
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/912c2610 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/912c2610 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/912c2610 Branch: refs/heads/master Commit: 912c2610e3e85730a435a09c6819c57d6d9457f1 Parents: 4174fb7 Author: Christian Schneider <[email protected]> Authored: Tue May 16 21:54:23 2017 +0200 Committer: Christian Schneider <[email protected]> Committed: Thu May 18 11:37:09 2017 +0200 ---------------------------------------------------------------------- .../karaf/features/internal/osgi/Activator.java | 3 - .../internal/service/BundleInstallSupport.java | 12 +++ .../service/BundleInstallSupportImpl.java | 18 +++- .../internal/service/FeaturesServiceConfig.java | 2 +- .../internal/service/FeaturesServiceImpl.java | 52 +++-------- .../internal/service/StaticInstallSupport.java | 95 ++++++++++++++++++++ .../karaf/features/FeaturesServiceTest.java | 48 +++++----- .../service/FeaturesServiceImplTest.java | 18 ++-- .../assembly/AssemblyDeployCallback.java | 56 +----------- .../org/apache/karaf/tooling/VerifyMojo.java | 58 +----------- 10 files changed, 180 insertions(+), 182 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/912c2610/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java index 1d0db3d..bc59af7 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java @@ -216,9 +216,6 @@ public class Activator extends BaseActivator { dg); register(RegionDigraphPersistence.class, () -> installSupport.saveState()); featuresService = new FeaturesServiceImpl( - bundleContext.getBundle(), - bundleContext, - systemBundleContext, stateStorage, featureFinder, configurationAdmin, http://git-wip-us.apache.org/repos/asf/karaf/blob/912c2610/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java index 5003515..6c26d14 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java @@ -20,6 +20,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -66,5 +67,16 @@ public interface BundleInstallSupport { void installLibraries(Feature feature) throws IOException; File getDataFile(String name); + + FrameworkInfo getInfo(); + + class FrameworkInfo { + public Bundle ourBundle; + public Bundle systemBundle; + public int initialBundleStartLevel; + public int currentStartLevel; + public Map<Long, Bundle> bundles = new HashMap<>(); + + } } http://git-wip-us.apache.org/repos/asf/karaf/blob/912c2610/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java index 6b9d1f9..562425f 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java @@ -48,6 +48,7 @@ import org.osgi.framework.hooks.resolver.ResolverHookFactory; import org.osgi.framework.namespace.ExecutionEnvironmentNamespace; import org.osgi.framework.namespace.HostNamespace; import org.osgi.framework.startlevel.BundleStartLevel; +import org.osgi.framework.startlevel.FrameworkStartLevel; import org.osgi.framework.wiring.BundleCapability; import org.osgi.framework.wiring.BundleRequirement; import org.osgi.framework.wiring.BundleRevision; @@ -147,9 +148,6 @@ public class BundleInstallSupportImpl implements BundleInstallSupport { bundle.uninstall(); } - /* (non-Javadoc) - * @see org.apache.karaf.features.internal.service.Regions#startBundle(org.osgi.framework.Bundle) - */ @Override public void startBundle(Bundle bundle) throws BundleException { if (bundle != this.ourBundle || bundle.getState() != Bundle.STARTING) { @@ -313,4 +311,18 @@ public class BundleInstallSupportImpl implements BundleInstallSupport { return ourBundleContext.getDataFile(fileName); } + @Override + public FrameworkInfo getInfo() { + FrameworkInfo info = new FrameworkInfo(); + info.ourBundle = ourBundle; + FrameworkStartLevel fsl = systemBundleContext.getBundle().adapt(FrameworkStartLevel.class); + info.initialBundleStartLevel = fsl.getInitialBundleStartLevel(); + info.currentStartLevel = fsl.getStartLevel(); + info.bundles = new HashMap<>(); + for (Bundle bundle : systemBundleContext.getBundles()) { + info.bundles.put(bundle.getBundleId(), bundle); + } + info.systemBundle = info.bundles.get(0); + return info; + } } http://git-wip-us.apache.org/repos/asf/karaf/blob/912c2610/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceConfig.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceConfig.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceConfig.java index d0b397b..45362e3 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceConfig.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceConfig.java @@ -42,7 +42,7 @@ public class FeaturesServiceConfig { */ public String updateSnapshots; - public int downloadThreads; + public int downloadThreads = 1; public long scheduleDelay; http://git-wip-us.apache.org/repos/asf/karaf/blob/912c2610/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java index b28328d..a14667b 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java @@ -63,16 +63,14 @@ import org.apache.karaf.features.RepositoryEvent; import org.apache.karaf.features.internal.download.DownloadManager; import org.apache.karaf.features.internal.download.DownloadManagers; import org.apache.karaf.features.internal.region.DigraphHelper; +import org.apache.karaf.features.internal.service.BundleInstallSupport.FrameworkInfo; import org.apache.karaf.features.internal.util.JsonReader; import org.apache.karaf.features.internal.util.JsonWriter; import org.apache.karaf.util.collections.CopyOnWriteArrayIdentityList; import org.eclipse.equinox.region.RegionDigraph; import org.ops4j.pax.url.mvn.MavenResolver; import org.ops4j.pax.url.mvn.MavenResolvers; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; import org.osgi.framework.Version; -import org.osgi.framework.startlevel.FrameworkStartLevel; import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; import org.osgi.service.resolver.Resolver; @@ -89,18 +87,12 @@ import static org.apache.karaf.features.internal.util.MapUtils.remove; */ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCallback { + private static final String RESOLVE_FILE = "resolve"; private static final Logger LOGGER = LoggerFactory.getLogger(FeaturesServiceImpl.class); private static final String FEATURE_OSGI_REQUIREMENT_PREFIX = "feature:"; private static final String VERSION_SEPARATOR = "/"; /** - * Our bundle and corresponding bundle context. - * We use it to check bundle operations affecting our own bundle. - */ - private final Bundle bundle; - private final BundleContext bundleContext; - private final BundleContext systemBundleContext; - /** * Used to load and save the {@link State} of this service. */ private final StateStorage storage; @@ -128,19 +120,13 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall private final ExecutorService executor; private Map<String, Map<String, Feature>> featureCache; - public FeaturesServiceImpl(Bundle bundle, - BundleContext bundleContext, - BundleContext systemBundleContext, - StateStorage storage, + public FeaturesServiceImpl(StateStorage storage, FeatureFinder featureFinder, ConfigurationAdmin configurationAdmin, Resolver resolver, BundleInstallSupport installSupport, org.osgi.service.repository.Repository globalRepository, FeaturesServiceConfig cfg) { - this.bundle = bundle; - this.bundleContext = bundleContext; - this.systemBundleContext = systemBundleContext; this.storage = storage; this.featureFinder = featureFinder; this.configurationAdmin = configurationAdmin; @@ -159,11 +145,8 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall @SuppressWarnings({"unchecked", "rawtypes"}) private void checkResolve() { - if (bundleContext == null) { - return; // Most certainly in unit tests - } - File resolveFile = bundleContext.getDataFile("resolve"); - if (!resolveFile.exists()) { + File resolveFile = installSupport.getDataFile(RESOLVE_FILE); + if (resolveFile == null || !resolveFile.exists()) { return; } Map<String, Object> request; @@ -191,7 +174,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall } private void writeResolve(Map<String, Set<String>> requestedFeatures, EnumSet<Option> options) throws IOException { - File resolveFile = bundleContext.getDataFile("resolve"); + File resolveFile = installSupport.getDataFile(RESOLVE_FILE); Map<String, Object> request = new HashMap<>(); List<String> opts = new ArrayList<>(); for (Option opt : options) { @@ -230,9 +213,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall state.bundleChecksums.clear(); } storage.save(state); - if (bundleContext != null) { // For tests, this should never happen at runtime - installSupport.saveState(); - } + installSupport.saveState(); } } catch (IOException e) { LOGGER.warn("Error saving FeaturesService state", e); @@ -1007,19 +988,12 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall private Deployer.DeploymentState getDeploymentState(State state) throws Exception { Deployer.DeploymentState dstate = new Deployer.DeploymentState(); - // State dstate.state = state; - // Service bundle - dstate.serviceBundle = bundle; - // Start level - FrameworkStartLevel fsl = systemBundleContext.getBundle().adapt(FrameworkStartLevel.class); - dstate.initialBundleStartLevel = fsl.getInitialBundleStartLevel(); - dstate.currentStartLevel = fsl.getStartLevel(); - // Bundles - dstate.bundles = new HashMap<>(); - for (Bundle bundle : systemBundleContext.getBundles()) { - dstate.bundles.put(bundle.getBundleId(), bundle); - } + FrameworkInfo info = installSupport.getInfo(); + dstate.serviceBundle = info.ourBundle; + dstate.initialBundleStartLevel = info.initialBundleStartLevel; + dstate.currentStartLevel = info.currentStartLevel; + dstate.bundles = info.bundles; // Features dstate.features = new HashMap<>(); for (Map<String, Feature> m : getFeatures().values()) { @@ -1051,8 +1025,6 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall return request; } - - private void doProvision(Map<String, Set<String>> requirements, // all requirements Map<String, Map<String, FeatureState>> stateChanges, // features state changes State state, // current state http://git-wip-us.apache.org/repos/asf/karaf/blob/912c2610/features/core/src/main/java/org/apache/karaf/features/internal/service/StaticInstallSupport.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/StaticInstallSupport.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/StaticInstallSupport.java new file mode 100644 index 0000000..2936b46 --- /dev/null +++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/StaticInstallSupport.java @@ -0,0 +1,95 @@ +/* + * 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.features.internal.service; + +import java.io.File; +import java.io.InputStream; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.equinox.region.RegionDigraph; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.resource.Resource; +import org.osgi.resource.Wire; + +public abstract class StaticInstallSupport implements BundleInstallSupport { + + @Override + public void print(String message, boolean verbose) { + } + + @Override + public void refreshPackages(Collection<Bundle> bundles) throws InterruptedException { + } + + @Override + public void updateBundle(Bundle bundle, String uri, InputStream is) throws BundleException { + throw new UnsupportedOperationException(); + } + + @Override + public void uninstall(Bundle bundle) throws BundleException { + throw new UnsupportedOperationException(); + } + + @Override + public void startBundle(Bundle bundle) throws BundleException { + } + + @Override + public void stopBundle(Bundle bundle, int options) throws BundleException { + } + + @Override + public void setBundleStartLevel(Bundle bundle, int startLevel) { + } + + @Override + public void resolveBundles(Set<Bundle> bundles, Map<Resource, List<Wire>> wiring, + Map<Resource, Bundle> resToBnd) { + } + + @Override + public void replaceDigraph(Map<String, Map<String, Map<String, Set<String>>>> policies, + Map<String, Set<Long>> bundles) + throws BundleException, InvalidSyntaxException { + } + + @Override + public void saveState() { + } + + @Override + public RegionDigraph getDiGraphCopy() throws BundleException { + return null; + } + + @Override + public File getDataFile(String name) { + return null; + } + + @Override + public FrameworkInfo getInfo() { + return new FrameworkInfo(); + } + +} http://git-wip-us.apache.org/repos/asf/karaf/blob/912c2610/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java ---------------------------------------------------------------------- diff --git a/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java b/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java index cffbe8b..a47943d 100644 --- a/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java +++ b/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java @@ -31,23 +31,22 @@ import java.util.concurrent.CopyOnWriteArraySet; import org.apache.felix.resolver.ResolverImpl; import org.apache.karaf.features.internal.resolver.Slf4jResolverLog; +import org.apache.karaf.features.internal.service.BundleInstallSupport; +import org.apache.karaf.features.internal.service.BundleInstallSupport.FrameworkInfo; import org.apache.karaf.features.internal.service.FeaturesServiceConfig; import org.apache.karaf.features.internal.service.FeaturesServiceImpl; import org.apache.karaf.features.internal.service.StateStorage; +import org.apache.karaf.features.internal.util.MultiException; import org.easymock.EasyMock; import org.junit.Assert; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.startlevel.FrameworkStartLevel; import org.osgi.service.resolver.Resolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -350,7 +349,9 @@ public class FeaturesServiceTest extends TestBase { + "</features>"); FeaturesServiceConfig cfg = new FeaturesServiceConfig(); - FeaturesServiceImpl svc = new FeaturesServiceImpl(null, null, null, new Storage(), null, null, resolver, null, null, cfg); + BundleInstallSupport installSupport = EasyMock.niceMock(BundleInstallSupport.class); + EasyMock.replay(installSupport); + FeaturesServiceImpl svc = new FeaturesServiceImpl(new Storage(), null, null, resolver, installSupport, null, cfg); svc.addRepository(uri); assertEquals(feature("f2", "0.2"), svc.getFeatures("f2", "[0.1,0.3)")[0]); @@ -360,22 +361,18 @@ public class FeaturesServiceTest extends TestBase { } @Test + @Ignore("Currently takes too long") public void testInstallBatchFeatureWithFailure() throws Exception { String bundle1Uri = "file:bundle1"; String bundle2Uri = "file:bundle2"; URI uri = createTempRepo(FEATURE_WITH_INVALID_BUNDLE, bundle1Uri, bundle2Uri); - BundleContext bundleContext = EasyMock.createMock(BundleContext.class); - Bundle bundle = EasyMock.createMock(Bundle.class); - FrameworkStartLevel fsl = EasyMock.createMock(FrameworkStartLevel.class); - expect(bundle.adapt(FrameworkStartLevel.class)).andReturn(fsl); - expect(fsl.getInitialBundleStartLevel()).andReturn(50); - expect(fsl.getStartLevel()).andReturn(100); - replay(bundleContext, bundle, fsl); - + BundleInstallSupport installSupport = EasyMock.niceMock(BundleInstallSupport.class); + expect(installSupport.getInfo()).andReturn(dummyInfo()); + EasyMock.replay(installSupport); FeaturesServiceConfig cfg = new FeaturesServiceConfig(); - FeaturesServiceImpl svc = new FeaturesServiceImpl(null, null, bundleContext, new Storage(), null, null, resolver, null, null, cfg); + FeaturesServiceImpl svc = new FeaturesServiceImpl(new Storage(), null, null, resolver, installSupport, null, cfg); svc.addRepository(uri); try { List<String> features = new ArrayList<String>(); @@ -386,10 +383,17 @@ public class FeaturesServiceTest extends TestBase { svc.installFeatures(new CopyOnWriteArraySet<String>(features), EnumSet.noneOf(FeaturesService.Option.class)); fail("Call should have thrown an exception"); - } catch (Exception t) { - // Expected + } catch (MultiException e) { + Throwable suppressed = e.getSuppressed()[0]; + Assert.assertEquals("Error downloading zfs:unknown", suppressed.getMessage()); } - verify(bundleContext); + } + + private FrameworkInfo dummyInfo() { + FrameworkInfo info = new FrameworkInfo(); + info.initialBundleStartLevel = 50; + info.currentStartLevel = 100; + return info; } /** @@ -400,8 +404,10 @@ public class FeaturesServiceTest extends TestBase { URI uri = createTempRepo("<features name='test' xmlns='http://karaf.apache.org/xmlns/features/v1.0.0'>" + " <featur><bundle>somebundle</bundle></featur></features>"); + BundleInstallSupport installSupport = EasyMock.niceMock(BundleInstallSupport.class); + EasyMock.replay(installSupport); FeaturesServiceConfig cfg = new FeaturesServiceConfig(); - FeaturesServiceImpl svc = new FeaturesServiceImpl(null, null, null, new Storage(), null, null, resolver, null, null, cfg); + FeaturesServiceImpl svc = new FeaturesServiceImpl(new Storage(), null, null, resolver, installSupport, null, cfg); try { svc.addRepository(uri); fail("exception expected"); @@ -419,8 +425,10 @@ public class FeaturesServiceTest extends TestBase { + " <feature name='f1'><bundle>file:bundle1</bundle><bundle>file:bundle2</bundle></feature>" + "</features>"); + BundleInstallSupport installSupport = EasyMock.niceMock(BundleInstallSupport.class); + EasyMock.replay(installSupport); FeaturesServiceConfig cfg = new FeaturesServiceConfig(); - FeaturesServiceImpl svc = new FeaturesServiceImpl(null, null, null, new Storage(), null, null, resolver, null, null, cfg); + FeaturesServiceImpl svc = new FeaturesServiceImpl(new Storage(), null, null, resolver, installSupport, null, cfg); svc.addRepository(uri); Feature[] features = svc.getFeatures("f1"); Assert.assertEquals(1, features.length); http://git-wip-us.apache.org/repos/asf/karaf/blob/912c2610/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java ---------------------------------------------------------------------- diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java index 06f2ebd..8ff215a 100644 --- a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java +++ b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java @@ -28,6 +28,7 @@ import org.apache.felix.resolver.ResolverImpl; import org.apache.karaf.features.Feature; import org.apache.karaf.features.TestBase; import org.apache.karaf.features.internal.resolver.Slf4jResolverLog; +import org.easymock.EasyMock; import org.junit.Before; import org.junit.Test; import org.osgi.service.resolver.Resolver; @@ -57,7 +58,9 @@ public class FeaturesServiceImplTest extends TestBase { Feature transactionFeature = feature("transaction", "1.0.0"); final Map<String, Map<String, Feature>> features = features(transactionFeature); FeaturesServiceConfig cfg = new FeaturesServiceConfig(); - final FeaturesServiceImpl impl = new FeaturesServiceImpl(null, null, null, new Storage(), null, null, this.resolver, null, null, cfg ) { + BundleInstallSupport installSupport = EasyMock.niceMock(BundleInstallSupport.class); + EasyMock.replay(installSupport); + final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg ) { protected Map<String,Map<String,Feature>> getFeatures() throws Exception { return features; } @@ -69,7 +72,8 @@ public class FeaturesServiceImplTest extends TestBase { @Test public void testGetFeatureStripVersion() throws Exception { FeaturesServiceConfig cfg = new FeaturesServiceConfig(); - final FeaturesServiceImpl impl = new FeaturesServiceImpl(null, null, null, new Storage(), null, null, this.resolver, null, null, cfg) { + BundleInstallSupport installSupport = EasyMock.mock(BundleInstallSupport.class); + final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg) { protected Map<String,Map<String,Feature>> getFeatures() throws Exception { return features(feature("transaction", "1.0.0")); } @@ -84,7 +88,8 @@ public class FeaturesServiceImplTest extends TestBase { @Test public void testGetFeatureNotAvailable() throws Exception { FeaturesServiceConfig cfg = new FeaturesServiceConfig(); - final FeaturesServiceImpl impl = new FeaturesServiceImpl(null, null, null, new Storage(), null, null, this.resolver, null, null, cfg) { + BundleInstallSupport installSupport = EasyMock.mock(BundleInstallSupport.class); + final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg) { protected Map<String,Map<String,Feature>> getFeatures() throws Exception { return features(feature("transaction", "1.0.0")); } @@ -99,7 +104,8 @@ public class FeaturesServiceImplTest extends TestBase { feature("transaction", "2.0.0") ); FeaturesServiceConfig cfg = new FeaturesServiceConfig(); - final FeaturesServiceImpl impl = new FeaturesServiceImpl(null, null, null, new Storage(), null, null, this.resolver, null, null, cfg) { + BundleInstallSupport installSupport = EasyMock.mock(BundleInstallSupport.class); + final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg) { protected Map<String,Map<String,Feature>> getFeatures() throws Exception { return features; } @@ -118,7 +124,9 @@ public class FeaturesServiceImplTest extends TestBase { } : null); try { FeaturesServiceConfig cfg = new FeaturesServiceConfig(); - final FeaturesServiceImpl impl = new FeaturesServiceImpl(null, null, null, new Storage(), null, null, this.resolver, null, null, cfg); + BundleInstallSupport installSupport = EasyMock.niceMock(BundleInstallSupport.class); + EasyMock.replay(installSupport); + final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg); impl.addRepository(URI.create("custom:cycle/a-references-b.xml")); impl.getFeatures(); } finally { http://git-wip-us.apache.org/repos/asf/karaf/blob/912c2610/profile/src/main/java/org/apache/karaf/profile/assembly/AssemblyDeployCallback.java ---------------------------------------------------------------------- diff --git a/profile/src/main/java/org/apache/karaf/profile/assembly/AssemblyDeployCallback.java b/profile/src/main/java/org/apache/karaf/profile/assembly/AssemblyDeployCallback.java index 0440182..b87410f 100644 --- a/profile/src/main/java/org/apache/karaf/profile/assembly/AssemblyDeployCallback.java +++ b/profile/src/main/java/org/apache/karaf/profile/assembly/AssemblyDeployCallback.java @@ -16,7 +16,6 @@ */ package org.apache.karaf.profile.assembly; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -29,7 +28,6 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.concurrent.atomic.AtomicLong; import java.util.jar.Attributes; import java.util.jar.JarFile; @@ -46,23 +44,20 @@ import org.apache.karaf.features.internal.model.ConfigFile; import org.apache.karaf.features.internal.model.Feature; import org.apache.karaf.features.internal.model.Features; import org.apache.karaf.features.internal.service.Blacklist; -import org.apache.karaf.features.internal.service.BundleInstallSupport; import org.apache.karaf.features.internal.service.Deployer; import org.apache.karaf.features.internal.service.State; +import org.apache.karaf.features.internal.service.StaticInstallSupport; import org.apache.karaf.features.internal.util.MapUtils; import org.apache.karaf.util.maven.Parser; -import org.eclipse.equinox.region.RegionDigraph; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.startlevel.BundleStartLevel; import org.osgi.framework.wiring.BundleRevision; -import org.osgi.resource.Resource; -import org.osgi.resource.Wire; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class AssemblyDeployCallback implements Deployer.DeployCallback, BundleInstallSupport { +public class AssemblyDeployCallback extends StaticInstallSupport implements Deployer.DeployCallback { private static final Logger LOGGER = LoggerFactory.getLogger(Builder.class); @@ -117,10 +112,6 @@ public class AssemblyDeployCallback implements Deployer.DeployCallback, BundleIn } @Override - public void print(String message, boolean verbose) { - } - - @Override public void saveState(State state) { dstate.state.replace(state); } @@ -263,40 +254,10 @@ public class AssemblyDeployCallback implements Deployer.DeployCallback, BundleIn } @Override - public void updateBundle(Bundle bundle, String uri, InputStream is) throws BundleException { - throw new UnsupportedOperationException(); - } - - @Override - public void uninstall(Bundle bundle) throws BundleException { - throw new UnsupportedOperationException(); - } - - @Override - public void startBundle(Bundle bundle) throws BundleException { - } - - @Override - public void stopBundle(Bundle bundle, int options) throws BundleException { - } - - @Override public void setBundleStartLevel(Bundle bundle, int startLevel) { bundle.adapt(BundleStartLevel.class).setStartLevel(startLevel); } - @Override - public void refreshPackages(Collection<Bundle> bundles) throws InterruptedException { - } - - @Override - public void resolveBundles(Set<Bundle> bundles, Map<Resource, List<Wire>> wiring, Map<Resource, Bundle> resToBnd) { - } - - @Override - public void replaceDigraph(Map<String, Map<String, Map<String, Set<String>>>> policies, Map<String, Set<Long>> bundles) throws BundleException, InvalidSyntaxException { - } - private String substFinalName(String finalname) { final String markerVarBeg = "${"; final String markerVarEnd = "}"; @@ -316,17 +277,4 @@ public class AssemblyDeployCallback implements Deployer.DeployCallback, BundleIn return finalname; } - @Override - public void saveState() { - } - - @Override - public RegionDigraph getDiGraphCopy() throws BundleException { - return null; - } - - @Override - public File getDataFile(String name) { - return null; - } } http://git-wip-us.apache.org/repos/asf/karaf/blob/912c2610/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java index 8a3b7d4..9e2ac74 100644 --- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java +++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java @@ -74,8 +74,8 @@ import org.apache.karaf.features.internal.resolver.ResourceBuilder; import org.apache.karaf.features.internal.resolver.ResourceImpl; import org.apache.karaf.features.internal.resolver.ResourceUtils; import org.apache.karaf.features.internal.service.Deployer; -import org.apache.karaf.features.internal.service.BundleInstallSupport; import org.apache.karaf.features.internal.service.State; +import org.apache.karaf.features.internal.service.StaticInstallSupport; import org.apache.karaf.features.internal.util.MapUtils; import org.apache.karaf.features.internal.util.MultiException; import org.apache.karaf.profile.assembly.CustomDownloadManager; @@ -88,7 +88,6 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; -import org.eclipse.equinox.region.RegionDigraph; import org.ops4j.pax.url.mvn.MavenResolver; import org.ops4j.pax.url.mvn.MavenResolvers; import org.osgi.framework.Bundle; @@ -103,8 +102,6 @@ import org.osgi.framework.wiring.BundleRequirement; import org.osgi.framework.wiring.BundleRevision; import org.osgi.framework.wiring.BundleWiring; import org.osgi.resource.Requirement; -import org.osgi.resource.Resource; -import org.osgi.resource.Wire; import org.osgi.service.resolver.ResolutionException; import static java.util.jar.JarFile.MANIFEST_NAME; @@ -758,7 +755,7 @@ public class VerifyMojo extends MojoSupport { } } - public static class DummyDeployCallback implements Deployer.DeployCallback, BundleInstallSupport { + public static class DummyDeployCallback extends StaticInstallSupport implements Deployer.DeployCallback { private final Bundle systemBundle; private final Deployer.DeploymentState dstate; @@ -787,10 +784,6 @@ public class VerifyMojo extends MojoSupport { } @Override - public void print(String message, boolean verbose) { - } - - @Override public void saveState(State state) { dstate.state.replace(state); } @@ -839,53 +832,6 @@ public class VerifyMojo extends MojoSupport { } } - @Override - public void updateBundle(Bundle bundle, String uri, InputStream is) throws BundleException { - throw new UnsupportedOperationException(); - } - - @Override - public void uninstall(Bundle bundle) throws BundleException { - throw new UnsupportedOperationException(); - } - - @Override - public void startBundle(Bundle bundle) throws BundleException { - } - - @Override - public void stopBundle(Bundle bundle, int options) throws BundleException { - } - - @Override - public void setBundleStartLevel(Bundle bundle, int startLevel) { - } - - @Override - public void refreshPackages(Collection<Bundle> bundles) throws InterruptedException { - } - - @Override - public void resolveBundles(Set<Bundle> bundles, Map<Resource, List<Wire>> wiring, Map<Resource, Bundle> resToBnd) { - } - - @Override - public void replaceDigraph(Map<String, Map<String, Map<String, Set<String>>>> policies, Map<String, Set<Long>> bundles) throws BundleException, InvalidSyntaxException { - } - - @Override - public void saveState() { - } - - @Override - public RegionDigraph getDiGraphCopy() throws BundleException { - return null; - } - - @Override - public File getDataFile(String name) { - return null; - } } public class MavenResolverLog extends org.apache.felix.resolver.Logger {
