import java.util.Comparator;
/**
+ * @deprecated
* ProxyConnectorConfigurationOrderComparator
*
* @version $Id$
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
/**
- * ProxyConnectorPredicate
- *
+ * ProxyConnectorPredicate
* @version $Id$
*/
public class ProxyConnectorSelectionPredicate
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
- <version>1</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.beanlib</groupId>
+ <artifactId>beanlib</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
* 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;
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
return rawPatterns;
}
- protected ProxyConnectorConfiguration findProxyConnector( String sourceId, String targetId,
- Configuration configuration )
+ public Map<String, List<ProxyConnector>> getProxyConnectorAsMap()
+ throws RepositoryAdminException
+ {
+ java.util.Map<String, List<ProxyConnector>> proxyConnectorMap =
+ new HashMap<String, java.util.List<ProxyConnector>>();
+
+ Iterator<ProxyConnector> it = getProxyConnectors().iterator();
+ while ( it.hasNext() )
+ {
+ ProxyConnector proxyConfig = it.next();
+ String key = proxyConfig.getSourceRepoId();
+
+ java.util.List<ProxyConnector> connectors = proxyConnectorMap.get( key );
+ if ( connectors == null )
+ {
+ connectors = new ArrayList<ProxyConnector>();
+ 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 ) )
{
protected ProxyConnectorConfiguration getProxyConnectorConfiguration( ProxyConnector proxyConnector )
{
+ /*
ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration();
proxyConnectorConfiguration.setOrder( proxyConnector.getOrder() );
proxyConnectorConfiguration.setBlackListPatterns(
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 )
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.
Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
throws RepositoryAdminException;
+ Map<String, List<ProxyConnector>> getProxyConnectorAsMap()
+ throws RepositoryAdminException;
+
+ ProxyConnector findProxyConnector( String sourceId, String targetId )
+ throws RepositoryAdminException;
+
}
--- /dev/null
+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<ProxyConnector>
+{
+ 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;
+ }
+}
--- /dev/null
+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;
+ }
+}
import org.springframework.stereotype.Service;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* @author Olivier Lamy
return Boolean.TRUE;
}
+ public Map<String, RemoteRepository> getRemoteRepositoriesAsMap()
+ throws RepositoryAdminException
+ {
+ java.util.Map<String, RemoteRepository> map = new HashMap<String, RemoteRepository>();
+
+ for ( RemoteRepository repo : getRemoteRepositories() )
+ {
+ map.put( repo.getId(), repo );
+ }
+
+ return map;
+ }
+
private RemoteRepositoryConfiguration getRemoteRepositoryConfiguration( RemoteRepository remoteRepository )
{
RemoteRepositoryConfiguration remoteRepositoryConfiguration = new RemoteRepositoryConfiguration();
import org.apache.archiva.admin.repository.RepositoryAdminException;
import java.util.List;
+import java.util.Map;
/**
* @author Olivier Lamy
Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
throws RepositoryAdminException;
+
+ Map<String, RemoteRepository> getRemoteRepositoriesAsMap()
+ throws RepositoryAdminException;
}
import org.apache.archiva.audit.AuditEvent;
import org.junit.Test;
+import java.util.Arrays;
+
/**
* @author Olivier Lamy
*/
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() );
mockAuditListener.clearEvents();
}
+ @Test
+ public void findProxyConnector()
+ throws Exception
+ {
+ ProxyConnector proxyConnector = proxyConnectorAdmin.findProxyConnector( "internal", "central" );
+ assertNotNull( proxyConnector );
+ }
+
}
* 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$
*/
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
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 ) )
{
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<String, List<ProxyConnector>> createProxyConnectorMap()
+ throws RepositoryAdminException
{
- return this.archivaConfiguration.getConfiguration();
+ return getProxyConnectorAdmin().getProxyConnectorAsMap();
}
- protected Map<String, List<ProxyConnectorConfiguration>> 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;
}
}
* 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$
*/
/**
* The model for this action.
*/
- protected ProxyConnectorConfiguration connector;
+ protected ProxyConnector connector;
+ @Inject
+ private ArchivaConfiguration archivaConfiguration;
@PostConstruct
public void initialize()
}
protected List<String> escapePatterns( List<String> patterns )
- {
+ {
List<String> escapedPatterns = new ArrayList<String>();
- if( patterns != null )
+ if ( patterns != null )
{
- for( String pattern : patterns )
+ for ( String pattern : patterns )
{
escapedPatterns.add( StringUtils.replace( pattern, "\\", "\\\\" ) );
}
}
-
+
return escapedPatterns;
}
-
+
protected List<String> unescapePatterns( List<String> patterns )
{
List<String> rawPatterns = new ArrayList<String>();
- 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();
{
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();
getConnector().getWhiteListPatterns().add( escapePattern( pattern ) );
setWhiteListPattern( null );
}
-
+
return INPUT;
}
return blackListPattern;
}
- public ProxyConnectorConfiguration getConnector()
+ public ProxyConnector getConnector()
{
return connector;
}
}
public void prepare()
+ throws RepositoryAdminException
{
proxyIdOptions = createNetworkProxyOptions();
managedRepoIdList = createManagedRepoOptions();
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." );
}
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." );
}
this.blackListPattern = blackListPattern;
}
- public void setConnector( ProxyConnectorConfiguration connector )
+ public void setConnector( ProxyConnector connector )
{
this.connector = connector;
}
}
protected List<String> createManagedRepoOptions()
+ throws RepositoryAdminException
{
- return new ArrayList<String>( getConfig().getManagedRepositoriesAsMap().keySet() );
+ return new ArrayList<String>( getManagedRepositoryAdmin().getManagedRepositoriesAsMap().keySet() );
}
protected List<String> createNetworkProxyOptions()
List<String> options = new ArrayList<String>();
options.add( DIRECT_CONNECTION );
- options.addAll( getConfig().getNetworkProxiesAsMap().keySet() );
+ options.addAll( archivaConfiguration.getConfiguration().getNetworkProxiesAsMap().keySet() );
return options;
}
}
protected List<String> createRemoteRepoOptions()
+ throws RepositoryAdminException
{
- return new ArrayList<String>( getConfig().getRemoteRepositoriesAsMap().keySet() );
+ return new ArrayList<String>( getRemoteRepositoryAdmin().getRemoteRepositoriesAsMap().keySet() );
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
protected void validateConnector()
{
if ( connector.getPolicies() == null )
continue;
}
- Map<String, Object> properties = connector.getProperties();
- for ( Map.Entry<String, Object> entry2 : properties.entrySet())
+ Map<String, String> properties = connector.getProperties();
+ for ( Map.Entry<String, String> entry2 : properties.entrySet() )
{
Object value = entry2.getValue();
if ( value.getClass().isArray() )
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;
+ }
}
<artifactId>stax</artifactId>
<version>1.2.0</version>
</dependency>
+ <dependency>
+ <groupId>net.sf.beanlib</groupId>
+ <artifactId>beanlib</artifactId>
+ <version>5.0.2beta</version>
+ </dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>