]> source.dussan.org Git - archiva.git/commitdiff
[MRM-746] also need to make sure the metadata is not scanned in getVersions
authorBrett Porter <brett@apache.org>
Thu, 3 Apr 2008 13:57:40 +0000 (13:57 +0000)
committerBrett Porter <brett@apache.org>
Thu, 3 Apr 2008 13:57:40 +0000 (13:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches@644317 13f79535-47bb-0310-9956-ffa450edef68

archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java
archiva-1.0.x/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java
archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java
archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContentTest.java
archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/include_xml/1.0/include_xml-1.0.pom [new file with mode: 0644]
archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/include_xml/1.0/include_xml-1.0.xml [new file with mode: 0644]
archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/include_xml/1.0/maven-metadata.xml [new file with mode: 0644]

index 4c529a4118d840f0ee09043037a90b918a4019dd..2547a6be0c862d0bd62803e6b3008e5fd9f33a16 100644 (file)
@@ -35,6 +35,7 @@ import org.codehaus.plexus.util.SelectorUtils;
 
 import java.lang.reflect.Field;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -72,6 +73,15 @@ public class FileTypes
 
     private List<String> artifactPatterns;
 
+    /**
+     * Default exclusions from artifact consumers that are using the file types. Note that this is simplistic in the
+     * case of the support files (based on extension) as it is elsewhere - it may be better to match these to actual
+     * artifacts and exclude later during scanning.
+     */
+    public static final List<String> DEFAULT_EXCLUSIONS = Arrays.asList( "**/maven-metadata.xml",
+                                                                          "**/maven-metadata-*.xml", "**/*.sha1",
+                                                                          "**/*.asc", "**/*.md5", "**/*.pgp" );
+
     public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
     {
         this.archivaConfiguration = archivaConfiguration;
@@ -125,7 +135,7 @@ public class FileTypes
         {
             artifactPatterns = getFileTypePatterns( ARTIFACTS );
         }
-        
+
         for ( String pattern : artifactPatterns )
         {
             if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
@@ -139,13 +149,31 @@ public class FileTypes
         return false;
     }
 
+    public boolean matchesDefaultExclusions( String relativePath )
+    {
+        // Correct the slash pattern.
+        relativePath = relativePath.replace( '\\', '/' );
+
+        for ( String pattern : DEFAULT_EXCLUSIONS )
+        {
+            if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
+            {
+                // Found match
+                return true;
+            }
+        }
+
+        // No match.
+        return false;
+    }
+
     public void initialize()
         throws InitializationException
     {
         // TODO: why is this done by hand?
 
         String errMsg = "Unable to load default archiva configuration for FileTypes: ";
-        
+
         try
         {
             CommonsConfigurationRegistry commonsRegistry = new CommonsConfigurationRegistry();
@@ -156,7 +184,7 @@ public class FileTypes
             fld.set( commonsRegistry, new CombinedConfiguration() );
             commonsRegistry.enableLogging( getLogger() );
             commonsRegistry.addConfigurationFromResource( "org/apache/maven/archiva/configuration/default-archiva.xml" );
-            
+
             // Read configuration as it was intended.
             ConfigurationRegistryReader configReader = new ConfigurationRegistryReader();
             Configuration defaultConfig = configReader.read( commonsRegistry );
index d478ea20bb8711abda19fcea285124004450e882..27a84a43e468d4ea4e81026764a1c8ad39f6a932 100644 (file)
@@ -19,9 +19,9 @@ package org.apache.maven.archiva.consumers;
  * under the License.
  */
 
+import org.apache.maven.archiva.configuration.FileTypes;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 
-import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -39,15 +39,6 @@ public abstract class AbstractMonitoredConsumer
 {
     private Set<ConsumerMonitor> monitors = new HashSet<ConsumerMonitor>();
 
-    /**
-     * Default exclusions from artifact consumers that are using the file types. Note that this is simplistic in the
-     * case of the support files (based on extension) as it is elsewhere - it may be better to match these to actual
-     * artifacts and exclude later during scanning.
-     */
-    private static final List<String> DEFAULT_EXCLUSIONS = Arrays.asList( "**/maven-metadata.xml",
-                                                                          "**/maven-metadata-*.xml", "**/*.sha1",
-                                                                          "**/*.asc", "**/*.md5", "**/*.pgp" );
-
     public void addConsumerMonitor( ConsumerMonitor monitor )
     {
         monitors.add( monitor );
@@ -113,6 +104,6 @@ public abstract class AbstractMonitoredConsumer
 
     protected List<String> getDefaultArtifactExclusions()
     {
-        return DEFAULT_EXCLUSIONS;
+        return FileTypes.DEFAULT_EXCLUSIONS;
     }
 }
index dcaafd1147ac68289d32d4b715011810058be5b4..21a75c2782851f27fa7900f3b5f6f2f7ead9a578 100644 (file)
@@ -242,6 +242,12 @@ public class ManagedDefaultRepositoryContent
 
             String relativePath = PathUtil.getRelative( repository.getLocation(), repoFiles[i] );
 
+            if ( filetypes.matchesDefaultExclusions( relativePath ) )
+            {
+                // Skip it, it's metadata or similar
+                continue;
+            }
+
             if ( filetypes.matchesArtifactPattern( relativePath ) )
             {
                 ArtifactReference artifact = toArtifactReference( relativePath );
index f86259063b6aa799cc5b1a0d2b0bbd4344fb5354..3a0a77abb5d1be27a4e2767f77fe62a37ae28d28 100644 (file)
@@ -20,6 +20,9 @@ package org.apache.maven.archiva.repository.content;
  */
 
 import org.apache.maven.archiva.common.utils.VersionComparator;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.FileType;
+import org.apache.maven.archiva.configuration.FileTypes;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.model.ArtifactReference;
 import org.apache.maven.archiva.model.ProjectReference;
@@ -122,6 +125,12 @@ public class ManagedDefaultRepositoryContentTest
         }
     }
 
+    public void testExcludeMetadataFile()
+        throws Exception
+    {
+        assertVersions( "include_xml", "1.0", new String[] { "1.0" } );
+    }
+
     private void assertGetVersions( String artifactId, List<String> expectedVersions )
         throws Exception
     {
@@ -187,6 +196,14 @@ public class ManagedDefaultRepositoryContentTest
 
         ManagedRepositoryConfiguration repository = createRepository( "testRepo", "Unit Test Repo", repoDir );
 
+        ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.ROLE );
+        FileType fileType = (FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
+        fileType.addPattern( "**/*.xml" );
+        assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
+
+        FileTypes fileTypes = (FileTypes) lookup( FileTypes.class );
+        fileTypes.afterConfigurationChange( null, "fileType", null );
+
         repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" );
         repoContent.setRepository( repository );
     }
diff --git a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/include_xml/1.0/include_xml-1.0.pom b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/include_xml/1.0/include_xml-1.0.pom
new file mode 100644 (file)
index 0000000..18cd439
--- /dev/null
@@ -0,0 +1,25 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you 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.
+  -->
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.archiva.metadata.tests</groupId>
+  <artifactId>include_xml</artifactId>
+  <version>1.0</version>
+  <packaging>xml</packaging>
+</project>
diff --git a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/include_xml/1.0/include_xml-1.0.xml b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/include_xml/1.0/include_xml-1.0.xml
new file mode 100644 (file)
index 0000000..176a50b
--- /dev/null
@@ -0,0 +1,2 @@
+<xml />
+    
\ No newline at end of file
diff --git a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/include_xml/1.0/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/include_xml/1.0/maven-metadata.xml
new file mode 100644 (file)
index 0000000..624cbda
--- /dev/null
@@ -0,0 +1,3 @@
+<metadata>
+  
+</metadata>
\ No newline at end of file