aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-configuration
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2006-08-26 05:47:59 +0000
committerBrett Porter <brett@apache.org>2006-08-26 05:47:59 +0000
commit209ef5ca84ee8de9e5ee61952e0d380749c3074b (patch)
tree1f64a28aa8f3bfab1ab17cb8715fe6eb0485391e /archiva-configuration
parent72cbf8748f2f0cb7dad3b45cd5668461aa4a76b2 (diff)
downloadarchiva-209ef5ca84ee8de9e5ee61952e0d380749c3074b.tar.gz
archiva-209ef5ca84ee8de9e5ee61952e0d380749c3074b.zip
rename archiva artifacts
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@437088 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-configuration')
-rw-r--r--archiva-configuration/pom.xml64
-rw-r--r--archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeException.java31
-rw-r--r--archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java36
-rw-r--r--archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java55
-rw-r--r--archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java36
-rw-r--r--archiva-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java143
-rw-r--r--archiva-configuration/src/main/java/org/apache/maven/repository/configuration/InvalidConfigurationException.java46
-rw-r--r--archiva-configuration/src/main/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoader.java146
-rw-r--r--archiva-configuration/src/main/mdo/configuration.mdo477
-rw-r--r--archiva-configuration/src/main/resources/org/apache/maven/repository/configuration/SyncedRepositoryConfiguration-conversion.properties18
-rw-r--r--archiva-configuration/src/test/conf/corrupt.xml16
-rw-r--r--archiva-configuration/src/test/conf/maven-proxy-complete.conf144
-rw-r--r--archiva-configuration/src/test/conf/repository-manager.xml53
-rw-r--r--archiva-configuration/src/test/java/org/apache/maven/repository/configuration/ConfigurationStoreTest.java154
-rw-r--r--archiva-configuration/src/test/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoaderTest.java103
-rw-r--r--archiva-configuration/src/test/resources/org/apache/maven/repository/configuration/ConfigurationStoreTest.xml52
16 files changed, 1574 insertions, 0 deletions
diff --git a/archiva-configuration/pom.xml b/archiva-configuration/pom.xml
new file mode 100644
index 000000000..25c939a50
--- /dev/null
+++ b/archiva-configuration/pom.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0"?>
+<project>
+ <parent>
+ <artifactId>archiva</artifactId>
+ <groupId>org.apache.maven.archiva</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>archiva-configuration</artifactId>
+ <name>Archiva Configuration</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>1.2_Java1.3</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.modello</groupId>
+ <artifactId>modello-maven-plugin</artifactId>
+ <version>1.0-alpha-10</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>xpp3-writer</goal>
+ <goal>java</goal>
+ <goal>xpp3-reader</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <version>1.0.0</version>
+ <model>src/main/mdo/configuration.mdo</model>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ <configuration>
+ <instrumentation>
+ <!-- exclude generated -->
+ <excludes>
+ <exclude>org/apache/maven/repository/configuration/io/**</exclude>
+ <exclude>org/apache/maven/repository/configuration/*RepositoryConfiguration.*</exclude>
+ <exclude>org/apache/maven/repository/configuration/Configuration.*</exclude>
+ <exclude>org/apache/maven/repository/configuration/Proxy.*</exclude>
+ </excludes>
+ </instrumentation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeException.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeException.java
new file mode 100644
index 000000000..547bff7a4
--- /dev/null
+++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeException.java
@@ -0,0 +1,31 @@
+package org.apache.maven.repository.configuration;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * An error changing the configuration
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class ConfigurationChangeException
+ extends Exception
+{
+ public ConfigurationChangeException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+}
diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java
new file mode 100644
index 000000000..ca01a493f
--- /dev/null
+++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java
@@ -0,0 +1,36 @@
+package org.apache.maven.repository.configuration;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Component capable of noticing configuration changes and adjusting accordingly.
+ * This is not a Plexus role.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public interface ConfigurationChangeListener
+{
+ /**
+ * Notify the object that there has been a configuration change.
+ *
+ * @param configuration the new configuration
+ * @throws InvalidConfigurationException if there is a problem with the new configuration
+ * @throws ConfigurationChangeException if there is a problem changing the configuration, but the configuration is valid
+ */
+ void notifyOfConfigurationChange( Configuration configuration )
+ throws InvalidConfigurationException, ConfigurationChangeException;
+}
diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java
new file mode 100644
index 000000000..968ce25d6
--- /dev/null
+++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java
@@ -0,0 +1,55 @@
+package org.apache.maven.repository.configuration;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * A component for loading the configuration into the model.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @todo this is something that could possibly be generalised into Modello.
+ */
+public interface ConfigurationStore
+{
+ /**
+ * The Plexus role for the component.
+ */
+ String ROLE = ConfigurationStore.class.getName();
+
+ /**
+ * Get the configuration from the store. A cached version may be used.
+ *
+ * @return the configuration
+ * @throws ConfigurationStoreException if there is a problem loading the configuration
+ */
+ Configuration getConfigurationFromStore()
+ throws ConfigurationStoreException;
+
+ /**
+ * Save the configuration to the store.
+ *
+ * @param configuration the configuration to store
+ */
+ void storeConfiguration( Configuration configuration )
+ throws ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException;
+
+ /**
+ * Add a configuration change listener.
+ *
+ * @param listener the listener
+ */
+ void addChangeListener( ConfigurationChangeListener listener );
+}
diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java
new file mode 100644
index 000000000..04dd8990b
--- /dev/null
+++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java
@@ -0,0 +1,36 @@
+package org.apache.maven.repository.configuration;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * Exception occurring using the configuration store.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class ConfigurationStoreException
+ extends Exception
+{
+ public ConfigurationStoreException( String message )
+ {
+ super( message );
+ }
+
+ public ConfigurationStoreException( String message, Throwable e )
+ {
+ super( message, e );
+ }
+}
diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java
new file mode 100644
index 000000000..ad771cba7
--- /dev/null
+++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java
@@ -0,0 +1,143 @@
+package org.apache.maven.repository.configuration;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Reader;
+import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Writer;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Load and store the configuration. No synchronization is used, but it is unnecessary as the old configuration object
+ * can continue to be used.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @todo would be great for plexus to do this for us - so the configuration would be a component itself rather than this store
+ * @todo would be good to monitor the store file for changes
+ * @todo support other implementations than XML file
+ * @plexus.component
+ */
+public class DefaultConfigurationStore
+ extends AbstractLogEnabled
+ implements ConfigurationStore
+{
+ /**
+ * @plexus.configuration default-value="${configuration.store.file}"
+ */
+ private File file;
+
+ /**
+ * The cached configuration.
+ */
+ private Configuration configuration;
+
+ /**
+ * List of listeners to configuration changes.
+ */
+ private List/*<ConfigurationChangeListener>*/ listeners = new LinkedList();
+
+ public Configuration getConfigurationFromStore()
+ throws ConfigurationStoreException
+ {
+ if ( configuration == null )
+ {
+ ConfigurationXpp3Reader reader = new ConfigurationXpp3Reader();
+
+ if ( file == null )
+ {
+ file = new File( System.getProperty( "user.home" ), "/.m2/repository-manager.xml" );
+ }
+
+ FileReader fileReader;
+ try
+ {
+ fileReader = new FileReader( file );
+ }
+ catch ( FileNotFoundException e )
+ {
+ getLogger().warn( "Configuration file: " + file + " not found. Using defaults." );
+ configuration = new Configuration();
+ return configuration;
+ }
+
+ getLogger().info( "Reading configuration from " + file );
+ try
+ {
+ configuration = reader.read( fileReader, false );
+ }
+ catch ( IOException e )
+ {
+ throw new ConfigurationStoreException( e.getMessage(), e );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new ConfigurationStoreException( e.getMessage(), e );
+ }
+ finally
+ {
+ IOUtil.close( fileReader );
+ }
+ }
+ return configuration;
+ }
+
+ public void storeConfiguration( Configuration configuration )
+ throws ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException
+ {
+ for ( Iterator i = listeners.iterator(); i.hasNext(); )
+ {
+ ConfigurationChangeListener listener = (ConfigurationChangeListener) i.next();
+
+ listener.notifyOfConfigurationChange( configuration );
+ }
+
+ ConfigurationXpp3Writer writer = new ConfigurationXpp3Writer();
+
+ getLogger().info( "Writing configuration to " + file );
+ FileWriter fileWriter = null;
+ try
+ {
+ file.getParentFile().mkdirs();
+
+ fileWriter = new FileWriter( file );
+ writer.write( fileWriter, configuration );
+ }
+ catch ( IOException e )
+ {
+ throw new ConfigurationStoreException( e.getMessage(), e );
+ }
+ finally
+ {
+ IOUtil.close( fileWriter );
+ }
+ }
+
+ public void addChangeListener( ConfigurationChangeListener listener )
+ {
+ listeners.add( listener );
+ }
+}
diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/InvalidConfigurationException.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/InvalidConfigurationException.java
new file mode 100644
index 000000000..05006df96
--- /dev/null
+++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/InvalidConfigurationException.java
@@ -0,0 +1,46 @@
+package org.apache.maven.repository.configuration;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * An error in the configuration.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class InvalidConfigurationException
+ extends Exception
+{
+ private final String name;
+
+ public InvalidConfigurationException( String name, String message )
+ {
+ super( message );
+ this.name = name;
+ }
+
+ public InvalidConfigurationException( String name, String message, Throwable cause )
+ {
+ super( message, cause );
+
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+}
diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoader.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoader.java
new file mode 100644
index 000000000..814cec7b1
--- /dev/null
+++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoader.java
@@ -0,0 +1,146 @@
+package org.apache.maven.repository.configuration;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+/**
+ * @author Ben Walding
+ * @author Brett Porter
+ */
+public class MavenProxyPropertyLoader
+{
+ private static final String REPO_LOCAL_STORE = "repo.local.store";
+
+ private static final String PROXY_LIST = "proxy.list";
+
+ private static final String REPO_LIST = "repo.list";
+
+ public void load( Properties props, Configuration configuration )
+ throws InvalidConfigurationException
+ {
+ // set up the managed repository
+ String localCachePath = getMandatoryProperty( props, REPO_LOCAL_STORE );
+
+ RepositoryConfiguration config = new RepositoryConfiguration();
+ config.setDirectory( localCachePath );
+ config.setName( "Imported Maven-Proxy Cache" );
+ config.setId( "maven-proxy" );
+ configuration.addRepository( config );
+
+ //just get the first HTTP proxy and break
+ String propertyList = props.getProperty( PROXY_LIST );
+ if ( propertyList != null )
+ {
+ StringTokenizer tok = new StringTokenizer( propertyList, "," );
+ while ( tok.hasMoreTokens() )
+ {
+ String key = tok.nextToken();
+ if ( StringUtils.isNotEmpty( key ) )
+ {
+ Proxy proxy = new Proxy();
+ proxy.setHost( getMandatoryProperty( props, "proxy." + key + ".host" ) );
+ proxy.setPort( Integer.parseInt( getMandatoryProperty( props, "proxy." + key + ".port" ) ) );
+
+ // the username and password isn't required
+ proxy.setUsername( props.getProperty( "proxy." + key + ".username" ) );
+ proxy.setPassword( props.getProperty( "proxy." + key + ".password" ) );
+
+ configuration.setProxy( proxy );
+
+ //accept only one proxy configuration
+ break;
+ }
+ }
+ }
+
+ //get the remote repository list
+ String repoList = getMandatoryProperty( props, REPO_LIST );
+
+ StringTokenizer tok = new StringTokenizer( repoList, "," );
+ while ( tok.hasMoreTokens() )
+ {
+ String key = tok.nextToken();
+
+ Properties repoProps = getSubset( props, "repo." + key + "." );
+ String url = getMandatoryProperty( props, "repo." + key + ".url" );
+ String proxyKey = repoProps.getProperty( "proxy" );
+
+ boolean cacheFailures =
+ Boolean.valueOf( repoProps.getProperty( "cache.failures", "false" ) ).booleanValue();
+ boolean hardFail = Boolean.valueOf( repoProps.getProperty( "hardfail", "true" ) ).booleanValue();
+ int cachePeriod = Integer.parseInt( repoProps.getProperty( "cache.period", "60" ) );
+
+ ProxiedRepositoryConfiguration repository = new ProxiedRepositoryConfiguration();
+ repository.setId( key );
+ repository.setLayout( "legacy" );
+ repository.setManagedRepository( config.getId() );
+ repository.setName( "Imported Maven-Proxy Remote Proxy" );
+ repository.setSnapshotsInterval( cachePeriod );
+ repository.setUrl( url );
+ repository.setUseNetworkProxy( StringUtils.isNotEmpty( proxyKey ) );
+ repository.setCacheFailures( cacheFailures );
+ repository.setHardFail( hardFail );
+
+ configuration.addProxiedRepository( repository );
+ }
+ }
+
+ private Properties getSubset( Properties props, String prefix )
+ {
+ Enumeration keys = props.keys();
+ Properties result = new Properties();
+ while ( keys.hasMoreElements() )
+ {
+ String key = (String) keys.nextElement();
+ String value = props.getProperty( key );
+ if ( key.startsWith( prefix ) )
+ {
+ String newKey = key.substring( prefix.length() );
+ result.setProperty( newKey, value );
+ }
+ }
+ return result;
+ }
+
+ public void load( InputStream is, Configuration configuration )
+ throws IOException, InvalidConfigurationException
+ {
+ Properties props = new Properties();
+ props.load( is );
+ load( props, configuration );
+ }
+
+ private String getMandatoryProperty( Properties props, String key )
+ throws InvalidConfigurationException
+ {
+ String value = props.getProperty( key );
+
+ if ( value == null )
+ {
+ throw new InvalidConfigurationException( key, "Missing required field: " + key );
+ }
+
+ return value;
+ }
+} \ No newline at end of file
diff --git a/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-configuration/src/main/mdo/configuration.mdo
new file mode 100644
index 000000000..a2f772800
--- /dev/null
+++ b/archiva-configuration/src/main/mdo/configuration.mdo
@@ -0,0 +1,477 @@
+<model>
+ <id>configuration</id>
+ <name>Configuration</name>
+ <description>
+ Configuration for the Maven Repository Manager.
+ </description>
+ <defaults>
+ <default>
+ <key>package</key>
+ <value>org.apache.maven.repository.configuration</value>
+ </default>
+ </defaults>
+ <!-- TODO! break out subtypes such as <discovery> and create a list of blacklist -->
+ <classes>
+ <class rootElement="true" xml.tagName="configuration">
+ <name>Configuration</name>
+ <version>1.0.0</version>
+ <fields>
+ <field>
+ <name>repositories</name>
+ <version>1.0.0</version>
+ <association>
+ <type>RepositoryConfiguration</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ <field>
+ <name>proxiedRepositories</name>
+ <version>1.0.0</version>
+ <association>
+ <type>ProxiedRepositoryConfiguration</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ <field>
+ <name>syncedRepositories</name>
+ <version>1.0.0</version>
+ <association>
+ <type>SyncedRepositoryConfiguration</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ <field>
+ <name>localRepository</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <description>
+ The location of the local repository.
+ </description>
+ </field>
+ <field>
+ <name>indexPath</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <description>
+ The location of the Lucene index to use for the repository. The default is the .index subdirectory of
+ the repository.
+ </description>
+ </field>
+ <field>
+ <name>minimalIndexPath</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <description>
+ The location of the reduced Lucene index to use for the repository. The default is the .small-index
+ subdirectory of the repository.
+ </description>
+ </field>
+ <field>
+ <name>indexerCronExpression</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <description>When to run the indexing mechanism. Default is every hour on the hour.</description>
+ <defaultValue>0 0 * * * ?</defaultValue>
+ </field>
+ <field>
+ <name>converterCronExpression</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <description>When to run the converter mechanism. Default is every 4 hours, on the half hour.</description>
+ <defaultValue>0 30 0/4 * * ?</defaultValue>
+ </field>
+ <field>
+ <name>globalBlackListPatterns</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <description>Blacklisted patterns in the discovery process</description>
+ </field>
+ <field>
+ <name>proxy</name>
+ <version>1.0.0</version>
+ <association>
+ <type>Proxy</type>
+ </association>
+ <description>The network proxy to use for outgoing requests.</description>
+ </field>
+ </fields>
+ <codeSegments>
+ <codeSegment>
+ <version>1.0.0</version>
+ <code><![CDATA[
+ public Configuration()
+ {
+ localRepository = new java.io.File( System.getProperty( "user.home" ), ".m2/repository" ).getAbsolutePath();
+ }
+
+ public boolean isValid()
+ {
+ boolean valid = true;
+
+ if ( indexPath == null )
+ {
+ valid = false;
+ }
+ else if ( getRepositories().isEmpty() )
+ {
+ valid = false;
+ }
+ return valid;
+ }
+
+ public RepositoryConfiguration getRepositoryById( String id )
+ {
+ for ( java.util.Iterator i = getRepositories().iterator(); i.hasNext(); )
+ {
+ RepositoryConfiguration repository = (RepositoryConfiguration) i.next();
+ if ( repository.getId().equals( id ) )
+ {
+ return repository;
+ }
+ }
+ return null;
+ }
+
+ public SyncedRepositoryConfiguration getSyncedRepositoryById( String id )
+ {
+ for ( java.util.Iterator i = getSyncedRepositories().iterator(); i.hasNext(); )
+ {
+ SyncedRepositoryConfiguration repository = (SyncedRepositoryConfiguration) i.next();
+ if ( repository.getId().equals( id ) )
+ {
+ return repository;
+ }
+ }
+ return null;
+ }
+
+ public ProxiedRepositoryConfiguration getProxiedRepositoryById( String id )
+ {
+ for ( java.util.Iterator i = getProxiedRepositories().iterator(); i.hasNext(); )
+ {
+ ProxiedRepositoryConfiguration repository = (ProxiedRepositoryConfiguration) i.next();
+ if ( repository.getId().equals( id ) )
+ {
+ return repository;
+ }
+ }
+ return null;
+ }
+
+ private java.util.Map repositoriesMap;
+
+ public java.util.Map getRepositoriesMap()
+ {
+ if ( repositoriesMap == null )
+ {
+ repositoriesMap = new java.util.HashMap();
+ for ( java.util.Iterator i = getRepositories().iterator(); i.hasNext(); )
+ {
+ RepositoryConfiguration repository = (RepositoryConfiguration) i.next();
+ repositoriesMap.put( repository.getId(), repository );
+ }
+ }
+ return repositoriesMap;
+ }
+
+ private java.util.Map proxiedRepositoriesMap;
+
+ public java.util.Map getProxiedRepositoriesMap()
+ {
+ if ( proxiedRepositoriesMap == null )
+ {
+ proxiedRepositoriesMap = new java.util.HashMap();
+ for ( java.util.Iterator i = getProxiedRepositories().iterator(); i.hasNext(); )
+ {
+ ProxiedRepositoryConfiguration repository = (ProxiedRepositoryConfiguration) i.next();
+ proxiedRepositoriesMap.put( repository.getId(), repository );
+ }
+ }
+ return proxiedRepositoriesMap;
+ }
+
+ private java.util.Map syncedRepositoriesMap;
+
+ public java.util.Map getSyncedRepositoriesMap()
+ {
+ if ( syncedRepositoriesMap == null )
+ {
+ syncedRepositoriesMap = new java.util.HashMap();
+ for ( java.util.Iterator i = getSyncedRepositories().iterator(); i.hasNext(); )
+ {
+ SyncedRepositoryConfiguration repository = (SyncedRepositoryConfiguration) i.next();
+ syncedRepositoriesMap.put( repository.getId(), repository );
+ }
+ }
+ return syncedRepositoriesMap;
+ }
+ ]]></code>
+ </codeSegment>
+ </codeSegments>
+ </class>
+ <class>
+ <name>AbstractRepositoryConfiguration</name>
+ <abstract>true</abstract>
+ <version>1.0.0</version>
+ <fields>
+ <field>
+ <name>id</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The repository identifier.
+ </description>
+ </field>
+ <field>
+ <name>name</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The descriptive name of the repository.
+ </description>
+ </field>
+ <field>
+ <name>layout</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The layout of the repository. Valid values are "default" and "legacy".
+ </description>
+ <!-- TODO: should be able to detect this from the repository (perhaps by metadata at the root) -->
+ <defaultValue>default</defaultValue>
+ </field>
+ </fields>
+ <codeSegments>
+ <codeSegment>
+ <version>1.0.0</version>
+ <code><![CDATA[
+ public String toString()
+ {
+ return name + " (" + id + ")";
+ }
+ ]]></code>
+ </codeSegment>
+ </codeSegments>
+ </class>
+ <class>
+ <superClass>AbstractRepositoryConfiguration</superClass>
+ <name>RepositoryConfiguration</name>
+ <version>1.0.0</version>
+ <fields>
+ <field>
+ <name>directory</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The location of the repository to monitor.
+ </description>
+ </field>
+ <field>
+ <name>includeSnapshots</name>
+ <version>1.0.0</version>
+ <type>boolean</type>
+ <description>Whether to include snapshot versions in the discovery process</description>
+ <defaultValue>false</defaultValue>
+ </field>
+ <field>
+ <name>indexed</name>
+ <version>1.0.0</version>
+ <type>boolean</type>
+ <description>Whether to index the artifacts in this repository.</description>
+ <defaultValue>true</defaultValue>
+ </field>
+ <field>
+ <name>blackListPatterns</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <description>Blacklisted patterns in the discovery process</description>
+ </field>
+ </fields>
+ </class>
+ <class>
+ <superClass>AbstractRepositoryConfiguration</superClass>
+ <name>ProxiedRepositoryConfiguration</name>
+ <version>1.0.0</version>
+ <fields>
+ <field>
+ <name>url</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The URL of the remote repository to proxy.
+ </description>
+ </field>
+ <!-- TODO: would be much easier to have an association here, as long as it could be specified as a reference -->
+ <field>
+ <name>managedRepository</name>
+ <version>1.0.0</version>
+ <required>true</required>
+ <type>String</type>
+ <description>
+ The ID of the managed repository to use as the local storage for proxied artifacts.
+ </description>
+ </field>
+ <field>
+ <name>snapshotsPolicy</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <defaultValue>disabled</defaultValue>
+ <description>
+ The policy for snapshots: one of disabled, daily, hourly, interval, never
+ (allow snapshots, but never update once retrieved).
+ </description>
+ </field>
+ <field>
+ <name>snapshotsInterval</name>
+ <version>1.0.0</version>
+ <type>int</type>
+ <description>
+ The interval in minutes before updating snapshots if the policy is set to 'interval'.
+ </description>
+ </field>
+ <field>
+ <name>releasesPolicy</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <defaultValue>daily</defaultValue>
+ <description>
+ The policy for releases: one of disabled, daily, hourly, interval, never
+ (allow releases, but never update once retrieved).
+ </description>
+ </field>
+ <field>
+ <name>releasesInterval</name>
+ <version>1.0.0</version>
+ <type>int</type>
+ <description>
+ The interval in minutes before updating releases if the policy is set to 'interval'.
+ </description>
+ </field>
+ <field>
+ <name>useNetworkProxy</name>
+ <version>1.0.0</version>
+ <type>boolean</type>
+ <defaultValue>false</defaultValue>
+ <description>
+ Whether to use the network proxy, if one is configured for the protocol of this repository.
+ </description>
+ </field>
+ <field>
+ <name>cacheFailures</name>
+ <version>1.0.0</version>
+ <type>boolean</type>
+ <defaultValue>false</defaultValue>
+ <description>
+ Whether to cache failures to avoid re-attempting them over the network. The cache will last for the duration
+ of the intervals specified above depending on whether it a release or snapshot.
+ </description>
+ </field>
+ <field>
+ <name>hardFail</name>
+ <version>1.0.0</version>
+ <type>boolean</type>
+ <defaultValue>false</defaultValue>
+ <description>
+ Whether to cause the entire request to fail if attempts to retrieve from this proxy fail.
+ </description>
+ </field>
+ </fields>
+ </class>
+ <class>
+ <superClass>AbstractRepositoryConfiguration</superClass>
+ <name>SyncedRepositoryConfiguration</name>
+ <abstract>true</abstract>
+ <version>1.0.0</version>
+ <fields>
+ <!-- TODO: would be much easier to have an association here, as long as it could be specified as a reference -->
+ <field>
+ <name>managedRepository</name>
+ <version>1.0.0</version>
+ <required>true</required>
+ <type>String</type>
+ <description>
+ The ID of the managed repository to use as the local storage for proxied artifacts.
+ </description>
+ </field>
+ <field>
+ <name>cronExpression</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <description>When to run the sync mechanism. Default is every hour on the hour.</description>
+ <defaultValue>0 0 * * * ?</defaultValue>
+ </field>
+ <field>
+ <name>method</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <description>The type of synchronization to use.</description>
+ <defaultValue>rsync</defaultValue>
+ </field>
+ <field>
+ <name>properties</name>
+ <version>1.0.0</version>
+ <type>Properties</type>
+ <description>Configuration for the repository synchronization.</description>
+ <association xml.mapStyle="inline">
+ <type>String</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ </fields>
+ </class>
+ <class>
+ <name>Proxy</name>
+ <version>1.0.0</version>
+ <fields>
+ <field>
+ <name>protocol</name>
+ <version>1.0.0</version>
+ <description><![CDATA[The proxy protocol.]]></description>
+ <type>String</type>
+ <defaultValue>http</defaultValue>
+ </field>
+ <field>
+ <name>username</name>
+ <version>1.0.0</version>
+ <description><![CDATA[The proxy user.]]></description>
+ <type>String</type>
+ </field>
+ <field>
+ <name>password</name>
+ <version>1.0.0</version>
+ <description><![CDATA[The proxy password.]]></description>
+ <type>String</type>
+ </field>
+ <field>
+ <name>port</name>
+ <version>1.0.0</version>
+ <description><![CDATA[The proxy port.]]></description>
+ <type>int</type>
+ <defaultValue>8080</defaultValue>
+ </field>
+ <field>
+ <name>host</name>
+ <version>1.0.0</version>
+ <description><![CDATA[The proxy host.]]></description>
+ <type>String</type>
+ <required>true</required>
+ </field>
+ <field>
+ <name>nonProxyHosts</name>
+ <version>1.0.0</version>
+ <description><![CDATA[
+ The list of non-proxied hosts (delimited by |).
+ ]]></description>
+ <type>String</type>
+ </field>
+ </fields>
+ </class>
+ </classes>
+</model>
+
+
diff --git a/archiva-configuration/src/main/resources/org/apache/maven/repository/configuration/SyncedRepositoryConfiguration-conversion.properties b/archiva-configuration/src/main/resources/org/apache/maven/repository/configuration/SyncedRepositoryConfiguration-conversion.properties
new file mode 100644
index 000000000..0bf28d59c
--- /dev/null
+++ b/archiva-configuration/src/main/resources/org/apache/maven/repository/configuration/SyncedRepositoryConfiguration-conversion.properties
@@ -0,0 +1,18 @@
+#
+# Copyright 2005-2006 The Apache Software Foundation.
+#
+# Licensed 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.
+#
+
+Key_properties=java.lang.String
+Element_properties=java.lang.String
diff --git a/archiva-configuration/src/test/conf/corrupt.xml b/archiva-configuration/src/test/conf/corrupt.xml
new file mode 100644
index 000000000..2476f91ff
--- /dev/null
+++ b/archiva-configuration/src/test/conf/corrupt.xml
@@ -0,0 +1,16 @@
+<!--
+ ~ Copyright 2005-2006 The Apache Software Foundation.
+ ~
+ ~ Licensed 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.
+ -->
+
diff --git a/archiva-configuration/src/test/conf/maven-proxy-complete.conf b/archiva-configuration/src/test/conf/maven-proxy-complete.conf
new file mode 100644
index 000000000..7908a9ad9
--- /dev/null
+++ b/archiva-configuration/src/test/conf/maven-proxy-complete.conf
@@ -0,0 +1,144 @@
+################ GLOBAL SETTINGS
+# This is where maven-proxy stores files it has downloaded
+repo.local.store=target
+
+#The port to listen on - not used if loaded as a webapp
+port=9999
+
+#This is the base area that all files are loaded from. While it is possible to leave this blank, this behaviour
+#is deprecated and will be disabled in version 2.0. There are too many namespace conflicts caused by not using
+#a prefix.
+#The repository will be shown at http://localhost:9999/repository/
+#for the .war loaded into a webapp server, the default prefix is "repository" (edit the web.xml to change)
+# As maven doesn't like a trailing slash, this address shouldn't have one either.
+prefix=repository
+
+#This is the simple date format used to display the last modified date while browsing the repository.
+lastModifiedDateFormat=yyyy/MM/dd HH:mm:ss
+
+################ SNAPSHOT HANDLING
+#If you want the proxy to look for newer snapshots, set to true
+snapshot.update=true
+
+################ M2 METADATA HANDLING
+#If you want the proxy to prevent looking for newer metadata, set to false (default is true)
+#metadata.update=false
+
+################ M2 POM HANDLING
+#If you want the proxy to look for newer POMs, set to true (default is false)
+pom.update=true
+
+################ PROMOTION HANDLING
+# ***** NOT CURRENTLY IMPLEMENTED *****
+#Promotion describes the process by which new artifacts are loaded to global maven-proxy repository. It
+# is designed to be used by "higher security installations" that do not want to acquire artifacts from
+# remote repositories without approval.
+#
+#If promotion handling is enabled, then the proxy will not download remote artifacts without permission
+# (local repositories with copy=false are considered to be local)
+#
+#Permission to download is granted via the Promotion menu which will be enabled
+# when promotion handling is enabled.
+#
+#If promotion is false, artifacts are sourced from any repository as per normal.
+#
+#Promotion and snapshots: If promotion is enabled, snapshots are not downloadable. The concept of using
+# a snapshot in a production build (which is primarily what promotion is for) is counterintuitive.
+##
+promotion=false
+
+################ WEB INTERFACE
+# This defines the absolute URL the server should use to identify itself.
+# This can often be determined automatically, but we recommend you specify
+# it explicitly to prevent problems during startup.
+# The prefix will be added to this for the actual repository
+# i.e. proxy available at http://localhost:9999/, repository at http://localhost:9999/repository
+serverName=http://localhost:9999
+
+#If true, the repository can be browsed
+browsable=true
+
+#If true, the repository can be searched
+searchable=true
+
+#Not currently implemented. Will allow webdav access to the repository at some point.
+webdav=true
+
+#Stylesheet - if configured, will override the default stylesheet shipped with maven-proxy - absolute URLs only
+#eg. /maven-proxy/style.css, http://www.example.com/style.css
+stylesheet=/maven-proxy/style.css
+
+#bgColor / bgColorHighlight are replaced in the built in stylesheet to produce a simple color scheme.
+#If a stylesheet is set, these are not used.
+bgColor=#14B
+bgColorHighlight=#94B
+
+#rowColor / rowColorHighlight are replaced in the built in stylesheet to produce a simple color scheme.
+#If a stylesheet is set, these are not used.
+rowColor=#CCF
+rowColorHighlight=#DDF
+
+
+################ PROXIES
+#This is just a hack, it should auto discover them
+proxy.list=one,two,three
+
+#Unauthenticated proxy
+proxy.one.host=proxy1.example.com
+proxy.one.port=3128
+
+#Authenticated proxy
+proxy.two.host=proxy2.example.org
+proxy.two.port=80
+proxy.two.username=username2
+proxy.two.password=password2
+
+#Authenticated proxy
+proxy.three.host=proxy3.example.net
+proxy.three.port=3129
+proxy.three.username=username3
+proxy.three.password=password3
+
+
+################# REPOSITORIES
+#This is not just a hack, it specifies the order repositories should be checked
+#Note that the proxy adds a "/" which is why the urls aren't suffixed with a "/"
+repo.list=local-repo,www-ibiblio-org,dist-codehaus-org,private-example-com
+
+#local-store
+# The local store represents a location that local jars you host can be located.
+# This could also be achieved by having a local http repository, but this is less cumbersome
+repo.local-repo.url=file://target
+repo.local-repo.description=Super Secret Custom Repository
+#If copy is true, jars are copied from the store to the proxy-repo. Only configurable for file:/// repos
+repo.local-repo.copy=false
+#If hardfail is true, any unexpected errors from the repository will cause
+#the client download to fail (typically with a 500 error)
+repo.local-repo.hardfail=true
+#Don't cache a file repository
+repo.local-repo.cache.period=0
+
+
+#www.ibiblio.org
+repo.www-ibiblio-org.url=http://www.ibiblio.org/maven2
+repo.www-ibiblio-org.description=www.ibiblio.org
+repo.www-ibiblio-org.proxy=one
+repo.www-ibiblio-org.hardfail=true
+#Cache this repository for 1 hour
+repo.www-ibiblio-org.cache.period=3600
+repo.www-ibiblio-org.cache.failures=true
+
+#dist.codehaus.org
+repo.dist-codehaus-org.url=http://dist.codehaus.org
+repo.dist-codehaus-org.proxy=two
+repo.dist-codehaus-org.hardfail=false
+repo.dist-codehaus-org.cache.period=3600
+repo.dist-codehaus-org.cache.failures=true
+
+#private.example.com
+repo.private-example-com.url=http://private.example.com/internal
+repo.private-example-com.description=Commercial In Confidence Repository
+repo.private-example-com.username=username1
+repo.private-example-com.password=password1
+repo.private-example-com.proxy=three
+repo.private-example-com.cache.period=3600
diff --git a/archiva-configuration/src/test/conf/repository-manager.xml b/archiva-configuration/src/test/conf/repository-manager.xml
new file mode 100644
index 000000000..a3f1f2745
--- /dev/null
+++ b/archiva-configuration/src/test/conf/repository-manager.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ Copyright 2005-2006 The Apache Software Foundation.
+ ~
+ ~ Licensed 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.
+ -->
+
+<configuration>
+ <repositories>
+ <repository>
+ <directory>managed-repository</directory>
+ <id>local</id>
+ <name>local</name>
+ </repository>
+ </repositories>
+ <proxiedRepositories>
+ <proxiedRepository>
+ <url>http://www.ibiblio.org/maven2/</url>
+ <managedRepository>local</managedRepository>
+ <snapshotsInterval></snapshotsInterval>
+ <releasesInterval></releasesInterval>
+ <useNetworkProxy>true</useNetworkProxy>
+ <id>ibiblio</id>
+ <name>Ibiblio</name>
+ </proxiedRepository>
+ </proxiedRepositories>
+ <syncedRepositories>
+ <syncedRepository>
+ <id>apache</id>
+ <name>ASF</name>
+ <cronExpression>0 0 * * * ?</cronExpression>
+ <managedRepository>local</managedRepository>
+ <method>rsync</method>
+ <properties>
+ <rsyncHost>host</rsyncHost>
+ <rsyncMethod>ssh</rsyncMethod>
+ </properties>
+ </syncedRepository>
+ </syncedRepositories>
+ <localRepository>local-repository</localRepository>
+ <indexPath>.index</indexPath>
+</configuration>
diff --git a/archiva-configuration/src/test/java/org/apache/maven/repository/configuration/ConfigurationStoreTest.java b/archiva-configuration/src/test/java/org/apache/maven/repository/configuration/ConfigurationStoreTest.java
new file mode 100644
index 000000000..34d350a68
--- /dev/null
+++ b/archiva-configuration/src/test/java/org/apache/maven/repository/configuration/ConfigurationStoreTest.java
@@ -0,0 +1,154 @@
+package org.apache.maven.repository.configuration;
+
+import org.codehaus.plexus.PlexusTestCase;
+import org.easymock.MockControl;
+
+import java.io.File;
+import java.util.Properties;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * Test the configuration store.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @noinspection JavaDoc
+ */
+public class ConfigurationStoreTest
+ extends PlexusTestCase
+{
+ public void testInvalidFile()
+ throws Exception
+ {
+ ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "invalid-file" );
+
+ Configuration configuration = configurationStore.getConfigurationFromStore();
+
+ // check default configuration
+ assertNotNull( "check configuration returned", configuration );
+ assertEquals( "check configuration has default elements", "0 0 * * * ?",
+ configuration.getIndexerCronExpression() );
+ assertNull( "check configuration has default elements", configuration.getIndexPath() );
+ assertTrue( "check configuration has default elements", configuration.getRepositories().isEmpty() );
+ }
+
+ public void testCorruptFile()
+ throws Exception
+ {
+ ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "corrupt-file" );
+
+ try
+ {
+ configurationStore.getConfigurationFromStore();
+ fail( "Configuration should not have succeeded" );
+ }
+ catch ( ConfigurationStoreException e )
+ {
+ // expected
+ assertTrue( true );
+ }
+ }
+
+ public void testGetConfiguration()
+ throws Exception
+ {
+ ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "default" );
+
+ Configuration configuration = configurationStore.getConfigurationFromStore();
+
+ assertEquals( "check indexPath", ".index", configuration.getIndexPath() );
+ assertEquals( "check localRepository", "local-repository", configuration.getLocalRepository() );
+
+ assertEquals( "check managed repositories", 1, configuration.getRepositories().size() );
+ RepositoryConfiguration repository =
+ (RepositoryConfiguration) configuration.getRepositories().iterator().next();
+
+ assertEquals( "check managed repositories", "managed-repository", repository.getDirectory() );
+ assertEquals( "check managed repositories", "local", repository.getName() );
+ assertEquals( "check managed repositories", "local", repository.getId() );
+ assertEquals( "check managed repositories", "default", repository.getLayout() );
+ assertTrue( "check managed repositories", repository.isIndexed() );
+
+ assertEquals( "check proxied repositories", 1, configuration.getProxiedRepositories().size() );
+ ProxiedRepositoryConfiguration proxiedRepository =
+ (ProxiedRepositoryConfiguration) configuration.getProxiedRepositories().iterator().next();
+
+ assertEquals( "check proxied repositories", "local", proxiedRepository.getManagedRepository() );
+ assertEquals( "check proxied repositories", "http://www.ibiblio.org/maven2/", proxiedRepository.getUrl() );
+ assertEquals( "check proxied repositories", "ibiblio", proxiedRepository.getId() );
+ assertEquals( "check proxied repositories", "Ibiblio", proxiedRepository.getName() );
+ assertEquals( "check proxied repositories", 0, proxiedRepository.getSnapshotsInterval() );
+ assertEquals( "check proxied repositories", 0, proxiedRepository.getReleasesInterval() );
+ assertTrue( "check proxied repositories", proxiedRepository.isUseNetworkProxy() );
+
+ assertEquals( "check synced repositories", 1, configuration.getSyncedRepositories().size() );
+ SyncedRepositoryConfiguration syncedRepository =
+ (SyncedRepositoryConfiguration) configuration.getSyncedRepositories().iterator().next();
+
+ assertEquals( "check synced repositories", "local", syncedRepository.getManagedRepository() );
+ assertEquals( "check synced repositories", "apache", syncedRepository.getId() );
+ assertEquals( "check synced repositories", "ASF", syncedRepository.getName() );
+ assertEquals( "check synced repositories", "0 0 * * * ?", syncedRepository.getCronExpression() );
+ assertEquals( "check synced repositories", "rsync", syncedRepository.getMethod() );
+ Properties properties = new Properties();
+ properties.setProperty( "rsyncHost", "host" );
+ properties.setProperty( "rsyncMethod", "ssh" );
+ assertEquals( "check synced repositories", properties, syncedRepository.getProperties() );
+ }
+
+ public void testStoreConfiguration()
+ throws Exception
+ {
+ ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "save-file" );
+
+ Configuration configuration = new Configuration();
+ configuration.setIndexPath( "index-path" );
+
+ File file = getTestFile( "target/test/test-file.xml" );
+ file.delete();
+ assertFalse( file.exists() );
+
+ configurationStore.storeConfiguration( configuration );
+
+ assertTrue( "Check file exists", file.exists() );
+
+ // read it back
+ configuration = configurationStore.getConfigurationFromStore();
+ assertEquals( "check value", "index-path", configuration.getIndexPath() );
+ }
+
+ /**
+ * @noinspection JUnitTestMethodWithNoAssertions
+ */
+ public void testChangeListeners()
+ throws Exception
+ {
+ ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "save-file" );
+
+ MockControl control = MockControl.createControl( ConfigurationChangeListener.class );
+ ConfigurationChangeListener mock = (ConfigurationChangeListener) control.getMock();
+ configurationStore.addChangeListener( mock );
+
+ Configuration configuration = new Configuration();
+ mock.notifyOfConfigurationChange( configuration );
+ control.replay();
+
+ configurationStore.storeConfiguration( configuration );
+
+ control.verify();
+ }
+}
diff --git a/archiva-configuration/src/test/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoaderTest.java b/archiva-configuration/src/test/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoaderTest.java
new file mode 100644
index 000000000..de8fb8d01
--- /dev/null
+++ b/archiva-configuration/src/test/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoaderTest.java
@@ -0,0 +1,103 @@
+package org.apache.maven.repository.configuration;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class MavenProxyPropertyLoaderTest
+ extends PlexusTestCase
+{
+ private static final int DEFAULT_CACHE_PERIOD = 3600;
+
+ private MavenProxyPropertyLoader loader;
+
+ public void testLoadValidMavenProxyConfiguration()
+ throws IOException, InvalidConfigurationException
+ {
+ File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" );
+
+ Configuration configuration = new Configuration();
+ Proxy proxy = new Proxy();
+ proxy.setHost( "original-host" );
+ configuration.setProxy( proxy ); // overwritten
+ configuration.setIndexPath( "index-path" ); // existing value
+
+ loader.load( new FileInputStream( confFile ), configuration );
+
+ List list = configuration.getRepositories();
+ assertEquals( "check single managed repository", 1, list.size() );
+ RepositoryConfiguration managedRepository = (RepositoryConfiguration) list.iterator().next();
+ assertEquals( "cache path changed", "target", managedRepository.getDirectory() );
+
+ assertEquals( "Count repositories", 4, configuration.getProxiedRepositories().size() );
+
+ list = configuration.getProxiedRepositories();
+ ProxiedRepositoryConfiguration repo = (ProxiedRepositoryConfiguration) list.get( 0 );
+ assertEquals( "Repository name not as expected", "local-repo", repo.getId() );
+ assertEquals( "Repository url does not match its name", "file://target", repo.getUrl() );
+ assertEquals( "Repository cache period check failed", 0, repo.getSnapshotsInterval() );
+ assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
+
+ repo = (ProxiedRepositoryConfiguration) list.get( 1 );
+ assertEquals( "Repository name not as expected", "www-ibiblio-org", repo.getId() );
+ assertEquals( "Repository url does not match its name", "http://www.ibiblio.org/maven2", repo.getUrl() );
+ assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() );
+ assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
+
+ repo = (ProxiedRepositoryConfiguration) list.get( 2 );
+ assertEquals( "Repository name not as expected", "dist-codehaus-org", repo.getId() );
+ assertEquals( "Repository url does not match its name", "http://dist.codehaus.org", repo.getUrl() );
+ assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() );
+ assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
+
+ repo = (ProxiedRepositoryConfiguration) list.get( 3 );
+ assertEquals( "Repository name not as expected", "private-example-com", repo.getId() );
+ assertEquals( "Repository url does not match its name", "http://private.example.com/internal", repo.getUrl() );
+ assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() );
+ assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
+ }
+
+ public void testInvalidConfiguration()
+ {
+ Configuration configuration = new Configuration();
+ try
+ {
+ loader.load( new Properties(), configuration );
+ fail( "Incomplete config should have failed" );
+ }
+ catch ( InvalidConfigurationException e )
+ {
+ assertTrue( true );
+ }
+ }
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ loader = new MavenProxyPropertyLoader();
+ }
+}
diff --git a/archiva-configuration/src/test/resources/org/apache/maven/repository/configuration/ConfigurationStoreTest.xml b/archiva-configuration/src/test/resources/org/apache/maven/repository/configuration/ConfigurationStoreTest.xml
new file mode 100644
index 000000000..39a15a996
--- /dev/null
+++ b/archiva-configuration/src/test/resources/org/apache/maven/repository/configuration/ConfigurationStoreTest.xml
@@ -0,0 +1,52 @@
+<!--
+ ~ Copyright 2005-2006 The Apache Software Foundation.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<component-set>
+ <components>
+ <component>
+ <role>org.apache.maven.repository.configuration.ConfigurationStore</role>
+ <role-hint>default</role-hint>
+ <implementation>org.apache.maven.repository.configuration.DefaultConfigurationStore</implementation>
+ <configuration>
+ <file>${basedir}/src/test/conf/repository-manager.xml</file>
+ </configuration>
+ </component>
+ <component>
+ <role>org.apache.maven.repository.configuration.ConfigurationStore</role>
+ <role-hint>corrupt-file</role-hint>
+ <implementation>org.apache.maven.repository.configuration.DefaultConfigurationStore</implementation>
+ <configuration>
+ <file>${basedir}/src/test/conf/corrupt.xml</file>
+ </configuration>
+ </component>
+ <component>
+ <role>org.apache.maven.repository.configuration.ConfigurationStore</role>
+ <role-hint>invalid-file</role-hint>
+ <implementation>org.apache.maven.repository.configuration.DefaultConfigurationStore</implementation>
+ <configuration>
+ <file>${basedir}/src/test/conf/nada.txt</file>
+ </configuration>
+ </component>
+ <component>
+ <role>org.apache.maven.repository.configuration.ConfigurationStore</role>
+ <role-hint>save-file</role-hint>
+ <implementation>org.apache.maven.repository.configuration.DefaultConfigurationStore</implementation>
+ <configuration>
+ <file>${basedir}/target/test/test-file.xml</file>
+ </configuration>
+ </component>
+ </components>
+</component-set>