mirror of
https://github.com/apache/archiva.git
synced 2025-02-21 01:15:08 +00:00
use beanlib for wrappers constructions
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1166391 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
06a1782dcd
commit
a2dd1fd1a4
@ -24,6 +24,7 @@
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* ProxyConnectorConfigurationOrderComparator
|
||||
*
|
||||
* @version $Id$
|
||||
|
@ -24,8 +24,7 @@
|
||||
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
|
||||
|
||||
/**
|
||||
* ProxyConnectorPredicate
|
||||
*
|
||||
* ProxyConnectorPredicate
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ProxyConnectorSelectionPredicate
|
||||
|
@ -47,7 +47,10 @@
|
||||
<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>
|
||||
|
@ -18,6 +18,7 @@
|
||||
* 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 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 @@ protected List<String> unescapePatterns( List<String> patterns )
|
||||
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 ) )
|
||||
{
|
||||
@ -169,6 +207,7 @@ protected ProxyConnectorConfiguration findProxyConnector( String sourceId, Strin
|
||||
|
||||
protected ProxyConnectorConfiguration getProxyConnectorConfiguration( ProxyConnector proxyConnector )
|
||||
{
|
||||
/*
|
||||
ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration();
|
||||
proxyConnectorConfiguration.setOrder( proxyConnector.getOrder() );
|
||||
proxyConnectorConfiguration.setBlackListPatterns(
|
||||
@ -181,7 +220,13 @@ protected ProxyConnectorConfiguration getProxyConnectorConfiguration( ProxyConne
|
||||
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 )
|
||||
|
@ -22,6 +22,7 @@
|
||||
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 @@ Boolean addProxyConnector( ProxyConnector proxyConnector, AuditInformation audit
|
||||
Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
|
||||
throws RepositoryAdminException;
|
||||
|
||||
Map<String, List<ProxyConnector>> getProxyConnectorAsMap()
|
||||
throws RepositoryAdminException;
|
||||
|
||||
ProxyConnector findProxyConnector( String sourceId, String targetId )
|
||||
throws RepositoryAdminException;
|
||||
|
||||
}
|
||||
|
@ -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<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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -29,7 +29,9 @@
|
||||
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 Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditI
|
||||
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();
|
||||
|
@ -23,6 +23,7 @@
|
||||
import org.apache.archiva.admin.repository.RepositoryAdminException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
@ -44,4 +45,7 @@ Boolean addRemoteRepository( RemoteRepository remoteRepository, AuditInformation
|
||||
|
||||
Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
|
||||
throws RepositoryAdminException;
|
||||
|
||||
Map<String, RemoteRepository> getRemoteRepositoriesAsMap()
|
||||
throws RepositoryAdminException;
|
||||
}
|
||||
|
@ -23,6 +23,8 @@
|
||||
import org.apache.archiva.audit.AuditEvent;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
*/
|
||||
@ -81,12 +83,15 @@ public void addAndUpdateAndDelete()
|
||||
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 void addAndUpdateAndDelete()
|
||||
mockAuditListener.clearEvents();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findProxyConnector()
|
||||
throws Exception
|
||||
{
|
||||
ProxyConnector proxyConnector = proxyConnectorAdmin.findProxyConnector( "internal", "central" );
|
||||
assertNotNull( proxyConnector );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,29 +19,25 @@
|
||||
* 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 SecureActionBundle getSecureActionBundle()
|
||||
return bundle;
|
||||
}
|
||||
|
||||
public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
|
||||
|
||||
protected void addProxyConnector( ProxyConnector proxyConnector )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
this.archivaConfiguration = archivaConfiguration;
|
||||
getProxyConnectorAdmin().addProxyConnector( proxyConnector, getAuditInformation() );
|
||||
}
|
||||
|
||||
protected void addProxyConnector( ProxyConnectorConfiguration proxyConnector )
|
||||
{
|
||||
getConfig().addProxyConnector( proxyConnector );
|
||||
}
|
||||
|
||||
protected ProxyConnectorConfiguration findProxyConnector( String sourceId, String targetId )
|
||||
protected ProxyConnector findProxyConnector( String sourceId, String targetId )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
if ( StringUtils.isBlank( sourceId ) )
|
||||
{
|
||||
@ -87,50 +87,59 @@ protected ProxyConnectorConfiguration findProxyConnector( String sourceId, Strin
|
||||
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();
|
||||
}
|
||||
|
||||
protected Map<String, List<ProxyConnectorConfiguration>> createProxyConnectorMap()
|
||||
{
|
||||
return getConfig().getProxyConnectorAsMap();
|
||||
return getProxyConnectorAdmin().getProxyConnectorAsMap();
|
||||
}
|
||||
|
||||
protected void removeConnector( String sourceId, String targetId )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
ProxyConnectorSelectionPredicate selectedProxy = new ProxyConnectorSelectionPredicate( sourceId, targetId );
|
||||
NotPredicate notSelectedProxy = new NotPredicate( selectedProxy );
|
||||
CollectionUtils.filter( getConfig().getProxyConnectors(), notSelectedProxy );
|
||||
ProxyConnector proxyConnector = findProxyConnector( sourceId, targetId );
|
||||
if ( proxyConnector != null )
|
||||
{
|
||||
getProxyConnectorAdmin().deleteProxyConnector( proxyConnector, getAuditInformation() );
|
||||
}
|
||||
}
|
||||
|
||||
protected void removeProxyConnector( ProxyConnectorConfiguration connector )
|
||||
protected void removeProxyConnector( ProxyConnector connector )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
getConfig().removeProxyConnector( connector );
|
||||
getProxyConnectorAdmin().deleteProxyConnector( connector, getAuditInformation() );
|
||||
}
|
||||
|
||||
protected String saveConfiguration()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
public ProxyConnectorAdmin getProxyConnectorAdmin()
|
||||
{
|
||||
return proxyConnectorAdmin;
|
||||
}
|
||||
|
||||
public void setProxyConnectorAdmin( ProxyConnectorAdmin proxyConnectorAdmin )
|
||||
{
|
||||
this.proxyConnectorAdmin = proxyConnectorAdmin;
|
||||
}
|
||||
|
||||
public RemoteRepositoryAdmin getRemoteRepositoryAdmin()
|
||||
{
|
||||
return remoteRepositoryAdmin;
|
||||
}
|
||||
|
||||
public void setRemoteRepositoryAdmin( RemoteRepositoryAdmin remoteRepositoryAdmin )
|
||||
{
|
||||
this.remoteRepositoryAdmin = remoteRepositoryAdmin;
|
||||
}
|
||||
|
||||
public ManagedRepositoryAdmin getManagedRepositoryAdmin()
|
||||
{
|
||||
return managedRepositoryAdmin;
|
||||
}
|
||||
|
||||
public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
|
||||
{
|
||||
this.managedRepositoryAdmin = managedRepositoryAdmin;
|
||||
}
|
||||
}
|
||||
|
@ -19,27 +19,26 @@
|
||||
* 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 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();
|
||||
@ -147,17 +148,17 @@ public String addBlackListPattern()
|
||||
{
|
||||
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 String addWhiteListPattern()
|
||||
getConnector().getWhiteListPatterns().add( escapePattern( pattern ) );
|
||||
setWhiteListPattern( null );
|
||||
}
|
||||
|
||||
|
||||
return INPUT;
|
||||
}
|
||||
|
||||
@ -206,7 +207,7 @@ public String getBlackListPattern()
|
||||
return blackListPattern;
|
||||
}
|
||||
|
||||
public ProxyConnectorConfiguration getConnector()
|
||||
public ProxyConnector getConnector()
|
||||
{
|
||||
return connector;
|
||||
}
|
||||
@ -252,6 +253,7 @@ public String getWhiteListPattern()
|
||||
}
|
||||
|
||||
public void prepare()
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
proxyIdOptions = createNetworkProxyOptions();
|
||||
managedRepoIdList = createManagedRepoOptions();
|
||||
@ -262,14 +264,14 @@ public void prepare()
|
||||
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 String removeWhiteListPattern()
|
||||
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 void setBlackListPattern( String blackListPattern )
|
||||
this.blackListPattern = blackListPattern;
|
||||
}
|
||||
|
||||
public void setConnector( ProxyConnectorConfiguration connector )
|
||||
public void setConnector( ProxyConnector connector )
|
||||
{
|
||||
this.connector = connector;
|
||||
}
|
||||
@ -387,8 +389,9 @@ public void setWhiteListPattern( String whiteListPattern )
|
||||
}
|
||||
|
||||
protected List<String> createManagedRepoOptions()
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
return new ArrayList<String>( getConfig().getManagedRepositoriesAsMap().keySet() );
|
||||
return new ArrayList<String>( getManagedRepositoryAdmin().getManagedRepositoriesAsMap().keySet() );
|
||||
}
|
||||
|
||||
protected List<String> createNetworkProxyOptions()
|
||||
@ -396,7 +399,7 @@ 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;
|
||||
}
|
||||
@ -413,11 +416,12 @@ protected Map<String, Policy> createPolicyMap()
|
||||
}
|
||||
|
||||
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 )
|
||||
@ -439,8 +443,8 @@ protected void validateConnector()
|
||||
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() )
|
||||
@ -473,11 +477,21 @@ protected void validateConnector()
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
5
pom.xml
5
pom.xml
@ -460,6 +460,11 @@
|
||||
<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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user