Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 67EA5CDF8 for ; Mon, 11 Jun 2012 15:51:41 +0000 (UTC) Received: (qmail 55138 invoked by uid 500); 11 Jun 2012 15:51:41 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 55110 invoked by uid 500); 11 Jun 2012 15:51:41 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 55103 invoked by uid 99); 11 Jun 2012 15:51:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Jun 2012 15:51:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Jun 2012 15:51:38 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 63F6F2388860 for ; Mon, 11 Jun 2012 15:51:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1348918 - in /felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin: SCRDescriptorGenerator.java xml/ComponentDescriptorIO.java Date: Mon, 11 Jun 2012 15:51:17 -0000 To: commits@felix.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120611155117.63F6F2388860@eris.apache.org> Author: cziegeler Date: Mon Jun 11 15:51:16 2012 New Revision: 1348918 URL: http://svn.apache.org/viewvc?rev=1348918&view=rev Log: New SCR Plugin (WiP) Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java?rev=1348918&r1=1348917&r2=1348918&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java (original) +++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java Mon Jun 11 15:51:16 2012 @@ -37,6 +37,7 @@ import java.util.jar.Manifest; import org.apache.felix.scrplugin.description.ClassDescription; import org.apache.felix.scrplugin.description.ComponentDescription; import org.apache.felix.scrplugin.description.PropertyDescription; +import org.apache.felix.scrplugin.description.PropertyType; import org.apache.felix.scrplugin.description.ReferenceDescription; import org.apache.felix.scrplugin.description.ServiceDescription; import org.apache.felix.scrplugin.description.SpecVersion; @@ -439,6 +440,16 @@ public class SCRDescriptorGenerator { } } + private boolean hasProperty(final Component component, final String name) { + boolean found = false; + final Iterator iter = component.getProperties().iterator(); + while ( !found && iter.hasNext() ) { + final Property prop = iter.next(); + found = name.equals( prop.getName() ); + } + return found; + } + /** * Process property directives */ @@ -459,19 +470,36 @@ public class SCRDescriptorGenerator { } } // PID handling - if ( componentDesc.isCreatePid() ) { - // check for an existing pid first - boolean found = false; - final Iterator iter = component.getProperties().iterator(); - while ( !found && iter.hasNext() ) { - final Property prop = iter.next(); - found = org.osgi.framework.Constants.SERVICE_PID.equals( prop.getName() ); - } - if ( !found ) { - final Property pid = new Property(); - component.addProperty( pid ); - pid.setName( org.osgi.framework.Constants.SERVICE_PID ); - pid.setValue( component.getName() ); + if ( componentDesc.isCreatePid() && !hasProperty(component, org.osgi.framework.Constants.SERVICE_PID)) { + final Property pid = new Property(); + component.addProperty( pid ); + pid.setName( org.osgi.framework.Constants.SERVICE_PID ); + pid.setValue( component.getName() ); + } + this.processGlobalProperties(desc, component); + } + + /** + * Process all found properties for the component. + * @param globalProperties Global properties are set on all components. + * @param iLog The issue log. + * @throws SCRDescriptorException + */ + private void processGlobalProperties(final ClassDescription desc, final Component component) { + // apply pre configured global properties + if ( this.options.getProperties() != null ) { + for(final Map.Entry entry : this.options.getProperties().entrySet()) { + final String propName = entry.getKey(); + final String value = entry.getValue(); + // check if the service already provides this property + if ( value != null && !hasProperty(component, propName) ) { + + final Property p = new Property(); + p.setName(propName); + p.setValue(value); + p.setType(PropertyType.String); + component.addProperty(p); + } } } } Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java?rev=1348918&r1=1348917&r2=1348918&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java (original) +++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java Mon Jun 11 15:51:16 2012 @@ -215,7 +215,9 @@ public class ComponentDescriptorIO { // attributes new in 1.1 if (NAMESPACE_URI_1_1.equals(namespace) || NAMESPACE_URI_1_1_FELIX.equals(namespace)) { - IOUtils.addAttribute(ai, COMPONENT_ATTR_POLICY, component.getConfigurationPolicy().name()); + if ( component.getConfigurationPolicy() != ComponentConfigurationPolicy.OPTIONAL ) { + IOUtils.addAttribute(ai, COMPONENT_ATTR_POLICY, component.getConfigurationPolicy().name()); + } IOUtils.addAttribute(ai, COMPONENT_ATTR_ACTIVATE, component.getActivate()); IOUtils.addAttribute(ai, COMPONENT_ATTR_DEACTIVATE, component.getDeactivate()); IOUtils.addAttribute(ai, COMPONENT_ATTR_MODIFIED, component.getModified()); @@ -463,6 +465,7 @@ public class ComponentDescriptorIO { desc.setFactory(attributes.getValue(COMPONENT_ATTR_FACTORY)); + desc.setConfigurationPolicy(ComponentConfigurationPolicy.OPTIONAL); // check for version 1.1 attributes if (specVersion == SpecVersion.VERSION_1_1 || specVersion == SpecVersion.VERSION_1_1_FELIX) {