]> source.dussan.org Git - archiva.git/commitdiff
Refactored tests and created an Abstract test case.
authorEdwin L. Punzalan <epunzalan@apache.org>
Wed, 14 Jun 2006 03:13:22 +0000 (03:13 +0000)
committerEdwin L. Punzalan <epunzalan@apache.org>
Wed, 14 Jun 2006 03:13:22 +0000 (03:13 +0000)
Also, refactored some of the module classes and improved some javadocs.

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@414034 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java [new file with mode: 0644]
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java

index 63d916fd6ef20db948e384ece874081d2516805a..70f17c9f8aaec09f3423480f1c5872560189221e 100644 (file)
@@ -56,6 +56,14 @@ public abstract class AbstractArtifactDiscoverer
         return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES );
     }
 
+    /**
+     * Return a list of artifacts found in a specified repository
+     *
+     * @param repository The ArtifactRepository to discover artifacts
+     * @param blacklistedPatterns Comma-delimited list of string paths that will be excluded in the discovery
+     * @param includeSnapshots if the repository contains snapshots which should also be included
+     * @return list of artifacts
+     */
     public List discoverArtifacts( ArtifactRepository repository, String blacklistedPatterns, boolean includeSnapshots )
     {
         if ( !"file".equals( repository.getProtocol() ) )
@@ -73,7 +81,7 @@ public abstract class AbstractArtifactDiscoverer
         {
             String path = artifactPaths[i];
 
-            Artifact artifact = null;
+            Artifact artifact;
             try
             {
                 artifact = buildArtifactFromPath( path, repository );
@@ -92,6 +100,14 @@ public abstract class AbstractArtifactDiscoverer
         return artifacts;
     }
 
+    /**
+     * Returns a list of pom packaging artifacts found in a specified repository
+     *
+     * @param repository The ArtifactRepository to discover artifacts
+     * @param blacklistedPatterns Comma-delimited list of string paths that will be excluded in the discovery
+     * @param includeSnapshots if the repository contains snapshots which should also be included
+     * @return list of pom artifacts
+     */
     public List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns,
                                         boolean includeSnapshots )
     {
@@ -148,6 +164,14 @@ public abstract class AbstractArtifactDiscoverer
         return artifacts;
     }
 
+    /**
+     * Returns an artifact object that is represented by the specified path in a repository
+     *
+     * @param path The path that is pointing to an artifact
+     * @param repository The repository of the artifact
+     * @return Artifact
+     * @throws DiscovererException when the specified path does correspond to an artifact
+     */
     public Artifact buildArtifactFromPath( String path, ArtifactRepository repository )
         throws DiscovererException
     {
index 349239a0b69851dffc49b4f019ef78b2938c1817..58a97d493e87cff89d3036594584dcd609299bbb 100644 (file)
@@ -59,6 +59,11 @@ public abstract class AbstractDiscoverer
         kickedOutPaths.add( new DiscovererPath( path, reason ) );
     }
 
+    /**
+     * Returns an iterator for the list if DiscovererPaths that were found to not represent a searched object
+     *
+     * @return Iterator for the DiscovererPath List
+     */
     public Iterator getKickedOutPathsIterator()
     {
         return kickedOutPaths.iterator();
@@ -102,6 +107,11 @@ public abstract class AbstractDiscoverer
         return scanner.getIncludedFiles();
     }
 
+    /**
+     * Returns an iterator for the list if DiscovererPaths that were not processed because they are explicitly excluded
+     *
+     * @return Iterator for the DiscovererPath List
+     */
     public Iterator getExcludedPathsIterator()
     {
         return excludedPaths.iterator();
index 5d7e32a6a7c91cfe0dd5d2c6a484c67e28daaa11..e0fc3c21ecbbf786e7cd680279942305efbe0371 100644 (file)
@@ -34,6 +34,9 @@ import java.util.StringTokenizer;
 public class DefaultArtifactDiscoverer
     extends AbstractArtifactDiscoverer
 {
+    /**
+     * @see org.apache.maven.repository.discovery.ArtifactDiscoverer#buildArtifact(String)
+     */
     public Artifact buildArtifact( String path )
         throws DiscovererException
     {
index 8dd3bf7faff802168aa87dd14c2a9e26a1712ed2..d7cc07eab710863056a1d723227c8f890f62d5d6 100644 (file)
@@ -51,14 +51,16 @@ public class DefaultMetadataDiscoverer
     /**
      * Standard patterns to include in discovery of metadata files.
      */
-    private static final String[] STANDARD_DISCOVERY_INCLUDES = {"**/*-metadata.xml", "**/*/*-metadata.xml",
-        "**/*/*/*-metadata.xml", "**/*-metadata-*.xml", "**/*/*-metadata-*.xml", "**/*/*/*-metadata-*.xml"};
+    private static final String[] STANDARD_DISCOVERY_INCLUDES = {"**/*-metadata.xml",
+                                                                 "**/*/*-metadata.xml",
+                                                                 "**/*/*/*-metadata.xml",
+                                                                 "**/*-metadata-*.xml",
+                                                                 "**/*/*-metadata-*.xml",
+                                                                 "**/*/*/*-metadata-*.xml"
+                                                                };
 
     /**
-     * Search the repository for metadata files.
-     *
-     * @param repositoryBase
-     * @param blacklistedPatterns
+     * @see org.apache.maven.repository.discovery.MetadataDiscoverer#discoverMetadata(java.io.File, String)
      */
     public List discoverMetadata( File repositoryBase, String blacklistedPatterns )
     {
@@ -92,7 +94,7 @@ public class DefaultMetadataDiscoverer
     private RepositoryMetadata buildMetadata( String repo, String metadataPath )
         throws DiscovererException
     {
-        Metadata m = null;
+        Metadata m;
         String repoPath = repo + "/" + metadataPath;
         try
         {
@@ -128,6 +130,13 @@ public class DefaultMetadataDiscoverer
         return repositoryMetadata;
     }
 
+    /**
+     * Builds a RepositoryMetadata object from a Metadata object and its path
+     *
+     * @param m Metadata
+     * @param metadataPath path
+     * @return RepositoryMetadata if the parameters represent one; null if not
+     */
     private RepositoryMetadata buildMetadata( Metadata m, String metadataPath )
     {
         String metaGroupId = m.getGroupId();
index 1040d580a9eae28412f937f6bcbc052f4f5769d1..9a8f7fc2254925b4ba64043e17dc265e5fce8d26 100644 (file)
@@ -37,6 +37,9 @@ import java.util.StringTokenizer;
 public class LegacyArtifactDiscoverer
     extends AbstractArtifactDiscoverer
 {
+    /**
+     * @see org.apache.maven.repository.discovery.ArtifactDiscoverer#buildArtifact(String)
+     */
     public Artifact buildArtifact( String path )
         throws DiscovererException
     {
diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java
new file mode 100644 (file)
index 0000000..8a50c4e
--- /dev/null
@@ -0,0 +1,82 @@
+package org.apache.maven.repository.discovery;
+
+/*
+ * 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.codehaus.plexus.PlexusTestCase;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.Artifact;
+
+import java.io.File;
+
+/**
+ * @author Edwin Punzalan
+ */
+public abstract class AbstractArtifactDiscovererTest
+    extends PlexusTestCase
+{
+    protected ArtifactDiscoverer discoverer;
+
+    private ArtifactFactory factory;
+
+    protected ArtifactRepository repository;
+
+    protected abstract String getLayout();
+
+    protected abstract File getRepositoryFile();
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, getLayout() );
+
+        factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+
+        repository = getRepository();
+    }
+
+    protected ArtifactRepository getRepository()
+        throws Exception
+    {
+        File basedir = getRepositoryFile();
+
+        ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+
+        ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, getLayout() );
+
+        return factory.createArtifactRepository( "discoveryRepo", "file://" + basedir, layout, null, null );
+    }
+
+    protected Artifact createArtifact( String groupId, String artifactId, String version )
+    {
+        return factory.createArtifact( groupId, artifactId, version, null, "jar" );
+    }
+
+    protected Artifact createArtifact( String groupId, String artifactId, String version, String type )
+    {
+        return factory.createArtifact( groupId, artifactId, version, null, type );
+    }
+
+    protected Artifact createArtifact( String groupId, String artifactId, String version, String type, String classifier )
+    {
+        return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
+    }
+}
index 4343cb546cd6fff56121c6e0977448eaa60b2c33..1da5a4f66fd9369172aa067ea1b65d856b2e4c9f 100644 (file)
@@ -17,12 +17,7 @@ package org.apache.maven.repository.discovery;
  */
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.model.Model;
-import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 
 import java.io.File;
@@ -40,28 +35,16 @@ import java.util.List;
  * @todo test location of poms, checksums
  */
 public class DefaultArtifactDiscovererTest
-    extends PlexusTestCase
+    extends AbstractArtifactDiscovererTest
 {
-    private ArtifactDiscoverer discoverer;
-
-    private ArtifactFactory factory;
-
-    private ArtifactRepository repository;
-
-    protected void setUp()
-        throws Exception
+    protected String getLayout()
     {
-        super.setUp();
-
-        discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "default" );
-
-        factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
-
-        File basedir = getTestFile( "src/test/repository" );
-        ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+        return "default";
+    }
 
-        ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
-        repository = factory.createArtifactRepository( "discoveryRepo", "file://" + basedir, layout, null, null );
+    protected File getRepositoryFile()
+    {
+        return getTestFile( "src/test/repository" );
     }
 
     public void testDefaultExcludes()
@@ -594,20 +577,4 @@ public class DefaultArtifactDiscovererTest
             return null;
         }
     }
-
-    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 );
-    }
-
 }
index 87cf546cead2626b4c0c11c863a020e6b9451446..7c2d03c122b39c70b6476a8bd074e1fdf0422ffa 100644 (file)
@@ -17,11 +17,6 @@ package org.apache.maven.repository.discovery;
  */
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
-import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 
 import java.io.File;
@@ -34,32 +29,18 @@ import java.util.List;
  *
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
  * @version $Id$
- * @todo share as much as possible with default via abstract test case
  */
 public class LegacyArtifactDiscovererTest
-    extends PlexusTestCase
+    extends AbstractArtifactDiscovererTest
 {
-    private ArtifactDiscoverer discoverer;
-
-    private ArtifactFactory factory;
-
-    private ArtifactRepository repository;
-
-    protected void setUp()
-        throws Exception
+    protected String getLayout()
     {
-        super.setUp();
-
-        discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "legacy" );
-
-        factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
-
-        File basedir = getTestFile( "src/test/legacy-repository" );
-
-        ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+        return "legacy";
+    }
 
-        ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
-        repository = factory.createArtifactRepository( "discoveryRepo", "file://" + basedir, layout, null, null );
+    protected File getRepositoryFile()
+    {
+        return getTestFile( "src/test/legacy-repository" );
     }
 
     public void testDefaultExcludes()
@@ -433,20 +414,4 @@ public class LegacyArtifactDiscovererTest
             return null;
         }
     }
-
-    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 );
-    }
-
 }