felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1636069 - in /felix/sandbox/pderop/dependencymanager-prototype: org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/ org.apache.felix.dependencymanager/src/org/apache/felix/dm/ org.apache.felix.dependencymanager/src/org/...
Date Sat, 01 Nov 2014 23:15:07 GMT
Author: pderop
Date: Sat Nov  1 23:15:06 2014
New Revision: 1636069

URL: http://svn.apache.org/r1636069
Log:
FELIX-4158: ComponentDeclaration should give access to component information.

The component implementation class and the component services were already returned by the

ComponentDeclaration.getClassName() and ComponentDeclaration.getServices method.
I added in ComponentDependencyDeclaration the following methods:

getSimpleName() -> returns the dependency name (only the name)
getFilter() -> returns the dependency filter.

Added:
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/FELIX4158_DependencyDeclarationTest.java
Modified:
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ComponentDependencyDeclaration.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/AbstractDependency.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/BundleDependencyImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ResourceDependencyImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ServiceDependencyImpl.java

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/FELIX4158_DependencyDeclarationTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/FELIX4158_DependencyDeclarationTest.java?rev=1636069&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/FELIX4158_DependencyDeclarationTest.java
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/FELIX4158_DependencyDeclarationTest.java
Sat Nov  1 23:15:06 2014
@@ -0,0 +1,94 @@
+package org.apache.felix.dm.itest;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import junit.framework.Assert;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.ComponentDeclaration;
+import org.apache.felix.dm.ComponentDependencyDeclaration;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.Bundle;
+import org.osgi.service.log.LogService;
+
+public class FELIX4158_DependencyDeclarationTest extends TestBase {
+    public void testServiceDependencyDeclaration() {
+        DependencyManager m = getDM();
+        Component c = m.createComponent()
+            .setImplementation(new Object())
+            .add(m.createServiceDependency().setService(LogService.class, "(foo=bar)"));
+        
+        ComponentDeclaration cd = c.getComponentDeclaration();
+        ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies();
+        Assert.assertNotNull(cdds);
+        Assert.assertNotNull(cdds.length == 1);
+        Assert.assertEquals(cdds[0].getName(), "org.osgi.service.log.LogService (foo=bar)");
+        Assert.assertEquals(cdds[0].getSimpleName(), "org.osgi.service.log.LogService");
+        Assert.assertNotNull(cdds[0].getFilter());
+        Assert.assertEquals(cdds[0].getFilter(), "(foo=bar)");
+    }
+    
+    public void testConfigurationDependencyDeclaration() {
+        DependencyManager m = getDM();
+        Component c = m.createComponent()
+            .setImplementation(new Object())
+            .add(m.createConfigurationDependency().setPid("foo"));
+        
+        ComponentDeclaration cd = c.getComponentDeclaration();
+        ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies();
+        Assert.assertNotNull(cdds);
+        Assert.assertNotNull(cdds.length == 1);
+        Assert.assertEquals(cdds[0].getName(), "foo");
+        Assert.assertEquals(cdds[0].getSimpleName(), "foo");
+        Assert.assertNull(cdds[0].getFilter());
+    }
+    
+    public void testResourceWithFilterDependencyDeclaration() {
+        DependencyManager m = getDM();
+        Component c = m.createComponent()
+            .setImplementation(new Object())
+            .add(m.createResourceDependency()
+                .setFilter("(&(path=/path/to/*.txt)(host=localhost))"));
+        
+        ComponentDeclaration cd = c.getComponentDeclaration();
+        ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies();
+        Assert.assertNotNull(cdds);
+        Assert.assertNotNull(cdds.length == 1);
+        Assert.assertEquals(cdds[0].getName(), ("(&(path=/path/to/*.txt)(host=localhost))"));
+        Assert.assertNotNull(cdds[0].getFilter());
+        Assert.assertEquals(cdds[0].getFilter(), "(&(path=/path/to/*.txt)(host=localhost))");
+    }
+    
+    public void testResourceDependencyDeclaration() throws MalformedURLException {
+        DependencyManager m = getDM();
+        Component c = m.createComponent()
+            .setImplementation(new Object())
+            .add(m.createResourceDependency()
+                  .setResource(new URL("file://localhost/path/to/file1.txt")));
+        
+        ComponentDeclaration cd = c.getComponentDeclaration();
+        ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies();
+        Assert.assertNotNull(cdds);
+        Assert.assertNotNull(cdds.length == 1);
+        Assert.assertEquals(cdds[0].getName(), "file://localhost/path/to/file1.txt");
+        Assert.assertNull(cdds[0].getFilter());
+    }
+    
+    public void testBundleDependencyDeclaration() throws MalformedURLException {
+        DependencyManager m = getDM();
+        Component c = m.createComponent()
+            .setImplementation(new Object())
+            .add(m.createBundleDependency()
+                .setStateMask( Bundle.ACTIVE )
+                .setFilter("(DependencyManager-Component=*)"));
+        
+        ComponentDeclaration cd = c.getComponentDeclaration();
+        ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies();
+        Assert.assertNotNull(cdds);
+        Assert.assertNotNull(cdds.length == 1);
+        Assert.assertEquals(cdds[0].getName(), "active (DependencyManager-Component=*)");
+        Assert.assertNotNull(cdds[0].getFilter());
+        Assert.assertEquals(cdds[0].getFilter(), "(DependencyManager-Component=*)");
+    }
+}

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ComponentDependencyDeclaration.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ComponentDependencyDeclaration.java?rev=1636069&r1=1636068&r2=1636069&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ComponentDependencyDeclaration.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ComponentDependencyDeclaration.java
Sat Nov  1 23:15:06 2014
@@ -48,8 +48,12 @@ public interface ComponentDependencyDecl
     public static final int STATE_OPTIONAL = 4;
     /** State constant for a required dependency that has not been started yet. */
     public static final int STATE_REQUIRED = 5;
-    /** Returns the name of this dependency. */
+    /** Returns the name of this dependency (a generic name with optional info seprated by
spaces)*/
     public String getName();
+    /** Returns the simple dependency name (service classname for example) */
+    public String getSimpleName();
+    /** Returns the Dependency filter or null */
+    public String getFilter();
     /** Returns the name of the type of this dependency. */
     public String getType();
     /** Returns the state of this dependency. */

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/AbstractDependency.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/AbstractDependency.java?rev=1636069&r1=1636068&r2=1636069&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/AbstractDependency.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/AbstractDependency.java
Sat Nov  1 23:15:06 2014
@@ -415,13 +415,23 @@ public abstract class AbstractDependency
     @Override
     public abstract DependencyContext createCopy();
 
-    // -------------- DependencyContext -----------------------------------------------
+    // -------------- ComponentDependencyDeclaration -----------------------------------------------
 
     @Override
     public abstract String getName();
 
     @Override
     public abstract String getType();
+    
+    @Override
+    public String getSimpleName() {
+        return getName();
+    }
+    
+    @Override
+    public String getFilter() {
+        return null;
+    }
 
     @Override
     public int getState() { // Can be called from any threads, but our class attributes are
volatile

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/BundleDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/BundleDependencyImpl.java?rev=1636069&r1=1636068&r2=1636069&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/BundleDependencyImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/BundleDependencyImpl.java
Sat Nov  1 23:15:06 2014
@@ -99,12 +99,27 @@ public class BundleDependencyImpl extend
             sb.append(m_filter.toString());
         }
         if (m_bundleId != -1) {
-            sb.append("bundle.id=" + m_bundleId);
+            sb.append("{bundle.id=" + m_bundleId + "}");
         }
         return sb.toString();
     }
 
     @Override
+    public String getFilter() {
+        if (m_filter != null || m_bundleId != -1) {
+            StringBuilder sb = new StringBuilder();
+            if (m_filter != null) {
+                sb.append(m_filter.toString());
+            }
+            if (m_bundleId != -1) {
+                sb.append("{bundle.id=" + m_bundleId + "}");
+            }
+            return sb.toString();
+        }
+        return null;
+    }
+
+    @Override
     public String getType() {
         return "bundle";
     }

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java?rev=1636069&r1=1636068&r2=1636069&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
Sat Nov  1 23:15:06 2014
@@ -125,6 +125,14 @@ public class ComponentImpl implements Co
         public String getName() {
             return m_name;
         }
+        
+        public String getSimpleName() {
+            return m_name;
+        }
+        
+        public String getFilter() {
+            return null;
+        }
 
         public int getState() {
             return m_state;

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java?rev=1636069&r1=1636068&r2=1636069&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java
Sat Nov  1 23:15:06 2014
@@ -111,10 +111,16 @@ public class ConfigurationDependencyImpl
     	return "ConfigurationDependency[" + m_pid + "]";
     }
     
+    @Override
     public String getName() {
         return m_pid;
     }
     
+    @Override
+    public String getFilter() {
+        return null;
+    }
+
     public String getType() {
         return "configuration";
     }

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ResourceDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ResourceDependencyImpl.java?rev=1636069&r1=1636068&r2=1636069&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ResourceDependencyImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ResourceDependencyImpl.java
Sat Nov  1 23:15:06 2014
@@ -214,14 +214,24 @@ public class ResourceDependencyImpl exte
     @Override
     public String getName() {
         StringBuilder sb = new StringBuilder();
-        if (m_resourceFilter != null) {
-            sb.append(m_resourceFilter);
-        }
         if (m_trackedResource != null) {
             sb.append(m_trackedResource.toString());
         }
+        if (m_resourceFilter != null) {
+            sb.append(m_resourceFilter);
+        }
         return sb.toString();
     }
+    
+    @Override
+    public String getSimpleName() {
+        return m_trackedResource != null ? m_trackedResource.toString() : null;
+    }
+
+    @Override
+    public String getFilter() {
+        return m_resourceFilter;
+    }
 
     @Override
     public String getType() {

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ServiceDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ServiceDependencyImpl.java?rev=1636069&r1=1636068&r2=1636069&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ServiceDependencyImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ServiceDependencyImpl.java
Sat Nov  1 23:15:06 2014
@@ -54,6 +54,7 @@ public class ServiceDependencyImpl exten
     private volatile Object m_nullObject;
     private boolean debug = false;
     private String debugKey;
+    private long m_trackedServiceReferenceId;
     
     public ServiceDependency setDebug(String debugKey) {
     	this.debugKey = debugKey;
@@ -329,6 +330,26 @@ public class ServiceDependencyImpl exten
     }
     
     @Override
+    public String getSimpleName() {
+        if (m_trackedServiceName != null) {
+            return m_trackedServiceName.getName();
+        }
+        return null;
+    }
+
+    @Override
+    public String getFilter() {
+        if (m_trackedServiceFilterUnmodified != null) {
+            return m_trackedServiceFilterUnmodified;
+        } else if (m_trackedServiceReference != null) {
+            return new StringBuilder("(").append(Constants.SERVICE_ID).append("=").append(
+                String.valueOf(m_trackedServiceReferenceId)).append(")").toString();
+        } else {
+            return null;
+        }
+    }
+    
+    @Override
     public String getType() {
         return "service";
     }
@@ -396,6 +417,7 @@ public class ServiceDependencyImpl exten
             if (serviceFilter != null) {
                 throw new IllegalArgumentException("Cannot specify both a filter and a service
reference.");
             }
+            m_trackedServiceReferenceId = (Long) m_trackedServiceReference.getProperty(Constants.SERVICE_ID);
         }
         else {
             m_trackedServiceReference = null;



Mime
View raw message