From: Olivier Lamy Date: Wed, 7 Sep 2011 20:33:48 +0000 (+0000) Subject: use beanlib for wrappers constructions X-Git-Tag: archiva-1.4-M1~363 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a2dd1fd1a42c97c3bb30ce4e7a4906a7e28b496c;p=archiva.git use beanlib for wrappers constructions git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1166391 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ProxyConnectorConfigurationOrderComparator.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ProxyConnectorConfigurationOrderComparator.java index 310967cf5..8db36e234 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ProxyConnectorConfigurationOrderComparator.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ProxyConnectorConfigurationOrderComparator.java @@ -24,6 +24,7 @@ import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import java.util.Comparator; /** + * @deprecated * ProxyConnectorConfigurationOrderComparator * * @version $Id$ diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ProxyConnectorSelectionPredicate.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ProxyConnectorSelectionPredicate.java index 6d5923446..2f7deddee 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ProxyConnectorSelectionPredicate.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ProxyConnectorSelectionPredicate.java @@ -24,8 +24,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; /** - * ProxyConnectorPredicate - * + * ProxyConnectorPredicate * @version $Id$ */ public class ProxyConnectorSelectionPredicate diff --git a/archiva-modules/archiva-base/archiva-repository-admin/pom.xml b/archiva-modules/archiva-base/archiva-repository-admin/pom.xml index 43abeecdc..2efa25bd2 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/pom.xml +++ b/archiva-modules/archiva-base/archiva-repository-admin/pom.xml @@ -47,7 +47,10 @@ javax.inject javax.inject - 1 + + + net.sf.beanlib + beanlib org.springframework diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java index 03ae1dfb9..d49e80744 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java @@ -18,6 +18,7 @@ package org.apache.archiva.admin.repository.proxyconnector; * under the License. */ +import net.sf.beanlib.provider.replicator.BeanReplicator; import org.apache.archiva.admin.AuditInformation; import org.apache.archiva.admin.repository.AbstractRepositoryAdmin; import org.apache.archiva.admin.repository.RepositoryAdminException; @@ -33,8 +34,11 @@ import org.springframework.stereotype.Service; import javax.inject.Inject; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; /** * @author Olivier Lamy @@ -150,8 +154,42 @@ public class DefaultProxyConnectorAdmin return rawPatterns; } - protected ProxyConnectorConfiguration findProxyConnector( String sourceId, String targetId, - Configuration configuration ) + public Map> getProxyConnectorAsMap() + throws RepositoryAdminException + { + java.util.Map> proxyConnectorMap = + new HashMap>(); + + Iterator it = getProxyConnectors().iterator(); + while ( it.hasNext() ) + { + ProxyConnector proxyConfig = it.next(); + String key = proxyConfig.getSourceRepoId(); + + java.util.List connectors = proxyConnectorMap.get( key ); + if ( connectors == null ) + { + connectors = new ArrayList(); + proxyConnectorMap.put( key, connectors ); + } + + connectors.add( proxyConfig ); + + Collections.sort( connectors, ProxyConnectorOrderComparator.getInstance() ); + } + + return proxyConnectorMap; + } + + public ProxyConnector findProxyConnector( String sourceId, String targetId ) + throws RepositoryAdminException + { + return getProxyConnector( + findProxyConnector( sourceId, targetId, getArchivaConfiguration().getConfiguration() ) ); + } + + private ProxyConnectorConfiguration findProxyConnector( String sourceId, String targetId, + Configuration configuration ) { if ( StringUtils.isBlank( sourceId ) ) { @@ -169,6 +207,7 @@ public class DefaultProxyConnectorAdmin protected ProxyConnectorConfiguration getProxyConnectorConfiguration( ProxyConnector proxyConnector ) { + /* ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration(); proxyConnectorConfiguration.setOrder( proxyConnector.getOrder() ); proxyConnectorConfiguration.setBlackListPatterns( @@ -181,7 +220,13 @@ public class DefaultProxyConnectorAdmin proxyConnectorConfiguration.setProxyId( proxyConnector.getProxyId() ); proxyConnectorConfiguration.setSourceRepoId( proxyConnector.getSourceRepoId() ); proxyConnectorConfiguration.setTargetRepoId( proxyConnector.getTargetRepoId() ); - return proxyConnectorConfiguration; + return proxyConnectorConfiguration;*/ + return new BeanReplicator().replicateBean( proxyConnector, ProxyConnectorConfiguration.class ); + } + + protected ProxyConnector getProxyConnector( ProxyConnectorConfiguration proxyConnectorConfiguration ) + { + return new BeanReplicator().replicateBean( proxyConnectorConfiguration, ProxyConnector.class ); } protected void validateProxyConnector( ProxyConnector proxyConnector ) diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdmin.java index e598eb28f..2eae5da1f 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdmin.java @@ -22,6 +22,7 @@ import org.apache.archiva.admin.AuditInformation; import org.apache.archiva.admin.repository.RepositoryAdminException; import java.util.List; +import java.util.Map; /** * No update method here as id is : sourceRepoId and targetRepoId, use delete then add. @@ -43,4 +44,10 @@ public interface ProxyConnectorAdmin Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation ) throws RepositoryAdminException; + Map> getProxyConnectorAsMap() + throws RepositoryAdminException; + + ProxyConnector findProxyConnector( String sourceId, String targetId ) + throws RepositoryAdminException; + } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorOrderComparator.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorOrderComparator.java new file mode 100644 index 000000000..3f8b0d05b --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorOrderComparator.java @@ -0,0 +1,68 @@ +package org.apache.archiva.admin.repository.proxyconnector; +/* + * 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 java.util.Comparator; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +public class ProxyConnectorOrderComparator + implements Comparator +{ + private static ProxyConnectorOrderComparator INSTANCE = new ProxyConnectorOrderComparator(); + + public int compare( ProxyConnector o1, ProxyConnector o2 ) + { + if ( o1 == null && o2 == null ) + { + return 0; + } + + // Ensure null goes to end of list. + if ( o1 == null && o2 != null ) + { + return 1; + } + + if ( o1 != null && o2 == null ) + { + return -1; + } + + // Ensure 0 (unordered) goes to end of list. + if ( o1.getOrder() == 0 && o2.getOrder() != 0 ) + { + return 1; + } + + if ( o1.getOrder() != 0 && o2.getOrder() == 0 ) + { + return -1; + } + + return o1.getOrder() - o2.getOrder(); + } + + public static ProxyConnectorOrderComparator getInstance() + { + return INSTANCE; + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorSelectionPredicate.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorSelectionPredicate.java new file mode 100644 index 000000000..01983b71d --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorSelectionPredicate.java @@ -0,0 +1,54 @@ +package org.apache.archiva.admin.repository.proxyconnector; +/* + * 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.commons.lang.StringUtils; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +public class ProxyConnectorSelectionPredicate + implements Predicate +{ + private String sourceId; + + private String targetId; + + public ProxyConnectorSelectionPredicate( String sourceId, String targetId ) + { + this.sourceId = sourceId; + this.targetId = targetId; + } + + public boolean evaluate( Object object ) + { + boolean satisfies = false; + + if ( object instanceof ProxyConnector ) + { + ProxyConnector connector = (ProxyConnector) object; + return ( StringUtils.equals( sourceId, connector.getSourceRepoId() ) && StringUtils.equals( targetId, + connector.getTargetRepoId() ) ); + } + + return satisfies; + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java index 732a479a0..a2c83a473 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java @@ -29,7 +29,9 @@ import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @author Olivier Lamy @@ -159,6 +161,19 @@ public class DefaultRemoteRepositoryAdmin return Boolean.TRUE; } + public Map getRemoteRepositoriesAsMap() + throws RepositoryAdminException + { + java.util.Map map = new HashMap(); + + for ( RemoteRepository repo : getRemoteRepositories() ) + { + map.put( repo.getId(), repo ); + } + + return map; + } + private RemoteRepositoryConfiguration getRemoteRepositoryConfiguration( RemoteRepository remoteRepository ) { RemoteRepositoryConfiguration remoteRepositoryConfiguration = new RemoteRepositoryConfiguration(); diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdmin.java index 3adde318f..15218ba8d 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdmin.java @@ -23,6 +23,7 @@ import org.apache.archiva.admin.AuditInformation; import org.apache.archiva.admin.repository.RepositoryAdminException; import java.util.List; +import java.util.Map; /** * @author Olivier Lamy @@ -44,4 +45,7 @@ public interface RemoteRepositoryAdmin Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation ) throws RepositoryAdminException; + + Map getRemoteRepositoriesAsMap() + throws RepositoryAdminException; } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdminTest.java index 4cedef2b0..97b0b12d3 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdminTest.java @@ -23,6 +23,8 @@ import org.apache.archiva.admin.repository.remote.RemoteRepository; import org.apache.archiva.audit.AuditEvent; import org.junit.Test; +import java.util.Arrays; + /** * @author Olivier Lamy */ @@ -81,12 +83,15 @@ public class ProxyConnectorAdminTest ProxyConnector proxyConnector = new ProxyConnector(); proxyConnector.setSourceRepoId( "snapshots" ); proxyConnector.setTargetRepoId( "central" ); + proxyConnector.setWhiteListPatterns( Arrays.asList( "foo", "bar" ) ); proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() ); assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() ); assertEquals( 3, proxyConnectorAdmin.getProxyConnectors().size() ); assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) ); + assertEquals( Arrays.asList( "foo", "bar" ), + proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ).getWhiteListPatterns() ); proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() ); @@ -123,4 +128,12 @@ public class ProxyConnectorAdminTest mockAuditListener.clearEvents(); } + @Test + public void findProxyConnector() + throws Exception + { + ProxyConnector proxyConnector = proxyConnectorAdmin.findProxyConnector( "internal", "central" ); + assertNotNull( proxyConnector ); + } + } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorAction.java index 979c6b88f..bf5729cff 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorAction.java @@ -19,29 +19,25 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; * under the License. */ +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.proxyconnector.ProxyConnector; +import org.apache.archiva.admin.repository.proxyconnector.ProxyConnectorAdmin; +import org.apache.archiva.admin.repository.remote.RemoteRepositoryAdmin; import org.apache.archiva.security.common.ArchivaRoleConstants; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.functors.NotPredicate; import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.Configuration; -import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; -import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; -import org.apache.maven.archiva.configuration.functors.ProxyConnectorSelectionPredicate; import org.apache.maven.archiva.web.action.AbstractActionSupport; import org.codehaus.plexus.redback.rbac.Resource; -import org.codehaus.plexus.registry.RegistryException; - -import java.util.List; -import java.util.Map; import org.codehaus.redback.integration.interceptor.SecureAction; import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionException; import javax.inject.Inject; +import java.util.List; +import java.util.Map; /** - * AbstractProxyConnectorAction + * AbstractProxyConnectorAction * * @version $Id$ */ @@ -52,7 +48,13 @@ public abstract class AbstractProxyConnectorAction public static final String DIRECT_CONNECTION = "(direct connection)"; @Inject - protected ArchivaConfiguration archivaConfiguration; + private ProxyConnectorAdmin proxyConnectorAdmin; + + @Inject + private RemoteRepositoryAdmin remoteRepositoryAdmin; + + @Inject + private ManagedRepositoryAdmin managedRepositoryAdmin; public SecureActionBundle getSecureActionBundle() throws SecureActionException @@ -65,17 +67,15 @@ public abstract class AbstractProxyConnectorAction return bundle; } - public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) - { - this.archivaConfiguration = archivaConfiguration; - } - protected void addProxyConnector( ProxyConnectorConfiguration proxyConnector ) + protected void addProxyConnector( ProxyConnector proxyConnector ) + throws RepositoryAdminException { - getConfig().addProxyConnector( proxyConnector ); + getProxyConnectorAdmin().addProxyConnector( proxyConnector, getAuditInformation() ); } - protected ProxyConnectorConfiguration findProxyConnector( String sourceId, String targetId ) + protected ProxyConnector findProxyConnector( String sourceId, String targetId ) + throws RepositoryAdminException { if ( StringUtils.isBlank( sourceId ) ) { @@ -87,50 +87,59 @@ public abstract class AbstractProxyConnectorAction return null; } - ProxyConnectorSelectionPredicate selectedProxy = new ProxyConnectorSelectionPredicate( sourceId, targetId ); - return (ProxyConnectorConfiguration) CollectionUtils.find( getConfig().getProxyConnectors(), selectedProxy ); + return getProxyConnectorAdmin().findProxyConnector( sourceId, targetId ); } - protected Configuration getConfig() + protected Map> createProxyConnectorMap() + throws RepositoryAdminException { - return this.archivaConfiguration.getConfiguration(); + return getProxyConnectorAdmin().getProxyConnectorAsMap(); } - protected Map> createProxyConnectorMap() + protected void removeConnector( String sourceId, String targetId ) + throws RepositoryAdminException { - return getConfig().getProxyConnectorAsMap(); + ProxyConnector proxyConnector = findProxyConnector( sourceId, targetId ); + if ( proxyConnector != null ) + { + getProxyConnectorAdmin().deleteProxyConnector( proxyConnector, getAuditInformation() ); + } } - protected void removeConnector( String sourceId, String targetId ) + protected void removeProxyConnector( ProxyConnector connector ) + throws RepositoryAdminException { - ProxyConnectorSelectionPredicate selectedProxy = new ProxyConnectorSelectionPredicate( sourceId, targetId ); - NotPredicate notSelectedProxy = new NotPredicate( selectedProxy ); - CollectionUtils.filter( getConfig().getProxyConnectors(), notSelectedProxy ); + getProxyConnectorAdmin().deleteProxyConnector( connector, getAuditInformation() ); } - protected void removeProxyConnector( ProxyConnectorConfiguration connector ) + + public ProxyConnectorAdmin getProxyConnectorAdmin() { - getConfig().removeProxyConnector( connector ); + return proxyConnectorAdmin; } - protected String saveConfiguration() + public void setProxyConnectorAdmin( ProxyConnectorAdmin proxyConnectorAdmin ) { - try - { - archivaConfiguration.save( getConfig() ); - addActionMessage( "Successfully saved configuration" ); - } - catch ( RegistryException e ) - { - addActionError( "Unable to save configuration: " + e.getMessage() ); - return INPUT; - } - catch ( IndeterminateConfigurationException e ) - { - addActionError( e.getMessage() ); - return INPUT; - } + this.proxyConnectorAdmin = proxyConnectorAdmin; + } + + public RemoteRepositoryAdmin getRemoteRepositoryAdmin() + { + return remoteRepositoryAdmin; + } + + public void setRemoteRepositoryAdmin( RemoteRepositoryAdmin remoteRepositoryAdmin ) + { + this.remoteRepositoryAdmin = remoteRepositoryAdmin; + } - return SUCCESS; + public ManagedRepositoryAdmin getManagedRepositoryAdmin() + { + return managedRepositoryAdmin; + } + + public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin ) + { + this.managedRepositoryAdmin = managedRepositoryAdmin; } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java index e5f05fdda..5a44dea36 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java @@ -19,27 +19,26 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; * under the License. */ -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.google.common.collect.Lists; -import org.apache.archiva.audit.AuditListener; +import com.opensymphony.xwork2.Preparable; +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.proxyconnector.ProxyConnector; import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.policies.DownloadErrorPolicy; import org.apache.maven.archiva.policies.Policy; import org.apache.maven.archiva.policies.PostDownloadPolicy; import org.apache.maven.archiva.policies.PreDownloadPolicy; -import com.opensymphony.xwork2.Preparable; - import javax.annotation.PostConstruct; +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** - * AbstractProxyConnectorFormAction - generic fields and methods for either add or edit actions related with the - * Proxy Connector. + * AbstractProxyConnectorFormAction - generic fields and methods for either add or edit actions related with the + * Proxy Connector. * * @version $Id$ */ @@ -94,8 +93,10 @@ public abstract class AbstractProxyConnectorFormAction /** * The model for this action. */ - protected ProxyConnectorConfiguration connector; + protected ProxyConnector connector; + @Inject + private ArchivaConfiguration archivaConfiguration; @PostConstruct public void initialize() @@ -107,38 +108,38 @@ public abstract class AbstractProxyConnectorFormAction } protected List escapePatterns( List patterns ) - { + { List escapedPatterns = new ArrayList(); - if( patterns != null ) + if ( patterns != null ) { - for( String pattern : patterns ) + for ( String pattern : patterns ) { escapedPatterns.add( StringUtils.replace( pattern, "\\", "\\\\" ) ); } } - + return escapedPatterns; } - + protected List unescapePatterns( List patterns ) { List rawPatterns = new ArrayList(); - if( patterns != null ) + if ( patterns != null ) { - for( String pattern : patterns ) + for ( String pattern : patterns ) { rawPatterns.add( StringUtils.replace( pattern, "\\\\", "\\" ) ); } } - + return rawPatterns; } - + private String escapePattern( String pattern ) { return StringUtils.replace( pattern, "\\", "\\\\" ); } - + public String addBlackListPattern() { String pattern = getBlackListPattern(); @@ -147,17 +148,17 @@ public abstract class AbstractProxyConnectorFormAction { addActionError( "Cannot add a blank black list pattern." ); } - + if ( !hasActionErrors() ) { getConnector().getBlackListPatterns().add( escapePattern( pattern ) ); setBlackListPattern( null ); } - + return INPUT; } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) public String addProperty() { String key = getPropertyKey(); @@ -197,7 +198,7 @@ public abstract class AbstractProxyConnectorFormAction getConnector().getWhiteListPatterns().add( escapePattern( pattern ) ); setWhiteListPattern( null ); } - + return INPUT; } @@ -206,7 +207,7 @@ public abstract class AbstractProxyConnectorFormAction return blackListPattern; } - public ProxyConnectorConfiguration getConnector() + public ProxyConnector getConnector() { return connector; } @@ -252,6 +253,7 @@ public abstract class AbstractProxyConnectorFormAction } public void prepare() + throws RepositoryAdminException { proxyIdOptions = createNetworkProxyOptions(); managedRepoIdList = createManagedRepoOptions(); @@ -262,14 +264,14 @@ public abstract class AbstractProxyConnectorFormAction public String removeBlackListPattern() { String pattern = getPattern(); - + if ( StringUtils.isBlank( pattern ) ) { addActionError( "Cannot remove a blank black list pattern." ); } - if ( !getConnector().getBlackListPatterns().contains( pattern ) && - !getConnector().getBlackListPatterns().contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) ) + if ( !getConnector().getBlackListPatterns().contains( pattern ) + && !getConnector().getBlackListPatterns().contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) ) { addActionError( "Non-existant black list pattern [" + pattern + "], no black list pattern removed." ); } @@ -319,8 +321,8 @@ public abstract class AbstractProxyConnectorFormAction addActionError( "Cannot remove a blank white list pattern." ); } - if ( !getConnector().getWhiteListPatterns().contains( pattern ) && - !getConnector().getWhiteListPatterns().contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) ) + if ( !getConnector().getWhiteListPatterns().contains( pattern ) + && !getConnector().getWhiteListPatterns().contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) ) { addActionError( "Non-existant white list pattern [" + pattern + "], no white list pattern removed." ); } @@ -341,7 +343,7 @@ public abstract class AbstractProxyConnectorFormAction this.blackListPattern = blackListPattern; } - public void setConnector( ProxyConnectorConfiguration connector ) + public void setConnector( ProxyConnector connector ) { this.connector = connector; } @@ -387,8 +389,9 @@ public abstract class AbstractProxyConnectorFormAction } protected List createManagedRepoOptions() + throws RepositoryAdminException { - return new ArrayList( getConfig().getManagedRepositoriesAsMap().keySet() ); + return new ArrayList( getManagedRepositoryAdmin().getManagedRepositoriesAsMap().keySet() ); } protected List createNetworkProxyOptions() @@ -396,7 +399,7 @@ public abstract class AbstractProxyConnectorFormAction List options = new ArrayList(); options.add( DIRECT_CONNECTION ); - options.addAll( getConfig().getNetworkProxiesAsMap().keySet() ); + options.addAll( archivaConfiguration.getConfiguration().getNetworkProxiesAsMap().keySet() ); return options; } @@ -413,11 +416,12 @@ public abstract class AbstractProxyConnectorFormAction } protected List createRemoteRepoOptions() + throws RepositoryAdminException { - return new ArrayList( getConfig().getRemoteRepositoriesAsMap().keySet() ); + return new ArrayList( getRemoteRepositoryAdmin().getRemoteRepositoriesAsMap().keySet() ); } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) protected void validateConnector() { if ( connector.getPolicies() == null ) @@ -439,8 +443,8 @@ public abstract class AbstractProxyConnectorFormAction continue; } - Map properties = connector.getProperties(); - for ( Map.Entry entry2 : properties.entrySet()) + Map properties = connector.getProperties(); + for ( Map.Entry entry2 : properties.entrySet() ) { Object value = entry2.getValue(); if ( value.getClass().isArray() ) @@ -473,11 +477,21 @@ public abstract class AbstractProxyConnectorFormAction if ( !options.contains( value ) ) { - addActionError( "Value of [" + value + "] is invalid for policy [" + policyId + "], valid values: " - + options ); + addActionError( + "Value of [" + value + "] is invalid for policy [" + policyId + "], valid values: " + options ); continue; } } } } + + public ArchivaConfiguration getArchivaConfiguration() + { + return archivaConfiguration; + } + + public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) + { + this.archivaConfiguration = archivaConfiguration; + } } diff --git a/pom.xml b/pom.xml index bb08b6e55..135ccf522 100644 --- a/pom.xml +++ b/pom.xml @@ -460,6 +460,11 @@ stax 1.2.0 + + net.sf.beanlib + beanlib + 5.0.2beta + commons-codec commons-codec