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;
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;
{
artifactPatterns = getFileTypePatterns( ARTIFACTS );
}
-
+
for ( String pattern : artifactPatterns )
{
if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
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();
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 );
* 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;
{
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 );
protected List<String> getDefaultArtifactExclusions()
{
- return DEFAULT_EXCLUSIONS;
+ return FileTypes.DEFAULT_EXCLUSIONS;
}
}
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 );
*/
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;
}
}
+ public void testExcludeMetadataFile()
+ throws Exception
+ {
+ assertVersions( "include_xml", "1.0", new String[] { "1.0" } );
+ }
+
private void assertGetVersions( String artifactId, List<String> expectedVersions )
throws Exception
{
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 );
}
--- /dev/null
+<!--
+ ~ 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>
--- /dev/null
+<xml />
+
\ No newline at end of file
--- /dev/null
+<metadata>
+
+</metadata>
\ No newline at end of file