maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject svn commit: r452714 - in /maven/plugins/trunk/maven-dependency-plugin/src: main/java/org/apache/maven/plugin/dependency/utils/translators/ test/java/org/apache/maven/plugin/dependency/ test/java/org/apache/maven/plugin/dependency/utils/ test/java/org/a...
Date Wed, 04 Oct 2006 04:07:13 GMT
Author: brianf
Date: Tue Oct  3 21:07:13 2006
New Revision: 452714

URL: http://svn.apache.org/viewvc?view=rev&rev=452714
Log:
more unit tests

Added:
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/translators/
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/translators/TestClassifierTypeTranslator.java
Modified:
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/translators/ClassifierTypeTranslator.java
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/translators/ClassifierTypeTranslator.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/translators/ClassifierTypeTranslator.java?view=diff&rev=452714&r1=452713&r2=452714
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/translators/ClassifierTypeTranslator.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/translators/ClassifierTypeTranslator.java
Tue Oct  3 21:07:13 2006
@@ -25,10 +25,11 @@
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.util.StringUtils;
 
 /**
  * @author brianf
- *
+ * 
  */
 public class ClassifierTypeTranslator
     implements ArtifactTranslator
@@ -47,8 +48,11 @@
         this.factory = factory;
     }
 
-    /* (non-Javadoc)
-     * @see org.apache.mojo.dependency.utils.translators.ArtifactTranslator#translate(java.util.Set,
org.apache.maven.plugin.logging.Log)
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.mojo.dependency.utils.translators.ArtifactTranslator#translate(java.util.Set,
+     *      org.apache.maven.plugin.logging.Log)
      */
     public Set translate( Set artifacts, Log log )
     {
@@ -59,9 +63,37 @@
         for ( Iterator i = artifacts.iterator(); i.hasNext(); )
         {
             Artifact artifact = (Artifact) i.next();
+
+            //this translator must pass both type and classifier here so we will use the
+            //base artifact value if null comes in
+            String useType = null;
+            if ( StringUtils.isNotEmpty(this.type) )
+            {
+                useType = this.type;
+            }
+            else
+            {
+                useType = artifact.getType();
+            }
+
+            String useClassifier = null;
+            if ( StringUtils.isNotEmpty(this.classifier) )
+            {
+                useClassifier = this.classifier;
+            }
+            else
+            {
+                useClassifier = artifact.getClassifier();
+            }
+
             // Create a new artifact
             Artifact newArtifact = factory.createArtifactWithClassifier( artifact.getGroupId(),
artifact
-                .getArtifactId(), artifact.getVersion(), this.type, this.classifier );
+                .getArtifactId(), artifact.getVersion(), useType, useClassifier );
+
+            // note the new artifacts will always have the scope set to null. We
+            // should
+            // reset it here so that it will pass other filters if needed
+            newArtifact.setScope( artifact.getScope() );
 
             results.add( newArtifact );
         }
@@ -78,7 +110,8 @@
     }
 
     /**
-     * @param classifier The classifier to set.
+     * @param classifier
+     *            The classifier to set.
      */
     public void setClassifier( String classifier )
     {
@@ -94,7 +127,8 @@
     }
 
     /**
-     * @param type The type to set.
+     * @param type
+     *            The type to set.
      */
     public void setType( String type )
     {

Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java?view=diff&rev=452714&r1=452713&r2=452714
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java
Tue Oct  3 21:07:13 2006
@@ -39,17 +39,20 @@
 
     protected void tearDown()
     {
-        try
+        if ( testDir != null )
         {
-            DependencyTestUtils.removeDirectory( testDir );
+            try
+            {
+                DependencyTestUtils.removeDirectory( testDir );
+            }
+            catch ( IOException e )
+            {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+                fail("Trying to remove directory:"+testDir);
+            }
+            assertFalse( testDir.exists() );
         }
-        catch ( IOException e )
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-            assertTrue( false );
-        }
-        assertFalse( testDir.exists() );
     }
 
 }

Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java?view=diff&rev=452714&r1=452713&r2=452714
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java
Tue Oct  3 21:07:13 2006
@@ -10,7 +10,6 @@
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
 import org.apache.maven.artifact.versioning.VersionRange;
-import org.codehaus.plexus.util.StringUtils;
 
 public class ArtifactStubFactory
 {
@@ -106,9 +105,18 @@
     {
      Set set = new HashSet();
      set.add(createArtifact("g","a","1.0",Artifact.SCOPE_COMPILE,"war",null));
-     set.add(createArtifact("g","a","1.0",Artifact.SCOPE_COMPILE,"jar",null));
-     set.add(createArtifact("g","a","1.0",Artifact.SCOPE_COMPILE,"sources",null));
-     set.add(createArtifact("g","a","1.0",Artifact.SCOPE_COMPILE,"zip",null));
+     set.add(createArtifact("g","b","1.0",Artifact.SCOPE_COMPILE,"jar",null));
+     set.add(createArtifact("g","c","1.0",Artifact.SCOPE_COMPILE,"sources",null));
+     set.add(createArtifact("g","d","1.0",Artifact.SCOPE_COMPILE,"zip",null));
      return set;
+    }
+    
+    public Set getMixedArtifacts()
+    {
+        Set set = new HashSet();
+        set.addAll(getTypedArtifacts());
+        set.addAll(getScopedArtifacts());
+        set.addAll(getReleaseAndSnapshotArtifacts());
+        return set;
     }
 }

Added: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/translators/TestClassifierTypeTranslator.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/translators/TestClassifierTypeTranslator.java?view=auto&rev=452714
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/translators/TestClassifierTypeTranslator.java
(added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/translators/TestClassifierTypeTranslator.java
Tue Oct  3 21:07:13 2006
@@ -0,0 +1,196 @@
+/*
+ *  Copyright 2005-2006 Brian Fox (brianefox@gmail.com)
+ *
+ * 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.
+ */
+/**
+ * 
+ */
+package org.apache.maven.plugin.dependency.utils.translators;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.factory.DefaultArtifactFactory;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager;
+import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase;
+import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.utils.SilentLog;
+import org.apache.maven.plugin.logging.Log;
+
+/**
+ * @author brianf
+ * 
+ */
+public class TestClassifierTypeTranslator
+    extends AbstractDependencyMojoTestCase
+{
+    Set artifacts = new HashSet();
+
+    ArtifactFactory artifactFactory;
+
+    Log log = new SilentLog();
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        
+        ArtifactHandlerManager manager = new DefaultArtifactHandlerManager();
+        this.setVariableValueToObject(manager,"artifactHandlers",new HashMap());
+        
+        artifactFactory = new DefaultArtifactFactory();
+        this.setVariableValueToObject(artifactFactory,"artifactHandlerManager",manager);
+        
+        ArtifactStubFactory factory = new ArtifactStubFactory( null, false );
+        artifacts = factory.getMixedArtifacts();
+    }
+
+    public void testNullClassifier()
+    {
+        doTestNullEmptyClassifier(null);
+    }
+    public void testEmptyClassifier()
+    {
+        doTestNullEmptyClassifier("");
+    }
+    
+    public void doTestNullEmptyClassifier(String classifier)
+    {
+        String type = "zip";
+        
+        ArtifactTranslator at = new ClassifierTypeTranslator( classifier,type, artifactFactory
);
+        Set results = at.translate(artifacts,log);
+        
+        Iterator iter = artifacts.iterator();
+        
+        while (iter.hasNext())
+        {
+            Artifact artifact = (Artifact) iter.next();
+            Iterator resultIter = results.iterator();
+            boolean found = false;
+            while (!found && resultIter.hasNext() )
+            {
+                Artifact translatedArtifact = (Artifact) resultIter.next(); 
+                if (artifact.getArtifactId() == translatedArtifact.getArtifactId() &&
+                    artifact.getGroupId() == translatedArtifact.getGroupId() &&
+                    artifact.getScope() == translatedArtifact.getScope())
+                {
+                    //classifier is null, should be the same as the artifact
+                    assertEquals(artifact.getClassifier(),translatedArtifact.getClassifier());
+                    assertEquals(type,translatedArtifact.getType());
+                    
+                    found = true;
+                    break;
+                }
+            }
+            assertTrue(found);
+        }  
+    }
+    
+    public void testNullType()
+    {
+        doTestNullEmptyType(null);
+    }
+    public void testEmptyType()
+    {
+        doTestNullEmptyType("");
+    }
+    
+    public void doTestNullEmptyType(String type)
+    {
+        String classifier = "jdk5";
+        
+        ArtifactTranslator at = new ClassifierTypeTranslator( classifier,type, artifactFactory
);
+        Set results = at.translate(artifacts,log);
+        
+        Iterator iter = artifacts.iterator();
+        
+        while (iter.hasNext())
+        {
+            Artifact artifact = (Artifact) iter.next();
+            Iterator resultIter = results.iterator();
+            boolean found = false;
+            while (!found && resultIter.hasNext() )
+            {
+                Artifact translatedArtifact = (Artifact) resultIter.next(); 
+                if (artifact.getArtifactId() == translatedArtifact.getArtifactId() &&
+                    artifact.getGroupId() == translatedArtifact.getGroupId() &&
+                    artifact.getScope() == translatedArtifact.getScope())
+                {
+                    //classifier is null, should be the same as the artifact
+                    assertEquals(classifier,translatedArtifact.getClassifier());
+                    assertEquals(artifact.getType(),translatedArtifact.getType());
+                    
+                    found = true;
+                    break;
+                }
+            }
+            assertTrue(found);
+        }  
+    }
+    
+    public void testClassifierAndType()
+    {
+        String classifier = "jdk14";
+        String type = "sources";
+        ArtifactTranslator at = new ClassifierTypeTranslator( classifier,type, artifactFactory
);
+        Set results = at.translate(artifacts,log);
+        
+        Iterator iter = artifacts.iterator();
+        
+        while (iter.hasNext())
+        {
+            Artifact artifact = (Artifact) iter.next();
+            Iterator resultIter = results.iterator();
+            boolean found = false;
+            while (!found && resultIter.hasNext() )
+            {
+                Artifact translatedArtifact = (Artifact) resultIter.next(); 
+                if (artifact.getArtifactId() == translatedArtifact.getArtifactId() &&
+                    artifact.getGroupId() == translatedArtifact.getGroupId() &&
+                    artifact.getScope() == translatedArtifact.getScope())
+                {
+                    assertEquals(translatedArtifact.getClassifier(),classifier);
+                    assertEquals(translatedArtifact.getType(),type);
+                    
+                    found = true;
+                    break;
+                }
+            }
+            assertTrue(found);
+        }     
+    }
+
+    public void testGetterSetter()
+    {
+        String classifier = "class";
+        String type = "type";
+        ClassifierTypeTranslator at = new ClassifierTypeTranslator( classifier,type, artifactFactory
);
+        
+        assertEquals(classifier,at.getClassifier());
+        assertEquals(type,at.getType());
+        
+        at.setClassifier(type);
+        at.setType(classifier);
+        
+        assertEquals(type,at.getClassifier());
+        assertEquals(classifier,at.getType());
+        
+    }
+}



Mime
View raw message