maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ogusa...@apache.org
Subject svn commit: r728843 - in /maven/mercury/trunk: mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/ mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/
Date Tue, 23 Dec 2008 01:46:10 GMT
Author: ogusakov
Date: Mon Dec 22 17:46:10 2008
New Revision: 728843

URL: http://svn.apache.org/viewvc?rev=728843&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/Dep.java
    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/java/org/apache/maven/mercury/ant/tasks/WriteTask.java
    maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MavenVersionRange.java
    maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java

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=728843&r1=728842&r2=728843&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 17:46:10 2008
@@ -1,84 +1,178 @@
 package org.apache.maven.mercury.ant.tasks;
 
+import java.io.File;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.maven.mercury.artifact.Artifact;
 import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.artifact.ArtifactScopeEnum;
+import org.apache.maven.mercury.metadata.DependencyBuilder;
+import org.apache.maven.mercury.metadata.DependencyBuilderFactory;
+import org.apache.maven.mercury.repository.api.ArtifactResults;
+import org.apache.maven.mercury.repository.api.Repository;
+import org.apache.maven.mercury.repository.virtual.VirtualRepositoryReader;
 import org.apache.maven.mercury.util.Util;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.FileList;
+import org.apache.tools.ant.types.ResourceCollection;
 import org.codehaus.plexus.lang.DefaultLanguage;
 import org.codehaus.plexus.lang.Language;
 
 /**
- *
- *
  * @author Oleg Gusakov
  * @version $Id$
- *
  */
 public class Dep
 extends AbstractDataType
+implements ResourceCollection
 {
-  private static final Language LANG = new DefaultLanguage( Dep.class );
-  
-  private List<Dependency> _dependencies;
-  
-  private boolean _transitive = true;
-  
-  public void setTransitive( boolean val )
-  {
-    this._transitive = val;
-  }
-  
-  protected void setList( List<Dependency> dependencies )
-  {
-      _dependencies = dependencies;
-  }
-  
-  protected List<ArtifactBasicMetadata> getList()
-  {
-    if( Util.isEmpty( _dependencies ) )
-      return null;
-    
-    List<ArtifactBasicMetadata> res = new ArrayList<ArtifactBasicMetadata>( _dependencies.size()
);
+    private static final Language _lang = new DefaultLanguage( Dep.class );
 
-    for( Dependency d : _dependencies )
-      res.add( d._amd );
+    private List<Dependency> _dependencies;
     
-    return res;
-  }
+    private List<Artifact> _artifacts;
 
-  public Dependency createDependency()
-  {
-    if( _dependencies == null )
-      _dependencies = new ArrayList<Dependency>(8);
-    
-    Dependency dep = new Dependency();
-    
-    _dependencies.add( dep );
-    
-    return dep;
-  }
+    private boolean _transitive = true;
 
-  public class Dependency
-  {
-    ArtifactBasicMetadata _amd;
-    
-    boolean _optional = false;
+    public void setTransitive( boolean val )
+    {
+        this._transitive = val;
+    }
 
-    public void setName( String name )
+    protected void setList( List<Dependency> dependencies )
     {
-      _amd = new ArtifactBasicMetadata( name );
+        _dependencies = dependencies;
+    }
 
-      _amd.setOptional( _optional );
+    protected List<ArtifactBasicMetadata> getDependencies()
+    {
+        if ( Util.isEmpty( _dependencies ) )
+            return null;
+
+        List<ArtifactBasicMetadata> res = new ArrayList<ArtifactBasicMetadata>(
_dependencies.size() );
+
+        for ( Dependency d : _dependencies )
+            res.add( d._amd );
+
+        return res;
     }
 
-    public void setOptional( boolean optional )
+    public Dependency createDependency()
     {
-      this._optional = optional;
+        if ( _dependencies == null )
+            _dependencies = new ArrayList<Dependency>( 8 );
+
+        Dependency dep = new Dependency();
 
-      if( _amd != null )
-        _amd.setOptional( optional );
+        _dependencies.add( dep );
+
+        return dep;
+    }
+
+    public class Dependency
+    {
+        ArtifactBasicMetadata _amd;
+
+        boolean _optional = false;
+
+        public void setName( String name )
+        {
+            _amd = new ArtifactBasicMetadata( name );
+
+            _amd.setOptional( _optional );
+        }
+
+        public void setOptional( boolean optional )
+        {
+            this._optional = optional;
+
+            if ( _amd != null )
+                _amd.setOptional( optional );
+        }
+
+    }
+    //----------------------------------------------------------------------------------------
+    protected List<Artifact> resolve( Config config, ArtifactScopeEnum scope )
+    throws Exception
+    {
+        if( ! Util.isEmpty(_artifacts) )
+            return _artifacts;
+        
+        if( Util.isEmpty( _dependencies ) )
+            return null;
+
+        Collection<Repository> repos = config.getRepositories();
+
+        DependencyBuilder db =
+            DependencyBuilderFactory.create( DependencyBuilderFactory.JAVA_DEPENDENCY_MODEL,
repos, null, null, null );
+        
+        List<ArtifactMetadata> res = db.resolveConflicts( scope, getDependencies()
);
+
+        if ( Util.isEmpty( res ) )
+            return null;
+
+        VirtualRepositoryReader vr = new VirtualRepositoryReader( repos );
+
+        ArtifactResults aRes = vr.readArtifacts( res );
+
+        if ( aRes == null )
+            throw new BuildException( _lang.getMessage( "resolve.cannot.read", config.getId(),
res.toString() ) );
+
+        if ( aRes == null || aRes.hasExceptions() )
+        {
+            throw new Exception( _lang.getMessage( "vr.error", aRes.getExceptions().toString()
) );
+        }
+
+        if ( !aRes.hasResults() )
+            return null;
+        
+
+        Map<ArtifactBasicMetadata, List<Artifact>> resMap = aRes.getResults();
+        
+        int count = 0;
+        for ( ArtifactBasicMetadata key : resMap.keySet() )
+        {
+            List<Artifact> artifacts = resMap.get( key );
+            if( artifacts != null )
+                count += artifacts.size();
+        }
+        
+        if( count == 0 )
+            return null;
+        
+        _artifacts = new ArrayList<Artifact>( count );
+
+        for ( ArtifactBasicMetadata key : resMap.keySet() )
+        {
+            List<Artifact> artifacts = resMap.get( key );
+
+            if ( !Util.isEmpty( artifacts ) )
+                for ( Artifact a : artifacts )
+                    _artifacts.add( a );
+        }
+        
+        
+        return _artifacts;
+    }
+    //----------------------------------------------------------------------------------------
+    public boolean isFilesystemOnly()
+    {
+        return true;
+    }
+
+    public Iterator iterator()
+    {
+        return null;
+    }
+
+    public int size()
+    {
+        // TODO Auto-generated method stub
+        return 0;
     }
-    
-  }
 }
\ No newline at end of file

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=728843&r1=728842&r2=728843&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 17:46:10 2008
@@ -27,7 +27,7 @@
  * @version $Id$
  */
 public class ResolveTask
-    extends AbstractAntTask
+extends AbstractAntTask
 {
     private static final Language _lang = new DefaultLanguage( ResolveTask.class );
 
@@ -154,56 +154,27 @@
 
         try
         {
-            Collection<Repository> repos = config.getRepositories();
+            Collection<Artifact> artifacts = dep.resolve( config, scope );
 
-            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() )
+            if ( artifacts == null )
                 return;
 
-            Map<ArtifactBasicMetadata, List<Artifact>> resMap = aRes.getResults();
-
             FileList pathFileList = new FileList();
 
             File dir = null;
 
-            for ( ArtifactBasicMetadata key : resMap.keySet() )
+            for ( Artifact a : artifacts )
             {
-                List<Artifact> artifacts = resMap.get( key );
-
-                if ( !Util.isEmpty( artifacts ) )
-                    for ( Artifact a : artifacts )
-                    {
-                        if ( dir == null )
-                            dir = a.getFile().getParentFile();
+                if ( dir == null )
+                    dir = a.getFile().getParentFile();
 
-                        String aPath = a.getFile().getCanonicalPath();
+                String aPath = a.getFile().getCanonicalPath();
 
-                        FileList.FileName fn = new FileList.FileName();
+                FileList.FileName fn = new FileList.FileName();
 
-                        fn.setName( aPath );
+                fn.setName( aPath );
 
-                        pathFileList.addConfiguredFile( fn );
-                    }
+                pathFileList.addConfiguredFile( fn );
             }
 
             pathFileList.setDir( dir );

Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/WriteTask.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/WriteTask.java?rev=728843&r1=728842&r2=728843&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/WriteTask.java
(original)
+++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/WriteTask.java
Mon Dec 22 17:46:10 2008
@@ -24,10 +24,10 @@
 public class WriteTask
 extends AbstractAntTask
 {
-  private static final Language LANG = new DefaultLanguage( WriteTask.class );
+  private static final Language _lang = new DefaultLanguage( WriteTask.class );
   
-  public static final String TASK_NAME = LANG.getMessage( "write.task.name" );
-  public static final String TASK_DESC = LANG.getMessage( "write.task.desc" );
+  public static final String TASK_NAME = _lang.getMessage( "write.task.name" );
+  public static final String TASK_DESC = _lang.getMessage( "write.task.desc" );
   
   private String _repoid;
   private String _file;
@@ -82,7 +82,7 @@
   {
     if( _repoid == null )
     {
-      throwIfEnabled( LANG.getMessage( "write.repo.id.mandatory" ) );
+      throwIfEnabled( _lang.getMessage( "write.repo.id.mandatory" ) );
       return;
     }
     
@@ -90,13 +90,13 @@
     
     if( repo == null )
     {
-      throwIfEnabled( LANG.getMessage( "write.repo.not.found", _repoid ) );
+      throwIfEnabled( _lang.getMessage( "write.repo.not.found", _repoid ) );
       return;
     }
     
     if( _file == null )
     {
-      throwIfEnabled( LANG.getMessage( "write.file.mandatory" ) );
+      throwIfEnabled( _lang.getMessage( "write.file.mandatory" ) );
       return;
     }
     
@@ -104,25 +104,25 @@
     
     if( !file.exists() )
     {
-      throwIfEnabled( LANG.getMessage( "write.file.not.found", _file, _repoid ) );
+      throwIfEnabled( _lang.getMessage( "write.file.not.found", _file, _repoid ) );
       return;
     }
     
     if( Util.isEmpty( _name ) && Util.isEmpty( _pom ) )
     {
-      throwIfEnabled( LANG.getMessage( "write.no.name.no.pom", _file, _repoid ) );
+      throwIfEnabled( _lang.getMessage( "write.no.name.no.pom", _file, _repoid ) );
       return;
     }
 
     if( !Util.isEmpty( _name ) && !Util.isEmpty( _pom ) )
     {
-      throwIfEnabled( LANG.getMessage( "write.no.name.no.pom", _file, _repoid ) );
+      throwIfEnabled( _lang.getMessage( "write.no.name.no.pom", _file, _repoid ) );
       return;
     }
 
     if( !Util.isEmpty( _pom ) )
     {
-      throwIfEnabled( LANG.getMessage( "write.pom.not.supported", _file, _repoid ) );
+      throwIfEnabled( _lang.getMessage( "write.pom.not.supported", _file, _repoid ) );
       return;
     }
 
@@ -157,7 +157,7 @@
       }
       else
       {
-        throwIfEnabled( LANG.getMessage( "write.pom.not.supported", _file, _repoid ) );
+        throwIfEnabled( _lang.getMessage( "write.pom.not.supported", _file, _repoid ) );
         return;
       }
         

Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MavenVersionRange.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MavenVersionRange.java?rev=728843&r1=728842&r2=728843&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MavenVersionRange.java
(original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MavenVersionRange.java
Mon Dec 22 17:46:10 2008
@@ -44,7 +44,7 @@
   private boolean _osgiVersion = Boolean.parseBoolean( System.getProperty( SYSTEM_PARAMETER_OSGI_VERSION,
SYSTEM_PARAMETER_OSGI_VERSION_DEFAULT ) );
 
   private static final DefaultArtifactVersion ZERO_VERSION = new DefaultArtifactVersion("0.0.0");
-  private static final Language LANG = new DefaultLanguage( MavenVersionRange.class );
+  private static final Language _lang = new DefaultLanguage( MavenVersionRange.class );
   
   QualityRange _toQualityRange = QualityRange.ALL;
   
@@ -79,14 +79,14 @@
       else if( range.startsWith("(") )
         _fromInclusive = false;
       else
-        throw new VersionException( LANG.getMessage( "invalid.maven.version.range", range
) );
+        throw new VersionException( _lang.getMessage( "invalid.maven.version.range", range
) );
 
       if( range.endsWith("]") )
         _toInclusive = true;
       else if( range.endsWith(")") )
         _toInclusive = false;
       else
-        throw new VersionException( LANG.getMessage( "invalid.maven.version.range", range
) );
+        throw new VersionException( _lang.getMessage( "invalid.maven.version.range", range
) );
       
       int ind = range.indexOf(',');
 
@@ -102,7 +102,7 @@
           if( vq.getQuality().equals( QualityEnum.snapshot )
               || vq.getQuality().equals( QualityEnum.unknown )
           )
-              throw new VersionException( LANG.getMessage( "bad.version.sn", sFromT ) );
+              throw new VersionException( _lang.getMessage( "bad.version.sn", sFromT ) );
           
           _fromVersion = new DefaultArtifactVersion( sFromT );
         }
@@ -120,10 +120,10 @@
       }
       
       if( _fromVersion == null && _fromInclusive )
-        throw new VersionException( LANG.getMessage( "invalid.maven.version.range.bad.from",
range ) );
+        throw new VersionException( _lang.getMessage( "invalid.maven.version.range.bad.from",
range ) );
       
       if( _toVersion == null && _toInclusive )
-        throw new VersionException( LANG.getMessage( "invalid.maven.version.range.bad.to",
range ) );
+        throw new VersionException( _lang.getMessage( "invalid.maven.version.range.bad.to",
range ) );
       
     }
     else
@@ -173,7 +173,7 @@
       if( c == '-' || c == '_' )
         continue;
       
-      throw new VersionException( LANG.getMessage( "invalid.character", ""+c, v ) );
+      throw new VersionException( _lang.getMessage( "invalid.character", ""+c, v ) );
     }
   }
   //--------------------------------------------------------------------------------------------

Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java?rev=728843&r1=728842&r2=728843&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java
(original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java
Mon Dec 22 17:46:10 2008
@@ -34,12 +34,12 @@
 public class MetadataVersionComparator
 implements Comparator<ArtifactBasicMetadata>
 {
-  private static final Language LANG = new DefaultLanguage( MetadataVersionComparator.class
);
+  private static final Language _lang = new DefaultLanguage( MetadataVersionComparator.class
);
   
   public int compare( ArtifactBasicMetadata v1, ArtifactBasicMetadata v2 )
   {
     if( v1 == null || v2 == null )
-      throw new IllegalArgumentException( LANG.getMessage( "null.version.to.compare", v1
== null ? "null" : v1.toString(), v2 == null ? "null" : v2.toString() )  );
+      throw new IllegalArgumentException( _lang.getMessage( "null.version.to.compare", v1
== null ? "null" : v1.toString(), v2 == null ? "null" : v2.toString() )  );
     
     DefaultArtifactVersion av1 = new DefaultArtifactVersion( v1.getVersion() );
     DefaultArtifactVersion av2 = new DefaultArtifactVersion( v2.getVersion() );



Mime
View raw message