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 2010/08/02 19:08:20 UTC

svn commit: r981604 [22/22] - in /felix/trunk/sigil: common/core.tests/src/org/apache/felix/sigil/common/core/ common/core.tests/src/org/apache/felix/sigil/common/core/internal/model/osgi/ common/core/src/org/apache/felix/sigil/common/bnd/ common/core/...

Modified: felix/trunk/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/SigilParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/SigilParser.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/SigilParser.java (original)
+++ felix/trunk/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/SigilParser.java Mon Aug  2 17:08:03 2010
@@ -19,7 +19,6 @@
 
 package org.apache.felix.sigil.ivy;
 
-
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -61,111 +60,102 @@ import org.apache.ivy.plugins.repository
 import org.apache.ivy.plugins.repository.url.URLResource;
 import org.apache.ivy.plugins.resolver.DependencyResolver;
 
-
 public class SigilParser implements ModuleDescriptorParser
 {
 
     private static DelegateParser instance;
 
-
     // used by ProjectRepository
     static synchronized DelegateParser instance()
     {
-        if ( instance == null )
-            throw new IllegalStateException( "SigilParser is not instantiated." );
-        
+        if (instance == null)
+            throw new IllegalStateException("SigilParser is not instantiated.");
+
         return instance;
     }
 
-
     public SigilParser()
     {
-        synchronized(SigilParser.class) {
-            if ( instance == null )
+        synchronized (SigilParser.class)
+        {
+            if (instance == null)
             {
                 instance = new DelegateParser();
             }
         }
     }
 
-
     /**
      * In IvyDE, IvyContext is not available, so we can't find the SigilResolver.
      * This allows us to construct one.
      * @deprecated temporary to support IvyDE
      */
-    public void setConfig( String config )
+    public void setConfig(String config)
     {
         instance.config = config;
     }
 
-
     /**
      * sets delegate parser.
      * If not set, we delegate to the default Ivy parser.
      * @param type name returned by desired parser's getType() method.
      */
-    public void setDelegateType( String type )
+    public void setDelegateType(String type)
     {
-        for ( ModuleDescriptorParser parser : ModuleDescriptorParserRegistry.getInstance().getParsers() )
+        for (ModuleDescriptorParser parser : ModuleDescriptorParserRegistry.getInstance().getParsers())
         {
-            if ( parser.getType().equals( type ) )
+            if (parser.getType().equals(type))
             {
                 instance.delegate = parser;
                 break;
             }
         }
 
-        if ( instance.delegate == null )
+        if (instance.delegate == null)
         {
-            throw new IllegalArgumentException( "Can't find parser delegateType=" + type );
+            throw new IllegalArgumentException("Can't find parser delegateType=" + type);
         }
     }
 
-
     /**
      * sets default file name the delegate parser accepts.
      * If not set, defaults to "ivy.xml".
      * @param name
      */
-    public void setDelegateFile( String name )
+    public void setDelegateFile(String name)
     {
         instance.ivyFile = name;
     }
 
-
     /**
      * sets the dependencies to keep from the delegate parser.
      * If not set, all existing dependencies are dropped.
      * @param regex pattern matching dependency names to keep.
      */
-    public void setKeepDependencies( String regex )
+    public void setKeepDependencies(String regex)
     {
-        instance.keepDependencyPattern = Pattern.compile( regex );
+        instance.keepDependencyPattern = Pattern.compile(regex);
     }
 
-
     /**
      * reduce level of info logging.
      * @param quiet
      */
-    public void setQuiet( String quiet )
+    public void setQuiet(String quiet)
     {
-        instance.quiet = Boolean.parseBoolean( quiet );
+        instance.quiet = Boolean.parseBoolean(quiet);
     }
 
-
     /**
      * sets the SigilResolver we use.
      * If not set, we use the first SigilResolver we find.
      * @param name
      */
-    public void setResolver( String name )
+    public void setResolver(String name)
     {
         instance.resolverName = name;
     }
 
-
     /**
      * adds override element: <override name="X" pattern="Y" replace="Z"/>. Overrides
      * Ivy variables using a pattern substitution on the resource directory path.
@@ -177,58 +167,53 @@ public class SigilParser implements Modu
      * the ivy:buildlist task won't work without this workaround.
      */
     // e.g. <override name="ant.project.name" pattern=".*/([^/]+)/([^/]+)$" replace="$1-$2"/>
-    public void addConfiguredOverride( Map<String, String> var )
+    public void addConfiguredOverride(Map<String, String> var)
     {
-        final String name = var.get( "name" );
-        final String regex = var.get( "pattern" );
-        final String replace = var.get( "replace" );
-
-        if ( name == null || regex == null || replace == null )
-            throw new IllegalArgumentException( "override must contain name, pattern and replace attributes." );
+        final String name = var.get("name");
+        final String regex = var.get("pattern");
+        final String replace = var.get("replace");
+
+        if (name == null || regex == null || replace == null)
+            throw new IllegalArgumentException(
+                "override must contain name, pattern and replace attributes.");
 
-        instance.varRegex.put( name, Pattern.compile( regex ) );
-        instance.varReplace.put( name, replace );
+        instance.varRegex.put(name, Pattern.compile(regex));
+        instance.varReplace.put(name, replace);
     }
 
-
     // implement ModuleDescriptorParser interface by delegation to singleton instance.
 
-    public boolean accept( Resource res )
+    public boolean accept(Resource res)
     {
-        return instance.accept( res );
+        return instance.accept(res);
     }
 
-
-    public Artifact getMetadataArtifact( ModuleRevisionId mrid, Resource res )
+    public Artifact getMetadataArtifact(ModuleRevisionId mrid, Resource res)
     {
-        return instance.getMetadataArtifact( mrid, res );
+        return instance.getMetadataArtifact(mrid, res);
     }
 
-
     public String getType()
     {
         return instance.getType();
     }
 
-
-    public ModuleDescriptor parseDescriptor( ParserSettings settings, URL xmlURL, boolean validate )
-        throws ParseException, IOException
+    public ModuleDescriptor parseDescriptor(ParserSettings settings, URL xmlURL,
+        boolean validate) throws ParseException, IOException
     {
-        return instance.parseDescriptor( settings, xmlURL, validate );
+        return instance.parseDescriptor(settings, xmlURL, validate);
     }
 
-
-    public ModuleDescriptor parseDescriptor( ParserSettings settings, URL xmlURL, Resource res, boolean validate )
-        throws ParseException, IOException
+    public ModuleDescriptor parseDescriptor(ParserSettings settings, URL xmlURL,
+        Resource res, boolean validate) throws ParseException, IOException
     {
-        return instance.parseDescriptor( settings, xmlURL, res, validate );
+        return instance.parseDescriptor(settings, xmlURL, res, validate);
     }
 
-
-    public void toIvyFile( InputStream source, Resource res, File destFile, ModuleDescriptor md )
-        throws ParseException, IOException
+    public void toIvyFile(InputStream source, Resource res, File destFile,
+        ModuleDescriptor md) throws ParseException, IOException
     {
-        instance.toIvyFile( source, res, destFile, md );
+        instance.toIvyFile(source, res, destFile, md);
     }
 
     /**
@@ -256,188 +241,187 @@ public class SigilParser implements Modu
         private boolean quiet;
         private String config;
 
-
         @Override
-        public boolean accept( Resource res )
+        public boolean accept(Resource res)
         {
-            boolean accept = ( res instanceof SigilResolver.SigilIvy )
-                || res.getName().endsWith( "/" + SIGIL_BUILDLIST )
-                || ( ( instance.getSigilURI( res ) != null ) && ( ( instance.delegate != null ? instance.delegate
-                    .accept( res ) : false ) || super.accept( res ) ) );
-            if ( accept )
-                Log.verbose( "accepted: " + res );
+            boolean accept = (res instanceof SigilResolver.SigilIvy)
+                || res.getName().endsWith("/" + SIGIL_BUILDLIST)
+                || ((instance.getSigilURI(res) != null) && ((instance.delegate != null ? instance.delegate.accept(res)
+                    : false) || super.accept(res)));
+            if (accept)
+                Log.verbose("accepted: " + res);
             return accept;
         }
 
-
         @Override
-        public void toIvyFile( InputStream source, Resource res, File destFile, ModuleDescriptor md )
-            throws ParseException, IOException
+        public void toIvyFile(InputStream source, Resource res, File destFile,
+            ModuleDescriptor md) throws ParseException, IOException
         {
-            Log.verbose( "writing resource: " + res + " toIvyFile: " + destFile );
+            Log.verbose("writing resource: " + res + " toIvyFile: " + destFile);
             // source allows us to keep layout and comments,
             // but this doesn't work if source is not ivy.xml.
             // So just write file directly from descriptor.
             try
             {
-                XmlModuleDescriptorWriter.write( md, destFile );
+                XmlModuleDescriptorWriter.write(md, destFile);
             }
             finally
             {
-                if ( source != null )
+                if (source != null)
                     source.close();
             }
         }
 
-
         @Override
-        public ModuleDescriptor parseDescriptor( ParserSettings settings, URL xmlURL, boolean validate )
-            throws ParseException, IOException
+        public ModuleDescriptor parseDescriptor(ParserSettings settings, URL xmlURL,
+            boolean validate) throws ParseException, IOException
         {
-            return parseDescriptor( settings, xmlURL, new URLResource( xmlURL ), validate );
+            return parseDescriptor(settings, xmlURL, new URLResource(xmlURL), validate);
         }
 
-
         @Override
-        public ModuleDescriptor parseDescriptor( ParserSettings settings, URL xmlURL, Resource res, boolean validate )
-            throws ParseException, IOException
+        public ModuleDescriptor parseDescriptor(ParserSettings settings, URL xmlURL,
+            Resource res, boolean validate) throws ParseException, IOException
         {
             String cacheKey = xmlURL.toString() + settings.hashCode();
-            DefaultModuleDescriptor dmd = augmentedCache.get( cacheKey );
+            DefaultModuleDescriptor dmd = augmentedCache.get(cacheKey);
 
-            if ( dmd == null )
+            if (dmd == null)
             {
-                dmd = rawCache.get( cacheKey );
-                if ( dmd == null )
+                dmd = rawCache.get(cacheKey);
+                if (dmd == null)
                 {
-                    dmd = delegateParse( settings, xmlURL, res, validate );
+                    dmd = delegateParse(settings, xmlURL, res, validate);
                 }
 
-                if ( !quiet )
-                    Log.info( "augmenting module=" + dmd.getModuleRevisionId().getName() + " ant.project.name="
-                        + settings.substitute( "${ant.project.name}" ) );
+                if (!quiet)
+                    Log.info("augmenting module=" + dmd.getModuleRevisionId().getName()
+                        + " ant.project.name="
+                        + settings.substitute("${ant.project.name}"));
 
-                addDependenciesToDescriptor( res, dmd );
-                augmentedCache.put( cacheKey, dmd );
+                addDependenciesToDescriptor(res, dmd);
+                augmentedCache.put(cacheKey, dmd);
 
-                Log.verbose( "augmented dependencies: " + Arrays.asList( dmd.getDependencies() ) );
+                Log.verbose("augmented dependencies: "
+                    + Arrays.asList(dmd.getDependencies()));
             }
 
             return dmd;
         }
 
-
         // used by ProjectRepository
-        ModuleDescriptor parseDescriptor( URL projectURL ) throws ParseException, IOException
+        ModuleDescriptor parseDescriptor(URL projectURL) throws ParseException,
+            IOException
         {
-            if ( defaultSettings == null )
+            if (defaultSettings == null)
             {
                 Ivy ivy = IvyContext.getContext().peekIvy();
-                if ( ivy == null )
-                    throw new IllegalStateException( "can't get default settings - no ivy context." );
+                if (ivy == null)
+                    throw new IllegalStateException(
+                        "can't get default settings - no ivy context.");
                 defaultSettings = ivy.getSettings();
             }
 
-            URL ivyURL = new URL( projectURL, ivyFile );
+            URL ivyURL = new URL(projectURL, ivyFile);
             String cacheKey = ivyURL.toString() + defaultSettings.hashCode();
-            DefaultModuleDescriptor dmd = rawCache.get( cacheKey );
+            DefaultModuleDescriptor dmd = rawCache.get(cacheKey);
 
-            if ( dmd == null )
+            if (dmd == null)
             {
-                URLResource res = new URLResource( ivyURL );
+                URLResource res = new URLResource(ivyURL);
                 // Note: this doesn't contain the augmented dependencies, which is OK,
                 // since the ProjectRepository only needs the id and status.
-                dmd = delegateParse( defaultSettings, ivyURL, res, false );
-                rawCache.put( cacheKey, dmd );
+                dmd = delegateParse(defaultSettings, ivyURL, res, false);
+                rawCache.put(cacheKey, dmd);
             }
 
             return dmd;
         }
 
-
-        private DefaultModuleDescriptor delegateParse( ParserSettings settings, URL xmlURL, Resource res,
-            boolean validate ) throws ParseException, IOException
+        private DefaultModuleDescriptor delegateParse(ParserSettings settings,
+            URL xmlURL, Resource res, boolean validate) throws ParseException,
+            IOException
         {
             String resName = res.getName();
 
-            if ( resName.endsWith( "/" + SIGIL_BUILDLIST ) )
+            if (resName.endsWith("/" + SIGIL_BUILDLIST))
             {
-                String name = resName.substring( 0, resName.length() - SIGIL_BUILDLIST.length() );
-                res = res.clone( name + ivyFile );
-                xmlURL = new URL( xmlURL, ivyFile );
+                String name = resName.substring(0, resName.length()
+                    - SIGIL_BUILDLIST.length());
+                res = res.clone(name + ivyFile);
+                xmlURL = new URL(xmlURL, ivyFile);
             }
 
-            if ( settings instanceof IvySettings )
+            if (settings instanceof IvySettings)
             {
-                IvySettings ivySettings = ( IvySettings ) settings;
-                String dir = new File( res.getName() ).getParent();
+                IvySettings ivySettings = (IvySettings) settings;
+                String dir = new File(res.getName()).getParent();
 
-                for ( String name : varRegex.keySet() )
+                for (String name : varRegex.keySet())
                 {
-                    Pattern regex = varRegex.get( name );
-                    String replace = varReplace.get( name );
+                    Pattern regex = varRegex.get(name);
+                    String replace = varReplace.get(name);
 
-                    String value = regex.matcher( dir ).replaceAll( replace );
+                    String value = regex.matcher(dir).replaceAll(replace);
 
-                    Log.debug( "overriding variable " + name + "=" + value );
-                    ivySettings.setVariable( name, value );
+                    Log.debug("overriding variable " + name + "=" + value);
+                    ivySettings.setVariable(name, value);
                 }
             }
 
             ModuleDescriptor md = null;
-            if ( delegate == null || !delegate.accept( res ) )
+            if (delegate == null || !delegate.accept(res))
             {
-                md = super.parseDescriptor( settings, xmlURL, res, validate );
+                md = super.parseDescriptor(settings, xmlURL, res, validate);
             }
             else
             {
-                md = delegate.parseDescriptor( settings, xmlURL, res, validate );
+                md = delegate.parseDescriptor(settings, xmlURL, res, validate);
             }
 
-            return mungeDescriptor( md, res );
+            return mungeDescriptor(md, res);
         }
 
-
         /**
          * clones descriptor and removes dependencies, as descriptor MUST have
          * 'this' as the parser given to its constructor.
          * Only dependency names matched by keepDependencyPattern are kept,
          * as we're going to add our own dependencies later.
          */
-        private DefaultModuleDescriptor mungeDescriptor( ModuleDescriptor md, Resource res )
+        private DefaultModuleDescriptor mungeDescriptor(ModuleDescriptor md, Resource res)
         {
 
-            if ( ( md instanceof DefaultModuleDescriptor ) && ( md.getParser() == this )
-                && ( KEEP_ALL.equals( keepDependencyPattern ) ) )
+            if ((md instanceof DefaultModuleDescriptor) && (md.getParser() == this)
+                && (KEEP_ALL.equals(keepDependencyPattern)))
             {
-                return ( DefaultModuleDescriptor ) md;
+                return (DefaultModuleDescriptor) md;
             }
 
-            DefaultModuleDescriptor dmd = new DefaultModuleDescriptor( this, res );
+            DefaultModuleDescriptor dmd = new DefaultModuleDescriptor(this, res);
 
-            dmd.setModuleRevisionId( md.getModuleRevisionId() );
-            dmd.setPublicationDate( md.getPublicationDate() );
+            dmd.setModuleRevisionId(md.getModuleRevisionId());
+            dmd.setPublicationDate(md.getPublicationDate());
 
-            for ( Configuration c : md.getConfigurations() )
+            for (Configuration c : md.getConfigurations())
             {
                 String conf = c.getName();
 
-                dmd.addConfiguration( c );
+                dmd.addConfiguration(c);
 
-                for ( Artifact a : md.getArtifacts( conf ) )
+                for (Artifact a : md.getArtifacts(conf))
                 {
-                    dmd.addArtifact( conf, a );
+                    dmd.addArtifact(conf, a);
                 }
             }
 
-            if ( keepDependencyPattern != null )
+            if (keepDependencyPattern != null)
             {
-                for ( DependencyDescriptor dependency : md.getDependencies() )
+                for (DependencyDescriptor dependency : md.getDependencies())
                 {
                     String name = dependency.getDependencyId().getName();
-                    if ( keepDependencyPattern.matcher( name ).matches() )
+                    if (keepDependencyPattern.matcher(name).matches())
                     {
-                        dmd.addDependency( dependency );
+                        dmd.addDependency(dependency);
                     }
                 }
             }
@@ -445,119 +429,123 @@ public class SigilParser implements Modu
             return dmd;
         }
 
-
         /*
          * find URI to Sigil project file. This assumes that it is in the same
          * directory as the ivy file.
          */
-        private URI getSigilURI( Resource res )
+        private URI getSigilURI(Resource res)
         {
             URI uri = null;
 
-            if ( res instanceof URLResource )
+            if (res instanceof URLResource)
             {
-                URL url = ( ( URLResource ) res ).getURL();
-                uri = URI.create( url.toString() ).resolve( IBldProject.PROJECT_FILE );
+                URL url = ((URLResource) res).getURL();
+                uri = URI.create(url.toString()).resolve(IBldProject.PROJECT_FILE);
                 try
                 {
                     InputStream stream = uri.toURL().openStream(); // check file
                     // exists
                     stream.close();
                 }
-                catch ( IOException e )
+                catch (IOException e)
                 {
                     uri = null;
                 }
             }
-            else if ( res instanceof FileResource )
+            else if (res instanceof FileResource)
             {
-                uri = ( ( FileResource ) res ).getFile().toURI().resolve( IBldProject.PROJECT_FILE );
-                if ( !( new File( uri ).exists() ) )
+                uri = ((FileResource) res).getFile().toURI().resolve(
+                    IBldProject.PROJECT_FILE);
+                if (!(new File(uri).exists()))
                     uri = null;
             }
 
             return uri;
         }
 
-
         /*
          * add sigil dependencies to ModuleDescriptor.
          */
-        private void addDependenciesToDescriptor( Resource res, DefaultModuleDescriptor md ) throws IOException
+        private void addDependenciesToDescriptor(Resource res, DefaultModuleDescriptor md)
+            throws IOException
         {
             // FIXME: transitive should be configurable
             final boolean transitive = true; // ivy default is true
             final boolean changing = false;
             final boolean force = false;
 
-            URI uri = getSigilURI( res );
-            if ( uri == null )
+            URI uri = getSigilURI(res);
+            if (uri == null)
                 return;
 
             IBldProject project;
 
-            project = BldFactory.getProject( uri );
+            project = BldFactory.getProject(uri);
 
             IBundleModelElement requirements = project.getDependencies();
-            Log.verbose( "requirements: " + Arrays.asList( requirements.children() ) );
+            Log.verbose("requirements: " + Arrays.asList(requirements.children()));
 
             // preserve version range for Require-Bundle
             // XXX: synthesise bundle version range corresponding to package version ranges?
             HashMap<String, VersionRange> versions = new HashMap<String, VersionRange>();
-            for ( IModelElement child : requirements.children() )
+            for (IModelElement child : requirements.children())
             {
-                if ( child instanceof IRequiredBundle )
+                if (child instanceof IRequiredBundle)
                 {
-                    IRequiredBundle bundle = ( IRequiredBundle ) child;
-                    versions.put( bundle.getSymbolicName(), bundle.getVersions() );
+                    IRequiredBundle bundle = (IRequiredBundle) child;
+                    versions.put(bundle.getSymbolicName(), bundle.getVersions());
                 }
             }
 
             IBldResolver resolver = findResolver();
-            if ( resolver == null )
+            if (resolver == null)
             {
                 // this can happen in IvyDE, but it retries and is OK next time.
-                Log.warn( "failed to find resolver - IvyContext not yet available." );
+                Log.warn("failed to find resolver - IvyContext not yet available.");
                 return;
             }
 
-            IResolution resolution = resolver.resolve( requirements, false );
-            Log.verbose( "resolution: " + resolution.getBundles() );
+            IResolution resolution = resolver.resolve(requirements, false);
+            Log.verbose("resolution: " + resolution.getBundles());
 
             ModuleRevisionId masterMrid = md.getModuleRevisionId();
             DefaultDependencyDescriptor dd;
             ModuleRevisionId mrid;
 
-            for ( ISigilBundle bundle : resolution.getBundles() )
+            for (ISigilBundle bundle : resolution.getBundles())
             {
                 IBundleModelElement info = bundle.getBundleInfo();
                 String name = info.getSymbolicName();
 
-                if ( "system bundle".equals(name) )
+                if ("system bundle".equals(name))
                 {
                     // e.g. SystemProvider with framework=null
-                    Log.verbose( "Discarding system bundle" );
+                    Log.verbose("Discarding system bundle");
                     continue;
                 }
 
-                ModuleDescriptor bmd = (ModuleDescriptor) bundle.getMeta().get(ModuleDescriptor.class);
-                if ( bmd != null )
+                ModuleDescriptor bmd = (ModuleDescriptor) bundle.getMeta().get(
+                    ModuleDescriptor.class);
+                if (bmd != null)
                 {
                     ModuleRevisionId bmrid = bmd.getModuleRevisionId();
                     String org = bmrid.getOrganisation();
-                    if ( org == null )
+                    if (org == null)
                         org = masterMrid.getOrganisation();
                     String module = bmrid.getName();
                     String rev = "latest." + bmd.getStatus();
 
-                    mrid = ModuleRevisionId.newInstance( org, module, rev );
-                    
-                    dd = new SigilDependencyDescriptor( md, mrid, force, changing, transitive );
+                    mrid = ModuleRevisionId.newInstance(org, module, rev);
+
+                    dd = new SigilDependencyDescriptor(md, mrid, force, changing,
+                        transitive);
 
                     Artifact artifact = (Artifact) bundle.getMeta().get(Artifact.class);
-                    if ( artifact != null ) {
-                        dd.addDependencyArtifact( mrid.getName(), new DefaultDependencyArtifactDescriptor( dd, artifact.getName(), "jar",
-                            "jar", null, null ) );                        
+                    if (artifact != null)
+                    {
+                        dd.addDependencyArtifact(mrid.getName(),
+                            new DefaultDependencyArtifactDescriptor(dd,
+                                artifact.getName(), "jar", "jar", null, null));
                     }
                 }
                 else
@@ -568,133 +556,140 @@ public class SigilParser implements Modu
                     // VersionRange version = versions.get( name );
                     // String rev = version != null ? version.toString() : info.getVersion().toString();
                     String rev = info.getVersion().toString();
-                    mrid = ModuleRevisionId.newInstance( SigilResolver.ORG_SIGIL, name, rev );
-                    dd = new SigilDependencyDescriptor( md, mrid, force, changing, transitive );
+                    mrid = ModuleRevisionId.newInstance(SigilResolver.ORG_SIGIL, name,
+                        rev);
+                    dd = new SigilDependencyDescriptor(md, mrid, force, changing,
+                        transitive);
                 }
 
                 int nDeps = 0;
                 boolean foundDefault = false;
 
                 // TODO: make dependency configurations configurable SIGIL-176
-                for ( String conf : md.getConfigurationsNames() )
+                for (String conf : md.getConfigurationsNames())
                 {
-                    if ( conf.equals( "default" ) )
+                    if (conf.equals("default"))
                     {
                         foundDefault = true;
                     }
-                    else if ( md.getArtifacts( conf ).length == 0 )
+                    else if (md.getArtifacts(conf).length == 0)
                     {
-                        dd.addDependencyConfiguration( conf, conf + "(default)" );
+                        dd.addDependencyConfiguration(conf, conf + "(default)");
                         nDeps++;
                     }
                 }
 
-                if ( nDeps > 0 )
+                if (nDeps > 0)
                 {
-                    if ( foundDefault )
-                        dd.addDependencyConfiguration( "default", "default" );
+                    if (foundDefault)
+                        dd.addDependencyConfiguration("default", "default");
                 }
                 else
                 {
-                    dd.addDependencyConfiguration( "*", "*" ); // all configurations
+                    dd.addDependencyConfiguration("*", "*"); // all configurations
                 }
 
-                md.addDependency( dd );
+                md.addDependency(dd);
             }
 
             boolean resolved = true;
-            for ( IModelElement child : requirements.children() )
+            for (IModelElement child : requirements.children())
             {
-                ISigilBundle provider = resolution.getProvider( child );
-                if ( provider == null )
+                ISigilBundle provider = resolution.getProvider(child);
+                if (provider == null)
                 {
                     resolved = false;
                     // this is parse phase, so only log verbose message.
                     // error is produced during resolution phase.
-                    Log.verbose( "WARN: can't resolve: " + child );
+                    Log.verbose("WARN: can't resolve: " + child);
 
                     String name;
                     String version;
-                    if ( child instanceof IRequiredBundle )
+                    if (child instanceof IRequiredBundle)
                     {
-                        IRequiredBundle rb = ( IRequiredBundle ) child;
+                        IRequiredBundle rb = (IRequiredBundle) child;
                         name = rb.getSymbolicName();
                         version = rb.getVersions().toString();
                     }
                     else
                     {
-                        IPackageImport pi = ( IPackageImport ) child;
+                        IPackageImport pi = (IPackageImport) child;
                         name = "import!" + pi.getPackageName();
                         version = pi.getVersions().toString();
                     }
 
-                    mrid = ModuleRevisionId.newInstance( "!" + SigilResolver.ORG_SIGIL, name, version );
-                    dd = new SigilDependencyDescriptor( md, mrid, force, changing, transitive );
-                    dd.addDependencyConfiguration( "*", "*" ); // all
+                    mrid = ModuleRevisionId.newInstance("!" + SigilResolver.ORG_SIGIL,
+                        name, version);
+                    dd = new SigilDependencyDescriptor(md, mrid, force, changing,
+                        transitive);
+                    dd.addDependencyConfiguration("*", "*"); // all
                     // configurations
-                    md.addDependency( dd );
+                    md.addDependency(dd);
                 }
             }
 
-            if ( !resolved )
+            if (!resolved)
             {
                 // Ivy does not show warnings or errors logged from parse phase, until after resolution.
                 // but <buildlist> ant task doesn't do resolution, so errors would be silently ignored.
                 // Hence, we must use Message.info to ensure this failure is seen.
-                if ( !quiet )
-                    Log.info( "WARN: resolution failed in: " + masterMrid.getName() + ". Use -v for details." );
+                if (!quiet)
+                    Log.info("WARN: resolution failed in: " + masterMrid.getName()
+                        + ". Use -v for details.");
             }
         }
 
-
         /*
          * find named resolver, or first resolver that implements IBldResolver.
          */
         private IBldResolver findResolver()
         {
-            if ( resolver == null )
+            if (resolver == null)
             {
                 Ivy ivy = IvyContext.getContext().peekIvy();
-                if ( ivy != null )
+                if (ivy != null)
                 {
-                    if ( resolverName != null )
+                    if (resolverName != null)
                     {
-                        DependencyResolver r = ivy.getSettings().getResolver( resolverName );
-                        if ( r == null )
+                        DependencyResolver r = ivy.getSettings().getResolver(resolverName);
+                        if (r == null)
                         {
-                            throw new Error( "SigilParser: resolver \"" + resolverName + "\" not defined." );
+                            throw new Error("SigilParser: resolver \"" + resolverName
+                                + "\" not defined.");
                         }
-                        else if ( r instanceof IBldResolver )
+                        else if (r instanceof IBldResolver)
                         {
-                            resolver = ( IBldResolver ) r;
+                            resolver = (IBldResolver) r;
                         }
                         else
                         {
-                            throw new Error( "SigilParser: resolver \"" + resolverName + "\" is not a SigilResolver." );
+                            throw new Error("SigilParser: resolver \"" + resolverName
+                                + "\" is not a SigilResolver.");
                         }
                     }
                     else
                     {
-                        for ( Object r : ivy.getSettings().getResolvers() )
+                        for (Object r : ivy.getSettings().getResolvers())
                         {
-                            if ( r instanceof IBldResolver )
+                            if (r instanceof IBldResolver)
                             {
-                                resolver = ( IBldResolver ) r;
+                                resolver = (IBldResolver) r;
                                 break;
                             }
                         }
                     }
 
-                    if ( resolver == null )
+                    if (resolver == null)
                     {
-                        throw new Error( "SigilParser: can't find SigilResolver. Check ivysettings.xml." );
+                        throw new Error(
+                            "SigilParser: can't find SigilResolver. Check ivysettings.xml.");
                     }
                 }
-                else if ( config != null )
+                else if (config != null)
                 {
-                    Log.warn( "creating duplicate resolver to support IvyDE." );
+                    Log.warn("creating duplicate resolver to support IvyDE.");
                     resolver = new SigilResolver();
-                    ( ( SigilResolver ) resolver ).setConfig( config );
+                    ((SigilResolver) resolver).setConfig(config);
                 }
             }
             return resolver;
@@ -709,9 +704,8 @@ public class SigilParser implements Modu
  */
 class SigilDependencyDescriptor extends DefaultDependencyDescriptor
 {
-    public SigilDependencyDescriptor( DefaultModuleDescriptor md, ModuleRevisionId mrid, boolean force,
-        boolean changing, boolean transitive )
+    public SigilDependencyDescriptor(DefaultModuleDescriptor md, ModuleRevisionId mrid, boolean force, boolean changing, boolean transitive)
     {
-        super( md, mrid, force, changing, transitive );
+        super(md, mrid, force, changing, transitive);
     }
 }
\ No newline at end of file

Modified: felix/trunk/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/SigilResolver.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/SigilResolver.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/SigilResolver.java (original)
+++ felix/trunk/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/SigilResolver.java Mon Aug  2 17:08:03 2010
@@ -19,7 +19,6 @@
 
 package org.apache.felix.sigil.ivy;
 
-
 import static java.lang.String.format;
 
 import java.io.File;
@@ -56,7 +55,6 @@ import org.apache.ivy.plugins.resolver.B
 import org.apache.ivy.plugins.resolver.util.ResolvedResource;
 import org.apache.ivy.util.FileUtil;
 
-
 /**
  * This resolver is able to work with Sigil repositories.
  * It does not allow publishing.
@@ -71,7 +69,6 @@ public class SigilResolver extends Basic
     private boolean extractBCP = false;
     private Map<String, Resource> resourcesCache = new HashMap<String, Resource>();
 
-
     /**
      * no-args constructor required by Ivy.
      * 
@@ -86,121 +83,115 @@ public class SigilResolver extends Basic
     {
     }
 
-
-    public void setConfig( String config )
+    public void setConfig(String config)
     {
         this.config = config;
     }
 
-
     /**
      * if true, resolver extracts any jars embedded in Bundle-ClassPath.
      */
-    public void setExtractBCP( String extract )
+    public void setExtractBCP(String extract)
     {
-        this.extractBCP = Boolean.parseBoolean( extract );
+        this.extractBCP = Boolean.parseBoolean(extract);
     }
 
-
     private IBldResolver getResolver()
     {
-        if ( resolver == null )
+        if (resolver == null)
         {
-            if ( config == null )
+            if (config == null)
             {
-                throw new Error( "SigilResolver: not configured. Specify config=\"PATH\" in ivysettings.xml." );
+                throw new Error(
+                    "SigilResolver: not configured. Specify config=\"PATH\" in ivysettings.xml.");
             }
             try
             {
                 URI uri;
-                File file = new File( config );
+                File file = new File(config);
 
-                if ( file.isAbsolute() )
+                if (file.isAbsolute())
                 {
                     uri = file.toURI();
                 }
                 else
                 {
-                    URI cwd = new File( "." ).toURI();
-                    uri = cwd.resolve( config );
+                    URI cwd = new File(".").toURI();
+                    uri = cwd.resolve(config);
                 }
 
-                Map<String, Properties> repositories = BldFactory.getConfig( uri ).getRepositoryConfig();
-                resolver = new BldResolver( repositories );
+                Map<String, Properties> repositories = BldFactory.getConfig(uri).getRepositoryConfig();
+                resolver = new BldResolver(repositories);
             }
-            catch ( IOException e )
+            catch (IOException e)
             {
-                throw new Error( "SigilResolver: failed to configure: " + e );
+                throw new Error("SigilResolver: failed to configure: " + e);
             }
         }
         return resolver;
     }
 
-
-    public IResolution resolveOrFail( IModelElement element, boolean transitive ) throws ResolutionException
+    public IResolution resolveOrFail(IModelElement element, boolean transitive)
+        throws ResolutionException
     {
-        return getResolver().resolveOrFail( element, transitive );
+        return getResolver().resolveOrFail(element, transitive);
     }
 
-
-    public IResolution resolve( IModelElement element, boolean transitive )
+    public IResolution resolve(IModelElement element, boolean transitive)
     {
-        return getResolver().resolve( element, transitive );
+        return getResolver().resolve(element, transitive);
     }
 
-
     public String getTypeName()
     {
         return "sigil";
     }
 
-
     /*
      * synthesize an ivy descriptor for a Sigil dependency. called after Sigil
      * resolution, so descriptor already contains resolved version.
      */
-    public ResolvedResource findIvyFileRef( DependencyDescriptor dd, ResolveData data )
+    public ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data)
     {
         ResolvedResource ref = null;
 
         ModuleRevisionId id = dd.getDependencyRevisionId();
 
-        if ( !id.getOrganisation().equals( ORG_SIGIL ) )
+        if (!id.getOrganisation().equals(ORG_SIGIL))
         {
             return null;
         }
 
-        ISigilBundle bundle = resolve( id );
-        if ( bundle == null )
+        ISigilBundle bundle = resolve(id);
+        if (bundle == null)
         {
-            Log.error( "Failed to find bundle for module " + id );
+            Log.error("Failed to find bundle for module " + id);
             return null;
         }
 
         String symbolicName = id.getName();
         String version = bundle.getVersion().toString();
 
-        Resource res = new SigilIvy( extractBCP ? bundle : null, symbolicName, version );
-        ref = new ResolvedResource( res, version );
+        Resource res = new SigilIvy(extractBCP ? bundle : null, symbolicName, version);
+        ref = new ResolvedResource(res, version);
 
-        Log.debug( format( "findIvyFileRef: dd=%s => ref=%s", dd, ref ) );
+        Log.debug(format("findIvyFileRef: dd=%s => ref=%s", dd, ref));
         return ref;
     }
 
-
     @Override
-    protected ResolvedResource findArtifactRef( Artifact artifact, Date date )
+    protected ResolvedResource findArtifactRef(Artifact artifact, Date date)
     {
         String name = artifact.getName();
         ModuleRevisionId id = artifact.getModuleRevisionId();
 
-        if ( !id.getOrganisation().equals( ORG_SIGIL ) )
+        if (!id.getOrganisation().equals(ORG_SIGIL))
         {
             return null;
         }
 
-        ISigilBundle bundle = resolve( id );
-        if ( bundle == null )
+        ISigilBundle bundle = resolve(id);
+        if (bundle == null)
         {
             return null;
         }
@@ -211,33 +202,33 @@ public class SigilResolver extends Basic
 
         try
         {
-            URL url = ( uri != null ) ? uri.toURL() : bundle.getLocation().toURL();
-            if ( name.contains( "!" ) )
+            URL url = (uri != null) ? uri.toURL() : bundle.getLocation().toURL();
+            if (name.contains("!"))
             {
-                String[] split = name.split( "!" );
-                url = new URL( "jar:" + url + "!/" + split[1] + "." + artifact.getExt() );
+                String[] split = name.split("!");
+                url = new URL("jar:" + url + "!/" + split[1] + "." + artifact.getExt());
             }
-            res = new URLResource( url );
+            res = new URLResource(url);
         }
-        catch ( MalformedURLException e )
+        catch (MalformedURLException e)
         {
-            System.out.println( "Oops! " + e );
+            System.out.println("Oops! " + e);
         }
 
         String version = bundle.getVersion().toString();
-        ResolvedResource ref = new ResolvedResource( res, version );
+        ResolvedResource ref = new ResolvedResource(res, version);
 
-        Log.debug( format( "findArtifactRef: artifact=%s, date=%s => ref=%s", artifact, date, ref ) );
+        Log.debug(format("findArtifactRef: artifact=%s, date=%s => ref=%s", artifact,
+            date, ref));
         return ref;
     }
 
-
-    private ISigilBundle resolve( ModuleRevisionId id )
+    private ISigilBundle resolve(ModuleRevisionId id)
     {
         String revision = id.getRevision();
         String range = revision;
 
-        if ( revision.indexOf( ',' ) < 0 )
+        if (revision.indexOf(',') < 0)
         {
             // SigilParser has already resolved the revision from the import
             // version range.
@@ -247,83 +238,80 @@ public class SigilResolver extends Basic
             range = "[" + revision + "," + revision + "]";
         }
 
-        IRequiredBundle bundle = ModelElementFactory.getInstance().newModelElement(IRequiredBundle.class);
-        bundle.setSymbolicName( id.getName() );
-        bundle.setVersions( VersionRange.parseVersionRange( range ) );
+        IRequiredBundle bundle = ModelElementFactory.getInstance().newModelElement(
+            IRequiredBundle.class);
+        bundle.setSymbolicName(id.getName());
+        bundle.setVersions(VersionRange.parseVersionRange(range));
 
-        Log.verbose( "searching for " + bundle );
+        Log.verbose("searching for " + bundle);
 
         try
         {
-            IResolution resolution = resolveOrFail( bundle, false );
-            ISigilBundle[] bundles = resolution.getBundles().toArray( new ISigilBundle[0] );
-            if ( bundles.length == 1 )
+            IResolution resolution = resolveOrFail(bundle, false);
+            ISigilBundle[] bundles = resolution.getBundles().toArray(new ISigilBundle[0]);
+            if (bundles.length == 1)
             {
                 return bundles[0];
             }
         }
-        catch ( ResolutionException e )
+        catch (ResolutionException e)
         {
-            Log.warn( e.getMessage() );
+            Log.warn(e.getMessage());
             return null;
         }
         return null;
     }
 
-
     /*
      * Implement BasicResolver abstract methods
      */
 
     @Override
-    protected long get( Resource res, File dest ) throws IOException
+    protected long get(Resource res, File dest) throws IOException
     {
-        FileUtil.copy( res.openStream(), dest, null );
+        FileUtil.copy(res.openStream(), dest, null);
         long len = res.getContentLength();
-        Log.debug( format( "get(%s, %s) = %d", res, dest, len ) );
+        Log.debug(format("get(%s, %s) = %d", res, dest, len));
         return len;
     }
 
-
     @Override
-    public Resource getResource( String source ) throws IOException
+    public Resource getResource(String source) throws IOException
     {
-        source = encode( source );
-        Resource res = resourcesCache.get( source );
-        if ( res == null )
+        source = encode(source);
+        Resource res = resourcesCache.get(source);
+        if (res == null)
         {
-            res = new URLResource( new URL( source ) );
-            resourcesCache.put( source, res );
+            res = new URLResource(new URL(source));
+            resourcesCache.put(source, res);
         }
-        Log.debug( format( "SIGIL: getResource(%s) = %d", source, res ) );
+        Log.debug(format("SIGIL: getResource(%s) = %d", source, res));
         return res;
     }
 
-
-    private static String encode( String source )
+    private static String encode(String source)
     {
-        return source.trim().replaceAll( " ", "%20" );
+        return source.trim().replaceAll(" ", "%20");
     }
 
-
     @SuppressWarnings("unchecked")
     @Override
-    protected Collection findNames( Map tokenValues, String token )
+    protected Collection findNames(Map tokenValues, String token)
     {
-        throw new Error( "SigilResolver: findNames not supported." );
+        throw new Error("SigilResolver: findNames not supported.");
     }
 
-
-    public void publish( Artifact artifact, File src, boolean overwrite ) throws IOException
+    public void publish(Artifact artifact, File src, boolean overwrite)
+        throws IOException
     {
-        throw new Error( "SigilResolver: publish not supported." );
+        throw new Error("SigilResolver: publish not supported.");
     }
 
-
-    public void beginPublishTransaction( ModuleRevisionId module, boolean overwrite ) throws IOException
+    public void beginPublishTransaction(ModuleRevisionId module, boolean overwrite)
+        throws IOException
     {
         // stop publish attempts being silently ignored.
-        throw new Error( "SigilResolver: publish not supported." );
+        throw new Error("SigilResolver: publish not supported.");
     }
 
     /*
@@ -335,13 +323,11 @@ public class SigilResolver extends Basic
         private String name;
         private boolean exists = true;
 
-
         private SigilIvy()
         {
         }
 
-
-        public SigilIvy( ISigilBundle bundle, String module, String rev )
+        public SigilIvy(ISigilBundle bundle, String module, String rev)
         {
             this.name = "sigil!" + module + "#" + rev;
 
@@ -350,29 +336,29 @@ public class SigilResolver extends Basic
             String status = "release";
             String pub = "20080912162859";
 
-            content.append( "<ivy-module version=\"1.0\">\n" );
+            content.append("<ivy-module version=\"1.0\">\n");
 
-            content.append( format(
-                "<info organisation=\"%s\" module=\"%s\" revision=\"%s\" status=\"%s\" publication=\"%s\"/>\n", org,
-                module, rev, status, pub ) );
+            content.append(format(
+                "<info organisation=\"%s\" module=\"%s\" revision=\"%s\" status=\"%s\" publication=\"%s\"/>\n",
+                org, module, rev, status, pub));
 
-            String bcp = readBundleClassPath( bundle );
-            if ( bcp != null )
+            String bcp = readBundleClassPath(bundle);
+            if (bcp != null)
             {
-                content.append( "<publications>\n" );
-                for ( String j : bcp.split( ",\\s*" ) )
+                content.append("<publications>\n");
+                for (String j : bcp.split(",\\s*"))
                 {
-                    if ( j.equals( "." ) )
+                    if (j.equals("."))
                     {
-                        content.append( "<artifact/>\n" );
+                        content.append("<artifact/>\n");
                     }
-                    else if ( j.endsWith( ".jar" ) && bundleContains( bundle, j ) )
+                    else if (j.endsWith(".jar") && bundleContains(bundle, j))
                     {
-                        j = j.substring( 0, j.length() - 4 );
-                        content.append( format( "<artifact name=\"%s!%s\"/>\n", module, j ) );
+                        j = j.substring(0, j.length() - 4);
+                        content.append(format("<artifact name=\"%s!%s\"/>\n", module, j));
                     }
                 }
-                content.append( "</publications>\n" );
+                content.append("</publications>\n");
             }
 
             // TODO: add dependencies?
@@ -381,39 +367,38 @@ public class SigilResolver extends Basic
             // revConstraint="[1.2,1.3)"/>
             // </dependencies>
 
-            content.append( "</ivy-module>\n" );
+            content.append("</ivy-module>\n");
         }
 
-
-        private boolean bundleContains( ISigilBundle bundle, String j )
+        private boolean bundleContains(ISigilBundle bundle, String j)
         {
             InputStream is = null;
             try
             {
-                URL url = getURL( bundle );
+                URL url = getURL(bundle);
                 is = url.openStream();
-                JarInputStream js = new JarInputStream( is, false );
+                JarInputStream js = new JarInputStream(is, false);
                 JarEntry entry;
-                while ( ( entry = js.getNextJarEntry() ) != null )
+                while ((entry = js.getNextJarEntry()) != null)
                 {
-                    if ( j.equals( entry.getName() ) )
+                    if (j.equals(entry.getName()))
                     {
                         return true;
                     }
                 }
             }
-            catch ( IOException e )
+            catch (IOException e)
             {
             }
             finally
             {
-                if ( is != null )
+                if (is != null)
                 {
                     try
                     {
                         is.close();
                     }
-                    catch ( IOException e2 )
+                    catch (IOException e2)
                     {
                     }
                 }
@@ -421,34 +406,33 @@ public class SigilResolver extends Basic
             return false;
         }
 
-
-        private String readBundleClassPath( ISigilBundle bundle )
+        private String readBundleClassPath(ISigilBundle bundle)
         {
-            if ( bundle == null )
+            if (bundle == null)
                 return null;
 
             InputStream is = null;
             try
             {
-                URL url = getURL( bundle );
+                URL url = getURL(bundle);
                 is = url.openStream();
-                JarInputStream js = new JarInputStream( is, false );
+                JarInputStream js = new JarInputStream(is, false);
                 Manifest m = js.getManifest();
-                if ( m != null )
-                    return ( String ) m.getMainAttributes().getValue( "Bundle-ClassPath" );
+                if (m != null)
+                    return (String) m.getMainAttributes().getValue("Bundle-ClassPath");
             }
-            catch ( IOException e )
+            catch (IOException e)
             {
             }
             finally
             {
-                if ( is != null )
+                if (is != null)
                 {
                     try
                     {
                         is.close();
                     }
-                    catch ( IOException e2 )
+                    catch (IOException e2)
                     {
                     }
                 }
@@ -457,77 +441,72 @@ public class SigilResolver extends Basic
             return null;
         }
 
-
-        private URL getURL( ISigilBundle bundle ) throws MalformedURLException
+        private URL getURL(ISigilBundle bundle) throws MalformedURLException
         {
             URI uri = bundle.getBundleInfo().getUpdateLocation();
-            if ( uri != null ) {
+            if (uri != null)
+            {
                 return uri.toURL();
             }
-            else {
+            else
+            {
                 File path = bundle.getLocation();
-                if ( path == null ) {
-                    throw new NullPointerException( "Missing location for " + bundle.getSymbolicName() );
+                if (path == null)
+                {
+                    throw new NullPointerException("Missing location for "
+                        + bundle.getSymbolicName());
                 }
                 return path.toURI().toURL();
             }
         }
 
-
         public String toString()
         {
             return "SigilIvy[" + name + "]";
         }
 
-
         // clone is used to read checksum files
         // so clone(getName() + ".sha1").exists() should be false
-        public Resource clone( String cloneName )
+        public Resource clone(String cloneName)
         {
-            Log.debug( "SigilIvy: clone: " + cloneName );
+            Log.debug("SigilIvy: clone: " + cloneName);
             SigilIvy clone = new SigilIvy();
             clone.name = cloneName;
             clone.exists = false;
             return clone;
         }
 
-
         public boolean exists()
         {
             return exists;
         }
 
-
         public long getContentLength()
         {
             return content.length();
         }
 
-
         public long getLastModified()
         {
             // TODO Auto-generated method stub
-            Log.debug( "NOT IMPLEMENTED: getLastModified" );
+            Log.debug("NOT IMPLEMENTED: getLastModified");
             return 0;
         }
 
-
         public String getName()
         {
             return name;
         }
 
-
         public boolean isLocal()
         {
             return false;
         }
 
-
         @SuppressWarnings("deprecation")
         public InputStream openStream() throws IOException
         {
-            return new java.io.StringBufferInputStream( content.toString() );
+            return new java.io.StringBufferInputStream(content.toString());
         }
     }
 }