import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryReader;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryException;
+import org.codehaus.plexus.registry.RegistryListener;
import org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry;
+import org.codehaus.plexus.util.SelectorUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @plexus.component role="org.apache.maven.archiva.configuration.FileTypes"
*/
public class FileTypes
- implements Initializable
+ implements Initializable, RegistryListener
{
private Logger log = LoggerFactory.getLogger(FileTypes.class);
*/
private Map<String, List<String>> defaultTypeMap = new HashMap<String, List<String>>();
+ private List<String> artifactPatterns;
+
+ public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
+ {
+ this.archivaConfiguration = archivaConfiguration;
+ }
+
/**
* <p>
* Get the list of patterns for a specified filetype.
* </p>
- *
+ *
* <p>
* You will always get a list. In this order.
* <ul>
* <li>A single item list of <code>"**<span>/</span>*"</code></li>
* </ul>
* </p>
- *
+ *
* @param id the id to lookup.
* @return the list of patterns.
*/
return defaultPatterns;
}
+ public synchronized boolean matchesArtifactPattern( String relativePath )
+ {
+ // Correct the slash pattern.
+ relativePath = relativePath.replace( '\\', '/' );
+
+ if ( artifactPatterns == null )
+ {
+ artifactPatterns = getFileTypePatterns( ARTIFACTS );
+ }
+
+ for ( String pattern : artifactPatterns )
+ {
+ if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
+ {
+ // Found match
+ return true;
+ }
+ }
+
+ // No match.
+ return false;
+ }
+
public void initialize()
throws InitializationException
{
- /* Initialize Default Type Map */
- defaultTypeMap.clear();
+ // TODO: why is this done by hand?
String errMsg = "Unable to load default archiva configuration for FileTypes: ";
ConfigurationRegistryReader configReader = new ConfigurationRegistryReader();
Configuration defaultConfig = configReader.read( commonsRegistry );
- // Store the default file type declaration.
- List<FileType> filetypes = defaultConfig.getRepositoryScanning().getFileTypes();
- for ( FileType filetype : filetypes )
- {
- List<String> patterns = defaultTypeMap.get( filetype.getId() );
- if ( patterns == null )
- {
- patterns = new ArrayList<String>();
- }
- patterns.addAll( filetype.getPatterns() );
-
- defaultTypeMap.put( filetype.getId(), patterns );
- }
+ initialiseTypeMap( defaultConfig );
}
catch ( RegistryException e )
{
{
throw new InitializationException( errMsg + e.getMessage(), e );
}
+
+ this.archivaConfiguration.addChangeListener( this );
+ }
+
+ private void initialiseTypeMap( Configuration configuration )
+ {
+ defaultTypeMap.clear();
+
+ // Store the default file type declaration.
+ List<FileType> filetypes = configuration.getRepositoryScanning().getFileTypes();
+ for ( FileType filetype : filetypes )
+ {
+ List<String> patterns = defaultTypeMap.get( filetype.getId() );
+ if ( patterns == null )
+ {
+ patterns = new ArrayList<String>();
+ }
+ patterns.addAll( filetype.getPatterns() );
+
+ defaultTypeMap.put( filetype.getId(), patterns );
+ }
+ }
+
+ public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+ {
+ if ( propertyName.contains( "fileType" ) )
+ {
+ artifactPatterns = null;
+
+ initialiseTypeMap( archivaConfiguration.getConfiguration() );
+ }
+ }
+
+ public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+ {
+ /* nothing to do */
}
}
--- /dev/null
+package org.apache.maven.archiva.configuration;
+
+/*
+ * 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.
+ */
+
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+
+public class FileTypesTest
+ extends PlexusInSpringTestCase
+{
+ private FileTypes filetypes;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ filetypes = (FileTypes) lookup( FileTypes.class );
+ }
+
+ public void testIsArtifact()
+ {
+ assertTrue( filetypes.matchesArtifactPattern( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
+ assertTrue( filetypes.matchesArtifactPattern(
+ "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
+ assertTrue( filetypes.matchesArtifactPattern( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
+
+ assertFalse(
+ filetypes.matchesArtifactPattern( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) );
+ assertFalse(
+ filetypes.matchesArtifactPattern( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ) );
+ assertFalse(
+ filetypes.matchesArtifactPattern( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.asc" ) );
+ assertFalse(
+ filetypes.matchesArtifactPattern( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
+ assertFalse( filetypes.matchesArtifactPattern( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
+ assertFalse( filetypes.matchesArtifactPattern( "org/apache/derby/derby/maven-metadata.xml" ) );
+ }
+}
* under the License.
*/
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
/**
{
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 );
{
return false;
}
+
+ protected List<String> getDefaultArtifactExclusions()
+ {
+ return DEFAULT_EXCLUSIONS;
+ }
}
public List<String> getExcludes()
{
- return null;
+ return getDefaultArtifactExclusions();
}
public List<String> getIncludes()
public List<String> getExcludes()
{
- return null;
+ return getDefaultArtifactExclusions();
}
public List<String> getIncludes()
public List<String> getExcludes()
{
- return null;
+ return getDefaultArtifactExclusions();
}
public List<String> getIncludes()
--- /dev/null
+package org.apache.maven.archiva.consumers.core;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.common.utils.BaseFile;
+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.consumers.KnownRepositoryContentConsumer;
+import org.apache.maven.archiva.repository.scanner.functors.ConsumerWantsFilePredicate;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+
+import java.io.File;
+
+public abstract class AbstractArtifactConsumerTest
+ extends PlexusInSpringTestCase
+{
+ private File repoLocation;
+
+ protected KnownRepositoryContentConsumer consumer;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.ROLE );
+ FileType fileType =
+ (FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
+ assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
+ fileType.addPattern( "**/*.xml" );
+
+ repoLocation = getTestFile( "target/test-" + getName() + "/test-repo" );
+ }
+
+ public void testConsumption()
+ {
+ File localFile =
+ new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
+
+ ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
+ BaseFile baseFile = new BaseFile( repoLocation, localFile );
+ predicate.setBasefile( baseFile );
+
+ assertFalse( predicate.evaluate( consumer ) );
+ }
+
+ public void testConsumptionOfOtherMetadata()
+ {
+ File localFile =
+ new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" );
+
+ ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
+ BaseFile baseFile = new BaseFile( repoLocation, localFile );
+ predicate.setBasefile( baseFile );
+
+ assertFalse( predicate.evaluate( consumer ) );
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.consumers.core;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+
+public class ArtifactMissingChecksumsConsumerTest
+ extends AbstractArtifactConsumerTest
+{
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ consumer = (ArtifactMissingChecksumsConsumer) lookup( KnownRepositoryContentConsumer.class.getName(),
+ "create-missing-checksums" );
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.consumers.core;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+
+public class MetadataUpdateConsumerTest
+ extends AbstractArtifactConsumerTest
+{
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ consumer = (KnownRepositoryContentConsumer) lookup( KnownRepositoryContentConsumer.class.getName(),
+ "metadata-updater" );
+ }
+}
\ No newline at end of file
* under the License.
*/
+import org.apache.commons.lang.time.DateUtils;
+import org.apache.maven.archiva.consumers.core.repository.stubs.LuceneRepositoryContentIndexStub;
+import org.apache.maven.archiva.indexer.RepositoryContentIndex;
+
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import org.apache.commons.lang.time.DateUtils;
-import org.apache.maven.archiva.consumers.core.repository.stubs.LuceneRepositoryContentIndexStub;
-import org.apache.maven.archiva.indexer.RepositoryContentIndex;
-
/**
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
*/
versions.add( "2.2-SNAPSHOT" );
populateDb( "org.apache.maven.plugins", "maven-install-plugin", versions );
- }
+ }
}
*/
import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.common.utils.BaseFile;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
+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.consumers.KnownRepositoryContentConsumer;
import org.apache.maven.archiva.consumers.core.repository.stubs.LuceneRepositoryContentIndexFactoryStub;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
+import org.apache.maven.archiva.repository.scanner.functors.ConsumerWantsFilePredicate;
import org.custommonkey.xmlunit.XMLAssert;
import java.io.File;
public class RepositoryPurgeConsumerTest
extends AbstractRepositoryPurgeTest
{
+ public void testConsumption()
+ throws Exception
+ {
+ assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
+ }
+
+ public void testConsumptionOfOtherMetadata()
+ throws Exception
+ {
+ assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" );
+ }
+
+ private void assertNotConsumed( String path )
+ throws Exception
+ {
+ ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.ROLE );
+ FileType fileType =
+ (FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
+ assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
+ fileType.addPattern( "**/*.xml" );
+
+ // trigger reload
+ FileTypes fileTypes = (FileTypes) lookup( FileTypes.class );
+ fileTypes.afterConfigurationChange( null, "repositoryScanning.fileTypes", null );
+
+ KnownRepositoryContentConsumer repoPurgeConsumer =
+ (KnownRepositoryContentConsumer) lookup( KnownRepositoryContentConsumer.class, "repository-purge" );
+
+ File repoLocation = getTestFile( "target/test-" + getName() + "/test-repo" );
+
+ File localFile =
+ new File( repoLocation, path );
+
+ ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
+ BaseFile baseFile = new BaseFile( repoLocation, localFile );
+ predicate.setBasefile( baseFile );
+
+ assertFalse( predicate.evaluate( repoPurgeConsumer ) );
+ }
+
private void setLastModified( String path )
{
File dir = new File( path );
/**
* Test the snapshot clean consumer on a repository set to NOT clean/delete snapshots based on released versions.
- *
+ *
* @throws Exception
*/
public void testReleasedSnapshotsWereNotCleaned()
</requirement>
<requirement>
<role>org.apache.maven.archiva.configuration.FileTypes</role>
+ <role-hint>retention-count</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.archiva.indexer.RepositoryContentIndexFactory</role>
</component>
<component>
<role>org.apache.maven.archiva.configuration.FileTypes</role>
+ <role-hint>retention-count</role-hint>
<implementation>org.apache.maven.archiva.configuration.FileTypes</implementation>
<requirements>
<requirement>
</requirement>
<requirement>
<role>org.apache.maven.archiva.configuration.FileTypes</role>
+ <role-hint>days-old</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.archiva.indexer.RepositoryContentIndexFactory</role>
</component>
<component>
<role>org.apache.maven.archiva.configuration.FileTypes</role>
+ <role-hint>days-old</role-hint>
<implementation>org.apache.maven.archiva.configuration.FileTypes</implementation>
<requirements>
<requirement>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-digest</artifactId>
</dependency>
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
public List<String> getExcludes()
{
- return null;
+ return getDefaultArtifactExclusions();
}
public List<String> getIncludes()
--- /dev/null
+package org.apache.maven.archiva.consumers.database;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.common.utils.BaseFile;
+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.consumers.KnownRepositoryContentConsumer;
+import org.apache.maven.archiva.repository.scanner.functors.ConsumerWantsFilePredicate;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+
+import java.io.File;
+
+public class ArtifactUpdateDatabaseConsumerTest
+ extends PlexusInSpringTestCase
+{
+ private File repoLocation;
+
+ protected KnownRepositoryContentConsumer consumer;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.ROLE );
+ FileType fileType =
+ (FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
+ assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
+ fileType.addPattern( "**/*.xml" );
+
+ repoLocation = getTestFile( "target/test-" + getName() + "/test-repo" );
+
+ consumer =
+ (KnownRepositoryContentConsumer) lookup( KnownRepositoryContentConsumer.class, "update-db-artifact" );
+ }
+
+ public void testConsumption()
+ {
+ File localFile =
+ new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
+
+ ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
+ BaseFile baseFile = new BaseFile( repoLocation, localFile );
+ predicate.setBasefile( baseFile );
+
+ assertFalse( predicate.evaluate( consumer ) );
+ }
+
+ public void testConsumptionOfOtherMetadata()
+ {
+ File localFile =
+ new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" );
+
+ ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
+ BaseFile baseFile = new BaseFile( repoLocation, localFile );
+ predicate.setBasefile( baseFile );
+
+ assertFalse( predicate.evaluate( consumer ) );
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ ~ 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.
+ -->
+
+<component-set>
+ <components>
+ <!-- JdoAccess -->
+ <component>
+ <role>org.apache.maven.archiva.database.jdo.JdoAccess</role>
+ <role-hint>archiva</role-hint>
+ <implementation>org.apache.maven.archiva.database.jdo.JdoAccess</implementation>
+ <requirements>
+ <requirement>
+ <role>org.codehaus.plexus.jdo.JdoFactory</role>
+ <role-hint>archiva</role-hint>
+ </requirement>
+ </requirements>
+ </component>
+
+ <!-- JDO Factory -->
+ <component>
+ <role>org.codehaus.plexus.jdo.JdoFactory</role>
+ <role-hint>archiva</role-hint>
+ <implementation>org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory</implementation>
+ <configuration>
+ <persistenceManagerFactoryClass>org.jpox.PersistenceManagerFactoryImpl</persistenceManagerFactoryClass>
+ <driverName>org.hsqldb.jdbcDriver</driverName>
+ <userName>sa</userName>
+ <password></password>
+ <url>jdbc:hsqldb:mem:testdb</url>
+ <otherProperties>
+ <property>
+ <name>javax.jdo.PersistenceManagerFactoryClass</name>
+ <value>org.jpox.PersistenceManagerFactoryImpl</value>
+ </property>
+ </otherProperties>
+ </configuration>
+ </component>
+ </components>
+</component-set>
import org.apache.maven.archiva.repository.ContentNotFoundException;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.layout.LayoutException;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
-import org.codehaus.plexus.util.SelectorUtils;
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
import java.util.Set;
/**
*/
public class ManagedDefaultRepositoryContent
extends AbstractDefaultRepositoryContent
- implements ManagedRepositoryContent, Initializable
+ implements ManagedRepositoryContent
{
/**
* @plexus.requirement
private ManagedRepositoryConfiguration repository;
- private List<String> artifactPatterns;
-
public void deleteVersion( VersionedReference reference )
throws ContentNotFoundException
{
String relativePath = PathUtil.getRelative( repository.getLocation(), repoFiles[i] );
- if ( matchesArtifactPattern( relativePath ) )
+ if ( filetypes.matchesArtifactPattern( relativePath ) )
{
ArtifactReference artifact = toArtifactReference( relativePath );
String relativePath = PathUtil.getRelative( repository.getLocation(), repoFiles[i] );
- if ( matchesArtifactPattern( relativePath ) )
+ if ( filetypes.matchesArtifactPattern( relativePath ) )
{
ArtifactReference artifact = toArtifactReference( relativePath );
}
}
- public void initialize()
- throws InitializationException
- {
- this.artifactPatterns = new ArrayList<String>();
- initVariables();
- }
-
public void setRepository( ManagedRepositoryConfiguration repository )
{
this.repository = repository;
String relativePath = PathUtil.getRelative( repository.getLocation(), repoFiles[i] );
- if ( matchesArtifactPattern( relativePath ) )
+ if ( filetypes.matchesArtifactPattern( relativePath ) )
{
ArtifactReference artifact = toArtifactReference( relativePath );
return false;
}
}
-
- private void initVariables()
- {
- synchronized ( this.artifactPatterns )
- {
- this.artifactPatterns.clear();
-
- this.artifactPatterns.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
- }
- }
-
- private boolean matchesArtifactPattern( String relativePath )
- {
- // Correct the slash pattern.
- relativePath = relativePath.replace( '\\', '/' );
-
- Iterator<String> it = this.artifactPatterns.iterator();
- while ( it.hasNext() )
- {
- String pattern = it.next();
-
- if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
- {
- // Found match
- return true;
- }
- }
-
- // No match.
- return false;
- }
}
import org.apache.maven.archiva.repository.ContentNotFoundException;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.layout.LayoutException;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
-import org.codehaus.plexus.util.SelectorUtils;
import java.io.File;
-import java.util.ArrayList;
import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
import java.util.Set;
/**
*/
public class ManagedLegacyRepositoryContent
extends AbstractLegacyRepositoryContent
- implements ManagedRepositoryContent, Initializable
+ implements ManagedRepositoryContent
{
/**
* @plexus.requirement
private ManagedRepositoryConfiguration repository;
- private List<String> artifactPatterns;
-
public void deleteVersion( VersionedReference reference )
throws ContentNotFoundException
{
String relativePath = PathUtil.getRelative( repository.getLocation(), repoFile );
- if ( matchesArtifactPattern( relativePath ) )
+ if ( filetypes.matchesArtifactPattern( relativePath ) )
{
try
{
}
}
- public void initialize()
- throws InitializationException
- {
- this.artifactPatterns = new ArrayList<String>();
- initVariables();
- }
-
public void setRepository( ManagedRepositoryConfiguration repository )
{
this.repository = repository;
String relativePath = PathUtil.getRelative( repository.getLocation(), repoFile );
- if ( matchesArtifactPattern( relativePath ) )
+ if ( filetypes.matchesArtifactPattern( relativePath ) )
{
try
{
String relativePath = PathUtil.getRelative( repository.getLocation(), repoFiles[i] );
- if ( matchesArtifactPattern( relativePath ) )
+ if ( filetypes.matchesArtifactPattern( relativePath ) )
{
try
{
String relativePath = PathUtil.getRelative( repository.getLocation(), repoFiles[i] );
- if ( matchesArtifactPattern( relativePath ) )
+ if ( filetypes.matchesArtifactPattern( relativePath ) )
{
try
{
}
}
}
-
- private void initVariables()
- {
- synchronized ( this.artifactPatterns )
- {
- this.artifactPatterns.clear();
-
- this.artifactPatterns.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
- }
- }
-
- private boolean matchesArtifactPattern( String relativePath )
- {
- // Correct the slash pattern.
- relativePath = relativePath.replace( '\\', '/' );
-
- Iterator<String> it = this.artifactPatterns.iterator();
- while ( it.hasNext() )
- {
- String pattern = it.next();
-
- if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
- {
- // Found match
- return true;
- }
- }
-
- // No match.
- return false;
- }
}
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.layout.LayoutException;
import org.apache.maven.archiva.repository.metadata.MetadataTools;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
-import org.codehaus.plexus.registry.Registry;
-import org.codehaus.plexus.registry.RegistryListener;
-import org.codehaus.plexus.util.SelectorUtils;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
/**
* RepositoryRequest is used to determine the type of request that is incoming, and convert it to an appropriate
* role="org.apache.maven.archiva.repository.content.RepositoryRequest"
*/
public class RepositoryRequest
- implements RegistryListener, Initializable
{
/**
* @plexus.requirement
*/
private PathParser legacyPathParser;
- private List<String> artifactPatterns;
-
- /**
- * Test path to see if it is an artifact being requested (or not).
- *
- * @param requestedPath the path to test.
- * @return true if it is an artifact being requested.
- */
- public boolean isArtifact( String requestedPath )
- {
- // Correct the slash pattern.
- String relativePath = requestedPath.replace( '\\', '/' );
-
- Iterator<String> it = this.artifactPatterns.iterator();
- while ( it.hasNext() )
- {
- String pattern = it.next();
-
- if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
- {
- // Found match
- return true;
- }
- }
-
- // No match.
- return false;
- }
-
/**
* Takes an incoming requested path (in "/" format) and gleans the layout
* and ArtifactReference appropriate for that content.
String adjustedPath = repository.toPath( ref );
return adjustedPath + supportfile;
}
-
- public void initialize()
- throws InitializationException
- {
- this.artifactPatterns = new ArrayList<String>();
- initVariables();
- this.archivaConfiguration.addChangeListener( this );
- }
-
- private void initVariables()
- {
- synchronized ( this.artifactPatterns )
- {
- this.artifactPatterns.clear();
- this.artifactPatterns.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
- }
- }
-
- public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
- {
- if ( propertyName.contains( "fileType" ) )
- {
- initVariables();
- }
- }
-
- public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
- {
- /* nothing to do */
-
- }
}
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryListener;
-import org.codehaus.plexus.util.SelectorUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
String relativePath = PathUtil.getRelative( managedRepository.getRepoRoot(), repoFiles[i] );
- if ( matchesArtifactPattern( relativePath ) )
+ if ( filetypes.matchesArtifactPattern( relativePath ) )
{
ArtifactReference artifact = managedRepository.toArtifactReference( relativePath );
// No artifact was found.
return null;
}
-
- private boolean matchesArtifactPattern( String relativePath )
- {
- // Correct the slash pattern.
- relativePath = relativePath.replace( '\\', '/' );
-
- Iterator<String> it = this.artifactPatterns.iterator();
- while ( it.hasNext() )
- {
- String pattern = it.next();
-
- if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
- {
- // Found match
- return true;
- }
- }
-
- // No match.
- return false;
- }
}
"org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" );
}
- public void testIsArtifact()
- {
- assertTrue( repoRequest.isArtifact( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
- assertTrue( repoRequest.isArtifact( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
- assertTrue( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
-
- assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) );
- assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ) );
- assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.asc" ) );
- assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
- assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
- assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/maven-metadata.xml" ) );
- }
-
public void testIsSupportFile()
{
assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) );
public ArtifactCountConsumer()
{
+ // TODO: shouldn't this use filetypes?
includes = new ArrayList();
includes.add( "**/*.pom" );
includes.add( "**/*.jar" );
*/
private RepositoryContentFactory repositoryFactory;
+ // TODO: why is this not used? If it should be, what about excludes?
private List<String> includes = new ArrayList<String>();
public String getId()
private Map repositoryMap = new HashMap();
+ // TODO: why is this not used? If it should be, what about excludes?
private List<String> includes = new ArrayList<String>();
public String getId()