Overhaul of configuration schema

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@521414 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-03-22 19:33:28 +00:00
parent 3e1c7a3ad2
commit ad842d82a2
7 changed files with 890 additions and 579 deletions

View File

@ -60,13 +60,10 @@ public class DefaultArchivaConfiguration
configuration = new ConfigurationRegistryReader().read( registry.getSubset( KEY ) ); configuration = new ConfigurationRegistryReader().read( registry.getSubset( KEY ) );
// TODO: for commons-configuration 1.3 only // TODO: for commons-configuration 1.3 only
configuration.setIndexPath( removeExpressions( configuration.getIndexPath() ) );
configuration.setMinimalIndexPath( removeExpressions( configuration.getMinimalIndexPath() ) );
configuration.setLocalRepository( removeExpressions( configuration.getLocalRepository() ) );
for ( Iterator i = configuration.getRepositories().iterator(); i.hasNext(); ) for ( Iterator i = configuration.getRepositories().iterator(); i.hasNext(); )
{ {
RepositoryConfiguration c = (RepositoryConfiguration) i.next(); RepositoryConfiguration c = (RepositoryConfiguration) i.next();
c.setDirectory( removeExpressions( c.getDirectory() ) ); c.setUrl( removeExpressions( c.getUrl() ) );
} }
} }
return configuration; return configuration;

View File

@ -21,8 +21,10 @@ package org.apache.maven.archiva.configuration;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@ -39,19 +41,18 @@ public class MavenProxyPropertyLoader
private static final String REPO_LIST = "repo.list"; private static final String REPO_LIST = "repo.list";
public void load( Properties props, Configuration configuration ) public void load( Properties props, Configuration configuration ) throws InvalidConfigurationException
throws InvalidConfigurationException
{ {
// set up the managed repository // set up the managed repository
String localCachePath = getMandatoryProperty( props, REPO_LOCAL_STORE ); String localCachePath = getMandatoryProperty( props, REPO_LOCAL_STORE );
RepositoryConfiguration config = new RepositoryConfiguration(); RepositoryConfiguration config = new RepositoryConfiguration();
config.setDirectory( localCachePath ); config.setUrl( toURL( localCachePath ) );
config.setName( "Imported Maven-Proxy Cache" ); config.setName( "Imported Maven-Proxy Cache" );
config.setId( "maven-proxy" ); config.setId( "maven-proxy" );
configuration.addRepository( config ); configuration.addRepository( config );
//just get the first HTTP proxy and break // Add the network proxies.
String propertyList = props.getProperty( PROXY_LIST ); String propertyList = props.getProperty( PROXY_LIST );
if ( propertyList != null ) if ( propertyList != null )
{ {
@ -61,7 +62,7 @@ public class MavenProxyPropertyLoader
String key = tok.nextToken(); String key = tok.nextToken();
if ( StringUtils.isNotEmpty( key ) ) if ( StringUtils.isNotEmpty( key ) )
{ {
Proxy proxy = new Proxy(); ProxyConfiguration proxy = new ProxyConfiguration();
proxy.setHost( getMandatoryProperty( props, "proxy." + key + ".host" ) ); proxy.setHost( getMandatoryProperty( props, "proxy." + key + ".host" ) );
proxy.setPort( Integer.parseInt( getMandatoryProperty( props, "proxy." + key + ".port" ) ) ); proxy.setPort( Integer.parseInt( getMandatoryProperty( props, "proxy." + key + ".port" ) ) );
@ -69,15 +70,12 @@ public class MavenProxyPropertyLoader
proxy.setUsername( props.getProperty( "proxy." + key + ".username" ) ); proxy.setUsername( props.getProperty( "proxy." + key + ".username" ) );
proxy.setPassword( props.getProperty( "proxy." + key + ".password" ) ); proxy.setPassword( props.getProperty( "proxy." + key + ".password" ) );
configuration.setProxy( proxy ); configuration.addNetworkProxy( proxy );
//accept only one proxy configuration
break;
} }
} }
} }
//get the remote repository list // Add the remote repository list
String repoList = getMandatoryProperty( props, REPO_LIST ); String repoList = getMandatoryProperty( props, REPO_LIST );
StringTokenizer tok = new StringTokenizer( repoList, "," ); StringTokenizer tok = new StringTokenizer( repoList, "," );
@ -89,23 +87,41 @@ public class MavenProxyPropertyLoader
String url = getMandatoryProperty( props, "repo." + key + ".url" ); String url = getMandatoryProperty( props, "repo." + key + ".url" );
String proxyKey = repoProps.getProperty( "proxy" ); 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" ) ); int cachePeriod = Integer.parseInt( repoProps.getProperty( "cache.period", "60" ) );
ProxiedRepositoryConfiguration repository = new ProxiedRepositoryConfiguration(); RepositoryConfiguration repository = new RepositoryConfiguration();
repository.setId( key ); repository.setId( key );
repository.setLayout( "legacy" );
repository.setManagedRepository( config.getId() );
repository.setName( "Imported Maven-Proxy Remote Proxy" ); repository.setName( "Imported Maven-Proxy Remote Proxy" );
repository.setSnapshotsInterval( cachePeriod );
repository.setUrl( url ); repository.setUrl( url );
repository.setUseNetworkProxy( StringUtils.isNotEmpty( proxyKey ) ); repository.setLayout( "legacy" );
repository.setCacheFailures( cacheFailures ); repository.setIndexed( false );
repository.setHardFail( hardFail ); repository.setReleases( true );
repository.setSnapshots( false );
configuration.addProxiedRepository( repository ); configuration.addRepository( repository );
RepositoryProxyConnectorConfiguration proxyConnector = new RepositoryProxyConnectorConfiguration();
proxyConnector.setSourceRepoId( "maven-proxy" );
proxyConnector.setTargetRepoId( key );
proxyConnector.setProxyId( proxyKey );
proxyConnector.setFailurePolicy( RepositoryProxyConnectorConfiguration.NOT_FOUND );
proxyConnector.setSnapshotsPolicy( String.valueOf( cachePeriod ) );
proxyConnector.setReleasesPolicy( RepositoryProxyConnectorConfiguration.NEVER );
configuration.addProxyConnector( proxyConnector );
}
}
private String toURL( String path )
{
File file = new File( path );
try
{
return file.toURL().toExternalForm();
}
catch ( MalformedURLException e )
{
return "file://" + StringUtils.replaceChars( file.getAbsolutePath(), '\\', '/' );
} }
} }
@ -126,16 +142,14 @@ public class MavenProxyPropertyLoader
return result; return result;
} }
public void load( InputStream is, Configuration configuration ) public void load( InputStream is, Configuration configuration ) throws IOException, InvalidConfigurationException
throws IOException, InvalidConfigurationException
{ {
Properties props = new Properties(); Properties props = new Properties();
props.load( is ); props.load( is );
load( props, configuration ); load( props, configuration );
} }
private String getMandatoryProperty( Properties props, String key ) private String getMandatoryProperty( Properties props, String key ) throws InvalidConfigurationException
throws InvalidConfigurationException
{ {
String value = props.getProperty( key ); String value = props.getProperty( key );

View File

@ -32,238 +32,79 @@
<classes> <classes>
<class rootElement="true" xml.tagName="configuration"> <class rootElement="true" xml.tagName="configuration">
<name>Configuration</name> <name>Configuration</name>
<version>1.0.0</version> <version>1.0.0+</version>
<fields> <fields>
<field> <field>
<name>repositories</name> <name>repositories</name>
<version>1.0.0</version> <version>1.0.0+</version>
<association> <association>
<type>RepositoryConfiguration</type> <type>RepositoryConfiguration</type>
<multiplicity>*</multiplicity> <multiplicity>*</multiplicity>
</association> </association>
<description>The list of repositories that this archiva instance uses.</description>
</field> </field>
<field> <field>
<name>proxiedRepositories</name> <name>proxyConnectors</name>
<version>1.0.0</version> <version>1.0.0+</version>
<association> <association>
<type>ProxiedRepositoryConfiguration</type> <type>RepositoryProxyConnectorConfiguration</type>
<multiplicity>*</multiplicity> <multiplicity>*</multiplicity>
</association> </association>
<description>The list of proxy connectors for this archiva instance.</description>
</field> </field>
<!-- To be introduced later.
<field> <field>
<name>syncedRepositories</name> <name>syncConnectors</name>
<version>1.0.0</version> <version>1.0.0+</version>
<association> <association>
<type>SyncedRepositoryConfiguration</type> <type>RepositorySyncConnectorConfiguration</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>dataRefreshCronExpression</name>
<version>1.0.0</version>
<type>String</type>
<description>When to run the data refresh task. Default is every 30 mins (translated as every 0 and 30 minute reading of every hour)</description>
<defaultValue>0 0,30 * * * ?</defaultValue>
</field>
<!--
<field>
<name>globalBlackListPatterns</name>
<version>1.0.0</version>
<description>Blacklisted patterns in the discovery process</description>
<association>
<type>String</type>
<multiplicity>*</multiplicity> <multiplicity>*</multiplicity>
</association> </association>
<description>The list of sync connectors for this archiva instance.</description>
</field> </field>
--> -->
<field> <field>
<name>proxy</name> <name>networkProxies</name>
<version>1.0.0</version> <version>1.0.0+</version>
<association> <association>
<type>Proxy</type> <type>ProxyConfiguration</type>
<multiplicity>*</multiplicity>
</association> </association>
<description>The network proxy to use for outgoing requests.</description> <description>
The list of network proxies to use for outgoing requests.
</description>
</field>
<field>
<name>fileProcessors</name>
<version>1.0.0+</version>
<association>
<type>FileProcessor</type>
<multiplicity>*</multiplicity>
</association>
<description>
The file processors setup.
</description>
</field> </field>
</fields> </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;
}
/**
* Perform any Upgrades and Adjustments needed to bring configuration up to the
* current configuration format.
*/
public void sanitize()
{
for ( java.util.Iterator i = getRepositories().iterator(); i.hasNext(); )
{
RepositoryConfiguration repo = (RepositoryConfiguration) i.next();
// Ensure that the repo.urlName is set.
if ( org.codehaus.plexus.util.StringUtils.isEmpty( repo.getUrlName() ) )
{
repo.setUrlName( repo.getId() );
}
}
}
public RepositoryConfiguration getRepositoryByUrlName( String urlName )
{
for ( java.util.Iterator i = getRepositories().iterator(); i.hasNext(); )
{
RepositoryConfiguration repository = (RepositoryConfiguration) i.next();
if ( urlName != null ? urlName.equals( repository.getUrlName() ) : repository.getUrlName() == null )
{
return repository;
}
}
return null;
}
public RepositoryConfiguration getRepositoryById( String id )
{
for ( java.util.Iterator i = getRepositories().iterator(); i.hasNext(); )
{
RepositoryConfiguration repository = (RepositoryConfiguration) i.next();
if ( id != null ? id.equals( repository.getId() ) : repository.getId() == null )
{
return repository;
}
}
return null;
}
public SyncedRepositoryConfiguration getSyncedRepositoryById( String id )
{
for ( java.util.Iterator i = getSyncedRepositories().iterator(); i.hasNext(); )
{
SyncedRepositoryConfiguration repository = (SyncedRepositoryConfiguration) i.next();
if ( id != null ? id.equals( repository.getId() ) : repository.getId() == null )
{
return repository;
}
}
return null;
}
public ProxiedRepositoryConfiguration getProxiedRepositoryById( String id )
{
for ( java.util.Iterator i = getProxiedRepositories().iterator(); i.hasNext(); )
{
ProxiedRepositoryConfiguration repository = (ProxiedRepositoryConfiguration) i.next();
if ( id != null ? id.equals( repository.getId() ) : repository.getId() == null )
{
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>
<!--
____ _ _
| _ \ ___ _ __ ___ ___(_) |_ ___ _ __ _ _
| |_) / _ \ '_ \ / _ \/ __| | __/ _ \| '__| | | |
| _ < __/ |_) | (_) \__ \ | || (_) | | | |_| |
|_| \_\___| .__/ \___/|___/_|\__\___/|_| \__, |
|_| |___/
-->
<class> <class>
<name>AbstractRepositoryConfiguration</name> <name>RepositoryConfiguration</name>
<abstract>true</abstract> <version>1.0.0+</version>
<version>1.0.0</version>
<fields> <fields>
<field> <field>
<name>id</name> <name>id</name>
<version>1.0.0</version> <version>1.0.0+</version>
<type>String</type> <type>String</type>
<required>true</required> <required>true</required>
<description> <description>
@ -272,16 +113,25 @@
</field> </field>
<field> <field>
<name>name</name> <name>name</name>
<version>1.0.0</version> <version>1.0.0+</version>
<type>String</type> <type>String</type>
<required>true</required> <required>true</required>
<description> <description>
The descriptive name of the repository. The descriptive name of the repository.
</description> </description>
</field> </field>
<field>
<name>url</name>
<version>1.0.0+</version>
<type>String</type>
<required>true</required>
<description>
The URL for this repository.
</description>
</field>
<field> <field>
<name>layout</name> <name>layout</name>
<version>1.0.0</version> <version>1.0.0+</version>
<type>String</type> <type>String</type>
<required>true</required> <required>true</required>
<description> <description>
@ -290,191 +140,213 @@
<!-- TODO: should be able to detect this from the repository (perhaps by metadata at the root) --> <!-- TODO: should be able to detect this from the repository (perhaps by metadata at the root) -->
<defaultValue>default</defaultValue> <defaultValue>default</defaultValue>
</field> </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> <field>
<name>urlName</name> <name>releases</name>
<version>1.0.0</version> <version>1.0.0+</version>
<type>String</type>
<required>true</required>
<description>
The URL name for this repository.
Used to create the WebDAV URL for the repository such like - http://hostname.com/repository/${urlName}/
</description>
</field>
<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> <type>boolean</type>
<description>Whether to include snapshot versions in the discovery process</description> <description>True if this repository contains release versioned artifacts.</description>
<defaultValue>true</defaultValue>
</field>
<field>
<name>snapshots</name>
<version>1.0.0+</version>
<type>boolean</type>
<description>True if this repository contains snapshot versioned artifacts.</description>
<defaultValue>false</defaultValue> <defaultValue>false</defaultValue>
</field> </field>
<field> <field>
<name>indexed</name> <name>indexed</name>
<version>1.0.0</version> <version>1.0.0+</version>
<type>boolean</type> <type>boolean</type>
<description>Whether to index the artifacts in this repository.</description> <description>True if this repository should be indexed.</description>
<defaultValue>true</defaultValue> <defaultValue>true</defaultValue>
</field> </field>
<field>
<name>refreshCronExpression</name>
<version>1.0.0+</version>
<type>String</type>
<description>
When to run the refresh task.
Default is every 30 minutes (translated as every 0 and 30 minute reading of every hour)
</description>
<defaultValue>0 0,30 * * * ?</defaultValue>
</field>
</fields>
</class>
<!--
____ _
/ ___|___ _ __ _ __ ___ ___| |_ ___ _ __ ___
| | / _ \| '_ \| '_ \ / _ \/ __| __/ _ \| '__/ __|
| |__| (_) | | | | | | | __/ (__| || (_) | | \__ \
\____\___/|_| |_|_| |_|\___|\___|\__\___/|_| |___/
-->
<class>
<name>AbstractRepositoryConnectorConfiguration</name>
<abstract>true</abstract>
<version>1.0.0+</version>
<fields>
<field>
<name>sourceRepoId</name>
<version>1.0.0+</version>
<type>String</type>
<required>true</required>
<description>
The Repository Source for this connector.
</description>
</field>
<field>
<name>targetRepoId</name>
<version>1.0.0+</version>
<type>String</type>
<required>true</required>
<description>
The Repository Target for this connector.
</description>
</field>
<field>
<name>proxyId</name>
<version>1.0.0+</version>
<type>String</type>
<description>
The network proxy ID to use for this connector.
</description>
</field>
<field> <field>
<name>blackListPatterns</name> <name>blackListPatterns</name>
<version>1.0.0</version> <version>1.0.0+</version>
<description>Blacklisted patterns in the discovery process</description>
<association> <association>
<type>String</type> <type>String</type>
<multiplicity>*</multiplicity> <multiplicity>*</multiplicity>
</association> </association>
<description>
The list of blacklisted patterns for this connector.
</description>
</field>
<field>
<name>whiteListPatterns</name>
<version>1.0.0+</version>
<association>
<type>String</type>
<multiplicity>*</multiplicity>
</association>
<description>
The list of whitelisted patterns for this connector.
</description>
</field> </field>
</fields> </fields>
</class> </class>
<class> <class>
<superClass>AbstractRepositoryConfiguration</superClass> <superClass>AbstractRepositoryConnectorConfiguration</superClass>
<name>ProxiedRepositoryConfiguration</name> <name>RepositoryProxyConnectorConfiguration</name>
<version>1.0.0</version> <version>1.0.0+</version>
<fields> <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> <field>
<name>snapshotsPolicy</name> <name>snapshotsPolicy</name>
<version>1.0.0</version> <version>1.0.0+</version>
<type>String</type> <type>String</type>
<defaultValue>disabled</defaultValue> <defaultValue>disabled</defaultValue>
<description> <description>
The policy for snapshots: one of disabled, daily, hourly, interval, never The policy for snapshots:
(allow snapshots, but never update once retrieved). Can be one of the following keywords:
</description> "disabled" - means retrieval isn't even attempted.
</field> "daily" - means snapshot is fetched, but only updated on
<field> a daily basis. (equivalent to "1440" minutes)
<name>snapshotsInterval</name> "hourly" - means snapshot is fetched, but only updated on
<version>1.0.0</version> an hourly basis. (equivalent to "60" minutes)
<type>int</type> "never" - means snapshot is fetched once, but never updated.
<description> (equivalent to "-1" minutes)
The interval in minutes before updating snapshots if the policy is set to 'interval'. Or it can be a number of minutes before updating of the snapshot.
</description> </description>
</field> </field>
<field> <field>
<name>releasesPolicy</name> <name>releasesPolicy</name>
<version>1.0.0</version> <version>1.0.0+</version>
<type>String</type> <type>String</type>
<defaultValue>daily</defaultValue> <defaultValue>never</defaultValue>
<description> <description>
The policy for releases: one of disabled, daily, hourly, interval, never The policy for releases:
(allow releases, but never update once retrieved). Can be one of the following keywords:
"disabled" - means retrieval isn't even attempted.
"daily" - means release is fetched, but only updated on
a daily basis. (equivalent to "1440" minutes)
"hourly" - means release is fetched, but only updated on
an hourly basis. (equivalent to "60" minutes)
"never" - means release is fetched once, but never updated.
(equivalent to "-1" minutes)
Or it can be a number of minutes before updating of the release.
</description> </description>
</field> </field>
<field> <field>
<name>releasesInterval</name> <name>failurePolicy</name>
<version>1.0.0</version> <version>1.0.0+</version>
<type>int</type> <type>String</type>
<defaultValue>not-found</defaultValue>
<description> <description>
The interval in minutes before updating releases if the policy is set to 'interval'. The policy for dealing with proxy failures.
</description> Can be one of the following keywords:
</field> "not-found" - means if the retrieval has a failure, an HTTP 404
<field> (not found) is returned to the client of this
<name>useNetworkProxy</name> archiva instance.
<version>1.0.0</version> This policy setting will allow other proxies
<type>boolean</type> to be checked for content.
<defaultValue>false</defaultValue> "failure" - means if the retrieval has a failure, an HTTP 500
<description> (server error) is returned to the client of this
Whether to use the network proxy, if one is configured for the protocol of this repository. archiva instance.
</description> This policy setting will return immediately to the
</field> client of the archiva instance and not allow
<field> furthor attempts on other proxies for this content.
<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> </description>
</field> </field>
</fields> </fields>
<codeSegments>
<codeSegment>
<version>1.0.0+</version>
<code><![CDATA[
public static final String NEVER = "never";
public static final String DISABLED = "disabled";
public static final String DAILY = "daily";
public static final String HOURLY = "hourly";
public static final String NOT_FOUND = "not-found";
public static final String FAILURE = "failure";
]]></code>
</codeSegment>
</codeSegments>
</class> </class>
<class> <class>
<superClass>AbstractRepositoryConfiguration</superClass> <superClass>AbstractRepositoryConnectorConfiguration</superClass>
<name>SyncedRepositoryConfiguration</name> <name>RepositorySynchConnectorConfiguration</name>
<abstract>true</abstract> <abstract>true</abstract>
<version>1.0.0</version> <version>1.0.0+</version>
<fields> <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> <field>
<name>cronExpression</name> <name>cronExpression</name>
<version>1.0.0</version> <version>1.0.0+</version>
<type>String</type> <type>String</type>
<description>When to run the sync mechanism. Default is every hour on the hour.</description> <description>When to run the sync mechanism. Default is every hour on the hour.</description>
<defaultValue>0 0 * * * ?</defaultValue> <defaultValue>0 0 * * * ?</defaultValue>
</field> </field>
<field> <field>
<name>method</name> <name>method</name>
<version>1.0.0</version> <version>1.0.0+</version>
<type>String</type> <type>String</type>
<description>The type of synchronization to use.</description> <description>The type of synchronization to use.</description>
<defaultValue>rsync</defaultValue> <defaultValue>rsync</defaultValue>
</field> </field>
<field> <field>
<name>properties</name> <name>properties</name>
<version>1.0.0</version> <version>1.0.0+</version>
<type>Properties</type> <type>Properties</type>
<description>Configuration for the repository synchronization.</description> <description>Configuration for the repository synchronization.</description>
<association xml.mapStyle="inline"> <association xml.mapStyle="inline">
@ -484,53 +356,123 @@
</field> </field>
</fields> </fields>
</class> </class>
<!--
____ _
| _ \ _ __ _____ _(_) ___ ___
| |_) | '__/ _ \ \/ / |/ _ \/ __|
| __/| | | (_) > <| | __/\__ \
|_| |_| \___/_/\_\_|\___||___/
-->
<class> <class>
<name>Proxy</name> <name>ProxyConfiguration</name>
<version>1.0.0</version> <version>1.0.0+</version>
<fields> <fields>
<field> <field>
<name>protocol</name> <name>id</name>
<version>1.0.0</version> <version>1.0.0+</version>
<description><![CDATA[The proxy protocol.]]></description>
<type>String</type> <type>String</type>
<description>
The ID for this proxy.
</description>
</field>
<field>
<name>protocol</name>
<version>1.0.0+</version>
<description>
The network protocol to use with this proxy.
</description>
<type>String</type>
<required>true</required>
<defaultValue>http</defaultValue> <defaultValue>http</defaultValue>
</field> </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> <field>
<name>host</name> <name>host</name>
<version>1.0.0</version> <version>1.0.0+</version>
<description><![CDATA[The proxy host.]]></description> <description>
The proxy host.
</description>
<type>String</type> <type>String</type>
<required>true</required> <required>true</required>
</field> </field>
<field> <field>
<name>nonProxyHosts</name> <name>port</name>
<version>1.0.0</version> <version>1.0.0+</version>
<description><![CDATA[ <description>
The list of non-proxied hosts (delimited by |). The proxy port.
]]></description> </description>
<type>int</type>
<defaultValue>8080</defaultValue>
</field>
<field>
<name>username</name>
<version>1.0.0+</version>
<description>
The proxy user.
</description>
<type>String</type>
</field>
<field>
<name>password</name>
<version>1.0.0+</version>
<description>
The proxy password.
</description>
<type>String</type> <type>String</type>
</field> </field>
</fields> </fields>
</class> </class>
<!--
_____ _ _ ____
| ___(_) | ___| _ \ _ __ ___ ___ ___ ___ ___ ___ _ __
| |_ | | |/ _ \ |_) | '__/ _ \ / __/ _ \/ __/ __|/ _ \| '__|
| _| | | | __/ __/| | | (_) | (_| __/\__ \__ \ (_) | |
|_| |_|_|\___|_| |_| \___/ \___\___||___/___/\___/|_|
-->
<class>
<name>FileProcessor</name>
<version>1.0.0+</version>
<fields>
<field>
<name>id</name>
<version>1.0.0+</version>
<required>true</required>
<type>String</type>
<description>
The ID for this file processor
</description>
</field>
<field>
<name>patterns</name>
<version>1.0.0+</version>
<required>true</required>
<association>
<type>String</type>
<multiplicity>*</multiplicity>
</association>
<description>
The list of patterns for this processor.
</description>
</field>
<field>
<name>consumers</name>
<version>1.0.0+</version>
<required>true</required>
<association>
<type>String</type>
<multiplicity>*</multiplicity>
</association>
<description>
The list of consumer IDs for this file processor.
</description>
</field>
</fields>
</class>
</classes> </classes>
</model> </model>

View File

@ -0,0 +1,219 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<repositories>
<repository>
<id>internal</id>
<name>Archiva Managed Internal Repository</name>
<url>file://${appserver.home}/repositories/internal</url>
<layout>default</layout>
<releases>true</releases>
<snapshots>false</snapshots>
<indexed>true</indexed>
<refreshCronExpression>0 0 * * ?</refreshCronExpression>
</repository>
<repository>
<id>snapshots</id>
<name>Archiva Managed Snapshot Repository</name>
<url>file://${appserver.home}/repositories/internal</url>
<layout>default</layout>
<releases>false</releases>
<snapshots>true</snapshots>
<indexed>true</indexed>
<refreshCronExpression>0 0,30 * * ?</refreshCronExpression>
</repository>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo1.maven.org/maven2</url>
<layout>default</layout>
<releases>true</releases>
<snapshots>false</snapshots>
<indexed>false</indexed>
</repository>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven 2</name>
<url>https://maven2-repository.dev.java.net/nonav/repository</url>
<layout>default</layout>
<releases>true</releases>
<snapshots>false</snapshots>
<indexed>false</indexed>
</repository>
</repositories>
<proxyConnectors>
<proxyConnector>
<sourceRepoId>internal</sourceRepoId>
<targetRepoId>central</targetRepoId>
<proxyId />
<snapshotsPolicy>disabled</snapshotsPolicy>
<releasePolicy>never</releasePolicy>
<failurePolicy>not-found</failurePolicy>
</proxyConnector>
<proxyConnector>
<sourceRepoId>internal</sourceRepoId>
<targetRepoId>maven2-repository.dev.java.net</targetRepoId>
<proxyId />
<snapshotsPolicy>disabled</snapshotsPolicy>
<releasePolicy>never</releasePolicy>
<failurePolicy>not-found</failurePolicy>
<whiteListPatterns>
<whileListPattern>javax/**</whileListPattern>
</whiteListPatterns>
</proxyConnector>
</proxyConnectors>
<networkProxies>
</networkProxies>
<fileProcessors>
<fileProcessor>
<id>artifacts</id>
<patterns>
<pattern>**/*.pom</pattern>
<pattern>**/*.jar</pattern>
<pattern>**/*.ear</pattern>
<pattern>**/*.war</pattern>
<pattern>**/*.car</pattern>
<pattern>**/*.sar</pattern>
<pattern>**/*.mar</pattern>
<pattern>**/*.rar</pattern>
<pattern>**/*.dtd</pattern>
<pattern>**/*.tld</pattern>
<pattern>**/*.tar.gz</pattern>
<pattern>**/*.tar.bz2</pattern>
<pattern>**/*.zip</pattern>
</patterns>
<consumers>
<consumer>artifact-to-db</consumer>
<consumer>artifact-to-lucene</consumer>
<consumer>artifact-create-missing-checksums</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>projects</id>
<patterns>
<pattern>**/*.pom</pattern>
</patterns>
<consumers>
<consumer>project-to-db</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>repository-metadata</id>
<patterns>
<pattern>**/maven-metadata.xml</pattern>
</patterns>
<consumers>
<consumer>repository-metadata-to-db</consumer>
<consumer>repository-metadata-version-mismatch</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>checksums</id>
<patterns>
<pattern>**/*.sha1</pattern>
<pattern>**/*.md5</pattern>
</patterns>
<consumers>
<consumer>checksum-validate</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>signatures</id>
<patterns>
<pattern>**/*.asc</pattern>
</patterns>
<consumers>
<consumer>signature-validate</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>archives</id>
<patterns>
<pattern>**/*.jar</pattern>
<pattern>**/*.ear</pattern>
<pattern>**/*.war</pattern>
<pattern>**/*.car</pattern>
<pattern>**/*.sar</pattern>
<pattern>**/*.mar</pattern>
<pattern>**/*.rar</pattern>
<pattern>**/*.tar.gz</pattern>
<pattern>**/*.tar.bz2</pattern>
<pattern>**/*.zip</pattern>
<pattern>**/*.nbm</pattern>
</patterns>
<consumers>
<consumer>archive-toc-to-lucene</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>bytecode</id>
<patterns>
<pattern>**/*.jar</pattern>
<pattern>**/*.war</pattern>
<pattern>**/*.car</pattern>
<pattern>**/*.sar</pattern>
<pattern>**/*.mar</pattern>
<pattern>**/*.rar</pattern>
</patterns>
<consumers>
<consumer>bytecode-to-db</consumer>
<consumer>bytecode-to-lucene</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>xmls</id>
<patterns>
<pattern>**/*.pom</pattern>
<pattern>**/*.xml</pattern>
<pattern>**/*.xsd</pattern>
</patterns>
<consumers>
<consumer>xml-to-lucene</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>text</id>
<patterns>
<pattern>**/*.txt</pattern>
<pattern>**/*.TXT</pattern>
<pattern>**/*.block</pattern>
<pattern>**/*.config</pattern>
</patterns>
</fileProcessor>
<fileProcessor>
<id>ignored</id>
<patterns>
<pattern>**/.htaccess</pattern>
<pattern>**/KEYS</pattern>
<pattern>**/*.rb</pattern>
<pattern>**/*.sh</pattern>
<pattern>**/.svn/**</pattern>
<pattern>**/.DAV/**</pattern>
</patterns>
<consumers>
<consumer>ignored</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>auto-remove</id>
<patterns>
<pattern>**/*.bak</pattern>
<pattern>**/*~</pattern>
<pattern>**/*-</pattern>
</patterns>
<consumers>
<consumer>auto-remove</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>auto-rename</id>
<patterns>
<pattern>**/*.distribution-tgz</pattern>
<pattern>**/*.distribution-zip</pattern>
<pattern>**/*.plugin</pattern>
</patterns>
<consumers>
<consumer>auto-rename</consumer>
</consumers>
</fileProcessor>
</fileProcessors>
</configuration>

View File

@ -21,33 +21,218 @@
<configuration> <configuration>
<repositories> <repositories>
<repository> <repository>
<directory>managed-repository</directory> <id>internal</id>
<id>local</id> <name>Archiva Managed Internal Repository</name>
<name>local</name> <url>file://${appserver.home}/repositories/internal</url>
<layout>default</layout>
<releases>true</releases>
<snapshots>false</snapshots>
<indexed>true</indexed>
<refreshCronExpression>0 0 * * ?</refreshCronExpression>
</repository>
<repository>
<id>snapshots</id>
<name>Archiva Managed Snapshot Repository</name>
<url>file://${appserver.home}/repositories/internal</url>
<layout>default</layout>
<releases>false</releases>
<snapshots>true</snapshots>
<indexed>true</indexed>
<refreshCronExpression>0 0,30 * * ?</refreshCronExpression>
</repository>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo1.maven.org/maven2</url>
<layout>default</layout>
<releases>true</releases>
<snapshots>false</snapshots>
<indexed>false</indexed>
</repository>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven 2</name>
<url>https://maven2-repository.dev.java.net/nonav/repository</url>
<layout>default</layout>
<releases>true</releases>
<snapshots>false</snapshots>
<indexed>false</indexed>
</repository> </repository>
</repositories> </repositories>
<proxiedRepositories> <proxyConnectors>
<proxiedRepository> <proxyConnector>
<url>http://www.ibiblio.org/maven2/</url> <sourceRepoId>internal</sourceRepoId>
<managedRepository>local</managedRepository> <targetRepoId>central</targetRepoId>
<useNetworkProxy>true</useNetworkProxy> <proxyId />
<id>ibiblio</id> <snapshotsPolicy>disabled</snapshotsPolicy>
<name>Ibiblio</name> <releasePolicy>never</releasePolicy>
</proxiedRepository> <failurePolicy>not-found</failurePolicy>
</proxiedRepositories> </proxyConnector>
<syncedRepositories> <proxyConnector>
<syncedRepository> <sourceRepoId>internal</sourceRepoId>
<id>apache</id> <targetRepoId>maven2-repository.dev.java.net</targetRepoId>
<name>ASF</name> <proxyId />
<cronExpression>0 0 * * * ?</cronExpression> <snapshotsPolicy>disabled</snapshotsPolicy>
<managedRepository>local</managedRepository> <releasePolicy>never</releasePolicy>
<method>rsync</method> <failurePolicy>not-found</failurePolicy>
<properties> <whiteListPatterns>
<rsyncHost>host</rsyncHost> <whileListPattern>javax/**</whileListPattern>
<rsyncMethod>ssh</rsyncMethod> </whiteListPatterns>
</properties> </proxyConnector>
</syncedRepository> </proxyConnectors>
</syncedRepositories> <networkProxies>
<localRepository>local-repository</localRepository> </networkProxies>
<indexPath>.index</indexPath> <fileProcessors>
<fileProcessor>
<id>artifacts</id>
<patterns>
<pattern>**/*.pom</pattern>
<pattern>**/*.jar</pattern>
<pattern>**/*.ear</pattern>
<pattern>**/*.war</pattern>
<pattern>**/*.car</pattern>
<pattern>**/*.sar</pattern>
<pattern>**/*.mar</pattern>
<pattern>**/*.rar</pattern>
<pattern>**/*.dtd</pattern>
<pattern>**/*.tld</pattern>
<pattern>**/*.tar.gz</pattern>
<pattern>**/*.tar.bz2</pattern>
<pattern>**/*.zip</pattern>
</patterns>
<consumers>
<consumer>artifact-to-db</consumer>
<consumer>artifact-to-lucene</consumer>
<consumer>artifact-create-missing-checksums</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>projects</id>
<patterns>
<pattern>**/*.pom</pattern>
</patterns>
<consumers>
<consumer>project-to-db</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>repository-metadata</id>
<patterns>
<pattern>**/maven-metadata.xml</pattern>
</patterns>
<consumers>
<consumer>repository-metadata-to-db</consumer>
<consumer>repository-metadata-version-mismatch</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>checksums</id>
<patterns>
<pattern>**/*.sha1</pattern>
<pattern>**/*.md5</pattern>
</patterns>
<consumers>
<consumer>checksum-validate</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>signatures</id>
<patterns>
<pattern>**/*.asc</pattern>
</patterns>
<consumers>
<consumer>signature-validate</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>archives</id>
<patterns>
<pattern>**/*.jar</pattern>
<pattern>**/*.ear</pattern>
<pattern>**/*.war</pattern>
<pattern>**/*.car</pattern>
<pattern>**/*.sar</pattern>
<pattern>**/*.mar</pattern>
<pattern>**/*.rar</pattern>
<pattern>**/*.tar.gz</pattern>
<pattern>**/*.tar.bz2</pattern>
<pattern>**/*.zip</pattern>
<pattern>**/*.nbm</pattern>
</patterns>
<consumers>
<consumer>archive-toc-to-lucene</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>bytecode</id>
<patterns>
<pattern>**/*.jar</pattern>
<pattern>**/*.war</pattern>
<pattern>**/*.car</pattern>
<pattern>**/*.sar</pattern>
<pattern>**/*.mar</pattern>
<pattern>**/*.rar</pattern>
</patterns>
<consumers>
<consumer>bytecode-to-db</consumer>
<consumer>bytecode-to-lucene</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>xmls</id>
<patterns>
<pattern>**/*.pom</pattern>
<pattern>**/*.xml</pattern>
<pattern>**/*.xsd</pattern>
</patterns>
<consumers>
<consumer>xml-to-lucene</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>text</id>
<patterns>
<pattern>**/*.txt</pattern>
<pattern>**/*.TXT</pattern>
<pattern>**/*.block</pattern>
<pattern>**/*.config</pattern>
</patterns>
</fileProcessor>
<fileProcessor>
<id>ignored</id>
<patterns>
<pattern>**/.htaccess</pattern>
<pattern>**/KEYS</pattern>
<pattern>**/*.rb</pattern>
<pattern>**/*.sh</pattern>
<pattern>**/.svn/**</pattern>
<pattern>**/.DAV/**</pattern>
</patterns>
<consumers>
<consumer>ignored</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>auto-remove</id>
<patterns>
<pattern>**/*.bak</pattern>
<pattern>**/*~</pattern>
<pattern>**/*-</pattern>
</patterns>
<consumers>
<consumer>auto-remove</consumer>
</consumers>
</fileProcessor>
<fileProcessor>
<id>auto-rename</id>
<patterns>
<pattern>**/*.distribution-tgz</pattern>
<pattern>**/*.distribution-zip</pattern>
<pattern>**/*.plugin</pattern>
</patterns>
<consumers>
<consumer>auto-rename</consumer>
</consumers>
</fileProcessor>
</fileProcessors>
</configuration> </configuration>

View File

@ -30,75 +30,43 @@ import java.util.Properties;
* *
* @author <a href="mailto:brett@apache.org">Brett Porter</a> * @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/ */
public class ArchivaConfigurationTest public class ArchivaConfigurationTest extends PlexusTestCase
extends PlexusTestCase
{ {
public void testDefaults() public void testDefaults() throws Exception
throws Exception
{ {
ArchivaConfiguration archivaConfiguration = ArchivaConfiguration archivaConfiguration =
(ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-defaults" ); (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-defaults" );
Configuration configuration = archivaConfiguration.getConfiguration(); Configuration configuration = archivaConfiguration.getConfiguration();
// check default configuration // check default configuration
assertNotNull( "check configuration returned", configuration ); assertNotNull( "check configuration returned", configuration );
assertEquals( "check configuration has default elements", "0 0,30 * * * ?",
configuration.getDataRefreshCronExpression() );
assertNull( "check configuration has default elements", configuration.getIndexPath() );
assertTrue( "check configuration has default elements", configuration.getRepositories().isEmpty() ); assertTrue( "check configuration has default elements", configuration.getRepositories().isEmpty() );
} }
public void testGetConfiguration() public void testGetConfiguration() throws Exception
throws Exception
{ {
ArchivaConfiguration archivaConfiguration = ArchivaConfiguration archivaConfiguration =
(ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" ); (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" );
Configuration configuration = archivaConfiguration.getConfiguration(); Configuration configuration = archivaConfiguration.getConfiguration();
assertEquals( "check indexPath", ".index", configuration.getIndexPath() ); assertEquals( "check repositories", 4, configuration.getRepositories().size() );
assertEquals( "check localRepository", "local-repository", configuration.getLocalRepository() ); assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
assertEquals( "check file processors", 12, configuration.getFileProcessors().size() );
assertEquals( "check managed repositories", 1, configuration.getRepositories().size() );
RepositoryConfiguration repository = RepositoryConfiguration repository =
(RepositoryConfiguration) configuration.getRepositories().iterator().next(); (RepositoryConfiguration) configuration.getRepositories().iterator().next();
assertEquals( "check managed repositories", "managed-repository", repository.getDirectory() ); assertEquals( "check managed repositories", "file://${appserver.home}/repositories/internal", repository.getUrl() );
assertEquals( "check managed repositories", "local", repository.getName() ); assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
assertEquals( "check managed repositories", "local", repository.getId() ); assertEquals( "check managed repositories", "internal", repository.getId() );
assertEquals( "check managed repositories", "default", repository.getLayout() ); assertEquals( "check managed repositories", "default", repository.getLayout() );
assertTrue( "check managed repositories", repository.isIndexed() ); 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 testGetConfigurationSystemOverride() public void testGetConfigurationSystemOverride() throws Exception
throws Exception
{ {
ArchivaConfiguration archivaConfiguration = ArchivaConfiguration archivaConfiguration =
(ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" ); (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" );
@ -107,12 +75,11 @@ public class ArchivaConfigurationTest
Configuration configuration = archivaConfiguration.getConfiguration(); Configuration configuration = archivaConfiguration.getConfiguration();
assertEquals( "check localRepository", "system-repository", configuration.getLocalRepository() ); // assertEquals( "check localRepository", "system-repository", configuration.getLocalRepository() );
assertEquals( "check indexPath", ".index", configuration.getIndexPath() ); // assertEquals( "check indexPath", ".index", configuration.getIndexPath() );
} }
public void testStoreConfiguration() public void testStoreConfiguration() throws Exception
throws Exception
{ {
File file = getTestFile( "target/test/test-file.xml" ); File file = getTestFile( "target/test/test-file.xml" );
file.delete(); file.delete();
@ -126,7 +93,7 @@ public class ArchivaConfigurationTest
(ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save" ); (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save" );
Configuration configuration = new Configuration(); Configuration configuration = new Configuration();
configuration.setIndexPath( "index-path" ); // configuration.setIndexPath( "index-path" );
archivaConfiguration.save( configuration ); archivaConfiguration.save( configuration );
@ -134,16 +101,15 @@ public class ArchivaConfigurationTest
// check it // check it
configuration = archivaConfiguration.getConfiguration(); configuration = archivaConfiguration.getConfiguration();
assertEquals( "check value", "index-path", configuration.getIndexPath() ); // assertEquals( "check value", "index-path", configuration.getIndexPath() );
// read it back // read it back
archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" ); archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" );
configuration = archivaConfiguration.getConfiguration(); configuration = archivaConfiguration.getConfiguration();
assertEquals( "check value", "index-path", configuration.getIndexPath() ); // assertEquals( "check value", "index-path", configuration.getIndexPath() );
} }
public void testStoreConfigurationUser() public void testStoreConfigurationUser() throws Exception
throws Exception
{ {
File baseFile = getTestFile( "target/test/test-file.xml" ); File baseFile = getTestFile( "target/test/test-file.xml" );
baseFile.delete(); baseFile.delete();
@ -161,7 +127,7 @@ public class ArchivaConfigurationTest
(ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" ); (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
Configuration configuration = new Configuration(); Configuration configuration = new Configuration();
configuration.setIndexPath( "index-path" ); // configuration.setIndexPath( "index-path" );
archivaConfiguration.save( configuration ); archivaConfiguration.save( configuration );
@ -170,11 +136,10 @@ public class ArchivaConfigurationTest
// check it // check it
configuration = archivaConfiguration.getConfiguration(); configuration = archivaConfiguration.getConfiguration();
assertEquals( "check value", "index-path", configuration.getIndexPath() ); // assertEquals( "check value", "index-path", configuration.getIndexPath() );
} }
public void testStoreConfigurationFallback() public void testStoreConfigurationFallback() throws Exception
throws Exception
{ {
File baseFile = getTestFile( "target/test/test-file.xml" ); File baseFile = getTestFile( "target/test/test-file.xml" );
baseFile.delete(); baseFile.delete();
@ -192,7 +157,7 @@ public class ArchivaConfigurationTest
(ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" ); (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
Configuration configuration = new Configuration(); Configuration configuration = new Configuration();
configuration.setIndexPath( "index-path" ); // configuration.setIndexPath( "index-path" );
archivaConfiguration.save( configuration ); archivaConfiguration.save( configuration );
@ -201,11 +166,10 @@ public class ArchivaConfigurationTest
// check it // check it
configuration = archivaConfiguration.getConfiguration(); configuration = archivaConfiguration.getConfiguration();
assertEquals( "check value", "index-path", configuration.getIndexPath() ); // assertEquals( "check value", "index-path", configuration.getIndexPath() );
} }
public void testRemoveProxiedRepositoryAndStoreConfiguration() public void testRemoveProxiedRepositoryAndStoreConfiguration() throws Exception
throws Exception
{ {
// MRM-300 // MRM-300
@ -217,13 +181,13 @@ public class ArchivaConfigurationTest
(ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-remove-proxied-repo" ); (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-remove-proxied-repo" );
Configuration configuration = archivaConfiguration.getConfiguration(); Configuration configuration = archivaConfiguration.getConfiguration();
configuration.getProxiedRepositories().remove( 0 ); // configuration.getProxiedRepositories().remove( 0 );
archivaConfiguration.save( configuration ); archivaConfiguration.save( configuration );
// check it // check it
configuration = archivaConfiguration.getConfiguration(); configuration = archivaConfiguration.getConfiguration();
assertEquals( 1, configuration.getProxiedRepositories().size() ); // assertEquals( 1, configuration.getProxiedRepositories().size() );
release( archivaConfiguration ); release( archivaConfiguration );
@ -231,6 +195,6 @@ public class ArchivaConfigurationTest
archivaConfiguration = archivaConfiguration =
(ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-back-remove-proxied-repo" ); (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-back-remove-proxied-repo" );
configuration = archivaConfiguration.getConfiguration(); configuration = archivaConfiguration.getConfiguration();
assertEquals( 1, configuration.getProxiedRepositories().size() ); // assertEquals( 1, configuration.getProxiedRepositories().size() );
} }
} }

View File

@ -24,63 +24,54 @@ import org.codehaus.plexus.PlexusTestCase;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
/** /**
* @author Edwin Punzalan * @author Edwin Punzalan
*/ */
public class MavenProxyPropertyLoaderTest public class MavenProxyPropertyLoaderTest extends PlexusTestCase
extends PlexusTestCase
{ {
private static final int DEFAULT_CACHE_PERIOD = 3600;
private MavenProxyPropertyLoader loader; private MavenProxyPropertyLoader loader;
public void testLoadValidMavenProxyConfiguration() public void testLoadValidMavenProxyConfiguration() throws IOException, InvalidConfigurationException
throws IOException, InvalidConfigurationException
{ {
File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" ); File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" );
Configuration configuration = new Configuration(); Configuration configuration = new Configuration();
Proxy proxy = new Proxy(); ProxyConfiguration proxy = new ProxyConfiguration();
proxy.setHost( "original-host" ); proxy.setHost( "original-host" );
configuration.setProxy( proxy ); // overwritten configuration.addNetworkProxy( proxy ); // overwritten
configuration.setIndexPath( "index-path" ); // existing value
loader.load( new FileInputStream( confFile ), configuration ); loader.load( new FileInputStream( confFile ), configuration );
List list = configuration.getRepositories(); List repos = configuration.getRepositories();
assertEquals( "check single managed repository", 1, list.size() ); assertEquals( "Count repositories", 5, repos.size() );
RepositoryConfiguration managedRepository = (RepositoryConfiguration) list.iterator().next();
assertEquals( "cache path changed", "target", managedRepository.getDirectory() );
assertEquals( "Count repositories", 4, configuration.getProxiedRepositories().size() ); Map repositoryIdMap = new HashMap();
list = configuration.getProxiedRepositories(); for ( Iterator itRepo = repos.iterator(); itRepo.hasNext(); )
ProxiedRepositoryConfiguration repo = (ProxiedRepositoryConfiguration) list.get( 0 ); {
assertEquals( "Repository name not as expected", "local-repo", repo.getId() ); RepositoryConfiguration repo = (RepositoryConfiguration) itRepo.next();
assertEquals( "Repository url does not match its name", "file://target", repo.getUrl() ); repositoryIdMap.put( repo.getId(), repo );
assertEquals( "Repository cache period check failed", 0, repo.getSnapshotsInterval() ); }
assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
repo = (ProxiedRepositoryConfiguration) list.get( 1 ); assertRepositoryExists( repositoryIdMap, "local-repo", "file://target" );
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 ); assertRepositoryExists( repositoryIdMap, "www-ibiblio-org", "http://www.ibiblio.org/maven2" );
assertEquals( "Repository name not as expected", "dist-codehaus-org", repo.getId() ); assertRepositoryExists( repositoryIdMap, "dist-codehaus-org", "http://dist.codehaus.org" );
assertEquals( "Repository url does not match its name", "http://dist.codehaus.org", repo.getUrl() ); assertRepositoryExists( repositoryIdMap, "private-example-com", "http://private.example.com/internal" );
assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() ); }
assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
repo = (ProxiedRepositoryConfiguration) list.get( 3 ); private void assertRepositoryExists( Map repoMap, String id, String expectedUrl )
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() ); RepositoryConfiguration repo = (RepositoryConfiguration) repoMap.get( id );
assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() ); assertNotNull( "Repository id [" + id + "] should not be null", repo );
assertFalse( "Repository failure caching check failed", repo.isCacheFailures() ); assertEquals( "Repository id", id, repo.getId() );
assertEquals( "Repository url", expectedUrl, repo.getUrl() );
} }
public void testInvalidConfiguration() public void testInvalidConfiguration()
@ -97,8 +88,7 @@ public class MavenProxyPropertyLoaderTest
} }
} }
protected void setUp() protected void setUp() throws Exception
throws Exception
{ {
super.setUp(); super.setUp();
loader = new MavenProxyPropertyLoader(); loader = new MavenProxyPropertyLoader();