You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ma...@apache.org on 2013/11/15 13:01:17 UTC

svn commit: r1542239 - in /felix/trunk/deploymentadmin: autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/ autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/ deploymentadmin/

Author: marrs
Date: Fri Nov 15 12:01:17 2013
New Revision: 1542239

URL: http://svn.apache.org/r1542239
Log:
FELIX-4314 Fixed the code as described. Adapted the test cases as this affected some of the mock objects we were constructing.

Modified:
    felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/Activator.java
    felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java
    felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java
    felix/trunk/deploymentadmin/deploymentadmin/pom.xml

Modified: felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/Activator.java?rev=1542239&r1=1542238&r2=1542239&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/Activator.java (original)
+++ felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/Activator.java Fri Nov 15 12:01:17 2013
@@ -21,13 +21,12 @@ package org.apache.felix.deployment.rp.a
 import java.util.Dictionary;
 import java.util.Properties;
 
+import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.service.deploymentadmin.spi.ResourceProcessor;
-import org.osgi.service.event.EventConstants;
-import org.osgi.service.event.EventHandler;
 import org.osgi.service.log.LogService;
 import org.osgi.service.metatype.MetaTypeService;
 
@@ -39,11 +38,12 @@ public class Activator extends Dependenc
     public void init(BundleContext context, DependencyManager manager) throws Exception {
     	Dictionary properties = new Properties();
         properties.put(Constants.SERVICE_PID, "org.osgi.deployment.rp.autoconf");
-        properties.put(EventConstants.EVENT_TOPIC, org.apache.felix.deploymentadmin.Constants.EVENTTOPIC_COMPLETE);
         
+        AutoConfResourceProcessor processor = new AutoConfResourceProcessor();
         manager.add(createComponent()
-            .setInterface(new String[] { ResourceProcessor.class.getName(), EventHandler.class.getName() }, properties)
-            .setImplementation(AutoConfResourceProcessor.class)
+            .setInterface(ResourceProcessor.class.getName(), properties)
+            .setAutoConfig(Component.class, false)
+            .setImplementation(processor)
             .add(createServiceDependency()
                 .setService(MetaTypeService.class)
                 .setRequired(false))

Modified: felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java?rev=1542239&r1=1542238&r2=1542239&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java (original)
+++ felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java Fri Nov 15 12:01:17 2013
@@ -31,13 +31,12 @@ import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 import java.util.Vector;
 
-import org.apache.felix.deploymentadmin.Constants;
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.ServiceDependency;
 import org.apache.felix.metatype.Attribute;
 import org.apache.felix.metatype.Designate;
 import org.apache.felix.metatype.MetaData;
@@ -54,13 +53,13 @@ import org.osgi.service.deploymentadmin.
 import org.osgi.service.deploymentadmin.spi.ResourceProcessor;
 import org.osgi.service.deploymentadmin.spi.ResourceProcessorException;
 import org.osgi.service.event.Event;
+import org.osgi.service.event.EventConstants;
 import org.osgi.service.event.EventHandler;
 import org.osgi.service.log.LogService;
 import org.osgi.service.metatype.AttributeDefinition;
 import org.osgi.service.metatype.MetaTypeInformation;
 import org.osgi.service.metatype.MetaTypeService;
 import org.osgi.service.metatype.ObjectClassDefinition;
-import org.xmlpull.v1.XmlPullParserException;
 
 public class AutoConfResourceProcessor implements ResourceProcessor, EventHandler {
     private static final String LOCATION_PREFIX = "osgi-dp:";
@@ -71,7 +70,9 @@ public class AutoConfResourceProcessor i
 	private volatile ConfigurationAdmin m_configAdmin;
 	private volatile MetaTypeService m_metaService;
 	private volatile BundleContext m_bc;
-	private volatile Component m_component;
+    private volatile DependencyManager m_dm;
+    
+	private Component m_component;
 	
 	private final Object LOCK = new Object(); // protects the members below
 
@@ -81,8 +82,6 @@ public class AutoConfResourceProcessor i
 	
 	private PersistencyManager m_persistencyManager;
 
-    private ServiceDependency m_configurationAdminDependency;
-
 	public void start() throws IOException {
 		File root = m_bc.getDataFile("");
 		if (root == null) {
@@ -100,7 +99,7 @@ public class AutoConfResourceProcessor i
             if (session == null) {
                 throw new IllegalArgumentException("Trying to begin new deployment session with a null session.");
             }
-            if (m_toBeInstalled.size() > 0 || m_toBeDeleted.size() > 0 || m_configurationAdminTasks.size() > 0 || m_postCommitTasks.size() > 0) {
+            if (m_toBeInstalled.size() > 0 || m_toBeDeleted.size() > 0 || m_configurationAdminTasks.size() > 0 || m_postCommitTasks.size() > 0 || m_component != null) {
                 throw new IllegalStateException("State not reset correctly at start of session.");
             }
             m_session = session;
@@ -289,12 +288,20 @@ public class AutoConfResourceProcessor i
 
     public synchronized void commit() {
         m_log.log(LogService.LOG_DEBUG, "commit");
-        DependencyManager dm = m_component.getDependencyManager();
-        m_configurationAdminDependency = dm.createServiceDependency()
-            .setService(ConfigurationAdmin.class)
-            .setCallbacks("addConfigurationAdmin", null)
-            .setRequired(false);
-        m_component.add(m_configurationAdminDependency);
+
+        Dictionary properties = new Properties();
+        properties.put(EventConstants.EVENT_TOPIC, org.apache.felix.deploymentadmin.Constants.EVENTTOPIC_COMPLETE);
+        m_component = m_dm.createComponent()
+            .setInterface(EventHandler.class.getName(), properties)
+            .setImplementation(this)
+            .setCallbacks(null, null, null, null)
+            .setAutoConfig(Component.class, false)
+            .add(m_dm.createServiceDependency()
+                .setService(ConfigurationAdmin.class)
+                .setCallbacks("addConfigurationAdmin", null)
+                .setRequired(false));
+        m_dm.add(m_component);
+
         m_log.log(LogService.LOG_DEBUG, "commit done");
     }
     
@@ -327,7 +334,6 @@ public class AutoConfResourceProcessor i
     
     public void postcommit() {
         m_log.log(LogService.LOG_DEBUG, "post commit");
-        m_component.remove(m_configurationAdminDependency);
         Iterator iterator = m_postCommitTasks.iterator();
         while (iterator.hasNext()) {
             PostCommitTask task = (PostCommitTask) iterator.next();
@@ -343,6 +349,10 @@ public class AutoConfResourceProcessor i
     }
 
     private void endSession() {
+        if (m_component != null) {
+        	m_dm.remove(m_component);
+            m_component = null;
+        }
         m_toBeInstalled.clear();
         m_toBeDeleted.clear();
         m_postCommitTasks.clear();
@@ -507,51 +517,51 @@ public class AutoConfResourceProcessor i
     		for (int i = 0; i < content.length; i++) {
     			String value = content[i];
     			switch (type) {
-    			case AttributeDefinition.BOOLEAN:
-    				typedContent = (typedContent == null) ? new Boolean[content.length] : typedContent;
-    				typedContent[i] = Boolean.valueOf(value);	
-    				break;
-    			case AttributeDefinition.BYTE:
-    				typedContent = (typedContent == null) ? new Byte[content.length] : typedContent;
-    				typedContent[i] = Byte.valueOf(value);
-    				break;
-    			case AttributeDefinition.CHARACTER:
-    				typedContent = (typedContent == null) ? new Character[content.length] : typedContent;
-    				char[] charArray = value.toCharArray();
-    				if (charArray.length == 1) {
-    					typedContent[i] = new Character(charArray[0]);
-    				}
-    				else {
-    					return null;
-    				}
-    				break;
-    			case AttributeDefinition.DOUBLE:
-    				typedContent = (typedContent == null) ? new Double[content.length] : typedContent;
-    				typedContent[i] = Double.valueOf(value);
-    				break;
-    			case AttributeDefinition.FLOAT:
-    				typedContent = (typedContent == null) ? new Float[content.length] : typedContent;
-    				typedContent[i] = Float.valueOf(value);
-    				break;
-    			case AttributeDefinition.INTEGER:
-    				typedContent = (typedContent == null) ? new Integer[content.length] : typedContent;
-    				typedContent[i] = Integer.valueOf(value);
-    				break;
-    			case AttributeDefinition.LONG:
-    				typedContent = (typedContent == null) ? new Long[content.length] : typedContent;
-    				typedContent[i] = Long.valueOf(value);
-    				break;
-    			case AttributeDefinition.SHORT:
-    				typedContent = (typedContent == null) ? new Short[content.length] : typedContent;
-    				typedContent[i] = Short.valueOf(value);
-    				break;
-    			case AttributeDefinition.STRING:
-    				typedContent = (typedContent == null) ? new String[content.length] : typedContent;
-    				typedContent[i] = value;
-    				break;
-    			default:
-    				// unsupported type
-    				return null;
+	    			case AttributeDefinition.BOOLEAN:
+	    				typedContent = (typedContent == null) ? new Boolean[content.length] : typedContent;
+	    				typedContent[i] = Boolean.valueOf(value);	
+	    				break;
+	    			case AttributeDefinition.BYTE:
+	    				typedContent = (typedContent == null) ? new Byte[content.length] : typedContent;
+	    				typedContent[i] = Byte.valueOf(value);
+	    				break;
+	    			case AttributeDefinition.CHARACTER:
+	    				typedContent = (typedContent == null) ? new Character[content.length] : typedContent;
+	    				char[] charArray = value.toCharArray();
+	    				if (charArray.length == 1) {
+	    					typedContent[i] = new Character(charArray[0]);
+	    				}
+	    				else {
+	    					return null;
+	    				}
+	    				break;
+	    			case AttributeDefinition.DOUBLE:
+	    				typedContent = (typedContent == null) ? new Double[content.length] : typedContent;
+	    				typedContent[i] = Double.valueOf(value);
+	    				break;
+	    			case AttributeDefinition.FLOAT:
+	    				typedContent = (typedContent == null) ? new Float[content.length] : typedContent;
+	    				typedContent[i] = Float.valueOf(value);
+	    				break;
+	    			case AttributeDefinition.INTEGER:
+	    				typedContent = (typedContent == null) ? new Integer[content.length] : typedContent;
+	    				typedContent[i] = Integer.valueOf(value);
+	    				break;
+	    			case AttributeDefinition.LONG:
+	    				typedContent = (typedContent == null) ? new Long[content.length] : typedContent;
+	    				typedContent[i] = Long.valueOf(value);
+	    				break;
+	    			case AttributeDefinition.SHORT:
+	    				typedContent = (typedContent == null) ? new Short[content.length] : typedContent;
+	    				typedContent[i] = Short.valueOf(value);
+	    				break;
+	    			case AttributeDefinition.STRING:
+	    				typedContent = (typedContent == null) ? new String[content.length] : typedContent;
+	    				typedContent[i] = value;
+	    				break;
+	    			default:
+	    				// unsupported type
+	    				return null;
     			}
     		}
     	}
@@ -596,14 +606,8 @@ public class AutoConfResourceProcessor i
     }
 
     public void handleEvent(Event event) {
-        Boolean result = (Boolean) event.getProperty(Constants.EVENTPROPERTY_SUCCESSFUL);
-        // check if successful
-        if (result.booleanValue()) {
-            postcommit();
-        }
-        else {
-            postcommit();
-        }
+    	// regardless of the outcome, we simply invoke postcommit
+    	postcommit();
     }
 }
 

Modified: felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java?rev=1542239&r1=1542238&r2=1542239&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java (original)
+++ felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java Fri Nov 15 12:01:17 2013
@@ -56,11 +56,10 @@ public class AutoConfResourceProcessorTe
     public void testSimpleSession() throws Exception {
         AutoConfResourceProcessor p = new AutoConfResourceProcessor();
         Utils.configureObject(p, LogService.class);
-        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
-            public DependencyManager getDependencyManager() {
-                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
-            }
-        }));
+        Utils.configureObject(p, DependencyManager.class, new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class)) {
+        	public void remove(Component service) {
+        	}
+        });
         File tempDir = File.createTempFile("persistence", "dir");
         tempDir.delete();
         tempDir.mkdirs();
@@ -70,6 +69,11 @@ public class AutoConfResourceProcessorTe
         Utils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
         Session s = new Session();
         p.begin(s);
+        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
+            public DependencyManager getDependencyManager() {
+                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
+            }
+        }));
         p.process("a", new ByteArrayInputStream("<MetaData />".getBytes()));
         p.process("b", new ByteArrayInputStream("<MetaData />".getBytes()));
         p.prepare();
@@ -82,11 +86,10 @@ public class AutoConfResourceProcessorTe
     public void testSimpleInstallAndUninstallSession() throws Throwable {
         AutoConfResourceProcessor p = new AutoConfResourceProcessor();
         Utils.configureObject(p, LogService.class);
-        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
-            public DependencyManager getDependencyManager() {
-                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
-            }
-        }));
+        Utils.configureObject(p, DependencyManager.class, new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class)) {
+        	public void remove(Component service) {
+        	}
+        });
         Logger logger = new Logger();
         Utils.configureObject(p, LogService.class, logger);
         File tempDir = File.createTempFile("persistence", "dir");
@@ -98,6 +101,11 @@ public class AutoConfResourceProcessorTe
         Utils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
         Session s = new Session();
         p.begin(s);
+        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
+            public DependencyManager getDependencyManager() {
+                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
+            }
+        }));
         p.process("a", new ByteArrayInputStream("<MetaData />".getBytes()));
         p.prepare();
         p.commit();
@@ -118,11 +126,10 @@ public class AutoConfResourceProcessorTe
         AutoConfResourceProcessor p = new AutoConfResourceProcessor();
         Logger logger = new Logger();
         Utils.configureObject(p, LogService.class, logger);
-        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
-            public DependencyManager getDependencyManager() {
-                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
-            }
-        }));
+        Utils.configureObject(p, DependencyManager.class, new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class)) {
+        	public void remove(Component service) {
+        	}
+        });
         File tempDir = File.createTempFile("persistence", "dir");
         tempDir.delete();
         tempDir.mkdirs();
@@ -132,6 +139,11 @@ public class AutoConfResourceProcessorTe
         Utils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
         Session s = new Session();
         p.begin(s);
+        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
+            public DependencyManager getDependencyManager() {
+                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
+            }
+        }));
         String config =
             "<MetaData xmlns:metatype='http://www.osgi.org/xmlns/metatype/v1.0.0'>\n" + 
             "  <OCD name='ocd' id='ocd'>\n" + 
@@ -179,12 +191,7 @@ public class AutoConfResourceProcessorTe
         AutoConfResourceProcessor p = new AutoConfResourceProcessor();
         Logger logger = new Logger();
         Utils.configureObject(p, LogService.class, logger);
-        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
-            public DependencyManager getDependencyManager() {
-                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
-            }
-        }));
-        Utils.configureObject(p, BundleContext.class, Utils.createMockObjectAdapter(BundleContext.class, new Object() {
+        BundleContext mockBC = (BundleContext) Utils.createMockObjectAdapter(BundleContext.class, new Object() {
             public Filter createFilter(String condition) {
                 return (Filter) Utils.createMockObjectAdapter(Filter.class, new Object() {
                     public boolean match(ServiceReference ref) {
@@ -194,9 +201,16 @@ public class AutoConfResourceProcessorTe
                         }
                         return false;
                     }
+                    public void remove(Component service) {
+                    }
                 });
             }
-        }));
+        });
+		Utils.configureObject(p, BundleContext.class, mockBC);
+        Utils.configureObject(p, DependencyManager.class, new DependencyManager(mockBC) {
+        	public void remove(Component service) {
+        	}
+        });
         File tempDir = File.createTempFile("persistence", "dir");
         tempDir.delete();
         tempDir.mkdirs();
@@ -206,6 +220,11 @@ public class AutoConfResourceProcessorTe
         Utils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
         Session s = new Session();
         p.begin(s);
+        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
+            public DependencyManager getDependencyManager() {
+                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
+            }
+        }));
         String config =
             "<MetaData xmlns:metatype='http://www.osgi.org/xmlns/metatype/v1.0.0' filter='(id=42)'>\n" + 
             "  <OCD name='ocd' id='ocd'>\n" + 

Modified: felix/trunk/deploymentadmin/deploymentadmin/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/pom.xml?rev=1542239&r1=1542238&r2=1542239&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/pom.xml (original)
+++ felix/trunk/deploymentadmin/deploymentadmin/pom.xml Fri Nov 15 12:01:17 2013
@@ -71,6 +71,7 @@
                 <extensions>true</extensions>
                 <configuration>
                     <instructions>
+                        <MyCustomHeader>(someKey=someValue)</MyCustomHeader>
                         <Bundle-SymbolicName>org.apache.felix.deploymentadmin</Bundle-SymbolicName>
                         <Bundle-Activator>org.apache.felix.deploymentadmin.Activator</Bundle-Activator>
                         <Bundle-Name>Apache Felix Deployment Admin</Bundle-Name>