You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by og...@apache.org on 2008/12/22 23:10:08 UTC

svn commit: r728804 - in /maven/mercury/trunk: mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/ mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/ mercury-md/mercury-md-sat/src/main/java/...

Author: ogusakov
Date: Mon Dec 22 14:10:08 2008
New Revision: 728804

URL: http://svn.apache.org/viewvc?rev=728804&view=rev
Log:
[MERCURY-65] preparing alternative syntax for ant tasks

Modified:
    maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Config.java
    maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Dep.java
    maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Messages.properties
    maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/ResolveTask.java
    maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/antlib.xml
    maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java

Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Config.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Config.java?rev=728804&r1=728803&r2=728804&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Config.java (original)
+++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Config.java Mon Dec 22 14:10:08 2008
@@ -31,397 +31,432 @@
 import org.codehaus.plexus.lang.Language;
 
 /**
- *
- *
  * @author Oleg Gusakov
  * @version $Id$
- *
  */
 public class Config
-extends AbstractDataType
+    extends AbstractDataType
 {
-  private static final Language _lang = new DefaultLanguage( Config.class );
-  
-  Collection<Repo> _repos;
-  
-  Collection<Auth> _auths;
-  
-  Collection<Repository> _repositories;
-  
-  public Collection<Repository> getRepositories()
-  throws BuildException
-  {
-    if( Util.isEmpty( _repos ) )
-      return null;
+    private static final Language _lang = new DefaultLanguage( Config.class );
     
-    if( _repositories != null )
-      return _repositories;
+    private static final String DEFAULT_LOCAL_DIR = System.getProperty( "user.home" )+"/.m2/repository"; 
     
-    _repositories = new ArrayList<Repository>( _repos.size() );
-    
-    for( Repo repo : _repos )
-      _repositories.add( repo.getRepository() );
+    private static final String DEFAULT_CENTRAL_URL = System.getProperty( "maven.central.url", "http://repo1.maven.org/maven2" ); 
 
-    return _repositories;
-  }
-  
-  private static Credentials createCredentials( Auth a )
-  {
-    Credentials cred = null;
-    
-    if( a._certfile != null )
-    {
-      File cf = new File( a._certfile );
-      if( ! cf.exists() )
-        throw new BuildException( _lang.getMessage( "config.no.cert.file", a._certfile ) );
-      
-      try
-      {
-        cred = new Credentials( FileUtil.readRawData( cf ), a._name, a._pass );
-      }
-      catch( IOException e )
-      {
-        throw new BuildException(e);
-      }
-    }
-    else
-      cred = new Credentials( a._name, a._pass );
-    
-    return cred;
-  }
-  
-  public Repo createRepo()
-  {
-    if( _repos == null )
-    _repos = new ArrayList<Repo>(4);
-    
-    Repo r = new Repo();
-    
-    _repos.add( r );
-    
-    return r;
-  }
-  
-  public Auth createAuth()
-  {
-    if( _auths == null )
-    _auths = new ArrayList<Auth>(4);
-    
-    Auth a = new Auth();
-    
-    _auths.add( a );
-    
-    return a;
-  }
-  
-  public class Repo
-  extends AbstractDataType
-  {
-    String _dir;
-    String _url;
-    String _type;
-    String _authid;
-    String _proxyauthid;
-    
-    boolean _readable = true;
-    boolean _writeable = false;
-    
-    List<Verify> _writeVerifiers;
-    List<Verify> _readVerifiers;
+    Collection<Repo> _repos;
 
-    public void setReadable( boolean readable )
-    {
-      this._readable = readable;
-    }
+    Collection<Auth> _auths;
 
-    public void setWriteable( boolean writeable )
-    {
-      this._writeable = writeable;
-    }
-    
-    public void setUrl( String url )
-    {
-      this._url = url;
-    }
+    Collection<Repository> _repositories;
 
-    public void setDir( String dir )
+    public Config( String localDir, String remoteUrl )
     {
-      this._dir = dir;
+        
+        Repo local = createRepo();
+        local.setId( "defaultLocalRepo" );
+        local.setDir( localDir == null ? DEFAULT_LOCAL_DIR : localDir  );
+        
+        Repo central = createRepo();
+        central.setId( "central" );
+        central.setUrl( remoteUrl );
+        
     }
 
-    public void setType( String type )
+    public Config()
     {
-      this._type = type;
     }
 
-    public void setAuthid( String authid )
+    public Collection<Repository> getRepositories()
+        throws BuildException
     {
-      this._authid = authid;
-    }
+        if ( Util.isEmpty( _repos ) )
+            return null;
 
-    public void setProxyauthid( String proxyauthid )
-    {
-      this._proxyauthid = proxyauthid;
-    }
-    
-    boolean isLocal()
-    {
-      return _dir != null;
+        if ( _repositories != null )
+            return _repositories;
+
+        _repositories = new ArrayList<Repository>( _repos.size() );
+
+        for ( Repo repo : _repos )
+            _repositories.add( repo.getRepository() );
+
+        return _repositories;
     }
-    
-    public Verify createVerifywrite()
+
+    private static Credentials createCredentials( Auth a )
     {
-      if( _writeVerifiers == null )
-        _writeVerifiers = new ArrayList<Verify>(2);
-      
-      Verify v = new Verify();
-      
-      _writeVerifiers.add( v );
-      
-      return v;
+        Credentials cred = null;
+
+        if ( a._certfile != null )
+        {
+            File cf = new File( a._certfile );
+            if ( !cf.exists() )
+                throw new BuildException( _lang.getMessage( "config.no.cert.file", a._certfile ) );
+
+            try
+            {
+                cred = new Credentials( FileUtil.readRawData( cf ), a._name, a._pass );
+            }
+            catch ( IOException e )
+            {
+                throw new BuildException( e );
+            }
+        }
+        else
+            cred = new Credentials( a._name, a._pass );
+
+        return cred;
     }
-    
-    public Verify createVerifyread()
+
+    public Repo createRepo()
     {
-      if( _readVerifiers == null )
-        _readVerifiers = new ArrayList<Verify>(2);
-      
-      Verify v = new Verify();
-      
-      _readVerifiers.add( v );
-      
-      return v;
+        if ( _repos == null )
+            _repos = new ArrayList<Repo>( 4 );
+
+        Repo r = new Repo();
+
+        _repos.add( r );
+
+        return r;
     }
 
-    private Set<StreamVerifierFactory> getVerifiers( List<Verify> vlist )
+    public Auth createAuth()
     {
-      if( Util.isEmpty( vlist ) )
-        return null;
-      
-      Set<StreamVerifierFactory> facs = new HashSet<StreamVerifierFactory>( vlist.size() );
-      
-      for( Verify v : vlist )
-        facs.add( v.getVerifierFactory() );
-      
-      return facs;
-      
+        if ( _auths == null )
+            _auths = new ArrayList<Auth>( 4 );
+
+        Auth a = new Auth();
+
+        _auths.add( a );
+
+        return a;
     }
-    
-    public Repository getRepository()
+
+    public class Repo
+        extends AbstractDataType
     {
-      Repository r = null;
-      
-      if( isLocal() )
-      {
-        DependencyProcessor dp = new MavenDependencyProcessor();
-        
-        Server server;
-        try
+        String _dir;
+
+        String _url;
+
+        String _type;
+
+        String _authid;
+
+        String _proxyauthid;
+
+        boolean _readable = true;
+
+        boolean _writeable = false;
+
+        List<Verify> _writeVerifiers;
+
+        List<Verify> _readVerifiers;
+
+        public void setReadable( boolean readable )
         {
-          server = new Server( getId(), new File( _dir ).toURL() );
+            this._readable = readable;
+        }
 
-          server.setReaderStreamVerifierFactories( getVerifiers( _readVerifiers ) );
-          server.setWriterStreamVerifierFactories( getVerifiers( _writeVerifiers ) );
+        public void setWriteable( boolean writeable )
+        {
+            this._writeable = writeable;
         }
-        catch( MalformedURLException e )
+
+        public void setUrl( String url )
         {
-          throw new BuildException( e );
+            this._url = url;
         }
-        
-        r = new LocalRepositoryM2( server, dp  );
-      }
-      else
-      {
-        DependencyProcessor dp = new MavenDependencyProcessor();
-        
-        Server server;
-        try
+
+        public void setDir( String dir )
         {
-          server = new Server( getId(), new URL( _url ) );
+            this._dir = dir;
+        }
 
-          server.setReaderStreamVerifierFactories( getVerifiers( _readVerifiers ) );
-          server.setWriterStreamVerifierFactories( getVerifiers( _writeVerifiers ) );
+        public void setType( String type )
+        {
+            this._type = type;
         }
-        catch( MalformedURLException e )
+
+        public void setAuthid( String authid )
         {
-          throw new BuildException(e);
+            this._authid = authid;
         }
-        
-        if( _authid != null )
+
+        public void setProxyauthid( String proxyauthid )
         {
-          Auth au = null;
-          
-          if( _auths == null )
-            throw new BuildException( _lang.getMessage( "config.no.auths", _authid ) );
-          
-          for( Auth a : _auths )
-            if( _authid.equals( a.getId() ) )
-              au = a;
-          
-          if( au == null )
-            throw new BuildException( _lang.getMessage( "config.no.auth.for.id", _authid ) );
-          
-          Credentials serverCred = createCredentials( au );
-          
-          server.setServerCredentials( serverCred );
+            this._proxyauthid = proxyauthid;
         }
-        
-        if( _proxyauthid != null )
+
+        boolean isLocal()
+        {
+            return _dir != null;
+        }
+
+        public Verify createVerifywrite()
         {
-          Auth au = null;
-          
-          if( _auths == null )
-            throw new BuildException( _lang.getMessage( "config.no.proxy.auths", _proxyauthid ) );
-          
-          for( Auth a : _auths )
-            if( _proxyauthid.equals( a.getId() ) )
-              au = a;
-          
-          if( au == null )
-            throw new BuildException( _lang.getMessage( "config.no.proxy.auth.for.id", _proxyauthid ) );
-          
-          Credentials proxyCred = createCredentials( au );
-          
-          server.setProxyCredentials( proxyCred );
+            if ( _writeVerifiers == null )
+                _writeVerifiers = new ArrayList<Verify>( 2 );
+
+            Verify v = new Verify();
 
+            _writeVerifiers.add( v );
+
+            return v;
         }
-        
 
-        server.setReaderStreamVerifierFactories( getVerifiers( _readVerifiers ) );
-        server.setWriterStreamVerifierFactories( getVerifiers( _writeVerifiers ) );
+        public Verify createVerifyread()
+        {
+            if ( _readVerifiers == null )
+                _readVerifiers = new ArrayList<Verify>( 2 );
 
-        r  = new RemoteRepositoryM2( server, dp  );
-        
-      }
-      
-      return r;
-    }
-    
-  }
+            Verify v = new Verify();
 
-  public class Auth
-  extends AbstractDataType
-  {
-    String _name;
-    String _pass;
-    String _certfile;
-    
-    public void setName( String name )
-    {
-      this._name = name;
-    }
+            _readVerifiers.add( v );
 
-    public void setPass( String pass )
-    {
-      this._pass = pass;
-    }
+            return v;
+        }
 
-    public void setCertfile( String certfile )
-    {
-      this._certfile = certfile;
-    }
-  }
-  
-  public class Verify
-  extends AbstractDataType
-  {
-    public static final String PGP  = "pgp";
-    public static final String SHA1 = "sha1";
-    
-    String _type;
-    boolean _lenient = true;
-    boolean _sufficient = false;
-    Map<String, String> _properties;
+        private Set<StreamVerifierFactory> getVerifiers( List<Verify> vlist )
+        {
+            if ( Util.isEmpty( vlist ) )
+                return null;
 
-    public void setType( String type )
-    {
-      this._type = type;
-    }
+            Set<StreamVerifierFactory> facs = new HashSet<StreamVerifierFactory>( vlist.size() );
 
-    public void setLenient( boolean lenient )
-    {
-      this._lenient = lenient;
-    }
+            for ( Verify v : vlist )
+                facs.add( v.getVerifierFactory() );
+
+            return facs;
+
+        }
+
+        public Repository getRepository()
+        {
+            Repository r = null;
+
+            if ( isLocal() )
+            {
+                DependencyProcessor dp = new MavenDependencyProcessor();
+
+                Server server;
+                try
+                {
+                    server = new Server( getId(), new File( _dir ).toURL() );
+
+                    server.setReaderStreamVerifierFactories( getVerifiers( _readVerifiers ) );
+                    server.setWriterStreamVerifierFactories( getVerifiers( _writeVerifiers ) );
+                }
+                catch ( MalformedURLException e )
+                {
+                    throw new BuildException( e );
+                }
+
+                r = new LocalRepositoryM2( server, dp );
+            }
+            else
+            {
+                DependencyProcessor dp = new MavenDependencyProcessor();
+
+                Server server;
+                try
+                {
+                    server = new Server( getId(), new URL( _url ) );
+
+                    server.setReaderStreamVerifierFactories( getVerifiers( _readVerifiers ) );
+                    server.setWriterStreamVerifierFactories( getVerifiers( _writeVerifiers ) );
+                }
+                catch ( MalformedURLException e )
+                {
+                    throw new BuildException( e );
+                }
+
+                if ( _authid != null )
+                {
+                    Auth au = null;
+
+                    if ( _auths == null )
+                        throw new BuildException( _lang.getMessage( "config.no.auths", _authid ) );
+
+                    for ( Auth a : _auths )
+                        if ( _authid.equals( a.getId() ) )
+                            au = a;
+
+                    if ( au == null )
+                        throw new BuildException( _lang.getMessage( "config.no.auth.for.id", _authid ) );
+
+                    Credentials serverCred = createCredentials( au );
+
+                    server.setServerCredentials( serverCred );
+                }
+
+                if ( _proxyauthid != null )
+                {
+                    Auth au = null;
+
+                    if ( _auths == null )
+                        throw new BuildException( _lang.getMessage( "config.no.proxy.auths", _proxyauthid ) );
+
+                    for ( Auth a : _auths )
+                        if ( _proxyauthid.equals( a.getId() ) )
+                            au = a;
+
+                    if ( au == null )
+                        throw new BuildException( _lang.getMessage( "config.no.proxy.auth.for.id", _proxyauthid ) );
+
+                    Credentials proxyCred = createCredentials( au );
+
+                    server.setProxyCredentials( proxyCred );
+
+                }
+
+                server.setReaderStreamVerifierFactories( getVerifiers( _readVerifiers ) );
+                server.setWriterStreamVerifierFactories( getVerifiers( _writeVerifiers ) );
+
+                r = new RemoteRepositoryM2( server, dp );
+
+            }
+
+            return r;
+        }
 
-    public void setSufficient( boolean sufficient )
-    {
-      this._sufficient = sufficient;
     }
-    
-    public void addConfiguredProperty( Property property )
+
+    public class Auth
+        extends AbstractDataType
     {
-      if( _properties == null )
-        _properties = new HashMap<String,String>(4);
-      
-      _properties.put( property.getName(), property.getValue() );
+        String _name;
+
+        String _pass;
+
+        String _certfile;
+
+        public void setName( String name )
+        {
+            this._name = name;
+        }
+
+        public void setPass( String pass )
+        {
+            this._pass = pass;
+        }
+
+        public void setCertfile( String certfile )
+        {
+            this._certfile = certfile;
+        }
     }
-    
-    public StreamVerifierFactory getVerifierFactory()
-    throws BuildException
+
+    public class Verify
+        extends AbstractDataType
     {
-      if( _type == null )
-        throw new BuildException( _lang.getMessage( "config.repo.verifier.no.type" ) );
-      
-      if( _properties == null || _properties.isEmpty() )
-        throw new BuildException( _lang.getMessage( "config.repo.verifier.no.properties", _type ) );
-      
-      if( PGP.equals( _type ) )
-      {
-        String keyRing = _properties.get( "keyring" );
-        
-        if( keyRing == null )
-          throw new BuildException( _lang.getMessage( "config.repo.verifier.pgp.no.keyring" ) );
+        public static final String PGP = "pgp";
 
-        String pass = _properties.get( "pass" );
-        
-        if( pass == null ) // reader configuration
+        public static final String SHA1 = "sha1";
+
+        String _type;
+
+        boolean _lenient = true;
+
+        boolean _sufficient = false;
+
+        Map<String, String> _properties;
+
+        public void setType( String type )
+        {
+            this._type = type;
+        }
+
+        public void setLenient( boolean lenient )
+        {
+            this._lenient = lenient;
+        }
+
+        public void setSufficient( boolean sufficient )
         {
-          try
-          {
-            PgpStreamVerifierFactory fac =
-                new PgpStreamVerifierFactory(
-                    new StreamVerifierAttributes( PgpStreamVerifierFactory.DEFAULT_EXTENSION, _lenient, _sufficient )
-                    , FileUtil.toStream( keyRing )
-                                            );
-            return fac;
-          }
-          catch( Exception e )
-          {
-            throw new BuildException( e );
-          }
-        }
-        else // writer configuration
-        {
-          String keyId = _properties.get( "key" );
-          
-          if( keyId == null || keyId.length() != 16 )
-            throw new BuildException( _lang.getMessage( "config.repo.verifier.pgp.bad.keyid", keyId, keyRing ) );
-          
-          try
-          {
-            PgpStreamVerifierFactory fac =
-                new PgpStreamVerifierFactory(
-                    new StreamVerifierAttributes( PgpStreamVerifierFactory.DEFAULT_EXTENSION, _lenient, _sufficient )
-                    , FileUtil.toStream( keyRing ), keyId, pass
-                                            );
-            return fac;
-          }
-          catch( Exception e )
-          {
-            throw new BuildException( e );
-          }
-          
-        }
-      }
-      else if( SHA1.equals( _type ) )
-      {
-        SHA1VerifierFactory fac = new SHA1VerifierFactory( new StreamVerifierAttributes( SHA1VerifierFactory.DEFAULT_EXTENSION, _lenient, _sufficient ) );
+            this._sufficient = sufficient;
+        }
+
+        public void addConfiguredProperty( Property property )
+        {
+            if ( _properties == null )
+                _properties = new HashMap<String, String>( 4 );
+
+            _properties.put( property.getName(), property.getValue() );
+        }
 
-        return fac;
-      }
+        public StreamVerifierFactory getVerifierFactory()
+            throws BuildException
+        {
+            if ( _type == null )
+                throw new BuildException( _lang.getMessage( "config.repo.verifier.no.type" ) );
+
+            if ( _properties == null || _properties.isEmpty() )
+                throw new BuildException( _lang.getMessage( "config.repo.verifier.no.properties", _type ) );
+
+            if ( PGP.equals( _type ) )
+            {
+                String keyRing = _properties.get( "keyring" );
+
+                if ( keyRing == null )
+                    throw new BuildException( _lang.getMessage( "config.repo.verifier.pgp.no.keyring" ) );
+
+                String pass = _properties.get( "pass" );
+
+                if ( pass == null ) // reader configuration
+                {
+                    try
+                    {
+                        PgpStreamVerifierFactory fac =
+                            new PgpStreamVerifierFactory(
+                                                          new StreamVerifierAttributes(
+                                                                                        PgpStreamVerifierFactory.DEFAULT_EXTENSION,
+                                                                                        _lenient, _sufficient ),
+                                                          FileUtil.toStream( keyRing ) );
+                        return fac;
+                    }
+                    catch ( Exception e )
+                    {
+                        throw new BuildException( e );
+                    }
+                }
+                else
+                // writer configuration
+                {
+                    String keyId = _properties.get( "key" );
+
+                    if ( keyId == null || keyId.length() != 16 )
+                        throw new BuildException( _lang.getMessage( "config.repo.verifier.pgp.bad.keyid", keyId,
+                                                                    keyRing ) );
+
+                    try
+                    {
+                        PgpStreamVerifierFactory fac =
+                            new PgpStreamVerifierFactory(
+                                                          new StreamVerifierAttributes(
+                                                                                        PgpStreamVerifierFactory.DEFAULT_EXTENSION,
+                                                                                        _lenient, _sufficient ),
+                                                          FileUtil.toStream( keyRing ), keyId, pass );
+                        return fac;
+                    }
+                    catch ( Exception e )
+                    {
+                        throw new BuildException( e );
+                    }
+
+                }
+            }
+            else if ( SHA1.equals( _type ) )
+            {
+                SHA1VerifierFactory fac =
+                    new SHA1VerifierFactory( new StreamVerifierAttributes( SHA1VerifierFactory.DEFAULT_EXTENSION,
+                                                                           _lenient, _sufficient ) );
 
-      throw new BuildException( _lang.getMessage( "config.repo.verifier.bad.type", _type ) );
+                return fac;
+            }
+
+            throw new BuildException( _lang.getMessage( "config.repo.verifier.bad.type", _type ) );
+        }
     }
-  }
 
 }

Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Dep.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Dep.java?rev=728804&r1=728803&r2=728804&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Dep.java (original)
+++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Dep.java Mon Dec 22 14:10:08 2008
@@ -29,6 +29,11 @@
     this._transitive = val;
   }
   
+  protected void setList( List<Dependency> dependencies )
+  {
+      _dependencies = dependencies;
+  }
+  
   protected List<ArtifactBasicMetadata> getList()
   {
     if( Util.isEmpty( _dependencies ) )

Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Messages.properties
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Messages.properties?rev=728804&r1=728803&r2=728804&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Messages.properties (original)
+++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Messages.properties Mon Dec 22 14:10:08 2008
@@ -10,7 +10,7 @@
 no.path.ref=neither pathid nor refpathid are specified
 path.exists=path with id {0} already exists, cannot create 
 no.path.ref=path with id {0} does not exist, cannot modify it
-no.dep.id=no dependency id specified, don't know what to do
+no.dep.id=no dependency id specified and no inner dependencies - don't know what to do
 no.dep=no object with id {0} found
 bad.dep=dependency {0} is of wrong type {1}, expected {2}
 vr.error=errors reading dependencies: {0}

Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/ResolveTask.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/ResolveTask.java?rev=728804&r1=728803&r2=728804&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/ResolveTask.java (original)
+++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/ResolveTask.java Mon Dec 22 14:10:08 2008
@@ -1,6 +1,7 @@
 package org.apache.maven.mercury.ant.tasks;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -22,233 +23,285 @@
 import org.codehaus.plexus.lang.Language;
 
 /**
- *
- *
  * @author Oleg Gusakov
  * @version $Id$
- *
  */
 public class ResolveTask
-extends AbstractAntTask
+    extends AbstractAntTask
 {
-  private static final Language _lang = new DefaultLanguage( ResolveTask.class );
-  
-  public static final String TASK_NAME = _lang.getMessage( "resolve.task.name" );
-  public static final String TASK_DESC = _lang.getMessage( "resolve.task.desc" );
-  
-  private String _pathId;
-  
-  private String _refPathId;
-  
-  private String _configId;
-  
-  private String _depId;
-  
-  private ArtifactScopeEnum scope = ArtifactScopeEnum.compile;
-  
-  private boolean _failOnError = true;
-  
-  //----------------------------------------------------------------------------------------
-  @Override
-  public String getDescription()
-  {
-    return TASK_DESC;
-  }
-
-  @Override
-  public String getTaskName()
-  {
-    return TASK_NAME;
-  }
-  //----------------------------------------------------------------------------------------
-  @Override
-  public void execute()
-  throws BuildException
-  {
-    if( _configId == null )
+    private static final Language _lang = new DefaultLanguage( ResolveTask.class );
+
+    public static final String TASK_NAME = _lang.getMessage( "resolve.task.name" );
+
+    public static final String TASK_DESC = _lang.getMessage( "resolve.task.desc" );
+
+    private String _pathId;
+
+    private String _fileSetId;
+
+    private String _refPathId;
+
+    private String _configId;
+
+    private String _depId;
+
+    private ArtifactScopeEnum scope = ArtifactScopeEnum.compile;
+
+    private List<Dep.Dependency> _dependencies;
+
+    // ----------------------------------------------------------------------------------------
+    @Override
+    public String getDescription()
     {
-      throwIfEnabled( _lang.getMessage( "config.id.mandatory" ) );
-      return;
+        return TASK_DESC;
     }
-    
-    Object so = getProject().getReference( _configId );
 
-    if( so == null )
+    @Override
+    public String getTaskName()
     {
-      throwIfEnabled( _lang.getMessage( "config.id.object.null", _configId ) );
-      return;
+        return TASK_NAME;
     }
-    
-    if( ! Config.class.isAssignableFrom( so.getClass() ) )
+
+    // ----------------------------------------------------------------------------------------
+    @Override
+    public void execute()
+        throws BuildException
     {
-      throwIfEnabled( _lang.getMessage( "config.id.object.wrong", _configId, so.getClass().getName() ) );
-      return;
-    }
+
+        // Config
+
+        Config config = null;
+        if ( _configId == null )
+        {
+            config = new Config( null, null );
+        }
+        else
+        {
+            Object so = getProject().getReference( _configId );
+    
+            if ( so == null )
+            {
+                throwIfEnabled( _lang.getMessage( "config.id.object.null", _configId ) );
+                return;
+            }
     
-    Config config = (Config)so;
+            if ( !Config.class.isAssignableFrom( so.getClass() ) )
+            {
+                throwIfEnabled( _lang.getMessage( "config.id.object.wrong", _configId, so.getClass().getName() ) );
+                return;
+            }
     
-    if( Util.isEmpty( _pathId ) && Util.isEmpty( _pathId ) )
+            config = (Config) so;
+        }
+
+        // Dependencies
+        Dep dep = null;
+
+        if ( _depId == null && Util.isEmpty( _dependencies ) )
+        {
+            throwIfEnabled( _lang.getMessage( "no.dep.id" ) );
+            return;
+        }
+
+        if ( _depId != null )
+        {
+            Object d = getProject().getReference( _depId );
+
+            if ( d == null )
+            {
+                throwIfEnabled( _lang.getMessage( "no.dep", _depId ) );
+                return;
+            }
+
+            if ( !Dep.class.isAssignableFrom( d.getClass() ) )
+            {
+                throwIfEnabled( _lang.getMessage( "bad.dep", _depId, d.getClass().getName(), Dep.class.getName() ) );
+                return;
+            }
+
+            dep = (Dep) d;
+        }
+        else // inner dependency set
+        {
+            dep = new Dep();
+
+            dep.setList( _dependencies );
+        }
+
+        // Path
+        Path path = null;
+
+        if ( !Util.isEmpty( _pathId ) )
+        {
+            if ( getProject().getReference( _pathId ) != null )
+            {
+                throwIfEnabled( _lang.getMessage( "path.exists", _pathId ) );
+                return;
+            }
+        }
+        else
+        {
+            Object p = getProject().getReference( _refPathId );
+
+            if ( p == null )
+            {
+                throwIfEnabled( _lang.getMessage( "no.path.ref", _refPathId ) );
+                return;
+            }
+
+            path = (Path) p;
+        }
+
+        try
+        {
+            Collection<Repository> repos = config.getRepositories();
+
+            DependencyBuilder db =
+                DependencyBuilderFactory.create( DependencyBuilderFactory.JAVA_DEPENDENCY_MODEL, repos, null, null,
+                                                 null );
+            List<ArtifactMetadata> res = db.resolveConflicts( scope, dep.getList() );
+
+            if ( Util.isEmpty( res ) )
+                return;
+
+            VirtualRepositoryReader vr = new VirtualRepositoryReader( repos );
+
+            ArtifactResults aRes = vr.readArtifacts( res );
+
+            if ( aRes == null )
+                throw new BuildException( _lang.getMessage( "resolve.cannot.read", _configId, res.toString() ) );
+
+            if ( aRes == null || aRes.hasExceptions() )
+            {
+                throwIfEnabled( _lang.getMessage( "vr.error", aRes.getExceptions().toString() ) );
+                return;
+            }
+
+            if ( !aRes.hasResults() )
+                return;
+
+            Map<ArtifactBasicMetadata, List<Artifact>> resMap = aRes.getResults();
+
+            FileList pathFileList = new FileList();
+
+            File dir = null;
+
+            for ( ArtifactBasicMetadata key : resMap.keySet() )
+            {
+                List<Artifact> artifacts = resMap.get( key );
+
+                if ( !Util.isEmpty( artifacts ) )
+                    for ( Artifact a : artifacts )
+                    {
+                        if ( dir == null )
+                            dir = a.getFile().getParentFile();
+
+                        String aPath = a.getFile().getCanonicalPath();
+
+                        FileList.FileName fn = new FileList.FileName();
+
+                        fn.setName( aPath );
+
+                        pathFileList.addConfiguredFile( fn );
+                    }
+            }
+
+            pathFileList.setDir( dir );
+
+            // now - the path
+            if ( path == null )
+            {
+                path = new Path( getProject(), _pathId );
+
+                path.addFilelist( pathFileList );
+
+                getProject().addReference( _pathId, path );
+            }
+            else
+            {
+                Path newPath = new Path( getProject() );
+
+                newPath.addFilelist( pathFileList );
+
+                path.append( newPath );
+            }
+
+        }
+        catch ( Exception e )
+        {
+            if ( _failOnError )
+                throw new BuildException( e.getMessage() );
+            else
+                return;
+        }
+    }
+
+    // attributes
+    public void setConfigid( String configid )
     {
-      throwIfEnabled( _lang.getMessage("no.path.ref") );
-      return;
+        this._configId = configid;
     }
-    
-    Dep dep = null;
-    
-    if( _depId == null )
+
+    public void setPathid( String pathId )
     {
-      throwIfEnabled( _lang.getMessage( "no.dep.id" ) );
-      return;
+        this._pathId = pathId;
     }
-    
-    Object d = getProject().getReference( _depId );
-    
-    if( d == null )
+
+    public void setPathId( String pathId )
     {
-      throwIfEnabled( _lang.getMessage( "no.dep", _depId ) );
-      return;
+        this._pathId = pathId;
     }
-    
-    if( ! Dep.class.isAssignableFrom( d.getClass() )  )
+
+    public void setFilesetid( String fileSetIdId )
     {
-      throwIfEnabled( _lang.getMessage( "bad.dep", _depId, d.getClass().getName(), Dep.class.getName() ) );
-      return;
+        this._fileSetId = fileSetIdId;
     }
-    
-    dep = (Dep)d;
 
-    Path path = null;
-    
-    if( !Util.isEmpty( _pathId ) )
+    public void setFilesetId( String fileSetIdId )
     {
-      if( getProject().getReference( _pathId ) != null )
-      {
-        throwIfEnabled( _lang.getMessage( "path.exists", _pathId ) );
-        return;
-      }
+        this._fileSetId = fileSetIdId;
     }
-    else
+
+    public void setFileSetId( String fileSetIdId )
     {
-      Object p = getProject().getReference( _refPathId );
+        this._fileSetId = fileSetIdId;
+    }
 
-      if( p == null )
-      {
-        throwIfEnabled( _lang.getMessage( "no.path.ref", _refPathId ) );
-        return;
-      }
+    public void setRefpathid( String refPathId )
+    {
+        this._refPathId = refPathId;
+    }
 
-      path = (Path)p;
+    public void setRefpathId( String refPathId )
+    {
+        this._refPathId = refPathId;
     }
-    
-    try
+
+    public void setRefPathId( String refPathId )
     {
-      Collection<Repository> repos = config.getRepositories();
-    
-      DependencyBuilder db = DependencyBuilderFactory.create( DependencyBuilderFactory.JAVA_DEPENDENCY_MODEL
-                                                            , repos
-                                                            , null
-                                                            , null
-                                                            , null 
-                                                            );
-      List<ArtifactMetadata> res = db.resolveConflicts( scope, dep.getList() );
-      
-      if( Util.isEmpty( res ) )
-        return;
-      
-      VirtualRepositoryReader vr = new VirtualRepositoryReader( repos );
-      
-      ArtifactResults aRes = vr.readArtifacts( res );
-      
-      if( aRes == null )
-        throw new BuildException( _lang.getMessage( "resolve.cannot.read", _configId, res.toString() ) );
-      
-      if( aRes == null || aRes.hasExceptions() )
-      {
-        throwIfEnabled( _lang.getMessage( "vr.error", aRes.getExceptions().toString() ) );
-        return;
-      }
-      
-      if( ! aRes.hasResults() )
-        return;
-      
-      Map<ArtifactBasicMetadata, List<Artifact>> resMap = aRes.getResults();
-      
-      FileList pathFileList = new FileList();
-      
-      File dir = null;
-      
-      for( ArtifactBasicMetadata key : resMap.keySet() )
-      {
-        List<Artifact> artifacts = resMap.get( key );
-
-        if( !Util.isEmpty( artifacts )  )
-          for( Artifact a : artifacts )
-          {
-            if( dir == null )
-              dir = a.getFile().getParentFile();
-            
-            String aPath = a.getFile().getCanonicalPath();
-            
-            FileList.FileName fn = new FileList.FileName();
-            
-            fn.setName( aPath );
-            
-            pathFileList.addConfiguredFile( fn );
-          }
-      }
-      
-      pathFileList.setDir( dir );
-
-      // now - the path
-      if( path == null )
-      {
-        path = new Path( getProject(), _pathId );
-        
-        path.addFilelist( pathFileList );
-        
-        getProject().addReference( _pathId, path );
-      }
-      else
-      {
-        Path newPath = new Path( getProject() );
-
-        newPath.addFilelist( pathFileList );
-        
-        path.append( newPath );
-      }
-      
-    }
-    catch( Exception e )
-    {
-      if( _failOnError )
-        throw new BuildException( e.getMessage() );
-      else 
-        return;
-    }
-  }
-
-  public void setConfigid( String configid )
-  {
-    this._configId = configid;
-  }
-
-  public void setPathid( String pathId )
-  {
-    this._pathId = pathId;
-  }
-
-  public void setRefpathid( String refPathId )
-  {
-    this._refPathId = refPathId;
-  }
-  
-  public void setDepid( String depid )
-  {
-    this._depId = depid;
-  }
-
-  public void setScope( ArtifactScopeEnum scope )
-  {
-    this.scope = scope;
-  }
+        this._refPathId = refPathId;
+    }
+
+    public void setDepid( String depid )
+    {
+        this._depId = depid;
+    }
+
+    public void setDepId( String depid )
+    {
+        this._depId = depid;
+    }
+
+    public void setScope( ArtifactScopeEnum scope )
+    {
+        this.scope = scope;
+    }
+
+    public void addConfiguredDependency( Dep.Dependency dependency )
+    {
+        if ( Util.isEmpty( _dependencies ) )
+            _dependencies = new ArrayList<Dep.Dependency>( 8 );
+
+        _dependencies.add( dependency );
+    }
 }
\ No newline at end of file

Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/antlib.xml
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/antlib.xml?rev=728804&r1=728803&r2=728804&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/antlib.xml (original)
+++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/antlib.xml Mon Dec 22 14:10:08 2008
@@ -2,11 +2,11 @@
 
 <antlib>
 
-  <taskdef name="resolve" classname="org.apache.maven.mercury.ant.tasks.ResolveTask"/>
-  <taskdef name="write"   classname="org.apache.maven.mercury.ant.tasks.WriteTask"/>
+  <taskdef name="resolve"      classname="org.apache.maven.mercury.ant.tasks.ResolveTask"/>
+  <taskdef name="dependencies" classname="org.apache.maven.mercury.ant.tasks.ResolveTask"/>
+  <taskdef name="write"        classname="org.apache.maven.mercury.ant.tasks.WriteTask"/>
 
   <typedef name="dep"             classname="org.apache.maven.mercury.ant.tasks.Dep"/>
-  <typedef name="depdependencies" classname="org.apache.maven.mercury.ant.tasks.Dep"/>
   <typedef name="config"          classname="org.apache.maven.mercury.ant.tasks.Config"/>
   
 </antlib>

Modified: maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java?rev=728804&r1=728803&r2=728804&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java (original)
+++ maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java Mon Dec 22 14:10:08 2008
@@ -60,8 +60,8 @@
 public class DefaultSatSolver
 implements SatSolver
 {
-  private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( DefaultSatSolver.class ); 
-  private static final Language LANG = new DefaultLanguage( DefaultSatSolver.class );
+  private static final IMercuryLogger _log = MercuryLoggerManager.getLogger( DefaultSatSolver.class ); 
+  private static final Language _lang = new DefaultLanguage( DefaultSatSolver.class );
   
   protected SatContext _context;
   protected IPBSolver _solver = SolverFactory.newEclipseP2();
@@ -102,7 +102,7 @@
       
       int nNodes = tree.countDistinctNodes();
   
-      LOG.debug( "SatContext: # of variables: "+nNodes );
+      _log.debug( "SatContext: # of variables: "+nNodes );
   
       _context = new SatContext( nNodes );
       _solver.newVar( tree.countNodes() );
@@ -165,15 +165,15 @@
     {
       List<MetadataTreeNode> bucket = buckets.get( key );
   
-// this is needed if optimization is "maximize"       
+// oleg: ? this is needed if optimization is "maximize"       
 //      Collections.reverse(  bucket );
       
       int bucketSize = bucket.size(); 
       
       boolean bigBucket = bucketSize > 1;
 
-if( LOG.isDebugEnabled() )
-  LOG.debug( "\n\nBucket "+key );
+if( _log.isDebugEnabled() )
+    _log.debug( "\n\nBucket "+key );
 
       IVecInt bucketVars = new VecInt( bucketSize );
       
@@ -181,8 +181,8 @@
       {
         MetadataTreeNode n  = bucket.get(i);
 
-if( LOG.isDebugEnabled() )
-  LOG.debug( n.toString() );
+if( _log.isDebugEnabled() )
+    _log.debug( n.toString() );
 
         SatVar var = _context.findOrAdd(n);
         int varLiteral = var.getLiteral(); 
@@ -197,8 +197,8 @@
           
           coeffs.push( BigInteger.valueOf( cf ) );
 
-          if( LOG.isDebugEnabled() )
-            LOG.debug( "    "+cf+" x"+var.getLiteral() );
+if( _log.isDebugEnabled() )
+    _log.debug( "    "+cf+" x"+var.getLiteral() );
         }
 
       }
@@ -216,8 +216,8 @@
         throw new SatException(e);
       }
       
-if( LOG.isDebugEnabled() )
-  LOG.debug( "\n" );
+if( _log.isDebugEnabled() )
+  _log.debug( "\n" );
     }
 
     if( vars.isEmpty() )
@@ -391,8 +391,8 @@
   {
     _solver.addPseudoBoolean( lits, coeff, ge, cardinality );
     
-if( LOG.isDebugEnabled() )
-  LOG.debug("PB: ");
+if( _log.isDebugEnabled() )
+  _log.debug("PB: ");
     
     for( int i=0; i<lits.size(); i++ )
     {
@@ -401,11 +401,11 @@
       int    val = Math.abs(co);
       String space = val == 1 ? "" : " ";
       
-if( LOG.isDebugEnabled() )
-  LOG.debug( " " + sign + (val==1?"":val) + space  + "x"+lits.get(i) );
+if( _log.isDebugEnabled() )
+  _log.debug( " " + sign + (val==1?"":val) + space  + "x"+lits.get(i) );
     }
-if( LOG.isDebugEnabled() )
-  LOG.debug(( ge ? " >= " : " < ")+" "+cardinality );
+if( _log.isDebugEnabled() )
+  _log.debug(( ge ? " >= " : " < ")+" "+cardinality );
   }
   //-----------------------------------------------------------------------
   private final Map<ArtifactBasicMetadata, List<MetadataTreeNode>> processChildren(
@@ -527,23 +527,23 @@
     
     if( optional ) // Sxi >= 0
     {
-if( LOG.isDebugEnabled() )
-  LOG.debug( "optional range: atMost 1: "+ SatHelper.vectorToString( rangeVector) );
+if( _log.isDebugEnabled() )
+  _log.debug( "optional range: atMost 1: "+ SatHelper.vectorToString( rangeVector) );
     
       _solver.addAtMost( rangeVector, 1 );
     }
     else // Sxi = 1
     {
-if( LOG.isDebugEnabled() )
-  LOG.debug( "range: " + SatHelper.vectorToString( rangeVector) );
+if( _log.isDebugEnabled() )
+  _log.debug( "range: " + SatHelper.vectorToString( rangeVector) );
 
     IConstr atLeast = _solver.addAtLeast( rangeVector, 1 );
-    if( LOG.isDebugEnabled() )
-      LOG.debug( "atLeast: " + SatHelper.vectorToString( atLeast) );
+    if( _log.isDebugEnabled() )
+      _log.debug( "atLeast: " + SatHelper.vectorToString( atLeast) );
 
     IConstr atMost  = _solver.addAtMost( rangeVector, 1 );
-    if( LOG.isDebugEnabled() )
-      LOG.debug( "atMost: " + SatHelper.vectorToString( atMost) );
+    if( _log.isDebugEnabled() )
+      _log.debug( "atMost: " + SatHelper.vectorToString( atMost) );
 
     }
     
@@ -567,7 +567,7 @@
         
         int [] model = _solver.model();
 
-if( LOG.isDebugEnabled() )
+if( _log.isDebugEnabled() )
   if( model != null )
   {
     StringBuilder sb = new StringBuilder();
@@ -577,10 +577,10 @@
       sb.append( comma+m );
       comma = ", ";
     }
-    LOG.debug( '['+sb.toString()+']' );
+    _log.debug( '['+sb.toString()+']' );
   }
   else 
-    LOG.debug( "model is null" );
+    _log.debug( "model is null" );
 
         for( int i : model )
           if( i > 0 )
@@ -611,7 +611,7 @@
       {
         int [] model = _solver.model();
 
-if( LOG.isDebugEnabled() )
+if( _log.isDebugEnabled() )
   if( model != null )
   {
     StringBuilder sb = new StringBuilder();
@@ -621,10 +621,10 @@
       sb.append( comma+m );
       comma = ", ";
     }
-    LOG.debug( '['+sb.toString()+']' );
+    _log.debug( '['+sb.toString()+']' );
   }
   else 
-    LOG.debug( "model is null" );
+    _log.debug( "model is null" );
 
         return _context.getSolutionSubtree( _root, model );
       }