aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2011-05-20 20:08:12 +0000
committerOlivier Lamy <olamy@apache.org>2011-05-20 20:08:12 +0000
commit02b4b8d6af1d5d3a07989b557fa5d91adaeccf09 (patch)
tree720fa1cde07566a57a377168350bb48534dc8e1a /archiva-modules/archiva-base
parentc96411890abc41e512583e409ea06715b6ddb84e (diff)
downloadarchiva-02b4b8d6af1d5d3a07989b557fa5d91adaeccf09.tar.gz
archiva-02b4b8d6af1d5d3a07989b557fa5d91adaeccf09.zip
[MRM-1473] remove use of plexus-spring
start with archiva-configuration and archiva-policies git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1125538 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base')
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/pom.xml57
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ArchivaConfiguration.java6
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java151
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java31
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java207
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ConfigurationTest.java10
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/FileTypesTest.java18
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/LegacyArtifactPathTest.java7
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java24
-rwxr-xr-xarchiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml280
-rw-r--r--archiva-modules/archiva-base/archiva-policies/pom.xml37
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/CachedFailuresPolicy.java5
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ChecksumPolicy.java2
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/PropagateErrorsDownloadPolicy.java2
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java2
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ReleasesPolicy.java3
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/SnapshotsPolicy.java3
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/urlcache/UrlFailureCache.java4
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/resources/META-INF/spring-context.xml9
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java34
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ChecksumPolicyTest.java65
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ReleasePolicyTest.java59
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/SnapshotsPolicyTest.java60
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.xml24
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ChecksumPolicyTest.xml24
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ReleasePolicyTest.xml24
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/SnapshotsPolicyTest.xml24
-rwxr-xr-xarchiva-modules/archiva-base/archiva-policies/src/test/resources/spring-context.xml44
-rw-r--r--archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MockConfiguration.java5
-rwxr-xr-xarchiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/MockConfiguration.java5
30 files changed, 922 insertions, 304 deletions
diff --git a/archiva-modules/archiva-base/archiva-configuration/pom.xml b/archiva-modules/archiva-base/archiva-configuration/pom.xml
index d7965b3cb..dac057cdf 100644
--- a/archiva-modules/archiva-base/archiva-configuration/pom.xml
+++ b/archiva-modules/archiva-base/archiva-configuration/pom.xml
@@ -29,11 +29,6 @@
<name>Archiva Base :: Configuration</name>
<dependencies>
<dependency>
- <groupId>org.codehaus.redback.components</groupId>
- <artifactId>plexus-spring</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.codehaus.redback.components.registry</groupId>
<artifactId>spring-registry-api</artifactId>
</dependency>
@@ -42,6 +37,49 @@
<artifactId>spring-registry-commons</artifactId>
</dependency>
<dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils-core</artifactId>
+ </exclusion>
+ <!-- targeting JDK 1.4, xml parser/apis not needed -->
+ <exclusion>
+ <groupId>xerces</groupId>
+ <artifactId>xerces</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>servletapi</groupId>
+ <artifactId>servletapi</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>ant</groupId>
+ <artifactId>ant-optional</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.redback.components</groupId>
+ <artifactId>spring-utils</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-expression-evaluator</artifactId>
</dependency>
@@ -116,6 +154,15 @@
</instrumentation>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <basedir>${basedir}</basedir>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ArchivaConfiguration.java
index 0705fd654..bf0b8b989 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ArchivaConfiguration.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ArchivaConfiguration.java
@@ -78,5 +78,11 @@ public interface ArchivaConfiguration
* TODO: Remove in future.
*/
void addChangeListener( RegistryListener listener );
+
+ /**
+ * reload configuration from file included registry
+ * @since 1.4-M1
+ */
+ void reload();
}
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
index aace6cb8b..b2234217c 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
@@ -21,6 +21,7 @@ package org.apache.maven.archiva.configuration;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.functors.ProxyConnectorConfigurationOrderComparator;
@@ -40,12 +41,14 @@ import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.registry.RegistryListener;
import org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry;
+import org.codehaus.redback.components.springutils.ComponentContainer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
+import javax.inject.Named;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -82,10 +85,10 @@ import java.util.Set;
* If the configuration is outdated, it will be upgraded when it is loaded. This is done by checking the version flag
* before reading it from the registry.
* </p>
- *
+ * <p/>
* plexus.component role="org.apache.maven.archiva.configuration.ArchivaConfiguration"
*/
-@Service("archivaConfiguration")
+@Service( "archivaConfiguration#default" )
public class DefaultArchivaConfiguration
implements ArchivaConfiguration, RegistryListener
//, Initializable
@@ -94,40 +97,48 @@ public class DefaultArchivaConfiguration
/**
* Plexus registry to read the configuration from.
- *
+ * <p/>
* plexus.requirement role-hint="commons-configuration"
*/
@Inject
+ @Named( value = "commons-configuration" )
private Registry registry;
+ @Inject
+ private ComponentContainer componentContainer;
+
/**
* The configuration that has been converted.
*/
private Configuration configuration;
/**
+ * see #initialize
* plexus.requirement role="org.apache.maven.archiva.policies.PreDownloadPolicy"
+ *
* @todo these don't strictly belong in here
*/
private Map<String, PreDownloadPolicy> prePolicies;
/**
+ * see #initialize
* plexus.requirement role="org.apache.maven.archiva.policies.PostDownloadPolicy"
+ *
* @todo these don't strictly belong in here
*/
private Map<String, PostDownloadPolicy> postPolicies;
/**
- * TODO take about default value with spring
+ * see #initialize
* plexus.configuration default-value="${user.home}/.m2/archiva.xml"
*/
- private String userConfigFilename;
+ private String userConfigFilename = "${user.home}/.m2/archiva.xml";
/**
- * * TODO take about default value with spring
+ * see #initialize
* plexus.configuration default-value="${appserver.base}/conf/archiva.xml"
*/
- private String altConfigFilename;
+ private String altConfigFilename = "${appserver.base}/conf/archiva.xml";
/**
* Configuration Listeners we've registered.
@@ -158,7 +169,7 @@ public class DefaultArchivaConfiguration
{
configuration = load();
configuration = unescapeExpressions( configuration );
- if( isConfigurationDefaulted )
+ if ( isConfigurationDefaulted )
{
configuration = checkRepositoryLocations( configuration );
}
@@ -167,9 +178,9 @@ public class DefaultArchivaConfiguration
return configuration;
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private Configuration load()
- {
+ {
// TODO: should this be the same as section? make sure unnamed sections still work (eg, sys properties)
Registry subset = registry.getSubset( KEY );
if ( subset.getString( "version" ) == null )
@@ -181,8 +192,8 @@ public class DefaultArchivaConfiguration
subset = readDefaultConfiguration();
}
}
-
- Configuration config = new ConfigurationRegistryReader().read( subset );
+
+ Configuration config = new ConfigurationRegistryReader().read( subset );
if ( !config.getRepositories().isEmpty() )
{
@@ -190,7 +201,7 @@ public class DefaultArchivaConfiguration
{
V1RepositoryConfiguration r = i.next();
r.setScanned( r.isIndexed() );
-
+
if ( r.getUrl().startsWith( "file://" ) )
{
r.setLocation( r.getUrl().substring( 7 ) );
@@ -319,8 +330,8 @@ public class DefaultArchivaConfiguration
}
// Normalize the order fields in the proxy connectors.
- Map<String, java.util.List<ProxyConnectorConfiguration>> proxyConnectorMap = config
- .getProxyConnectorAsMap();
+ Map<String, java.util.List<ProxyConnectorConfiguration>> proxyConnectorMap =
+ config.getProxyConnectorAsMap();
for ( List<ProxyConnectorConfiguration> connectors : proxyConnectorMap.values() )
{
@@ -400,13 +411,12 @@ public class DefaultArchivaConfiguration
catch ( RegistryException e )
{
throw new ConfigurationRuntimeException(
- "Fatal error: Unable to find the built-in default configuration and load it into the registry",
- e );
+ "Fatal error: Unable to find the built-in default configuration and load it into the registry", e );
}
return registry.getSubset( KEY );
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public synchronized void save( Configuration configuration )
throws IndeterminateConfigurationException, RegistryException
{
@@ -444,7 +454,7 @@ public class DefaultArchivaConfiguration
this.configuration = null;
throw new IndeterminateConfigurationException(
- "Configuration can not be saved when it is loaded from two sources" );
+ "Configuration can not be saved when it is loaded from two sources" );
}
}
@@ -452,48 +462,50 @@ public class DefaultArchivaConfiguration
escapeCronExpressions( configuration );
// [MRM-661] Due to a bug in the modello registry writer, we need to take these out by hand. They'll be put back by the writer.
- if ( configuration.getManagedRepositories().isEmpty() )
+ if ( configuration.getManagedRepositories().isEmpty() && section != null )
{
section.removeSubset( "managedRepositories" );
}
- if ( configuration.getRemoteRepositories().isEmpty() )
+ if ( configuration.getRemoteRepositories().isEmpty() && section != null )
{
section.removeSubset( "remoteRepositories" );
+
}
- if ( configuration.getProxyConnectors().isEmpty() )
+ if ( configuration.getProxyConnectors().isEmpty() && section != null )
{
section.removeSubset( "proxyConnectors" );
}
- if ( configuration.getNetworkProxies().isEmpty() )
+ if ( configuration.getNetworkProxies().isEmpty() && section != null )
{
section.removeSubset( "networkProxies" );
}
- if ( configuration.getLegacyArtifactPaths().isEmpty() )
+ if ( configuration.getLegacyArtifactPaths().isEmpty() && section != null )
{
section.removeSubset( "legacyArtifactPaths" );
}
- if ( configuration.getRepositoryGroups().isEmpty() )
+ if ( configuration.getRepositoryGroups().isEmpty() && section != null )
{
section.removeSubset( "repositoryGroups" );
}
if ( configuration.getRepositoryScanning() != null )
{
- if ( configuration.getRepositoryScanning().getKnownContentConsumers().isEmpty() )
+ if ( configuration.getRepositoryScanning().getKnownContentConsumers().isEmpty() && section != null )
{
section.removeSubset( "repositoryScanning.knownContentConsumers" );
}
- if ( configuration.getRepositoryScanning().getInvalidContentConsumers().isEmpty() )
+ if ( configuration.getRepositoryScanning().getInvalidContentConsumers().isEmpty() && section != null )
{
section.removeSubset( "repositoryScanning.invalidContentConsumers" );
}
}
if ( configuration.getDatabaseScanning() != null )
{
- if ( configuration.getDatabaseScanning().getCleanupConsumers().isEmpty() )
+ if ( configuration.getDatabaseScanning().getCleanupConsumers().isEmpty() && section != null )
{
section.removeSubset( "databaseScanning.cleanupConsumers" );
+
}
- if ( configuration.getDatabaseScanning().getUnprocessedConsumers().isEmpty() )
+ if ( configuration.getDatabaseScanning().getUnprocessedConsumers().isEmpty() && section != null )
{
section.removeSubset( "databaseScanning.unprocessedConsumers" );
}
@@ -532,12 +544,14 @@ public class DefaultArchivaConfiguration
{
if ( !writeFile( "alternative configuration", altConfigFilename, contents ) )
{
- throw new RegistryException( "Unable to create configuration file in either user ["
- + userConfigFilename + "] or alternative [" + altConfigFilename
- + "] locations on disk, usually happens when not allowed to write to those locations." );
+ throw new RegistryException(
+ "Unable to create configuration file in either user [" + userConfigFilename + "] or alternative ["
+ + altConfigFilename
+ + "] locations on disk, usually happens when not allowed to write to those locations." );
}
}
+ ( (CommonsConfigurationRegistry) registry ).setProperties( contents );
( (CommonsConfigurationRegistry) registry ).initialize();
@@ -546,19 +560,19 @@ public class DefaultArchivaConfiguration
addRegistryChangeListener( regListener );
}
-
triggerEvent( ConfigurationEvent.SAVED );
- return registry.getSection( KEY + ".user" );
+ Registry section = registry.getSection( KEY + ".user" );
+ return section == null ? new CommonsConfigurationRegistry( new BaseConfiguration() ) : section;
}
/**
* Attempts to write the contents to a file, if an IOException occurs, return false.
- *
+ * <p/>
* The file will be created if the directory to the file exists, otherwise this will return false.
- *
+ *
* @param filetype the filetype (freeform text) to use in logging messages when failure to write.
- * @param path the path to write to.
+ * @param path the path to write to.
* @param contents the contents to write.
* @return true if write successful.
*/
@@ -643,6 +657,9 @@ public class DefaultArchivaConfiguration
@PostConstruct
public void initialize()
{
+
+ this.postPolicies = componentContainer.buildMapWithRole( PostDownloadPolicy.class );
+ this.prePolicies = componentContainer.buildMapWithRole( PreDownloadPolicy.class );
// Resolve expressions in the userConfigFilename and altConfigFilename
try
{
@@ -654,12 +671,26 @@ public class DefaultArchivaConfiguration
}
catch ( EvaluatorException e )
{
- throw new RuntimeException( "Unable to evaluate expressions found in "
- + "userConfigFilename or altConfigFilename." );
+ throw new RuntimeException(
+ "Unable to evaluate expressions found in " + "userConfigFilename or altConfigFilename." );
}
registry.addChangeListener( this );
}
+ public void reload()
+ {
+ this.configuration = null;
+ try
+ {
+ this.registry.initialize();
+ }
+ catch ( RegistryException e )
+ {
+ throw new ConfigurationRuntimeException( e.getMessage(), e );
+ }
+ this.initialize();
+ }
+
public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{
// nothing to do here
@@ -672,10 +703,10 @@ public class DefaultArchivaConfiguration
private String removeExpressions( String directory )
{
- String value = StringUtils.replace( directory, "${appserver.base}", registry.getString( "appserver.base",
- "${appserver.base}" ) );
- value = StringUtils.replace( value, "${appserver.home}", registry.getString( "appserver.home",
- "${appserver.home}" ) );
+ String value = StringUtils.replace( directory, "${appserver.base}",
+ registry.getString( "appserver.base", "${appserver.base}" ) );
+ value = StringUtils.replace( value, "${appserver.home}",
+ registry.getString( "appserver.home", "${appserver.home}" ) );
return value;
}
@@ -708,22 +739,23 @@ public class DefaultArchivaConfiguration
return config;
}
-
+
private Configuration checkRepositoryLocations( Configuration config )
{
// additional check for [MRM-789], ensure that the location of the default repositories
// are not installed in the server installation
- for( ManagedRepositoryConfiguration repo : (List<ManagedRepositoryConfiguration>) config.getManagedRepositories() )
+ for ( ManagedRepositoryConfiguration repo : (List<ManagedRepositoryConfiguration>) config.getManagedRepositories() )
{
String repoPath = repo.getLocation();
- File repoLocation = new File( repoPath );
-
- if( repoLocation.exists() && repoLocation.isDirectory() && !repoPath.endsWith( "data/repositories/" + repo.getId() ) )
+ File repoLocation = new File( repoPath );
+
+ if ( repoLocation.exists() && repoLocation.isDirectory() && !repoPath.endsWith(
+ "data/repositories/" + repo.getId() ) )
{
repo.setLocation( repoPath + "/data/repositories/" + repo.getId() );
}
}
-
+
return config;
}
@@ -741,4 +773,25 @@ public class DefaultArchivaConfiguration
{
return this.isConfigurationDefaulted;
}
+
+ public Registry getRegistry()
+ {
+ return registry;
+ }
+
+ public void setRegistry( Registry registry )
+ {
+ this.registry = registry;
+ }
+
+
+ public void setUserConfigFilename( String userConfigFilename )
+ {
+ this.userConfigFilename = userConfigFilename;
+ }
+
+ public void setAltConfigFilename( String altConfigFilename )
+ {
+ this.altConfigFilename = altConfigFilename;
+ }
}
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 e5e1a7e6d..cf1c57720 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
@@ -33,6 +33,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
+import javax.inject.Named;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
@@ -42,13 +43,13 @@ import java.util.List;
import java.util.Map;
/**
- * FileTypes
+ * FileTypes
*
* @version $Id$
- *
- * plexus.component role="org.apache.maven.archiva.configuration.FileTypes"
+ * <p/>
+ * plexus.component role="org.apache.maven.archiva.configuration.FileTypes"
*/
-@Service("fileTypes")
+@Service( "fileTypes" )
public class FileTypes
implements RegistryListener
{
@@ -64,6 +65,7 @@ public class FileTypes
* plexus.requirement
*/
@Inject
+ @Named( value = "archivaConfiguration#default" )
private ArchivaConfiguration archivaConfiguration;
/**
@@ -91,14 +93,14 @@ public class FileTypes
* <p>
* Get the list of patterns for a specified filetype.
* </p>
- *
+ * <p/>
* <p>
* You will always get a list. In this order.
- * <ul>
- * <li>The Configured List</li>
- * <li>The Default List</li>
- * <li>A single item list of <code>"**<span>/</span>*"</code></li>
- * </ul>
+ * <ul>
+ * <li>The Configured List</li>
+ * <li>The Default List</li>
+ * <li>A single item list of <code>"**<span>/</span>*"</code></li>
+ * </ul>
* </p>
*
* @param id the id to lookup.
@@ -108,8 +110,8 @@ public class FileTypes
{
Configuration config = archivaConfiguration.getConfiguration();
Predicate selectedFiletype = new FiletypeSelectionPredicate( id );
- FileType filetype = (FileType) CollectionUtils.find( config.getRepositoryScanning().getFileTypes(),
- selectedFiletype );
+ FileType filetype =
+ (FileType) CollectionUtils.find( config.getRepositoryScanning().getFileTypes(), selectedFiletype );
if ( ( filetype != null ) && CollectionUtils.isNotEmpty( filetype.getPatterns() ) )
{
@@ -171,7 +173,7 @@ public class FileTypes
public void initialize()
{
// TODO: why is this done by hand?
-
+
// TODO: ideally, this would be instantiated by configuration instead, and not need to be a component
String errMsg = "Unable to load default archiva configuration for FileTypes: ";
@@ -184,7 +186,8 @@ public class FileTypes
Field fld = commonsRegistry.getClass().getDeclaredField( "configuration" );
fld.setAccessible( true );
fld.set( commonsRegistry, new CombinedConfiguration() );
- commonsRegistry.addConfigurationFromResource( "org/apache/maven/archiva/configuration/default-archiva.xml" );
+ commonsRegistry.addConfigurationFromResource(
+ "org/apache/maven/archiva/configuration/default-archiva.xml" );
// Read configuration as it was intended.
ConfigurationRegistryReader configReader = new ConfigurationRegistryReader();
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
index c28aebb73..63811fd3d 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
@@ -19,38 +19,75 @@ package org.apache.maven.archiva.configuration;
* under the License.
*/
-import java.io.File;
-import java.util.List;
-import java.util.Map;
-
+import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.codehaus.plexus.registry.RegistryException;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.codehaus.redback.components.springutils.ComponentContainer;
import org.custommonkey.xmlunit.XMLAssert;
import org.easymock.MockControl;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.util.List;
+import java.util.Map;
/**
* Test the configuration store.
- *
*/
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
public class ArchivaConfigurationTest
- extends PlexusInSpringTestCase
+ extends TestCase
{
+
+ @Inject
+ private ComponentContainer componentContainer;
+
+ public static String getBasedir()
+ {
+ String basedir = System.getProperty( "basedir" );
+ if ( basedir == null )
+ {
+ basedir = new File( "" ).getAbsolutePath();
+ }
+
+ return basedir;
+ }
+
+ public static File getTestFile( String path )
+ {
+ return new File( getBasedir(), path );
+ }
+
/**
- * {@inheritDoc}
- * @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getSpringConfigLocation()
+ * @TODO to remove
*/
protected String getSpringConfigLocation()
{
return "org/apache/maven/archiva/configuration/spring-context.xml";
}
+ protected <T> T lookup(Class<T> clazz, String hint)
+ {
+ return componentContainer.getComponent( clazz, hint );
+ }
+
+ protected <T> T lookup(Class<T> clazz)
+ {
+ return componentContainer.getComponent( clazz );
+ }
+
+ @Test
public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource()
throws Exception
{
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration" );
Configuration configuration = archivaConfiguration.getConfiguration();
assertConfiguration( configuration );
@@ -67,11 +104,12 @@ public class ArchivaConfigurationTest
assertTrue( "check managed repositories", repository.isScanned() );
}
+ @Test
public void testGetConfigurationFromDefaults()
throws Exception
{
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-defaults" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-defaults" );
Configuration configuration = archivaConfiguration.getConfiguration();
assertConfiguration( configuration );
@@ -87,48 +125,50 @@ public class ArchivaConfigurationTest
assertEquals( "check managed repositories", "default", repository.getLayout() );
assertTrue( "check managed repositories", repository.isScanned() );
}
-
+
// test for [MRM-789]
+ @Test
public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting()
throws Exception
{
File repo = new File( getBasedir(), "/target/test-classes/existing_snapshots" );
repo.mkdirs();
-
+
repo = new File( getBasedir(), "/target/test-classes/existing_internal" );
repo.mkdirs();
-
- String existingTestDefaultArchivaConfigFile =
- FileUtils.readFileToString( getTestFile( "target/test-classes/org/apache/maven/archiva/configuration/test-default-archiva.xml" ) ) ;
- existingTestDefaultArchivaConfigFile = StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", getBasedir() );
-
+
+ String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString(
+ getTestFile( "target/test-classes/org/apache/maven/archiva/configuration/test-default-archiva.xml" ) );
+ existingTestDefaultArchivaConfigFile =
+ StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", getBasedir() );
+
File generatedTestDefaultArchivaConfigFile =
new File( getBasedir(), "target/test-classes/org/apache/maven/archiva/configuration/default-archiva.xml" );
-
- FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile, null );
-
- ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(),
- "test-defaults-default-repo-location-exists" );
+
+ FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile,
+ null );
+
+ ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class,
+ "test-defaults-default-repo-location-exists" );
Configuration configuration = archivaConfiguration.getConfiguration();
assertConfiguration( configuration );
-
+
ManagedRepositoryConfiguration repository =
- (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
+ (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
assertTrue( "check managed repositories", repository.getLocation().endsWith( "data/repositories/internal" ) );
-
+
generatedTestDefaultArchivaConfigFile.delete();
assertFalse( generatedTestDefaultArchivaConfigFile.exists() );
}
-
+
/**
* Ensures that the provided configuration matches the details present in the archiva-default.xml file.
*/
private void assertConfiguration( Configuration configuration )
throws Exception
{
- FileTypes filetypes = (FileTypes) lookup( FileTypes.class.getName() );
+ FileTypes filetypes = (FileTypes) lookup( FileTypes.class );
assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
@@ -158,11 +198,12 @@ public class ArchivaConfigurationTest
assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() );
}
+ @Test
public void testGetConfigurationFromRegistryWithTwoConfigurationResources()
throws Exception
{
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration-both" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration-both" );
Configuration configuration = archivaConfiguration.getConfiguration();
@@ -183,6 +224,7 @@ public class ArchivaConfigurationTest
assertFalse( "check appletFindEnabled", ui.isAppletFindEnabled() );
}
+ @Test
public void testGetConfigurationSystemOverride()
throws Exception
{
@@ -190,7 +232,9 @@ public class ArchivaConfigurationTest
System.setProperty( "org.apache.maven.archiva.webapp.ui.appletFindEnabled", "false" );
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration" );
+
+ archivaConfiguration.reload();
try
{
@@ -204,6 +248,7 @@ public class ArchivaConfigurationTest
}
}
+ @Test
public void testStoreConfiguration()
throws Exception
{
@@ -212,11 +257,13 @@ public class ArchivaConfigurationTest
assertFalse( file.exists() );
// TODO: remove with commons-configuration 1.4
- file.getParentFile().mkdirs();
- FileUtils.writeStringToFile( file, "<configuration/>", null );
+ //file.getParentFile().mkdirs();
+ //FileUtils.writeStringToFile( file, "<configuration/>", null );
DefaultArchivaConfiguration archivaConfiguration =
- (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save" );
+ (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save" );
+
+ archivaConfiguration.reload();
Configuration configuration = new Configuration();
configuration.setVersion( "1" );
@@ -246,7 +293,9 @@ public class ArchivaConfigurationTest
// read it back
archivaConfiguration =
- (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" );
+ (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
+
+ archivaConfiguration.reload();
configuration = archivaConfiguration.getConfiguration();
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
}
@@ -256,6 +305,7 @@ public class ArchivaConfigurationTest
return MockControl.createControl( ConfigurationListener.class );
}
+ @Test
public void testStoreConfigurationUser()
throws Exception
{
@@ -271,7 +321,7 @@ public class ArchivaConfigurationTest
FileUtils.writeStringToFile( userFile, "<configuration/>", null );
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
Configuration configuration = new Configuration();
configuration.setWebapp( new WebappConfiguration() );
@@ -288,6 +338,7 @@ public class ArchivaConfigurationTest
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
}
+ @Test
public void testStoreConfigurationLoadedFromDefaults()
throws Exception
{
@@ -300,7 +351,9 @@ public class ArchivaConfigurationTest
assertFalse( userFile.exists() );
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
+
+ archivaConfiguration.reload();
Configuration configuration = new Configuration();
configuration.setWebapp( new WebappConfiguration() );
@@ -330,11 +383,14 @@ public class ArchivaConfigurationTest
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
}
+ @Test
public void testDefaultUserConfigFilename()
throws Exception
{
DefaultArchivaConfiguration archivaConfiguration =
- (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName() );
+ (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
+
+ archivaConfiguration.reload();
assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
archivaConfiguration.getUserConfigFilename() );
@@ -342,6 +398,7 @@ public class ArchivaConfigurationTest
archivaConfiguration.getAltConfigFilename() );
}
+ @Test
public void testStoreConfigurationFallback()
throws Exception
{
@@ -357,7 +414,9 @@ public class ArchivaConfigurationTest
FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
+
+ archivaConfiguration.reload();
Configuration configuration = new Configuration();
configuration.setWebapp( new WebappConfiguration() );
@@ -369,11 +428,13 @@ public class ArchivaConfigurationTest
assertTrue( "Check file exists", baseFile.exists() );
assertFalse( "Check file not created", userFile.exists() );
+
// check it
configuration = archivaConfiguration.getConfiguration();
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
}
+ @Test
public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
throws Exception
{
@@ -392,7 +453,9 @@ public class ArchivaConfigurationTest
FileUtils.writeStringToFile( userFile, "<configuration/>", null );
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
+
+ archivaConfiguration.reload();
Configuration configuration = archivaConfiguration.getConfiguration();
assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
@@ -413,6 +476,7 @@ public class ArchivaConfigurationTest
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
}
+ @Test
public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
throws Exception
{
@@ -431,7 +495,9 @@ public class ArchivaConfigurationTest
FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
+
+ archivaConfiguration.reload();
Configuration configuration = archivaConfiguration.getConfiguration();
assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
@@ -452,6 +518,7 @@ public class ArchivaConfigurationTest
assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
}
+ @Test
public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
throws Exception
{
@@ -470,7 +537,9 @@ public class ArchivaConfigurationTest
FileUtils.writeStringToFile( userFile, "<configuration/>", null );
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
+
+ archivaConfiguration.reload();
Configuration configuration = archivaConfiguration.getConfiguration();
assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
@@ -490,11 +559,12 @@ public class ArchivaConfigurationTest
}
}
+ @Test
public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
throws Exception
{
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-not-allowed-to-write-to-both" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
Configuration config = archivaConfiguration.getConfiguration();
try
@@ -508,6 +578,7 @@ public class ArchivaConfigurationTest
}
}
+ @Test
public void testLoadConfigurationFromInvalidUserLocationOnDisk()
throws Exception
{
@@ -515,18 +586,19 @@ public class ArchivaConfigurationTest
testConfDir.mkdirs();
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-not-allowed-to-write-to-user" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
Configuration config = archivaConfiguration.getConfiguration();
archivaConfiguration.save( config );
// No Exception == test passes.
// Expected Path is: Should not have thrown an exception.
}
+ @Test
public void testConfigurationUpgradeFrom09()
throws Exception
{
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-upgrade-09" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-upgrade-09" );
// we just use the defaults when upgrading from 0.9 at this point.
Configuration configuration = archivaConfiguration.getConfiguration();
@@ -544,6 +616,7 @@ public class ArchivaConfigurationTest
assertTrue( "check managed repositories", repository.isScanned() );
}
+ @Test
public void testAutoDetectV1()
throws Exception
{
@@ -557,7 +630,9 @@ public class ArchivaConfigurationTest
// Load the original (unconverted) archiva.xml
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-autodetect-v1" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
+
+ archivaConfiguration.reload();
Configuration configuration = archivaConfiguration.getConfiguration();
assertConfiguration( configuration );
@@ -582,11 +657,11 @@ public class ArchivaConfigurationTest
archivaConfiguration.save( configuration );
// Release existing
- release( archivaConfiguration );
+ //release( archivaConfiguration );
// Reload.
archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-autodetect-v1" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
configuration = archivaConfiguration.getConfiguration();
// Test that only 1 set of repositories exist.
@@ -601,11 +676,12 @@ public class ArchivaConfigurationTest
XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
}
+ @Test
public void testArchivaV1()
throws Exception
{
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-archiva-v1" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-archiva-v1" );
Configuration configuration = archivaConfiguration.getConfiguration();
assertConfiguration( configuration );
@@ -635,6 +711,7 @@ public class ArchivaConfigurationTest
assertTrue( "check managed repositories", repository.isSnapshots() );
}
+ @Test
public void testCronExpressionsWithComma()
throws Exception
{
@@ -653,7 +730,9 @@ public class ArchivaConfigurationTest
FileUtils.writeStringToFile( userFile, "<configuration/>", null );
final ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-cron-expressions" );
+ lookup( ArchivaConfiguration.class, "test-cron-expressions" );
+
+ archivaConfiguration.reload();
Configuration configuration = archivaConfiguration.getConfiguration();
@@ -696,6 +775,7 @@ public class ArchivaConfigurationTest
assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
}
+ @Test
public void testRemoveLastElements()
throws Exception
{
@@ -714,15 +794,16 @@ public class ArchivaConfigurationTest
FileUtils.writeStringToFile( userFile, "<configuration/>", null );
ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-remove-central" );
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-remove-central" );
Configuration configuration = archivaConfiguration.getConfiguration();
-
- RepositoryGroupConfiguration repositoryGroup = ( RepositoryGroupConfiguration ) configuration.getRepositoryGroups().get( 0 );
+
+ RepositoryGroupConfiguration repositoryGroup =
+ (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
assertNotNull( repositoryGroup );
configuration.removeRepositoryGroup( repositoryGroup );
assertTrue( configuration.getRepositoryGroups().isEmpty() );
-
+
RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
assertNotNull( repository );
configuration.removeRemoteRepository( repository );
@@ -772,8 +853,7 @@ public class ArchivaConfigurationTest
archivaConfiguration.save( configuration );
- archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" );
+ archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
configuration = archivaConfiguration.getConfiguration();
assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
assertTrue( configuration.getRepositoryGroups().isEmpty() );
@@ -792,21 +872,24 @@ public class ArchivaConfigurationTest
/**
* [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
*/
+ @Test
public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
throws Exception
{
- ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup(
- ArchivaConfiguration.class.getName(),
- "test-configuration" );
+ ArchivaConfiguration archivaConfiguration =
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration" );
+ archivaConfiguration.reload();
Configuration configuration = archivaConfiguration.getConfiguration();
assertConfiguration( configuration );
assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
- RemoteRepositoryConfiguration repository = (RemoteRepositoryConfiguration) configuration
- .getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
+ RemoteRepositoryConfiguration repository =
+ (RemoteRepositoryConfiguration) configuration.getRemoteRepositoriesAsMap().get(
+ "maven2-repository.dev.java.net" );
- assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository", repository.getUrl() );
+ assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
+ repository.getUrl() );
assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
assertEquals( "remote repository.layout", "default", repository.getLayout() );
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ConfigurationTest.java b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ConfigurationTest.java
index fa6699766..80d21179a 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ConfigurationTest.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ConfigurationTest.java
@@ -20,6 +20,9 @@ package org.apache.maven.archiva.configuration;
*/
import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import java.util.Arrays;
import java.util.HashSet;
@@ -28,11 +31,13 @@ import java.util.Map;
/**
* Test the generated Configuration class from Modello. This is primarily to test the hand coded methods.
*/
+@RunWith( JUnit4.class )
public class ConfigurationTest
extends TestCase
{
private Configuration configuration = new Configuration();
+ @Test
public void testNetworkProxyRetrieval()
{
NetworkProxyConfiguration proxy1 = createNetworkProxy( "id1", "host1", 8080 );
@@ -58,6 +63,7 @@ public class ConfigurationTest
return proxy;
}
+ @Test
public void testRemoteRepositoryRetrieval()
{
RemoteRepositoryConfiguration repo1 = createRemoteRepository( "id1", "name 1", "url 1" );
@@ -87,6 +93,7 @@ public class ConfigurationTest
return repo;
}
+ @Test
public void testManagedRepositoryRetrieval()
{
ManagedRepositoryConfiguration repo1 = createManagedRepository( "id1", "name 1", "path 1", false );
@@ -117,6 +124,7 @@ public class ConfigurationTest
return repo;
}
+ @Test
public void testNetworkProxyRetrievalWhenEmpty()
{
Map<String, NetworkProxyConfiguration> map = configuration.getNetworkProxiesAsMap();
@@ -124,6 +132,7 @@ public class ConfigurationTest
assertTrue( map.isEmpty() );
}
+ @Test
public void testRemoteRepositoryRetrievalWhenEmpty()
{
Map<String, RemoteRepositoryConfiguration> map = configuration.getRemoteRepositoriesAsMap();
@@ -133,6 +142,7 @@ public class ConfigurationTest
assertNull( configuration.findRemoteRepositoryById( "id" ) );
}
+ @Test
public void testManagedRepositoryRetrievalWhenEmpty()
{
Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/FileTypesTest.java b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/FileTypesTest.java
index 613c86c24..598ee244a 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/FileTypesTest.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/FileTypesTest.java
@@ -19,11 +19,20 @@ package org.apache.maven.archiva.configuration;
* under the License.
*/
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import javax.inject.Inject;
+
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml"} )
public class FileTypesTest
- extends PlexusInSpringTestCase
+ extends TestCase
{
+ @Inject
private FileTypes filetypes;
protected void setUp()
@@ -31,9 +40,9 @@ public class FileTypesTest
{
super.setUp();
- filetypes = (FileTypes) lookup( FileTypes.class );
}
+ @Test
public void testIsArtifact()
{
assertTrue( filetypes.matchesArtifactPattern( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
@@ -52,7 +61,8 @@ public class FileTypesTest
assertFalse( filetypes.matchesArtifactPattern( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
assertFalse( filetypes.matchesArtifactPattern( "org/apache/derby/derby/maven-metadata.xml" ) );
}
-
+
+ @Test
public void testDefaultExclusions()
{
assertTrue( filetypes.matchesDefaultExclusions( "repository/test/.index/nexus-maven-repository-index.gz" ) );
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/LegacyArtifactPathTest.java b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/LegacyArtifactPathTest.java
index dfeba0527..f19e2d0ab 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/LegacyArtifactPathTest.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/LegacyArtifactPathTest.java
@@ -20,17 +20,22 @@ package org.apache.maven.archiva.configuration;
*/
import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Test the generated LegacyArtifactPath class from Modello. This is primarily to test the hand coded methods.
* @since 1.1
*/
+@RunWith( JUnit4.class )
public class LegacyArtifactPathTest
extends TestCase
{
private LegacyArtifactPath legacyArtifactPath = new LegacyArtifactPath();
+ @Test
public void testLegacyArtifactPathWithClassifierResolution()
{
legacyArtifactPath.setArtifact( "groupId:artifactId:version:classifier:type" );
@@ -42,7 +47,7 @@ public class LegacyArtifactPathTest
assertEquals( "type", legacyArtifactPath.getType() );
}
-
+ @Test
public void testLegacyArtifactPathWithoutClassifierResolution()
{
legacyArtifactPath.setArtifact( "groupId:artifactId:version::type" );
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java
index 9e138f476..6eb7ef56a 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java
@@ -19,34 +19,38 @@ package org.apache.maven.archiva.configuration;
* under the License.
*/
+import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-
/**
*/
+@RunWith( JUnit4.class )
public class MavenProxyPropertyLoaderTest
- extends PlexusInSpringTestCase
+ extends TestCase
{
private MavenProxyPropertyLoader loader;
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getSpringConfigLocation()
- */
+
+ // TODO to remove
protected String getSpringConfigLocation()
{
return "org/apache/maven/archiva/configuration/spring-context.xml";
}
+ @Test
public void testLoadValidMavenProxyConfiguration()
throws IOException, InvalidConfigurationException
{
- File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" );
+ File confFile = ArchivaConfigurationTest.getTestFile( "src/test/conf/maven-proxy-complete.conf" );
Configuration configuration = new Configuration();
NetworkProxyConfiguration proxy = new NetworkProxyConfiguration();
@@ -84,6 +88,7 @@ public class MavenProxyPropertyLoaderTest
assertEquals( "Repository url", expectedUrl, repo.getUrl() );
}
+ @Test
public void testInvalidConfiguration()
{
Configuration configuration = new Configuration();
@@ -98,7 +103,8 @@ public class MavenProxyPropertyLoaderTest
}
}
- protected void setUp()
+ @Before
+ public void setUp()
throws Exception
{
super.setUp();
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml
new file mode 100755
index 000000000..697cde1a6
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml
@@ -0,0 +1,280 @@
+<?xml version="1.0"?>
+
+<!--
+ ~ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+ default-lazy-init="true">
+
+ <context:property-placeholder system-properties-mode="OVERRIDE"/>
+
+ <bean name="archivaConfiguration#test-defaults-default-repo-location-exists" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#empty"/>
+ </bean>
+
+ <bean name="archivaConfiguration#test-defaults" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#empty"/>
+ </bean>
+ <bean name="registry#empty" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry"/>
+
+ <bean name="archivaConfiguration#test-upgrade-09" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#test-upgrade-09"/>
+ </bean>
+
+ <bean name="registry#test-upgrade-09" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <xml fileName="${basedir}/src/test/conf/archiva-0.9.xml"
+ config-name="org.apache.maven.archiva" config-at="org.apache.maven.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+ <bean name="archivaConfiguration#test-configuration" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#configured"/>
+ </bean>
+
+ <bean name="registry#configured" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <system/>
+ <xml fileName="${basedir}/src/test/conf/repository-manager.xml"
+ config-name="org.apache.maven.archiva" config-at="org.apache.maven.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+
+ <bean name="archivaConfiguration#test-autodetect-v1" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#test-autodetect-v1"/>
+ </bean>
+
+ <bean name="registry#test-autodetect-v1" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <system/>
+ <xml fileName="${basedir}/target/test-autodetect-v1/archiva-user.xml" config-optional="true"
+ config-name="org.apache.maven.archiva.user"
+ config-at="org.apache.maven.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+ <bean name="archivaConfiguration#test-archiva-v1" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#test-archiva-v1"/>
+ </bean>
+
+ <bean name="registry#test-archiva-v1" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <system/>
+ <xml fileName="${basedir}/src/test/conf/archiva-v1.xml"
+ config-name="org.apache.maven.archiva" config-at="org.apache.maven.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+ <bean name="archivaConfiguration#test-save" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#test-save"/>
+ </bean>
+
+ <bean name="registry#test-save" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <xml fileName="${basedir}/target/test/test-file.xml" config-optional="true" config-forceCreate="true"
+ config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+ <bean name="archivaConfiguration#test-save-user" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#test-save-user"/>
+ </bean>
+
+ <bean name="registry#test-save-user" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <xml fileName="${basedir}/target/test/test-file-user.xml" config-optional="true" config-forceCreate="false"
+ config-name="org.apache.maven.archiva.user" config-at="org.apache.maven.archiva"/>
+ <xml fileName="${basedir}/target/test/test-file.xml" config-optional="true" config-forceCreate="true"
+ config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+
+ <bean name="archivaConfiguration#test-configuration-both" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#test-configuration-both"/>
+ </bean>
+
+ <bean name="registry#test-configuration-both" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <xml fileName="${basedir}/src/test/conf/conf-user.xml" config-optional="true" config-forceCreate="true"
+ config-name="org.apache.maven.archiva.user" config-at="org.apache.maven.archiva"/>
+ <xml fileName="${basedir}/src/test/conf/conf-base.xml" config-optional="true" config-forceCreate="true"
+ config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+
+ <bean name="archivaConfiguration#test-read-saved" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#test-read-saved"/>
+ </bean>
+
+ <bean name="registry#test-read-saved" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <xml fileName="${basedir}/target/test/test-file.xml" config-optional="true" config-forceCreate="true"
+ config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+
+ <bean name="archivaConfiguration#test-cron-expressions" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#test-cron-expressions"/>
+ <property name="userConfigFilename" value="${basedir}/target/test/test-file.xml"/>
+ </bean>
+
+ <bean name="registry#test-cron-expressions" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <xml fileName="${basedir}/target/test/test-file.xml" config-optional="true" config-forceCreate="true"
+ config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+
+ <bean name="archivaConfiguration#test-remove-central" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#test-remove-central"/>
+ </bean>
+
+ <bean name="registry#test-remove-central" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <xml fileName="${basedir}/target/test/test-file.xml" config-optional="true" config-forceCreate="true"
+ config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+
+ <bean name="archivaConfiguration#test-not-allowed-to-write-to-both" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#test-not-allowed-to-write-to-both"/>
+ <property name="userConfigFilename" value="${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml"/>
+ <property name="altConfigFilename" value="${basedir}/target/*intentionally:invalid*/conf/archiva.xml"/>
+ </bean>
+
+ <bean name="registry#test-not-allowed-to-write-to-both" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <xml fileName="${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml" config-optional="true"
+ config-name="org.apache.maven.archiva.user" config-at="org.apache.maven.archiva"/>
+ <xml fileName="${basedir}/target/*intentionally:invalid*/conf/archiva.xml" config-optional="true"
+ config-name="org.apache.maven.archiva.user" config-at="org.apache.maven.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+ <bean name="archivaConfiguration#test-not-allowed-to-write-to-user" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#test-not-allowed-to-write-to-user"/>
+ <property name="userConfigFilename" value="${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml"/>
+ <property name="altConfigFilename" value="${basedir}/target/test-appserver-base/conf/archiva.xml"/>
+ </bean>
+
+ <bean name="registry#test-not-allowed-to-write-to-user" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <xml fileName="${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml" config-optional="true"
+ config-name="org.apache.maven.archiva.user" config-at="org.apache.maven.archiva"/>
+ <xml fileName="${basedir}/target/test-appserver-base/conf/archiva.xml" config-optional="true"
+ config-name="org.apache.maven.archiva.user" config-at="org.apache.maven.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+ <bean name="cache#url-failures-cache" class="org.codehaus.plexus.cache.ehcache.EhcacheCache">
+ <property name="diskExpiryThreadIntervalSeconds" value="600"/>
+ <property name="diskPersistent" value="false"/>
+ <property name="eternal" value="false"/>
+ <property name="maxElementsInMemory" value="1000"/>
+ <property name="memoryEvictionPolicy" value="LRU"/>
+ <property name="name" value="cache"/>
+ <property name="overflowToDisk" value="false"/>
+ <property name="timeToIdleSeconds" value="2700"/>
+ <property name="timeToLiveSeconds" value="1800"/>
+ </bean>
+
+</beans> \ No newline at end of file
diff --git a/archiva-modules/archiva-base/archiva-policies/pom.xml b/archiva-modules/archiva-base/archiva-policies/pom.xml
index d3247ea98..ca681bfc6 100644
--- a/archiva-modules/archiva-base/archiva-policies/pom.xml
+++ b/archiva-modules/archiva-base/archiva-policies/pom.xml
@@ -38,23 +38,18 @@
<artifactId>archiva-checksum</artifactId>
</dependency>
<dependency>
- <groupId>org.codehaus.redback.components</groupId>
- <artifactId>plexus-spring</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-asm</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.codehaus.redback.components.cache</groupId>
<artifactId>spring-cache-api</artifactId>
<exclusions>
<exclusion>
- <groupId>org.springframework</groupId>
- <artifactId>spring-asm</artifactId>
- </exclusion>
- <exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
@@ -91,21 +86,23 @@
<artifactId>jcl-over-slf4j</artifactId>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
+
<build>
<plugins>
<plugin>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-component-metadata</artifactId>
- <executions>
- <execution>
- <id>descriptor</id>
- <phase>generate-resources</phase>
- <goals>
- <goal>generate-metadata</goal>
- </goals>
- </execution>
- </executions>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <basedir>${basedir}</basedir>
+ </systemPropertyVariables>
+ </configuration>
</plugin>
</plugins>
</build>
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/CachedFailuresPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/CachedFailuresPolicy.java
index 6b4584ad3..ae8b735d6 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/CachedFailuresPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/CachedFailuresPolicy.java
@@ -28,6 +28,9 @@ import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
/**
* {@link PreDownloadPolicy} to check if the requested url has failed before.
@@ -36,6 +39,7 @@ import org.slf4j.LoggerFactory;
* @plexus.component role="org.apache.maven.archiva.policies.PreDownloadPolicy"
* role-hint="cache-failures"
*/
+@Service("preDownloadPolicy#cache-failures")
public class CachedFailuresPolicy
implements PreDownloadPolicy
{
@@ -56,6 +60,7 @@ public class CachedFailuresPolicy
/**
* @plexus.requirement
*/
+ @Inject
private UrlFailureCache urlFailureCache;
private List<String> options = new ArrayList<String>();
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ChecksumPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ChecksumPolicy.java
index 4627d331e..5fcea2440 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ChecksumPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ChecksumPolicy.java
@@ -29,6 +29,7 @@ import org.apache.archiva.checksum.ChecksummedFile;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
/**
* ChecksumPolicy - a policy applied after the download to see if the file has been downloaded
@@ -39,6 +40,7 @@ import org.slf4j.LoggerFactory;
* @plexus.component role="org.apache.maven.archiva.policies.PostDownloadPolicy"
* role-hint="checksum"
*/
+@Service("postDownloadPolicy#checksum")
public class ChecksumPolicy
implements PostDownloadPolicy
{
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/PropagateErrorsDownloadPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/PropagateErrorsDownloadPolicy.java
index e21130e6f..47e18173b 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/PropagateErrorsDownloadPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/PropagateErrorsDownloadPolicy.java
@@ -28,6 +28,7 @@ import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
/**
* PropagateErrorsPolicy - a policy applied on error to determine how to treat the error.
@@ -35,6 +36,7 @@ import org.slf4j.LoggerFactory;
* @plexus.component role="org.apache.maven.archiva.policies.DownloadErrorPolicy"
* role-hint="propagate-errors"
*/
+@Service("downloadErrorPolicy#propagate-errors")
public class PropagateErrorsDownloadPolicy
implements DownloadErrorPolicy
{
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java
index 9e20ba524..bbceee338 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java
@@ -26,6 +26,7 @@ import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
+import org.springframework.stereotype.Service;
/**
* PropagateErrorsPolicy - a policy applied on error to determine how to treat the error.
@@ -33,6 +34,7 @@ import org.apache.commons.lang.StringUtils;
* @plexus.component role="org.apache.maven.archiva.policies.DownloadErrorPolicy"
* role-hint="propagate-errors-on-update"
*/
+@Service("downloadErrorPolicy#propagate-errors-on-update")
public class PropagateErrorsOnUpdateDownloadPolicy
implements DownloadErrorPolicy
{
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ReleasesPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ReleasesPolicy.java
index 82df41ed3..75bb82e72 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ReleasesPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ReleasesPolicy.java
@@ -20,6 +20,8 @@ package org.apache.maven.archiva.policies;
*/
+import org.springframework.stereotype.Service;
+
/**
* {@link PreDownloadPolicy} to apply for released versions.
*
@@ -28,6 +30,7 @@ package org.apache.maven.archiva.policies;
* @plexus.component role="org.apache.maven.archiva.policies.PreDownloadPolicy"
* role-hint="releases"
*/
+@Service("preDownloadPolicy#releases")
public class ReleasesPolicy
extends AbstractUpdatePolicy
implements PreDownloadPolicy
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/SnapshotsPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/SnapshotsPolicy.java
index 3cce0b032..a8e3863f3 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/SnapshotsPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/SnapshotsPolicy.java
@@ -20,6 +20,8 @@ package org.apache.maven.archiva.policies;
*/
+import org.springframework.stereotype.Service;
+
/**
* {@link PreDownloadPolicy} to apply for snapshot versions.
*
@@ -28,6 +30,7 @@ package org.apache.maven.archiva.policies;
* @plexus.component role="org.apache.maven.archiva.policies.PreDownloadPolicy"
* role-hint="snapshots"
*/
+@Service("preDownloadPolicy#snapshots")
public class SnapshotsPolicy
extends AbstractUpdatePolicy
implements PreDownloadPolicy
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/urlcache/UrlFailureCache.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/urlcache/UrlFailureCache.java
index 67fcc4bfa..0abdf6ecd 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/urlcache/UrlFailureCache.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/urlcache/UrlFailureCache.java
@@ -32,7 +32,7 @@ public interface UrlFailureCache
*
* @param url the url to store.
*/
- public void cacheFailure( String url );
+ void cacheFailure( String url );
/**
* Test if a specified URL has failed before.
@@ -43,5 +43,5 @@ public interface UrlFailureCache
* @param url the URL to test.
* @return true if it has failed before, false if not.
*/
- public boolean hasFailedBefore( String url );
+ boolean hasFailedBefore( String url );
}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-policies/src/main/resources/META-INF/spring-context.xml
index 082069ef7..ffdf1cc6d 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/resources/META-INF/spring-context.xml
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/resources/META-INF/spring-context.xml
@@ -19,8 +19,15 @@
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+ <context:property-placeholder system-properties-mode="FALLBACK"/>
+ <context:annotation-config/>
+ <context:component-scan base-package="org.apache.maven.archiva.policies"/>
<bean id="urlFailureCache"
class="org.apache.maven.archiva.policies.urlcache.DefaultUrlFailureCache" lazy-init="true">
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java
index 3ee8878d8..f6b3bb2ee 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java
@@ -19,24 +19,40 @@ package org.apache.maven.archiva.policies;
* under the License.
*/
+import junit.framework.TestCase;
+import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import javax.inject.Named;
import java.io.File;
import java.util.Properties;
-import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-
/**
* CachedFailuresPolicyTest
*
* @version $Id$
*/
+@RunWith( value = SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
public class CachedFailuresPolicyTest
- extends PlexusInSpringTestCase
+ extends TestCase
{
+
+
+ @Inject
+ private UrlFailureCache urlFailureCache;
+
+ @Inject @Named(value="preDownloadPolicy#cache-failures")
+ DownloadPolicy downloadPolicy;
+
private DownloadPolicy lookupPolicy()
throws Exception
{
- return (DownloadPolicy) lookup( PreDownloadPolicy.class, "cache-failures" );
+ return downloadPolicy;
}
private File getFile()
@@ -51,6 +67,7 @@ public class CachedFailuresPolicyTest
return request;
}
+ @Test
public void testPolicyNo()
throws Exception
{
@@ -63,9 +80,13 @@ public class CachedFailuresPolicyTest
policy.applyPolicy( CachedFailuresPolicy.NO, request, localFile );
}
+ @Test
public void testPolicyYesNotInCache()
throws Exception
{
+
+ //CacheManager.getInstance().clearAll();
+
DownloadPolicy policy = lookupPolicy();
File localFile = getFile();
Properties request = createRequest();
@@ -75,6 +96,7 @@ public class CachedFailuresPolicyTest
policy.applyPolicy( CachedFailuresPolicy.YES, request, localFile );
}
+ @Test
public void testPolicyYesInCache()
throws Exception
{
@@ -84,7 +106,7 @@ public class CachedFailuresPolicyTest
String url = "http://a.bad.hostname.maven.org/path/to/resource.txt";
- UrlFailureCache urlFailureCache = (UrlFailureCache) lookup( "urlFailureCache" );
+
urlFailureCache.cacheFailure( url );
request.setProperty( "url", url );
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ChecksumPolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ChecksumPolicyTest.java
index 5a2a14ae1..7d7448862 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ChecksumPolicyTest.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ChecksumPolicyTest.java
@@ -19,134 +19,171 @@ package org.apache.maven.archiva.policies;
* under the License.
*/
+import junit.framework.TestCase;
+import org.apache.commons.io.FileUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import javax.inject.Named;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Properties;
-import org.apache.commons.io.FileUtils;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-
/**
* ChecksumPolicyTest
*
* @version $Id$
*/
+@RunWith( value = SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
public class ChecksumPolicyTest
- extends PlexusInSpringTestCase
+ extends TestCase
{
private static final String GOOD = "good";
private static final String BAD = "bad";
+ @Inject
+ @Named(value="postDownloadPolicy#checksum")
+ PostDownloadPolicy downloadPolicy;
+
+ private PostDownloadPolicy lookupPolicy()
+ throws Exception
+ {
+ return downloadPolicy;
+ }
+
+ @Test
public void testFailOnFileOnly()
throws Exception
{
assertFailSetting( false, null, null );
}
+ @Test
public void testFailOnFileWithBadMd5AndBadSha1()
throws Exception
{
assertFailSetting( false, BAD, BAD );
}
+ @Test
public void testFailOnFileWithBadMd5AndGoodSha1()
throws Exception
{
assertFailSetting( false, BAD, GOOD );
}
+ @Test
public void testFailOnFileWithBadMd5Only()
throws Exception
{
assertFailSetting( false, BAD, null );
}
+ @Test
public void testFailOnFileWithBadSha1Only()
throws Exception
{
assertFailSetting( false, null, BAD );
}
+ @Test
public void testFailOnFileWithGoodMd5AndBadSha1()
throws Exception
{
assertFailSetting( false, GOOD, BAD );
}
+ @Test
public void testFailOnFileWithGoodMd5AndGoodSha1()
throws Exception
{
assertFailSetting( true, GOOD, GOOD );
}
+ @Test
public void testFailOnFileWithGoodMd5Only()
throws Exception
{
assertFailSetting( true, GOOD, null );
}
+ @Test
public void testFailOnFileWithGoodSha1Only()
throws Exception
{
assertFailSetting( true, null, GOOD );
}
+ @Test
public void testFixOnFileOnly()
throws Exception
{
assertFixSetting( true, null, null );
}
+ @Test
public void testFixOnFileWithBadMd5AndBadSha1()
throws Exception
{
assertFixSetting( true, BAD, BAD );
}
+ @Test
public void testFixOnFileWithBadMd5AndGoodSha1()
throws Exception
{
assertFixSetting( true, BAD, GOOD );
}
+ @Test
public void testFixOnFileWithBadMd5Only()
throws Exception
{
assertFixSetting( true, BAD, null );
}
+ @Test
public void testFixOnFileWithBadSha1Only()
throws Exception
{
assertFixSetting( true, null, BAD );
}
+ @Test
public void testFixOnFileWithGoodMd5AndBadSha1()
throws Exception
{
assertFixSetting( true, GOOD, BAD );
}
+ @Test
public void testFixOnFileWithGoodMd5AndGoodSha1()
throws Exception
{
assertFixSetting( true, GOOD, GOOD );
}
+ @Test
public void testFixOnFileWithGoodMd5Only()
throws Exception
{
assertFixSetting( true, GOOD, null );
}
+ @Test
public void testFixOnFileWithGoodSha1Only()
throws Exception
{
assertFixSetting( true, null, GOOD );
}
+ @Test
public void testIgnore()
throws Exception
{
@@ -320,12 +357,22 @@ public class ChecksumPolicyTest
return localFile;
}
- private PostDownloadPolicy lookupPolicy()
- throws Exception
+
+
+ public static String getBasedir()
+ {
+ String basedir = System.getProperty( "basedir" );
+ if ( basedir == null )
+ {
+ basedir = new File( "" ).getAbsolutePath();
+ }
+
+ return basedir;
+ }
+
+ public static File getTestFile( String path )
{
- PostDownloadPolicy policy = (PostDownloadPolicy) lookup( PostDownloadPolicy.class.getName(), "checksum" );
- assertNotNull( policy );
- return policy;
+ return new File( getBasedir(), path );
}
}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ReleasePolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ReleasePolicyTest.java
index 9961e32fa..4d73d3238 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ReleasePolicyTest.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ReleasePolicyTest.java
@@ -19,9 +19,16 @@ package org.apache.maven.archiva.policies;
* under the License.
*/
+import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import javax.inject.Named;
import java.io.File;
import java.util.Properties;
@@ -30,8 +37,10 @@ import java.util.Properties;
*
* @version $Id$
*/
+@RunWith( value = SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
public class ReleasePolicyTest
- extends PlexusInSpringTestCase
+ extends TestCase
{
private static final String PATH_VERSION_METADATA = "org/apache/archiva/archiva-testable/1.0-SNAPSHOT/maven-metadata.xml";
@@ -63,6 +72,17 @@ public class ReleasePolicyTest
private long generatedLocalFileUpdateDelta = 0;
+
+ @Inject @Named(value = "preDownloadPolicy#releases")
+ PreDownloadPolicy preDownloadPolicy;
+
+ private PreDownloadPolicy lookupPolicy()
+ throws Exception
+ {
+ return preDownloadPolicy;
+ }
+
+ @Test
public void testReleasePolicyDailyProjectMetadata()
throws Exception
{
@@ -79,6 +99,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.DAILY, PATH_PROJECT_METADATA, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyDailyReleaseArtifact()
throws Exception
{
@@ -94,6 +115,7 @@ public class ReleasePolicyTest
assertReleasesPolicyViolation( ReleasesPolicy.DAILY, PATH_RELEASE_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyDailySnapshotArtifact()
throws Exception
{
@@ -109,6 +131,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.DAILY, PATH_SNAPSHOT_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyDailyVersionedMetadata()
throws Exception
{
@@ -125,6 +148,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.DAILY, PATH_VERSION_METADATA, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyRejectProjectMetadata()
throws Exception
{
@@ -133,6 +157,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.NEVER, PATH_PROJECT_METADATA, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyRejectReleaseArtifact()
throws Exception
{
@@ -140,6 +165,7 @@ public class ReleasePolicyTest
assertReleasesPolicyViolation( ReleasesPolicy.NEVER, PATH_RELEASE_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyRejectSnapshotArtifact()
throws Exception
{
@@ -147,6 +173,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.NEVER, PATH_SNAPSHOT_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyRejectVersionedMetadata()
throws Exception
{
@@ -155,6 +182,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.NEVER, PATH_VERSION_METADATA, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyHourlyProjectMetadata()
throws Exception
{
@@ -171,6 +199,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.HOURLY, PATH_PROJECT_METADATA, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyHourlyReleaseArtifact()
throws Exception
{
@@ -186,6 +215,7 @@ public class ReleasePolicyTest
assertReleasesPolicyViolation( ReleasesPolicy.HOURLY, PATH_RELEASE_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyHourlySnapshotArtifact()
throws Exception
{
@@ -201,6 +231,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.HOURLY, PATH_SNAPSHOT_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyHourlyVersionedMetadata()
throws Exception
{
@@ -217,6 +248,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.HOURLY, PATH_VERSION_METADATA, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyAlwaysProjectMetadata()
throws Exception
{
@@ -225,6 +257,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.ALWAYS, PATH_PROJECT_METADATA, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyAlwaysReleaseArtifact()
throws Exception
{
@@ -232,6 +265,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.ALWAYS, PATH_RELEASE_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyAlwaysSnapshotArtifact()
throws Exception
{
@@ -239,6 +273,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.ALWAYS, PATH_SNAPSHOT_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyAlwaysVersionedMetadata()
throws Exception
{
@@ -247,6 +282,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.ALWAYS, PATH_VERSION_METADATA, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyOnceProjectMetadata()
throws Exception
{
@@ -255,6 +291,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.ONCE, PATH_PROJECT_METADATA, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyOnceReleaseArtifact()
throws Exception
{
@@ -262,6 +299,7 @@ public class ReleasePolicyTest
assertReleasesPolicyViolation( ReleasesPolicy.ONCE, PATH_RELEASE_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyOnceSnapshotArtifact()
throws Exception
{
@@ -269,6 +307,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.ONCE, PATH_SNAPSHOT_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testReleasePolicyOnceVersionedMetadata()
throws Exception
{
@@ -294,7 +333,7 @@ public class ReleasePolicyTest
request.setProperty( "version", "2.0" );
}
- File targetDir = getTestFile( "target/test-policy/" );
+ File targetDir = ChecksumPolicyTest.getTestFile( "target/test-policy/" );
File localFile = new File( targetDir, path );
if ( localFile.exists() )
@@ -326,16 +365,10 @@ public class ReleasePolicyTest
}
}
- private PreDownloadPolicy lookupPolicy()
- throws Exception
- {
- PreDownloadPolicy policy = (PreDownloadPolicy) lookup( PreDownloadPolicy.class.getName(), "releases" );
- assertNotNull( policy );
- return policy;
- }
- @Override
- protected void setUp()
+
+ @Before
+ public void setUp()
throws Exception
{
super.setUp();
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/SnapshotsPolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/SnapshotsPolicyTest.java
index 0202555e2..8c6739df3 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/SnapshotsPolicyTest.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/SnapshotsPolicyTest.java
@@ -19,19 +19,28 @@ package org.apache.maven.archiva.policies;
* under the License.
*/
+import junit.framework.TestCase;
+import org.apache.commons.io.FileUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import javax.inject.Named;
import java.io.File;
import java.util.Properties;
-import org.apache.commons.io.FileUtils;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-
/**
* SnapshotsPolicyTest
*
* @version $Id$
*/
+@RunWith( value = SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
public class SnapshotsPolicyTest
- extends PlexusInSpringTestCase
+ extends TestCase
{
private static final String PATH_VERSION_METADATA = "org/apache/archiva/archiva-testable/1.0-SNAPSHOT/maven-metadata.xml";
@@ -63,6 +72,17 @@ public class SnapshotsPolicyTest
private long generatedLocalFileUpdateDelta = 0;
+
+ @Inject @Named(value="preDownloadPolicy#snapshots")
+ PreDownloadPolicy policy;
+
+ private PreDownloadPolicy lookupPolicy()
+ throws Exception
+ {
+ return policy;
+ }
+
+ @Test
public void testSnapshotPolicyDailyProjectMetadata()
throws Exception
{
@@ -79,6 +99,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.DAILY, PATH_PROJECT_METADATA, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyDailyReleaseArtifact()
throws Exception
{
@@ -94,6 +115,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.DAILY, PATH_RELEASE_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyDailySnapshotArtifact()
throws Exception
{
@@ -109,6 +131,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicyViolation( SnapshotsPolicy.DAILY, PATH_SNAPSHOT_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyDailyVersionedMetadata()
throws Exception
{
@@ -125,6 +148,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.DAILY, PATH_VERSION_METADATA, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyRejectProjectMetadata()
throws Exception
{
@@ -133,6 +157,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.NEVER, PATH_PROJECT_METADATA, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyRejectReleaseArtifact()
throws Exception
{
@@ -140,6 +165,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.NEVER, PATH_RELEASE_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyRejectSnapshotArtifact()
throws Exception
{
@@ -147,6 +173,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicyViolation( SnapshotsPolicy.NEVER, PATH_SNAPSHOT_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyRejectVersionedMetadata()
throws Exception
{
@@ -155,6 +182,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.NEVER, PATH_VERSION_METADATA, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyHourlyProjectMetadata()
throws Exception
{
@@ -171,6 +199,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.HOURLY, PATH_PROJECT_METADATA, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyHourlyReleaseArtifact()
throws Exception
{
@@ -186,6 +215,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.HOURLY, PATH_RELEASE_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyHourlySnapshotArtifact()
throws Exception
{
@@ -201,6 +231,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicyViolation( SnapshotsPolicy.HOURLY, PATH_SNAPSHOT_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyHourlyVersionedMetadata()
throws Exception
{
@@ -217,6 +248,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.HOURLY, PATH_VERSION_METADATA, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyAlwaysProjectMetadata()
throws Exception
{
@@ -225,6 +257,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.ALWAYS, PATH_PROJECT_METADATA, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyAlwaysReleaseArtifact()
throws Exception
{
@@ -232,6 +265,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.ALWAYS, PATH_RELEASE_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyAlwaysSnapshotArtifact()
throws Exception
{
@@ -239,6 +273,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.ALWAYS, PATH_SNAPSHOT_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyAlwaysVersionedMetadata()
throws Exception
{
@@ -247,6 +282,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.ALWAYS, PATH_VERSION_METADATA, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyOnceProjectMetadata()
throws Exception
{
@@ -255,6 +291,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.ONCE, PATH_PROJECT_METADATA, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyOnceReleaseArtifact()
throws Exception
{
@@ -262,6 +299,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.ONCE, PATH_RELEASE_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyOnceSnapshotArtifact()
throws Exception
{
@@ -269,6 +307,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicyViolation( SnapshotsPolicy.ONCE, PATH_SNAPSHOT_ARTIFACT, WITH_LOCAL );
}
+ @Test
public void testSnapshotPolicyOnceVersionedMetadata()
throws Exception
{
@@ -294,7 +333,7 @@ public class SnapshotsPolicyTest
request.setProperty( "version", "2.0" );
}
- File targetDir = getTestFile( "target/test-policy/" );
+ File targetDir = ChecksumPolicyTest.getTestFile( "target/test-policy/" );
File localFile = new File( targetDir, path );
if ( localFile.exists() )
@@ -326,16 +365,11 @@ public class SnapshotsPolicyTest
}
}
- private PreDownloadPolicy lookupPolicy()
- throws Exception
- {
- PreDownloadPolicy policy = (PreDownloadPolicy) lookup( PreDownloadPolicy.class.getName(), "snapshots" );
- assertNotNull( policy );
- return policy;
- }
+
@Override
- protected void setUp()
+ @Before
+ public void setUp()
throws Exception
{
super.setUp();
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.xml b/archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.xml
deleted file mode 100644
index a42cdec07..000000000
--- a/archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<component-set>
- <components>
- <component>
- <role>org.codehaus.plexus.cache.Cache</role>
- <role-hint>url-failures-cache</role-hint>
- <implementation>org.codehaus.plexus.cache.ehcache.EhcacheCache</implementation>
- <description>URL Failure Cache</description>
- <configuration>
- <disk-expiry-thread-interval-seconds>600</disk-expiry-thread-interval-seconds>
- <disk-persistent>false</disk-persistent>
- <disk-store-path>${java.io.tmpdir}/archiva/urlcache</disk-store-path>
- <eternal>false</eternal>
- <max-elements-in-memory>1000</max-elements-in-memory>
- <memory-eviction-policy>LRU</memory-eviction-policy>
- <name>cache</name>
- <overflow-to-disk>false</overflow-to-disk>
- <!-- 45 minutes = 2700 seconds -->
- <time-to-idle-seconds>2700</time-to-idle-seconds>
- <!-- 30 minutes = 1800 seconds -->
- <time-to-live-seconds>1800</time-to-live-seconds>
- </configuration>
- </component>
- </components>
-</component-set>
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ChecksumPolicyTest.xml b/archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ChecksumPolicyTest.xml
deleted file mode 100644
index a42cdec07..000000000
--- a/archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ChecksumPolicyTest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<component-set>
- <components>
- <component>
- <role>org.codehaus.plexus.cache.Cache</role>
- <role-hint>url-failures-cache</role-hint>
- <implementation>org.codehaus.plexus.cache.ehcache.EhcacheCache</implementation>
- <description>URL Failure Cache</description>
- <configuration>
- <disk-expiry-thread-interval-seconds>600</disk-expiry-thread-interval-seconds>
- <disk-persistent>false</disk-persistent>
- <disk-store-path>${java.io.tmpdir}/archiva/urlcache</disk-store-path>
- <eternal>false</eternal>
- <max-elements-in-memory>1000</max-elements-in-memory>
- <memory-eviction-policy>LRU</memory-eviction-policy>
- <name>cache</name>
- <overflow-to-disk>false</overflow-to-disk>
- <!-- 45 minutes = 2700 seconds -->
- <time-to-idle-seconds>2700</time-to-idle-seconds>
- <!-- 30 minutes = 1800 seconds -->
- <time-to-live-seconds>1800</time-to-live-seconds>
- </configuration>
- </component>
- </components>
-</component-set>
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ReleasePolicyTest.xml b/archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ReleasePolicyTest.xml
deleted file mode 100644
index a42cdec07..000000000
--- a/archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ReleasePolicyTest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<component-set>
- <components>
- <component>
- <role>org.codehaus.plexus.cache.Cache</role>
- <role-hint>url-failures-cache</role-hint>
- <implementation>org.codehaus.plexus.cache.ehcache.EhcacheCache</implementation>
- <description>URL Failure Cache</description>
- <configuration>
- <disk-expiry-thread-interval-seconds>600</disk-expiry-thread-interval-seconds>
- <disk-persistent>false</disk-persistent>
- <disk-store-path>${java.io.tmpdir}/archiva/urlcache</disk-store-path>
- <eternal>false</eternal>
- <max-elements-in-memory>1000</max-elements-in-memory>
- <memory-eviction-policy>LRU</memory-eviction-policy>
- <name>cache</name>
- <overflow-to-disk>false</overflow-to-disk>
- <!-- 45 minutes = 2700 seconds -->
- <time-to-idle-seconds>2700</time-to-idle-seconds>
- <!-- 30 minutes = 1800 seconds -->
- <time-to-live-seconds>1800</time-to-live-seconds>
- </configuration>
- </component>
- </components>
-</component-set>
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/SnapshotsPolicyTest.xml b/archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/SnapshotsPolicyTest.xml
deleted file mode 100644
index a42cdec07..000000000
--- a/archiva-modules/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/SnapshotsPolicyTest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<component-set>
- <components>
- <component>
- <role>org.codehaus.plexus.cache.Cache</role>
- <role-hint>url-failures-cache</role-hint>
- <implementation>org.codehaus.plexus.cache.ehcache.EhcacheCache</implementation>
- <description>URL Failure Cache</description>
- <configuration>
- <disk-expiry-thread-interval-seconds>600</disk-expiry-thread-interval-seconds>
- <disk-persistent>false</disk-persistent>
- <disk-store-path>${java.io.tmpdir}/archiva/urlcache</disk-store-path>
- <eternal>false</eternal>
- <max-elements-in-memory>1000</max-elements-in-memory>
- <memory-eviction-policy>LRU</memory-eviction-policy>
- <name>cache</name>
- <overflow-to-disk>false</overflow-to-disk>
- <!-- 45 minutes = 2700 seconds -->
- <time-to-idle-seconds>2700</time-to-idle-seconds>
- <!-- 30 minutes = 1800 seconds -->
- <time-to-live-seconds>1800</time-to-live-seconds>
- </configuration>
- </component>
- </components>
-</component-set>
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-policies/src/test/resources/spring-context.xml
new file mode 100755
index 000000000..18a7fa5f8
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-policies/src/test/resources/spring-context.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0"?>
+
+<!--
+ ~ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+ default-lazy-init="true">
+
+ <context:property-placeholder system-properties-mode="OVERRIDE"/>
+
+ <bean name="url-failures-cache" class="org.codehaus.plexus.cache.ehcache.EhcacheCache">
+ <property name="diskExpiryThreadIntervalSeconds" value="600"/>
+ <property name="diskPersistent" value="false"/>
+ <property name="eternal" value="false"/>
+ <property name="maxElementsInMemory" value="1000"/>
+ <property name="memoryEvictionPolicy" value="LRU"/>
+ <property name="name" value="cache"/>
+ <property name="overflowToDisk" value="false"/>
+ <property name="timeToIdleSeconds" value="2700"/>
+ <property name="timeToLiveSeconds" value="1800"/>
+ </bean>
+
+</beans> \ No newline at end of file
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MockConfiguration.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MockConfiguration.java
index ce44784b0..f4f16151d 100644
--- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MockConfiguration.java
+++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MockConfiguration.java
@@ -101,4 +101,9 @@ public class MockConfiguration
{
return false;
}
+
+ public void reload()
+ {
+ // no op
+ }
}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/MockConfiguration.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/MockConfiguration.java
index 7052fb3ab..63edd8b4c 100755
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/MockConfiguration.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/MockConfiguration.java
@@ -101,4 +101,9 @@ public class MockConfiguration
{
return false;
}
+
+ public void reload()
+ {
+ // no op
+ }
}