diff options
author | Brett Porter <brett@apache.org> | 2007-09-12 09:33:41 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2007-09-12 09:33:41 +0000 |
commit | 17f229020f24ab34c553ef619f11834ae6882b21 (patch) | |
tree | 1867c4e8f537fe2f7cb05c129aa75b728ae035e5 /archiva-base | |
parent | b8cca284caff8744badd9db482f6db163b6e0a18 (diff) | |
download | archiva-17f229020f24ab34c553ef619f11834ae6882b21.tar.gz archiva-17f229020f24ab34c553ef619f11834ae6882b21.zip |
[MRM-462] separate configuration of managed and remote repositories
Merged from branches/MRM-462
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@574859 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-base')
66 files changed, 1333 insertions, 1385 deletions
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationNames.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationNames.java index e371f0920..e1daac902 100644 --- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationNames.java +++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationNames.java @@ -20,7 +20,7 @@ package org.apache.maven.archiva.configuration; */ /** - * Utility methods for testing the configuration property name. + * Utility methods for testing the configuration property name. * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ @@ -37,9 +37,14 @@ public class ConfigurationNames return startsWith( "repositoryScanning.", propertyName ); } - public static boolean isRepositories( String propertyName ) + public static boolean isManagedRepositories( String propertyName ) { - return startsWith( "repositories.", propertyName ); + return startsWith( "managedRepositories.", propertyName ); + } + + public static boolean isRemoteRepositories( String propertyName ) + { + return startsWith( "remoteRepositories.", propertyName ); } public static boolean isProxyConnector( String propertyName ) diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java index 75ab84426..1acc3c8a7 100644 --- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java +++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java @@ -117,6 +117,34 @@ public class DefaultArchivaConfiguration Configuration config = new ConfigurationRegistryReader().read( subset ); + if ( !config.getRepositories().isEmpty() ) + { + for ( Iterator i = config.getRepositories().iterator(); i.hasNext(); ) + { + V1RepositoryConfiguration r = (V1RepositoryConfiguration) i.next(); + + if ( r.getUrl().startsWith( "file://" ) ) + { + r.setLocation( r.getUrl().substring( 7 ) ); + config.addManagedRepository( r ); + } + else if ( r.getUrl().startsWith( "file:" ) ) + { + r.setLocation( r.getUrl().substring( 5 ) ); + config.addManagedRepository( r ); + } + else + { + RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration(); + repo.setId( r.getId() ); + repo.setLayout( r.getLayout() ); + repo.setName( r.getName() ); + repo.setUrl( r.getUrl() ); + config.addRemoteRepository( repo ); + } + } + } + return config; } @@ -162,7 +190,8 @@ public class DefaultArchivaConfiguration // that configuration if ( key.startsWith( "repositories" ) || key.startsWith( "proxyConnectors" ) || key.startsWith( "networkProxies" ) || key.startsWith( "repositoryScanning" ) || - key.startsWith( "databaseScanning" ) ) + key.startsWith( "databaseScanning" ) || key.startsWith( "remoteRepositories" ) || + key.startsWith( "managedRepositories" ) ) { foundList = true; } @@ -178,9 +207,9 @@ public class DefaultArchivaConfiguration } // escape all cron expressions to handle ',' - for ( Iterator i = configuration.getRepositories().iterator(); i.hasNext(); ) + for ( Iterator i = configuration.getManagedRepositories().iterator(); i.hasNext(); ) { - RepositoryConfiguration c = (RepositoryConfiguration) i.next(); + ManagedRepositoryConfiguration c = (ManagedRepositoryConfiguration) i.next(); c.setRefreshCronExpression( escapeCronExpression( c.getRefreshCronExpression() ) ); } @@ -289,10 +318,10 @@ public class DefaultArchivaConfiguration private Configuration processExpressions( Configuration config ) { // TODO: for commons-configuration 1.3 only - for ( Iterator i = config.getRepositories().iterator(); i.hasNext(); ) + for ( Iterator i = config.getManagedRepositories().iterator(); i.hasNext(); ) { - RepositoryConfiguration c = (RepositoryConfiguration) i.next(); - c.setUrl( removeExpressions( c.getUrl() ) ); + ManagedRepositoryConfiguration c = (ManagedRepositoryConfiguration) i.next(); + c.setLocation( removeExpressions( c.getLocation() ) ); c.setRefreshCronExpression( unescapeCronExpression( c.getRefreshCronExpression() ) ); } diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoader.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoader.java index a44911e5d..e174c7edb 100644 --- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoader.java +++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoader.java @@ -20,7 +20,6 @@ package org.apache.maven.archiva.configuration; */ import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.common.utils.PathUtil; import org.apache.maven.archiva.policies.ReleasesPolicy; import org.apache.maven.archiva.policies.SnapshotsPolicy; @@ -48,11 +47,14 @@ public class MavenProxyPropertyLoader // set up the managed repository String localCachePath = getMandatoryProperty( props, REPO_LOCAL_STORE ); - RepositoryConfiguration config = new RepositoryConfiguration(); - config.setUrl( PathUtil.toUrl( localCachePath ) ); + ManagedRepositoryConfiguration config = new ManagedRepositoryConfiguration(); + config.setLocation( localCachePath ); config.setName( "Imported Maven-Proxy Cache" ); config.setId( "maven-proxy" ); - configuration.addRepository( config ); + config.setIndexed( false ); + config.setReleases( true ); + config.setSnapshots( false ); + configuration.addManagedRepository( config ); // Add the network proxies. String propertyList = props.getProperty( PROXY_LIST ); @@ -91,26 +93,21 @@ public class MavenProxyPropertyLoader int cachePeriod = Integer.parseInt( repoProps.getProperty( "cache.period", "60" ) ); - RepositoryConfiguration repository = new RepositoryConfiguration(); + RemoteRepositoryConfiguration repository = new RemoteRepositoryConfiguration(); repository.setId( key ); repository.setName( "Imported Maven-Proxy Remote Proxy" ); repository.setUrl( url ); repository.setLayout( "legacy" ); - repository.setIndexed( false ); - repository.setReleases( true ); - repository.setSnapshots( false ); - configuration.addRepository( repository ); + configuration.addRemoteRepository( repository ); ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration(); proxyConnector.setSourceRepoId( "maven-proxy" ); proxyConnector.setTargetRepoId( key ); proxyConnector.setProxyId( proxyKey ); // TODO: convert cachePeriod to closest "daily" or "hourly" - proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, - SnapshotsPolicy.DAILY ); - proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, - ReleasesPolicy.IGNORED ); + proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, SnapshotsPolicy.DAILY ); + proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, ReleasesPolicy.IGNORED ); configuration.addProxyConnector( proxyConnector ); } diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/IndexedRepositoryPredicate.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/IndexedRepositoryPredicate.java deleted file mode 100644 index 8dadf9879..000000000 --- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/IndexedRepositoryPredicate.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.apache.maven.archiva.configuration.functors; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.collections.Predicate; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; - -/** - * Predicate for Repositories with their Indexed setting set to true. - * - * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> - * @version $Id$ - */ -public class IndexedRepositoryPredicate - implements Predicate -{ - private static IndexedRepositoryPredicate INSTANCE = new IndexedRepositoryPredicate(); - - public static IndexedRepositoryPredicate getInstance() - { - return INSTANCE; - } - - public boolean evaluate( Object object ) - { - boolean satisfies = false; - - if ( object instanceof RepositoryConfiguration ) - { - RepositoryConfiguration repoconfig = (RepositoryConfiguration) object; - return repoconfig.isIndexed(); - } - - return satisfies; - } -} diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/LocalRepositoryPredicate.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/LocalRepositoryPredicate.java deleted file mode 100644 index b81657abe..000000000 --- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/LocalRepositoryPredicate.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.apache.maven.archiva.configuration.functors; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.collections.Predicate; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; - -/** - * Predicate for {@link RepositoryConfiguration} objects that are local (aka managed) - * {@link RepositoryConfiguration#isManaged()} - * - * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> - * @version $Id$ - */ -public class LocalRepositoryPredicate - implements Predicate -{ - public static final Predicate INSTANCE = new LocalRepositoryPredicate(); - - public static Predicate getInstance() - { - return INSTANCE; - } - - public boolean evaluate( Object object ) - { - boolean satisfies = false; - - if ( object instanceof RepositoryConfiguration ) - { - RepositoryConfiguration repoconfig = (RepositoryConfiguration) object; - return repoconfig.isManaged(); - } - - return satisfies; - } - -} diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RemoteRepositoryPredicate.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RemoteRepositoryPredicate.java deleted file mode 100644 index a78d00826..000000000 --- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RemoteRepositoryPredicate.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.maven.archiva.configuration.functors; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.collections.Predicate; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; - -/** - * Predicate for {@link RepositoryConfiguration} objects that are remote - * {@link RepositoryConfiguration#isRemote()} - * - * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> - * @version $Id$ - */ -public class RemoteRepositoryPredicate - implements Predicate -{ - public static final Predicate INSTANCE = new RemoteRepositoryPredicate(); - - public static Predicate getInstance() - { - return INSTANCE; - } - - public boolean evaluate( Object object ) - { - boolean satisfies = false; - - if ( object instanceof RepositoryConfiguration ) - { - RepositoryConfiguration repoconfig = (RepositoryConfiguration) object; - return repoconfig.isRemote(); - } - - return satisfies; - } -} diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationComparator.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationComparator.java index 68fd13e0f..caf99d343 100644 --- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationComparator.java +++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationComparator.java @@ -19,45 +19,36 @@ package org.apache.maven.archiva.configuration.functors; * under the License. */ -import org.apache.maven.archiva.configuration.RepositoryConfiguration; +import org.apache.maven.archiva.configuration.AbstractRepositoryConfiguration; import java.util.Comparator; /** - * RepositoryConfigurationComparator + * RepositoryConfigurationComparator * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ */ public class RepositoryConfigurationComparator - implements Comparator + implements Comparator<AbstractRepositoryConfiguration> { - - public int compare( Object o1, Object o2 ) + public int compare( AbstractRepositoryConfiguration o1, AbstractRepositoryConfiguration o2 ) { if ( o1 == null && o2 == null ) { return 0; } - if ( o1 == null && o2 != null ) - { - return 1; - } - - if ( o1 != null && o2 == null ) + if ( o1 == null ) { return -1; } - if ( ( o1 instanceof RepositoryConfiguration ) && ( o2 instanceof RepositoryConfiguration ) ) + if ( o2 == null ) { - String id1 = ( (RepositoryConfiguration) o1 ).getId(); - String id2 = ( (RepositoryConfiguration) o2 ).getId(); - return id1.compareToIgnoreCase( id2 ); + return 1; } - return 0; + return o1.getId().compareToIgnoreCase( o2.getId() ); } - } diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationToMapClosure.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationToMapClosure.java deleted file mode 100644 index 40c1f8adc..000000000 --- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationToMapClosure.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.apache.maven.archiva.configuration.functors; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.collections.Closure; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; - -import java.util.HashMap; -import java.util.Map; - -/** - * RepositoryConfigurationToMapClosure - * - * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> - * @version $Id$ - */ -public class RepositoryConfigurationToMapClosure - implements Closure -{ - private Map map = new HashMap(); - - public void execute( Object input ) - { - if ( input instanceof RepositoryConfiguration ) - { - RepositoryConfiguration repo = (RepositoryConfiguration) input; - map.put( repo.getId(), repo ); - } - } - - public Map getMap() - { - return map; - } -} diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryIdListClosure.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryIdListClosure.java deleted file mode 100644 index a8ba49e43..000000000 --- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryIdListClosure.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.apache.maven.archiva.configuration.functors; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.collections.Closure; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; - -import java.util.List; - -/** - * RepositoryIdListClosure - * - * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> - * @version $Id$ - */ -public class RepositoryIdListClosure - implements Closure -{ - private List list; - - public RepositoryIdListClosure( List list ) - { - this.list = list; - } - - public void execute( Object input ) - { - if ( input instanceof RepositoryConfiguration ) - { - RepositoryConfiguration repoconfig = (RepositoryConfiguration) input; - list.add( repoconfig.getId() ); - } - } - - public List getList() - { - return list; - } -} diff --git a/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo index f2022addc..5ed67ddb0 100644 --- a/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo +++ b/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo @@ -43,14 +43,31 @@ </field>
<field>
<name>repositories</name>
+ <version>1.0.0</version>
+ <association>
+ <type>V1RepositoryConfiguration</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ <field>
+ <name>managedRepositories</name>
<version>1.0.0+</version>
<association>
- <type>RepositoryConfiguration</type>
+ <type>ManagedRepositoryConfiguration</type>
<multiplicity>*</multiplicity>
</association>
<description>The list of repositories that this archiva instance uses.</description>
</field>
<field>
+ <name>remoteRepositories</name>
+ <version>1.0.0+</version>
+ <association>
+ <type>RemoteRepositoryConfiguration</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ <description>The list of repositories that this archiva can retrieve from or publish to.</description>
+ </field>
+ <field>
<name>proxyConnectors</name>
<version>1.0.0+</version>
<association>
@@ -119,58 +136,78 @@ <codeSegment>
<version>1.0.0+</version>
<code><![CDATA[
- /**
- * Find {@link RepositoryConfiguration} with specified Id.
- *
- * @param id the id of the repository to find.
- * @return the repository configuration.
- */
- public RepositoryConfiguration findRepositoryById( String id )
+ public java.util.Map<String, NetworkProxyConfiguration> getNetworkProxiesAsMap()
{
- // null id = null repo config.
- if ( id == null )
+ java.util.Map<String, NetworkProxyConfiguration> map = new java.util.HashMap<String, NetworkProxyConfiguration>();
+ if ( networkProxies != null )
{
- return null;
+ for ( java.util.Iterator i = networkProxies.iterator(); i.hasNext(); )
+ {
+ NetworkProxyConfiguration proxy = (NetworkProxyConfiguration) i.next();
+ map.put( proxy.getId(), proxy );
+ }
}
+ return map;
+ }
- // empty id = null repo config.
- if ( id.trim().length() <= 0 )
+ public java.util.Map<String, RemoteRepositoryConfiguration> getRemoteRepositoriesAsMap()
+ {
+ java.util.Map<String, RemoteRepositoryConfiguration> map = new java.util.HashMap<String, RemoteRepositoryConfiguration>();
+ if ( remoteRepositories != null )
{
- return null;
+ for ( java.util.Iterator i = remoteRepositories.iterator(); i.hasNext(); )
+ {
+ RemoteRepositoryConfiguration repo = (RemoteRepositoryConfiguration) i.next();
+ map.put( repo.getId(), repo );
+ }
}
-
- return (RepositoryConfiguration) createRepositoryMap().get( id );
+ return map;
}
- /**
- * Create a RepositoryMap of the current repositories.
- *
- * @return the map of repository id's, to repository configurations.
- */
- public java.util.Map createRepositoryMap()
+ public RemoteRepositoryConfiguration findRemoteRepositoryById( String id )
{
- java.util.Map ret = new java.util.HashMap();
-
- // null repository list = null repo config.
- if ( getRepositories() == null )
+ if ( remoteRepositories != null )
{
- return ret;
+ for ( java.util.Iterator i = remoteRepositories.iterator(); i.hasNext(); )
+ {
+ RemoteRepositoryConfiguration repo = (RemoteRepositoryConfiguration) i.next();
+ if ( repo.getId().equals( id ) )
+ {
+ return repo;
+ }
+ }
}
+ return null;
+ }
- // empty repository list == null repo config.
- if ( getRepositories().isEmpty() )
+ public java.util.Map<String, ManagedRepositoryConfiguration> getManagedRepositoriesAsMap()
+ {
+ java.util.Map<String, ManagedRepositoryConfiguration> map = new java.util.HashMap<String, ManagedRepositoryConfiguration>();
+ if ( managedRepositories != null )
{
- return ret;
+ for ( java.util.Iterator i = managedRepositories.iterator(); i.hasNext(); )
+ {
+ ManagedRepositoryConfiguration repo = (ManagedRepositoryConfiguration) i.next();
+ map.put( repo.getId(), repo );
+ }
}
-
- java.util.Iterator it = getRepositories().iterator();
- while ( it.hasNext() )
+ return map;
+ }
+
+ public ManagedRepositoryConfiguration findManagedRepositoryById( String id )
+ {
+ if ( managedRepositories != null )
{
- RepositoryConfiguration repoConfig = (RepositoryConfiguration) it.next();
- ret.put( repoConfig.getId(), repoConfig );
+ for ( java.util.Iterator i = managedRepositories.iterator(); i.hasNext(); )
+ {
+ ManagedRepositoryConfiguration repo = (ManagedRepositoryConfiguration) i.next();
+ if ( repo.getId().equals( id ) )
+ {
+ return repo;
+ }
+ }
}
-
- return ret;
+ return null;
}
]]></code>
</codeSegment>
@@ -188,8 +225,9 @@ -->
<class>
- <name>RepositoryConfiguration</name>
+ <name>AbstractRepositoryConfiguration</name>
<version>1.0.0+</version>
+ <abstract>true</abstract>
<fields>
<field>
<name>id</name>
@@ -210,6 +248,24 @@ </description>
</field>
<field>
+ <name>layout</name>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The layout of the repository. Valid values are "default" and "legacy".
+ </description>
+ <!-- TODO: should be able to detect this from the repository (perhaps by metadata at the root) -->
+ <defaultValue>default</defaultValue>
+ </field>
+ </fields>
+ </class>
+ <class>
+ <name>RemoteRepositoryConfiguration</name>
+ <version>1.0.0+</version>
+ <superClass>AbstractRepositoryConfiguration</superClass>
+ <fields>
+ <field>
<name>url</name>
<version>1.0.0+</version>
<type>String</type>
@@ -218,16 +274,21 @@ The URL for this repository.
</description>
</field>
+ </fields>
+ </class>
+ <class>
+ <name>ManagedRepositoryConfiguration</name>
+ <version>1.0.0+</version>
+ <superClass>AbstractRepositoryConfiguration</superClass>
+ <fields>
<field>
- <name>layout</name>
+ <name>location</name>
<version>1.0.0+</version>
<type>String</type>
<required>true</required>
<description>
- The layout of the repository. Valid values are "default" and "legacy".
+ The file system location for this repository.
</description>
- <!-- TODO: should be able to detect this from the repository (perhaps by metadata at the root) -->
- <defaultValue>default</defaultValue>
</field>
<field>
<name>releases</name>
@@ -243,6 +304,7 @@ <description>True if this repository contains snapshot versioned artifacts.</description>
<defaultValue>false</defaultValue>
</field>
+ <!-- TODO! is indexed better named as scanned? check it's usages (or lack of usages) when iterating repos -->
<field>
<name>indexed</name>
<version>1.0.0+</version>
@@ -273,7 +335,7 @@ <version>1.0.0+</version>
<type>int</type>
<description>
- The total count of the artifact to be retained for each snapshot.
+ The total count of the artifact to be retained for each snapshot.
</description>
<defaultValue>2</defaultValue>
</field>
@@ -282,7 +344,7 @@ <version>1.0.0+</version>
<type>int</type>
<description>
- The number of days old which will be the basis for removing a snapshot.
+ The number of days old which will be the basis for removing a snapshot.
</description>
<defaultValue>100</defaultValue>
</field>
@@ -291,52 +353,27 @@ <version>1.0.0+</version>
<type>boolean</type>
<description>
- True if the released snapshots are to be removed from the repo during repository purge.
+ True if the released snapshots are to be removed from the repo during repository purge.
</description>
<defaultValue>false</defaultValue>
</field>
</fields>
- <codeSegments>
- <codeSegment>
+ </class>
+ <class>
+ <name>V1RepositoryConfiguration</name>
+ <version>1.0.0</version>
+ <superClass>ManagedRepositoryConfiguration</superClass>
+ <fields>
+ <field>
+ <name>url</name>
<version>1.0.0+</version>
- <code><![CDATA[
- /**
- * Utility method to help determine if configuration refers to a remote repository.
- *
- * @return true if configuration belongs to a remote repository.
- * (note: false does not automatically mean this is a managed repository,
- * you must use {@link #isManaged()} to test for that.)
- */
- public boolean isRemote()
- {
- if ( this.url == null )
- {
- return false;
- }
-
- return !this.url.startsWith( "file" );
- }
-
- /**
- * Utility method to help determine if configuration refers to a managed repository.
- *
- * @return true if configuration belongs to a managed repository.
- * (note: false does not automatically mean this is a remote repository,
- * you must use {@link #isRemote()} to test for that.)
- */
- public boolean isManaged()
- {
- if ( this.url == null )
- {
- return false;
- }
-
- return this.url.startsWith( "file" );
- }
-
- ]]></code>
- </codeSegment>
- </codeSegments>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The URL for this repository.
+ </description>
+ </field>
+ </fields>
</class>
<!--
diff --git a/archiva-base/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml b/archiva-base/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml index 8fd0669a5..6b5b2134d 100644 --- a/archiva-base/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml +++ b/archiva-base/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml @@ -1,48 +1,44 @@ <?xml version="1.0" encoding="UTF-8"?> <configuration> - <version>1</version> - <repositories> - <repository> + <version>2</version> + <managedRepositories> + <managedRepository> <id>internal</id> <name>Archiva Managed Internal Repository</name> - <url>file://${appserver.base}/data/repositories/internal</url> + <location>${appserver.base}/data/repositories/internal</location> <layout>default</layout> <releases>true</releases> <snapshots>false</snapshots> <indexed>true</indexed> <refreshCronExpression>0 0 0 * * ?</refreshCronExpression> <daysOlder>30</daysOlder> - </repository> - <repository> + </managedRepository> + <managedRepository> <id>snapshots</id> <name>Archiva Managed Snapshot Repository</name> - <url>file://${appserver.base}/data/repositories/snapshots</url> + <location>${appserver.base}/data/repositories/snapshots</location> <layout>default</layout> <releases>false</releases> <snapshots>true</snapshots> <indexed>true</indexed> <refreshCronExpression>0 0\,30 0 * * ?</refreshCronExpression> <daysOlder>30</daysOlder> - </repository> - <repository> + </managedRepository> + </managedRepositories> + <remoteRepositories> + <remoteRepository> <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> + </remoteRepository> + <remoteRepository> <id>maven2-repository.dev.java.net</id> <name>Java.net Repository for Maven 2</name> <url>http://download.java.net/maven/2/</url> <layout>default</layout> - <releases>true</releases> - <snapshots>false</snapshots> - <indexed>false</indexed> - </repository> - </repositories> + </remoteRepository> + </remoteRepositories> <proxyConnectors> <proxyConnector> diff --git a/archiva-base/archiva-configuration/src/test/conf/archiva-v1.xml b/archiva-base/archiva-configuration/src/test/conf/archiva-v1.xml new file mode 100644 index 000000000..3dd0281ae --- /dev/null +++ b/archiva-base/archiva-configuration/src/test/conf/archiva-v1.xml @@ -0,0 +1,191 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + +<configuration> + <repositories> + <repository> + <id>internal</id> + <name>Archiva Managed Internal Repository</name> + <url>file://${appserver.base}/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.base}/repositories/snapshots</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> + <whiteListPattern>javax/**</whiteListPattern> + </whiteListPatterns> + </proxyConnector> + </proxyConnectors> + + <networkProxies> + <networkProxy> + <id>example</id> + <protocol>http</protocol> + <host>proxy.mycompany.com</host> + <port>8080</port> + <username>myself</username> + <password>mypass</password> + </networkProxy> + </networkProxies> + + <repositoryScanning> + <fileTypes> + <fileType> + <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> + </fileType> + <fileType> + <id>indexable-content</id> + <patterns> + <pattern>**/*.txt</pattern> + <pattern>**/*.TXT</pattern> + <pattern>**/*.block</pattern> + <pattern>**/*.config</pattern> + <pattern>**/*.pom</pattern> + <pattern>**/*.xml</pattern> + <pattern>**/*.xsd</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + </patterns> + </fileType> + <fileType> + <id>auto-remove</id> + <patterns> + <pattern>**/*.bak</pattern> + <pattern>**/*~</pattern> + <pattern>**/*-</pattern> + </patterns> + </fileType> + <fileType> + <id>ignored</id> + <patterns> + <pattern>**/.htaccess</pattern> + <pattern>**/KEYS</pattern> + <pattern>**/*.rb</pattern> + <pattern>**/*.sh</pattern> + <pattern>**/.svn/**</pattern> + <pattern>**/.DAV/**</pattern> + </patterns> + </fileType> + </fileTypes> + <knownContentConsumers> + <knownContentConsumer>update-db-artifact</knownContentConsumer> + <knownContentConsumer>create-missing-checksums</knownContentConsumer> + <knownContentConsumer>update-db-repository-metadata</knownContentConsumer> + <knownContentConsumer>validate-checksum</knownContentConsumer> + <knownContentConsumer>validate-signature</knownContentConsumer> + <knownContentConsumer>index-content</knownContentConsumer> + <knownContentConsumer>auto-remove</knownContentConsumer> + <knownContentConsumer>auto-rename</knownContentConsumer> + <knownContentConsumer>metadata-updater</knownContentConsumer> + <!--knownContentConsumer>repository-purge</knownContentConsumer--> + </knownContentConsumers> + <invalidContentConsumers> + <invalidContentConsumer>update-db-bad-content</invalidContentConsumer> + </invalidContentConsumers> + </repositoryScanning> + + <databaseScanning> + <cronExpression>0 0 * * ?</cronExpression> + <unprocessedConsumers> + <unprocessedConsumer>index-artifact</unprocessedConsumer> + <unprocessedConsumer>update-db-project</unprocessedConsumer> + <unprocessedConsumer>validate-repository-metadata</unprocessedConsumer> + <unprocessedConsumer>index-archive-toc</unprocessedConsumer> + <unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer> + <unprocessedConsumer>index-public-methods</unprocessedConsumer> + </unprocessedConsumers> + <cleanupConsumers> + <cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer> + <cleanupConsumer>not-present-remove-db-project</cleanupConsumer> + <cleanupConsumer>not-present-remove-indexed</cleanupConsumer> + </cleanupConsumers> + </databaseScanning> + + <webapp> + <ui> + <showFindArtifacts>true</showFindArtifacts> + <appletFindEnabled>true</appletFindEnabled> + </ui> + </webapp> + +</configuration> diff --git a/archiva-base/archiva-configuration/src/test/conf/autodetect-v1.xml b/archiva-base/archiva-configuration/src/test/conf/autodetect-v1.xml index 7a50c699e..ab4417eb2 100644 --- a/archiva-base/archiva-configuration/src/test/conf/autodetect-v1.xml +++ b/archiva-base/archiva-configuration/src/test/conf/autodetect-v1.xml @@ -33,7 +33,7 @@ <repository> <id>snapshots</id> <name>Archiva Managed Snapshot Repository</name> - <url>file://${appserver.base}/repositories/internal</url> + <url>file:${appserver.base}/repositories/snapshots</url> <layout>default</layout> <releases>false</releases> <snapshots>true</snapshots> diff --git a/archiva-base/archiva-configuration/src/test/conf/conf-base.xml b/archiva-base/archiva-configuration/src/test/conf/conf-base.xml index c3dba42b8..4e96ccc0d 100644 --- a/archiva-base/archiva-configuration/src/test/conf/conf-base.xml +++ b/archiva-base/archiva-configuration/src/test/conf/conf-base.xml @@ -19,47 +19,43 @@ --> <configuration> - <version>1</version> - <repositories> - <repository> + <version>2</version> + <managedRepositories> + <managedRepository> <id>internal</id> <name>Archiva Managed Internal Repository</name> - <url>file://${appserver.base}/repositories/internal</url> + <location>${appserver.base}/repositories/internal</location> <layout>default</layout> <releases>true</releases> <snapshots>false</snapshots> <indexed>true</indexed> <refreshCronExpression>0 0 * * ?</refreshCronExpression> - </repository> - <repository> + </managedRepository> + <managedRepository> <id>snapshots</id> <name>Archiva Managed Snapshot Repository</name> - <url>file://${appserver.base}/repositories/internal</url> + <location>${appserver.base}/repositories/snapshots</location> <layout>default</layout> <releases>false</releases> <snapshots>true</snapshots> <indexed>true</indexed> <refreshCronExpression>0 0,30 * * ?</refreshCronExpression> - </repository> - <repository> + </managedRepository> + </managedRepositories> + <remoteRepositories> + <remoteRepository> <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> + </remoteRepository> + <remoteRepository> <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> + </remoteRepository> + </remoteRepositories> <webapp> <ui> diff --git a/archiva-base/archiva-configuration/src/test/conf/conf-user.xml b/archiva-base/archiva-configuration/src/test/conf/conf-user.xml index bceb96d8e..61c4dadc2 100644 --- a/archiva-base/archiva-configuration/src/test/conf/conf-user.xml +++ b/archiva-base/archiva-configuration/src/test/conf/conf-user.xml @@ -18,7 +18,7 @@ ~ under the License. --> <configuration> - <version>1</version> + <version>2</version> <proxyConnectors> <proxyConnector> <sourceRepoId>internal</sourceRepoId> diff --git a/archiva-base/archiva-configuration/src/test/conf/escape-cron-expressions.xml b/archiva-base/archiva-configuration/src/test/conf/escape-cron-expressions.xml index 56868a951..48de2878d 100644 --- a/archiva-base/archiva-configuration/src/test/conf/escape-cron-expressions.xml +++ b/archiva-base/archiva-configuration/src/test/conf/escape-cron-expressions.xml @@ -18,17 +18,17 @@ ~ under the License. --> <configuration> - <version>1</version> - <repositories> - <repository> + <version>2</version> + <managedRepositories> + <managedRepository> <id>snapshots</id> <name>Archiva Managed Snapshot Repository</name> - <url>file://${appserver.base}/repositories/internal</url> + <location>file://${appserver.base}/repositories/internal</location> <releases>false</releases> <snapshots>true</snapshots> <refreshCronExpression>0 0\,30 * * ?</refreshCronExpression> - </repository> - </repositories> + </managedRepository> + </managedRepositories> <databaseScanning> <cronExpression>0 0 0 * * ?</cronExpression> <unprocessedConsumers> diff --git a/archiva-base/archiva-configuration/src/test/conf/repository-manager.xml b/archiva-base/archiva-configuration/src/test/conf/repository-manager.xml index f5dd079f5..06a881c1b 100644 --- a/archiva-base/archiva-configuration/src/test/conf/repository-manager.xml +++ b/archiva-base/archiva-configuration/src/test/conf/repository-manager.xml @@ -19,47 +19,43 @@ --> <configuration> - <version>1</version> - <repositories> - <repository> + <version>2</version> + <managedRepositories> + <managedRepository> <id>internal</id> <name>Archiva Managed Internal Repository</name> - <url>file://${appserver.base}/repositories/internal</url> + <location>${appserver.base}/repositories/internal</location> <layout>default</layout> <releases>true</releases> <snapshots>false</snapshots> <indexed>true</indexed> <refreshCronExpression>0 0 * * ?</refreshCronExpression> - </repository> - <repository> + </managedRepository> + <managedRepository> <id>snapshots</id> <name>Archiva Managed Snapshot Repository</name> - <url>file://${appserver.base}/repositories/internal</url> + <location>${appserver.base}/repositories/internal</location> <layout>default</layout> <releases>false</releases> <snapshots>true</snapshots> <indexed>true</indexed> <refreshCronExpression>0 0,30 * * ?</refreshCronExpression> - </repository> - <repository> + </managedRepository> + </managedRepositories> + <remoteRepositories> + <remoteRepository> <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> + </remoteRepository> + <remoteRepository> <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> + </remoteRepository> + </remoteRepositories> <proxyConnectors> <proxyConnector> diff --git a/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java index d37ae51ef..f7708409f 100644 --- a/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java +++ b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java @@ -28,6 +28,7 @@ import org.easymock.MockControl; import java.io.File; import java.util.List; +import java.util.Map; /** * Test the configuration store. @@ -57,11 +58,11 @@ public class ArchivaConfigurationTest assertConfiguration( configuration ); assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() ); - RepositoryConfiguration repository = - (RepositoryConfiguration) configuration.getRepositories().iterator().next(); + ManagedRepositoryConfiguration repository = + (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 ); - assertEquals( "check managed repositories", "file://${appserver.base}/repositories/internal", - repository.getUrl() ); + assertEquals( "check managed repositories", "${appserver.base}/repositories/internal", + repository.getLocation() ); assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() ); assertEquals( "check managed repositories", "internal", repository.getId() ); assertEquals( "check managed repositories", "default", repository.getLayout() ); @@ -78,11 +79,11 @@ public class ArchivaConfigurationTest assertConfiguration( configuration ); assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() ); - RepositoryConfiguration repository = - (RepositoryConfiguration) configuration.getRepositories().iterator().next(); + ManagedRepositoryConfiguration repository = + (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 ); - assertEquals( "check managed repositories", "file://${appserver.base}/data/repositories/internal", - repository.getUrl() ); + assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal", + repository.getLocation() ); assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() ); assertEquals( "check managed repositories", "internal", repository.getId() ); assertEquals( "check managed repositories", "default", repository.getLayout() ); @@ -97,7 +98,8 @@ public class ArchivaConfigurationTest { FileTypes filetypes = (FileTypes) lookup( FileTypes.class.getName() ); - assertEquals( "check repositories", 4, configuration.getRepositories().size() ); + assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() ); + assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() ); assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() ); RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning(); @@ -133,7 +135,8 @@ public class ArchivaConfigurationTest Configuration configuration = archivaConfiguration.getConfiguration(); // from base - assertEquals( "check repositories", 4, configuration.getRepositories().size() ); + assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() ); + assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() ); // from user assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() ); @@ -478,11 +481,11 @@ public class ArchivaConfigurationTest assertConfiguration( configuration ); assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() ); - RepositoryConfiguration repository = - (RepositoryConfiguration) configuration.getRepositories().iterator().next(); + ManagedRepositoryConfiguration repository = + (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 ); - assertEquals( "check managed repositories", "file://${appserver.base}/data/repositories/internal", - repository.getUrl() ); + assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal", + repository.getLocation() ); assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() ); assertEquals( "check managed repositories", "internal", repository.getId() ); assertEquals( "check managed repositories", "default", repository.getLayout() ); @@ -499,17 +502,50 @@ public class ArchivaConfigurationTest assertConfiguration( configuration ); assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() ); - RepositoryConfiguration repository = - (RepositoryConfiguration) configuration.getRepositories().iterator().next(); + ManagedRepositoryConfiguration repository = + (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 ); - assertEquals( "check managed repositories", "file://${appserver.base}/repositories/internal", - repository.getUrl() ); + assertEquals( "check managed repositories", "${appserver.base}/repositories/internal", + repository.getLocation() ); 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() ); } + public void testArchivaV1() + throws Exception + { + ArchivaConfiguration archivaConfiguration = + (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-archiva-v1" ); + + Configuration configuration = archivaConfiguration.getConfiguration(); + assertConfiguration( configuration ); + assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() ); + + assertEquals( "check managed repositories", 2, configuration.getManagedRepositories().size() ); + + Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap(); + + ManagedRepositoryConfiguration repository = map.get( "internal" ); + assertEquals( "check managed repositories", "${appserver.base}/repositories/internal", + repository.getLocation() ); + 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() ); + assertFalse( "check managed repositories", repository.isSnapshots() ); + + repository = map.get( "snapshots" ); + assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots", + repository.getLocation() ); + assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName() ); + assertEquals( "check managed repositories", "snapshots", repository.getId() ); + assertEquals( "check managed repositories", "default", repository.getLayout() ); + assertTrue( "check managed repositories", repository.isIndexed() ); + assertTrue( "check managed repositories", repository.isSnapshots() ); + } + public void testCronExpressionsWithComma() throws Exception { @@ -530,12 +566,12 @@ public class ArchivaConfigurationTest ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-cron-expressions" ); - Configuration configuration = archivaConfiguration.getConfiguration(); - - RepositoryConfiguration repository = - (RepositoryConfiguration) configuration.getRepositories().iterator().next(); + Configuration configuration = archivaConfiguration.getConfiguration(); - assertEquals( "check cron expression", "0 0,30 * * ?", repository.getRefreshCronExpression() ); + ManagedRepositoryConfiguration repository = + (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 ); + + assertEquals( "check cron expression", "0 0,30 * * ?", repository.getRefreshCronExpression().trim() ); configuration.getDatabaseScanning().setCronExpression( "0 0,15 0 * * ?" ); @@ -544,17 +580,15 @@ public class ArchivaConfigurationTest configuration = archivaConfiguration.getConfiguration(); assertEquals( "check cron expression", "0 0,15 0 * * ?", - configuration.getDatabaseScanning().getCronExpression() ); + configuration.getDatabaseScanning().getCronExpression() ); // test for the escape character '\' showing up on repositories.jsp repository.setRefreshCronExpression( "0 0,20 0 * * ?" ); archivaConfiguration.save( configuration ); - repository = archivaConfiguration.getConfiguration().findRepositoryById( "snapshots" ); + repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" ); assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() ); - } - } diff --git a/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ConfigurationTest.java b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ConfigurationTest.java new file mode 100644 index 000000000..c242bcb8b --- /dev/null +++ b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ConfigurationTest.java @@ -0,0 +1,144 @@ +package org.apache.maven.archiva.configuration; + +import junit.framework.TestCase; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Test the generated Configuration class from Modello. This is primarily to test the hand coded methods. + */ +public class ConfigurationTest + extends TestCase +{ + private Configuration configuration = new Configuration(); + + public void testNetworkProxyRetrieval() + { + NetworkProxyConfiguration proxy1 = createNetworkProxy( "id1", "host1", 8080 ); + configuration.addNetworkProxy( proxy1 ); + NetworkProxyConfiguration proxy2 = createNetworkProxy( "id2", "host2", 9090 ); + configuration.addNetworkProxy( proxy2 ); + + Map<String, NetworkProxyConfiguration> map = configuration.getNetworkProxiesAsMap(); + assertNotNull( map ); + assertEquals( 2, map.size() ); + assertEquals( new HashSet<String>( Arrays.asList( "id1", "id2" ) ), map.keySet() ); + assertEquals( new HashSet<NetworkProxyConfiguration>( Arrays.asList( proxy1, proxy2 ) ), + new HashSet<NetworkProxyConfiguration>( map.values() ) ); + } + + private NetworkProxyConfiguration createNetworkProxy( String id, String host, int port ) + { + NetworkProxyConfiguration proxy = new NetworkProxyConfiguration(); + proxy.setId( id ); + proxy.setHost( host ); + proxy.setPort( port ); + proxy.setProtocol( "http" ); + return proxy; + } + + public void testRemoteRepositoryRetrieval() + { + RemoteRepositoryConfiguration repo1 = createRemoteRepository( "id1", "name 1", "url 1" ); + configuration.addRemoteRepository( repo1 ); + RemoteRepositoryConfiguration repo2 = createRemoteRepository( "id2", "name 2", "url 2" ); + configuration.addRemoteRepository( repo2 ); + + Map<String, RemoteRepositoryConfiguration> map = configuration.getRemoteRepositoriesAsMap(); + assertNotNull( map ); + assertEquals( 2, map.size() ); + assertEquals( new HashSet<String>( Arrays.asList( "id1", "id2" ) ), map.keySet() ); + assertEquals( new HashSet<RemoteRepositoryConfiguration>( Arrays.asList( repo1, repo2 ) ), + new HashSet<RemoteRepositoryConfiguration>( map.values() ) ); + + assertEquals( repo1, configuration.findRemoteRepositoryById( "id1" ) ); + assertEquals( repo2, configuration.findRemoteRepositoryById( "id2" ) ); + assertNull( configuration.findRemoteRepositoryById( "id3" ) ); + } + + private RemoteRepositoryConfiguration createRemoteRepository( String id, String name, String url ) + { + RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration(); + repo.setId( id ); + repo.setName( name ); + repo.setLayout( "default" ); + repo.setUrl( url ); + return repo; + } + + public void testManagedRepositoryRetrieval() + { + ManagedRepositoryConfiguration repo1 = createManagedRepository( "id1", "name 1", "path 1", false ); + configuration.addManagedRepository( repo1 ); + ManagedRepositoryConfiguration repo2 = createManagedRepository( "id2", "name 2", "path 2", true ); + configuration.addManagedRepository( repo2 ); + + Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap(); + assertNotNull( map ); + assertEquals( 2, map.size() ); + assertEquals( new HashSet<String>( Arrays.asList( "id1", "id2" ) ), map.keySet() ); + assertEquals( new HashSet<ManagedRepositoryConfiguration>( Arrays.asList( repo1, repo2 ) ), + new HashSet<ManagedRepositoryConfiguration>( map.values() ) ); + + assertEquals( repo1, configuration.findManagedRepositoryById( "id1" ) ); + assertEquals( repo2, configuration.findManagedRepositoryById( "id2" ) ); + assertNull( configuration.findManagedRepositoryById( "id3" ) ); + } + + private ManagedRepositoryConfiguration createManagedRepository( String id, String name, String location, + boolean indexed ) + { + ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration(); + repo.setId( id ); + repo.setName( name ); + repo.setLocation( location ); + repo.setIndexed( indexed ); + return repo; + } + + public void testNetworkProxyRetrievalWhenEmpty() + { + Map<String, NetworkProxyConfiguration> map = configuration.getNetworkProxiesAsMap(); + assertNotNull( map ); + assertTrue( map.isEmpty() ); + } + + public void testRemoteRepositoryRetrievalWhenEmpty() + { + Map<String, RemoteRepositoryConfiguration> map = configuration.getRemoteRepositoriesAsMap(); + assertNotNull( map ); + assertTrue( map.isEmpty() ); + + assertNull( configuration.findRemoteRepositoryById( "id" ) ); + } + + public void testManagedRepositoryRetrievalWhenEmpty() + { + Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap(); + assertNotNull( map ); + assertTrue( map.isEmpty() ); + + assertNull( configuration.findManagedRepositoryById( "id" ) ); + } +} diff --git a/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java index 8d1d3909c..db3049277 100644 --- a/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java +++ b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoaderTest.java @@ -24,20 +24,19 @@ 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 MavenProxyPropertyLoader loader; - public void testLoadValidMavenProxyConfiguration() throws IOException, InvalidConfigurationException + public void testLoadValidMavenProxyConfiguration() + throws IOException, InvalidConfigurationException { File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" ); @@ -48,27 +47,30 @@ public class MavenProxyPropertyLoaderTest extends PlexusTestCase loader.load( new FileInputStream( confFile ), configuration ); - List repos = configuration.getRepositories(); - assertEquals( "Count repositories", 5, repos.size() ); + Map<String, ManagedRepositoryConfiguration> repositoryIdMap = configuration.getManagedRepositoriesAsMap(); + assertEquals( "Count repositories", 1, repositoryIdMap.size() ); + assertRepositoryExists( "maven-proxy", "target", repositoryIdMap.get( "maven-proxy" ) ); - Map repositoryIdMap = new HashMap(); - - for ( Iterator itRepo = repos.iterator(); itRepo.hasNext(); ) - { - RepositoryConfiguration repo = (RepositoryConfiguration) itRepo.next(); - repositoryIdMap.put( repo.getId(), repo ); - } - - assertRepositoryExists( repositoryIdMap, "local-repo", "file://target" ); + Map<String, RemoteRepositoryConfiguration> remoteRepositoryMap = configuration.getRemoteRepositoriesAsMap(); + assertEquals( "Count repositories", 4, remoteRepositoryMap.size() ); + assertRepositoryExists( "local-repo", "file://target", remoteRepositoryMap.get( "local-repo" ) ); + assertRepositoryExists( "www-ibiblio-org", "http://www.ibiblio.org/maven2", + remoteRepositoryMap.get( "www-ibiblio-org" ) ); + assertRepositoryExists( "dist-codehaus-org", "http://dist.codehaus.org", + remoteRepositoryMap.get( "dist-codehaus-org" ) ); + assertRepositoryExists( "private-example-com", "http://private.example.com/internal", + remoteRepositoryMap.get( "private-example-com" ) ); + } - 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" ); + private void assertRepositoryExists( String id, String expectedLocation, ManagedRepositoryConfiguration repo ) + { + assertNotNull( "Repository id [" + id + "] should not be null", repo ); + assertEquals( "Repository id", id, repo.getId() ); + assertEquals( "Repository url", expectedLocation, repo.getLocation() ); } - private void assertRepositoryExists( Map repoMap, String id, String expectedUrl ) + private void assertRepositoryExists( String id, String expectedUrl, RemoteRepositoryConfiguration repo ) { - 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() ); @@ -88,7 +90,8 @@ public class MavenProxyPropertyLoaderTest extends PlexusTestCase } } - protected void setUp() throws Exception + protected void setUp() + throws Exception { super.setUp(); loader = new MavenProxyPropertyLoader(); diff --git a/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationComparatorTest.java b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationComparatorTest.java new file mode 100644 index 000000000..bfce66756 --- /dev/null +++ b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationComparatorTest.java @@ -0,0 +1,52 @@ +package org.apache.maven.archiva.configuration.functors; + +import junit.framework.TestCase; +import org.apache.maven.archiva.configuration.AbstractRepositoryConfiguration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; + +import java.util.Comparator; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Test the repositry comparator. + */ +public class RepositoryConfigurationComparatorTest + extends TestCase +{ + public void testComparator() + { + Comparator<AbstractRepositoryConfiguration> comparator = new RepositoryConfigurationComparator(); + + assertEquals( 0, comparator.compare( null, null ) ); + assertEquals( 1, comparator.compare( createRepository( "id" ), null ) ); + assertEquals( -1, comparator.compare( null, createRepository( "id" ) ) ); + assertEquals( 0, comparator.compare( createRepository( "id1" ), createRepository( "id1" ) ) ); + assertEquals( -1, comparator.compare( createRepository( "id1" ), createRepository( "id2" ) ) ); + assertEquals( 1, comparator.compare( createRepository( "id2" ), createRepository( "id1" ) ) ); + } + + private ManagedRepositoryConfiguration createRepository( String id ) + { + ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration(); + repo.setId( id ); + return repo; + } +} diff --git a/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml b/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml index ce70c03bc..b4415af3a 100644 --- a/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml +++ b/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml @@ -112,6 +112,30 @@ <component> <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> + <role-hint>test-archiva-v1</role-hint> + <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation> + <requirements> + <requirement> + <role>org.codehaus.plexus.registry.Registry</role> + <role-hint>archiva-v1</role-hint> + </requirement> + </requirements> + </component> + <component> + <role>org.codehaus.plexus.registry.Registry</role> + <role-hint>archiva-v1</role-hint> + <implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation> + <configuration> + <properties> + <system/> + <xml fileName="${basedir}/src/test/conf/archiva-v1.xml" + config-name="org.apache.maven.archiva" config-at="org.apache.maven.archiva"/> + </properties> + </configuration> + </component> + + <component> + <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> <role-hint>test-save</role-hint> <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation> <requirements> @@ -236,6 +260,6 @@ config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/> </properties> </configuration> - </component> + </component> </components> </component-set> diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java index 9ec52b8f7..25114f1fb 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java @@ -46,10 +46,11 @@ import java.util.Map; * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" - * role-hint="create-missing-checksums" - * instantiation-strategy="per-lookup" + * role-hint="create-missing-checksums" + * instantiation-strategy="per-lookup" */ -public class ArtifactMissingChecksumsConsumer extends AbstractMonitoredConsumer +public class ArtifactMissingChecksumsConsumer + extends AbstractMonitoredConsumer implements KnownRepositoryContentConsumer, RegistryListener, Initializable { /** @@ -66,7 +67,7 @@ public class ArtifactMissingChecksumsConsumer extends AbstractMonitoredConsumer * @plexus.requirement */ private ArchivaConfiguration configuration; - + /** * @plexus.requirement */ @@ -123,22 +124,18 @@ public class ArtifactMissingChecksumsConsumer extends AbstractMonitoredConsumer return false; } - public void beginScan( ArchivaRepository repository ) throws ConsumerException + public void beginScan( ArchivaRepository repository ) + throws ConsumerException { - if ( !repository.isManaged() ) - { - throw new ConsumerException( "Consumer requires managed repository." ); - } - this.repository = repository; this.repositoryDir = new File( repository.getUrl().getPath() ); String layoutName = repository.getModel().getLayoutName(); if ( !bidirectionalLayoutMap.containsKey( layoutName ) ) { - throw new ConsumerException( "Unable to process repository with layout [" + layoutName - + "] as there is no corresponding " + BidirectionalRepositoryLayout.class.getName() - + " implementation available." ); + throw new ConsumerException( "Unable to process repository with layout [" + layoutName + + "] as there is no corresponding " + BidirectionalRepositoryLayout.class.getName() + + " implementation available." ); } this.layout = (BidirectionalRepositoryLayout) bidirectionalLayoutMap.get( layoutName ); @@ -159,7 +156,8 @@ public class ArtifactMissingChecksumsConsumer extends AbstractMonitoredConsumer return includes; } - public void processFile( String path ) throws ConsumerException + public void processFile( String path ) + throws ConsumerException { createIfMissing( path, digestSha1 ); createIfMissing( path, digestMd5 ); @@ -177,19 +175,19 @@ public class ArtifactMissingChecksumsConsumer extends AbstractMonitoredConsumer } catch ( DigesterException e ) { - triggerConsumerError( TYPE_CHECKSUM_CANNOT_CALC, "Cannot calculate checksum for file " + checksumFile - + ": " + e.getMessage() ); + triggerConsumerError( TYPE_CHECKSUM_CANNOT_CALC, + "Cannot calculate checksum for file " + checksumFile + ": " + e.getMessage() ); } catch ( IOException e ) { - triggerConsumerError( TYPE_CHECKSUM_CANNOT_CREATE, "Cannot create checksum for file " + checksumFile - + ": " + e.getMessage() ); + triggerConsumerError( TYPE_CHECKSUM_CANNOT_CREATE, + "Cannot create checksum for file " + checksumFile + ": " + e.getMessage() ); } } else if ( !checksumFile.isFile() ) { - triggerConsumerWarning( TYPE_CHECKSUM_NOT_FILE, "Checksum file " + checksumFile.getAbsolutePath() - + " is not a file." ); + triggerConsumerWarning( TYPE_CHECKSUM_NOT_FILE, + "Checksum file " + checksumFile.getAbsolutePath() + " is not a file." ); } } @@ -210,11 +208,12 @@ public class ArtifactMissingChecksumsConsumer extends AbstractMonitoredConsumer private void initIncludes() { includes.clear(); - + includes.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) ); } - public void initialize() throws InitializationException + public void initialize() + throws InitializationException { propertyNameTriggers = new ArrayList(); propertyNameTriggers.add( "repositoryScanning" ); diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRemoveConsumer.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRemoveConsumer.java index 790a13444..d93d4f7b1 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRemoveConsumer.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRemoveConsumer.java @@ -35,14 +35,13 @@ import java.util.ArrayList; import java.util.List; /** - * AutoRemoveConsumer + * AutoRemoveConsumer * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ - * * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" - * role-hint="auto-remove" - * instantiation-strategy="per-lookup" + * role-hint="auto-remove" + * instantiation-strategy="per-lookup" */ public class AutoRemoveConsumer extends AbstractMonitoredConsumer @@ -62,7 +61,7 @@ public class AutoRemoveConsumer * @plexus.requirement */ private ArchivaConfiguration configuration; - + /** * @plexus.requirement */ @@ -92,11 +91,6 @@ public class AutoRemoveConsumer public void beginScan( ArchivaRepository repository ) throws ConsumerException { - if ( !repository.isManaged() ) - { - throw new ConsumerException( "Consumer requires managed repository." ); - } - this.repositoryDir = new File( repository.getUrl().getPath() ); } @@ -142,7 +136,7 @@ public class AutoRemoveConsumer private void initIncludes() { includes.clear(); - + includes.addAll( filetypes.getFileTypePatterns( FileTypes.AUTO_REMOVE ) ); } diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRenameConsumer.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRenameConsumer.java index 004e382e7..152461017 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRenameConsumer.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRenameConsumer.java @@ -22,7 +22,6 @@ package org.apache.maven.archiva.consumers.core; import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; import org.apache.maven.archiva.consumers.ConsumerException; import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.RepositoryContentConsumer; import org.apache.maven.archiva.model.ArchivaRepository; import org.codehaus.plexus.util.FileUtils; @@ -35,14 +34,13 @@ import java.util.List; import java.util.Map; /** - * AutoRenameConsumer + * AutoRenameConsumer * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ - * * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" - * role-hint="auto-rename" - * instantiation-strategy="per-lookup" + * role-hint="auto-rename" + * instantiation-strategy="per-lookup" */ public class AutoRenameConsumer extends AbstractMonitoredConsumer @@ -95,11 +93,6 @@ public class AutoRenameConsumer public void beginScan( ArchivaRepository repository ) throws ConsumerException { - if ( !repository.isManaged() ) - { - throw new ConsumerException( "Consumer requires managed repository." ); - } - this.repositoryDir = new File( repository.getUrl().getPath() ); } @@ -139,8 +132,8 @@ public class AutoRenameConsumer } catch ( IOException e ) { - triggerConsumerWarning( RENAME_FAILURE, "Unable to rename " + path + " to " + correctedPath - + ": " + e.getMessage() ); + triggerConsumerWarning( RENAME_FAILURE, "Unable to rename " + path + " to " + correctedPath + + ": " + e.getMessage() ); } } } diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/MetadataUpdaterConsumer.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/MetadataUpdaterConsumer.java index 10410cf4e..fd1dd2bcb 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/MetadataUpdaterConsumer.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/MetadataUpdaterConsumer.java @@ -49,10 +49,9 @@ import java.util.List; * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ - * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" - * role-hint="metadata-updater" - * instantiation-strategy="per-lookup" + * role-hint="metadata-updater" + * instantiation-strategy="per-lookup" */ public class MetadataUpdaterConsumer extends AbstractMonitoredConsumer @@ -122,11 +121,6 @@ public class MetadataUpdaterConsumer public void beginScan( ArchivaRepository repository ) throws ConsumerException { - if ( !repository.isManaged() ) - { - throw new ConsumerException( "Consumer requires managed repository." ); - } - this.repository = repository; this.repositoryDir = new File( repository.getUrl().getPath() ); try @@ -135,8 +129,9 @@ public class MetadataUpdaterConsumer } catch ( LayoutException e ) { - throw new ConsumerException( "Cannot operate with bad layout definition on repo [" + repository.getId() - + "]: " + e.getMessage(), e ); + throw new ConsumerException( + "Cannot operate with bad layout definition on repo [" + repository.getId() + "]: " + e.getMessage(), + e ); } this.scanStartTimestamp = System.currentTimeMillis(); } @@ -195,18 +190,18 @@ public class MetadataUpdaterConsumer } catch ( LayoutException e ) { - triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF, "Unable to convert path [" + path - + "] to an internal project reference: " + e.getMessage() ); + triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF, "Unable to convert path [" + path + + "] to an internal project reference: " + e.getMessage() ); } catch ( RepositoryMetadataException e ) { - triggerConsumerError( TYPE_METADATA_WRITE_FAILURE, "Unable to write project metadata for artifact [" + path - + "]: " + e.getMessage() ); + triggerConsumerError( TYPE_METADATA_WRITE_FAILURE, + "Unable to write project metadata for artifact [" + path + "]: " + e.getMessage() ); } catch ( IOException e ) { - triggerConsumerWarning( TYPE_METADATA_IO, "Project metadata not written due to IO warning: " - + e.getMessage() ); + triggerConsumerWarning( TYPE_METADATA_IO, + "Project metadata not written due to IO warning: " + e.getMessage() ); } } @@ -235,18 +230,18 @@ public class MetadataUpdaterConsumer } catch ( LayoutException e ) { - triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF, "Unable to convert path [" + path - + "] to an internal version reference: " + e.getMessage() ); + triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF, "Unable to convert path [" + path + + "] to an internal version reference: " + e.getMessage() ); } catch ( RepositoryMetadataException e ) { - triggerConsumerError( TYPE_METADATA_WRITE_FAILURE, "Unable to write version metadata for artifact [" + path - + "]: " + e.getMessage() ); + triggerConsumerError( TYPE_METADATA_WRITE_FAILURE, + "Unable to write version metadata for artifact [" + path + "]: " + e.getMessage() ); } catch ( IOException e ) { - triggerConsumerWarning( TYPE_METADATA_IO, "Version metadata not written due to IO warning: " - + e.getMessage() ); + triggerConsumerWarning( TYPE_METADATA_IO, + "Version metadata not written due to IO warning: " + e.getMessage() ); } } diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ValidateChecksumConsumer.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ValidateChecksumConsumer.java index 4a48f87b8..81272565a 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ValidateChecksumConsumer.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ValidateChecksumConsumer.java @@ -22,7 +22,6 @@ package org.apache.maven.archiva.consumers.core; import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; import org.apache.maven.archiva.consumers.ConsumerException; import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.RepositoryContentConsumer; import org.apache.maven.archiva.model.ArchivaRepository; import org.codehaus.plexus.digest.ChecksumFile; import org.codehaus.plexus.digest.Digester; @@ -38,16 +37,16 @@ import java.util.Iterator; import java.util.List; /** - * ValidateChecksumConsumer - validate the provided checksum against the file it represents. + * ValidateChecksumConsumer - validate the provided checksum against the file it represents. * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ - * * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" - * role-hint="validate-checksum" - * instantiation-strategy="per-lookup" + * role-hint="validate-checksum" + * instantiation-strategy="per-lookup" */ -public class ValidateChecksumConsumer extends AbstractMonitoredConsumer +public class ValidateChecksumConsumer + extends AbstractMonitoredConsumer implements KnownRepositoryContentConsumer, Initializable { private static final String NOT_VALID_CHECKSUM = "checksum-not-valid"; @@ -99,13 +98,9 @@ public class ValidateChecksumConsumer extends AbstractMonitoredConsumer return false; } - public void beginScan( ArchivaRepository repository ) throws ConsumerException + public void beginScan( ArchivaRepository repository ) + throws ConsumerException { - if ( !repository.isManaged() ) - { - throw new ConsumerException( "Consumer requires managed repository." ); - } - this.repository = repository; this.repositoryDir = new File( repository.getUrl().getPath() ); } @@ -125,7 +120,8 @@ public class ValidateChecksumConsumer extends AbstractMonitoredConsumer return this.includes; } - public void processFile( String path ) throws ConsumerException + public void processFile( String path ) + throws ConsumerException { File checksumFile = new File( this.repositoryDir, path ); try @@ -141,7 +137,8 @@ public class ValidateChecksumConsumer extends AbstractMonitoredConsumer } catch ( DigesterException e ) { - triggerConsumerError( CHECKSUM_DIGESTER_FAILURE, "Digester failure during checksum validation on " + checksumFile ); + triggerConsumerError( CHECKSUM_DIGESTER_FAILURE, + "Digester failure during checksum validation on " + checksumFile ); } catch ( IOException e ) { @@ -149,7 +146,8 @@ public class ValidateChecksumConsumer extends AbstractMonitoredConsumer } } - public void initialize() throws InitializationException + public void initialize() + throws InitializationException { for ( Iterator itDigesters = digesterList.iterator(); itDigesters.hasNext(); ) { diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java index 433d9b217..7a0a1d7c4 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java @@ -19,24 +19,22 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ -import org.apache.maven.archiva.model.ArchivaRepository; -import org.apache.maven.archiva.model.ArchivaArtifact; -import org.apache.maven.archiva.repository.layout.FilenameParts; -import org.apache.maven.archiva.repository.layout.RepositoryLayoutUtils; -import org.apache.maven.archiva.repository.layout.LayoutException; -import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; +import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.indexer.RepositoryIndexException; -import org.apache.commons.lang.StringUtils; -import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.apache.maven.archiva.model.ArchivaArtifact; +import org.apache.maven.archiva.model.ArchivaRepository; +import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; +import org.apache.maven.archiva.repository.layout.FilenameParts; +import org.apache.maven.archiva.repository.layout.LayoutException; +import org.apache.maven.archiva.repository.layout.RepositoryLayoutUtils; import java.io.File; import java.io.FilenameFilter; /** * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> - * @version */ public abstract class AbstractRepositoryPurge implements RepositoryPurge @@ -47,12 +45,12 @@ public abstract class AbstractRepositoryPurge protected ArtifactDAO artifactDao; - public AbstractRepositoryPurge( ArchivaRepository repository, - BidirectionalRepositoryLayout layout, ArtifactDAO artifactDao ) + public AbstractRepositoryPurge( ArchivaRepository repository, BidirectionalRepositoryLayout layout, + ArtifactDAO artifactDao ) { this.repository = repository; this.layout = layout; - this.artifactDao = artifactDao; + this.artifactDao = artifactDao; } /** diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java index 5141cd87a..c12a2559e 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java @@ -19,35 +19,31 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ -import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader; -import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter; -import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException; -import org.apache.maven.archiva.repository.layout.FilenameParts; -import org.apache.maven.archiva.repository.layout.LayoutException; -import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; -import org.apache.maven.archiva.configuration.Configuration; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; -import org.apache.maven.archiva.common.utils.VersionUtil; +import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.common.utils.VersionComparator; -import org.apache.maven.archiva.indexer.RepositoryIndexException; -import org.apache.maven.archiva.model.ArchivaRepositoryMetadata; -import org.apache.maven.archiva.model.ArchivaRepository; +import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.database.ArtifactDAO; -import org.apache.commons.io.FileUtils; +import org.apache.maven.archiva.model.ArchivaRepository; +import org.apache.maven.archiva.model.ArchivaRepositoryMetadata; +import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; +import org.apache.maven.archiva.repository.layout.FilenameParts; +import org.apache.maven.archiva.repository.layout.LayoutException; +import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException; +import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader; +import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter; import java.io.File; import java.io.IOException; -import java.util.List; +import java.util.ArrayList; import java.util.Collections; import java.util.Date; -import java.util.ArrayList; import java.util.Iterator; +import java.util.List; /** * M2 implementation for cleaning up the released snapshots. * * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> - * @version */ public class CleanupReleasedSnapshotsRepositoryPurge extends AbstractRepositoryPurge @@ -60,7 +56,7 @@ public class CleanupReleasedSnapshotsRepositoryPurge ArtifactDAO artifactDao ) { super( repository, layout, artifactDao ); - metadataReader = new RepositoryMetadataReader(); + metadataReader = new RepositoryMetadataReader(); } public void process( String path ) diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java index 5c05a2a66..14e0f0a8e 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java @@ -19,35 +19,32 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ -import org.apache.maven.archiva.repository.layout.FilenameParts; -import org.apache.maven.archiva.repository.layout.LayoutException; -import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; +import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.common.utils.VersionUtil; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; -import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.database.ArtifactDAO; -import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.model.ArchivaRepository; +import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; +import org.apache.maven.archiva.repository.layout.FilenameParts; +import org.apache.maven.archiva.repository.layout.LayoutException; -import java.util.Calendar; import java.io.File; +import java.util.Calendar; /** * Purge repository for snapshots older than the specified days in the repository configuration. * * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> - * @version */ public class DaysOldRepositoryPurge extends AbstractRepositoryPurge -{ - private RepositoryConfiguration repoConfig; +{ + private int daysOlder; - public DaysOldRepositoryPurge( ArchivaRepository repository, - BidirectionalRepositoryLayout layout, ArtifactDAO artifactDao, - RepositoryConfiguration repoConfig) + public DaysOldRepositoryPurge( ArchivaRepository repository, BidirectionalRepositoryLayout layout, + ArtifactDAO artifactDao, int daysOlder ) { super( repository, layout, artifactDao ); - this.repoConfig = repoConfig; + this.daysOlder = daysOlder; } public void process( String path ) @@ -57,7 +54,7 @@ public class DaysOldRepositoryPurge { File artifactFile = new File( repository.getUrl().getPath(), path ); - if( !artifactFile.exists() ) + if ( !artifactFile.exists() ) { return; } @@ -65,7 +62,7 @@ public class DaysOldRepositoryPurge FilenameParts parts = getFilenameParts( path ); Calendar olderThanThisDate = Calendar.getInstance(); - olderThanThisDate.add( Calendar.DATE, ( -1 * repoConfig.getDaysOlder() ) ); + olderThanThisDate.add( Calendar.DATE, -daysOlder ); if ( VersionUtil.isGenericSnapshot( parts.version ) ) { @@ -88,7 +85,7 @@ public class DaysOldRepositoryPurge Calendar timestampDate = Calendar.getInstance(); timestampDate.set( year, month, day, hour, min, sec ); - if( timestampDate.getTimeInMillis() < olderThanThisDate.getTimeInMillis() ) + if ( timestampDate.getTimeInMillis() < olderThanThisDate.getTimeInMillis() ) { doPurge( artifactFile, parts.extension ); } @@ -97,7 +94,7 @@ public class DaysOldRepositoryPurge if ( artifactFile.lastModified() < olderThanThisDate.getTimeInMillis() ) { doPurge( artifactFile, parts.extension ); - } + } } } diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java index 8addb1220..af87c25ce 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java @@ -19,26 +19,24 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.FileTypes; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.maven.archiva.consumers.ConsumerException; +import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.model.ArchivaRepository; -import org.apache.maven.archiva.repository.layout.LayoutException; import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.FileTypes; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; -import org.apache.maven.archiva.database.ArchivaDAO; -import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory; -import org.apache.maven.archiva.indexer.RepositoryContentIndex; -import org.codehaus.plexus.registry.RegistryListener; -import org.codehaus.plexus.registry.Registry; +import org.apache.maven.archiva.repository.layout.LayoutException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; +import org.codehaus.plexus.registry.Registry; +import org.codehaus.plexus.registry.RegistryListener; -import java.util.List; import java.util.ArrayList; +import java.util.List; /** * Consumer for removing old snapshots in the repository based on the criteria @@ -83,8 +81,6 @@ public class RepositoryPurgeConsumer */ private FileTypes filetypes; - private ArchivaRepository repository; - private List includes = new ArrayList(); private List propertyNameTriggers = new ArrayList(); @@ -93,6 +89,8 @@ public class RepositoryPurgeConsumer private RepositoryPurge cleanUp; + private boolean deleteReleasedSnapshots; + public String getId() { return this.id; @@ -121,15 +119,7 @@ public class RepositoryPurgeConsumer public void beginScan( ArchivaRepository repository ) throws ConsumerException { - BidirectionalRepositoryLayout repositoryLayout = null; - - if ( !repository.isManaged() ) - { - throw new ConsumerException( "Consumer requires managed repository." ); - } - - this.repository = repository; - + BidirectionalRepositoryLayout repositoryLayout; try { repositoryLayout = layoutFactory.getLayout( repository.getLayoutType() ); @@ -140,18 +130,23 @@ public class RepositoryPurgeConsumer "Unable to initialize consumer due to unknown repository layout: " + e.getMessage(), e ); } - RepositoryConfiguration repoConfig = configuration.getConfiguration().findRepositoryById( repository.getId() ); + ManagedRepositoryConfiguration repoConfig = + configuration.getConfiguration().findManagedRepositoryById( repository.getId() ); + if ( repoConfig.getDaysOlder() != 0 ) { - repoPurge = new DaysOldRepositoryPurge( repository, repositoryLayout, dao.getArtifactDAO(), repoConfig ); + repoPurge = new DaysOldRepositoryPurge( repository, repositoryLayout, dao.getArtifactDAO(), + repoConfig.getDaysOlder() ); } else { - repoPurge = - new RetentionCountRepositoryPurge( repository, repositoryLayout, dao.getArtifactDAO(), repoConfig ); + repoPurge = new RetentionCountRepositoryPurge( repository, repositoryLayout, dao.getArtifactDAO(), + repoConfig.getRetentionCount() ); } cleanUp = new CleanupReleasedSnapshotsRepositoryPurge( repository, repositoryLayout, dao.getArtifactDAO() ); + + deleteReleasedSnapshots = repoConfig.isDeleteReleasedSnapshots(); } public void processFile( String path ) @@ -159,9 +154,7 @@ public class RepositoryPurgeConsumer { try { - RepositoryConfiguration repoConfig = - configuration.getConfiguration().findRepositoryById( repository.getId() ); - if ( repoConfig.isDeleteReleasedSnapshots() ) + if ( deleteReleasedSnapshots ) { cleanUp.process( path ); } diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java index 18ba29c5c..76456bf95 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java @@ -19,49 +19,44 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ -import org.apache.maven.archiva.configuration.Configuration; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; -import org.apache.maven.archiva.repository.layout.FilenameParts; -import org.apache.maven.archiva.repository.layout.LayoutException; -import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; import org.apache.maven.archiva.common.utils.VersionUtil; -import org.apache.maven.archiva.indexer.RepositoryIndexException; -import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.database.ArtifactDAO; +import org.apache.maven.archiva.model.ArchivaRepository; +import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; +import org.apache.maven.archiva.repository.layout.FilenameParts; +import org.apache.maven.archiva.repository.layout.LayoutException; import java.io.File; -import java.util.List; import java.util.ArrayList; -import java.util.Iterator; import java.util.Collections; +import java.util.Iterator; +import java.util.List; /** * Purge the repository by retention count. Retain only the specified number of snapshots. * * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> - * @version */ public class RetentionCountRepositoryPurge extends AbstractRepositoryPurge { - private RepositoryConfiguration repoConfig; + private int retentionCount; - public RetentionCountRepositoryPurge( ArchivaRepository repository, - BidirectionalRepositoryLayout layout, ArtifactDAO artifactDao, - RepositoryConfiguration repoConfig ) + public RetentionCountRepositoryPurge( ArchivaRepository repository, BidirectionalRepositoryLayout layout, + ArtifactDAO artifactDao, int retentionCount ) { super( repository, layout, artifactDao ); - this.repoConfig = repoConfig; + this.retentionCount = retentionCount; } public void process( String path ) throws RepositoryPurgeException { try - { + { File artifactFile = new File( repository.getUrl().getPath(), path ); - if( !artifactFile.exists() ) + if ( !artifactFile.exists() ) { return; } @@ -69,7 +64,7 @@ public class RetentionCountRepositoryPurge FilenameParts parts = getFilenameParts( path ); if ( VersionUtil.isSnapshot( parts.version ) ) - { + { File parentDir = artifactFile.getParentFile(); if ( parentDir.isDirectory() ) @@ -78,13 +73,13 @@ public class RetentionCountRepositoryPurge List uniqueVersionFilenames = getUniqueVersions( files ); Collections.sort( uniqueVersionFilenames ); - if ( uniqueVersionFilenames.size() > repoConfig.getRetentionCount() ) + if ( uniqueVersionFilenames.size() > retentionCount ) { int count = uniqueVersionFilenames.size(); for ( Iterator iter = uniqueVersionFilenames.iterator(); iter.hasNext(); ) { String filename = (String) iter.next(); - if ( count > repoConfig.getRetentionCount() ) + if ( count > retentionCount ) { File[] artifactFiles = getFiles( parentDir, filename ); purge( artifactFiles ); diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java index 040acb57a..5e2251b73 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java @@ -19,40 +19,41 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory; -import org.codehaus.plexus.jdo.JdoFactory; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; -import org.apache.maven.archiva.model.ArchivaRepository; +import org.apache.maven.archiva.common.utils.PathUtil; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.database.ArchivaDatabaseException; +import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.model.ArchivaArtifact; +import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; -import org.apache.maven.archiva.repository.layout.LayoutException; import org.apache.maven.archiva.repository.layout.DefaultBidirectionalRepositoryLayout; -import org.apache.maven.archiva.database.ArtifactDAO; -import org.apache.maven.archiva.database.ArchivaDatabaseException; +import org.apache.maven.archiva.repository.layout.LayoutException; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory; +import org.codehaus.plexus.jdo.JdoFactory; import org.jpox.SchemaTool; -import javax.jdo.PersistenceManagerFactory; import javax.jdo.PersistenceManager; -import java.util.Properties; +import javax.jdo.PersistenceManagerFactory; +import java.io.File; +import java.net.URL; +import java.util.Date; import java.util.Iterator; -import java.util.Map; import java.util.List; -import java.util.Date; -import java.net.URL; -import java.io.File; +import java.util.Map; +import java.util.Properties; /** * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> */ -public class AbstractRepositoryPurgeTest +public abstract class AbstractRepositoryPurgeTest extends PlexusTestCase { public static final String TEST_REPO_ID = "test-repo"; public static final String TEST_REPO_NAME = "Test Repository"; - public static final String TEST_REPO_URL = "file://" + getBasedir() + "/target/test/test-repo/"; + public static final String TEST_REPO_URL = getBasedir() + "/target/test/test-repo/"; public static final int TEST_RETENTION_COUNT = 2; @@ -76,7 +77,7 @@ public class AbstractRepositoryPurgeTest public static final String PATH_TO_HIGHER_SNAPSHOT_EXISTS = "org/apache/maven/plugins/maven-source-plugin/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar"; - private RepositoryConfiguration config; + private ManagedRepositoryConfiguration config; private ArchivaRepository repo; @@ -154,17 +155,17 @@ public class AbstractRepositoryPurgeTest dao = (ArtifactDAO) lookup( ArtifactDAO.class.getName(), "jdo" ); } - public RepositoryConfiguration getRepoConfiguration() + public ManagedRepositoryConfiguration getRepoConfiguration() { if ( config == null ) { - config = new RepositoryConfiguration(); + config = new ManagedRepositoryConfiguration(); } config.setId( TEST_REPO_ID ); config.setName( TEST_REPO_NAME ); config.setDaysOlder( TEST_DAYS_OLDER ); - config.setUrl( TEST_REPO_URL ); + config.setLocation( TEST_REPO_URL ); config.setReleases( true ); config.setSnapshots( true ); config.setRetentionCount( TEST_RETENTION_COUNT ); @@ -176,7 +177,7 @@ public class AbstractRepositoryPurgeTest { if ( repo == null ) { - repo = new ArchivaRepository( TEST_REPO_ID, TEST_REPO_NAME, TEST_REPO_URL ); + repo = new ArchivaRepository( TEST_REPO_ID, TEST_REPO_NAME, PathUtil.toUrl( TEST_REPO_URL ) ); } return repo; @@ -196,12 +197,11 @@ public class AbstractRepositoryPurgeTest protected void populateDb( String groupId, String artifactId, List versions ) throws ArchivaDatabaseException { - for( Iterator iter = versions.iterator(); iter.hasNext(); ) + for ( Iterator iter = versions.iterator(); iter.hasNext(); ) { String version = (String) iter.next(); - - ArchivaArtifact artifact = - dao.createArtifact( groupId, artifactId, version, "", "jar" ); + + ArchivaArtifact artifact = dao.createArtifact( groupId, artifactId, version, "", "jar" ); assertNotNull( artifact ); artifact.getModel().setLastModified( new Date() ); artifact.getModel().setOrigin( "test" ); @@ -209,8 +209,7 @@ public class AbstractRepositoryPurgeTest assertNotNull( savedArtifact ); //POM - artifact = - dao.createArtifact( groupId, artifactId, version, "", "pom" ); + artifact = dao.createArtifact( groupId, artifactId, version, "", "pom" ); assertNotNull( artifact ); artifact.getModel().setLastModified( new Date() ); artifact.getModel().setOrigin( "test" ); diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java index e2be47500..d91291934 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java @@ -21,9 +21,9 @@ package org.apache.maven.archiva.consumers.core.repository; import org.apache.commons.io.FileUtils; -import java.util.List; -import java.util.ArrayList; import java.io.File; +import java.util.ArrayList; +import java.util.List; /** * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> @@ -37,7 +37,8 @@ public class DaysOldRepositoryPurgeTest { super.setUp(); - repoPurge = new DaysOldRepositoryPurge( getRepository(), getLayout(), dao, getRepoConfiguration() ); + repoPurge = + new DaysOldRepositoryPurge( getRepository(), getLayout(), dao, getRepoConfiguration().getDaysOlder() ); } private void setLastModified( String dirPath ) diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java index 346d20caa..1ed780036 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java @@ -19,20 +19,20 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ +import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.maven.archiva.database.ArchivaDatabaseException; -import org.apache.commons.io.FileUtils; +import org.codehaus.plexus.util.IOUtil; import org.jdom.Document; import org.jdom.Element; -import org.jdom.xpath.XPath; import org.jdom.input.SAXBuilder; -import org.codehaus.plexus.util.IOUtil; +import org.jdom.xpath.XPath; import java.io.File; import java.io.FileReader; -import java.util.List; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; /** * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> @@ -40,16 +40,9 @@ import java.util.Iterator; public class RepositoryPurgeConsumerTest extends AbstractRepositoryPurgeTest { - protected void setUp() - throws Exception - { - super.setUp(); - } - private void setLastModified() { - File dir = - new File( "target/test/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/" ); + File dir = new File( "target/test/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/" ); File[] contents = dir.listFiles(); for ( int i = 0; i < contents.length; i++ ) { @@ -60,8 +53,8 @@ public class RepositoryPurgeConsumerTest public void testConsumerByRetentionCount() throws Exception { - KnownRepositoryContentConsumer repoPurgeConsumer = ( KnownRepositoryContentConsumer ) - lookup( KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-retention-count" ); + KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup( + KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-retention-count" ); populateDbForRetentionCountTest(); @@ -69,7 +62,7 @@ public class RepositoryPurgeConsumerTest File testDir = new File( "target/test" ); FileUtils.copyDirectoryToDirectory( new File( "target/test-classes/test-repo" ), testDir ); - + repoPurgeConsumer.processFile( PATH_TO_BY_RETENTION_COUNT_ARTIFACT ); // assert if removed from repo @@ -134,8 +127,8 @@ public class RepositoryPurgeConsumerTest { populateDbForDaysOldTest(); - KnownRepositoryContentConsumer repoPurgeConsumer = ( KnownRepositoryContentConsumer ) - lookup( KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-days-old" ); + KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup( + KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-days-old" ); repoPurgeConsumer.beginScan( getRepository() ); @@ -143,7 +136,7 @@ public class RepositoryPurgeConsumerTest FileUtils.copyDirectoryToDirectory( new File( "target/test-classes/test-repo" ), testDir ); setLastModified(); - + repoPurgeConsumer.processFile( PATH_TO_BY_DAYS_OLD_ARTIFACT ); assertFalse( new File( @@ -158,15 +151,15 @@ public class RepositoryPurgeConsumerTest "target/test/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" ).exists() ); assertFalse( new File( "target/test/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" ).exists() ); - + FileUtils.deleteDirectory( testDir ); } public void testReleasedSnapshotsWereNotCleaned() throws Exception { - KnownRepositoryContentConsumer repoPurgeConsumer = ( KnownRepositoryContentConsumer ) - lookup( KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-retention-count" ); + KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup( + KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-retention-count" ); populateDbForReleasedSnapshotsTest(); @@ -178,8 +171,8 @@ public class RepositoryPurgeConsumerTest repoPurgeConsumer.processFile( PATH_TO_RELEASED_SNAPSHOT ); // check if the snapshot wasn't removed - assertTrue( new File( - "target/test/test-repo/org/apache/maven/plugins/maven-plugin-plugin/2.3-SNAPSHOT" ).exists() ); + assertTrue( + new File( "target/test/test-repo/org/apache/maven/plugins/maven-plugin-plugin/2.3-SNAPSHOT" ).exists() ); assertTrue( new File( "target/test/test-repo/org/apache/maven/plugins/maven-plugin-plugin/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" ).exists() ); assertTrue( new File( @@ -221,14 +214,13 @@ public class RepositoryPurgeConsumerTest el = (Element) xPath.newInstance( "./lastUpdated" ).selectSingleNode( versioning ); assertTrue( el.getValue().equals( "20070315032817" ) ); - List nodes = xPath.newInstance( "./versions" ).selectNodes( - versioning ); + List nodes = xPath.newInstance( "./versions" ).selectNodes( versioning ); boolean found = false; for ( Iterator iter = nodes.iterator(); iter.hasNext(); ) { - el = ( Element ) iter.next(); - if( el.getValue().trim().equals( "2.3-SNAPSHOT" ) ) + el = (Element) iter.next(); + if ( el.getValue().trim().equals( "2.3-SNAPSHOT" ) ) { found = true; } @@ -241,8 +233,8 @@ public class RepositoryPurgeConsumerTest public void testReleasedSnapshotsWereCleaned() throws Exception { - KnownRepositoryContentConsumer repoPurgeConsumer = ( KnownRepositoryContentConsumer ) - lookup( KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-days-old" ); + KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup( + KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-days-old" ); populateDbForReleasedSnapshotsTest(); @@ -254,8 +246,8 @@ public class RepositoryPurgeConsumerTest repoPurgeConsumer.processFile( PATH_TO_RELEASED_SNAPSHOT ); // check if the snapshot was removed - assertFalse( new File( - "target/test/test-repo/org/apache/maven/plugins/maven-plugin-plugin/2.3-SNAPSHOT" ).exists() ); + assertFalse( + new File( "target/test/test-repo/org/apache/maven/plugins/maven-plugin-plugin/2.3-SNAPSHOT" ).exists() ); assertFalse( new File( "target/test/test-repo/org/apache/maven/plugins/maven-plugin-plugin/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" ).exists() ); assertFalse( new File( @@ -297,14 +289,13 @@ public class RepositoryPurgeConsumerTest el = (Element) xPath.newInstance( "./lastUpdated" ).selectSingleNode( versioning ); assertFalse( el.getValue().equals( "20070315032817" ) ); - List nodes = xPath.newInstance( "./versions" ).selectNodes( - rootElement ); + List nodes = xPath.newInstance( "./versions" ).selectNodes( rootElement ); boolean found = false; for ( Iterator iter = nodes.iterator(); iter.hasNext(); ) { - el = ( Element ) iter.next(); - if( el.getValue().equals( "2.3-SNAPSHOT" ) ) + el = (Element) iter.next(); + if ( el.getValue().equals( "2.3-SNAPSHOT" ) ) { found = true; } @@ -315,7 +306,7 @@ public class RepositoryPurgeConsumerTest } public void populateDbForRetentionCountTest() - throws ArchivaDatabaseException + throws ArchivaDatabaseException { List versions = new ArrayList(); versions.add( "1.0RC1-20070504.153317-1" ); @@ -323,7 +314,7 @@ public class RepositoryPurgeConsumerTest versions.add( "1.0RC1-20070505.090015-3" ); versions.add( "1.0RC1-20070506.090132-4" ); - populateDb( "org.jruby.plugins", "jruby-rake-plugin", versions); + populateDb( "org.jruby.plugins", "jruby-rake-plugin", versions ); } private void populateDbForDaysOldTest() @@ -341,7 +332,7 @@ public class RepositoryPurgeConsumerTest List versions = new ArrayList(); versions.add( "2.3-SNAPSHOT" ); - populateDb( "org.apache.maven.plugins", "maven-plugin-plugin", versions ); + populateDb( "org.apache.maven.plugins", "maven-plugin-plugin", versions ); } } diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java index ab4af8b47..2521f0535 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java @@ -22,8 +22,8 @@ package org.apache.maven.archiva.consumers.core.repository; import org.apache.commons.io.FileUtils; import java.io.File; -import java.util.List; import java.util.ArrayList; +import java.util.List; /** * Test RetentionsCountRepositoryPurgeTest @@ -39,7 +39,8 @@ public class RetentionCountRepositoryPurgeTest { super.setUp(); - repoPurge = new RetentionCountRepositoryPurge( getRepository(), getLayout(), dao, getRepoConfiguration() ); + repoPurge = new RetentionCountRepositoryPurge( getRepository(), getLayout(), dao, + getRepoConfiguration().getRetentionCount() ); } /** diff --git a/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java b/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java index a4772571f..f1c38e091 100644 --- a/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java +++ b/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java @@ -49,10 +49,9 @@ import java.util.List; * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ - * * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" - * role-hint="update-db-artifact" - * instantiation-strategy="per-lookup" + * role-hint="update-db-artifact" + * instantiation-strategy="per-lookup" */ public class ArtifactUpdateDatabaseConsumer extends AbstractMonitoredConsumer @@ -140,11 +139,6 @@ public class ArtifactUpdateDatabaseConsumer public void beginScan( ArchivaRepository repository ) throws ConsumerException { - if ( !repository.isManaged() ) - { - throw new ConsumerException( "Consumer requires managed repository." ); - } - this.repository = repository; this.repositoryDir = new File( repository.getUrl().getPath() ); @@ -180,7 +174,8 @@ public class ArtifactUpdateDatabaseConsumer } catch ( DigesterException e ) { - triggerConsumerWarning( CHECKSUM_CALCULATION, "Unable to calculate the MD5 checksum: " + e.getMessage() ); + triggerConsumerWarning( CHECKSUM_CALCULATION, + "Unable to calculate the MD5 checksum: " + e.getMessage() ); } try @@ -189,8 +184,8 @@ public class ArtifactUpdateDatabaseConsumer } catch ( DigesterException e ) { - triggerConsumerWarning( CHECKSUM_CALCULATION, "Unable to calculate the SHA1 checksum: " - + e.getMessage() ); + triggerConsumerWarning( CHECKSUM_CALCULATION, + "Unable to calculate the SHA1 checksum: " + e.getMessage() ); } artifact.getModel().setLastModified( new Date( artifactFile.lastModified() ) ); @@ -207,11 +202,11 @@ public class ArtifactUpdateDatabaseConsumer /** * Get a Live Artifact from a Path. - * + * <p/> * Will resolve the artifact details from the path, and then return a database live version * of that artifact. Suitable for modification and saving (without the need to check for * existance in database prior to save.) - * + * * @param path the path to work from. * @return the artifact that is suitable for database saving. */ @@ -231,8 +226,8 @@ public class ArtifactUpdateDatabaseConsumer } catch ( LayoutException e ) { - triggerConsumerError( TYPE_NOT_ARTIFACT, "Path " + path + " cannot be converted to artifact: " - + e.getMessage() ); + triggerConsumerError( TYPE_NOT_ARTIFACT, + "Path " + path + " cannot be converted to artifact: " + e.getMessage() ); return null; } } diff --git a/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java b/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java index 4495e2cd5..ba4b6b5a8 100644 --- a/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java +++ b/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java @@ -20,8 +20,10 @@ package org.apache.maven.archiva.consumers.database; */ import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.common.utils.VersionUtil; +import org.apache.maven.archiva.configuration.AbstractRepositoryConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; import org.apache.maven.archiva.consumers.ConsumerException; import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer; @@ -31,7 +33,6 @@ import org.apache.maven.archiva.database.ObjectNotFoundException; import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaProjectModel; import org.apache.maven.archiva.model.RepositoryProblem; -import org.apache.maven.archiva.model.RepositoryURL; import org.apache.maven.archiva.reporting.artifact.CorruptArtifactReport; import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory; @@ -42,7 +43,6 @@ import org.apache.maven.archiva.repository.project.ProjectModelException; import org.apache.maven.archiva.repository.project.ProjectModelFilter; import org.apache.maven.archiva.repository.project.ProjectModelReader; import org.apache.maven.archiva.repository.project.filters.EffectiveProjectModelFilter; -import org.apache.maven.archiva.common.utils.VersionUtil; import java.io.File; import java.util.ArrayList; @@ -146,7 +146,7 @@ public class ProjectModelToDatabaseConsumer } File artifactFile = toFile( artifact ); - RepositoryConfiguration repo = getRepository( artifact ); + AbstractRepositoryConfiguration repo = getRepository( artifact ); ProjectModelReader reader = project400Reader; if ( StringUtils.equals( "legacy", repo.getLayout() ) ) @@ -223,15 +223,15 @@ public class ProjectModelToDatabaseConsumer } } - private RepositoryConfiguration getRepository( ArchivaArtifact artifact ) + private ManagedRepositoryConfiguration getRepository( ArchivaArtifact artifact ) { String repoId = artifact.getModel().getRepositoryId(); - return archivaConfiguration.getConfiguration().findRepositoryById( repoId ); + return archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId ); } private File toFile( ArchivaArtifact artifact ) { - RepositoryConfiguration repoConfig = getRepository( artifact ); + ManagedRepositoryConfiguration repoConfig = getRepository( artifact ); BidirectionalRepositoryLayout layout = null; @@ -245,9 +245,7 @@ public class ProjectModelToDatabaseConsumer return null; } - String path = layout.toPath( artifact ); - RepositoryURL url = new RepositoryURL( repoConfig.getUrl() ); - return new File( url.getPath(), path ); + return new File( repoConfig.getLocation(), layout.toPath( artifact ) ); } public String getDescription() diff --git a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexArtifactConsumer.java b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexArtifactConsumer.java index a9dd4070f..ac43237f6 100644 --- a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexArtifactConsumer.java +++ b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexArtifactConsumer.java @@ -22,7 +22,7 @@ package org.apache.maven.archiva.consumers.lucene; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; import org.apache.maven.archiva.consumers.ConsumerException; import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer; @@ -45,14 +45,13 @@ import java.util.List; import java.util.Map; /** - * IndexArtifactConsumer + * IndexArtifactConsumer * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ - * * @plexus.component role="org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer" - * role-hint="index-artifact" - * instantiation-strategy="per-lookup" + * role-hint="index-artifact" + * instantiation-strategy="per-lookup" */ public class IndexArtifactConsumer extends AbstractMonitoredConsumer @@ -129,8 +128,8 @@ public class IndexArtifactConsumer String repoId = artifact.getModel().getRepositoryId(); if ( StringUtils.isBlank( repoId ) ) { - throw new IllegalStateException( "Unable to process artifact [" + artifact - + "] as it has no repository id associated with it." ); + throw new IllegalStateException( + "Unable to process artifact [" + artifact + "] as it has no repository id associated with it." ); } return getIndexedRepositoryDetails( repoId ); @@ -158,7 +157,7 @@ public class IndexArtifactConsumer public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) { - if ( ConfigurationNames.isRepositories( propertyName ) ) + if ( ConfigurationNames.isManagedRepositories( propertyName ) ) { initRepositoryMap(); } @@ -182,14 +181,10 @@ public class IndexArtifactConsumer { this.repositoryMap.clear(); - Iterator it = configuration.getConfiguration().getRepositories().iterator(); + Iterator it = configuration.getConfiguration().getManagedRepositories().iterator(); while ( it.hasNext() ) { - RepositoryConfiguration repoconfig = (RepositoryConfiguration) it.next(); - if ( !repoconfig.isManaged() ) - { - continue; - } + ManagedRepositoryConfiguration repoconfig = (ManagedRepositoryConfiguration) it.next(); ArchivaRepository repository = ArchivaConfigurationAdaptor.toArchivaRepository( repoconfig ); IndexedRepositoryDetails pnl = new IndexedRepositoryDetails(); diff --git a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java index d49d01ab0..cdda88bc6 100644 --- a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java +++ b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java @@ -45,14 +45,13 @@ import java.util.ArrayList; import java.util.List; /** - * IndexContentConsumer - generic full file content indexing consumer. + * IndexContentConsumer - generic full file content indexing consumer. * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ - * * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" - * role-hint="index-content" - * instantiation-strategy="per-lookup" + * role-hint="index-content" + * instantiation-strategy="per-lookup" */ public class IndexContentConsumer extends AbstractMonitoredConsumer @@ -132,11 +131,6 @@ public class IndexContentConsumer public void beginScan( ArchivaRepository repository ) throws ConsumerException { - if ( !repository.isManaged() ) - { - throw new ConsumerException( "Consumer requires managed repository." ); - } - this.repository = repository; this.repositoryDir = new File( repository.getUrl().getPath() ); this.index = indexFactory.createFileContentIndex( repository ); @@ -147,8 +141,8 @@ public class IndexContentConsumer } catch ( LayoutException e ) { - throw new ConsumerException( "Unable to initialize consumer due to unknown repository layout: " - + e.getMessage(), e ); + throw new ConsumerException( + "Unable to initialize consumer due to unknown repository layout: " + e.getMessage(), e ); } } diff --git a/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndexFactory.java b/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndexFactory.java index 3e2e96460..de6b8626d 100644 --- a/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndexFactory.java +++ b/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndexFactory.java @@ -21,7 +21,7 @@ package org.apache.maven.archiva.indexer.lucene; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.indexer.RepositoryContentIndex; import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory; import org.apache.maven.archiva.indexer.bytecode.BytecodeHandlers; @@ -36,7 +36,6 @@ import java.io.File; * * @author <a href="mailto:brett@apache.org">Brett Porter</a> * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> - * * @plexus.component role="org.apache.maven.archiva.indexer.RepositoryContentIndexFactory" role-hint="lucene" */ public class LuceneRepositoryContentIndexFactory @@ -66,21 +65,17 @@ public class LuceneRepositoryContentIndexFactory } /** - * Obtain the index directory for the provided repository. - * + * Obtain the index directory for the provided repository. + * * @param repository the repository to obtain the index directory from. - * @param indexId the id of the index + * @param indexId the id of the index * @return the directory to put the index into. */ private File toIndexDir( ArchivaRepository repository, String indexId ) { - if ( !repository.isManaged() ) - { - throw new IllegalArgumentException( "Only supports managed repositories." ); - } - // Attempt to get the specified indexDir in the configuration first. - RepositoryConfiguration repoConfig = configuration.getConfiguration().findRepositoryById( repository.getId() ); + ManagedRepositoryConfiguration repoConfig = + configuration.getConfiguration().findManagedRepositoryById( repository.getId() ); File indexDir; if ( repoConfig == null ) diff --git a/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java b/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java index eb1676750..2d1a955cf 100644 --- a/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java +++ b/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java @@ -22,7 +22,6 @@ package org.apache.maven.archiva.indexer.search; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; import org.apache.commons.collections.Transformer; -import org.apache.commons.collections.functors.AndPredicate; import org.apache.lucene.document.Document; import org.apache.lucene.queryParser.MultiFieldQueryParser; import org.apache.lucene.queryParser.ParseException; @@ -32,9 +31,7 @@ import org.apache.lucene.search.MultiSearcher; import org.apache.lucene.search.Searchable; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; -import org.apache.maven.archiva.configuration.functors.IndexedRepositoryPredicate; -import org.apache.maven.archiva.configuration.functors.LocalRepositoryPredicate; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.indexer.RepositoryContentIndex; import org.apache.maven.archiva.indexer.bytecode.BytecodeHandlers; import org.apache.maven.archiva.indexer.filecontent.FileContentHandlers; @@ -53,11 +50,10 @@ import org.codehaus.plexus.registry.RegistryListener; import java.io.IOException; import java.util.ArrayList; -import java.util.Collection; import java.util.List; /** - * DefaultCrossRepositorySearch + * DefaultCrossRepositorySearch * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ @@ -105,7 +101,7 @@ public class DefaultCrossRepositorySearch try { - QueryParser parser = new MultiFieldQueryParser( new String[] { HashcodesKeys.MD5, HashcodesKeys.SHA1 }, + QueryParser parser = new MultiFieldQueryParser( new String[]{HashcodesKeys.MD5, HashcodesKeys.SHA1}, new HashcodesHandlers().getAnalyzer() ); LuceneQuery query = new LuceneQuery( parser.parse( checksum ) ); SearchResults results = searchAll( query, limits, indexes ); @@ -256,7 +252,7 @@ public class DefaultCrossRepositorySearch } catch ( IOException ie ) { - getLogger().error( "Unable to close index searcher: " + ie.getMessage(), ie ); + getLogger().error( "Unable to close index searcher: " + ie.getMessage(), ie ); } } @@ -312,7 +308,7 @@ public class DefaultCrossRepositorySearch public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) { - if ( ConfigurationNames.isRepositories( propertyName ) ) + if ( ConfigurationNames.isManagedRepositories( propertyName ) ) { initRepositories(); } @@ -329,28 +325,14 @@ public class DefaultCrossRepositorySearch { this.localIndexedRepositories.clear(); - Predicate localIndexedRepos = AndPredicate.getInstance( LocalRepositoryPredicate.getInstance(), - IndexedRepositoryPredicate.getInstance() ); - - Collection repos = CollectionUtils.select( configuration.getConfiguration().getRepositories(), - localIndexedRepos ); - - Transformer toArchivaRepository = new Transformer() + List<ManagedRepositoryConfiguration> repos = configuration.getConfiguration().getManagedRepositories(); + for ( ManagedRepositoryConfiguration repo : repos ) { - - public Object transform( Object input ) + if ( repo.isIndexed() ) { - if ( input instanceof RepositoryConfiguration ) - { - return ArchivaConfigurationAdaptor.toArchivaRepository( (RepositoryConfiguration) input ); - } - return input; + localIndexedRepositories.add( ArchivaConfigurationAdaptor.toArchivaRepository( repo ) ); } - }; - - CollectionUtils.transform( repos, toArchivaRepository ); - - this.localIndexedRepositories.addAll( repos ); + } } } diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractIndexerTestCase.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractIndexerTestCase.java index 05c0eab59..2149906a3 100644 --- a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractIndexerTestCase.java +++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractIndexerTestCase.java @@ -23,7 +23,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexWriter; import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.indexer.lucene.LuceneIndexHandlers; import org.apache.maven.archiva.indexer.lucene.LuceneRepositoryContentRecord; import org.apache.maven.archiva.model.ArchivaArtifact; @@ -41,7 +41,7 @@ import java.util.List; import java.util.Map; /** - * AbstractIndexerTestCase + * AbstractIndexerTestCase * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ @@ -53,6 +53,10 @@ public abstract class AbstractIndexerTestCase protected LuceneIndexHandlers indexHandlers; + private static final String TEST_DEFAULT_REPOSITORY_NAME = "Test Default Repository"; + + private static final String TEST_DEFAULT_REPO_ID = "testDefaultRepo"; + public abstract String getIndexName(); protected void assertRecord( LuceneRepositoryContentRecord expectedRecord, Document luceneDocument ) @@ -78,9 +82,9 @@ public abstract class AbstractIndexerTestCase { super.setUp(); - RepositoryContentIndexFactory indexFactory = (RepositoryContentIndexFactory) lookup( - RepositoryContentIndexFactory.class - .getName(), "lucene" ); + RepositoryContentIndexFactory indexFactory = + (RepositoryContentIndexFactory) lookup( RepositoryContentIndexFactory.class + .getName(), "lucene" ); ArchivaRepository repository = createTestIndex( getIndexName() ); @@ -90,7 +94,7 @@ public abstract class AbstractIndexerTestCase } private ArchivaRepository createTestIndex( String indexName ) - throws Exception, IOException + throws Exception { File repoDir = new File( getBasedir(), "src/test/managed-repository" ); File testIndexesDir = new File( getBasedir(), "target/test-indexes" ); @@ -104,16 +108,17 @@ public abstract class AbstractIndexerTestCase String repoUri = "file://" + StringUtils.replace( repoDir.getAbsolutePath(), "\\", "/" ); - ArchivaRepository repository = new ArchivaRepository( "testDefaultRepo", "Test Default Repository", repoUri ); + ArchivaRepository repository = + new ArchivaRepository( TEST_DEFAULT_REPO_ID, TEST_DEFAULT_REPOSITORY_NAME, repoUri ); File indexLocation = new File( testIndexesDir, "/index-" + indexName + "-" + getName() + "/" ); MockConfiguration config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" ); - RepositoryConfiguration repoConfig = new RepositoryConfiguration(); - repoConfig.setId( repository.getId() ); - repoConfig.setName( repository.getModel().getName() ); - repoConfig.setUrl( repository.getModel().getUrl() ); + ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration(); + repoConfig.setId( TEST_DEFAULT_REPO_ID ); + repoConfig.setName( TEST_DEFAULT_REPOSITORY_NAME ); + repoConfig.setLocation( repoDir.getAbsolutePath() ); repoConfig.setIndexDir( indexLocation.getAbsolutePath() ); if ( indexLocation.exists() ) @@ -121,7 +126,7 @@ public abstract class AbstractIndexerTestCase FileUtils.deleteDirectory( indexLocation ); } - config.getConfiguration().addRepository( repoConfig ); + config.getConfiguration().addManagedRepository( repoConfig ); return repository; } @@ -130,8 +135,8 @@ public abstract class AbstractIndexerTestCase Map dumps = new HashMap(); // archiva-common-1.0.jar.txt - dumps.put( "archiva-common", createArchivaArtifact( "org.apache.maven.archiva", "archiva-common", "1.0", "", - "jar" ) ); + dumps.put( "archiva-common", + createArchivaArtifact( "org.apache.maven.archiva", "archiva-common", "1.0", "", "jar" ) ); // continuum-webapp-1.0.3-SNAPSHOT.war.txt dumps.put( "continuum-webapp", createArchivaArtifact( "org.apache.maven.continuum", "continuum-webapp", @@ -198,8 +203,8 @@ public abstract class AbstractIndexerTestCase return dumpFile; } - private ArchivaArtifact createArchivaArtifact( String groupId, String artifactId, String version, - String classifier, String type ) + private ArchivaArtifact createArchivaArtifact( String groupId, String artifactId, String version, String classifier, + String type ) { ArchivaArtifact artifact = new ArchivaArtifact( groupId, artifactId, version, classifier, type ); return artifact; diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java index 5d682e36f..2a0d8d657 100644 --- a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java +++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java @@ -25,7 +25,7 @@ import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.Searcher; import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.indexer.MockConfiguration; import org.apache.maven.archiva.indexer.RepositoryContentIndex; import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory; @@ -37,7 +37,7 @@ import java.io.File; import java.util.Map; /** - * DefaultCrossRepositorySearchTest + * DefaultCrossRepositorySearchTest * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ @@ -45,15 +45,18 @@ import java.util.Map; public class DefaultCrossRepositorySearchTest extends PlexusTestCase { + private static final String TEST_DEFAULT_REPOSITORY_NAME = "Test Default Repository"; + + private static final String TEST_DEFAULT_REPO_ID = "testDefaultRepo"; protected void setUp() throws Exception { super.setUp(); - RepositoryContentIndexFactory indexFactory = (RepositoryContentIndexFactory) lookup( - RepositoryContentIndexFactory.class - .getName(), "lucene" ); + RepositoryContentIndexFactory indexFactory = + (RepositoryContentIndexFactory) lookup( RepositoryContentIndexFactory.class + .getName(), "lucene" ); File repoDir = new File( getBasedir(), "src/test/managed-repository" ); @@ -61,16 +64,17 @@ public class DefaultCrossRepositorySearchTest String repoUri = "file://" + StringUtils.replace( repoDir.getAbsolutePath(), "\\", "/" ); - ArchivaRepository repository = new ArchivaRepository( "testDefaultRepo", "Test Default Repository", repoUri ); + ArchivaRepository repository = + new ArchivaRepository( TEST_DEFAULT_REPO_ID, TEST_DEFAULT_REPOSITORY_NAME, repoUri ); File indexLocation = new File( "target/index-crossrepo-" + getName() + "/" ); MockConfiguration config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" ); - RepositoryConfiguration repoConfig = new RepositoryConfiguration(); - repoConfig.setId( repository.getId() ); - repoConfig.setName( repository.getModel().getName() ); - repoConfig.setUrl( repository.getModel().getUrl() ); + ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration(); + repoConfig.setId( TEST_DEFAULT_REPO_ID ); + repoConfig.setName( TEST_DEFAULT_REPOSITORY_NAME ); + repoConfig.setLocation( repoDir.getAbsolutePath() ); repoConfig.setIndexDir( indexLocation.getAbsolutePath() ); repoConfig.setIndexed( true ); @@ -79,7 +83,7 @@ public class DefaultCrossRepositorySearchTest FileUtils.deleteDirectory( indexLocation ); } - config.getConfiguration().addRepository( repoConfig ); + config.getConfiguration().addManagedRepository( repoConfig ); // Create the (empty) indexes. RepositoryContentIndex indexHashcode = indexFactory.createHashcodeIndex( repository ); @@ -115,7 +119,8 @@ public class DefaultCrossRepositorySearchTest private CrossRepositorySearch lookupCrossRepositorySearch() throws Exception { - CrossRepositorySearch search = (CrossRepositorySearch) lookup( CrossRepositorySearch.class.getName(), "default" ); + CrossRepositorySearch search = + (CrossRepositorySearch) lookup( CrossRepositorySearch.class.getName(), "default" ); assertNotNull( "CrossRepositorySearch:default should not be null.", search ); return search; } diff --git a/archiva-base/archiva-model/pom.xml b/archiva-base/archiva-model/pom.xml index f1ef81730..bc46db79e 100755 --- a/archiva-base/archiva-model/pom.xml +++ b/archiva-base/archiva-model/pom.xml @@ -18,7 +18,8 @@ ~ under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <parent> <groupId>org.apache.maven.archiva</groupId> <artifactId>archiva-base</artifactId> @@ -89,7 +90,7 @@ </executions> </plugin> <plugin> - <groupId>org.codehaus.mojo</groupId> + <groupId>org.codehaus.mojo</groupId> <artifactId>jpox-maven-plugin</artifactId> <version>1.1.6</version> <dependencies> @@ -100,44 +101,44 @@ </dependency> </dependencies> <executions> - <!-- TODO: put this into a profile! - <execution> - <id>create-ddl</id> - <phase>generate-test-resources</phase> - <goals> - <goal>schema-create</goal> - </goals> - <configuration> - <outputFile>${basedir}/target/classes/org/apache/maven/archiva/model/schema.ddl</outputFile> - <toolProperties> - <property> - <name>javax.jdo.option.ConnectionDriverName</name> - <value>org.apache.derby.jdbc.EmbeddedDriver</value> - </property> - <property> - <name>javax.jdo.option.ConnectionURL</name> - <value>jdbc:derby:target/jdo-schema-create;create=true</value> - </property> - <property> - <name>javax.jdo.option.ConnectionUserName</name> - <value>sa</value> - </property> - <property> - <name>javax.jdo.option.ConnectionPassword</name> - <value></value> - </property> - <property> - <name>log4j.configuration</name> - <value>${basedir}/src/test/resources/log4j.xml</value> - </property> - <property> - <name>org.jpox.autoCreateTables</name> - <value>true</value> - </property> - </toolProperties> - </configuration> - </execution> - --> + <!-- TODO: put this into a profile + <execution> + <id>create-ddl</id> + <phase>generate-test-resources</phase> + <goals> + <goal>schema-create</goal> + </goals> + <configuration> + <outputFile>${basedir}/target/classes/org/apache/maven/archiva/model/schema.ddl</outputFile> + <toolProperties> + <property> + <name>javax.jdo.option.ConnectionDriverName</name> + <value>org.apache.derby.jdbc.EmbeddedDriver</value> + </property> + <property> + <name>javax.jdo.option.ConnectionURL</name> + <value>jdbc:derby:target/jdo-schema-create;create=true</value> + </property> + <property> + <name>javax.jdo.option.ConnectionUserName</name> + <value>sa</value> + </property> + <property> + <name>javax.jdo.option.ConnectionPassword</name> + <value></value> + </property> + <property> + <name>log4j.configuration</name> + <value>${basedir}/src/test/resources/log4j.xml</value> + </property> + <property> + <name>org.jpox.autoCreateTables</name> + <value>true</value> + </property> + </toolProperties> + </configuration> + </execution> + --> <execution> <id>enhance</id> <goals> diff --git a/archiva-base/archiva-model/src/main/java/org/apache/maven/archiva/model/ArchivaRepository.java b/archiva-base/archiva-model/src/main/java/org/apache/maven/archiva/model/ArchivaRepository.java index 4a01831c4..dc29d542f 100644 --- a/archiva-base/archiva-model/src/main/java/org/apache/maven/archiva/model/ArchivaRepository.java +++ b/archiva-base/archiva-model/src/main/java/org/apache/maven/archiva/model/ArchivaRepository.java @@ -20,7 +20,7 @@ package org.apache.maven.archiva.model; */ /** - * ArchivaRepository + * ArchivaRepository * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ @@ -35,10 +35,10 @@ public class ArchivaRepository /** * Construct a Repository. - * - * @param id the unique identifier for this repository. - * @param name the name for this repository. - * @param url the base URL for this repository (this should point to the top level URL for the entire repository) + * + * @param id the unique identifier for this repository. + * @param name the name for this repository. + * @param url the base URL for this repository (this should point to the top level URL for the entire repository) * @param layout the layout technique for this repository. */ public ArchivaRepository( String id, String name, String url ) @@ -52,7 +52,7 @@ public class ArchivaRepository /** * Construct a Repository. - * + * * @param model the model to use */ public ArchivaRepository( ArchivaRepositoryModel model ) @@ -93,16 +93,6 @@ public class ArchivaRepository this.blacklisted = blacklisted; } - public boolean isRemote() - { - return this.url.getProtocol().equals( "file" ); - } - - public boolean isManaged() - { - return this.url.getProtocol().equals( "file" ); - } - public String getLayoutType() { return this.model.getLayoutName(); diff --git a/archiva-base/archiva-model/src/main/java/org/apache/maven/archiva/model/functors/ManagedRepositoryPredicate.java b/archiva-base/archiva-model/src/main/java/org/apache/maven/archiva/model/functors/ManagedRepositoryPredicate.java deleted file mode 100644 index 849d39ef0..000000000 --- a/archiva-base/archiva-model/src/main/java/org/apache/maven/archiva/model/functors/ManagedRepositoryPredicate.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.apache.maven.archiva.model.functors; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.collections.Predicate; -import org.apache.maven.archiva.model.ArchivaRepository; - -/** - * ManagedRepositoryPredicate - * - * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> - * @version $Id$ - */ -public class ManagedRepositoryPredicate - implements Predicate -{ - public static final Predicate INSTANCE = new ManagedRepositoryPredicate(); - - public static Predicate getInstance() - { - return INSTANCE; - } - - public boolean evaluate( Object object ) - { - boolean satisfies = false; - - if ( object instanceof ArchivaRepository ) - { - ArchivaRepository repo = (ArchivaRepository) object; - return repo.isManaged(); - } - - return satisfies; - } -} diff --git a/archiva-base/archiva-model/src/main/mdo/archiva-base.xml b/archiva-base/archiva-model/src/main/mdo/archiva-base.xml index 3468598f6..859747925 100644 --- a/archiva-base/archiva-model/src/main/mdo/archiva-base.xml +++ b/archiva-base/archiva-model/src/main/mdo/archiva-base.xml @@ -15,7 +15,7 @@ </defaults> <classes> - <class stash.storable="false" + <class stash.storable="false" rootElement="true" jpox.enabled="false"> <name>ArchivaAll</name> @@ -25,6 +25,7 @@ This object is not serialized to the Database. </description> <fields> + <!-- Note: these are only managed repositories. This should be reviewed as to whether they are still needed --> <field> <name>repositories</name> <version>1.0.0+</version> @@ -527,16 +528,16 @@ </codeSegment> </codeSegments> </class> - + <!-- _______________________________________________________________ - __ __ _ _ _ - | \/ | ___| |_ __ _ __| | __ _| |_ __ _ - | |\/| |/ _ \ __/ _` |/ _` |/ _` | __/ _` | - | | | | __/ || (_| | (_| | (_| | || (_| | - |_| |_|\___|\__\__,_|\__,_|\__,_|\__\__,_| - - --> - + __ __ _ _ _ + | \/ | ___| |_ __ _ __| | __ _| |_ __ _ + | |\/| |/ _ \ __/ _` |/ _` |/ _` | __/ _` | + | | | | __/ || (_| | (_| | (_| | || (_| | + |_| |_|\___|\__\__,_|\__,_|\__,_|\__\__,_| + + --> + <class stash.storable="true" jpox.use-identifiers-as-primary-key="false" jpox.not-persisted-fields="modelEncoding" @@ -695,21 +696,21 @@ <code> public void updateTimestamp() { - setLastUpdatedTimestamp( new java.util.Date() ); + setLastUpdatedTimestamp( new java.util.Date() ); } public void setLastUpdatedTimestamp( java.util.Date date ) { - java.util.TimeZone timezone = java.util.TimeZone.getTimeZone( "UTC" ); - java.text.DateFormat fmt = new java.text.SimpleDateFormat( "yyyyMMddHHmmss" ); - fmt.setTimeZone( timezone ); - setLastUpdated( fmt.format( date ) ); + java.util.TimeZone timezone = java.util.TimeZone.getTimeZone( "UTC" ); + java.text.DateFormat fmt = new java.text.SimpleDateFormat( "yyyyMMddHHmmss" ); + fmt.setTimeZone( timezone ); + setLastUpdated( fmt.format( date ) ); } </code> </codeSegment> </codeSegments> </class> - + <class stash.storable="true" jpox.not-persisted-fields="modelEncoding" jpox.table="REPOSITORY_METADATA_SNAPSHOTS"> @@ -724,7 +725,7 @@ <identifier>false</identifier> <required>true</required> <description> - The unique timestamp for the snapshot version. + The unique timestamp for the snapshot version. </description> </field> <field> @@ -744,16 +745,15 @@ </codeSegment> </codeSegments> </class> - - - + + <!-- _______________________________________________________________ - ____ __ - | _ \ ___ / _| ___ _ __ ___ _ __ ___ ___ ___ - | |_) / _ \ |_ / _ \ '__/ _ \ '_ \ / __/ _ \/ __| - | _ ( __/ _| __/ | | __/ | | | (_| __/\__ \ - |_| \_\___|_| \___|_| \___|_| |_|\___\___||___/ - --> + ____ __ + | _ \ ___ / _| ___ _ __ ___ _ __ ___ ___ ___ + | |_) / _ \ |_ / _ \ '__/ _ \ '_ \ / __/ _ \/ __| + | _ ( __/ _| __/ | | __/ | | | (_| __/\__ \ + |_| \_\___|_| \___|_| \___|_| |_|\___\___||___/ + --> <class stash.storable="true" jpox.not-persisted-fields="modelEncoding" @@ -818,7 +818,7 @@ </codeSegment> </codeSegments> </class> - + <class stash.storable="true" jpox.not-persisted-fields="modelEncoding" jpox.table="VERSIONED_REFERENCE"> @@ -894,7 +894,7 @@ </codeSegment> </codeSegments> </class> - + <class stash.storable="true" jpox.not-persisted-fields="modelEncoding" jpox.table="ARTIFACT_REFERENCE"> @@ -1431,7 +1431,7 @@ </codeSegment> </codeSegments> </class> - + <class stash.storable="true" jpox.not-persisted-fields="modelEncoding" jpox.table="MAILING_LISTS"> @@ -1489,7 +1489,7 @@ </codeSegment> </codeSegments> </class> - + <class stash.storable="true" jpox.not-persisted-fields="modelEncoding" jpox.table="ORGANIZATION"> @@ -1533,7 +1533,7 @@ </codeSegment> </codeSegments> </class> - + <class stash.storable="true" jpox.not-persisted-fields="modelEncoding" jpox.table="LICENSES"> @@ -1584,7 +1584,7 @@ </codeSegment> </codeSegments> </class> - + <class stash.storable="true" jpox.not-persisted-fields="modelEncoding" jpox.table="ISSUE_MANAGEMENT"> @@ -1617,7 +1617,7 @@ </codeSegment> </codeSegments> </class> - + <class jpox.not-persisted-fields="modelEncoding"> <name>CiManagement</name> <version>1.0.0+</version> @@ -1648,7 +1648,7 @@ </codeSegment> </codeSegments> </class> - + <class stash.storable="true" jpox.not-persisted-fields="modelEncoding"> <name>Individual</name> @@ -1942,7 +1942,7 @@ </codeSegment> </codeSegments> </class> - + <class stash.storable="true" jpox.not-persisted-fields="modelEncoding" jpox.table="EXCLUSIONS"> @@ -1973,7 +1973,7 @@ </codeSegment> </codeSegments> </class> - + <class stash.storable="true" jpox.not-persisted-fields="modelEncoding" jpox.table="SCM"> @@ -2019,7 +2019,7 @@ </codeSegment> </codeSegments> </class> - + <class stash.storable="true" jpox.not-persisted-fields="modelEncoding" jpox.table="PROJECT_REPOSITORIES"> @@ -2119,7 +2119,7 @@ The repository associated with this path and problem. </description> </field> - <field stash.maxSize="250" + <field stash.maxSize="250" jpox.column="REPO_PATH"> <name>path</name> <version>1.0.0+</version> diff --git a/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java index 005d229e8..12c08be58 100644 --- a/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java +++ b/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java @@ -23,15 +23,17 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.NetworkProxyConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; +import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.model.ProjectReference; import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.policies.DownloadPolicy; import org.apache.maven.archiva.policies.urlcache.UrlFailureCache; +import org.apache.maven.archiva.repository.ArchivaConfigurationAdaptor; import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory; import org.apache.maven.archiva.repository.layout.LayoutException; @@ -60,15 +62,14 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Map.Entry; +import java.util.Properties; /** - * DefaultRepositoryProxyConnectors + * DefaultRepositoryProxyConnectors * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ - * * @plexus.component role-hint="default" */ public class DefaultRepositoryProxyConnectors @@ -116,18 +117,16 @@ public class DefaultRepositoryProxyConnectors /** * Fetch an artifact from a remote repository. - * + * * @param repository the managed repository to utilize for the request. - * @param artifact the artifact reference to fetch. - * @return the local file in the managed repository that was fetched, or null if the artifact was not (or - * could not be) fetched. + * @param artifact the artifact reference to fetch. + * @return the local file in the managed repository that was fetched, or null if the artifact was not (or + * could not be) fetched. * @throws ProxyException if there was a problem fetching the artifact. */ public File fetchFromProxies( ArchivaRepository repository, ArtifactReference artifact ) throws ProxyException { - assertProxyCapable( repository ); - File localFile = toLocalFile( repository, artifact ); Properties requestProperties = new Properties(); @@ -155,14 +154,12 @@ public class DefaultRepositoryProxyConnectors /** * Fetch, from the proxies, a metadata.xml file for the groupId:artifactId:version metadata contents. - * + * * @return the (local) metadata file that was fetched/merged/updated, or null if no metadata file exists. */ public File fetchFromProxies( ArchivaRepository repository, VersionedReference metadata ) throws ProxyException { - assertProxyCapable( repository ); - File localFile = toLocalFile( repository, metadata ); Properties requestProperties = new Properties(); @@ -175,9 +172,10 @@ public class DefaultRepositoryProxyConnectors ProxyConnector connector = (ProxyConnector) it.next(); ArchivaRepository targetRepository = connector.getTargetRepository(); String targetPath = metadataTools.toPath( metadata ); - + File localRepoFile = toLocalRepoFile( repository, targetRepository, targetPath ); - File downloadedFile = transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties ); + File downloadedFile = + transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties ); if ( fileExists( downloadedFile ) ) { @@ -221,14 +219,12 @@ public class DefaultRepositoryProxyConnectors /** * Fetch from the proxies a metadata.xml file for the groupId:artifactId metadata contents. - * + * * @return the (local) metadata file that was fetched/merged/updated, or null if no metadata file exists. */ public File fetchFromProxies( ArchivaRepository repository, ProjectReference metadata ) throws ProxyException { - assertProxyCapable( repository ); - File localFile = toLocalFile( repository, metadata ); Properties requestProperties = new Properties(); @@ -243,7 +239,8 @@ public class DefaultRepositoryProxyConnectors String targetPath = metadataTools.toPath( metadata ); File localRepoFile = toLocalRepoFile( repository, targetRepository, targetPath ); - File downloadedFile = transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties ); + File downloadedFile = + transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties ); if ( fileExists( downloadedFile ) ) { @@ -302,21 +299,6 @@ public class DefaultRepositoryProxyConnectors } } - /** - * Test the repository to see if it is proxy capable. - * - * @param repository the repository to test. - * @throws ProxyException if the repository is not proxy capable. - */ - private void assertProxyCapable( ArchivaRepository repository ) - throws ProxyException - { - if ( !repository.isManaged() ) - { - throw new ProxyException( "Can only proxy managed repositories." ); - } - } - private File toLocalFile( ArchivaRepository repository, ArtifactReference artifact ) throws ProxyException { @@ -341,7 +323,7 @@ public class DefaultRepositoryProxyConnectors /** * Get the layout for the repository. - * + * * @param repository the repository to get the layout from. * @return the layout * @throws ProxyException if there was a problem obtaining the layout from the repository (usually due to a bad @@ -356,14 +338,14 @@ public class DefaultRepositoryProxyConnectors } catch ( LayoutException e ) { - throw new ProxyException( "Unable to proxy due to bad repository layout definition [" + repository.getId() - + "] had a layout defined as [" + repository.getLayoutType() + "] : " + e.getMessage(), e ); + throw new ProxyException( "Unable to proxy due to bad repository layout definition [" + repository.getId() + + "] had a layout defined as [" + repository.getLayoutType() + "] : " + e.getMessage(), e ); } } /** * Simple method to test if the file exists on the local disk. - * + * * @param file the file to test. (may be null) * @return true if file exists. false if the file param is null, doesn't exist, or is not of type File. */ @@ -389,11 +371,11 @@ public class DefaultRepositoryProxyConnectors /** * Perform the transfer of the file. - * - * @param connector the connector configuration to use. - * @param remoteRepository the remote repository get the resource from. - * @param remotePath the path in the remote repository to the resource to get. - * @param localFile the local file to place the downloaded resource into + * + * @param connector the connector configuration to use. + * @param remoteRepository the remote repository get the resource from. + * @param remotePath the path in the remote repository to the resource to get. + * @param localFile the local file to place the downloaded resource into * @param requestProperties the request properties to utilize for policy handling. * @return the local file that was downloaded, or null if not downloaded. * @throws ProxyException if transfer was unsuccessful. @@ -499,14 +481,14 @@ public class DefaultRepositoryProxyConnectors /** * Quietly transfer the checksum file from the remote repository to the local file. - * + * <p/> * NOTE: This will not throw a WagonException if the checksum is unable to be downloaded. - * - * @param wagon the wagon instance (should already be connected) to use. + * + * @param wagon the wagon instance (should already be connected) to use. * @param remoteRepository the remote repository to transfer from. - * @param remotePath the remote path to the resource to get. - * @param localFile the local file that should contain the downloaded contents - * @param type the type of checksum to transfer (example: ".md5" or ".sha1") + * @param remotePath the remote path to the resource to get. + * @param localFile the local file that should contain the downloaded contents + * @param type the type of checksum to transfer (example: ".md5" or ".sha1") * @throws ProxyException if copying the downloaded file into place did not succeed. */ private void transferChecksum( Wagon wagon, ArchivaRepository remoteRepository, String remotePath, File localFile, @@ -540,16 +522,17 @@ public class DefaultRepositoryProxyConnectors /** * Perform the transfer of the remote file to the local file specified. - * - * @param wagon the wagon instance to use. + * + * @param wagon the wagon instance to use. * @param remoteRepository the remote repository to use - * @param remotePath the remote path to attempt to get - * @param localFile the local file to save to + * @param remotePath the remote path to attempt to get + * @param localFile the local file to save to * @return The local file that was transfered. * @throws ProxyException if there was a problem moving the downloaded file into place. * @throws WagonException if there was a problem tranfering the file. */ - private File transferSimpleFile( Wagon wagon, ArchivaRepository remoteRepository, String remotePath, File localFile ) + private File transferSimpleFile( Wagon wagon, ArchivaRepository remoteRepository, String remotePath, + File localFile ) throws ProxyException, WagonException { assert ( remotePath != null ); @@ -584,8 +567,7 @@ public class DefaultRepositoryProxyConnectors if ( !success ) { getLogger().info( - "Not downloaded, as local file is newer than remote side: " - + localFile.getAbsolutePath() ); + "Not downloaded, as local file is newer than remote side: " + localFile.getAbsolutePath() ); } else if ( temp.exists() ) { @@ -617,11 +599,11 @@ public class DefaultRepositoryProxyConnectors /** * Apply the policies. - * @param policies the map of policies to execute. (Map of String policy keys, to {@link DownloadPolicy} objects) - * @param settings the map of settings for the policies to execute. (Map of String policy keys, to String policy setting) - * @param request the request properties (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, File)}) - * @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, File)}) - * + * + * @param policies the map of policies to execute. (Map of String policy keys, to {@link DownloadPolicy} objects) + * @param settings the map of settings for the policies to execute. (Map of String policy keys, to String policy setting) + * @param request the request properties (utilized by the {@link DownloadPolicy#applyPolicy(String,Properties,File)}) + * @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(String,Properties,File)}) * @return true if all of the policies passed, false if a policy failed. */ private boolean applyPolicies( Map policies, Map settings, Properties request, File localFile ) @@ -682,9 +664,9 @@ public class DefaultRepositoryProxyConnectors /** * Using wagon, connect to the remote repository. - * - * @param connector the connector configuration to utilize (for obtaining network proxy configuration from) - * @param wagon the wagon instance to establish the connection on. + * + * @param connector the connector configuration to utilize (for obtaining network proxy configuration from) + * @param wagon the wagon instance to establish the connection on. * @param remoteRepository the remote repository to connect to. * @return true if the connection was successful. false if not connected. */ @@ -700,7 +682,8 @@ public class DefaultRepositoryProxyConnectors try { - Repository wagonRepository = new Repository( remoteRepository.getId(), remoteRepository.getUrl().toString() ); + Repository wagonRepository = + new Repository( remoteRepository.getId(), remoteRepository.getUrl().toString() ); if ( networkProxy != null ) { wagon.connect( wagonRepository, networkProxy ); @@ -727,8 +710,8 @@ public class DefaultRepositoryProxyConnectors /** * Tests whitelist and blacklist patterns against path. - * - * @param path the path to test. + * + * @param path the path to test. * @param patterns the list of patterns to check. * @return true if the path matches at least 1 pattern in the provided patterns list. */ @@ -770,8 +753,10 @@ public class DefaultRepositoryProxyConnectors public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) { - if ( ConfigurationNames.isNetworkProxy( propertyName ) || ConfigurationNames.isRepositories( propertyName ) - || ConfigurationNames.isProxyConnector( propertyName ) ) + if ( ConfigurationNames.isNetworkProxy( propertyName ) || + ConfigurationNames.isManagedRepositories( propertyName ) || + ConfigurationNames.isRemoteRepositories( propertyName ) || + ConfigurationNames.isProxyConnector( propertyName ) ) { initConnectorsAndNetworkProxies(); } @@ -799,8 +784,8 @@ public class DefaultRepositoryProxyConnectors // Create connector object. ProxyConnector connector = new ProxyConnector(); - connector.setSourceRepository( getRepository( proxyConfig.getSourceRepoId() ) ); - connector.setTargetRepository( getRepository( proxyConfig.getTargetRepoId() ) ); + connector.setSourceRepository( getManagedRepository( proxyConfig.getSourceRepoId() ) ); + connector.setTargetRepository( getRemoteRepository( proxyConfig.getTargetRepoId() ) ); connector.setProxyId( proxyConfig.getProxyId() ); connector.setPolicies( proxyConfig.getPolicies() ); @@ -870,19 +855,24 @@ public class DefaultRepositoryProxyConnectors return collection.size() == 0; } - private ArchivaRepository getRepository( String repoId ) + private ArchivaRepository getRemoteRepository( String repoId ) { - RepositoryConfiguration repoConfig = archivaConfiguration.getConfiguration().findRepositoryById( repoId ); - if ( repoConfig == null ) - { - return null; - } + RemoteRepositoryConfiguration repoConfig = + archivaConfiguration.getConfiguration().findRemoteRepositoryById( repoId ); ArchivaRepository repo = new ArchivaRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getUrl() ); repo.getModel().setLayoutName( repoConfig.getLayout() ); return repo; } + private ArchivaRepository getManagedRepository( String repoId ) + { + ManagedRepositoryConfiguration repoConfig = + archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId ); + + return ArchivaConfigurationAdaptor.toArchivaRepository( repoConfig ); + } + public void initialize() throws InitializationException { diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java index 7c498a1dd..6c6113506 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java @@ -22,8 +22,9 @@ package org.apache.maven.archiva.proxy; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.common.utils.PathUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; +import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.model.ArtifactReference; @@ -47,12 +48,12 @@ import java.util.Iterator; import java.util.Locale; /** - * AbstractProxyTestCase + * AbstractProxyTestCase * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ */ -public class AbstractProxyTestCase +public abstract class AbstractProxyTestCase extends PlexusTestCase { protected static final String ID_LEGACY_PROXIED = "legacy-proxied"; @@ -161,7 +162,7 @@ public class AbstractProxyTestCase return; } - Collection tmpFiles = FileUtils.listFiles( workingDir, new String[] { "tmp" }, false ); + Collection tmpFiles = FileUtils.listFiles( workingDir, new String[]{"tmp"}, false ); if ( !tmpFiles.isEmpty() ) { StringBuffer emsg = new StringBuffer(); @@ -220,8 +221,8 @@ public class AbstractProxyTestCase { if ( !destination.exists() && !destination.mkdirs() ) { - throw new IOException( "Could not create destination directory '" - + destination.getAbsolutePath() + "'." ); + throw new IOException( + "Could not create destination directory '" + destination.getAbsolutePath() + "'." ); } copyDirectoryStructure( file, destination ); @@ -260,19 +261,19 @@ public class AbstractProxyTestCase "Test Proxied (Legacy) Repository", "legacy" ); } - protected RepositoryConfiguration createRepoConfig( ArchivaRepository repo ) + protected ManagedRepositoryConfiguration createRepoConfig( ArchivaRepository repo ) { return createRepoConfig( repo.getId(), repo.getName(), repo.getUrl().toString(), repo.getLayoutType() ); } - protected RepositoryConfiguration createRepoConfig( String id, String name, String path, String layout ) + protected ManagedRepositoryConfiguration createRepoConfig( String id, String name, String path, String layout ) { - RepositoryConfiguration repoConfig = new RepositoryConfiguration(); + ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration(); repoConfig.setId( id ); repoConfig.setName( name ); - repoConfig.setUrl( PathUtil.toUrl( path ) ); + repoConfig.setLocation( path ); repoConfig.setLayout( layout ); return repoConfig; @@ -323,8 +324,8 @@ public class AbstractProxyTestCase } } - protected void saveConnector( String sourceRepoId, String targetRepoId, String checksumPolicy, - String releasePolicy, String snapshotPolicy, String cacheFailuresPolicy ) + protected void saveConnector( String sourceRepoId, String targetRepoId, String checksumPolicy, String releasePolicy, + String snapshotPolicy, String cacheFailuresPolicy ) { ProxyConnectorConfiguration connectorConfig = new ProxyConnectorConfiguration(); connectorConfig.setSourceRepoId( sourceRepoId ); @@ -348,24 +349,33 @@ public class AbstractProxyTestCase config.triggerChange( prefix + ".policies.cache-failures", connectorConfig.getPolicy( "cache-failures", "" ) ); } - protected void saveRepositoryConfig( String id, String name, String path, String layout ) + protected void saveManagedRepositoryConfig( String id, String name, String path, String layout ) { - RepositoryConfiguration repoConfig = new RepositoryConfiguration(); + ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration(); repoConfig.setId( id ); repoConfig.setName( name ); + repoConfig.setLayout( layout ); - if ( path.startsWith( "test://" ) ) - { - repoConfig.setUrl( path ); - } - else - { - repoConfig.setUrl( PathUtil.toUrl( path ) ); - } + repoConfig.setLocation( path ); + + config.getConfiguration().addManagedRepository( repoConfig ); + + config.triggerChange( "repository", "" ); + } + + protected void saveRemoteRepositoryConfig( String id, String name, String path, String layout ) + { + RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration(); + + repoConfig.setId( id ); + repoConfig.setName( name ); repoConfig.setLayout( layout ); - config.getConfiguration().addRepository( repoConfig ); + repoConfig.setUrl( path ); + + config.getConfiguration().addRemoteRepository( repoConfig ); + config.triggerChange( "repository", "" ); } @@ -376,7 +386,7 @@ public class AbstractProxyTestCase FileUtils.deleteDirectory( repoLocation ); copyDirectoryStructure( getTestFile( originalPath ), repoLocation ); - saveRepositoryConfig( id, "Target Repo-" + id, targetPath, layout ); + saveRemoteRepositoryConfig( id, "Target Repo-" + id, targetPath, layout ); return repoLocation; } @@ -390,20 +400,19 @@ public class AbstractProxyTestCase .getName() ); config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" ); - RepositoryConfiguration repoConfig; // Setup source repository (using default layout) String repoPath = "target/test-repository/managed/" + getName(); File repoLocation = getTestFile( repoPath ); - managedDefaultRepository = createRepository( ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath, - "default" ); + managedDefaultRepository = + createRepository( ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath, "default" ); managedDefaultDir = new File( managedDefaultRepository.getUrl().getPath() ); - repoConfig = createRepoConfig( managedDefaultRepository ); + ManagedRepositoryConfiguration repoConfig = createRepoConfig( managedDefaultRepository ); - config.getConfiguration().addRepository( repoConfig ); + config.getConfiguration().addManagedRepository( repoConfig ); // Setup source repository (using legacy layout) repoLocation = getTestFile( REPOPATH_LEGACY_MANAGED_TARGET ); @@ -417,16 +426,19 @@ public class AbstractProxyTestCase repoConfig = createRepoConfig( managedLegacyRepository ); - config.getConfiguration().addRepository( repoConfig ); + config.getConfiguration().addManagedRepository( repoConfig ); // Setup target (proxied to) repository. - saveRepositoryConfig( ID_PROXIED1, "Proxied Repository 1", REPOPATH_PROXIED1, "default" ); + saveRemoteRepositoryConfig( ID_PROXIED1, "Proxied Repository 1", + new File( REPOPATH_PROXIED1 ).toURL().toExternalForm(), "default" ); // Setup target (proxied to) repository. - saveRepositoryConfig( ID_PROXIED2, "Proxied Repository 2", REPOPATH_PROXIED2, "default" ); + saveRemoteRepositoryConfig( ID_PROXIED2, "Proxied Repository 2", + new File( REPOPATH_PROXIED2 ).toURL().toExternalForm(), "default" ); // Setup target (proxied to) repository using legacy layout. - saveRepositoryConfig( ID_LEGACY_PROXIED, "Proxied Legacy Repository", REPOPATH_PROXIED_LEGACY, "legacy" ); + saveRemoteRepositoryConfig( ID_LEGACY_PROXIED, "Proxied Legacy Repository", + new File( REPOPATH_PROXIED_LEGACY ).toURL().toExternalForm(), "legacy" ); // Setup the proxy handler. proxyHandler = (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() ); @@ -443,21 +455,21 @@ public class AbstractProxyTestCase /** * Copy the specified resource directory from the src/test/repository/managed/ to * the testable directory under target/test-repository/managed/${testName}/ - * + * * @param resourceDir - * @throws IOException + * @throws IOException */ protected void setupTestableManagedRepository( String resourcePath ) throws IOException { String resourceDir = resourcePath; - - if( !resourcePath.endsWith( "/" ) ) + + if ( !resourcePath.endsWith( "/" ) ) { int idx = resourcePath.lastIndexOf( '/' ); resourceDir = resourcePath.substring( 0, idx ); } - + File sourceRepoDir = new File( REPOPATH_DEFAULT_MANAGED ); File sourceDir = new File( sourceRepoDir, resourceDir ); @@ -474,8 +486,8 @@ public class AbstractProxyTestCase if ( !sourceDir.exists() ) { // This is just a warning. - System.err.println( "Skipping setup of testable managed repsoitory, source dir does not exist: " - + sourceDir ); + System.err.println( + "Skipping setup of testable managed repsoitory, source dir does not exist: " + sourceDir ); return; } diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AllTests.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AllTests.java index 552762313..548c6d860 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AllTests.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AllTests.java @@ -23,7 +23,7 @@ import junit.framework.Test; import junit.framework.TestSuite; /** - * IDE Provided Utility Class for all tests. + * IDE Provided Utility Class for all tests. * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java index 86bfa5f2f..622c7bc04 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java @@ -31,7 +31,7 @@ import org.apache.maven.wagon.TransferFailedException; import java.io.File; /** - * CacheFailuresTransferTest + * CacheFailuresTransferTest * * @author Brett Porter * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> @@ -51,8 +51,8 @@ public class CacheFailuresTransferTest assertFalse( expectedFile.exists() ); // Configure Repository (usually done within archiva.xml configuration) - saveRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); - saveRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/repo/", "default" ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, @@ -85,8 +85,8 @@ public class CacheFailuresTransferTest assertFalse( expectedFile.exists() ); // Configure Repository (usually done within archiva.xml configuration) - saveRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); - saveRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/repo/", "default" ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java index 62e3f0e30..f23b2d6f3 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java @@ -30,7 +30,7 @@ import org.apache.maven.wagon.TransferFailedException; import java.io.File; /** - * ChecksumTransferTest + * ChecksumTransferTest * * @author Brett Porter * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> @@ -44,7 +44,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -69,7 +69,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -85,7 +85,8 @@ public class ChecksumTransferTest File proxied1File = new File( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertNoTempFiles( expectedFile ); - assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", null ); + assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", + null ); } public void testGetChecksumNoSha1CorrectMd5() @@ -93,7 +94,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -117,7 +118,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -141,7 +142,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -165,7 +166,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -187,7 +188,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -212,7 +213,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -234,7 +235,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -259,7 +260,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -281,7 +282,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -306,7 +307,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -331,7 +332,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -356,7 +357,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -381,7 +382,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -389,7 +390,7 @@ public class ChecksumTransferTest assertFalse( expectedFile.getParentFile().exists() ); assertFalse( expectedFile.exists() ); - saveRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED, @@ -417,7 +418,8 @@ public class ChecksumTransferTest File proxied1File = new File( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertNoTempFiles( expectedFile ); - assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", null ); + assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", + null ); } public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingIgnoredSetting() @@ -425,7 +427,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -449,7 +451,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -473,7 +475,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java index 1807d0f77..605eb9d61 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java @@ -31,7 +31,7 @@ import org.apache.maven.wagon.TransferFailedException; import java.io.File; /** - * ManagedDefaultTransferTest + * ManagedDefaultTransferTest * * @author Brett Porter * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> @@ -45,7 +45,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -67,9 +67,9 @@ public class ManagedDefaultTransferTest /** * The attempt here should result in no file being transferred. - * + * <p/> * The file exists locally, and the policy is ONCE. - * + * * @throws Exception */ public void testGetDefaultLayoutAlreadyPresentPolicyOnce() @@ -77,7 +77,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -97,9 +97,9 @@ public class ManagedDefaultTransferTest /** * The attempt here should result in file being transferred. - * + * <p/> * The file exists locally, and the policy is IGNORE. - * + * * @throws Exception */ public void testGetDefaultLayoutAlreadyPresentPolicyIgnored() @@ -107,7 +107,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); long originalModificationTime = expectedFile.lastModified(); @@ -135,15 +135,15 @@ public class ManagedDefaultTransferTest * This delta is the amount of milliseconds of 'fudge factor' we allow for * the unit test to still be considered 'passed'. */ - int delta = 1100; + int delta = 20000; long hirange = originalModificationTime + ( delta / 2 ); long lorange = originalModificationTime - ( delta / 2 ); if ( ( downloadedLastModified < lorange ) || ( downloadedLastModified > hirange ) ) { - fail( "Check file timestamp is that of original managed file: expected within range lo:<" + lorange - + "> hi:<" + hirange + "> but was:<" + downloadedLastModified + ">" ); + fail( "Check file timestamp is that of original managed file: expected within range lo:<" + lorange + + "> hi:<" + hirange + "> but was:<" + downloadedLastModified + ">" ); } } assertNoTempFiles( expectedFile ); @@ -151,9 +151,9 @@ public class ManagedDefaultTransferTest /** * The attempt here should result in file being transferred. - * + * <p/> * The file exists locally, is over 6 years old, and the policy is DAILY. - * + * * @throws Exception */ public void testGetDefaultLayoutRemoteUpdate() @@ -161,7 +161,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -169,8 +169,8 @@ public class ManagedDefaultTransferTest expectedFile.setLastModified( getPastDate().getTime() ); // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.DAILY, - SnapshotsPolicy.DAILY, CachedFailuresPolicy.IGNORED ); + saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.DAILY, SnapshotsPolicy.DAILY, + CachedFailuresPolicy.IGNORED ); // Attempt the proxy fetch. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); @@ -185,7 +185,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -209,8 +209,8 @@ public class ManagedDefaultTransferTest // TODO: is this check even needed if it passes above? String actualContents = FileUtils.readFileToString( downloadedFile, null ); String badContents = FileUtils.readFileToString( proxied2File, null ); - assertFalse( "Downloaded file contents should not be that of proxy 2", StringUtils.equals( actualContents, - badContents ) ); + assertFalse( "Downloaded file contents should not be that of proxy 2", + StringUtils.equals( actualContents, badContents ) ); } public void testGetInSecondProxiedRepo() @@ -218,7 +218,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -244,7 +244,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/does-not-exist/1.0/does-not-exist-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -261,7 +261,8 @@ public class ManagedDefaultTransferTest // Attempt the proxy fetch. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); - assertNull( "File returned was: " + downloadedFile + "; should have got a not found exception", downloadedFile ); + assertNull( "File returned was: " + downloadedFile + "; should have got a not found exception", + downloadedFile ); assertNoTempFiles( expectedFile ); } @@ -270,7 +271,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -278,7 +279,7 @@ public class ManagedDefaultTransferTest assertFalse( expectedFile.exists() ); // Configure Repository (usually done within archiva.xml configuration) - saveRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); wagonMock.getIfNewer( path, new File( expectedFile.getAbsolutePath() + ".tmp" ), 0 ); wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); @@ -305,7 +306,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -313,8 +314,8 @@ public class ManagedDefaultTransferTest assertFalse( expectedFile.exists() ); // Configure Repository (usually done within archiva.xml configuration) - saveRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); - saveRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://dead.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://dead.machine.com/repo/", "default" ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, @@ -346,7 +347,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -358,8 +359,8 @@ public class ManagedDefaultTransferTest File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); - File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, - "org.apache.maven.test/jars/get-default-layout-present-1.0.jar" ); + File proxiedFile = + new File( REPOPATH_PROXIED_LEGACY, "org.apache.maven.test/jars/get-default-layout-present-1.0.jar" ); assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertNoTempFiles( expectedFile ); } @@ -373,7 +374,7 @@ public class ManagedDefaultTransferTest String legacyPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -396,7 +397,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/RelocateTransferTest.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/RelocateTransferTest.java index 5e3399195..a23ace51d 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/RelocateTransferTest.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/RelocateTransferTest.java @@ -19,31 +19,8 @@ package org.apache.maven.archiva.proxy; * under the License. */ -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.common.utils.PathUtil; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; -import org.apache.maven.archiva.model.ArchivaRepository; -import org.apache.maven.archiva.model.ArtifactReference; -import org.apache.maven.archiva.model.ProjectReference; -import org.apache.maven.archiva.policies.CachedFailuresPolicy; -import org.apache.maven.archiva.policies.ChecksumPolicy; -import org.apache.maven.archiva.policies.ReleasesPolicy; -import org.apache.maven.archiva.policies.SnapshotsPolicy; -import org.apache.maven.archiva.policies.urlcache.UrlFailureCache; -import org.apache.maven.wagon.ResourceDoesNotExistException; -import org.apache.maven.wagon.TransferFailedException; -import org.apache.maven.wagon.Wagon; -import org.easymock.MockControl; - -import java.io.File; -import java.io.IOException; -import java.text.ParseException; -import java.util.Arrays; - /** - * RelocateTransferTest + * RelocateTransferTest * * @author Brett Porter * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ActiveManagedRepositories.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ActiveManagedRepositories.java deleted file mode 100644 index 859abf0e8..000000000 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ActiveManagedRepositories.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.apache.maven.archiva.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.collections.CollectionUtils; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.ConfigurationNames; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; -import org.apache.maven.archiva.configuration.functors.LocalRepositoryPredicate; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; -import org.codehaus.plexus.registry.Registry; -import org.codehaus.plexus.registry.RegistryListener; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * A component that provides a real-time listing of the active managed repositories within archiva. - * This object is internally consistent and will return maintain a consistent list of managed repositories internally. - * - * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> - * @version $Id$ - * - * @plexus.component role="org.apache.maven.archiva.repository.ActiveManagedRepositories" - */ -public class ActiveManagedRepositories - implements RegistryListener, Initializable -{ - /** - * @plexus.requirement - */ - private ArchivaConfiguration archivaConfiguration; - - private List allManagedRepositories = new ArrayList(); - - /** - * Get the {@link List} of {@link RepositoryConfiguration} objects representing managed repositories. - * - * @return the {@link List} of {@link RepositoryConfiguration} objects. - */ - public List getAllManagedRepositories() - { - synchronized ( allManagedRepositories ) - { - return Collections.unmodifiableList( allManagedRepositories ); - } - } - - public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) - { - if ( ConfigurationNames.isRepositories( propertyName ) ) - { - update(); - } - } - - public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) - { - /* nothing to do here */ - } - - public void initialize() - throws InitializationException - { - update(); - archivaConfiguration.addChangeListener( this ); - } - - private void update() - { - synchronized ( allManagedRepositories ) - { - allManagedRepositories.clear(); - - List configRepos = archivaConfiguration.getConfiguration().getRepositories(); - CollectionUtils.filter( configRepos, LocalRepositoryPredicate.getInstance() ); - } - } -} diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaConfigurationAdaptor.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaConfigurationAdaptor.java index 618e7e61d..21aabb429 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaConfigurationAdaptor.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaConfigurationAdaptor.java @@ -20,11 +20,12 @@ package org.apache.maven.archiva.repository; */ import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; +import org.apache.maven.archiva.common.utils.PathUtil; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.model.ArchivaRepository; /** - * ArchivaConfigurationAdaptor + * ArchivaConfigurationAdaptor * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ @@ -32,7 +33,11 @@ import org.apache.maven.archiva.model.ArchivaRepository; */ public class ArchivaConfigurationAdaptor { - public static ArchivaRepository toArchivaRepository( RepositoryConfiguration config ) + private ArchivaConfigurationAdaptor() + { + } + + public static ArchivaRepository toArchivaRepository( ManagedRepositoryConfiguration config ) { if ( config == null ) { @@ -44,13 +49,14 @@ public class ArchivaConfigurationAdaptor throw new IllegalArgumentException( "Unable to repository config with blank ID to archiva repository." ); } - if ( StringUtils.isBlank( config.getUrl() ) ) + if ( StringUtils.isBlank( config.getLocation() ) ) { throw new IllegalArgumentException( - "Unable to convert repository config with blank URL to archiva repository." ); + "Unable to convert repository config with blank location to archiva repository." ); } - ArchivaRepository repository = new ArchivaRepository( config.getId(), config.getName(), config.getUrl() ); + ArchivaRepository repository = + new ArchivaRepository( config.getId(), config.getName(), PathUtil.toUrl( config.getLocation() ) ); repository.getModel().setLayoutName( config.getLayout() ); repository.getModel().setReleasePolicy( config.isReleases() ); diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactory.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactory.java index b02b1021c..2ae41f58c 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactory.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/BidirectionalRepositoryLayoutFactory.java @@ -20,9 +20,9 @@ package org.apache.maven.archiva.repository.layout; */ import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.configuration.AbstractRepositoryConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; import org.apache.maven.archiva.model.ArchivaArtifact; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; @@ -98,13 +98,13 @@ public class BidirectionalRepositoryLayoutFactory throw new LayoutException( "Cannot determine layout using artifact with no repository id: " + artifact ); } - RepositoryConfiguration repo = (RepositoryConfiguration) this.repositoryMap.get( repoId ); + AbstractRepositoryConfiguration repo = (AbstractRepositoryConfiguration) this.repositoryMap.get( repoId ); return getLayout( repo.getLayout() ); } public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) { - if ( ConfigurationNames.isRepositories( propertyName ) ) + if ( ConfigurationNames.isManagedRepositories( propertyName ) ) { initRepositoryMap(); } @@ -120,7 +120,7 @@ public class BidirectionalRepositoryLayoutFactory synchronized ( this.repositoryMap ) { this.repositoryMap.clear(); - this.repositoryMap.putAll( configuration.getConfiguration().createRepositoryMap() ); + this.repositoryMap.putAll( configuration.getConfiguration().getManagedRepositoriesAsMap() ); } } diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelResolverFactory.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelResolverFactory.java index 97c1aef77..30475056b 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelResolverFactory.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelResolverFactory.java @@ -19,12 +19,10 @@ package org.apache.maven.archiva.repository.project; * under the License. */ -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; -import org.apache.maven.archiva.configuration.functors.LocalRepositoryPredicate; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.repository.ArchivaConfigurationAdaptor; import org.apache.maven.archiva.repository.RepositoryException; @@ -40,16 +38,13 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExce import org.codehaus.plexus.registry.Registry; import org.codehaus.plexus.registry.RegistryListener; -import java.util.ArrayList; -import java.util.Iterator; import java.util.List; /** - * Factory for ProjectModelResolver objects + * Factory for ProjectModelResolver objects * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ - * * @plexus.component role="org.apache.maven.archiva.repository.project.ProjectModelResolverFactory" */ public class ProjectModelResolverFactory @@ -80,7 +75,7 @@ public class ProjectModelResolverFactory public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) { - if ( ConfigurationNames.isRepositories( propertyName ) ) + if ( ConfigurationNames.isManagedRepositories( propertyName ) ) { update(); } @@ -106,12 +101,6 @@ public class ProjectModelResolverFactory private RepositoryProjectResolver toResolver( ArchivaRepository repo ) throws RepositoryException { - if ( !repo.isManaged() ) - { - throw new RepositoryException( "Unable to create RepositoryProjectResolver from non-managed repository: " - + repo ); - } - try { BidirectionalRepositoryLayout layout = layoutFactory.getLayout( repo.getLayoutType() ); @@ -127,8 +116,8 @@ public class ProjectModelResolverFactory } catch ( LayoutException e ) { - throw new RepositoryException( "Unable to create RepositoryProjectResolver due to invalid layout spec: " - + repo ); + throw new RepositoryException( + "Unable to create RepositoryProjectResolver due to invalid layout spec: " + repo ); } } @@ -138,15 +127,11 @@ public class ProjectModelResolverFactory { this.currentResolverStack.clearResolvers(); - List configLocalRepos = new ArrayList(); - CollectionUtils.select( archivaConfiguration.getConfiguration().getRepositories(), LocalRepositoryPredicate - .getInstance(), configLocalRepos ); - - Iterator it = configLocalRepos.iterator(); - while ( it.hasNext() ) + List<ManagedRepositoryConfiguration> list = + archivaConfiguration.getConfiguration().getManagedRepositories(); + for ( ManagedRepositoryConfiguration repositoryConfiguration : list ) { - RepositoryConfiguration repoconfig = (RepositoryConfiguration) it.next(); - ArchivaRepository repo = ArchivaConfigurationAdaptor.toArchivaRepository( repoconfig ); + ArchivaRepository repo = ArchivaConfigurationAdaptor.toArchivaRepository( repositoryConfiguration ); try { RepositoryProjectResolver resolver = toResolver( repo ); diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/DefaultRepositoryScanner.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/DefaultRepositoryScanner.java index 22ca95a7d..d9f513874 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/DefaultRepositoryScanner.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/DefaultRepositoryScanner.java @@ -34,11 +34,10 @@ import java.util.ArrayList; import java.util.List; /** - * DefaultRepositoryScanner + * DefaultRepositoryScanner * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ - * * @plexus.component role="org.apache.maven.archiva.repository.scanner.RepositoryScanner" */ public class DefaultRepositoryScanner @@ -75,7 +74,7 @@ public class DefaultRepositoryScanner throw new IllegalArgumentException( "Unable to operate on a null repository." ); } - if ( !repository.isManaged() ) + if ( !"file".equals( repository.getUrl().getProtocol() ) ) { throw new UnsupportedOperationException( "Only filesystem repositories are supported." ); } @@ -84,14 +83,14 @@ public class DefaultRepositoryScanner if ( !repositoryBase.exists() ) { - throw new UnsupportedOperationException( "Unable to scan a repository, directory " - + repositoryBase.getAbsolutePath() + " does not exist." ); + throw new UnsupportedOperationException( + "Unable to scan a repository, directory " + repositoryBase.getAbsolutePath() + " does not exist." ); } if ( !repositoryBase.isDirectory() ) { - throw new UnsupportedOperationException( "Unable to scan a repository, path " - + repositoryBase.getAbsolutePath() + " is not a directory." ); + throw new UnsupportedOperationException( + "Unable to scan a repository, path " + repositoryBase.getAbsolutePath() + " is not a directory." ); } // Setup Includes / Excludes. @@ -116,8 +115,8 @@ public class DefaultRepositoryScanner dirWalker.setExcludes( allExcludes ); // Setup the Scan Instance - RepositoryScannerInstance scannerInstance = new RepositoryScannerInstance( repository, knownContentConsumers, - invalidContentConsumers, getLogger() ); + RepositoryScannerInstance scannerInstance = + new RepositoryScannerInstance( repository, knownContentConsumers, invalidContentConsumers, getLogger() ); scannerInstance.setOnlyModifiedAfterTimestamp( changesSince ); dirWalker.addDirectoryWalkListener( scannerInstance ); diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/AbstractBidirectionalRepositoryLayoutTestCase.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/AbstractBidirectionalRepositoryLayoutTestCase.java index dfd63a985..e0c38757b 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/AbstractBidirectionalRepositoryLayoutTestCase.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/AbstractBidirectionalRepositoryLayoutTestCase.java @@ -30,12 +30,12 @@ import org.codehaus.plexus.PlexusTestCase; import java.io.File; /** - * AbstractBidirectionalRepositoryLayoutTestCase + * AbstractBidirectionalRepositoryLayoutTestCase * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ */ -public class AbstractBidirectionalRepositoryLayoutTestCase +public abstract class AbstractBidirectionalRepositoryLayoutTestCase extends PlexusTestCase { protected ArchivaRepository repository; @@ -60,9 +60,7 @@ public class AbstractBidirectionalRepositoryLayoutTestCase String repoUri = "file://" + StringUtils.replace( testRepo.getAbsolutePath(), "\\", "/" ); - ArchivaRepository repo = new ArchivaRepository( "testRepo", "Test Repository", repoUri ); - - return repo; + return new ArchivaRepository( "testRepo", "Test Repository", repoUri ); } protected ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier, @@ -94,8 +92,8 @@ public class AbstractBidirectionalRepositoryLayoutTestCase protected void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId, String version, String classifier, String type ) { - String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier - + ":" + type; + String expectedId = + "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type; assertNotNull( expectedId + " - Should not be null.", actualReference ); diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/AllTests.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/AllTests.java index 661a57a0c..30341b4c6 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/AllTests.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/AllTests.java @@ -23,19 +23,17 @@ import junit.framework.Test; import junit.framework.TestSuite; /** - * AllTests - Useful for developers using IDEs. + * AllTests - Useful for developers using IDEs. * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ */ public class AllTests { - public static Test suite() { TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.repository.layout" ); //$JUnit-BEGIN$ - suite.addTestSuite( AbstractBidirectionalRepositoryLayoutTestCase.class ); suite.addTestSuite( BidirectionalRepositoryLayoutFactoryTest.class ); suite.addTestSuite( LegacyBidirectionalRepositoryLayoutTest.class ); suite.addTestSuite( DefaultBidirectionalRepositoryLayoutTest.class ); diff --git a/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva-parent/1.0-SNAPSHOT/archiva-parent-1.0-SNAPSHOT.pom b/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva-parent/1.0-SNAPSHOT/archiva-parent-1.0-SNAPSHOT.pom index c3a69b1a2..970098384 100644 --- a/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva-parent/1.0-SNAPSHOT/archiva-parent-1.0-SNAPSHOT.pom +++ b/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva-parent/1.0-SNAPSHOT/archiva-parent-1.0-SNAPSHOT.pom @@ -492,7 +492,6 @@ <artifactId>cobertura-maven-plugin</artifactId> <configuration> <check> - <!-- TODO! raise to 85/100 --> <totalLineRate>77</totalLineRate> <totalBranchRate>95</totalBranchRate> </check> diff --git a/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva-webapp/1.0-SNAPSHOT/archiva-webapp-1.0-SNAPSHOT.pom b/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva-webapp/1.0-SNAPSHOT/archiva-webapp-1.0-SNAPSHOT.pom index 2d58dbf40..8304d2dd0 100644 --- a/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva-webapp/1.0-SNAPSHOT/archiva-webapp-1.0-SNAPSHOT.pom +++ b/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva-webapp/1.0-SNAPSHOT/archiva-webapp-1.0-SNAPSHOT.pom @@ -321,7 +321,6 @@ <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> - <!-- TODO! add unit tests --> <configuration> <instrumentation> <excludes> diff --git a/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva/1.0-SNAPSHOT/archiva-1.0-20061126.005254-2.pom b/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva/1.0-SNAPSHOT/archiva-1.0-20061126.005254-2.pom index b99001024..cf8e32963 100644 --- a/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva/1.0-SNAPSHOT/archiva-1.0-20061126.005254-2.pom +++ b/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva/1.0-SNAPSHOT/archiva-1.0-20061126.005254-2.pom @@ -74,13 +74,13 @@ </site>
</distributionManagement>
<build>
- <extensions>
- <extension>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-ssh-external</artifactId>
- <version>1.0-alpha-5</version>
- </extension>
- </extensions>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-ssh-external</artifactId>
+ <version>1.0-alpha-5</version>
+ </extension>
+ </extensions>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
@@ -431,7 +431,6 @@ <artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<check>
- <!-- TODO! raise to 85/100 -->
<totalLineRate>77</totalLineRate>
<totalBranchRate>95</totalBranchRate>
</check>
diff --git a/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva/1.0-SNAPSHOT/archiva-1.0-SNAPSHOT.pom b/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva/1.0-SNAPSHOT/archiva-1.0-SNAPSHOT.pom index 4992be115..31df31eda 100644 --- a/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva/1.0-SNAPSHOT/archiva-1.0-SNAPSHOT.pom +++ b/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/maven/archiva/archiva/1.0-SNAPSHOT/archiva-1.0-SNAPSHOT.pom @@ -483,7 +483,6 @@ <artifactId>cobertura-maven-plugin</artifactId> <configuration> <check> - <!-- TODO! raise to 85/100 --> <totalLineRate>77</totalLineRate> <totalBranchRate>95</totalBranchRate> </check> |