felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1759454 - in /felix/trunk/dependencymanager: org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/ org.apache.felix.dependencymanager.shell/src/org/apache/felix/dm/shell/ org.apache.felix.dependencymanager/ org.apache...
Date Tue, 06 Sep 2016 16:17:51 GMT
Author: pderop
Date: Tue Sep  6 16:17:51 2016
New Revision: 1759454

URL: http://svn.apache.org/viewvc?rev=1759454&view=rev
Log:
FELIX-5339: Enhance the diagnostics API to retrieve missing custom dependencies (applied the
patch provided by Raluca, thanks!).

Modified:
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/DiagnosticsTest.java
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager.shell/src/org/apache/felix/dm/shell/DMCommand.java
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager/bnd.bnd
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/diagnostics/DependencyGraph.java
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/diagnostics/packageinfo

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/DiagnosticsTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/DiagnosticsTest.java?rev=1759454&r1=1759453&r2=1759454&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/DiagnosticsTest.java
(original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/DiagnosticsTest.java
Tue Sep  6 16:17:51 2016
@@ -24,8 +24,11 @@ import java.util.Properties;
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.ComponentDeclaration;
 import org.apache.felix.dm.ConfigurationDependency;
+import org.apache.felix.dm.Dependency;
 import org.apache.felix.dm.DependencyManager;
 import org.apache.felix.dm.ServiceDependency;
+import org.apache.felix.dm.context.AbstractDependency;
+import org.apache.felix.dm.context.DependencyContext;
 import org.apache.felix.dm.diagnostics.CircularDependency;
 import org.apache.felix.dm.diagnostics.DependencyGraph;
 import org.apache.felix.dm.diagnostics.DependencyGraph.ComponentState;
@@ -112,7 +115,6 @@ public class DiagnosticsTest extends Tes
 		assertTrue(graph.getMissingDependencies("configuration").isEmpty());
 		assertTrue(graph.getMissingDependencies("bundle").isEmpty());
 		assertTrue(graph.getMissingDependencies("resource").isEmpty());
-		
 	}
 	
 	public void testConfigurationDependencyMissing() throws Exception {
@@ -417,6 +419,42 @@ public class DiagnosticsTest extends Tes
 
 	}
 	
+	public void testMissingCustomDependencies() {
+		
+		DependencyManager dm = getDM();
+		
+		Component component0 = dm.createComponent()
+				.setImplementation(C0.class)
+				.add(dm.createServiceDependency()
+						.setService(S1.class)
+						.setRequired(true))
+				.add(dm.createServiceDependency()
+						.setService(S2.class)
+						.setRequired(true));
+		
+
+		Component component1 = dm.createComponent()
+				.setImplementation(S1Impl1.class)
+				.setInterface(S1.class.getName(), null)
+				.add(ToggleDependency.create());
+		
+		m_dm.add(component0);
+		m_dm.add(component1);
+		
+		DependencyGraph graph = DependencyGraph.getGraph(ComponentState.UNREGISTERED,DependencyState.REQUIRED_UNAVAILABLE);
+		
+		List<MissingDependency> missingCustomDependencies = graph.getMissingCustomDependencies();
+		assertEquals(1, missingCustomDependencies.size());
+		
+		MissingDependency missingCustomeDependency = missingCustomDependencies.get(0);
+		assertTrue(missingCustomeDependency.getType().equals("toggle"));
+		assertTrue(missingCustomeDependency.getName().equals("false"));
+		
+		List<MissingDependency> missingDependencies = graph.getMissingDependencies("service");
+		assertEquals(1, missingDependencies.size());
+	}
+	
+	
 	static interface S1 {}
 	static interface S2 {}
 	static interface S3 {}
@@ -461,5 +499,48 @@ public class DiagnosticsTest extends Tes
 	static class S8Impl1 implements S8 {
 		public S8Impl1() {}
 	}
+	
+	static class CA {
+		public CA(){}
+	}
+	
+	static interface ToggleDependency extends Dependency {
+		static ToggleDependency create() {
+			return new ToggleDependencyImpl();
+		}
+		
+	}
+	
+	static class ToggleDependencyImpl extends AbstractDependency<ToggleDependencyImpl>
implements ToggleDependency {
+		
+		public ToggleDependencyImpl() {
+			setRequired(true);
+		}
+		
+		public ToggleDependencyImpl(ToggleDependencyImpl prototype) {
+			super(prototype);
+		}
+
+		@Override
+		public Class<?> getAutoConfigType() {
+			return null;
+		}
+
+		@Override
+		public DependencyContext createCopy() {
+			return new ToggleDependencyImpl(this);
+		}
+
+		@Override
+		public String getSimpleName() {
+	        return "" + isAvailable();
+		}
+
+		@Override
+		public String getType() {
+	        return "toggle";
+		}
+		
+	}
 
 }

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.shell/src/org/apache/felix/dm/shell/DMCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.shell/src/org/apache/felix/dm/shell/DMCommand.java?rev=1759454&r1=1759453&r2=1759454&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.shell/src/org/apache/felix/dm/shell/DMCommand.java
(original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.shell/src/org/apache/felix/dm/shell/DMCommand.java
Tue Sep  6 16:17:51 2016
@@ -594,6 +594,12 @@ public class DMCommand {
     		System.out.println("The following bundle(s) are missing: ");
     		printMissingDependencies(missingBundleDependencies);
     	}
+    	
+    	List<MissingDependency> missingCustomDependencies = graph.getMissingCustomDependencies();
+    	if(!missingCustomDependencies.isEmpty()) {
+    		System.out.println("The following custom dependency(ies) are missing: ");
+    		printMissingCustomDependencies(missingCustomDependencies);
+    	}
     }
 
 	private void printCircularDependencies(List<CircularDependency> circularDependencies)
{
@@ -606,11 +612,17 @@ public class DMCommand {
 		}
 	}
 
-	private void printMissingDependencies(List<MissingDependency> missingConfigDependencies)
{
-		for(MissingDependency m : missingConfigDependencies) {
+	private void printMissingDependencies(List<MissingDependency> missingDependencies)
{
+		for(MissingDependency m : missingDependencies) {
 			System.out.println(" * " + m.getName() + " for bundle " + m.getBundleName());
 		}
 	}
+	
+	private void printMissingCustomDependencies(List<MissingDependency> missingDependencies)
{
+		for(MissingDependency m : missingDependencies) {
+			System.out.println(" * " + m.getName() + "(" + m.getType() + ")" + " for bundle " + m.getBundleName());
+		}
+	}
 
     private void listResolvedBundles() {
         boolean areResolved = false;

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager/bnd.bnd
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/bnd.bnd?rev=1759454&r1=1759453&r2=1759454&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager/bnd.bnd (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager/bnd.bnd Tue Sep  6 16:17:51
2016
@@ -36,7 +36,7 @@ Include-Resource: META-INF/=resources/LI
 	META-INF/=${workspace}/release/resources/changelog.txt
 Import-Package: !org.junit,!org.mockito.*,*
 Bundle-Activator: org.apache.felix.dm.impl.Activator
-Bundle-Version: 4.3.1
+Bundle-Version: 4.4.0
 Bundle-Name: Apache Felix Dependency Manager
 Bundle-Description: Provides dynamic service and component dependency management
 Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/diagnostics/DependencyGraph.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/diagnostics/DependencyGraph.java?rev=1759454&r1=1759453&r2=1759454&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/diagnostics/DependencyGraph.java
(original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/diagnostics/DependencyGraph.java
Tue Sep  6 16:17:51 2016
@@ -25,6 +25,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.Stack;
+import java.util.stream.Collectors;
 
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.ComponentDeclaration;
@@ -60,6 +61,9 @@ public class DependencyGraph {
 	};
 	
 	private static final String SERVICE = "service";
+	private static final String CONFIGURATION = "configuration";
+	private static final String BUNDLE = "bundle";
+	private static final String RESOURCE = "resource";
 
 	private Map<ComponentDeclaration, DependencyGraphNode> m_componentToNode = new HashMap<>();
 	private Map<ComponentDependencyDeclaration, DependencyGraphNode> m_dependencyToNode
= new HashMap<>();
@@ -354,8 +358,25 @@ public class DependencyGraph {
 		}
 		return result;
 	}
-    
-    private String getSimpleName(String name) {
+
+	/**
+	 * Returns all custom missing dependencies. Custom dependencies are not 'out of the box'
dependencies (service, resource, 
+	 * bundle, configuration).
+	 * 
+	 * @return The missing dependencies which are not 'out of the box dependencies'.
+	 */
+	public List<MissingDependency> getMissingCustomDependencies() {
+		
+		List<MissingDependency> missingDependencies = getMissingDependencies(null);
+		return missingDependencies.stream().filter(m -> !isOutOfTheBoxDependencyType(m.getType())).collect(Collectors.toList());
+		
+	}
+	
+    private boolean isOutOfTheBoxDependencyType(String type) {
+    	return SERVICE.equals(type) || CONFIGURATION.equals(type) || BUNDLE.equals(type) ||
RESOURCE.equals(type);
+	}
+
+	private String getSimpleName(String name) {
         int cuttOff = name.indexOf("(");
         if (cuttOff != -1) {
             return name.substring(0, cuttOff).trim();

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/diagnostics/packageinfo
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/diagnostics/packageinfo?rev=1759454&r1=1759453&r2=1759454&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/diagnostics/packageinfo
(original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/diagnostics/packageinfo
Tue Sep  6 16:17:51 2016
@@ -1 +1 @@
-version 1.0.0
\ No newline at end of file
+version 1.1.0
\ No newline at end of file



Mime
View raw message