aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1353319 [3/3] - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ subsystem-itests/src/test/java/org/apache/aries/subsyst...
Date Sun, 24 Jun 2012 19:48:45 GMT
Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/UninstallAction.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/UninstallAction.java?rev=1353319&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/UninstallAction.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/UninstallAction.java
Sun Jun 24 19:48:40 2012
@@ -0,0 +1,32 @@
+package org.apache.aries.subsystem.core.internal;
+
+import java.util.EnumSet;
+
+import org.osgi.service.subsystem.Subsystem.State;
+
+public class UninstallAction extends AbstractAction {
+	public UninstallAction(AriesSubsystem subsystem) {
+		super(subsystem);
+	}
+	
+	@Override
+	public Object run() {
+		checkRoot();
+		State state = subsystem.getState();
+		// UNINSTALLING is included here because the transition to UNINSTALLED
+		// is guaranteed, so there's no point in waiting.
+		if (EnumSet.of(State.UNINSTALLING, State.UNINSTALLED).contains(state))
+			return null;
+		else if (EnumSet.of(State.INSTALLING, State.RESOLVING, State.STARTING, State.STOPPING).contains(state))
{
+			waitForStateChange();
+			subsystem.uninstall();
+		}
+		else if (state.equals(State.ACTIVE)) {
+			subsystem.stop();
+			subsystem.uninstall();
+		}
+		else
+			ResourceUninstaller.newInstance(subsystem).uninstall();
+		return null;
+	}
+}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java?rev=1353319&r1=1353318&r2=1353319&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
Sun Jun 24 19:48:40 2012
@@ -1,10 +1,22 @@
 package org.apache.aries.subsystem.core.internal;
 
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.resource.Resource;
 import org.osgi.service.coordinator.Coordination;
+import org.osgi.service.coordinator.CoordinationException;
+import org.osgi.service.subsystem.Subsystem;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class Utils {
+	private static final Logger logger = LoggerFactory.getLogger(Utils.class);
+	
+	public static Coordination createCoordination() {
+		return Activator.getInstance().getCoordinator().begin(AriesSubsystem.ROOT_SYMBOLIC_NAME
+ "-0", 0);
+	}
+	
 	public static Coordination createCoordination(AriesSubsystem subsystem) {
-		return Activator.getInstance().getCoordinator().create(subsystem.getSymbolicName() + '-'
+ subsystem.getSubsystemId(), 0);
+		return Activator.getInstance().getCoordinator().begin(subsystem.getSymbolicName() + '-'
+ subsystem.getSubsystemId(), 0);
 	}
 	
 	public static AriesSubsystem findFirstSubsystemAcceptingDependenciesStartingFrom(AriesSubsystem
subsystem) {
@@ -15,7 +27,55 @@ public class Utils {
 		return subsystem;
 	}
 	
+	public static AriesSubsystem findScopedSubsystemInRegion(AriesSubsystem subsystem) {
+		while (!subsystem.isScoped())
+			subsystem = (AriesSubsystem)subsystem.getParents().iterator().next();
+		return subsystem;
+	}
+	
+	public static int getActiveUseCount(Resource resource) {
+		int result = 0;
+		for (AriesSubsystem subsystem : Activator.getInstance().getSubsystems().getSubsystemsReferencing(resource))
+			if (Subsystem.State.ACTIVE.equals(subsystem.getState()))
+				result++;
+		return result;
+	}
+	
+	public static long getId(Resource resource) {
+		if (resource instanceof AriesSubsystem)
+			return ((AriesSubsystem)resource).getSubsystemId();
+		if (resource instanceof BundleRevision)
+			return ((BundleRevision)resource).getBundle().getBundleId();
+		return -1;
+	}
+	
+	public static void installResource(Resource resource, AriesSubsystem subsystem) {
+		Coordination coordination = Utils.createCoordination(subsystem);
+		try {
+			ResourceInstaller.newInstance(coordination, resource, subsystem, false).install();
+		}
+		catch (Throwable t) {
+			coordination.fail(t);
+		}
+		finally {
+			try {
+				coordination.end();
+			}
+			catch (CoordinationException e) {
+				logger.error("Resource could not be installed", e);
+			}
+		}
+	}
+	
 	public static boolean isAcceptDependencies(AriesSubsystem subsystem) {
-		return subsystem.getArchive().getSubsystemManifest().getSubsystemTypeHeader().getProvisionPolicyDirective().isAcceptDependencies();
+		return subsystem.getSubsystemManifest().getSubsystemTypeHeader().getProvisionPolicyDirective().isAcceptDependencies();
+	}
+	
+	public static boolean isInstallableResource(Resource resource) {
+		return !isSharedResource(resource);
+	}
+	
+	public static boolean isSharedResource(Resource resource) {
+		return resource instanceof AriesSubsystem || resource instanceof BundleRevision;
 	}
 }

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/FeatureTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/FeatureTest.java?rev=1353319&r1=1353318&r2=1353319&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/FeatureTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/FeatureTest.java
Sun Jun 24 19:48:40 2012
@@ -128,10 +128,7 @@ public class FeatureTest extends Subsyst
 		}
 	}
 	
-	/*
-	 * Persistence needs to be refactored based on directory structure changes.
-	 */
-	//@Test
+	@Test
 	public void testPersistence() throws Exception {
 		Subsystem feature3Before = installSubsystemFromFile("feature3.esa");
 		Subsystem feature3After = null;

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java?rev=1353319&r1=1353318&r2=1353319&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
Sun Jun 24 19:48:40 2012
@@ -304,6 +304,7 @@ public abstract class SubsystemTest exte
 	
 	protected void assertEvent(Subsystem subsystem, Subsystem.State state, SubsystemEventHandler.ServiceEventInfo
event, int type) {
 		// TODO Could accept a ServiceRegistration as an argument and verify it against the one
in the event.
+		assertNotNull("No event", event);
 		assertEquals("Wrong ID", subsystem.getSubsystemId(), event.getId());
 		assertEquals("Wrong symbolic name", subsystem.getSymbolicName(), event.getSymbolicName());
 		assertEquals("Wrong version", subsystem.getVersion(), event.getVersion());



Mime
View raw message