FELIX-593 Only set immediate attribute if explicitly declared (to not implement
complicated default value evaluation which is done anyways in the Declarative
Services implementation) and check that immediate is not true if the factory
attribute is set.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@662692 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
index b7cae5c..1f2a156 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
@@ -345,7 +345,13 @@
 
         component.setEnabled(Boolean.valueOf(getBoolean(tag, Constants.COMPONENT_ENABLED, true)));
         component.setFactory(tag.getNamedParameter(Constants.COMPONENT_FACTORY));
-        component.setImmediate(Boolean.valueOf(getBoolean(tag, Constants.COMPONENT_IMMEDIATE, true)));
+        
+        // FELIX-593: immediate attribute does not default to true all the
+        // times hence we only set it if declared in the tag
+        if (tag.getNamedParameter(Constants.COMPONENT_IMMEDIATE) != null) {
+            component.setImmediate(Boolean.valueOf(getBoolean(tag,
+                Constants.COMPONENT_IMMEDIATE, true)));
+        }
 
         // whether metatype information is to generated for the component
         final String metaType = tag.getNamedParameter(Constants.COMPONENT_METATYPE);
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
index 122f162..93e46a9 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
@@ -249,6 +249,11 @@
                     if (isServiceFactory && this.isImmediate() != null && this.isImmediate().booleanValue() && this.getFactory() != null) {
                         issues.add(this.getMessage("Component must not be a ServiceFactory, if immediate and/or component factory: " + javaClass.getName()));
                     }
+                    
+                    // immediate must not be true for component factory
+                    if (this.isImmediate() != null && this.isImmediate().booleanValue() && this.getFactory() != null) {
+                        issues.add(this.getMessage("Component must not be immediate if component factory: " + javaClass.getName()));
+                    }
 
                     // verify references
                     for (Iterator ri = this.getReferences().iterator(); ri.hasNext();) {