You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ds...@apache.org on 2009/07/28 18:29:57 UTC

svn commit: r798598 - in /felix/trunk/sigil/common/core/src/org/apache/felix/sigil: bnd/BundleBuilder.java config/BldConfig.java config/BldConverter.java config/BldProject.java config/IBldProject.java

Author: dsavage
Date: Tue Jul 28 16:29:57 2009
New Revision: 798598

URL: http://svn.apache.org/viewvc?rev=798598&view=rev
Log:
* Allow sigil.properties files to specify -singleton=true to cause bundles created by this project to be marked as singletons FELIX-1351
* Tidy up large methods into sub methods for readability


Modified:
    felix/trunk/sigil/common/core/src/org/apache/felix/sigil/bnd/BundleBuilder.java
    felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldConfig.java
    felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldConverter.java
    felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java
    felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/IBldProject.java

Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/bnd/BundleBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/bnd/BundleBuilder.java?rev=798598&r1=798597&r2=798598&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/bnd/BundleBuilder.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/bnd/BundleBuilder.java Tue Jul 28 16:29:57 2009
@@ -453,7 +453,9 @@
         // instructions we generate?
         spec.putAll( headers );
 
-        spec.setProperty( Constants.BUNDLE_SYMBOLICNAME, bundle.getSymbolicName() );
+        String sn = bundle.isSingleton() ? bundle.getSymbolicName() + ";singleton:=true" : bundle.getSymbolicName();
+        
+        spec.setProperty( Constants.BUNDLE_SYMBOLICNAME, sn );
         spec.setProperty( Constants.BUNDLE_VERSION, bundle.getVersion() );
 
         String activator = bundle.getActivator();
@@ -733,13 +735,50 @@
             omitUnusedImports = false;
         }
 
-        List<IPackageImport> imports = getImports( bundle );
-
         sb.setLength( 0 );
 
         // allow existing header;Package-Import to specify ignored packages
         sb.append( spec.getProperty( Constants.IMPORT_PACKAGE, "" ) );
 
+        buildImports(sb, getImports( bundle ));
+        
+        if ( sb.length() > 0 )
+        {
+            spec.setProperty( Constants.IMPORT_PACKAGE, sb.toString() );
+        }
+
+        sb.setLength( 0 );
+        
+        buildRequires(sb, bundle.getRequires());
+
+        if ( sb.length() > 0 )
+        {
+            spec.setProperty( Constants.REQUIRE_BUNDLE, sb.toString() );
+        }
+    }
+
+
+    /**
+     * @param sb
+     * @param list 
+     */
+    private void buildRequires( StringBuilder sb, List<IRequiredBundle> requires )
+    {
+        for ( IRequiredBundle rb : requires )
+        {
+            if ( sb.length() > 0 )
+                sb.append( "," );
+            sb.append( rb.getSymbolicName() );
+            addVersions( rb.getVersions(), sb );
+        }
+    }
+
+
+    /**
+     * @param sb
+     */
+    private void buildImports( StringBuilder sb, List<IPackageImport> imports )
+    {
         for ( IPackageImport pi : imports )
         {
             switch ( pi.getOSGiImport() )
@@ -789,22 +828,6 @@
                 sb.append( "," );
             sb.append( "*" );
         }
-
-        spec.setProperty( Constants.IMPORT_PACKAGE, sb.toString() );
-
-        sb.setLength( 0 );
-        for ( IRequiredBundle rb : bundle.getRequires() )
-        {
-            if ( sb.length() > 0 )
-                sb.append( "," );
-            sb.append( rb.getSymbolicName() );
-            addVersions( rb.getVersions(), sb );
-        }
-
-        if ( sb.length() > 0 )
-        {
-            spec.setProperty( Constants.REQUIRE_BUNDLE, sb.toString() );
-        }
     }
 
 

Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldConfig.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldConfig.java?rev=798598&r1=798597&r2=798598&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldConfig.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldConfig.java Tue Jul 28 16:29:57 2009
@@ -43,11 +43,12 @@
     // string properties
     public static final String S_ACTIVATOR = "-activator";
     public static final String S_DEFAULTS = "-defaults";
+    public static final String S_SINGLETON = "-singleton";
     public static final String S_ID = "id";
     public static final String S_SYM_NAME = "name";
     public static final String S_VERSION = "version";
     public static final String[] STRING_KEYS =
-        { S_ACTIVATOR, S_DEFAULTS, S_ID, S_SYM_NAME, S_VERSION };
+        { S_ACTIVATOR, S_DEFAULTS, S_ID, S_SYM_NAME, S_VERSION, S_SINGLETON };
 
     // list properties
     public static final String L_COMPOSITES = "-composites";

Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldConverter.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldConverter.java?rev=798598&r1=798597&r2=798598&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldConverter.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldConverter.java Tue Jul 28 16:29:57 2009
@@ -36,7 +36,6 @@
 import org.apache.felix.sigil.core.internal.model.eclipse.SigilBundle;
 import org.apache.felix.sigil.core.internal.model.osgi.BundleModelElement;
 import org.apache.felix.sigil.model.common.VersionRange;
-import org.apache.felix.sigil.model.eclipse.ISCAComposite;
 import org.apache.felix.sigil.model.eclipse.ISigilBundle;
 import org.apache.felix.sigil.model.osgi.IBundleModelElement;
 import org.apache.felix.sigil.model.osgi.IPackageExport;
@@ -272,136 +271,97 @@
     {
         IBundleModelElement info = bundle.getBundleInfo();
         String bundleVersion = config.getString( id, BldConfig.S_VERSION );
-
-        // exports
         Map<String, Map<String, String>> exports = new TreeMap<String, Map<String, String>>();
-        for ( IPackageExport export : info.getExports() )
-        {
-            Map<String, String> map2 = new TreeMap<String, String>();
-            String version = export.getVersion().toString();
-            if ( !version.equals( bundleVersion ) )
-                map2.put( BldAttr.VERSION_ATTRIBUTE, version );
-            exports.put( export.getPackageName(), map2 );
-        }
+        
+        setSimpleHeaders(id, info);
+        setExports(id, bundleVersion, info, exports);
+        setImports(id, bundleVersion, info, exports);
+        setRequires(id, bundleVersion, info);
+        setFragments(id, info);
+        setContents(id, info, bundle);
+        setLibraries(id, info, bundle);
+        setResources(id, info, bundle);
 
-        if ( !exports.isEmpty() || !config.getMap( id, BldConfig.M_EXPORTS ).isEmpty() )
+        if ( info.getSourceLocation() != null )
         {
-            config.setMap( id, BldConfig.M_EXPORTS, exports );
+            BldCore.error( "SourceLocation conversion not yet implemented." );
         }
 
-        // imports
-        Map<String, Map<String, String>> imports = new TreeMap<String, Map<String, String>>();
-
-        // FIXME: default version logic is wrong here
-        //    if the version to be saved is the same as the default version,
-        //    then we should _remove_ the version from the value being saved,
-        //    since config.getMap() does not apply default versions.
-        for ( IPackageImport import1 : info.getImports() )
+        if ( !info.getLibraryImports().isEmpty() )
         {
-            Map<String, String> map2 = new TreeMap<String, String>();
-            String name = import1.getPackageName();
-            VersionRange versions = defaultVersion( import1.getVersions(), getDefaultPackageVersion( name ) );
+            BldCore.error( "LibraryImports conversion not yet implemented." );
+        }
+    }
 
-            boolean isDependency = import1.isDependency();
-            Map<String, String> selfImport = exports.get( name );
 
-            if ( selfImport != null )
-            {
-                // avoid saving self-import attributes, e.g.
-                // org.cauldron.newton.example.fractal.engine;resolve=auto;version=1.0.0
-                isDependency = true;
+    /**
+     * @param id
+     * @param info
+     */
+    private void setSimpleHeaders( String id, IBundleModelElement info )
+    {
+        List<String> ids = config.getList( null, BldConfig.C_BUNDLES );
+        String idBsn = id != null ? id : ids.get( 0 );
+        String oldBsn = config.getString( id, BldConfig.S_SYM_NAME );
+        String bsn = info.getSymbolicName();
 
-                if ( versions != null )
-                {
-                    String exportVersion = selfImport.get( BldAttr.VERSION_ATTRIBUTE );
-                    if ( exportVersion == null )
-                        exportVersion = bundleVersion;
+        if ( !bsn.equals( idBsn ) || oldBsn != null )
+            config.setString( id, BldConfig.S_SYM_NAME, bsn );
 
-                    if ( exportVersion.equals( versions.toString() ) )
-                    {
-                        versions = null;
-                    }
-                }
-            }
+        String version = info.getVersion().toString();
+        if ( version != null )
+            config.setString( id, BldConfig.S_VERSION, version );
 
-            if ( versions != null )
-            {
-                map2.put( BldAttr.VERSION_ATTRIBUTE, versions.toString() );
-            }
+        String activator = info.getActivator();
+        if ( activator != null )
+            config.setString( id, BldConfig.S_ACTIVATOR, activator );
 
-            if ( import1.isOptional() )
-            {
-                map2.put( BldAttr.RESOLUTION_ATTRIBUTE, BldAttr.RESOLUTION_OPTIONAL );
-            }
+        Properties headers = config.getProps( null, BldConfig.P_HEADER );
 
-            String resolve = BldProject.getResolve( import1, isDependency );
-            if ( resolve != null )
-                map2.put( BldAttr.RESOLVE_ATTRIBUTE, resolve );
+        setHeader( headers, id, "CATEGORY", info.getCategory() );
+        setHeader( headers, id, Constants.BUNDLE_CONTACTADDRESS, info.getContactAddress() );
+        setHeader( headers, id, Constants.BUNDLE_COPYRIGHT, info.getCopyright() );
+        setHeader( headers, id, Constants.BUNDLE_DESCRIPTION, info.getDescription() );
+        setHeader( headers, id, Constants.BUNDLE_VENDOR, info.getVendor() );
+        setHeader( headers, id, Constants.BUNDLE_NAME, info.getName() );
 
-            imports.put( name, map2 );
-        }
-        if ( !imports.isEmpty() || !config.getMap( id, BldConfig.M_IMPORTS ).isEmpty() )
-        {
-            config.setMap( id, BldConfig.M_IMPORTS, imports );
-        }
+        if ( info.getDocURI() != null )
+            config.setProp( id, BldConfig.P_HEADER, Constants.BUNDLE_DOCURL, info.getDocURI().toString() );
 
-        // requires
-        Properties defaultBundles = config.getProps( null, BldConfig.P_BUNDLE_VERSION );
-        Map<String, Map<String, String>> requires = new TreeMap<String, Map<String, String>>();
+        if ( info.getLicenseURI() != null )
+            config.setProp( id, BldConfig.P_HEADER, Constants.BUNDLE_LICENSE, info.getLicenseURI().toString() );
+    }
 
-        for ( IRequiredBundle require : info.getRequiredBundles() )
-        {
-            Map<String, String> map2 = new TreeMap<String, String>();
-            String name = require.getSymbolicName();
-            VersionRange versions = defaultVersion( require.getVersions(), defaultBundles.getProperty( name ) );
-            if ( versions != null )
-                map2.put( BldAttr.VERSION_ATTRIBUTE, versions.toString() );
-            requires.put( name, map2 );
-        }
-        if ( !requires.isEmpty() || !config.getMap( id, BldConfig.M_REQUIRES ).isEmpty() )
-        {
-            config.setMap( id, BldConfig.M_REQUIRES, requires );
-        }
 
-        // fragment
-        Map<String, Map<String, String>> fragments = new TreeMap<String, Map<String, String>>();
-        IRequiredBundle fragment = info.getFragmentHost();
-        if ( fragment != null )
-        {
-            Map<String, String> map2 = new TreeMap<String, String>();
-            String name = fragment.getSymbolicName();
-            VersionRange versions = defaultVersion( fragment.getVersions(), defaultBundles.getProperty( name ) );
-            if ( versions != null )
-                map2.put( BldAttr.VERSION_ATTRIBUTE, versions.toString() );
-            fragments.put( name, map2 );
-        }
-        if ( !fragments.isEmpty() || !config.getMap( id, BldConfig.M_FRAGMENT ).isEmpty() )
+    /**
+     * @param id
+     * @param info
+     * @param bundle 
+     */
+    private void setResources( String id, IBundleModelElement info, ISigilBundle bundle )
+    {
+        // resources
+        ArrayList<String> resources = new ArrayList<String>();
+        for ( IPath ipath : bundle.getSourcePaths() )
         {
-            config.setMap( id, BldConfig.M_FRAGMENT, fragments );
+            resources.add( ipath.toString() );
         }
 
-        // contents
-        List<String> contents = new ArrayList<String>();
-        for ( String pkg : bundle.getPackages() )
-        {
-            contents.add( pkg );
-        }
-        if ( !contents.isEmpty() || !config.getList( id, BldConfig.L_CONTENTS ).isEmpty() )
+        if ( !resources.isEmpty() || !config.getList( id, BldConfig.L_RESOURCES ).isEmpty() )
         {
-            config.setList( id, BldConfig.L_CONTENTS, contents );
+            Collections.sort( resources );
+            config.setList( id, BldConfig.L_RESOURCES, resources );
         }
+    }
 
-        // dl contents
-        List<String> dlcontents = new ArrayList<String>();
-        for ( String pkg : bundle.getDownloadPackages() )
-        {
-            dlcontents.add( pkg );
-        }
-        if ( !dlcontents.isEmpty() || !config.getList( id, BldConfig.L_DL_CONTENTS ).isEmpty() )
-        {
-            config.setList( id, BldConfig.L_DL_CONTENTS, dlcontents );
-        }
 
+    /**
+     * @param id 
+     * @param info
+     * @param bundle 
+     */
+    private void setLibraries( String id, IBundleModelElement info, ISigilBundle bundle )
+    {
         // libs
         Map<String, Map<String, String>> libs = new TreeMap<String, Map<String, String>>();
         List<String> sources = new ArrayList<String>();
@@ -449,77 +409,168 @@
             config.setList( id, BldConfig.L_SRC_CONTENTS, sources );
         }
 
-        // composites
-        ArrayList<String> composites = new ArrayList<String>();
-        for ( ISCAComposite composite : bundle.getComposites() )
+    }
+
+
+    /**
+     * @param id 
+     * @param info
+     * @param bundle 
+     */
+    private void setContents( String id, IBundleModelElement info, ISigilBundle bundle )
+    {
+        // contents
+        List<String> contents = new ArrayList<String>();
+        for ( String pkg : bundle.getPackages() )
         {
-            String path = composite.getLocation().toString();
-            // TODO relativize
-            composites.add( path );
+            contents.add( pkg );
         }
-
-        if ( !composites.isEmpty() || !config.getList( id, BldConfig.L_COMPOSITES ).isEmpty() )
+        if ( !contents.isEmpty() || !config.getList( id, BldConfig.L_CONTENTS ).isEmpty() )
         {
-            Collections.sort( composites );
-            config.setList( id, BldConfig.L_COMPOSITES, composites );
+            config.setList( id, BldConfig.L_CONTENTS, contents );
         }
+    }
 
-        // resources
-        ArrayList<String> resources = new ArrayList<String>();
-        for ( IPath ipath : bundle.getSourcePaths() )
+
+    /**
+     * @param id
+     * @param info
+     */
+    private void setFragments( String id, IBundleModelElement info )
+    {
+        Properties defaultBundles = config.getProps( null, BldConfig.P_BUNDLE_VERSION );
+        Map<String, Map<String, String>> fragments = new TreeMap<String, Map<String, String>>();
+        IRequiredBundle fragment = info.getFragmentHost();
+        if ( fragment != null )
         {
-            resources.add( ipath.toString() );
+            Map<String, String> map2 = new TreeMap<String, String>();
+            String name = fragment.getSymbolicName();
+            VersionRange versions = defaultVersion( fragment.getVersions(), defaultBundles.getProperty( name ) );
+            if ( versions != null )
+                map2.put( BldAttr.VERSION_ATTRIBUTE, versions.toString() );
+            fragments.put( name, map2 );
         }
-
-        if ( !resources.isEmpty() || !config.getList( id, BldConfig.L_RESOURCES ).isEmpty() )
+        if ( !fragments.isEmpty() || !config.getMap( id, BldConfig.M_FRAGMENT ).isEmpty() )
         {
-            Collections.sort( resources );
-            config.setList( id, BldConfig.L_RESOURCES, resources );
+            config.setMap( id, BldConfig.M_FRAGMENT, fragments );
         }
+    }
 
-        if ( info.getSourceLocation() != null )
+
+    /**
+     * @param id
+     * @param bundleVersion
+     * @param info
+     */
+    private void setRequires( String id, String bundleVersion, IBundleModelElement info )
+    {
+        // requires
+        Properties defaultBundles = config.getProps( null, BldConfig.P_BUNDLE_VERSION );
+        Map<String, Map<String, String>> requires = new TreeMap<String, Map<String, String>>();
+
+        for ( IRequiredBundle require : info.getRequiredBundles() )
         {
-            BldCore.error( "SourceLocation conversion not yet implemented." );
+            Map<String, String> map2 = new TreeMap<String, String>();
+            String name = require.getSymbolicName();
+            VersionRange versions = defaultVersion( require.getVersions(), defaultBundles.getProperty( name ) );
+            if ( versions != null )
+                map2.put( BldAttr.VERSION_ATTRIBUTE, versions.toString() );
+            requires.put( name, map2 );
         }
-
-        if ( !info.getLibraryImports().isEmpty() )
+        if ( !requires.isEmpty() || !config.getMap( id, BldConfig.M_REQUIRES ).isEmpty() )
         {
-            BldCore.error( "LibraryImports conversion not yet implemented." );
+            config.setMap( id, BldConfig.M_REQUIRES, requires );
         }
+    }
 
-        ////////////////////
-        // simple headers
 
-        List<String> ids = config.getList( null, BldConfig.C_BUNDLES );
-        String idBsn = id != null ? id : ids.get( 0 );
-        String oldBsn = config.getString( id, BldConfig.S_SYM_NAME );
-        String bsn = info.getSymbolicName();
+    /**
+     * @param bundleVersion 
+     * @param info
+     * @param exports 
+     */
+    private void setImports( String id, String bundleVersion, IBundleModelElement info, Map<String, Map<String, String>> exports )
+    {
+        // imports
+        Map<String, Map<String, String>> imports = new TreeMap<String, Map<String, String>>();
 
-        if ( !bsn.equals( idBsn ) || oldBsn != null )
-            config.setString( id, BldConfig.S_SYM_NAME, bsn );
+        // FIXME: default version logic is wrong here
+        //    if the version to be saved is the same as the default version,
+        //    then we should _remove_ the version from the value being saved,
+        //    since config.getMap() does not apply default versions.
+        for ( IPackageImport import1 : info.getImports() )
+        {
+            Map<String, String> map2 = new TreeMap<String, String>();
+            String name = import1.getPackageName();
+            VersionRange versions = defaultVersion( import1.getVersions(), getDefaultPackageVersion( name ) );
 
-        String version = info.getVersion().toString();
-        if ( version != null )
-            config.setString( id, BldConfig.S_VERSION, version );
+            boolean isDependency = import1.isDependency();
+            Map<String, String> selfImport = exports.get( name );
 
-        String activator = info.getActivator();
-        if ( activator != null )
-            config.setString( id, BldConfig.S_ACTIVATOR, activator );
+            if ( selfImport != null )
+            {
+                // avoid saving self-import attributes, e.g.
+                // org.cauldron.newton.example.fractal.engine;resolve=auto;version=1.0.0
+                isDependency = true;
 
-        Properties headers = config.getProps( null, BldConfig.P_HEADER );
+                if ( versions != null )
+                {
+                    String exportVersion = selfImport.get( BldAttr.VERSION_ATTRIBUTE );
+                    if ( exportVersion == null )
+                        exportVersion = bundleVersion;
 
-        setHeader( headers, id, "CATEGORY", info.getCategory() );
-        setHeader( headers, id, Constants.BUNDLE_CONTACTADDRESS, info.getContactAddress() );
-        setHeader( headers, id, Constants.BUNDLE_COPYRIGHT, info.getCopyright() );
-        setHeader( headers, id, Constants.BUNDLE_DESCRIPTION, info.getDescription() );
-        setHeader( headers, id, Constants.BUNDLE_VENDOR, info.getVendor() );
-        setHeader( headers, id, Constants.BUNDLE_NAME, info.getName() );
+                    if ( exportVersion.equals( versions.toString() ) )
+                    {
+                        versions = null;
+                    }
+                }
+            }
 
-        if ( info.getDocURI() != null )
-            config.setProp( id, BldConfig.P_HEADER, Constants.BUNDLE_DOCURL, info.getDocURI().toString() );
+            if ( versions != null )
+            {
+                map2.put( BldAttr.VERSION_ATTRIBUTE, versions.toString() );
+            }
 
-        if ( info.getLicenseURI() != null )
-            config.setProp( id, BldConfig.P_HEADER, Constants.BUNDLE_LICENSE, info.getLicenseURI().toString() );
+            if ( import1.isOptional() )
+            {
+                map2.put( BldAttr.RESOLUTION_ATTRIBUTE, BldAttr.RESOLUTION_OPTIONAL );
+            }
+
+            String resolve = BldProject.getResolve( import1, isDependency );
+            if ( resolve != null )
+                map2.put( BldAttr.RESOLVE_ATTRIBUTE, resolve );
+
+            imports.put( name, map2 );
+        }
+        if ( !imports.isEmpty() || !config.getMap( id, BldConfig.M_IMPORTS ).isEmpty() )
+        {
+            config.setMap( id, BldConfig.M_IMPORTS, imports );
+        }
+    }
+
+
+    /**
+     * @param id 
+     * @param info 
+     * @param bundleVersion 
+     * @param exports 
+     * 
+     */
+    private void setExports(String id, String bundleVersion, IBundleModelElement info, Map<String, Map<String, String>> exports)
+    {
+        for ( IPackageExport export : info.getExports() )
+        {
+            Map<String, String> map2 = new TreeMap<String, String>();
+            String version = export.getVersion().toString();
+            if ( !version.equals( bundleVersion ) )
+                map2.put( BldAttr.VERSION_ATTRIBUTE, version );
+            exports.put( export.getPackageName(), map2 );
+        }
+
+        if ( !exports.isEmpty() || !config.getMap( id, BldConfig.M_EXPORTS ).isEmpty() )
+        {
+            config.setMap( id, BldConfig.M_EXPORTS, exports );
+        }
     }
 
 

Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java?rev=798598&r1=798597&r2=798598&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java Tue Jul 28 16:29:57 2009
@@ -42,7 +42,6 @@
 import java.util.Properties;
 import java.util.TreeSet;
 
-import org.apache.felix.sigil.bnd.BundleBuilder;
 import org.apache.felix.sigil.core.internal.model.osgi.BundleModelElement;
 import org.apache.felix.sigil.core.internal.model.osgi.PackageExport;
 import org.apache.felix.sigil.core.internal.model.osgi.PackageImport;
@@ -53,8 +52,8 @@
 import org.apache.felix.sigil.model.osgi.IBundleModelElement;
 import org.apache.felix.sigil.model.osgi.IPackageExport;
 import org.apache.felix.sigil.model.osgi.IPackageImport;
-import org.apache.felix.sigil.model.osgi.IRequiredBundle;
 import org.apache.felix.sigil.model.osgi.IPackageImport.OSGiImport;
+import org.apache.felix.sigil.model.osgi.IRequiredBundle;
 import org.osgi.framework.Version;
 
 
@@ -182,6 +181,7 @@
                 }
 
                 Properties p = new Properties();
+                // FIXME stream not closed
                 p.load( url.openStream() );
                 dflt.merge( p );
 
@@ -430,6 +430,22 @@
         List<String> sourceContents = getSourcePkgs();
         HashSet<String> exports = new HashSet<String>();
 
+        parseExports(reqs, exports);
+        
+        parseImports(reqs, sourceContents, exports);
+        
+        parseRequires(reqs);
+        
+        return reqs;
+    }
+
+
+    /**
+     * @param reqs
+     * @param exports
+     */
+    private void parseExports( BundleModelElement reqs, HashSet<String> exports )
+    {
         for ( IBldBundle bundle : getBundles() )
         {
             for ( IPackageExport export : bundle.getExports() )
@@ -437,7 +453,62 @@
                 exports.add( export.getPackageName() );
             }
         }
+    }
+
+
+    /**
+     * @param reqs
+     * @throws IOException 
+     */
+    private void parseRequires( BundleModelElement reqs ) throws IOException
+    {
+        Map<String, Map<String, String>> requires = config.getMap( null, BldConfig.M_REQUIRES );
+        Properties bundleDefaults = config.getProps( null, BldConfig.P_BUNDLE_VERSION );
+
+        if ( requires != null )
+        {
+            for ( String name : requires.keySet() )
+            {
+                Map<String, String> attr = requires.get( name );
+                String versions = attr.containsKey( BldAttr.VERSION_ATTRIBUTE ) ? attr.get( BldAttr.VERSION_ATTRIBUTE )
+                    : bundleDefaults.getProperty( name );
+                String resolution = attr.get( BldAttr.RESOLUTION_ATTRIBUTE );
+
+                RequiredBundle rb = new RequiredBundle();
+                rb.setSymbolicName( name );
+                rb.setVersions( VersionRange.parseVersionRange( versions ) );
+
+                if ( BldAttr.RESOLUTION_OPTIONAL.equals( resolution ) )
+                {
+                    rb.setOptional( true );
+                }
+                else if ( resolution != null )
+                {
+                    throw new IOException( "Bad attribute value: " + BldAttr.RESOLUTION_ATTRIBUTE + "=" + resolution );
+                }
+
+                reqs.addRequiredBundle( rb );
+            }
+        }
 
+        for ( IBldBundle bundle : getBundles() )
+        {
+            IRequiredBundle fh = bundle.getFragmentHost();
+            if ( fh != null )
+                reqs.addRequiredBundle( fh );
+        }
+    }
+
+
+    /**
+     * @param reqs 
+     * @param exports 
+     * @param sourceContents 
+     * @throws IOException 
+     * 
+     */
+    private void parseImports(BundleModelElement reqs, List<String> sourceContents, HashSet<String> exports) throws IOException
+    {
         Map<String, Map<String, String>> imports = config.getMap( null, BldConfig.M_IMPORTS );
 
         for ( String name : imports.keySet() )
@@ -482,34 +553,6 @@
 
             reqs.addImport( pi );
         }
-
-        Map<String, Map<String, String>> requires = config.getMap( null, BldConfig.M_REQUIRES );
-        Properties bundleDefaults = config.getProps( null, BldConfig.P_BUNDLE_VERSION );
-
-        if ( requires != null )
-        {
-            for ( String name : requires.keySet() )
-            {
-                Map<String, String> attr = requires.get( name );
-                String versions = attr.containsKey( BldAttr.VERSION_ATTRIBUTE ) ? attr.get( BldAttr.VERSION_ATTRIBUTE )
-                    : bundleDefaults.getProperty( name );
-
-                RequiredBundle rb = new RequiredBundle();
-                rb.setSymbolicName( name );
-                rb.setVersions( VersionRange.parseVersionRange( versions ) );
-
-                reqs.addRequiredBundle( rb );
-            }
-        }
-
-        for ( IBldBundle bundle : getBundles() )
-        {
-            IRequiredBundle fh = bundle.getFragmentHost();
-            if ( fh != null )
-                reqs.addRequiredBundle( fh );
-        }
-
-        return reqs;
     }
 
 
@@ -809,6 +852,12 @@
         }
 
 
+        private boolean getBoolean( String key )
+        {
+            return Boolean.parseBoolean( getString( key ) );
+        }
+
+
         private List<String> getList( String key )
         {
             List<String> list = config.getList( id, key );
@@ -854,6 +903,12 @@
         }
 
 
+        public boolean isSingleton()
+        {
+            return getBoolean( BldConfig.S_SINGLETON );
+        }
+
+
         public List<IPackageExport> getExports()
         {
             ArrayList<IPackageExport> list = new ArrayList<IPackageExport>();

Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/IBldProject.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/IBldProject.java?rev=798598&r1=798597&r2=798598&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/IBldProject.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/IBldProject.java Tue Jul 28 16:29:57 2009
@@ -233,5 +233,11 @@
          * resolves a relative path against the project file location.
          */
         File resolve( String path );
+
+
+        /**
+         * @return
+         */
+        boolean isSingleton();
     }
 }