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/05/05 18:34:03 UTC

svn commit: r771907 - in /maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src: main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java site/apt/reference.apt test/java/org/apache/maven/artifact/ant/PomTestCase.java

Author: pgier
Date: Tue May  5 16:34:00 2009
New Revision: 771907

URL: http://svn.apache.org/viewvc?rev=771907&view=rev
Log:
[MANTTASKS-142] Improve default remote repository id.

Added:
    maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/java/org/apache/maven/artifact/ant/PomTestCase.java   (with props)
Modified:
    maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java
    maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/reference.apt

Modified: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java?rev=771907&r1=771906&r2=771907&view=diff
==============================================================================
--- maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java (original)
+++ maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java Tue May  5 16:34:00 2009
@@ -19,11 +19,15 @@
  * under the License.
  */
 
+import java.math.BigInteger;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
 import org.apache.maven.model.Repository;
+import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 
 /**
@@ -123,8 +127,51 @@
         return remoteRepositories;
     }
 
-    public void addRemoteRepository( RemoteRepository remoteRepository )
+    /**
+     * This is called automatically by ant when the task is initialized.
+     * Need to use "addConfigured..." instead of "add..." because the 
+     * repository Id and URL need to be set before the method is called.
+     * 
+     * @param remoteRepository
+     */
+    public void addConfiguredRemoteRepository( RemoteRepository remoteRepository )
     {
+        // Validate the url and id parameters before adding the repository
+        if ( remoteRepository.getUrl() == null )
+        {
+            throw new BuildException( "Each remote repository must specify a url." );
+        }
+        if ( remoteRepository.getId() == null || remoteRepository.getId().equals( remoteRepository.getUrl() ) )
+        {
+            log( "Each remote repository should specify a unique id.", Project.MSG_WARN );
+            remoteRepository.setId( generateDefaultRepositoryId( remoteRepository ) );
+        }
         remoteRepositories.add( remoteRepository );
     }
+    
+    public final String MD5_ALGO_NAME = "MD5";
+    
+    /**
+     * Generates an MD5 digest based on the url of the repository.
+     * This is safer to use for the id than the url.  
+     * MANTTASKS-142
+     * 
+     * @param repository
+     * @return
+     */
+    public String generateDefaultRepositoryId( RemoteRepository repository )
+    {
+        try
+        {
+            MessageDigest md = MessageDigest.getInstance( MD5_ALGO_NAME );
+            md.update( repository.getUrl().getBytes() );
+            BigInteger digest = new BigInteger( md.digest() );
+            return digest.toString( 16 );
+        }
+        catch ( NoSuchAlgorithmException e )
+        {
+            log( "Unable to generate unique repository Id: " + e, Project.MSG_WARN );
+            return "default";
+        }
+    }
 }
\ No newline at end of file

Modified: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/reference.apt
URL: http://svn.apache.org/viewvc/maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/reference.apt?rev=771907&r1=771906&r2=771907&view=diff
==============================================================================
--- maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/reference.apt (original)
+++ maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/reference.apt Tue May  5 16:34:00 2009
@@ -186,10 +186,12 @@
 *----------------------+--------------------------------------------------------+--------------+
 | <<Attribute>>        | <<Description>>                                        | <<Required>> |
 *----------------------+--------------------------------------------------------+--------------+
-| <<<layout>>>         | The layout of the remote repository. The valid options are <<<legacy>>> (Maven 1), or <<<default>>> (Maven 2). Defaults to <<<default>>>. | No |
+| <<<id>>>             | A unique ID of the repository.                         | Yes          |
 *----------------------+--------------------------------------------------------+--------------+
 | <<<url>>>            | The URL of the repository.                             | Yes          |
 *----------------------+--------------------------------------------------------+--------------+
+| <<<layout>>>         | The layout of the remote repository. The valid options are <<<legacy>>> (Maven 1), or <<<default>>> (Maven 2). Defaults to <<<default>>>. | No |
+*----------------------+--------------------------------------------------------+--------------+
 
   The <<<remoteRepository>>> can have the following nested elements: <<<releases>>>, <<<snapshots>>>, <<<authentication>>> and <<<proxy>>>.
 

Added: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/java/org/apache/maven/artifact/ant/PomTestCase.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/java/org/apache/maven/artifact/ant/PomTestCase.java?rev=771907&view=auto
==============================================================================
--- maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/java/org/apache/maven/artifact/ant/PomTestCase.java (added)
+++ maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/java/org/apache/maven/artifact/ant/PomTestCase.java Tue May  5 16:34:00 2009
@@ -0,0 +1,21 @@
+package org.apache.maven.artifact.ant;
+
+import junit.framework.TestCase;
+
+public class PomTestCase
+    extends TestCase
+{
+
+    public void testDefaultRepositoryId()
+    {
+        RemoteRepository repo = new RemoteRepository();
+        repo.setUrl( "file:///home/test/stuff" );
+        
+        Pom task = new Pom();
+        String defaultId = task.generateDefaultRepositoryId( repo );
+        if ( defaultId.equals( repo.getUrl() ) )
+        {
+            this.fail( "MD5 digest not calculated" );
+        }
+    }
+}

Propchange: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/java/org/apache/maven/artifact/ant/PomTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/java/org/apache/maven/artifact/ant/PomTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Re: svn commit: r771907 - in /maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src: main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java site/apt/reference.apt test/java/org/apache/maven/artifact/ant/PomTestCase.java

Posted by Paul Gier <pg...@redhat.com>.
Ok, it's done.
Thanks for the suggestions!

Benjamin Bentmann wrote:
> Hi Paul,
> 
>> Author: pgier
>> Date: Tue May  5 16:34:00 2009
>> New Revision: 771907
>>
>> URL: http://svn.apache.org/viewvc?rev=771907&view=rev
>> Log:
>> [MANTTASKS-142] Improve default remote repository id.
>>
>> Added:
>>     
>> maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/java/org/apache/maven/artifact/ant/PomTestCase.java   
>> (with props)
>> Modified:
>>     
>> maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java 
>>
>>     
>> maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/reference.apt
>> [...]
>> +        if ( remoteRepository.getId() == null || 
>> remoteRepository.getId().equals( remoteRepository.getUrl() ) )
>> +        {
>> +            log( "Each remote repository should specify a unique 
>> id.", Project.MSG_WARN );
> 
> Just a cosmetic thing: The mere "should" is maybe a little bit too weak. 
>  I suggest to clearly state that
> 
> Each remote repository must specify a unique id. For 
> backward-compatibility, a default id will be used. In future releases, a 
> missing repository id will raise an error.
> 
> so that users really update their scripts now.
> 
>> +        {
>> +            MessageDigest md = MessageDigest.getInstance( 
>> MD5_ALGO_NAME );
>> +            md.update( repository.getUrl().getBytes() );
> 
> For reproducibility, better use a fixed encoding like UTF-8 when 
> converting the string into a byte sequence.
> 
> Thanks for fixing this,
> 
> 
> Benjamin
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: svn commit: r771907 - in /maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src: main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java site/apt/reference.apt test/java/org/apache/maven/artifact/ant/PomTestCase.java

Posted by Benjamin Bentmann <be...@udo.edu>.
Hi Paul,

> Author: pgier
> Date: Tue May  5 16:34:00 2009
> New Revision: 771907
> 
> URL: http://svn.apache.org/viewvc?rev=771907&view=rev
> Log:
> [MANTTASKS-142] Improve default remote repository id.
> 
> Added:
>     maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/java/org/apache/maven/artifact/ant/PomTestCase.java   (with props)
> Modified:
>     maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java
>     maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/reference.apt
> [...]
> +        if ( remoteRepository.getId() == null || remoteRepository.getId().equals( remoteRepository.getUrl() ) )
> +        {
> +            log( "Each remote repository should specify a unique id.", Project.MSG_WARN );

Just a cosmetic thing: The mere "should" is maybe a little bit too weak. 
  I suggest to clearly state that

Each remote repository must specify a unique id. For 
backward-compatibility, a default id will be used. In future releases, a 
missing repository id will raise an error.

so that users really update their scripts now.

> +        {
> +            MessageDigest md = MessageDigest.getInstance( MD5_ALGO_NAME );
> +            md.update( repository.getUrl().getBytes() );

For reproducibility, better use a fixed encoding like UTF-8 when 
converting the string into a byte sequence.

Thanks for fixing this,


Benjamin


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org