You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2017/05/01 14:23:00 UTC
karaf git commit: [KARAF-5107] Add DeploymentListener
Repository: karaf
Updated Branches:
refs/heads/karaf-4.1.x 594d80dcf -> 9e6f8c9bf
[KARAF-5107] Add DeploymentListener
Signed-off-by: Robert Varga <ro...@pantheon.tech>
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/9e6f8c9b
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/9e6f8c9b
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/9e6f8c9b
Branch: refs/heads/karaf-4.1.x
Commit: 9e6f8c9bfdfddb477aafd089eed3221c24fdac45
Parents: 594d80d
Author: Robert Varga <ni...@hq.sk>
Authored: Thu Apr 27 14:15:41 2017 +0200
Committer: Jean-Baptiste Onofr� <jb...@apache.org>
Committed: Mon May 1 16:22:50 2017 +0200
----------------------------------------------------------------------
.../apache/karaf/features/DeploymentEvent.java | 40 +++++++++++++++
.../karaf/features/DeploymentListener.java | 31 ++++++++++++
.../apache/karaf/features/FeaturesService.java | 4 ++
.../features/internal/service/Deployer.java | 41 +++++++++------
.../internal/service/FeaturesServiceImpl.java | 50 ++++++++++++++++---
.../features/internal/service/DeployerTest.java | 52 ++++++++++++++++++--
.../assembly/AssemblyDeployCallback.java | 11 +++--
.../org/apache/karaf/tooling/VerifyMojo.java | 21 ++++----
8 files changed, 211 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/9e6f8c9b/features/core/src/main/java/org/apache/karaf/features/DeploymentEvent.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/DeploymentEvent.java b/features/core/src/main/java/org/apache/karaf/features/DeploymentEvent.java
new file mode 100644
index 0000000..f9bcad0
--- /dev/null
+++ b/features/core/src/main/java/org/apache/karaf/features/DeploymentEvent.java
@@ -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.features;
+
+/**
+ * Enumeration of deployment events. Each deployment is an operation potentially involving multiple features and its
+ * bundles. Deployments cannot overlap.
+ */
+public enum DeploymentEvent {
+ /**
+ * A new deployment operation has started.
+ */
+ DEPLOYMENT_STARTED,
+ /**
+ * Bundle install/uninstall operations within this deployment have completed.
+ */
+ BUNDLES_INSTALLED,
+ /**
+ * Bundle resolution has completed, but the bundles have not yet been started.
+ */
+ BUNDLES_RESOLVED,
+ /**
+ * The deployment has completed.
+ */
+ DEPLOYMENT_FINISHED,
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/9e6f8c9b/features/core/src/main/java/org/apache/karaf/features/DeploymentListener.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/DeploymentListener.java b/features/core/src/main/java/org/apache/karaf/features/DeploymentListener.java
new file mode 100644
index 0000000..3371ebc
--- /dev/null
+++ b/features/core/src/main/java/org/apache/karaf/features/DeploymentListener.java
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+import java.util.EventListener;
+
+/**
+ * Interface implemented by components interested in bundle lifecycle operations triggered by {@link FeaturesService}.
+ */
+public interface DeploymentListener extends EventListener {
+ /**
+ * Fired when a deployment event occurs.
+ *
+ * @param event Triggered event
+ */
+ void deploymentEvent(DeploymentEvent event);
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/9e6f8c9b/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java b/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
index c7c932a..faceddb 100644
--- a/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
+++ b/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
@@ -156,6 +156,10 @@ public interface FeaturesService {
void unregisterListener(FeaturesListener listener);
+ void registerListener(DeploymentListener listener);
+
+ void unregisterListener(DeploymentListener listener);
+
FeatureState getState(String featureId);
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/9e6f8c9b/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
index 73c1cb3..7fb066b 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
@@ -41,6 +41,7 @@ import org.apache.felix.utils.version.VersionRange;
import org.apache.felix.utils.version.VersionTable;
import org.apache.karaf.features.BundleInfo;
import org.apache.karaf.features.Conditional;
+import org.apache.karaf.features.DeploymentEvent;
import org.apache.karaf.features.Feature;
import org.apache.karaf.features.FeatureEvent;
import org.apache.karaf.features.FeatureState;
@@ -115,6 +116,7 @@ public class Deployer {
void saveState(State state);
void persistResolveRequest(DeploymentRequest request) throws IOException;
void installFeature(Feature feature) throws IOException, InvalidSyntaxException;
+ void callListeners(DeploymentEvent deployEvent);
void callListeners(FeatureEvent featureEvent);
Bundle installBundle(String region, String uri, InputStream is) throws BundleException;
@@ -252,9 +254,13 @@ public class Deployer {
for (String feature : featureSet) {
String[] p = feature.split("/");
found = name.equals(p[0]) && range.contains(VersionTable.getVersion(p[1]));
- if (found) break;
+ if (found) {
+ break;
+ }
+ }
+ if (found) {
+ break;
}
- if (found) break;
}
if (found) {
iterator.remove();
@@ -569,7 +575,6 @@ public class Deployer {
// #10: send events
//
-
//
// Handle updates on the FeaturesService bundle
//
@@ -578,6 +583,7 @@ public class Deployer {
if (rootRegionDeployment != null && rootRegionDeployment.toDelete.contains(dstate.serviceBundle)) {
throw new UnsupportedOperationException("Uninstalling the FeaturesService bundle is not supported");
}
+
// If the bundle needs to be updated, do the following:
// - persist the request to indicate the resolution must be continued after restart
// - update the checksum and save the state
@@ -588,8 +594,7 @@ public class Deployer {
// - start the bundle
// - exit
// When restarting, the resolution will be attempted again
- if (rootRegionDeployment != null && rootRegionDeployment.toUpdate.containsKey(dstate.serviceBundle)
- ) {
+ if (rootRegionDeployment != null && rootRegionDeployment.toUpdate.containsKey(dstate.serviceBundle)) {
callback.persistResolveRequest(request);
// If the bundle is updated because of a different checksum,
// save the new checksum persistently
@@ -619,6 +624,8 @@ public class Deployer {
return;
}
+ callback.callListeners(DeploymentEvent.DEPLOYMENT_STARTED);
+
//
// Perform bundle operations
//
@@ -754,7 +761,7 @@ public class Deployer {
}
if (hasToInstall) {
print("Installing bundles:", verbose);
- Map<Bundle, Integer> customStartLevels = new HashMap<Bundle, Integer>();
+ Map<Bundle, Integer> customStartLevels = new HashMap<>();
for (Map.Entry<String, Deployer.RegionDeployment> entry : deployment.regions.entrySet()) {
String name = entry.getKey();
Deployer.RegionDeployment regionDeployment = entry.getValue();
@@ -795,7 +802,7 @@ public class Deployer {
}
}
}
-
+
// Set start levels after install to avoid starting before all bundles are installed
for (Bundle bundle : customStartLevels.keySet()) {
callback.setBundleStartLevel(bundle, customStartLevels.get(bundle));
@@ -874,7 +881,9 @@ public class Deployer {
toResolve.addAll(toStart);
toResolve.addAll(toRefresh.keySet());
removeBundlesInState(toResolve, UNINSTALLED);
+ callback.callListeners(DeploymentEvent.BUNDLES_INSTALLED);
callback.resolveBundles(toResolve, resolver.getWiring(), deployment.resToBnd);
+ callback.callListeners(DeploymentEvent.BUNDLES_RESOLVED);
// Compute bundles to start
removeFragmentsAndBundlesInState(toStart, UNINSTALLED | ACTIVE);
@@ -916,11 +925,12 @@ public class Deployer {
}
}
}
+ callback.callListeners(DeploymentEvent.DEPLOYMENT_FINISHED);
print("Done.", verbose);
}
- private VersionRange getRange(String version, String featureResolutionRange) {
+ private static VersionRange getRange(String version, String featureResolutionRange) {
VersionRange range;
if (version.equals("0.0.0")) {
range = VersionRange.ANY_VERSION;
@@ -946,18 +956,18 @@ public class Deployer {
}
}
- private boolean isSubsystem(Resource resource) {
+ private static boolean isSubsystem(Resource resource) {
return TYPE_SUBSYSTEM.equals(getType(resource));
}
- private boolean isBundle(Resource resource) {
+ private static boolean isBundle(Resource resource) {
return TYPE_BUNDLE.equals(getType(resource));
}
/**
* Returns the most active state of the given states
*/
- private FeatureState mergeStates(FeatureState s1, FeatureState s2) {
+ private static FeatureState mergeStates(FeatureState s1, FeatureState s2) {
if (s1 == FeatureState.Started || s2 == FeatureState.Started) {
return FeatureState.Started;
}
@@ -967,7 +977,7 @@ public class Deployer {
return FeatureState.Installed;
}
- private void computeBundlesToRefresh(Map<Bundle, String> toRefresh, Collection<Bundle> bundles, Map<Resource, Bundle> resources, Map<Resource, List<Wire>> resolution) {
+ private static void computeBundlesToRefresh(Map<Bundle, String> toRefresh, Collection<Bundle> bundles, Map<Resource, Bundle> resources, Map<Resource, List<Wire>> resolution) {
// Compute the new list of fragments
Map<Bundle, Set<Resource>> newFragments = new HashMap<>();
for (Bundle bundle : bundles) {
@@ -1096,7 +1106,7 @@ public class Deployer {
callback.print(message, verbose);
}
- private void removeFragmentsAndBundlesInState(Collection<Bundle> bundles, int state) {
+ private static void removeFragmentsAndBundlesInState(Collection<Bundle> bundles, int state) {
for (Iterator<Bundle> iterator = bundles.iterator(); iterator.hasNext();) {
Bundle bundle = iterator.next();
if ((bundle.getState() & state) != 0
@@ -1106,7 +1116,7 @@ public class Deployer {
}
}
- private void removeBundlesInState(Collection<Bundle> bundles, int state) {
+ private static void removeBundlesInState(Collection<Bundle> bundles, int state) {
for (Iterator<Bundle> iterator = bundles.iterator(); iterator.hasNext();) {
Bundle bundle = iterator.next();
if ((bundle.getState() & state) != 0) {
@@ -1196,7 +1206,7 @@ public class Deployer {
// Compute the list of resources to deploy in the region
Set<Resource> bundlesInRegion = bundlesPerRegions.get(region);
List<Resource> toDeploy = bundlesInRegion != null
- ? new ArrayList<>(bundlesInRegion) : new ArrayList<Resource>();
+ ? new ArrayList<>(bundlesInRegion) : new ArrayList<>();
// Remove the system bundle
Bundle systemBundle = dstate.bundles.get(0l);
@@ -1411,6 +1421,7 @@ public class Deployer {
}
if (!bundlesToDestroy.isEmpty()) {
Collections.sort(bundlesToDestroy, new Comparator<Bundle>() {
+ @Override
public int compare(Bundle b1, Bundle b2) {
return Long.compare(b2.getLastModified(), b1.getLastModified());
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/9e6f8c9b/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 eeb692e..02be751 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
@@ -38,7 +38,6 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
-import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
@@ -50,6 +49,8 @@ import java.util.regex.Pattern;
import org.apache.felix.utils.version.VersionCleaner;
import org.apache.felix.utils.version.VersionRange;
import org.apache.felix.utils.version.VersionTable;
+import org.apache.karaf.features.DeploymentEvent;
+import org.apache.karaf.features.DeploymentListener;
import org.apache.karaf.features.Feature;
import org.apache.karaf.features.FeatureEvent;
import org.apache.karaf.features.FeatureState;
@@ -176,6 +177,8 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
private final org.osgi.service.repository.Repository globalRepository;
private final List<FeaturesListener> listeners = new CopyOnWriteArrayIdentityList<>();
+ private final List<DeploymentListener> deploymentListeners = new CopyOnWriteArrayIdentityList<>();
+ private DeploymentEvent lastDeploymentEvent = DeploymentEvent.DEPLOYMENT_FINISHED;
// Synchronized on lock
private final Object lock = new Object();
@@ -255,9 +258,6 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
checkResolve();
}
- @SuppressWarnings({
- "unchecked", "rawtypes"
- })
public void stop() {
this.executor.shutdown();
}
@@ -361,6 +361,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
// Listeners support
//
+ @Override
public void registerListener(FeaturesListener listener) {
listeners.add(listener);
try {
@@ -385,10 +386,23 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
}
}
+ @Override
public void unregisterListener(FeaturesListener listener) {
listeners.remove(listener);
}
+ @Override
+ public void registerListener(DeploymentListener listener) {
+ deploymentListeners.add(listener);
+ listener.deploymentEvent(lastDeploymentEvent);
+ }
+
+ @Override
+ public void unregisterListener(DeploymentListener listener) {
+ deploymentListeners.remove(listener);
+ }
+
+ @Override
public void callListeners(FeatureEvent event) {
if (eventAdminListener != null) {
eventAdminListener.featureEvent(event);
@@ -398,6 +412,18 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
}
}
+ @Override
+ public void callListeners(DeploymentEvent event) {
+ lastDeploymentEvent = event;
+ for (DeploymentListener listener : deploymentListeners) {
+ try {
+ listener.deploymentEvent(event);
+ } catch (Exception e) {
+ LOGGER.warn("DeploymentListener {} failed to process event {}", listener, event, e);
+ }
+ }
+ }
+
protected void callListeners(RepositoryEvent event) {
if (eventAdminListener != null) {
eventAdminListener.repositoryEvent(event);
@@ -590,6 +616,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
// Features support
//
+ @Override
public Feature getFeature(String name) throws Exception {
Feature[] features = this.getFeatures(name);
if (features.length < 1) {
@@ -599,6 +626,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
}
}
+ @Override
public Feature getFeature(String name, String version) throws Exception {
Feature[] features = this.getFeatures(name, version);
if (features.length < 1) {
@@ -608,6 +636,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
}
}
+ @Override
public Feature[] getFeatures(String nameOrId) throws Exception {
String[] parts = nameOrId.split("/");
String name = parts.length > 0 ? parts[0] : nameOrId;
@@ -615,6 +644,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
return getFeatures(name, version);
}
+ @Override
public Feature[] getFeatures(String name, String version) throws Exception {
List<Feature> features = new ArrayList<>();
Pattern pattern = Pattern.compile(name);
@@ -662,6 +692,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
}
}
+ @Override
public Feature[] listFeatures() throws Exception {
Set<Feature> features = new HashSet<>();
for (Map<String, Feature> featureWithDifferentVersion : getFeatures().values()) {
@@ -780,7 +811,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
return installed != null && installed.contains(id);
}
}
-
+
@Override
public FeatureState getState(String featureId) {
String id = normalize(featureId);
@@ -906,8 +937,8 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
String req = f.getName() + "/" + new VersionRange(f.getVersion(), true);
featuresToAdd.add(req);
Feature[] installedFeatures = listInstalledFeatures();
- for (int i=0;i<installedFeatures.length;i++) {
- if (installedFeatures[i].getName().equals(f.getName()) && installedFeatures[i].getVersion().equals(f.getVersion())) {
+ for (Feature installedFeature : installedFeatures) {
+ if (installedFeature.getName().equals(f.getName()) && installedFeature.getVersion().equals(f.getVersion())) {
LOGGER.info("The specified feature: '{}' version '{}' {}",f.getName(),f.getVersion(),f.getVersion().endsWith("SNAPSHOT") ? "has been upgraded": "is already installed");
}
}
@@ -945,6 +976,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
doProvisionInThread(required, stateChanges, state, options);
}
+ @Override
public void uninstallFeatures(Set<String> features, String region, EnumSet<Option> options) throws Exception {
State state = copyState();
Map<String, Set<String>> required = copy(state.requirements);
@@ -1203,6 +1235,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
return props;
}
+ @Override
public void print(String message, boolean verbose) {
LOGGER.info(message);
if (verbose) {
@@ -1210,6 +1243,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
}
}
+ @Override
public void refreshPackages(Collection<Bundle> bundles) throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
FrameworkWiring fw = systemBundleContext.getBundle().adapt(FrameworkWiring.class);
@@ -1397,7 +1431,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
}
digraph.replace(temp);
}
-
+
private Pattern getFeaturePattern(String name, String version) {
String req = FEATURE_OSGI_REQUIREMENT_PREFIX + name + "/" + new VersionRange(version, true);
req = req.replace("[", "\\[");
http://git-wip-us.apache.org/repos/asf/karaf/blob/9e6f8c9b/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java b/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
index 4f5584c..fb898c0 100644
--- a/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
@@ -32,6 +32,7 @@ import java.util.jar.Manifest;
import org.apache.felix.resolver.ResolverImpl;
import org.apache.felix.utils.version.VersionRange;
+import org.apache.karaf.features.DeploymentEvent;
import org.apache.karaf.features.Feature;
import org.apache.karaf.features.FeatureEvent;
import org.apache.karaf.features.FeaturesService;
@@ -41,7 +42,6 @@ import org.apache.karaf.features.internal.support.TestDownloadManager;
import org.easymock.EasyMock;
import org.easymock.IAnswer;
import org.easymock.IArgumentMatcher;
-import org.junit.Ignore;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
@@ -79,6 +79,8 @@ public class DeployerTest {
callback.print(EasyMock.anyString(), EasyMock.anyBoolean());
EasyMock.expectLastCall().anyTimes();
+ callback.callListeners(DeploymentEvent.DEPLOYMENT_STARTED);
+ EasyMock.expectLastCall();
callback.replaceDigraph(EasyMock.<Map<String, Map<String, Map<String, Set<String>>>>>anyObject(),
EasyMock.<Map<String, Set<Long>>>anyObject());
EasyMock.expectLastCall();
@@ -86,12 +88,18 @@ public class DeployerTest {
EasyMock.expectLastCall();
callback.installFeature(f100);
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.BUNDLES_INSTALLED);
+ EasyMock.expectLastCall();
callback.resolveBundles(EasyMock.<Set<Bundle>>anyObject(),
EasyMock.<Map<Resource, List<Wire>>>anyObject(),
EasyMock.<Map<Resource, Bundle>>anyObject());
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.BUNDLES_RESOLVED);
+ EasyMock.expectLastCall();
callback.callListeners(EasyMock.<FeatureEvent>anyObject());
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.DEPLOYMENT_FINISHED);
+ EasyMock.expectLastCall();
Bundle bundleA = createTestBundle(1, Bundle.ACTIVE, dataDir, "a100");
EasyMock.expect(callback.installBundle(EasyMock.eq(ROOT_REGION), EasyMock.eq("a100"), EasyMock.<InputStream>anyObject()))
@@ -144,6 +152,8 @@ public class DeployerTest {
callback.print(EasyMock.anyString(), EasyMock.anyBoolean());
EasyMock.expectLastCall().anyTimes();
+ callback.callListeners(DeploymentEvent.DEPLOYMENT_STARTED);
+ EasyMock.expectLastCall();
callback.stopBundle(EasyMock.eq(bundleA), anyInt());
EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
@@ -160,7 +170,7 @@ public class DeployerTest {
URL loc = getClass().getResource(dataDir + "/" + "a101" + ".mf");
Manifest man = new Manifest(loc.openStream());
Hashtable<String, String> headers = new Hashtable<>();
- for (Map.Entry attr : man.getMainAttributes().entrySet()) {
+ for (Map.Entry<Object, Object> attr : man.getMainAttributes().entrySet()) {
headers.put(attr.getKey().toString(), attr.getValue().toString());
}
bundleA.update(headers);
@@ -177,16 +187,22 @@ public class DeployerTest {
EasyMock.expectLastCall();
callback.installFeature(f101);
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.BUNDLES_INSTALLED);
+ EasyMock.expectLastCall();
callback.resolveBundles(EasyMock.eq(Collections.<Bundle>singleton(bundleA)),
EasyMock.<Map<Resource, List<Wire>>>anyObject(),
EasyMock.<Map<Resource, Bundle>>anyObject());
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.BUNDLES_RESOLVED);
+ EasyMock.expectLastCall();
callback.refreshPackages(EasyMock.eq(Collections.<Bundle>singleton(bundleA)));
EasyMock.expectLastCall();
callback.callListeners(FeatureEventMatcher.eq(new FeatureEvent(FeatureEvent.EventType.FeatureUninstalled, f100, FeaturesService.ROOT_REGION, false)));
EasyMock.expectLastCall();
callback.callListeners(FeatureEventMatcher.eq(new FeatureEvent(FeatureEvent.EventType.FeatureInstalled, f101, FeaturesService.ROOT_REGION, false)));
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.DEPLOYMENT_FINISHED);
+ EasyMock.expectLastCall();
EasyMock.replay(callback);
@@ -238,19 +254,27 @@ public class DeployerTest {
callback.print(EasyMock.anyString(), EasyMock.anyBoolean());
EasyMock.expectLastCall().anyTimes();
+ callback.callListeners(DeploymentEvent.DEPLOYMENT_STARTED);
+ EasyMock.expectLastCall();
callback.replaceDigraph(EasyMock.<Map<String, Map<String, Map<String, Set<String>>>>>anyObject(),
EasyMock.<Map<String, Set<Long>>>anyObject());
EasyMock.expectLastCall();
callback.saveState(EasyMock.<State>anyObject());
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.BUNDLES_INSTALLED);
+ EasyMock.expectLastCall();
callback.installFeature(f1);
EasyMock.expectLastCall();
callback.resolveBundles(EasyMock.<Set<Bundle>>anyObject(),
EasyMock.<Map<Resource, List<Wire>>>anyObject(),
EasyMock.<Map<Resource, Bundle>>anyObject());
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.BUNDLES_RESOLVED);
+ EasyMock.expectLastCall();
callback.callListeners(EasyMock.<FeatureEvent>anyObject());
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.DEPLOYMENT_FINISHED);
+ EasyMock.expectLastCall();
EasyMock.replay(callback);
@@ -300,6 +324,8 @@ public class DeployerTest {
callback.print(EasyMock.anyString(), EasyMock.anyBoolean());
EasyMock.expectLastCall().anyTimes();
+ callback.callListeners(DeploymentEvent.DEPLOYMENT_STARTED);
+ EasyMock.expectLastCall();
callback.installBundle(EasyMock.eq(ROOT_REGION), EasyMock.eq("a100"), EasyMock.<InputStream>anyObject());
EasyMock.expectLastCall().andReturn(serviceBundle1);
callback.replaceDigraph(EasyMock.<Map<String, Map<String, Map<String, Set<String>>>>>anyObject(),
@@ -309,12 +335,18 @@ public class DeployerTest {
EasyMock.expectLastCall();
callback.installFeature(f1);
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.BUNDLES_INSTALLED);
+ EasyMock.expectLastCall();
callback.resolveBundles(EasyMock.<Set<Bundle>>anyObject(),
EasyMock.<Map<Resource, List<Wire>>>anyObject(),
EasyMock.<Map<Resource, Bundle>>anyObject());
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.BUNDLES_RESOLVED);
+ EasyMock.expectLastCall();
callback.callListeners(EasyMock.<FeatureEvent>anyObject());
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.DEPLOYMENT_FINISHED);
+ EasyMock.expectLastCall();
EasyMock.replay(callback);
@@ -352,6 +384,8 @@ public class DeployerTest {
callback.print(EasyMock.anyString(), EasyMock.anyBoolean());
EasyMock.expectLastCall().anyTimes();
+ callback.callListeners(DeploymentEvent.DEPLOYMENT_STARTED);
+ EasyMock.expectLastCall();
callback.installBundle(EasyMock.eq(ROOT_REGION), EasyMock.eq("b100"), EasyMock.<InputStream>anyObject());
EasyMock.expectLastCall().andReturn(serviceBundle2);
callback.replaceDigraph(EasyMock.<Map<String, Map<String, Map<String, Set<String>>>>>anyObject(),
@@ -361,12 +395,18 @@ public class DeployerTest {
EasyMock.expectLastCall();
callback.installFeature(f2);
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.BUNDLES_INSTALLED);
+ EasyMock.expectLastCall();
callback.resolveBundles(EasyMock.<Set<Bundle>>anyObject(),
EasyMock.<Map<Resource, List<Wire>>>anyObject(),
EasyMock.<Map<Resource, Bundle>>anyObject());
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.BUNDLES_RESOLVED);
+ EasyMock.expectLastCall();
callback.callListeners(EasyMock.<FeatureEvent>anyObject());
EasyMock.expectLastCall();
+ callback.callListeners(DeploymentEvent.DEPLOYMENT_FINISHED);
+ EasyMock.expectLastCall();
EasyMock.replay(callback);
@@ -480,7 +520,7 @@ public class DeployerTest {
URL loc = getClass().getResource(dir + "/" + name + ".mf");
Manifest man = new Manifest(loc.openStream());
Hashtable<String, String> headers = new Hashtable<>();
- for (Map.Entry attr : man.getMainAttributes().entrySet()) {
+ for (Map.Entry<Object, Object> attr : man.getMainAttributes().entrySet()) {
headers.put(attr.getKey().toString(), attr.getValue().toString());
}
return new TestBundle(bundleId, name, state, headers);
@@ -498,6 +538,7 @@ public class DeployerTest {
return null;
}
+ @Override
public boolean matches(Object argument) {
if (!(argument instanceof FeatureEvent)) {
return false;
@@ -508,6 +549,7 @@ public class DeployerTest {
&& arg.isReplay() == expected.isReplay();
}
+ @Override
public void appendTo(StringBuffer buffer) {
}
@@ -544,6 +586,10 @@ public class DeployerTest {
}
@Override
+ public void callListeners(DeploymentEvent deployEvent) {
+ }
+
+ @Override
public Bundle installBundle(String region, String uri, InputStream is) throws BundleException {
return bundles.get(uri);
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/9e6f8c9b/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 026bf10..77ce577 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
@@ -34,13 +34,12 @@ import java.util.jar.Attributes;
import java.util.jar.JarFile;
import org.apache.felix.utils.properties.Properties;
+import org.apache.karaf.features.DeploymentEvent;
import org.apache.karaf.features.FeatureEvent;
import org.apache.karaf.features.FeaturesService;
import org.apache.karaf.features.internal.model.Library;
-import org.apache.karaf.features.internal.download.DownloadCallback;
import org.apache.karaf.features.internal.download.DownloadManager;
import org.apache.karaf.features.internal.download.Downloader;
-import org.apache.karaf.features.internal.download.StreamProvider;
import org.apache.karaf.features.internal.model.Config;
import org.apache.karaf.features.internal.model.ConfigFile;
import org.apache.karaf.features.internal.model.Feature;
@@ -183,6 +182,10 @@ public class AssemblyDeployCallback implements Deployer.DeployCallback {
}
@Override
+ public void callListeners(DeploymentEvent deployEvent) {
+ }
+
+ @Override
public void callListeners(FeatureEvent featureEvent) {
}
@@ -218,7 +221,7 @@ public class AssemblyDeployCallback implements Deployer.DeployCallback {
Hashtable<String, String> headers = new Hashtable<>();
try (JarFile jar = new JarFile(bundleSystemFile.toFile())) {
Attributes attributes = jar.getManifest().getMainAttributes();
- for (Map.Entry attr : attributes.entrySet()) {
+ for (Map.Entry<Object, Object> attr : attributes.entrySet()) {
headers.put(attr.getKey().toString(), attr.getValue().toString());
}
}
@@ -268,7 +271,7 @@ public class AssemblyDeployCallback implements Deployer.DeployCallback {
@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 = "}";
http://git-wip-us.apache.org/repos/asf/karaf/blob/9e6f8c9b/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 1c212c1..e94aa00 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
@@ -58,6 +58,7 @@ import org.apache.felix.resolver.Logger;
import org.apache.felix.resolver.ResolverImpl;
import org.apache.felix.utils.version.VersionRange;
import org.apache.felix.utils.version.VersionTable;
+import org.apache.karaf.features.DeploymentEvent;
import org.apache.karaf.features.FeatureEvent;
import org.apache.karaf.features.FeaturesService;
import org.apache.karaf.features.internal.download.DownloadCallback;
@@ -82,12 +83,10 @@ import org.apache.karaf.util.config.PropertiesLoader;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Component;
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.apache.maven.settings.Settings;
import org.ops4j.pax.url.mvn.MavenResolver;
import org.ops4j.pax.url.mvn.MavenResolvers;
import org.osgi.framework.Bundle;
@@ -211,7 +210,7 @@ public class VerifyMojo extends MojoSupport {
}
}
- private Object invoke(Object object, String getter) throws MojoExecutionException {
+ private static Object invoke(Object object, String getter) throws MojoExecutionException {
try {
return object.getClass().getMethod(getter).invoke(object);
} catch (Exception e) {
@@ -219,11 +218,11 @@ public class VerifyMojo extends MojoSupport {
}
}
- private Object getPolicy(Object object, boolean snapshots) throws MojoExecutionException {
+ private static Object getPolicy(Object object, boolean snapshots) throws MojoExecutionException {
return invoke(object, "getPolicy", new Class[] { Boolean.TYPE }, new Object[] { snapshots });
}
- private Object invoke(Object object, String getter, Class[] types, Object[] params) throws MojoExecutionException {
+ private static Object invoke(Object object, String getter, Class<?>[] types, Object[] params) throws MojoExecutionException {
try {
return object.getClass().getMethod(getter, types).invoke(object, params);
} catch (Exception e) {
@@ -474,7 +473,7 @@ public class VerifyMojo extends MojoSupport {
}
}
- private Deployer.DeploymentRequest createDeploymentRequest() {
+ private static Deployer.DeploymentRequest createDeploymentRequest() {
Deployer.DeploymentRequest request = new Deployer.DeploymentRequest();
request.bundleUpdateRange = FeaturesService.DEFAULT_BUNDLE_UPDATE_RANGE;
request.featureResolutionRange = FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE;
@@ -486,7 +485,7 @@ public class VerifyMojo extends MojoSupport {
return request;
}
- private String toString(Collection<String> collection) {
+ private static String toString(Collection<String> collection) {
StringBuilder sb = new StringBuilder();
sb.append("{\n");
for (String s : collection) {
@@ -551,7 +550,7 @@ public class VerifyMojo extends MojoSupport {
// attributes = DeploymentBuilder.overrideAttributes(attributes, metadata);
final Hashtable<String, String> headers = new Hashtable<>();
- for (Map.Entry attr : attributes.entrySet()) {
+ for (Map.Entry<Object, Object> attr : attributes.entrySet()) {
headers.put(attr.getKey().toString(), attr.getValue().toString());
}
@@ -788,6 +787,10 @@ public class VerifyMojo extends MojoSupport {
}
@Override
+ public void callListeners(DeploymentEvent deployEvent) {
+ }
+
+ @Override
public Bundle installBundle(String region, String uri, InputStream is) throws BundleException {
try {
Hashtable<String, String> headers = new Hashtable<>();
@@ -796,7 +799,7 @@ public class VerifyMojo extends MojoSupport {
while ((entry = zis.getNextEntry()) != null) {
if (MANIFEST_NAME.equals(entry.getName())) {
Attributes attributes = new Manifest(zis).getMainAttributes();
- for (Map.Entry attr : attributes.entrySet()) {
+ for (Map.Entry<Object, Object> attr : attributes.entrySet()) {
headers.put(attr.getKey().toString(), attr.getValue().toString());
}
}