]> source.dussan.org Git - archiva.git/commitdiff
PR: MRM-42
authorEdwin L. Punzalan <epunzalan@apache.org>
Thu, 2 Mar 2006 09:21:15 +0000 (09:21 +0000)
committerEdwin L. Punzalan <epunzalan@apache.org>
Thu, 2 Mar 2006 09:21:15 +0000 (09:21 +0000)
Submitted by: Maria Odea Ching

Applied patch fixed a bug from scheduler and indexer usage

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

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/DefaultArtifactDiscovererTest.java
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java

index 42de10bf3a69d28cc8becab930e24e9a8856175a..8d5d4cf7b96c802072d183744a912650f03329c9 100644 (file)
@@ -19,9 +19,9 @@ 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.repository.ArtifactUtils;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.repository.ArtifactUtils;
 import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
@@ -36,7 +36,7 @@ import java.util.StringTokenizer;
  *
  * @author John Casey
  * @author Brett Porter
- * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="default" instantiation-strategy="per-lookup"
+ * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.DefaultArtifactDiscoverer"
  */
 public class DefaultArtifactDiscoverer
     extends AbstractArtifactDiscoverer
@@ -108,13 +108,18 @@ public class DefaultArtifactDiscoverer
                 try
                 {
                     Model model = mavenReader.read( new FileReader( filename ) );
-                    if ( ( pomArtifact != null ) && ( "pom".equals( model.getPackaging() ) ) )
+                    if ( ( model != null ) && ( "pom".equals( model.getPackaging() ) ) )
+                    {
+                        artifacts.add( model );
+                    }
+                    /*if ( ( pomArtifact != null ) && ( "pom".equals( model.getPackaging() ) ) )
                     {
                         if ( convertSnapshots || !pomArtifact.isSnapshot() )
                         {
                             artifacts.add( pomArtifact );
                         }
                     }
+                    */
                 }
                 catch ( Exception e )
                 {
index c3db648487d28c93af1f24c9c6f8654bd35af3fd..a2f0119171b425efdb9a8161398c96d72c5fceb6 100644 (file)
@@ -17,16 +17,13 @@ package org.apache.maven.repository.discovery;
  */
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.Metadata;
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
-import org.apache.maven.artifact.versioning.VersionRange;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
@@ -46,12 +43,17 @@ import java.util.StringTokenizer;
 /**
  * This class gets all the paths that contain the metadata files.
  *
- * @plexus.component role="org.apache.maven.repository.discovery.MetadataDiscoverer" role-hint="default" instantiation-strategy="per-lookup"
+ * @plexus.component role="org.apache.maven.repository.discovery.MetadataDiscoverer" role-hint="org.apache.maven.repository.discovery.DefaultMetadataDiscoverer"
  */
 public class DefaultMetadataDiscoverer
     extends AbstractArtifactDiscoverer
     implements MetadataDiscoverer
 {
+    /**
+     * @plexus.requirement
+     */
+    private ArtifactFactory artifactFactory;
+
     /**
      * Standard patterns to include in discovery of metadata files.
      */
@@ -126,20 +128,33 @@ public class DefaultMetadataDiscoverer
             Iterator it = pathParts.iterator();
             String tmpDir = (String) it.next();
 
-            ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
-            VersionRange version = VersionRange.createFromVersion( metaVersion );
-            Artifact artifact =
-                new DefaultArtifact( metaGroupId, metaArtifactId, version, "compile", "jar", "", handler );
+            //ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
+            //if( metaVersion != null && !metaVersion.equals( "" ) )
+            //{
+            //   VersionRange version = VersionRange.createFromVersion( metaVersion );
+            //}
+
+            Artifact artifact = null;
+            if ( metaVersion != null && !metaVersion.equals( "" ) )
+            {
+                artifact = artifactFactory.createBuildArtifact( metaGroupId, metaArtifactId, metaVersion, "jar" );
+            }
 
             // snapshotMetadata
-            if ( tmpDir.equals( metaVersion ) )
+            if ( tmpDir != null && tmpDir.equals( metaVersion ) )
             {
-                metadata = new SnapshotArtifactRepositoryMetadata( artifact );
+                if ( artifact != null )
+                {
+                    metadata = new SnapshotArtifactRepositoryMetadata( artifact );
+                }
             }
-            else if ( tmpDir.equals( metaArtifactId ) )
+            else if ( tmpDir != null && tmpDir.equals( metaArtifactId ) )
             {
                 // artifactMetadata
-                metadata = new ArtifactRepositoryMetadata( artifact );
+                if ( artifact != null )
+                {
+                    metadata = new ArtifactRepositoryMetadata( artifact );
+                }
             }
             else
             {
@@ -161,7 +176,7 @@ public class DefaultMetadataDiscoverer
                 }
 
                 // groupMetadata
-                if ( metaGroupId.equals( groupDir ) )
+                if ( metaGroupId != null && metaGroupId.equals( groupDir ) )
                 {
                     metadata = new GroupRepositoryMetadata( metaGroupId );
                 }
index e592eafe4e2465a93d3b0492f200d8f78545f123..4ad5d21d742e69eb92bcdc30704e68a623d749db 100644 (file)
@@ -17,10 +17,10 @@ package org.apache.maven.repository.discovery;
  */
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
@@ -37,13 +37,14 @@ import java.util.StringTokenizer;
  *
  * @author John Casey
  * @author Brett Porter
- * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="legacy" instantiation-strategy="per-lookup"
+ * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.LegacyArtifactDiscoverer"
  */
 public class LegacyArtifactDiscoverer
     extends AbstractArtifactDiscoverer
     implements ArtifactDiscoverer
 {
     private final static String POM = ".pom";
+
     private final static String DELIM = "\\";
 
     /**
@@ -75,7 +76,8 @@ public class LegacyArtifactDiscoverer
         return artifacts;
     }
 
-    public List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns, boolean convertSnapshots )
+    public List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns,
+                                        boolean convertSnapshots )
     {
         List artifacts = new ArrayList();
 
@@ -96,7 +98,7 @@ public class LegacyArtifactDiscoverer
                 try
                 {
                     Model model = mavenReader.read( new FileReader( filename ) );
-                    if ( ( pomArtifact != null ) && ( "pom".equals(model.getPackaging()) ) )
+                    if ( ( pomArtifact != null ) && ( "pom".equals( model.getPackaging() ) ) )
                     {
                         if ( convertSnapshots || !pomArtifact.isSnapshot() )
                         {
@@ -104,9 +106,9 @@ public class LegacyArtifactDiscoverer
                         }
                     }
                 }
-                catch (Exception e)
+                catch ( Exception e )
                 {
-                    System.out.println( "error reading file: " +  filename );
+                    System.out.println( "error reading file: " + filename );
                     e.printStackTrace();
                 }
             }
index 84bba71e50b7311e021eb23e5dfcc40cc73c4527..83614f9815a8352f3434eab7f414543be1d032cf 100644 (file)
@@ -21,6 +21,7 @@ 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 java.io.File;
@@ -49,12 +50,12 @@ public class DefaultArtifactDiscovererTest
     {
         super.setUp();
 
-        discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "default" );
+        discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE,
+                                                  "org.apache.maven.repository.discovery.DefaultArtifactDiscoverer" );
 
         factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
 
         File basedir = getTestFile( "src/test/repository" );
-
         ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
 
         ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
@@ -361,19 +362,28 @@ public class DefaultArtifactDiscovererTest
         List artifacts = discoverer.discoverStandalonePoms( repository, null, false );
         assertEquals( 4, artifacts.size() );
         Iterator itr = artifacts.iterator();
-        Artifact artifact = (Artifact) itr.next();
+        //Artifact artifact = (Artifact) itr.next();
+        Model model = (Model) itr.next();
+        Artifact artifact =
+            createArtifact( model.getGroupId(), model.getArtifactId(), model.getVersion(), model.getPackaging() );
         assertEquals( "org.apache.maven", artifact.getGroupId() );
         assertEquals( "B", artifact.getArtifactId() );
         assertEquals( "1.0", artifact.getVersion() );
-        artifact = (Artifact) itr.next();
+        model = (Model) itr.next();
+        artifact =
+            createArtifact( model.getGroupId(), model.getArtifactId(), model.getVersion(), model.getPackaging() );
         assertEquals( "org.apache.maven", artifact.getGroupId() );
         assertEquals( "B", artifact.getArtifactId() );
         assertEquals( "2.0", artifact.getVersion() );
-        artifact = (Artifact) itr.next();
+        model = (Model) itr.next();
+        artifact =
+            createArtifact( model.getGroupId(), model.getArtifactId(), model.getVersion(), model.getPackaging() );
         assertEquals( "org.apache.maven", artifact.getGroupId() );
         assertEquals( "discovery", artifact.getArtifactId() );
         assertEquals( "1.0", artifact.getVersion() );
-        artifact = (Artifact) itr.next();
+        model = (Model) itr.next();
+        artifact =
+            createArtifact( model.getGroupId(), model.getArtifactId(), model.getVersion(), model.getPackaging() );
         assertEquals( "org.apache.testgroup", artifact.getGroupId() );
         assertEquals( "discovery", artifact.getArtifactId() );
         assertEquals( "1.0", artifact.getVersion() );
index 2e958fc3960c60bd6052809d286d38e848a41ca6..c779c1567aabd8986711866335f9f4493fe90dc0 100644 (file)
@@ -40,7 +40,8 @@ public class DefaultMetadataDiscovererTest
     {
         super.setUp();
 
-        discoverer = (MetadataDiscoverer) lookup( MetadataDiscoverer.ROLE, "default" );
+        discoverer = (MetadataDiscoverer) lookup( MetadataDiscoverer.ROLE,
+                                                  "org.apache.maven.repository.discovery.DefaultMetadataDiscoverer" );
         repositoryLocation = getTestFile( "src/test/repository" );
     }
 
index f7781e622fa100224303d2c19a7be9065dc1661a..6e699ccb17542e20186de67c24cfebad07d6ebb3 100644 (file)
@@ -17,16 +17,16 @@ 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.artifact.factory.ArtifactFactory;
 import org.codehaus.plexus.PlexusTestCase;
 
+import java.io.File;
+import java.net.MalformedURLException;
 import java.util.Iterator;
 import java.util.List;
-import java.net.MalformedURLException;
-import java.io.File;
 
 /**
  * Test the legacy artifact discoverer.
@@ -49,7 +49,8 @@ public class LegacyArtifactDiscovererTest
     {
         super.setUp();
 
-        discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "legacy" );
+        discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE,
+                                                  "org.apache.maven.repository.discovery.LegacyArtifactDiscoverer" );
 
         factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );