You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ep...@apache.org on 2006/02/02 09:52:34 UTC
svn commit: r374306 - in
/maven/repository-manager/trunk/maven-repository-utils: pom.xml
src/main/java/org/apache/maven/repository/ArtifactUtils.java
src/test/java/org/apache/maven/repository/ArtifactUtilsTest.java
Author: epunzalan
Date: Thu Feb 2 00:52:25 2006
New Revision: 374306
URL: http://svn.apache.org/viewcvs?rev=374306&view=rev
Log:
PR: MRM-43
Added unit tests for ArtifactUtils.java
Added:
maven/repository-manager/trunk/maven-repository-utils/src/test/java/org/apache/maven/repository/ArtifactUtilsTest.java
Modified:
maven/repository-manager/trunk/maven-repository-utils/pom.xml
maven/repository-manager/trunk/maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java
Modified: maven/repository-manager/trunk/maven-repository-utils/pom.xml
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-utils/pom.xml?rev=374306&r1=374305&r2=374306&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-utils/pom.xml (original)
+++ maven/repository-manager/trunk/maven-repository-utils/pom.xml Thu Feb 2 00:52:25 2006
@@ -27,6 +27,10 @@
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
Modified: maven/repository-manager/trunk/maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java?rev=374306&r1=374305&r2=374306&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java (original)
+++ maven/repository-manager/trunk/maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java Thu Feb 2 00:52:25 2006
@@ -35,6 +35,19 @@
public static Artifact buildArtifact( File repositoryBase, String path, ArtifactRepository repository,
ArtifactFactory artifactFactory )
{
+ Artifact artifact = buildArtifact( path, artifactFactory );
+
+ if ( artifact != null )
+ {
+ artifact.setRepository( repository );
+ artifact.setFile( new File( repositoryBase, path ) );
+ }
+
+ return artifact;
+ }
+
+ public static Artifact buildArtifact( String path, ArtifactFactory artifactFactory )
+ {
List pathParts = new ArrayList();
StringTokenizer st = new StringTokenizer( path, "/\\" );
while ( st.hasMoreTokens() )
@@ -175,12 +188,6 @@
}
}
}
- }
-
- if ( finalResult != null )
- {
- finalResult.setRepository( repository );
- finalResult.setFile( new File( repositoryBase, path ) );
}
return finalResult;
Added: maven/repository-manager/trunk/maven-repository-utils/src/test/java/org/apache/maven/repository/ArtifactUtilsTest.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-utils/src/test/java/org/apache/maven/repository/ArtifactUtilsTest.java?rev=374306&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-utils/src/test/java/org/apache/maven/repository/ArtifactUtilsTest.java (added)
+++ maven/repository-manager/trunk/maven-repository-utils/src/test/java/org/apache/maven/repository/ArtifactUtilsTest.java Thu Feb 2 00:52:25 2006
@@ -0,0 +1,226 @@
+package org.apache.maven.repository;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class ArtifactUtilsTest
+ extends PlexusTestCase
+{
+ private ArtifactFactory factory;
+
+ protected void tearDown()
+ throws Exception
+ {
+ container.release( factory );
+
+ super.tearDown();
+ }
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ factory = (ArtifactFactory) container.lookup( ArtifactFactory.ROLE );
+ }
+
+ public void testShortPath()
+ throws ComponentLookupException
+ {
+ String testPath = "invalid/invalid-1.0.jar";
+
+ Artifact artifact = getArtifactFromPath( testPath );
+
+ assertNull( "Artifact should be null for short paths", artifact );
+ }
+
+ public void testWrongArtifactId()
+ throws ComponentLookupException
+ {
+ String testPath = "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar";
+
+ Artifact artifact = getArtifactFromPath( testPath );
+
+ assertNull( "Artifact should be null for wrong ArtifactId", artifact );
+ }
+
+ public void testNoType()
+ throws ComponentLookupException
+ {
+ String testPath = "invalid/invalid/1/invalid-1";
+
+ Artifact artifact = getArtifactFromPath( testPath );
+
+ assertNull( "Artifact should be null for no type", artifact );
+ }
+
+ public void testWrongVersion()
+ throws ComponentLookupException
+ {
+ String testPath = "invalid/invalid/1.0/invalid-2.0.jar";
+
+ Artifact artifact = getArtifactFromPath( testPath );
+
+ assertNull( "Artifact should be null for wrong version", artifact );
+ }
+
+ public void testLongVersion()
+ throws ComponentLookupException
+ {
+ String testPath = "invalid/invalid/1.0/invalid-1.0b.jar";
+
+ Artifact artifact = getArtifactFromPath( testPath );
+
+ assertNull( "Artifact should be null for long version", artifact );
+ }
+
+ public void testWrongSnapshotVersion()
+ throws ComponentLookupException
+ {
+ String testPath = "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar";
+
+ Artifact artifact = getArtifactFromPath( testPath );
+
+ assertNull( "Artifact should be null for wrong snapshot version", artifact );
+ }
+
+ public void testSnapshotBaseVersion()
+ throws ComponentLookupException
+ {
+ String testPath = "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar";
+
+ Artifact artifact = getArtifactFromPath( testPath );
+
+ assertNull( "Artifact should be null for snapshot base version", artifact );
+ }
+
+ public void testPathWithClassifier()
+ throws ComponentLookupException
+ {
+ String testPath = "org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar";
+
+ Artifact artifact = getArtifactFromPath( testPath );
+
+ assertNotNull( "Artifact path with classifier error", artifact );
+
+ assertEquals( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ), artifact );
+ }
+
+ public void testWithJavaSourceInclusion()
+ throws ComponentLookupException
+ {
+ String testPath = "org/apache/maven/testing/1.0/testing-1.0-sources.jar";
+
+ Artifact artifact = getArtifactFromPath( testPath );
+
+ assertNotNull( "Artifact path with java source inclusion error", artifact );
+
+ assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ), artifact );
+ }
+
+ public void testDistributionArtifacts()
+ throws ComponentLookupException
+ {
+ String testPath = "org/apache/maven/testing/1.0/testing-1.0.tar.gz";
+
+ Artifact artifact = getArtifactFromPath( testPath );
+
+ assertNotNull( "tar.gz distribution artifact error", artifact );
+
+ assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ), artifact );
+
+ testPath = "org/apache/maven/testing/1.0/testing-1.0.zip";
+
+ artifact = getArtifactFromPath( testPath );
+
+ assertNotNull( "zip distribution artifact error", artifact );
+
+ assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ), artifact );
+ }
+
+ public void testSnapshot()
+ throws ComponentLookupException
+ {
+ String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar";
+
+ Artifact artifact = getArtifactFromPath( testPath );
+
+ assertNotNull( "Artifact path with invalid snapshot error", artifact );
+
+ assertEquals( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ), artifact );
+
+ testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar";
+
+ artifact = getArtifactFromPath( testPath );
+
+ assertNotNull( "Artifact path with snapshot error", artifact );
+
+ assertEquals( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1" ), artifact );
+ }
+
+ public void testNormal()
+ throws ComponentLookupException
+ {
+ String testPath = "javax/sql/jdbc/2.0/jdbc-2.0.jar";
+
+ Artifact artifact = getArtifactFromPath( testPath );
+
+ assertNotNull( "Normal artifact path error", artifact );
+
+ assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact );
+ }
+
+ public void testSnapshotWithClassifier()
+ throws ComponentLookupException
+ {
+ String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar";
+
+ Artifact artifact = getArtifactFromPath( testPath );
+
+ assertNotNull( "Artifact path with snapshot and classifier error", artifact );
+
+ assertEquals( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1", "jar", "javadoc" ), artifact );
+ }
+
+ private Artifact getArtifactFromPath( String path )
+ throws ComponentLookupException
+ {
+ return ArtifactUtils.buildArtifact( path, factory );
+ }
+
+ private Artifact createArtifact( String groupId, String artifactId, String version )
+ {
+ return factory.createArtifact( groupId, artifactId, version, null, "jar" );
+ }
+
+ private Artifact createArtifact( String groupId, String artifactId, String version, String type )
+ {
+ return factory.createArtifact( groupId, artifactId, version, null, type );
+ }
+
+ private Artifact createArtifact( String groupId, String artifactId, String version, String type, String classifier )
+ {
+ return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
+ }
+}
Re: svn commit: r374306 - in /maven/repository-manager/trunk/maven-repository-utils:
pom.xml src/main/java/org/apache/maven/repository/ArtifactUtils.java src/test/java/org/apache/maven/repository/ArtifactUtilsTest.java
Posted by Edwin Punzalan <ep...@exist.com>.
I think one of the commits after this fixed it. ^_^
Brett Porter wrote:
>epunzalan@apache.org wrote:
>
>
>>Modified: maven/repository-manager/trunk/maven-repository-utils/pom.xml
>>URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-utils/pom.xml?rev=374306&r1=374305&r2=374306&view=diff
>>==============================================================================
>>--- maven/repository-manager/trunk/maven-repository-utils/pom.xml (original)
>>+++ maven/repository-manager/trunk/maven-repository-utils/pom.xml Thu Feb 2 00:52:25 2006
>>@@ -27,6 +27,10 @@
>> <dependencies>
>> <dependency>
>> <groupId>org.codehaus.plexus</groupId>
>>+ <artifactId>plexus-container-default</artifactId>
>>+ </dependency>
>>+ <dependency>
>>+ <groupId>org.codehaus.plexus</groupId>
>> <artifactId>plexus-utils</artifactId>
>> </dependency>
>> <dependency>
>>
>>
>
>Should this be <scope>test</scope> ?
>
>- Brett
>
>---------------------------------------------------------------------
>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: r374306 - in /maven/repository-manager/trunk/maven-repository-utils:
pom.xml src/main/java/org/apache/maven/repository/ArtifactUtils.java src/test/java/org/apache/maven/repository/ArtifactUtilsTest.java
Posted by Brett Porter <br...@apache.org>.
epunzalan@apache.org wrote:
> Modified: maven/repository-manager/trunk/maven-repository-utils/pom.xml
> URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-utils/pom.xml?rev=374306&r1=374305&r2=374306&view=diff
> ==============================================================================
> --- maven/repository-manager/trunk/maven-repository-utils/pom.xml (original)
> +++ maven/repository-manager/trunk/maven-repository-utils/pom.xml Thu Feb 2 00:52:25 2006
> @@ -27,6 +27,10 @@
> <dependencies>
> <dependency>
> <groupId>org.codehaus.plexus</groupId>
> + <artifactId>plexus-container-default</artifactId>
> + </dependency>
> + <dependency>
> + <groupId>org.codehaus.plexus</groupId>
> <artifactId>plexus-utils</artifactId>
> </dependency>
> <dependency>
Should this be <scope>test</scope> ?
- Brett
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org