From ad842d82a28427eb458b73f99f2e9e13e75701eb Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 22 Mar 2007 19:33:28 +0000 Subject: [PATCH] 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 --- .../DefaultArchivaConfiguration.java | 5 +- .../MavenProxyPropertyLoader.java | 64 +- .../src/main/mdo/configuration.mdo | 788 ++++++++---------- .../archiva/configuration/default-archiva.xml | 219 +++++ .../src/test/conf/repository-manager.xml | 239 +++++- .../ArchivaConfigurationTest.java | 92 +- .../MavenProxyPropertyLoaderTest.java | 64 +- 7 files changed, 891 insertions(+), 580 deletions(-) create mode 100644 archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml diff --git a/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java index f3c50fbc0..ab64a661d 100644 --- a/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java +++ b/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java @@ -60,13 +60,10 @@ public class DefaultArchivaConfiguration configuration = new ConfigurationRegistryReader().read( registry.getSubset( KEY ) ); // 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(); ) { RepositoryConfiguration c = (RepositoryConfiguration) i.next(); - c.setDirectory( removeExpressions( c.getDirectory() ) ); + c.setUrl( removeExpressions( c.getUrl() ) ); } } return configuration; diff --git a/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoader.java b/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoader.java index fec53daf4..070ed0539 100644 --- a/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoader.java +++ b/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoader.java @@ -21,8 +21,10 @@ package org.apache.maven.archiva.configuration; import org.apache.commons.lang.StringUtils; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; import java.util.Enumeration; import java.util.Properties; import java.util.StringTokenizer; @@ -39,19 +41,18 @@ public class MavenProxyPropertyLoader private static final String REPO_LIST = "repo.list"; - public void load( Properties props, Configuration configuration ) - throws InvalidConfigurationException + 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.setUrl( toURL( localCachePath ) ); config.setName( "Imported Maven-Proxy Cache" ); config.setId( "maven-proxy" ); configuration.addRepository( config ); - //just get the first HTTP proxy and break + // Add the network proxies. String propertyList = props.getProperty( PROXY_LIST ); if ( propertyList != null ) { @@ -61,7 +62,7 @@ public class MavenProxyPropertyLoader String key = tok.nextToken(); if ( StringUtils.isNotEmpty( key ) ) { - Proxy proxy = new Proxy(); + ProxyConfiguration proxy = new ProxyConfiguration(); proxy.setHost( getMandatoryProperty( props, "proxy." + key + ".host" ) ); proxy.setPort( Integer.parseInt( getMandatoryProperty( props, "proxy." + key + ".port" ) ) ); @@ -69,15 +70,12 @@ public class MavenProxyPropertyLoader proxy.setUsername( props.getProperty( "proxy." + key + ".username" ) ); proxy.setPassword( props.getProperty( "proxy." + key + ".password" ) ); - configuration.setProxy( proxy ); - - //accept only one proxy configuration - break; + configuration.addNetworkProxy( proxy ); } } } - //get the remote repository list + // Add the remote repository list String repoList = getMandatoryProperty( props, REPO_LIST ); StringTokenizer tok = new StringTokenizer( repoList, "," ); @@ -89,23 +87,41 @@ public class MavenProxyPropertyLoader 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(); + RepositoryConfiguration repository = new RepositoryConfiguration(); 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 ); + repository.setLayout( "legacy" ); + repository.setIndexed( false ); + repository.setReleases( true ); + repository.setSnapshots( false ); + + 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 ); + } + } - configuration.addProxiedRepository( repository ); + 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; } - public void load( InputStream is, Configuration configuration ) - throws IOException, InvalidConfigurationException + 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 + private String getMandatoryProperty( Properties props, String key ) throws InvalidConfigurationException { String value = props.getProperty( key ); diff --git a/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-configuration/src/main/mdo/configuration.mdo index 2893e289c..75ba48c53 100644 --- a/archiva-configuration/src/main/mdo/configuration.mdo +++ b/archiva-configuration/src/main/mdo/configuration.mdo @@ -32,449 +32,321 @@ Configuration - 1.0.0 + 1.0.0+ repositories - 1.0.0 + 1.0.0+ RepositoryConfiguration - * - - - - proxiedRepositories - 1.0.0 - - ProxiedRepositoryConfiguration - * - - - - syncedRepositories - 1.0.0 - - SyncedRepositoryConfiguration - * - - - - localRepository - 1.0.0 - String - - The location of the local repository. - - - - indexPath - 1.0.0 - String - - The location of the Lucene index to use for the repository. The default is the .index subdirectory of - the repository. - - - - minimalIndexPath - 1.0.0 - String - - The location of the reduced Lucene index to use for the repository. The default is the .small-index - subdirectory of the repository. - - - - dataRefreshCronExpression - 1.0.0 - String - When to run the data refresh task. Default is every 30 mins (translated as every 0 and 30 minute reading of every hour) - 0 0,30 * * * ? + * + + The list of repositories that this archiva instance uses. + + + proxyConnectors + 1.0.0+ + + RepositoryProxyConnectorConfiguration + * + + The list of proxy connectors for this archiva instance. - - globalBlackListPatterns - 1.0.0 - Blacklisted patterns in the discovery process + networkProxies + 1.0.0+ - String + ProxyConfiguration * + + The list of network proxies to use for outgoing requests. + - --> - - proxy - 1.0.0 - - Proxy - - The network proxy to use for outgoing requests. + + fileProcessors + 1.0.0+ + + FileProcessor + * + + + The file processors setup. + - - - 1.0.0 - + + - 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; - } - ]]> - - - - - AbstractRepositoryConfiguration - true - 1.0.0 - - - id - 1.0.0 - String - true - - The repository identifier. - - - - name - 1.0.0 - String - true - - The descriptive name of the repository. - - - - layout - 1.0.0 - String - true - - The layout of the repository. Valid values are "default" and "legacy". - - - default - - - - - 1.0.0 - - - - - AbstractRepositoryConfiguration RepositoryConfiguration - 1.0.0 + 1.0.0+ + + id + 1.0.0+ + String + true + + The repository identifier. + + + + name + 1.0.0+ + String + true + + The descriptive name of the repository. + + + + url + 1.0.0+ + String + true + + The URL for this repository. + + + + layout + 1.0.0+ + String + true + + The layout of the repository. Valid values are "default" and "legacy". + + + default + + + releases + 1.0.0+ + boolean + True if this repository contains release versioned artifacts. + true + - urlName - 1.0.0 - String - true - - The URL name for this repository. - Used to create the WebDAV URL for the repository such like - http://hostname.com/repository/${urlName}/ - - - - directory - 1.0.0 - String - true - - The location of the repository to monitor. - - - - includeSnapshots - 1.0.0 + snapshots + 1.0.0+ boolean - Whether to include snapshot versions in the discovery process + True if this repository contains snapshot versioned artifacts. false indexed - 1.0.0 + 1.0.0+ boolean - Whether to index the artifacts in this repository. + True if this repository should be indexed. true - - - blackListPatterns - 1.0.0 - Blacklisted patterns in the discovery process - - String - * - - + + + refreshCronExpression + 1.0.0+ + String + + When to run the refresh task. + Default is every 30 minutes (translated as every 0 and 30 minute reading of every hour) + + 0 0,30 * * * ? + - + + + + + + AbstractRepositoryConnectorConfiguration + true + 1.0.0+ + + + sourceRepoId + 1.0.0+ + String + true + + The Repository Source for this connector. + + + + targetRepoId + 1.0.0+ + String + true + + The Repository Target for this connector. + + + + proxyId + 1.0.0+ + String + + The network proxy ID to use for this connector. + + + + blackListPatterns + 1.0.0+ + + String + * + + + The list of blacklisted patterns for this connector. + + + + whiteListPatterns + 1.0.0+ + + String + * + + + The list of whitelisted patterns for this connector. + + + + + - AbstractRepositoryConfiguration - ProxiedRepositoryConfiguration - 1.0.0 - - - url - 1.0.0 - String - true - - The URL of the remote repository to proxy. - - - - - managedRepository - 1.0.0 - true - String - - The ID of the managed repository to use as the local storage for proxied artifacts. - - + AbstractRepositoryConnectorConfiguration + RepositoryProxyConnectorConfiguration + 1.0.0+ + snapshotsPolicy - 1.0.0 + 1.0.0+ String disabled - The policy for snapshots: one of disabled, daily, hourly, interval, never - (allow snapshots, but never update once retrieved). - - - - snapshotsInterval - 1.0.0 - int - - The interval in minutes before updating snapshots if the policy is set to 'interval'. + The policy for snapshots: + Can be one of the following keywords: + "disabled" - means retrieval isn't even attempted. + "daily" - means snapshot is fetched, but only updated on + a daily basis. (equivalent to "1440" minutes) + "hourly" - means snapshot is fetched, but only updated on + an hourly basis. (equivalent to "60" minutes) + "never" - means snapshot is fetched once, but never updated. + (equivalent to "-1" minutes) + Or it can be a number of minutes before updating of the snapshot. releasesPolicy - 1.0.0 + 1.0.0+ String - daily + never - The policy for releases: one of disabled, daily, hourly, interval, never - (allow releases, but never update once retrieved). + The policy for releases: + 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. - releasesInterval - 1.0.0 - int - - The interval in minutes before updating releases if the policy is set to 'interval'. - - - - useNetworkProxy - 1.0.0 - boolean - false - - Whether to use the network proxy, if one is configured for the protocol of this repository. - - - - cacheFailures - 1.0.0 - boolean - false - - 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. - - - - hardFail - 1.0.0 - boolean - false - - Whether to cause the entire request to fail if attempts to retrieve from this proxy fail. + failurePolicy + 1.0.0+ + String + not-found + + The policy for dealing with proxy failures. + Can be one of the following keywords: + "not-found" - means if the retrieval has a failure, an HTTP 404 + (not found) is returned to the client of this + archiva instance. + This policy setting will allow other proxies + to be checked for content. + "failure" - means if the retrieval has a failure, an HTTP 500 + (server error) is returned to the client of this + archiva instance. + This policy setting will return immediately to the + client of the archiva instance and not allow + furthor attempts on other proxies for this content. - - - + + + + + 1.0.0+ + + + + + - AbstractRepositoryConfiguration - SyncedRepositoryConfiguration + AbstractRepositoryConnectorConfiguration + RepositorySynchConnectorConfiguration true - 1.0.0 + 1.0.0+ - - - managedRepository - 1.0.0 - true - String - - The ID of the managed repository to use as the local storage for proxied artifacts. - - cronExpression - 1.0.0 + 1.0.0+ String When to run the sync mechanism. Default is every hour on the hour. 0 0 * * * ? method - 1.0.0 + 1.0.0+ String The type of synchronization to use. rsync properties - 1.0.0 + 1.0.0+ Properties Configuration for the repository synchronization. @@ -483,54 +355,124 @@ - + + + + - Proxy - 1.0.0 - - - protocol - 1.0.0 - - String - http - + ProxyConfiguration + 1.0.0+ + + + id + 1.0.0+ + String + + The ID for this proxy. + + + + protocol + 1.0.0+ + + The network protocol to use with this proxy. + + String + true + http + + + host + 1.0.0+ + + The proxy host. + + String + true + + + port + 1.0.0+ + + The proxy port. + + int + 8080 + username - 1.0.0 - + 1.0.0+ + + The proxy user. + String password - 1.0.0 - - String - - - port - 1.0.0 - - int - 8080 - - - host - 1.0.0 - - String - true - - - nonProxyHosts - 1.0.0 - + 1.0.0+ + + The proxy password. + String - + - + + + + + FileProcessor + 1.0.0+ + + + id + 1.0.0+ + true + String + + The ID for this file processor + + + + patterns + 1.0.0+ + true + + String + * + + + The list of patterns for this processor. + + + + consumers + 1.0.0+ + true + + String + * + + + The list of consumer IDs for this file processor. + + + + + diff --git a/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml b/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml new file mode 100644 index 000000000..4c48beb5d --- /dev/null +++ b/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml @@ -0,0 +1,219 @@ + + + + + internal + Archiva Managed Internal Repository + file://${appserver.home}/repositories/internal + default + true + false + true + 0 0 * * ? + + + snapshots + Archiva Managed Snapshot Repository + file://${appserver.home}/repositories/internal + default + false + true + true + 0 0,30 * * ? + + + central + Central Repository + http://repo1.maven.org/maven2 + default + true + false + false + + + maven2-repository.dev.java.net + Java.net Repository for Maven 2 + https://maven2-repository.dev.java.net/nonav/repository + default + true + false + false + + + + + internal + central + + disabled + never + not-found + + + internal + maven2-repository.dev.java.net + + disabled + never + not-found + + javax/** + + + + + + + + artifacts + + **/*.pom + **/*.jar + **/*.ear + **/*.war + **/*.car + **/*.sar + **/*.mar + **/*.rar + **/*.dtd + **/*.tld + **/*.tar.gz + **/*.tar.bz2 + **/*.zip + + + artifact-to-db + artifact-to-lucene + artifact-create-missing-checksums + + + + projects + + **/*.pom + + + project-to-db + + + + repository-metadata + + **/maven-metadata.xml + + + repository-metadata-to-db + repository-metadata-version-mismatch + + + + checksums + + **/*.sha1 + **/*.md5 + + + checksum-validate + + + + signatures + + **/*.asc + + + signature-validate + + + + archives + + **/*.jar + **/*.ear + **/*.war + **/*.car + **/*.sar + **/*.mar + **/*.rar + **/*.tar.gz + **/*.tar.bz2 + **/*.zip + **/*.nbm + + + archive-toc-to-lucene + + + + bytecode + + **/*.jar + **/*.war + **/*.car + **/*.sar + **/*.mar + **/*.rar + + + bytecode-to-db + bytecode-to-lucene + + + + xmls + + **/*.pom + **/*.xml + **/*.xsd + + + xml-to-lucene + + + + text + + **/*.txt + **/*.TXT + **/*.block + **/*.config + + + + ignored + + **/.htaccess + **/KEYS + **/*.rb + **/*.sh + **/.svn/** + **/.DAV/** + + + ignored + + + + auto-remove + + **/*.bak + **/*~ + **/*- + + + auto-remove + + + + auto-rename + + **/*.distribution-tgz + **/*.distribution-zip + **/*.plugin + + + auto-rename + + + + diff --git a/archiva-configuration/src/test/conf/repository-manager.xml b/archiva-configuration/src/test/conf/repository-manager.xml index 4008e2503..44e7fc155 100644 --- a/archiva-configuration/src/test/conf/repository-manager.xml +++ b/archiva-configuration/src/test/conf/repository-manager.xml @@ -21,33 +21,218 @@ - managed-repository - local - local + internal + Archiva Managed Internal Repository + file://${appserver.home}/repositories/internal + default + true + false + true + 0 0 * * ? + + + snapshots + Archiva Managed Snapshot Repository + file://${appserver.home}/repositories/internal + default + false + true + true + 0 0,30 * * ? + + + central + Central Repository + http://repo1.maven.org/maven2 + default + true + false + false + + + maven2-repository.dev.java.net + Java.net Repository for Maven 2 + https://maven2-repository.dev.java.net/nonav/repository + default + true + false + false - - - http://www.ibiblio.org/maven2/ - local - true - ibiblio - Ibiblio - - - - - apache - ASF - 0 0 * * * ? - local - rsync - - host - ssh - - - - local-repository - .index + + + internal + central + + disabled + never + not-found + + + internal + maven2-repository.dev.java.net + + disabled + never + not-found + + javax/** + + + + + + + + artifacts + + **/*.pom + **/*.jar + **/*.ear + **/*.war + **/*.car + **/*.sar + **/*.mar + **/*.rar + **/*.dtd + **/*.tld + **/*.tar.gz + **/*.tar.bz2 + **/*.zip + + + artifact-to-db + artifact-to-lucene + artifact-create-missing-checksums + + + + projects + + **/*.pom + + + project-to-db + + + + repository-metadata + + **/maven-metadata.xml + + + repository-metadata-to-db + repository-metadata-version-mismatch + + + + checksums + + **/*.sha1 + **/*.md5 + + + checksum-validate + + + + signatures + + **/*.asc + + + signature-validate + + + + archives + + **/*.jar + **/*.ear + **/*.war + **/*.car + **/*.sar + **/*.mar + **/*.rar + **/*.tar.gz + **/*.tar.bz2 + **/*.zip + **/*.nbm + + + archive-toc-to-lucene + + + + bytecode + + **/*.jar + **/*.war + **/*.car + **/*.sar + **/*.mar + **/*.rar + + + bytecode-to-db + bytecode-to-lucene + + + + xmls + + **/*.pom + **/*.xml + **/*.xsd + + + xml-to-lucene + + + + text + + **/*.txt + **/*.TXT + **/*.block + **/*.config + + + + ignored + + **/.htaccess + **/KEYS + **/*.rb + **/*.sh + **/.svn/** + **/.DAV/** + + + ignored + + + + auto-remove + + **/*.bak + **/*~ + **/*- + + + auto-remove + + + + auto-rename + + **/*.distribution-tgz + **/*.distribution-zip + **/*.plugin + + + auto-rename + + + diff --git a/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java b/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java index 4c21b15df..8f4243c27 100644 --- a/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java +++ b/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java @@ -30,75 +30,43 @@ import java.util.Properties; * * @author Brett Porter */ -public class ArchivaConfigurationTest - extends PlexusTestCase +public class ArchivaConfigurationTest extends PlexusTestCase { - public void testDefaults() - throws Exception + public void testDefaults() throws Exception { ArchivaConfiguration archivaConfiguration = - (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-defaults" ); + (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-defaults" ); Configuration configuration = archivaConfiguration.getConfiguration(); // check default 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() ); } - public void testGetConfiguration() - throws Exception + public void testGetConfiguration() throws Exception { ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" ); Configuration configuration = archivaConfiguration.getConfiguration(); - assertEquals( "check indexPath", ".index", configuration.getIndexPath() ); - assertEquals( "check localRepository", "local-repository", configuration.getLocalRepository() ); + assertEquals( "check repositories", 4, configuration.getRepositories().size() ); + 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) 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", "file://${appserver.home}/repositories/internal", repository.getUrl() ); + assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() ); + assertEquals( "check managed repositories", "internal", 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 testGetConfigurationSystemOverride() - throws Exception + public void testGetConfigurationSystemOverride() throws Exception { ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" ); @@ -107,12 +75,11 @@ public class ArchivaConfigurationTest Configuration configuration = archivaConfiguration.getConfiguration(); - assertEquals( "check localRepository", "system-repository", configuration.getLocalRepository() ); - assertEquals( "check indexPath", ".index", configuration.getIndexPath() ); + // assertEquals( "check localRepository", "system-repository", configuration.getLocalRepository() ); + // assertEquals( "check indexPath", ".index", configuration.getIndexPath() ); } - public void testStoreConfiguration() - throws Exception + public void testStoreConfiguration() throws Exception { File file = getTestFile( "target/test/test-file.xml" ); file.delete(); @@ -126,7 +93,7 @@ public class ArchivaConfigurationTest (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save" ); Configuration configuration = new Configuration(); - configuration.setIndexPath( "index-path" ); + // configuration.setIndexPath( "index-path" ); archivaConfiguration.save( configuration ); @@ -134,16 +101,15 @@ public class ArchivaConfigurationTest // check it configuration = archivaConfiguration.getConfiguration(); - assertEquals( "check value", "index-path", configuration.getIndexPath() ); + // assertEquals( "check value", "index-path", configuration.getIndexPath() ); // read it back archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" ); configuration = archivaConfiguration.getConfiguration(); - assertEquals( "check value", "index-path", configuration.getIndexPath() ); + // assertEquals( "check value", "index-path", configuration.getIndexPath() ); } - public void testStoreConfigurationUser() - throws Exception + public void testStoreConfigurationUser() throws Exception { File baseFile = getTestFile( "target/test/test-file.xml" ); baseFile.delete(); @@ -161,7 +127,7 @@ public class ArchivaConfigurationTest (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" ); Configuration configuration = new Configuration(); - configuration.setIndexPath( "index-path" ); + // configuration.setIndexPath( "index-path" ); archivaConfiguration.save( configuration ); @@ -170,11 +136,10 @@ public class ArchivaConfigurationTest // check it configuration = archivaConfiguration.getConfiguration(); - assertEquals( "check value", "index-path", configuration.getIndexPath() ); + // assertEquals( "check value", "index-path", configuration.getIndexPath() ); } - public void testStoreConfigurationFallback() - throws Exception + public void testStoreConfigurationFallback() throws Exception { File baseFile = getTestFile( "target/test/test-file.xml" ); baseFile.delete(); @@ -192,7 +157,7 @@ public class ArchivaConfigurationTest (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" ); Configuration configuration = new Configuration(); - configuration.setIndexPath( "index-path" ); + // configuration.setIndexPath( "index-path" ); archivaConfiguration.save( configuration ); @@ -201,11 +166,10 @@ public class ArchivaConfigurationTest // check it configuration = archivaConfiguration.getConfiguration(); - assertEquals( "check value", "index-path", configuration.getIndexPath() ); + // assertEquals( "check value", "index-path", configuration.getIndexPath() ); } - public void testRemoveProxiedRepositoryAndStoreConfiguration() - throws Exception + public void testRemoveProxiedRepositoryAndStoreConfiguration() throws Exception { // MRM-300 @@ -217,13 +181,13 @@ public class ArchivaConfigurationTest (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-remove-proxied-repo" ); Configuration configuration = archivaConfiguration.getConfiguration(); - configuration.getProxiedRepositories().remove( 0 ); + // configuration.getProxiedRepositories().remove( 0 ); archivaConfiguration.save( configuration ); // check it configuration = archivaConfiguration.getConfiguration(); - assertEquals( 1, configuration.getProxiedRepositories().size() ); + // assertEquals( 1, configuration.getProxiedRepositories().size() ); release( archivaConfiguration ); @@ -231,6 +195,6 @@ public class ArchivaConfigurationTest archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-back-remove-proxied-repo" ); configuration = archivaConfiguration.getConfiguration(); - assertEquals( 1, configuration.getProxiedRepositories().size() ); + // assertEquals( 1, configuration.getProxiedRepositories().size() ); } } diff --git a/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java b/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java index e56bf2aa1..091126087 100644 --- a/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java +++ b/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java @@ -24,63 +24,54 @@ import org.codehaus.plexus.PlexusTestCase; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Properties; /** * @author Edwin Punzalan */ -public class MavenProxyPropertyLoaderTest - extends PlexusTestCase +public class MavenProxyPropertyLoaderTest extends PlexusTestCase { - private static final int DEFAULT_CACHE_PERIOD = 3600; - private MavenProxyPropertyLoader loader; - public void testLoadValidMavenProxyConfiguration() - throws IOException, InvalidConfigurationException + public void testLoadValidMavenProxyConfiguration() throws IOException, InvalidConfigurationException { File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" ); Configuration configuration = new Configuration(); - Proxy proxy = new Proxy(); + ProxyConfiguration proxy = new ProxyConfiguration(); proxy.setHost( "original-host" ); - configuration.setProxy( proxy ); // overwritten - configuration.setIndexPath( "index-path" ); // existing value + configuration.addNetworkProxy( proxy ); // overwritten 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() ); + List repos = configuration.getRepositories(); + assertEquals( "Count repositories", 5, repos.size() ); - assertEquals( "Count repositories", 4, configuration.getProxiedRepositories().size() ); + Map repositoryIdMap = new HashMap(); - 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() ); + for ( Iterator itRepo = repos.iterator(); itRepo.hasNext(); ) + { + RepositoryConfiguration repo = (RepositoryConfiguration) itRepo.next(); + repositoryIdMap.put( repo.getId(), repo ); + } - 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() ); + assertRepositoryExists( repositoryIdMap, "local-repo", "file://target" ); - 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() ); + assertRepositoryExists( repositoryIdMap, "www-ibiblio-org", "http://www.ibiblio.org/maven2" ); + assertRepositoryExists( repositoryIdMap, "dist-codehaus-org", "http://dist.codehaus.org" ); + assertRepositoryExists( repositoryIdMap, "private-example-com", "http://private.example.com/internal" ); + } - 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() ); + private void assertRepositoryExists( Map repoMap, String id, String expectedUrl ) + { + RepositoryConfiguration repo = (RepositoryConfiguration) repoMap.get( id ); + assertNotNull( "Repository id [" + id + "] should not be null", repo ); + assertEquals( "Repository id", id, repo.getId() ); + assertEquals( "Repository url", expectedUrl, repo.getUrl() ); } public void testInvalidConfiguration() @@ -97,8 +88,7 @@ public class MavenProxyPropertyLoaderTest } } - protected void setUp() - throws Exception + protected void setUp() throws Exception { super.setUp(); loader = new MavenProxyPropertyLoader(); -- 2.39.5