From: Brett Porter Date: Thu, 3 Apr 2008 14:16:35 +0000 (+0000) Subject: [MRM-746] also need to make sure the metadata is not scanned in getVersions X-Git-Tag: archiva-r676265~220 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e8feb3b2239ddd688a538139feec9c82c857091e;p=archiva.git [MRM-746] also need to make sure the metadata is not scanned in getVersions Merged from: r644317 git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@644324 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java index 2f97b1db1..07bcc1b9a 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java @@ -19,13 +19,6 @@ package org.apache.maven.archiva.configuration; * under the License. */ -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; import org.apache.commons.configuration.CombinedConfiguration; @@ -42,6 +35,14 @@ import org.codehaus.plexus.util.SelectorUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +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; +import java.util.Map; + /** * FileTypes * @@ -75,6 +76,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; @@ -128,7 +138,7 @@ public class FileTypes { artifactPatterns = getFileTypePatterns( ARTIFACTS ); } - + for ( String pattern : artifactPatterns ) { if ( SelectorUtils.matchPath( pattern, relativePath, false ) ) @@ -142,13 +152,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(); @@ -159,7 +187,7 @@ public class FileTypes fld.set( commonsRegistry, new CombinedConfiguration() ); commonsRegistry.enableLogging( new Slf4JPlexusLogger( FileTypes.class ) ); 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-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java index 5301e8191..c1ad42dd3 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java @@ -19,7 +19,6 @@ package org.apache.maven.archiva.consumers; * under the License. */ -import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -36,15 +35,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 ); @@ -110,6 +100,6 @@ public abstract class AbstractMonitoredConsumer protected List getDefaultArtifactExclusions() { - return DEFAULT_EXCLUSIONS; + return FileTypes.DEFAULT_EXCLUSIONS; } } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java index dcaafd114..21a75c278 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java +++ b/archiva-modules/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-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContentTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContentTest.java index f86259063..3a0a77abb 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContentTest.java +++ b/archiva-modules/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-modules/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-modules/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-modules/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-modules/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-modules/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-modules/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-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/include_xml/1.0/maven-metadata.xml b/archiva-modules/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-modules/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