You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by pg...@apache.org on 2009/07/09 21:40:39 UTC

svn commit: r792652 - in /maven/ant-tasks/trunk/src: main/java/org/apache/maven/artifact/ant/ site/apt/ site/apt/examples/

Author: pgier
Date: Thu Jul  9 19:40:39 2009
New Revision: 792652

URL: http://svn.apache.org/viewvc?rev=792652&view=rev
Log:
[MANTTASKS-156] Add documentation and do some minor refactoring.

Modified:
    maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java
    maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java
    maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DeployTask.java
    maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java
    maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallTask.java
    maven/ant-tasks/trunk/src/site/apt/examples/dependencies.apt
    maven/ant-tasks/trunk/src/site/apt/reference.apt

Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java?rev=792652&r1=792651&r2=792652&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java Thu Jul  9 19:40:39 2009
@@ -533,28 +533,22 @@
         return container;
     }
 
-    public Pom buildPom( ArtifactRepository localArtifactRepository )
+    /**
+     * Tries to initialize the pom.  If no pom has been configured, returns null.
+     * 
+     * @param localArtifactRepository
+     * @return An initialized pom or null.
+     */
+    public Pom initializePom( ArtifactRepository localArtifactRepository )
     {
-        if ( pomRefId != null && this.pom != null )
-        {
-            throw new BuildException( "You cannot specify both a POM element and a pomrefid element" );
-        }
-
-        Pom pom = this.pom;
-        if ( pomRefId != null )
-        {
-            pom = (Pom) getProject().getReference( pomRefId );
-            if ( pom == null )
-            {
-                throw new BuildException( "Reference '" + pomRefId + "' was not found." );
-            }
-        }
 
+        Pom pom = getPom();
         if ( pom != null )
         {
             MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
             pom.initialise( projectBuilder, localArtifactRepository );
         }
+        
         return pom;
     }
 
@@ -637,6 +631,34 @@
     {
         this.pom = pom;
     }
+    
+    /**
+     * Try to get the POM from the nested pom element or a pomRefId
+     * 
+     * @return The pom object
+     */
+    public Pom getPom()
+    {
+        if ( pom != null && getPomRefId() != null )
+        {
+            throw new BuildException( "You cannot specify both a POM element and a pomrefid element" );
+        }
+
+        if ( getPomRefId() != null )
+        {
+            Object pomRefObj = getProject().getReference( getPomRefId() );
+            if ( pomRefObj instanceof Pom )
+            {
+                pom = (Pom) pomRefObj;
+            }
+            else
+            {
+                throw new BuildException( "Reference '" + pomRefId + "' was not found." );
+            }
+        }
+        
+        return pom;
+    }
 
     public String getPomRefId()
     {
@@ -905,5 +927,5 @@
             return false;
         }
     }
-        
+
 }

Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java?rev=792652&r1=792651&r2=792652&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java Thu Jul  9 19:40:39 2009
@@ -48,9 +48,7 @@
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Enumeration;
 import java.util.HashSet;
-import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -92,8 +90,14 @@
     
     private boolean addArtifactFileSetRefs;
     
-    private String cacheBuildFile;
-    
+    /**
+     * The file name to use for the generated Ant build that contains dependency properties and references.
+     */
+    private String dependencyRefsBuildFile;
+
+    /**
+     * Whether to use a generated Ant build file to cache the list of dependency properties and references.
+     */
     private boolean cacheDependencyRefs;
 
     protected void doExecute()
@@ -108,13 +112,13 @@
         // Try to load dependency refs from Ant
         if ( isCacheDependencyRefs() )
         {
-            if ( getCacheBuildFile() == null )
+            if ( getDependencyRefsBuildFile() == null )
             {
-                setCacheBuildFile( DEFAULT_ANT_BUILD_FILE );
+                setDependencyRefsBuildFile( DEFAULT_ANT_BUILD_FILE );
             }
             if ( checkCachedDependencies() )
             {
-                log( "Dependency refs loaded from file: " + getCacheBuildFile(), Project.MSG_VERBOSE );
+                log( "Dependency refs loaded from file: " + getDependencyRefsBuildFile(), Project.MSG_VERBOSE );
                 return;
             }
         }
@@ -128,7 +132,7 @@
 
         List dependencies = this.dependencies;
 
-        Pom pom = buildPom( localRepo );
+        Pom pom = initializePom( localRepo );
         if ( pom != null )
         {
             if ( !dependencies.isEmpty() )
@@ -264,15 +268,15 @@
         }
         
         // Write the dependency references out to a file.
-        if ( getCacheBuildFile() != null || this.isCacheDependencyRefs() )
+        if ( getDependencyRefsBuildFile() != null || this.isCacheDependencyRefs() )
         {
-            if ( getCacheBuildFile() == null || getCacheBuildFile().equals( "default" ) )
+            if ( getDependencyRefsBuildFile() == null || getDependencyRefsBuildFile().equals( "default" ) )
             {
-                setCacheBuildFile( DEFAULT_ANT_BUILD_FILE );
+                setDependencyRefsBuildFile( DEFAULT_ANT_BUILD_FILE );
             }
-            log( "Building ant file: " + getCacheBuildFile());
+            log( "Building ant file: " + getDependencyRefsBuildFile());
             AntBuildWriter antBuildWriter = new AntBuildWriter();
-            File antBuildFile = new File( getProject().getBaseDir(), getCacheBuildFile() );
+            File antBuildFile = new File( getProject().getBaseDir(), getDependencyRefsBuildFile() );
             try 
             {
                 antBuildWriter.openAntBuild( antBuildFile, "maven-dependencies", "init-dependencies" );
@@ -320,19 +324,35 @@
         }
     }
     
+    /**
+     * Check if the cache needs to be updated.
+     * 
+     * @return true if the dependency refs were successfully loaded, false otherwise
+     */
     private boolean checkCachedDependencies()
     {
-        File cacheBuildFile = new File( getProject().getBaseDir(), getCacheBuildFile() );
+        File cacheBuildFile = new File( getProject().getBaseDir(), getDependencyRefsBuildFile() );
         if ( ! cacheBuildFile.exists() )
         {
             return false;
         }
+        
         File antBuildFile = new File( getProject().getProperty( "ant.file" ) );
         if ( antBuildFile.lastModified() > cacheBuildFile.lastModified() )
         {
             return false;
         }
         
+        Pom pom = getPom();
+        if ( pom != null )
+        {
+            File pomFile = pom.getFile();
+            if ( pomFile == null || ( pomFile.lastModified() > cacheBuildFile.lastModified() ) )
+            {
+                return false;
+            }
+        }
+        
         return loadDependenciesFromAntBuildFile();
     }
     
@@ -347,7 +367,7 @@
         
         // Run the ant build with the dependency refs
         AntTaskModified dependenciesAntBuild = new AntTaskModified();
-        dependenciesAntBuild.setAntfile( getCacheBuildFile() );
+        dependenciesAntBuild.setAntfile( getDependencyRefsBuildFile() );
         dependenciesAntBuild.setProject( currentAntProject );
         dependenciesAntBuild.execute();
         
@@ -557,14 +577,14 @@
         this.addArtifactFileSetRefs = addArtifactFileSetRefs;
     }
 
-    public String getCacheBuildFile()
+    public String getDependencyRefsBuildFile()
     {
-        return cacheBuildFile;
+        return dependencyRefsBuildFile;
     }
 
-    public void setCacheBuildFile( String cacheBuildFile )
+    public void setDependencyRefsBuildFile( String dependencyRefsBuildFile )
     {
-        this.cacheBuildFile = cacheBuildFile;
+        this.dependencyRefsBuildFile = dependencyRefsBuildFile;
     }
 
     public boolean isCacheDependencyRefs()

Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DeployTask.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DeployTask.java?rev=792652&r1=792651&r2=792652&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DeployTask.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DeployTask.java Thu Jul  9 19:40:39 2009
@@ -90,7 +90,7 @@
     {
         ArtifactRepository localRepo = createLocalArtifactRepository();
 
-        Pom pom = buildPom( localRepo );
+        Pom pom = initializePom( localRepo );
 
         if ( pom == null )
         {

Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java?rev=792652&r1=792651&r2=792652&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java Thu Jul  9 19:40:39 2009
@@ -49,9 +49,9 @@
         this.file = file;
     }
     
-    public Pom buildPom( ArtifactRepository localArtifactRepository )
+    public Pom initializePom( ArtifactRepository localArtifactRepository )
     {
-        Pom pom = super.buildPom( localArtifactRepository );
+        Pom pom = super.initializePom( localArtifactRepository );
 
         // attach artifacts
         if ( attachedArtifacts != null )

Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallTask.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallTask.java?rev=792652&r1=792651&r2=792652&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallTask.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallTask.java Thu Jul  9 19:40:39 2009
@@ -43,7 +43,7 @@
     {
         ArtifactRepository localRepo = createLocalArtifactRepository();
 
-        Pom pom = buildPom( localRepo );
+        Pom pom = initializePom( localRepo );
 
         if ( pom == null )
         {

Modified: maven/ant-tasks/trunk/src/site/apt/examples/dependencies.apt
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/site/apt/examples/dependencies.apt?rev=792652&r1=792651&r2=792652&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/site/apt/examples/dependencies.apt (original)
+++ maven/ant-tasks/trunk/src/site/apt/examples/dependencies.apt Thu Jul  9 19:40:39 2009
@@ -181,3 +181,33 @@
 -----
 
   By default all artifact types will be included when building the list of dependencies.
+
+  
+Generating an Ant build with the dependency properties and references 
+
+  <(Since 2.1.0)>  For a project with a large dependency tree, the resolution process can take some time.
+  In these cases, the dependencies task provides an option to generate an Ant build file (called build-dependencies.xml
+  by default) that contains properties and references generated by the dependency resolution.  This file can be 
+  used as a cache to quicly load the paths to the dependency artifacts.  Or it can be used directly in
+  other ant build files via the <<import>> task.
+  
+  There are two parameters to the dependencies task related to this feature <<cacheDependencyRefs>> and 
+  <<dependencyRefsBuildFile>>.  The first is a boolean parameter to say whether the build file should be
+  generated.  By default the file will be created as "./target/build-dependencies.xml".  The second parameter
+  allows the default file name to be changed.
+  
+  For example, to turn on the dependency cache, the following configuration could be used.
+  
+-----
+    <artifact:dependencies cacheDependencyRefs="true">
+      <pom file="mypom.xml"/>
+    </artifact:dependencies>
+-----
+
+  The first time the build is run, the dependencies will be resolved from the repository, and the task
+  will generate a file called "build-dependencies.xml".  This file contains a list of the properties
+  and fileset references generated during the build.  The next time the build is run, the dependency
+  references will simply be loaded from the generate file. 
+  
+  
+  

Modified: maven/ant-tasks/trunk/src/site/apt/reference.apt
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/site/apt/reference.apt?rev=792652&r1=792651&r2=792652&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/site/apt/reference.apt (original)
+++ maven/ant-tasks/trunk/src/site/apt/reference.apt Thu Jul  9 19:40:39 2009
@@ -66,6 +66,10 @@
 *-------------------------+---------------------------------------------------------------------------+--------------+-------------+
 | <<<addArtifactFileSetRefs>>> | If set to true, will add a fileset for each resolved dependency.  The fileset has an id of <<<groupId:artifactId:type[:classifier]>>>.  Default is <false>.  | No | 2.0.10 |
 *-------------------------+---------------------------------------------------------------------------+--------------+-------------+
+| <<<cacheDependencyRefs>>> | If set to true, will generate an Ant build file that contains properties and fileset references for the dependencies.  Then try to load information from this file in subsequent builds.  Default is <false>.  | No | 2.1.0 |
+*-------------------------+---------------------------------------------------------------------------+--------------+-------------+
+| <<<addArtifactFileSetRefs>>> | Defines the name of the file in which to store properties and references to the paths of dependency artifacts.  Default is <false>.  | No | 2.1.0 |
+*-------------------------+---------------------------------------------------------------------------+--------------+-------------+
 
   The task can include the <<<dependency>>> nested type, in addition to the other shared types
   {{{reference.html#localRepository} <<<localRepository>>>}}, {{{reference.html#pom} <<<pom>>>}} and