From: Brett Porter Date: Thu, 3 Apr 2008 13:57:40 +0000 (+0000) Subject: [MRM-746] also need to make sure the metadata is not scanned in getVersions X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=74adedbe139b659fb0043761dc962025a2519424;p=archiva.git [MRM-746] also need to make sure the metadata is not scanned in getVersions git-svn-id: https://svn.apache.org/repos/asf/archiva/branches@644317 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java b/archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java index 4c529a411..2547a6be0 100644 --- a/archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java +++ b/archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java @@ -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 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 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 ); diff --git a/archiva-1.0.x/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java b/archiva-1.0.x/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java index d478ea20b..27a84a43e 100644 --- a/archiva-1.0.x/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java +++ b/archiva-1.0.x/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java @@ -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 monitors = new HashSet(); - /** - * 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 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 getDefaultArtifactExclusions() { - return DEFAULT_EXCLUSIONS; + return FileTypes.DEFAULT_EXCLUSIONS; } } diff --git a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java index dcaafd114..21a75c278 100644 --- a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java +++ b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java @@ -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 ); diff --git a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContentTest.java b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContentTest.java index f86259063..3a0a77abb 100644 --- a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContentTest.java +++ b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContentTest.java @@ -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 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 index 000000000..18cd43943 --- /dev/null +++ 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 @@ -0,0 +1,25 @@ + + + 4.0.0 + org.apache.archiva.metadata.tests + include_xml + 1.0 + xml + 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 index 000000000..176a50bcf --- /dev/null +++ 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 @@ -0,0 +1,2 @@ + + \ 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 index 000000000..624cbdace --- /dev/null +++ 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 @@ -0,0 +1,3 @@ + + + \ No newline at end of file