mirror of https://github.com/apache/archiva.git
[MRM-494] leaving repository ID blank on the add repository page goes to the edit page where ID cannot be edited
Overhauled repository admin actions to be more consistent with best practices. Split into seperate actions. Added -validation.xml files. Added unit tests. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@579417 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6b825688e0
commit
0af7305111
|
@ -0,0 +1,107 @@
|
||||||
|
package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.io.FileUtils;
|
||||||
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
|
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
|
import org.codehaus.plexus.redback.role.RoleManager;
|
||||||
|
import org.codehaus.plexus.redback.role.RoleManagerException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract ManagedRepositories Action.
|
||||||
|
*
|
||||||
|
* Place for all generic methods used in Managed Repository Administration.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public abstract class AbstractManagedRepositoriesAction
|
||||||
|
extends AbstractRepositoriesAdminAction
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @plexus.requirement role-hint="default"
|
||||||
|
*/
|
||||||
|
protected RoleManager roleManager;
|
||||||
|
|
||||||
|
public RoleManager getRoleManager()
|
||||||
|
{
|
||||||
|
return roleManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleManager( RoleManager roleManager )
|
||||||
|
{
|
||||||
|
this.roleManager = roleManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
// Normalize the path
|
||||||
|
File file = new File( repository.getLocation() );
|
||||||
|
repository.setLocation( file.getCanonicalPath() );
|
||||||
|
if ( !file.exists() )
|
||||||
|
{
|
||||||
|
file.mkdirs();
|
||||||
|
}
|
||||||
|
if ( !file.exists() || !file.isDirectory() )
|
||||||
|
{
|
||||||
|
throw new IOException( "unable to add repository - can not create the root directory: " + file );
|
||||||
|
}
|
||||||
|
|
||||||
|
configuration.addManagedRepository( repository );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addRepositoryRoles( ManagedRepositoryConfiguration newRepository ) throws RoleManagerException
|
||||||
|
{
|
||||||
|
// TODO: double check these are configured on start up
|
||||||
|
// TODO: belongs in the business logic
|
||||||
|
roleManager.createTemplatedRole( "archiva-repository-manager", newRepository.getId() );
|
||||||
|
roleManager.createTemplatedRole( "archiva-repository-observer", newRepository.getId() );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void removeContents( ManagedRepositoryConfiguration existingRepository )
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
FileUtils.deleteDirectory( new File( existingRepository.getLocation() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void removeRepository( String repoId, Configuration configuration )
|
||||||
|
{
|
||||||
|
ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( repoId );
|
||||||
|
if ( toremove != null )
|
||||||
|
{
|
||||||
|
configuration.removeManagedRepository( toremove );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository )
|
||||||
|
throws RoleManagerException
|
||||||
|
{
|
||||||
|
roleManager.removeTemplatedRole( "archiva-repository-manager", existingRepository.getId() );
|
||||||
|
roleManager.removeTemplatedRole( "archiva-repository-observer", existingRepository.getId() );
|
||||||
|
|
||||||
|
getLogger().debug( "removed user roles associated with repository " + existingRepository.getId() );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
|
|
||||||
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
|
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
|
||||||
|
import org.codehaus.plexus.redback.role.RoleManagerException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AbstractRemoteRepositoriesAction
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class AbstractRemoteRepositoriesAction
|
||||||
|
extends AbstractRepositoriesAdminAction
|
||||||
|
{
|
||||||
|
protected void addRepository( RemoteRepositoryConfiguration repository, Configuration configuration )
|
||||||
|
throws IOException, RoleManagerException
|
||||||
|
{
|
||||||
|
configuration.addRemoteRepository( repository );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void removeRepository( String repoId, Configuration configuration )
|
||||||
|
{
|
||||||
|
RemoteRepositoryConfiguration toremove = configuration.findRemoteRepositoryById( repoId );
|
||||||
|
if ( toremove != null )
|
||||||
|
{
|
||||||
|
configuration.removeRemoteRepository( toremove );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,14 +19,12 @@ package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.archiva.configuration.AbstractRepositoryConfiguration;
|
|
||||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.maven.archiva.configuration.Configuration;
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
|
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
|
||||||
import org.apache.maven.archiva.configuration.InvalidConfigurationException;
|
import org.apache.maven.archiva.configuration.InvalidConfigurationException;
|
||||||
import org.apache.maven.archiva.security.ArchivaRoleConstants;
|
import org.apache.maven.archiva.security.ArchivaRoleConstants;
|
||||||
import org.codehaus.plexus.redback.rbac.Resource;
|
import org.codehaus.plexus.redback.rbac.Resource;
|
||||||
import org.codehaus.plexus.redback.role.RoleManagerException;
|
|
||||||
import org.codehaus.plexus.redback.xwork.interceptor.SecureAction;
|
import org.codehaus.plexus.redback.xwork.interceptor.SecureAction;
|
||||||
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
|
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
|
||||||
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
|
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
|
||||||
|
@ -36,32 +34,26 @@ import org.codehaus.plexus.xwork.action.PlexusActionSupport;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for repository configuration actions.
|
* Abstract AdminRepositories Action base.
|
||||||
|
*
|
||||||
|
* Base class for all repository administrative functions.
|
||||||
|
* This should be neutral to the type of action (add/edit/delete) and type of repo (managed/remote)
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractConfigureRepositoryAction<T extends AbstractRepositoryConfiguration>
|
public abstract class AbstractRepositoriesAdminAction
|
||||||
extends PlexusActionSupport
|
extends PlexusActionSupport
|
||||||
implements SecureAction
|
implements SecureAction
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The model for this action.
|
|
||||||
*/
|
|
||||||
protected T repository;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @plexus.requirement
|
* @plexus.requirement
|
||||||
*/
|
*/
|
||||||
protected ArchivaConfiguration archivaConfiguration;
|
protected ArchivaConfiguration archivaConfiguration;
|
||||||
|
|
||||||
protected String repoid;
|
public ArchivaConfiguration getArchivaConfiguration()
|
||||||
|
|
||||||
public String getRepoid()
|
|
||||||
{
|
{
|
||||||
return repoid;
|
return archivaConfiguration;
|
||||||
}
|
|
||||||
|
|
||||||
public T getRepository()
|
|
||||||
{
|
|
||||||
return repository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SecureActionBundle getSecureActionBundle()
|
public SecureActionBundle getSecureActionBundle()
|
||||||
|
@ -75,18 +67,21 @@ public abstract class AbstractConfigureRepositoryAction<T extends AbstractReposi
|
||||||
return bundle;
|
return bundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRepoid( String repoid )
|
|
||||||
{
|
|
||||||
this.repoid = repoid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
|
public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
|
||||||
{
|
{
|
||||||
this.archivaConfiguration = archivaConfiguration;
|
this.archivaConfiguration = archivaConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the configuration.
|
||||||
|
*
|
||||||
|
* @param configuration the configuration to save.
|
||||||
|
* @return the webwork result code to issue.
|
||||||
|
* @throws IOException thrown if unable to save file to disk.
|
||||||
|
* @throws InvalidConfigurationException thrown if configuration is invalid.
|
||||||
|
* @throws RegistryException thrown if configuration subsystem has a problem saving the configuration to disk.
|
||||||
|
*/
|
||||||
protected String saveConfiguration( Configuration configuration )
|
protected String saveConfiguration( Configuration configuration )
|
||||||
throws IOException, InvalidConfigurationException, RegistryException
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -96,85 +91,14 @@ public abstract class AbstractConfigureRepositoryAction<T extends AbstractReposi
|
||||||
catch ( IndeterminateConfigurationException e )
|
catch ( IndeterminateConfigurationException e )
|
||||||
{
|
{
|
||||||
addActionError( e.getMessage() );
|
addActionError( e.getMessage() );
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String add()
|
|
||||||
{
|
|
||||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
|
||||||
|
|
||||||
String repoId = repository.getId();
|
|
||||||
if ( configuration.getManagedRepositoriesAsMap().containsKey( repoId ) ||
|
|
||||||
configuration.getRemoteRepositoriesAsMap().containsKey( repoId ) )
|
|
||||||
{
|
|
||||||
addFieldError( "repository.id",
|
|
||||||
"Unable to add new repository with id [" + repoId + "], that id already exists." );
|
|
||||||
return INPUT;
|
return INPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean containsError = validateFields( configuration );
|
|
||||||
if ( containsError )
|
|
||||||
{
|
|
||||||
return INPUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return saveRepositoryConfiguration( configuration );
|
|
||||||
}
|
|
||||||
|
|
||||||
public String edit()
|
|
||||||
{
|
|
||||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
|
||||||
|
|
||||||
boolean containsError = validateFields( configuration );
|
|
||||||
if ( containsError )
|
|
||||||
{
|
|
||||||
return INPUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
removeRepository( repository.getId(), configuration );
|
|
||||||
|
|
||||||
return saveRepositoryConfiguration( configuration );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String saveRepositoryConfiguration( Configuration configuration )
|
|
||||||
{
|
|
||||||
String result;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
addRepository( repository, configuration );
|
|
||||||
result = saveConfiguration( configuration );
|
|
||||||
}
|
|
||||||
catch ( IOException e )
|
|
||||||
{
|
|
||||||
addActionError( "I/O Exception: " + e.getMessage() );
|
|
||||||
result = ERROR;
|
|
||||||
}
|
|
||||||
catch ( InvalidConfigurationException e )
|
|
||||||
{
|
|
||||||
addActionError( "Invalid Configuration Exception: " + e.getMessage() );
|
|
||||||
result = ERROR;
|
|
||||||
}
|
|
||||||
catch ( RegistryException e )
|
catch ( RegistryException e )
|
||||||
{
|
{
|
||||||
addActionError( "Configuration Registry Exception: " + e.getMessage() );
|
addActionError( "Configuration Registry Exception: " + e.getMessage() );
|
||||||
result = ERROR;
|
return INPUT;
|
||||||
}
|
|
||||||
catch ( RoleManagerException e )
|
|
||||||
{
|
|
||||||
addActionError( "Security role creation Exception: " + e.getMessage() );
|
|
||||||
result = ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract boolean validateFields( Configuration config );
|
|
||||||
|
|
||||||
protected abstract void addRepository( T repository, Configuration configuration )
|
|
||||||
throws IOException, RoleManagerException;
|
|
||||||
|
|
||||||
protected abstract void removeRepository( String repoId, Configuration configuration );
|
|
||||||
}
|
}
|
|
@ -0,0 +1,123 @@
|
||||||
|
package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 com.opensymphony.xwork.Preparable;
|
||||||
|
import com.opensymphony.xwork.Validateable;
|
||||||
|
|
||||||
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
|
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
|
import org.codehaus.plexus.redback.role.RoleManagerException;
|
||||||
|
import org.codehaus.plexus.scheduler.CronExpressionValidator;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AddManagedRepositoryAction
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*
|
||||||
|
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="addManagedRepositoryAction"
|
||||||
|
*/
|
||||||
|
public class AddManagedRepositoryAction
|
||||||
|
extends AbstractManagedRepositoriesAction
|
||||||
|
implements Preparable, Validateable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The model for this action.
|
||||||
|
*/
|
||||||
|
private ManagedRepositoryConfiguration repository;
|
||||||
|
|
||||||
|
public void prepare()
|
||||||
|
{
|
||||||
|
this.repository = new ManagedRepositoryConfiguration();
|
||||||
|
this.repository.setReleases( false );
|
||||||
|
this.repository.setScanned( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String input()
|
||||||
|
{
|
||||||
|
this.repository.setReleases( true );
|
||||||
|
this.repository.setScanned( true );
|
||||||
|
|
||||||
|
return INPUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String commit()
|
||||||
|
{
|
||||||
|
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||||
|
|
||||||
|
String result;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
addRepository( repository, configuration );
|
||||||
|
addRepositoryRoles( repository );
|
||||||
|
result = saveConfiguration( configuration );
|
||||||
|
}
|
||||||
|
catch ( RoleManagerException e )
|
||||||
|
{
|
||||||
|
addActionError( "Role Manager Exception: " + e.getMessage() );
|
||||||
|
result = INPUT;
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
addActionError( "Role Manager Exception: " + e.getMessage() );
|
||||||
|
result = INPUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate()
|
||||||
|
{
|
||||||
|
Configuration config = archivaConfiguration.getConfiguration();
|
||||||
|
|
||||||
|
CronExpressionValidator validator = new CronExpressionValidator();
|
||||||
|
String repoId = repository.getId();
|
||||||
|
|
||||||
|
if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
|
||||||
|
{
|
||||||
|
addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
|
||||||
|
+ "], that id already exists as a managed repository." );
|
||||||
|
}
|
||||||
|
else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
|
||||||
|
{
|
||||||
|
addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
|
||||||
|
+ "], that id already exists as a remote repository." );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !validator.validate( repository.getRefreshCronExpression() ) )
|
||||||
|
{
|
||||||
|
addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ManagedRepositoryConfiguration getRepository()
|
||||||
|
{
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepository( ManagedRepositoryConfiguration repository )
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,111 @@
|
||||||
|
package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 com.opensymphony.xwork.Preparable;
|
||||||
|
import com.opensymphony.xwork.Validateable;
|
||||||
|
|
||||||
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
|
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
|
||||||
|
import org.codehaus.plexus.redback.role.RoleManagerException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AddRemoteRepositoryAction
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*
|
||||||
|
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="addRemoteRepositoryAction"
|
||||||
|
*/
|
||||||
|
public class AddRemoteRepositoryAction
|
||||||
|
extends AbstractRemoteRepositoriesAction
|
||||||
|
implements Preparable, Validateable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The model for this action.
|
||||||
|
*/
|
||||||
|
private RemoteRepositoryConfiguration repository;
|
||||||
|
|
||||||
|
public void prepare()
|
||||||
|
{
|
||||||
|
this.repository = new RemoteRepositoryConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String input()
|
||||||
|
{
|
||||||
|
return INPUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String commit()
|
||||||
|
{
|
||||||
|
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||||
|
|
||||||
|
// Save the repository configuration.
|
||||||
|
String result;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
addRepository( repository, configuration );
|
||||||
|
result = saveConfiguration( configuration );
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
addActionError( "I/O Exception: " + e.getMessage() );
|
||||||
|
result = INPUT;
|
||||||
|
}
|
||||||
|
catch ( RoleManagerException e )
|
||||||
|
{
|
||||||
|
addActionError( "Role Manager Exception: " + e.getMessage() );
|
||||||
|
result = INPUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate()
|
||||||
|
{
|
||||||
|
Configuration config = archivaConfiguration.getConfiguration();
|
||||||
|
|
||||||
|
String repoId = repository.getId();
|
||||||
|
|
||||||
|
if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
|
||||||
|
{
|
||||||
|
addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
|
||||||
|
+ "], that id already exists as a managed repository." );
|
||||||
|
}
|
||||||
|
else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
|
||||||
|
{
|
||||||
|
addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
|
||||||
|
+ "], that id already exists as a remote repository." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RemoteRepositoryConfiguration getRepository()
|
||||||
|
{
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepository( RemoteRepositoryConfiguration repository )
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,131 +0,0 @@
|
||||||
package org.apache.maven.archiva.web.action.admin.repositories;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 com.opensymphony.xwork.Preparable;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.maven.archiva.configuration.Configuration;
|
|
||||||
import org.apache.maven.archiva.configuration.InvalidConfigurationException;
|
|
||||||
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
|
|
||||||
import org.codehaus.plexus.registry.RegistryException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the application repositories.
|
|
||||||
*
|
|
||||||
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureRemoteRepositoryAction"
|
|
||||||
*/
|
|
||||||
public class ConfigureRemoteRepositoryAction
|
|
||||||
extends AbstractConfigureRepositoryAction<RemoteRepositoryConfiguration>
|
|
||||||
implements Preparable
|
|
||||||
{
|
|
||||||
public String delete()
|
|
||||||
{
|
|
||||||
if ( repository == null )
|
|
||||||
{
|
|
||||||
addActionError( "A repository with that id does not exist" );
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
String result;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
|
||||||
removeRepository( repoid, configuration );
|
|
||||||
result = saveConfiguration( configuration );
|
|
||||||
}
|
|
||||||
catch ( IOException e )
|
|
||||||
{
|
|
||||||
addActionError( "Unable to delete repository: " + e.getMessage() );
|
|
||||||
result = ERROR;
|
|
||||||
}
|
|
||||||
catch ( InvalidConfigurationException e )
|
|
||||||
{
|
|
||||||
addActionError( "Unable to delete repository: " + e.getMessage() );
|
|
||||||
result = ERROR;
|
|
||||||
}
|
|
||||||
catch ( RegistryException e )
|
|
||||||
{
|
|
||||||
addActionError( "Unable to delete repository: " + e.getMessage() );
|
|
||||||
result = ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void prepare()
|
|
||||||
{
|
|
||||||
String id = repoid;
|
|
||||||
if ( id == null )
|
|
||||||
{
|
|
||||||
this.repository = new RemoteRepositoryConfiguration();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.repository = archivaConfiguration.getConfiguration().findRemoteRepositoryById( id );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean validateFields( Configuration config )
|
|
||||||
{
|
|
||||||
// TODO: push this into the webwork validation instead
|
|
||||||
boolean containsError = false;
|
|
||||||
String repoId = repository.getId();
|
|
||||||
|
|
||||||
if ( StringUtils.isBlank( repoId ) )
|
|
||||||
{
|
|
||||||
addFieldError( "repository.id", "You must enter a repository identifier." );
|
|
||||||
containsError = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( StringUtils.isBlank( repository.getUrl() ) )
|
|
||||||
{
|
|
||||||
addFieldError( "repository.url", "You must enter a URL." );
|
|
||||||
containsError = true;
|
|
||||||
}
|
|
||||||
if ( StringUtils.isBlank( repository.getName() ) )
|
|
||||||
{
|
|
||||||
addFieldError( "repository.name", "You must enter a repository name." );
|
|
||||||
containsError = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return containsError;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addRepository( RemoteRepositoryConfiguration repository, Configuration configuration )
|
|
||||||
{
|
|
||||||
configuration.addRemoteRepository( repository );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void removeRepository( String repoId, Configuration configuration )
|
|
||||||
{
|
|
||||||
RemoteRepositoryConfiguration toremove = configuration.findRemoteRepositoryById( repoId );
|
|
||||||
if ( toremove != null )
|
|
||||||
{
|
|
||||||
configuration.removeRemoteRepository( toremove );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String input()
|
|
||||||
{
|
|
||||||
return INPUT;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,222 +0,0 @@
|
||||||
package org.apache.maven.archiva.web.action.admin.repositories;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 com.opensymphony.xwork.Preparable;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.maven.archiva.configuration.Configuration;
|
|
||||||
import org.apache.maven.archiva.configuration.InvalidConfigurationException;
|
|
||||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
|
||||||
import org.codehaus.plexus.redback.role.RoleManager;
|
|
||||||
import org.codehaus.plexus.redback.role.RoleManagerException;
|
|
||||||
import org.codehaus.plexus.registry.RegistryException;
|
|
||||||
import org.codehaus.plexus.scheduler.CronExpressionValidator;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the managed repositories.
|
|
||||||
*
|
|
||||||
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureRepositoryAction"
|
|
||||||
*/
|
|
||||||
public class ConfigureRepositoryAction
|
|
||||||
extends AbstractConfigureRepositoryAction<ManagedRepositoryConfiguration>
|
|
||||||
implements Preparable
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @plexus.requirement role-hint="default"
|
|
||||||
*/
|
|
||||||
protected RoleManager roleManager;
|
|
||||||
|
|
||||||
private String deleteMode = "delete-entry";
|
|
||||||
|
|
||||||
public String getDeleteMode()
|
|
||||||
{
|
|
||||||
return deleteMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeleteMode( String deleteMode )
|
|
||||||
{
|
|
||||||
this.deleteMode = deleteMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String addInput()
|
|
||||||
{
|
|
||||||
// set defaults
|
|
||||||
this.repository.setReleases( true );
|
|
||||||
this.repository.setScanned( true );
|
|
||||||
|
|
||||||
return INPUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String editInput()
|
|
||||||
{
|
|
||||||
return INPUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String delete()
|
|
||||||
{
|
|
||||||
if ( repository == null )
|
|
||||||
{
|
|
||||||
addActionError( "A repository with that id does not exist" );
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
String result;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
|
||||||
removeRepository( repoid, configuration );
|
|
||||||
result = saveConfiguration( configuration );
|
|
||||||
|
|
||||||
if ( result.equals( SUCCESS ) )
|
|
||||||
{
|
|
||||||
removeRepositoryRoles( repository );
|
|
||||||
if ( StringUtils.equals( deleteMode, "delete-contents" ) )
|
|
||||||
{
|
|
||||||
removeContents( repository );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( IOException e )
|
|
||||||
{
|
|
||||||
addActionError( "Unable to delete repository: " + e.getMessage() );
|
|
||||||
result = ERROR;
|
|
||||||
}
|
|
||||||
catch ( RoleManagerException e )
|
|
||||||
{
|
|
||||||
addActionError( "Unable to delete repository: " + e.getMessage() );
|
|
||||||
result = ERROR;
|
|
||||||
}
|
|
||||||
catch ( InvalidConfigurationException e )
|
|
||||||
{
|
|
||||||
addActionError( "Unable to delete repository: " + e.getMessage() );
|
|
||||||
result = ERROR;
|
|
||||||
}
|
|
||||||
catch ( RegistryException e )
|
|
||||||
{
|
|
||||||
addActionError( "Unable to delete repository: " + e.getMessage() );
|
|
||||||
result = ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void prepare()
|
|
||||||
{
|
|
||||||
String id = repoid;
|
|
||||||
if ( id == null )
|
|
||||||
{
|
|
||||||
this.repository = new ManagedRepositoryConfiguration();
|
|
||||||
this.repository.setReleases( false );
|
|
||||||
this.repository.setScanned( false );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( id );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean validateFields( Configuration config )
|
|
||||||
{
|
|
||||||
boolean containsError = false;
|
|
||||||
CronExpressionValidator validator = new CronExpressionValidator();
|
|
||||||
String repoId = repository.getId();
|
|
||||||
|
|
||||||
if ( StringUtils.isBlank( repoId ) )
|
|
||||||
{
|
|
||||||
addFieldError( "repository.id", "You must enter a repository identifier." );
|
|
||||||
containsError = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( StringUtils.isBlank( repository.getLocation() ) )
|
|
||||||
{
|
|
||||||
addFieldError( "repository.location", "You must enter a directory." );
|
|
||||||
containsError = true;
|
|
||||||
}
|
|
||||||
if ( StringUtils.isBlank( repository.getName() ) )
|
|
||||||
{
|
|
||||||
addFieldError( "repository.name", "You must enter a repository name." );
|
|
||||||
containsError = true;
|
|
||||||
}
|
|
||||||
if ( !validator.validate( repository.getRefreshCronExpression() ) )
|
|
||||||
{
|
|
||||||
addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
|
|
||||||
containsError = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return containsError;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
|
|
||||||
throws IOException, RoleManagerException
|
|
||||||
{
|
|
||||||
// Normalize the path
|
|
||||||
File file = new File( repository.getLocation() );
|
|
||||||
repository.setLocation( file.getCanonicalPath() );
|
|
||||||
if ( !file.exists() )
|
|
||||||
{
|
|
||||||
file.mkdirs();
|
|
||||||
}
|
|
||||||
if ( !file.exists() || !file.isDirectory() )
|
|
||||||
{
|
|
||||||
throw new IOException( "unable to add repository - can not create the root directory: " + file );
|
|
||||||
}
|
|
||||||
|
|
||||||
configuration.addManagedRepository( repository );
|
|
||||||
|
|
||||||
// TODO: double check these are configured on start up
|
|
||||||
// TODO: belongs in the business logic
|
|
||||||
roleManager.createTemplatedRole( "archiva-repository-manager", repository.getId() );
|
|
||||||
|
|
||||||
roleManager.createTemplatedRole( "archiva-repository-observer", repository.getId() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeContents( ManagedRepositoryConfiguration existingRepository )
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
FileUtils.deleteDirectory( new File( existingRepository.getLocation() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void removeRepository( String repoId, Configuration configuration )
|
|
||||||
{
|
|
||||||
ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( repoId );
|
|
||||||
if ( toremove != null )
|
|
||||||
{
|
|
||||||
configuration.removeManagedRepository( toremove );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository )
|
|
||||||
throws RoleManagerException
|
|
||||||
{
|
|
||||||
roleManager.removeTemplatedRole( "archiva-repository-manager", existingRepository.getId() );
|
|
||||||
roleManager.removeTemplatedRole( "archiva-repository-observer", existingRepository.getId() );
|
|
||||||
|
|
||||||
getLogger().debug( "removed user roles associated with repository " + existingRepository.getId() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoleManager( RoleManager roleManager )
|
|
||||||
{
|
|
||||||
this.roleManager = roleManager;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,148 @@
|
||||||
|
package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 com.opensymphony.xwork.Preparable;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
|
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
|
import org.codehaus.plexus.redback.role.RoleManagerException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DeleteManagedRepositoryAction
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*
|
||||||
|
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteManagedRepositoryAction"
|
||||||
|
*/
|
||||||
|
public class DeleteManagedRepositoryAction
|
||||||
|
extends AbstractManagedRepositoriesAction
|
||||||
|
implements Preparable
|
||||||
|
{
|
||||||
|
private ManagedRepositoryConfiguration repository;
|
||||||
|
|
||||||
|
private String repoid;
|
||||||
|
|
||||||
|
public void prepare()
|
||||||
|
{
|
||||||
|
if ( StringUtils.isNotBlank( repoid ) )
|
||||||
|
{
|
||||||
|
this.repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String confirmDelete()
|
||||||
|
{
|
||||||
|
if ( StringUtils.isBlank( repoid ) )
|
||||||
|
{
|
||||||
|
addActionError( "Unable to delete managed repository: repository id was blank." );
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return INPUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String deleteEntry()
|
||||||
|
{
|
||||||
|
return deleteRepository( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String deleteContents()
|
||||||
|
{
|
||||||
|
return deleteRepository( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
private String deleteRepository( boolean deleteContents )
|
||||||
|
{
|
||||||
|
ManagedRepositoryConfiguration existingRepository = repository;
|
||||||
|
if ( existingRepository == null )
|
||||||
|
{
|
||||||
|
addActionError( "A repository with that id does not exist" );
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
String result = SUCCESS;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||||
|
removeRepository( repoid, configuration );
|
||||||
|
result = saveConfiguration( configuration );
|
||||||
|
|
||||||
|
if ( result.equals( SUCCESS ) )
|
||||||
|
{
|
||||||
|
cleanupRepositoryData( existingRepository );
|
||||||
|
|
||||||
|
if ( deleteContents )
|
||||||
|
{
|
||||||
|
removeContents( existingRepository );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
addActionError( "Unable to delete repository: " + e.getMessage() );
|
||||||
|
result = ERROR;
|
||||||
|
}
|
||||||
|
catch ( RoleManagerException e )
|
||||||
|
{
|
||||||
|
addActionError( "Unable to delete repository: " + e.getMessage() );
|
||||||
|
result = ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanupRepositoryData( ManagedRepositoryConfiguration cleanupRepository )
|
||||||
|
throws RoleManagerException
|
||||||
|
{
|
||||||
|
removeRepositoryRoles( cleanupRepository );
|
||||||
|
|
||||||
|
// TODO: [MRM-382] Remove index from artifacts of deleted managed repositories.
|
||||||
|
|
||||||
|
// TODO: [MRM-265] After removing a managed repository - Browse/Search still see it
|
||||||
|
|
||||||
|
// TODO: [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
|
||||||
|
}
|
||||||
|
|
||||||
|
public ManagedRepositoryConfiguration getRepository()
|
||||||
|
{
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepository( ManagedRepositoryConfiguration repository )
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRepoid()
|
||||||
|
{
|
||||||
|
return repoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepoid( String repoid )
|
||||||
|
{
|
||||||
|
this.repoid = repoid;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 com.opensymphony.xwork.Preparable;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
|
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DeleteRemoteRepositoryAction
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*
|
||||||
|
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteRemoteRepositoryAction"
|
||||||
|
*/
|
||||||
|
public class DeleteRemoteRepositoryAction
|
||||||
|
extends AbstractRemoteRepositoriesAction
|
||||||
|
implements Preparable
|
||||||
|
{
|
||||||
|
private RemoteRepositoryConfiguration repository;
|
||||||
|
|
||||||
|
private String repoid;
|
||||||
|
|
||||||
|
public void prepare()
|
||||||
|
{
|
||||||
|
if ( StringUtils.isNotBlank( repoid ) )
|
||||||
|
{
|
||||||
|
this.repository = archivaConfiguration.getConfiguration().findRemoteRepositoryById( repoid );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String confirmDelete()
|
||||||
|
{
|
||||||
|
if ( StringUtils.isBlank( repoid ) )
|
||||||
|
{
|
||||||
|
addActionError( "Unable to delete remote repository: repository id was blank." );
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return INPUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String delete()
|
||||||
|
{
|
||||||
|
String result = SUCCESS;
|
||||||
|
RemoteRepositoryConfiguration existingRepository = repository;
|
||||||
|
if ( existingRepository == null )
|
||||||
|
{
|
||||||
|
addActionError( "A repository with that id does not exist" );
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||||
|
removeRepository( repoid, configuration );
|
||||||
|
result = saveConfiguration( configuration );
|
||||||
|
|
||||||
|
cleanupRepositoryData( existingRepository );
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanupRepositoryData( RemoteRepositoryConfiguration existingRepository )
|
||||||
|
{
|
||||||
|
// TODO: [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
|
||||||
|
}
|
||||||
|
|
||||||
|
public RemoteRepositoryConfiguration getRepository()
|
||||||
|
{
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepository( RemoteRepositoryConfiguration repository )
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRepoid()
|
||||||
|
{
|
||||||
|
return repoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepoid( String repoid )
|
||||||
|
{
|
||||||
|
this.repoid = repoid;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 com.opensymphony.xwork.Preparable;
|
||||||
|
import com.opensymphony.xwork.Validateable;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
|
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
|
import org.codehaus.plexus.redback.role.RoleManagerException;
|
||||||
|
import org.codehaus.plexus.scheduler.CronExpressionValidator;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AddManagedRepositoryAction
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*
|
||||||
|
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="editManagedRepositoryAction"
|
||||||
|
*/
|
||||||
|
public class EditManagedRepositoryAction
|
||||||
|
extends AbstractManagedRepositoriesAction
|
||||||
|
implements Preparable, Validateable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The model for this action.
|
||||||
|
*/
|
||||||
|
private ManagedRepositoryConfiguration repository;
|
||||||
|
|
||||||
|
private String repoid;
|
||||||
|
|
||||||
|
public void prepare()
|
||||||
|
{
|
||||||
|
if ( StringUtils.isNotBlank( repoid ) )
|
||||||
|
{
|
||||||
|
repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String input()
|
||||||
|
{
|
||||||
|
if ( repository == null )
|
||||||
|
{
|
||||||
|
addActionError( "Edit failure, unable to edit a repository with a blank repository id." );
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return INPUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String commit()
|
||||||
|
{
|
||||||
|
// Ensure that the fields are valid.
|
||||||
|
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||||
|
|
||||||
|
// We are in edit mode, remove the old repository configuration.
|
||||||
|
removeRepository( repository.getId(), configuration );
|
||||||
|
|
||||||
|
// Save the repository configuration.
|
||||||
|
String result;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
addRepository( repository, configuration );
|
||||||
|
addRepositoryRoles( repository );
|
||||||
|
result = saveConfiguration( configuration );
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
addActionError( "I/O Exception: " + e.getMessage() );
|
||||||
|
result = ERROR;
|
||||||
|
}
|
||||||
|
catch ( RoleManagerException e )
|
||||||
|
{
|
||||||
|
addActionError( "Role Manager Exception: " + e.getMessage() );
|
||||||
|
result = ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate()
|
||||||
|
{
|
||||||
|
CronExpressionValidator validator = new CronExpressionValidator();
|
||||||
|
|
||||||
|
if ( !validator.validate( repository.getRefreshCronExpression() ) )
|
||||||
|
{
|
||||||
|
addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRepoid()
|
||||||
|
{
|
||||||
|
return repoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepoid( String repoid )
|
||||||
|
{
|
||||||
|
this.repoid = repoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ManagedRepositoryConfiguration getRepository()
|
||||||
|
{
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepository( ManagedRepositoryConfiguration repository )
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 com.opensymphony.xwork.Preparable;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
|
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
|
||||||
|
import org.codehaus.plexus.redback.role.RoleManagerException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EditRemoteRepositoryAction
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*
|
||||||
|
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="editRemoteRepositoryAction"
|
||||||
|
*/
|
||||||
|
public class EditRemoteRepositoryAction
|
||||||
|
extends AbstractRemoteRepositoriesAction
|
||||||
|
implements Preparable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The model for this action.
|
||||||
|
*/
|
||||||
|
private RemoteRepositoryConfiguration repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The repository id to edit.
|
||||||
|
*/
|
||||||
|
private String repoid;
|
||||||
|
|
||||||
|
public void prepare()
|
||||||
|
{
|
||||||
|
String id = repoid;
|
||||||
|
if ( StringUtils.isNotBlank( repoid ) )
|
||||||
|
{
|
||||||
|
this.repository = archivaConfiguration.getConfiguration().findRemoteRepositoryById( id );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String input()
|
||||||
|
{
|
||||||
|
if ( StringUtils.isBlank( repoid ) )
|
||||||
|
{
|
||||||
|
addActionError( "Edit failure, unable to edit a repository with a blank repository id." );
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return INPUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String commit()
|
||||||
|
{
|
||||||
|
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||||
|
|
||||||
|
// We are in edit mode, remove the old repository configuration.
|
||||||
|
removeRepository( repository.getId(), configuration );
|
||||||
|
|
||||||
|
// Save the repository configuration.
|
||||||
|
String result;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
addRepository( repository, configuration );
|
||||||
|
result = saveConfiguration( configuration );
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
addActionError( "I/O Exception: " + e.getMessage() );
|
||||||
|
result = INPUT;
|
||||||
|
}
|
||||||
|
catch ( RoleManagerException e )
|
||||||
|
{
|
||||||
|
addActionError( "Role Manager Exception: " + e.getMessage() );
|
||||||
|
result = INPUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RemoteRepositoryConfiguration getRepository()
|
||||||
|
{
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepository( RemoteRepositoryConfiguration repository )
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRepoid()
|
||||||
|
{
|
||||||
|
return repoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepoid( String repoid )
|
||||||
|
{
|
||||||
|
this.repoid = repoid;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
|
||||||
|
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
|
||||||
|
|
||||||
|
<validators>
|
||||||
|
<field name="repository.id">
|
||||||
|
<field-validator type="requiredstring">
|
||||||
|
<message>You must enter a repository identifier.</message>
|
||||||
|
</field-validator>
|
||||||
|
</field>
|
||||||
|
<field name="repository.location">
|
||||||
|
<field-validator type="requiredstring">
|
||||||
|
<message>You must enter a directory.</message>
|
||||||
|
</field-validator>
|
||||||
|
</field>
|
||||||
|
<field name="repository.name">
|
||||||
|
<field-validator type="requiredstring">
|
||||||
|
<message>You must enter a repository name.</message>
|
||||||
|
</field-validator>
|
||||||
|
</field>
|
||||||
|
</validators>
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
|
||||||
|
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
|
||||||
|
|
||||||
|
<validators>
|
||||||
|
<field name="repository.id">
|
||||||
|
<field-validator type="requiredstring">
|
||||||
|
<message>You must enter a repository identifier.</message>
|
||||||
|
</field-validator>
|
||||||
|
</field>
|
||||||
|
<field name="repository.url">
|
||||||
|
<field-validator type="requiredstring">
|
||||||
|
<message>You must enter a url.</message>
|
||||||
|
</field-validator>
|
||||||
|
</field>
|
||||||
|
<field name="repository.name">
|
||||||
|
<field-validator type="requiredstring">
|
||||||
|
<message>You must enter a repository name.</message>
|
||||||
|
</field-validator>
|
||||||
|
</field>
|
||||||
|
</validators>
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
|
||||||
|
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
|
||||||
|
|
||||||
|
<validators>
|
||||||
|
<field name="repository.id">
|
||||||
|
<field-validator type="requiredstring">
|
||||||
|
<message>You must enter a repository identifier.</message>
|
||||||
|
</field-validator>
|
||||||
|
</field>
|
||||||
|
<field name="repository.location">
|
||||||
|
<field-validator type="requiredstring">
|
||||||
|
<message>You must enter a directory.</message>
|
||||||
|
</field-validator>
|
||||||
|
</field>
|
||||||
|
<field name="repository.name">
|
||||||
|
<field-validator type="requiredstring">
|
||||||
|
<message>You must enter a repository name.</message>
|
||||||
|
</field-validator>
|
||||||
|
</field>
|
||||||
|
</validators>
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
|
||||||
|
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
|
||||||
|
|
||||||
|
<validators>
|
||||||
|
<field name="repository.id">
|
||||||
|
<field-validator type="requiredstring">
|
||||||
|
<message>You must enter a repository identifier.</message>
|
||||||
|
</field-validator>
|
||||||
|
</field>
|
||||||
|
<field name="repository.url">
|
||||||
|
<field-validator type="requiredstring">
|
||||||
|
<message>You must enter a url.</message>
|
||||||
|
</field-validator>
|
||||||
|
</field>
|
||||||
|
<field name="repository.name">
|
||||||
|
<field-validator type="requiredstring">
|
||||||
|
<message>You must enter a repository name.</message>
|
||||||
|
</field-validator>
|
||||||
|
</field>
|
||||||
|
</validators>
|
|
@ -228,52 +228,52 @@
|
||||||
<result type="redirect-action">repositories</result>
|
<result type="redirect-action">repositories</result>
|
||||||
</action>
|
</action>
|
||||||
|
|
||||||
<action name="addRepository" class="configureRepositoryAction" method="add">
|
<action name="addRepository" class="addManagedRepositoryAction" method="input">
|
||||||
<result name="input">/WEB-INF/jsp/admin/addRepository.jsp</result>
|
<result name="input">/WEB-INF/jsp/admin/addRepository.jsp</result>
|
||||||
<result name="error">/WEB-INF/jsp/admin/addRepository.jsp</result>
|
<result name="error">/WEB-INF/jsp/admin/addRepository.jsp</result>
|
||||||
<result name="success" type="redirect-action">repositories</result>
|
<result name="success" type="redirect-action">repositories</result>
|
||||||
<interceptor-ref name="configuredPrepareParamsStack"/>
|
<interceptor-ref name="configuredPrepareParamsStack"/>
|
||||||
</action>
|
</action>
|
||||||
|
|
||||||
<action name="editRepository" class="configureRepositoryAction" method="edit">
|
<action name="editRepository" class="editManagedRepositoryAction" method="input">
|
||||||
<result name="input">/WEB-INF/jsp/admin/editRepository.jsp</result>
|
<result name="input">/WEB-INF/jsp/admin/editRepository.jsp</result>
|
||||||
<result name="error">/WEB-INF/jsp/admin/editRepository.jsp</result>
|
<result name="error">/WEB-INF/jsp/admin/editRepository.jsp</result>
|
||||||
<result name="success" type="redirect-action">repositories</result>
|
<result name="success" type="redirect-action">repositories</result>
|
||||||
<interceptor-ref name="configuredPrepareParamsStack"/>
|
<interceptor-ref name="configuredPrepareParamsStack"/>
|
||||||
</action>
|
</action>
|
||||||
|
|
||||||
<action name="confirmDeleteRepository" class="configureRepositoryAction">
|
<action name="confirmDeleteRepository" class="deleteManagedRepositoryAction" method="confirmDelete">
|
||||||
<result>/WEB-INF/jsp/admin/deleteRepository.jsp</result>
|
<result name="input">/WEB-INF/jsp/admin/deleteRepository.jsp</result>
|
||||||
<interceptor-ref name="configuredPrepareParamsStack"/>
|
<interceptor-ref name="configuredPrepareParamsStack"/>
|
||||||
</action>
|
</action>
|
||||||
|
|
||||||
<action name="deleteRepository" class="configureRepositoryAction" method="delete">
|
<action name="deleteRepository" class="deleteManagedRepositoryAction" method="delete">
|
||||||
<result name="input">/WEB-INF/jsp/admin/deleteRepository.jsp</result>
|
<result name="input">/WEB-INF/jsp/admin/deleteRepository.jsp</result>
|
||||||
<result name="error">/WEB-INF/jsp/admin/deleteRepository.jsp</result>
|
<result name="error">/WEB-INF/jsp/admin/deleteRepository.jsp</result>
|
||||||
<result name="success" type="redirect-action">repositories</result>
|
<result name="success" type="redirect-action">repositories</result>
|
||||||
<interceptor-ref name="configuredPrepareParamsStack"/>
|
<interceptor-ref name="configuredPrepareParamsStack"/>
|
||||||
</action>
|
</action>
|
||||||
|
|
||||||
<action name="addRemoteRepository" class="configureRemoteRepositoryAction" method="add">
|
<action name="addRemoteRepository" class="addRemoteRepositoryAction" method="input">
|
||||||
<result name="input">/WEB-INF/jsp/admin/addRemoteRepository.jsp</result>
|
<result name="input">/WEB-INF/jsp/admin/addRemoteRepository.jsp</result>
|
||||||
<result name="error">/WEB-INF/jsp/admin/addRemoteRepository.jsp</result>
|
<result name="error">/WEB-INF/jsp/admin/addRemoteRepository.jsp</result>
|
||||||
<result name="success" type="redirect-action">repositories</result>
|
<result name="success" type="redirect-action">repositories</result>
|
||||||
<interceptor-ref name="configuredPrepareParamsStack"/>
|
<interceptor-ref name="configuredPrepareParamsStack"/>
|
||||||
</action>
|
</action>
|
||||||
|
|
||||||
<action name="editRemoteRepository" class="configureRemoteRepositoryAction" method="edit">
|
<action name="editRemoteRepository" class="editRemoteRepositoryAction" method="input">
|
||||||
<result name="input">/WEB-INF/jsp/admin/editRemoteRepository.jsp</result>
|
<result name="input">/WEB-INF/jsp/admin/editRemoteRepository.jsp</result>
|
||||||
<result name="error">/WEB-INF/jsp/admin/editRemoteRepository.jsp</result>
|
<result name="error">/WEB-INF/jsp/admin/editRemoteRepository.jsp</result>
|
||||||
<result name="success" type="redirect-action">repositories</result>
|
<result name="success" type="redirect-action">repositories</result>
|
||||||
<interceptor-ref name="configuredPrepareParamsStack"/>
|
<interceptor-ref name="configuredPrepareParamsStack"/>
|
||||||
</action>
|
</action>
|
||||||
|
|
||||||
<action name="confirmDeleteRemoteRepository" class="configureRemoteRepositoryAction">
|
<action name="confirmDeleteRemoteRepository" class="deleteRemoteRepositoryAction" method="confirmDelete">
|
||||||
<result>/WEB-INF/jsp/admin/deleteRemoteRepository.jsp</result>
|
<result name="input">/WEB-INF/jsp/admin/deleteRemoteRepository.jsp</result>
|
||||||
<interceptor-ref name="configuredPrepareParamsStack"/>
|
<interceptor-ref name="configuredPrepareParamsStack"/>
|
||||||
</action>
|
</action>
|
||||||
|
|
||||||
<action name="deleteRemoteRepository" class="configureRemoteRepositoryAction" method="delete">
|
<action name="deleteRemoteRepository" class="deleteRemoteRepositoryAction" method="delete">
|
||||||
<result name="input">/WEB-INF/jsp/admin/deleteRemoteRepository.jsp</result>
|
<result name="input">/WEB-INF/jsp/admin/deleteRemoteRepository.jsp</result>
|
||||||
<result name="error">/WEB-INF/jsp/admin/deleteRemoteRepository.jsp</result>
|
<result name="error">/WEB-INF/jsp/admin/deleteRemoteRepository.jsp</result>
|
||||||
<result name="success" type="redirect-action">repositories</result>
|
<result name="success" type="redirect-action">repositories</result>
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
<h2>Add Repository</h2>
|
<h2>Add Repository</h2>
|
||||||
|
|
||||||
<ww:actionmessage/>
|
<ww:actionmessage/>
|
||||||
<ww:form method="post" action="addRemoteRepository" namespace="/admin" validate="true">
|
<ww:form method="post" action="addRemoteRepository!commit" namespace="/admin" validate="true">
|
||||||
<ww:textfield name="repository.id" label="Identifier" size="10" required="true"/>
|
<ww:textfield name="repository.id" label="Identifier" size="10" required="true"/>
|
||||||
<%@ include file="/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf" %>
|
<%@ include file="/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf" %>
|
||||||
<ww:submit value="Add Repository"/>
|
<ww:submit value="Add Repository"/>
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
<h2>Add Repository</h2>
|
<h2>Add Repository</h2>
|
||||||
|
|
||||||
<ww:actionmessage/>
|
<ww:actionmessage/>
|
||||||
<ww:form method="post" action="addRepository" namespace="/admin" validate="true">
|
<ww:form method="post" action="addRepository!commit" namespace="/admin" validate="true">
|
||||||
<ww:textfield name="repository.id" label="Identifier" size="10" required="true"/>
|
<ww:textfield name="repository.id" label="Identifier" size="10" required="true"/>
|
||||||
<%@ include file="/WEB-INF/jsp/admin/include/repositoryForm.jspf" %>
|
<%@ include file="/WEB-INF/jsp/admin/include/repositoryForm.jspf" %>
|
||||||
<ww:submit value="Add Repository"/>
|
<ww:submit value="Add Repository"/>
|
||||||
|
|
|
@ -21,32 +21,51 @@
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Admin: Delete Repository</title>
|
<title>Admin: Delete Remote Repository</title>
|
||||||
<ww:head/>
|
<ww:head/>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>Admin: Delete Repository</h1>
|
<h1>Admin: Delete Remote Repository</h1>
|
||||||
|
|
||||||
<ww:actionerror/>
|
<ww:actionerror/>
|
||||||
|
|
||||||
<div id="contentArea">
|
<div id="contentArea">
|
||||||
|
|
||||||
<h2>Delete Repository</h2>
|
<div class="warningbox">
|
||||||
|
<p>
|
||||||
<blockquote>
|
<strong>WARNING: This operation can not be undone.</strong>
|
||||||
<strong><span class="statusFailed">WARNING:</span> This operation can not be undone.</strong>
|
</p>
|
||||||
</blockquote>
|
</div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Are you sure you want to delete the repository <code>[ ${repoid} ]</code> ?
|
Are you sure you want to delete the following remote repository?
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<ww:form method="post" action="deleteRemoteRepository" namespace="/admin" validate="true">
|
<div class="infobox">
|
||||||
|
<table class="infotable">
|
||||||
|
<tr>
|
||||||
|
<td>ID:</td>
|
||||||
|
<td><code>${repository.id}</code></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Name:</td>
|
||||||
|
<td>${repository.name}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>URL:</td>
|
||||||
|
<td><a href="${repository.url}">${repository.url}</a></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ww:form method="post" action="deleteRemoteRepository" namespace="/admin" validate="true" theme="simple">
|
||||||
<ww:hidden name="repoid"/>
|
<ww:hidden name="repoid"/>
|
||||||
<ww:submit value="Confirm" method="delete"/>
|
<div class="buttons">
|
||||||
<ww:submit value="Cancel" method="execute"/>
|
<ww:submit value="Confirm" method="delete"/>
|
||||||
|
<ww:submit value="Cancel" method="execute"/>
|
||||||
|
</div>
|
||||||
</ww:form>
|
</ww:form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -21,31 +21,52 @@
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Admin: Delete Repository</title>
|
<title>Admin: Delete Managed Repository</title>
|
||||||
<ww:head/>
|
<ww:head/>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>Admin: Delete Repository</h1>
|
<h1>Admin: Delete Managed Repository</h1>
|
||||||
|
|
||||||
<ww:actionerror/>
|
<ww:actionerror/>
|
||||||
|
|
||||||
<div id="contentArea">
|
<div id="contentArea">
|
||||||
|
|
||||||
<h2>Delete Repository</h2>
|
<div class="warningbox">
|
||||||
|
<p>
|
||||||
|
<strong>WARNING: This operation can not be undone.</strong>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Are you sure you want to delete the following managed repository?
|
||||||
|
</p>
|
||||||
|
|
||||||
<blockquote>
|
<div class="infobox">
|
||||||
<strong><span class="statusFailed">WARNING:</span> This operation can not be undone.</strong>
|
<table class="infotable">
|
||||||
</blockquote>
|
<tr>
|
||||||
|
<td>ID:</td>
|
||||||
|
<td><code>${repository.id}</code></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Name:</td>
|
||||||
|
<td>${repository.name}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Directory:</td>
|
||||||
|
<td>${repository.location}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
<ww:form method="post" action="deleteRepository" namespace="/admin" validate="true">
|
<ww:form method="post" action="deleteRepository" namespace="/admin" validate="true" theme="simple">
|
||||||
<ww:hidden name="repoid"/>
|
<ww:hidden name="repoid"/>
|
||||||
<ww:radio list="#@java.util.LinkedHashMap@{'delete-contents' : 'Remove the repository and delete its contents from disk',
|
<div class="buttons">
|
||||||
'delete-entry' : 'Remove the repository from the management list, but leave the contents unmodified'}"
|
<ww:submit value="Delete Configuration Only" method="deleteEntry" />
|
||||||
name="deleteMode" theme="archiva"/>
|
<ww:submit value="Delete Configuration and Contents" method="deleteContents" />
|
||||||
<ww:submit value="Confirm" method="delete"/>
|
<ww:submit value="Cancel" method="execute"/>
|
||||||
<ww:submit value="Cancel" method="execute"/>
|
</div>
|
||||||
</ww:form>
|
</ww:form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
<h2>Edit Repository</h2>
|
<h2>Edit Repository</h2>
|
||||||
|
|
||||||
<ww:actionmessage/>
|
<ww:actionmessage/>
|
||||||
<ww:form method="post" action="editRemoteRepository" namespace="/admin" validate="false">
|
<ww:form method="post" action="editRemoteRepository!commit" namespace="/admin" validate="false">
|
||||||
<ww:hidden name="repository.id"/>
|
<ww:hidden name="repository.id"/>
|
||||||
<%@ include file="/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf" %>
|
<%@ include file="/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf" %>
|
||||||
<ww:submit value="Update Repository"/>
|
<ww:submit value="Update Repository"/>
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
<h2>Edit Repository</h2>
|
<h2>Edit Repository</h2>
|
||||||
|
|
||||||
<ww:actionmessage/>
|
<ww:actionmessage/>
|
||||||
<ww:form method="post" action="editRepository" namespace="/admin" validate="false">
|
<ww:form method="post" action="editRepository!commit" namespace="/admin" validate="false">
|
||||||
<ww:hidden name="repository.id"/>
|
<ww:hidden name="repository.id"/>
|
||||||
<%@ include file="/WEB-INF/jsp/admin/include/repositoryForm.jspf" %>
|
<%@ include file="/WEB-INF/jsp/admin/include/repositoryForm.jspf" %>
|
||||||
<ww:submit value="Update Repository"/>
|
<ww:submit value="Update Repository"/>
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
<div class="admin">
|
<div class="admin">
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<redback:ifAuthorized permission="archiva-manage-configuration">
|
<redback:ifAuthorized permission="archiva-manage-configuration">
|
||||||
<ww:url id="addRepositoryUrl" action="addRepository" method="addInput"/>
|
<ww:url id="addRepositoryUrl" action="addRepository"/>
|
||||||
<ww:a href="%{addRepositoryUrl}">
|
<ww:a href="%{addRepositoryUrl}">
|
||||||
<img src="<c:url value="/images/icons/create.png" />" alt="" width="16" height="16"/>
|
<img src="<c:url value="/images/icons/create.png" />" alt="" width="16" height="16"/>
|
||||||
Add
|
Add
|
||||||
|
@ -72,7 +72,7 @@
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%-- TODO: make some icons --%>
|
<%-- TODO: make some icons --%>
|
||||||
<redback:ifAnyAuthorized permissions="archiva-manage-configuration">
|
<redback:ifAnyAuthorized permissions="archiva-manage-configuration">
|
||||||
<ww:url id="editRepositoryUrl" action="editRepository" method="editInput">
|
<ww:url id="editRepositoryUrl" action="editRepository">
|
||||||
<ww:param name="repoid" value="%{'${repository.id}'}"/>
|
<ww:param name="repoid" value="%{'${repository.id}'}"/>
|
||||||
</ww:url>
|
</ww:url>
|
||||||
<ww:url id="deleteRepositoryUrl" action="confirmDeleteRepository">
|
<ww:url id="deleteRepositoryUrl" action="confirmDeleteRepository">
|
||||||
|
@ -230,7 +230,7 @@
|
||||||
|
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<redback:ifAuthorized permission="archiva-manage-configuration">
|
<redback:ifAuthorized permission="archiva-manage-configuration">
|
||||||
<ww:url id="addRepositoryUrl" action="addRemoteRepository" method="input"/>
|
<ww:url id="addRepositoryUrl" action="addRemoteRepository"/>
|
||||||
<ww:a href="%{addRepositoryUrl}">
|
<ww:a href="%{addRepositoryUrl}">
|
||||||
<img src="<c:url value="/images/icons/create.png" />" alt="" width="16" height="16"/>
|
<img src="<c:url value="/images/icons/create.png" />" alt="" width="16" height="16"/>
|
||||||
Add
|
Add
|
||||||
|
@ -260,7 +260,7 @@
|
||||||
|
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<redback:ifAnyAuthorized permissions="archiva-manage-configuration">
|
<redback:ifAnyAuthorized permissions="archiva-manage-configuration">
|
||||||
<ww:url id="editRepositoryUrl" action="editRemoteRepository" method="input">
|
<ww:url id="editRepositoryUrl" action="editRemoteRepository">
|
||||||
<ww:param name="repoid" value="%{'${repository.id}'}"/>
|
<ww:param name="repoid" value="%{'${repository.id}'}"/>
|
||||||
</ww:url>
|
</ww:url>
|
||||||
<ww:a href="%{editRepositoryUrl}">
|
<ww:a href="%{editRepositoryUrl}">
|
||||||
|
|
|
@ -367,3 +367,24 @@ div.admin table.consumers th {
|
||||||
div.admin table.consumers td strong {
|
div.admin table.consumers td strong {
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.warningbox {
|
||||||
|
margin: 20px 40px 20px 40px;
|
||||||
|
border: 1px solid #CC0000;
|
||||||
|
background-color: #FFCCCC;
|
||||||
|
color: #000000;
|
||||||
|
font-size: 15pt;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.infobox {
|
||||||
|
margin: 20px 40px 20px 40px;
|
||||||
|
border: 1px solid #0000CC;
|
||||||
|
background-color: #EEEEFF;
|
||||||
|
font-size: 9pt;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.buttons {
|
||||||
|
text-align: center;
|
||||||
|
}
|
|
@ -0,0 +1,167 @@
|
||||||
|
package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 com.opensymphony.xwork.Action;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
|
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
import org.codehaus.plexus.redback.role.RoleManager;
|
||||||
|
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
|
||||||
|
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
|
||||||
|
import org.easymock.MockControl;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AddManagedRepositoryActionTest
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class AddManagedRepositoryActionTest
|
||||||
|
extends PlexusTestCase
|
||||||
|
{
|
||||||
|
private AddManagedRepositoryAction action;
|
||||||
|
|
||||||
|
private RoleManager roleManager;
|
||||||
|
|
||||||
|
private MockControl roleManagerControl;
|
||||||
|
|
||||||
|
private MockControl archivaConfigurationControl;
|
||||||
|
|
||||||
|
private ArchivaConfiguration archivaConfiguration;
|
||||||
|
|
||||||
|
private static final String REPO_ID = "repo-ident";
|
||||||
|
|
||||||
|
private File location;
|
||||||
|
|
||||||
|
protected void setUp()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
action = (AddManagedRepositoryAction) lookup( Action.class.getName(), "addManagedRepositoryAction" );
|
||||||
|
|
||||||
|
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
|
||||||
|
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
|
||||||
|
action.setArchivaConfiguration( archivaConfiguration );
|
||||||
|
|
||||||
|
roleManagerControl = MockControl.createControl( RoleManager.class );
|
||||||
|
roleManager = (RoleManager) roleManagerControl.getMock();
|
||||||
|
action.setRoleManager( roleManager );
|
||||||
|
location = getTestFile( "target/test/location" );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSecureActionBundle()
|
||||||
|
throws SecureActionException
|
||||||
|
{
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( new Configuration() );
|
||||||
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
|
action.prepare();
|
||||||
|
SecureActionBundle bundle = action.getSecureActionBundle();
|
||||||
|
assertTrue( bundle.requiresAuthentication() );
|
||||||
|
assertEquals( 1, bundle.getAuthorizationTuples().size() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAddRepositoryInitialPage()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( new Configuration() );
|
||||||
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
|
action.prepare();
|
||||||
|
ManagedRepositoryConfiguration configuration = action.getRepository();
|
||||||
|
assertNotNull( configuration );
|
||||||
|
assertNull( configuration.getId() );
|
||||||
|
// check all booleans are false
|
||||||
|
assertFalse( configuration.isDeleteReleasedSnapshots() );
|
||||||
|
assertFalse( configuration.isScanned() );
|
||||||
|
assertFalse( configuration.isReleases() );
|
||||||
|
assertFalse( configuration.isSnapshots() );
|
||||||
|
|
||||||
|
String status = action.input();
|
||||||
|
assertEquals( Action.INPUT, status );
|
||||||
|
|
||||||
|
// check defaults
|
||||||
|
assertFalse( configuration.isDeleteReleasedSnapshots() );
|
||||||
|
assertTrue( configuration.isScanned() );
|
||||||
|
assertTrue( configuration.isReleases() );
|
||||||
|
assertFalse( configuration.isSnapshots() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAddRepository()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
FileUtils.deleteDirectory( location );
|
||||||
|
|
||||||
|
// TODO: should be in the business model
|
||||||
|
roleManager.createTemplatedRole( "archiva-repository-manager", REPO_ID );
|
||||||
|
roleManager.createTemplatedRole( "archiva-repository-observer", REPO_ID );
|
||||||
|
|
||||||
|
roleManagerControl.replay();
|
||||||
|
|
||||||
|
Configuration configuration = new Configuration();
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( configuration );
|
||||||
|
|
||||||
|
archivaConfiguration.save( configuration );
|
||||||
|
|
||||||
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
|
action.prepare();
|
||||||
|
ManagedRepositoryConfiguration repository = action.getRepository();
|
||||||
|
populateRepository( repository );
|
||||||
|
|
||||||
|
assertFalse( location.exists() );
|
||||||
|
String status = action.commit();
|
||||||
|
assertEquals( Action.SUCCESS, status );
|
||||||
|
assertTrue( location.exists() );
|
||||||
|
|
||||||
|
assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
|
||||||
|
|
||||||
|
roleManagerControl.verify();
|
||||||
|
archivaConfigurationControl.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateRepository( ManagedRepositoryConfiguration repository )
|
||||||
|
{
|
||||||
|
repository.setId( REPO_ID );
|
||||||
|
repository.setName( "repo name" );
|
||||||
|
repository.setLocation( location.getAbsolutePath() );
|
||||||
|
repository.setLayout( "default" );
|
||||||
|
repository.setRefreshCronExpression( "* 0/5 * * * ?" );
|
||||||
|
repository.setDaysOlder( 31 );
|
||||||
|
repository.setRetentionCount( 20 );
|
||||||
|
repository.setReleases( true );
|
||||||
|
repository.setSnapshots( true );
|
||||||
|
repository.setScanned( false );
|
||||||
|
repository.setDeleteReleasedSnapshots( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: test errors during add, other actions
|
||||||
|
}
|
|
@ -0,0 +1,124 @@
|
||||||
|
package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 com.opensymphony.xwork.Action;
|
||||||
|
|
||||||
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
|
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
|
||||||
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
|
||||||
|
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
|
||||||
|
import org.easymock.MockControl;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AddRemoteRepositoryActionTest
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class AddRemoteRepositoryActionTest
|
||||||
|
extends PlexusTestCase
|
||||||
|
{
|
||||||
|
private AddRemoteRepositoryAction action;
|
||||||
|
|
||||||
|
private MockControl archivaConfigurationControl;
|
||||||
|
|
||||||
|
private ArchivaConfiguration archivaConfiguration;
|
||||||
|
|
||||||
|
private static final String REPO_ID = "remote-repo-ident";
|
||||||
|
|
||||||
|
protected void setUp()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
action = (AddRemoteRepositoryAction) lookup( Action.class.getName(), "addRemoteRepositoryAction" );
|
||||||
|
|
||||||
|
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
|
||||||
|
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
|
||||||
|
action.setArchivaConfiguration( archivaConfiguration );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSecureActionBundle()
|
||||||
|
throws SecureActionException
|
||||||
|
{
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( new Configuration() );
|
||||||
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
|
action.prepare();
|
||||||
|
SecureActionBundle bundle = action.getSecureActionBundle();
|
||||||
|
assertTrue( bundle.requiresAuthentication() );
|
||||||
|
assertEquals( 1, bundle.getAuthorizationTuples().size() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAddRemoteRepositoryInitialPage()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( new Configuration() );
|
||||||
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
|
action.prepare();
|
||||||
|
RemoteRepositoryConfiguration configuration = action.getRepository();
|
||||||
|
assertNotNull( configuration );
|
||||||
|
assertNull( configuration.getId() );
|
||||||
|
|
||||||
|
String status = action.input();
|
||||||
|
assertEquals( Action.INPUT, status );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAddRemoteRepository()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
Configuration configuration = new Configuration();
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( configuration );
|
||||||
|
|
||||||
|
archivaConfiguration.save( configuration );
|
||||||
|
|
||||||
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
|
action.prepare();
|
||||||
|
RemoteRepositoryConfiguration repository = action.getRepository();
|
||||||
|
populateRepository( repository );
|
||||||
|
|
||||||
|
String status = action.commit();
|
||||||
|
assertEquals( Action.SUCCESS, status );
|
||||||
|
|
||||||
|
assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories() );
|
||||||
|
|
||||||
|
archivaConfigurationControl.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateRepository( RemoteRepositoryConfiguration repository )
|
||||||
|
{
|
||||||
|
repository.setId( REPO_ID );
|
||||||
|
repository.setName( "repo name" );
|
||||||
|
repository.setUrl( "url" );
|
||||||
|
repository.setLayout( "default" );
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: test errors during add, other actions
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.opensymphony.xwork.Action;
|
import com.opensymphony.xwork.Action;
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.maven.archiva.configuration.Configuration;
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
|
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
|
||||||
|
@ -36,12 +36,15 @@ import java.io.File;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the repositories action returns the correct data.
|
* DeleteManagedRepositoryActionTest
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class ConfigureRepositoryActionTest
|
public class DeleteManagedRepositoryActionTest
|
||||||
extends PlexusTestCase
|
extends PlexusTestCase
|
||||||
{
|
{
|
||||||
private ConfigureRepositoryAction action;
|
private DeleteManagedRepositoryAction action;
|
||||||
|
|
||||||
private RoleManager roleManager;
|
private RoleManager roleManager;
|
||||||
|
|
||||||
|
@ -60,10 +63,7 @@ public class ConfigureRepositoryActionTest
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
// TODO: purely to quiet logging - shouldn't be needed
|
action = (DeleteManagedRepositoryAction) lookup( Action.class.getName(), "deleteManagedRepositoryAction" );
|
||||||
String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath();
|
|
||||||
System.setProperty( "appserver.base", appserverBase );
|
|
||||||
action = (ConfigureRepositoryAction) lookup( Action.class.getName(), "configureRepositoryAction" );
|
|
||||||
|
|
||||||
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
|
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
|
||||||
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
|
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
|
||||||
|
@ -88,125 +88,6 @@ public class ConfigureRepositoryActionTest
|
||||||
assertEquals( 1, bundle.getAuthorizationTuples().size() );
|
assertEquals( 1, bundle.getAuthorizationTuples().size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddRepositoryInitialPage()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
archivaConfiguration.getConfiguration();
|
|
||||||
archivaConfigurationControl.setReturnValue( new Configuration() );
|
|
||||||
archivaConfigurationControl.replay();
|
|
||||||
|
|
||||||
action.prepare();
|
|
||||||
assertNull( action.getRepoid() );
|
|
||||||
ManagedRepositoryConfiguration configuration = action.getRepository();
|
|
||||||
assertNotNull( configuration );
|
|
||||||
assertNull( configuration.getId() );
|
|
||||||
// check all booleans are false
|
|
||||||
assertFalse( configuration.isDeleteReleasedSnapshots() );
|
|
||||||
assertFalse( configuration.isScanned() );
|
|
||||||
assertFalse( configuration.isReleases() );
|
|
||||||
assertFalse( configuration.isSnapshots() );
|
|
||||||
|
|
||||||
String status = action.addInput();
|
|
||||||
assertEquals( Action.INPUT, status );
|
|
||||||
|
|
||||||
// check defaults
|
|
||||||
assertFalse( configuration.isDeleteReleasedSnapshots() );
|
|
||||||
assertTrue( configuration.isScanned() );
|
|
||||||
assertTrue( configuration.isReleases() );
|
|
||||||
assertFalse( configuration.isSnapshots() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testAddRepository()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
FileUtils.deleteDirectory( location );
|
|
||||||
|
|
||||||
// TODO: should be in the business model
|
|
||||||
roleManager.createTemplatedRole( "archiva-repository-manager", REPO_ID );
|
|
||||||
roleManager.createTemplatedRole( "archiva-repository-observer", REPO_ID );
|
|
||||||
|
|
||||||
roleManagerControl.replay();
|
|
||||||
|
|
||||||
Configuration configuration = new Configuration();
|
|
||||||
archivaConfiguration.getConfiguration();
|
|
||||||
archivaConfigurationControl.setReturnValue( configuration );
|
|
||||||
|
|
||||||
archivaConfiguration.save( configuration );
|
|
||||||
|
|
||||||
archivaConfigurationControl.replay();
|
|
||||||
|
|
||||||
action.prepare();
|
|
||||||
ManagedRepositoryConfiguration repository = action.getRepository();
|
|
||||||
populateRepository( repository );
|
|
||||||
|
|
||||||
assertFalse( location.exists() );
|
|
||||||
String status = action.add();
|
|
||||||
assertEquals( Action.SUCCESS, status );
|
|
||||||
assertTrue( location.exists() );
|
|
||||||
|
|
||||||
assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
|
|
||||||
|
|
||||||
roleManagerControl.verify();
|
|
||||||
archivaConfigurationControl.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testEditRepositoryInitialPage()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
Configuration configuration = createConfigurationForEditing( createRepository() );
|
|
||||||
|
|
||||||
archivaConfiguration.getConfiguration();
|
|
||||||
archivaConfigurationControl.setReturnValue( configuration );
|
|
||||||
archivaConfigurationControl.replay();
|
|
||||||
|
|
||||||
action.setRepoid( REPO_ID );
|
|
||||||
|
|
||||||
action.prepare();
|
|
||||||
assertEquals( REPO_ID, action.getRepoid() );
|
|
||||||
ManagedRepositoryConfiguration repository = action.getRepository();
|
|
||||||
assertNotNull( repository );
|
|
||||||
assertRepositoryEquals( repository, createRepository() );
|
|
||||||
|
|
||||||
String status = action.editInput();
|
|
||||||
assertEquals( Action.INPUT, status );
|
|
||||||
repository = action.getRepository();
|
|
||||||
assertRepositoryEquals( repository, createRepository() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testEditRepository()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
// TODO: should be in the business model
|
|
||||||
roleManager.createTemplatedRole( "archiva-repository-manager", REPO_ID );
|
|
||||||
roleManager.createTemplatedRole( "archiva-repository-observer", REPO_ID );
|
|
||||||
|
|
||||||
roleManagerControl.replay();
|
|
||||||
|
|
||||||
Configuration configuration = createConfigurationForEditing( createRepository() );
|
|
||||||
archivaConfiguration.getConfiguration();
|
|
||||||
archivaConfigurationControl.setReturnValue( configuration );
|
|
||||||
|
|
||||||
archivaConfiguration.save( configuration );
|
|
||||||
|
|
||||||
archivaConfigurationControl.replay();
|
|
||||||
|
|
||||||
action.prepare();
|
|
||||||
ManagedRepositoryConfiguration repository = action.getRepository();
|
|
||||||
populateRepository( repository );
|
|
||||||
repository.setName( "new repo name" );
|
|
||||||
|
|
||||||
String status = action.edit();
|
|
||||||
assertEquals( Action.SUCCESS, status );
|
|
||||||
|
|
||||||
ManagedRepositoryConfiguration newRepository = createRepository();
|
|
||||||
newRepository.setName( "new repo name" );
|
|
||||||
assertRepositoryEquals( repository, newRepository );
|
|
||||||
assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
|
|
||||||
|
|
||||||
roleManagerControl.verify();
|
|
||||||
archivaConfigurationControl.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteRepositoryConfirmation()
|
public void testDeleteRepositoryConfirmation()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -227,7 +108,6 @@ public class ConfigureRepositoryActionTest
|
||||||
|
|
||||||
String status = action.execute();
|
String status = action.execute();
|
||||||
assertEquals( Action.SUCCESS, status );
|
assertEquals( Action.SUCCESS, status );
|
||||||
assertEquals( "delete-entry", action.getDeleteMode() );
|
|
||||||
repository = action.getRepository();
|
repository = action.getRepository();
|
||||||
assertRepositoryEquals( repository, createRepository() );
|
assertRepositoryEquals( repository, createRepository() );
|
||||||
assertEquals( Collections.singletonList( originalRepository ), configuration.getManagedRepositories() );
|
assertEquals( Collections.singletonList( originalRepository ), configuration.getManagedRepositories() );
|
||||||
|
@ -237,7 +117,7 @@ public class ConfigureRepositoryActionTest
|
||||||
throws RegistryException, IndeterminateConfigurationException
|
throws RegistryException, IndeterminateConfigurationException
|
||||||
{
|
{
|
||||||
Configuration configuration = prepDeletionTest( createRepository(), "delete-entry" );
|
Configuration configuration = prepDeletionTest( createRepository(), "delete-entry" );
|
||||||
String status = action.delete();
|
String status = action.deleteEntry();
|
||||||
assertEquals( Action.SUCCESS, status );
|
assertEquals( Action.SUCCESS, status );
|
||||||
|
|
||||||
assertTrue( configuration.getManagedRepositories().isEmpty() );
|
assertTrue( configuration.getManagedRepositories().isEmpty() );
|
||||||
|
@ -249,7 +129,7 @@ public class ConfigureRepositoryActionTest
|
||||||
throws RegistryException, IndeterminateConfigurationException
|
throws RegistryException, IndeterminateConfigurationException
|
||||||
{
|
{
|
||||||
Configuration configuration = prepDeletionTest( createRepository(), "delete-contents" );
|
Configuration configuration = prepDeletionTest( createRepository(), "delete-contents" );
|
||||||
String status = action.delete();
|
String status = action.deleteContents();
|
||||||
assertEquals( Action.SUCCESS, status );
|
assertEquals( Action.SUCCESS, status );
|
||||||
|
|
||||||
assertTrue( configuration.getManagedRepositories().isEmpty() );
|
assertTrue( configuration.getManagedRepositories().isEmpty() );
|
||||||
|
@ -288,11 +168,9 @@ public class ConfigureRepositoryActionTest
|
||||||
archivaConfigurationControl.replay();
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
action.setRepoid( REPO_ID );
|
action.setRepoid( REPO_ID );
|
||||||
action.setDeleteMode( mode );
|
|
||||||
|
|
||||||
action.prepare();
|
action.prepare();
|
||||||
assertEquals( REPO_ID, action.getRepoid() );
|
assertEquals( REPO_ID, action.getRepoid() );
|
||||||
assertEquals( mode, action.getDeleteMode() );
|
|
||||||
ManagedRepositoryConfiguration repository = action.getRepository();
|
ManagedRepositoryConfiguration repository = action.getRepository();
|
||||||
assertNotNull( repository );
|
assertNotNull( repository );
|
||||||
assertRepositoryEquals( repository, createRepository() );
|
assertRepositoryEquals( repository, createRepository() );
|
||||||
|
@ -348,7 +226,4 @@ public class ConfigureRepositoryActionTest
|
||||||
repository.setDeleteReleasedSnapshots( true );
|
repository.setDeleteReleasedSnapshots( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test errors during add, other actions
|
|
||||||
// TODO: what if there are proxy connectors attached to a deleted repository?
|
|
||||||
// TODO: what about removing proxied content if a proxy is removed?
|
|
||||||
}
|
}
|
|
@ -20,150 +20,46 @@ package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.opensymphony.xwork.Action;
|
import com.opensymphony.xwork.Action;
|
||||||
|
|
||||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.maven.archiva.configuration.Configuration;
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
|
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
|
||||||
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
|
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
|
|
||||||
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
|
|
||||||
import org.codehaus.plexus.registry.RegistryException;
|
import org.codehaus.plexus.registry.RegistryException;
|
||||||
import org.easymock.MockControl;
|
import org.easymock.MockControl;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the repositories action returns the correct data.
|
* DeleteRemoteRepositoryActionTest
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class ConfigureRemoteRepositoryActionTest
|
public class DeleteRemoteRepositoryActionTest
|
||||||
extends PlexusTestCase
|
extends PlexusTestCase
|
||||||
{
|
{
|
||||||
private ConfigureRemoteRepositoryAction action;
|
private static final String REPO_ID = "remote-repo-ident";
|
||||||
|
|
||||||
|
private DeleteRemoteRepositoryAction action;
|
||||||
|
|
||||||
private MockControl archivaConfigurationControl;
|
private MockControl archivaConfigurationControl;
|
||||||
|
|
||||||
private ArchivaConfiguration archivaConfiguration;
|
private ArchivaConfiguration archivaConfiguration;
|
||||||
|
|
||||||
private static final String REPO_ID = "remote-repo-ident";
|
|
||||||
|
|
||||||
protected void setUp()
|
protected void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
// TODO: purely to quiet logging - shouldn't be needed
|
action = (DeleteRemoteRepositoryAction) lookup( Action.class.getName(), "deleteRemoteRepositoryAction" );
|
||||||
String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath();
|
|
||||||
System.setProperty( "appserver.base", appserverBase );
|
|
||||||
action = (ConfigureRemoteRepositoryAction) lookup( Action.class.getName(), "configureRemoteRepositoryAction" );
|
|
||||||
|
|
||||||
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
|
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
|
||||||
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
|
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
|
||||||
action.setArchivaConfiguration( archivaConfiguration );
|
action.setArchivaConfiguration( archivaConfiguration );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSecureActionBundle()
|
|
||||||
throws SecureActionException
|
|
||||||
{
|
|
||||||
archivaConfiguration.getConfiguration();
|
|
||||||
archivaConfigurationControl.setReturnValue( new Configuration() );
|
|
||||||
archivaConfigurationControl.replay();
|
|
||||||
|
|
||||||
action.prepare();
|
|
||||||
SecureActionBundle bundle = action.getSecureActionBundle();
|
|
||||||
assertTrue( bundle.requiresAuthentication() );
|
|
||||||
assertEquals( 1, bundle.getAuthorizationTuples().size() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testAddRemoteRepositoryInitialPage()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
archivaConfiguration.getConfiguration();
|
|
||||||
archivaConfigurationControl.setReturnValue( new Configuration() );
|
|
||||||
archivaConfigurationControl.replay();
|
|
||||||
|
|
||||||
action.prepare();
|
|
||||||
assertNull( action.getRepoid() );
|
|
||||||
RemoteRepositoryConfiguration configuration = action.getRepository();
|
|
||||||
assertNotNull( configuration );
|
|
||||||
assertNull( configuration.getId() );
|
|
||||||
|
|
||||||
String status = action.input();
|
|
||||||
assertEquals( Action.INPUT, status );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testAddRemoteRepository()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
Configuration configuration = new Configuration();
|
|
||||||
archivaConfiguration.getConfiguration();
|
|
||||||
archivaConfigurationControl.setReturnValue( configuration );
|
|
||||||
|
|
||||||
archivaConfiguration.save( configuration );
|
|
||||||
|
|
||||||
archivaConfigurationControl.replay();
|
|
||||||
|
|
||||||
action.prepare();
|
|
||||||
RemoteRepositoryConfiguration repository = action.getRepository();
|
|
||||||
populateRepository( repository );
|
|
||||||
|
|
||||||
String status = action.add();
|
|
||||||
assertEquals( Action.SUCCESS, status );
|
|
||||||
|
|
||||||
assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories() );
|
|
||||||
|
|
||||||
archivaConfigurationControl.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testEditRemoteRepositoryInitialPage()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
Configuration configuration = createConfigurationForEditing( createRepository() );
|
|
||||||
|
|
||||||
archivaConfiguration.getConfiguration();
|
|
||||||
archivaConfigurationControl.setReturnValue( configuration );
|
|
||||||
archivaConfigurationControl.replay();
|
|
||||||
|
|
||||||
action.setRepoid( REPO_ID );
|
|
||||||
|
|
||||||
action.prepare();
|
|
||||||
assertEquals( REPO_ID, action.getRepoid() );
|
|
||||||
RemoteRepositoryConfiguration repository = action.getRepository();
|
|
||||||
assertNotNull( repository );
|
|
||||||
assertRepositoryEquals( repository, createRepository() );
|
|
||||||
|
|
||||||
String status = action.input();
|
|
||||||
assertEquals( Action.INPUT, status );
|
|
||||||
repository = action.getRepository();
|
|
||||||
assertRepositoryEquals( repository, createRepository() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testEditRemoteRepository()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
Configuration configuration = createConfigurationForEditing( createRepository() );
|
|
||||||
archivaConfiguration.getConfiguration();
|
|
||||||
archivaConfigurationControl.setReturnValue( configuration );
|
|
||||||
|
|
||||||
archivaConfiguration.save( configuration );
|
|
||||||
|
|
||||||
archivaConfigurationControl.replay();
|
|
||||||
|
|
||||||
action.prepare();
|
|
||||||
RemoteRepositoryConfiguration repository = action.getRepository();
|
|
||||||
populateRepository( repository );
|
|
||||||
repository.setName( "new repo name" );
|
|
||||||
|
|
||||||
String status = action.edit();
|
|
||||||
assertEquals( Action.SUCCESS, status );
|
|
||||||
|
|
||||||
RemoteRepositoryConfiguration newRepository = createRepository();
|
|
||||||
newRepository.setName( "new repo name" );
|
|
||||||
assertRepositoryEquals( repository, newRepository );
|
|
||||||
assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories() );
|
|
||||||
|
|
||||||
archivaConfigurationControl.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteRemoteRepositoryConfirmation()
|
public void testDeleteRemoteRepositoryConfirmation()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -182,17 +78,36 @@ public class ConfigureRemoteRepositoryActionTest
|
||||||
assertNotNull( repository );
|
assertNotNull( repository );
|
||||||
assertRepositoryEquals( repository, createRepository() );
|
assertRepositoryEquals( repository, createRepository() );
|
||||||
|
|
||||||
String status = action.execute();
|
String status = action.confirmDelete();
|
||||||
assertEquals( Action.SUCCESS, status );
|
assertEquals( Action.INPUT, status );
|
||||||
repository = action.getRepository();
|
repository = action.getRepository();
|
||||||
assertRepositoryEquals( repository, createRepository() );
|
assertRepositoryEquals( repository, createRepository() );
|
||||||
assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() );
|
assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteRemoteRepositoryKeepContent()
|
public void testDeleteRemoteRepository()
|
||||||
throws RegistryException, IndeterminateConfigurationException
|
throws RegistryException, IndeterminateConfigurationException
|
||||||
{
|
{
|
||||||
Configuration configuration = executeDeletionTest( createRepository() );
|
Configuration configuration = createConfigurationForEditing( createRepository() );
|
||||||
|
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( configuration );
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( configuration );
|
||||||
|
|
||||||
|
archivaConfiguration.save( configuration );
|
||||||
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
|
action.setRepoid( REPO_ID );
|
||||||
|
|
||||||
|
action.prepare();
|
||||||
|
assertEquals( REPO_ID, action.getRepoid() );
|
||||||
|
RemoteRepositoryConfiguration repository = action.getRepository();
|
||||||
|
assertNotNull( repository );
|
||||||
|
assertRepositoryEquals( repository, createRepository() );
|
||||||
|
|
||||||
|
String status = action.delete();
|
||||||
|
assertEquals( Action.SUCCESS, status );
|
||||||
|
|
||||||
assertTrue( configuration.getRemoteRepositories().isEmpty() );
|
assertTrue( configuration.getRemoteRepositories().isEmpty() );
|
||||||
}
|
}
|
||||||
|
@ -227,32 +142,21 @@ public class ConfigureRemoteRepositoryActionTest
|
||||||
assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() );
|
assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private Configuration executeDeletionTest( RemoteRepositoryConfiguration originalRepository )
|
private Configuration createConfigurationForEditing( RemoteRepositoryConfiguration repositoryConfiguration )
|
||||||
throws RegistryException, IndeterminateConfigurationException
|
|
||||||
{
|
{
|
||||||
Configuration configuration = createConfigurationForEditing( originalRepository );
|
Configuration configuration = new Configuration();
|
||||||
|
configuration.addRemoteRepository( repositoryConfiguration );
|
||||||
archivaConfiguration.getConfiguration();
|
|
||||||
archivaConfigurationControl.setReturnValue( configuration );
|
|
||||||
archivaConfiguration.getConfiguration();
|
|
||||||
archivaConfigurationControl.setReturnValue( configuration );
|
|
||||||
|
|
||||||
archivaConfiguration.save( configuration );
|
|
||||||
archivaConfigurationControl.replay();
|
|
||||||
|
|
||||||
action.setRepoid( REPO_ID );
|
|
||||||
|
|
||||||
action.prepare();
|
|
||||||
assertEquals( REPO_ID, action.getRepoid() );
|
|
||||||
RemoteRepositoryConfiguration repository = action.getRepository();
|
|
||||||
assertNotNull( repository );
|
|
||||||
assertRepositoryEquals( repository, createRepository() );
|
|
||||||
|
|
||||||
String status = action.delete();
|
|
||||||
assertEquals( Action.SUCCESS, status );
|
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RemoteRepositoryConfiguration createRepository()
|
||||||
|
{
|
||||||
|
RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration();
|
||||||
|
r.setId( REPO_ID );
|
||||||
|
populateRepository( r );
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
private void assertRepositoryEquals( RemoteRepositoryConfiguration expectedRepository,
|
private void assertRepositoryEquals( RemoteRepositoryConfiguration expectedRepository,
|
||||||
RemoteRepositoryConfiguration actualRepository )
|
RemoteRepositoryConfiguration actualRepository )
|
||||||
{
|
{
|
||||||
|
@ -262,21 +166,6 @@ public class ConfigureRemoteRepositoryActionTest
|
||||||
assertEquals( expectedRepository.getName(), actualRepository.getName() );
|
assertEquals( expectedRepository.getName(), actualRepository.getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private Configuration createConfigurationForEditing( RemoteRepositoryConfiguration repositoryConfiguration )
|
|
||||||
{
|
|
||||||
Configuration configuration = new Configuration();
|
|
||||||
configuration.addRemoteRepository( repositoryConfiguration );
|
|
||||||
return configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
private RemoteRepositoryConfiguration createRepository()
|
|
||||||
{
|
|
||||||
RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration();
|
|
||||||
r.setId( REPO_ID );
|
|
||||||
populateRepository( r );
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void populateRepository( RemoteRepositoryConfiguration repository )
|
private void populateRepository( RemoteRepositoryConfiguration repository )
|
||||||
{
|
{
|
||||||
repository.setId( REPO_ID );
|
repository.setId( REPO_ID );
|
||||||
|
@ -284,8 +173,7 @@ public class ConfigureRemoteRepositoryActionTest
|
||||||
repository.setUrl( "url" );
|
repository.setUrl( "url" );
|
||||||
repository.setLayout( "default" );
|
repository.setLayout( "default" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test errors during add, other actions
|
|
||||||
// TODO: what if there are proxy connectors attached to a deleted repository?
|
// TODO: what if there are proxy connectors attached to a deleted repository?
|
||||||
// TODO: what about removing proxied content if a proxy is removed?
|
// TODO: what about removing proxied content if a proxy is removed?
|
||||||
}
|
}
|
|
@ -0,0 +1,196 @@
|
||||||
|
package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 com.opensymphony.xwork.Action;
|
||||||
|
|
||||||
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
|
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
import org.codehaus.plexus.redback.role.RoleManager;
|
||||||
|
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
|
||||||
|
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
|
||||||
|
import org.easymock.MockControl;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EditManagedRepositoryActionTest
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class EditManagedRepositoryActionTest
|
||||||
|
extends PlexusTestCase
|
||||||
|
{
|
||||||
|
private EditManagedRepositoryAction action;
|
||||||
|
|
||||||
|
private RoleManager roleManager;
|
||||||
|
|
||||||
|
private MockControl roleManagerControl;
|
||||||
|
|
||||||
|
private MockControl archivaConfigurationControl;
|
||||||
|
|
||||||
|
private ArchivaConfiguration archivaConfiguration;
|
||||||
|
|
||||||
|
private static final String REPO_ID = "repo-ident";
|
||||||
|
|
||||||
|
private File location;
|
||||||
|
|
||||||
|
protected void setUp()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
action = (EditManagedRepositoryAction) lookup( Action.class.getName(), "editManagedRepositoryAction" );
|
||||||
|
|
||||||
|
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
|
||||||
|
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
|
||||||
|
action.setArchivaConfiguration( archivaConfiguration );
|
||||||
|
|
||||||
|
roleManagerControl = MockControl.createControl( RoleManager.class );
|
||||||
|
roleManager = (RoleManager) roleManagerControl.getMock();
|
||||||
|
action.setRoleManager( roleManager );
|
||||||
|
location = getTestFile( "target/test/location" );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSecureActionBundle()
|
||||||
|
throws SecureActionException
|
||||||
|
{
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( new Configuration() );
|
||||||
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
|
action.prepare();
|
||||||
|
SecureActionBundle bundle = action.getSecureActionBundle();
|
||||||
|
assertTrue( bundle.requiresAuthentication() );
|
||||||
|
assertEquals( 1, bundle.getAuthorizationTuples().size() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testEditRepositoryInitialPage()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
Configuration configuration = createConfigurationForEditing( createRepository() );
|
||||||
|
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( configuration );
|
||||||
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
|
action.setRepoid( REPO_ID );
|
||||||
|
|
||||||
|
action.prepare();
|
||||||
|
assertEquals( REPO_ID, action.getRepoid() );
|
||||||
|
ManagedRepositoryConfiguration repository = action.getRepository();
|
||||||
|
assertNotNull( repository );
|
||||||
|
assertRepositoryEquals( repository, createRepository() );
|
||||||
|
|
||||||
|
String status = action.input();
|
||||||
|
assertEquals( Action.INPUT, status );
|
||||||
|
repository = action.getRepository();
|
||||||
|
assertRepositoryEquals( repository, createRepository() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testEditRepository()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
// TODO: should be in the business model
|
||||||
|
roleManager.createTemplatedRole( "archiva-repository-manager", REPO_ID );
|
||||||
|
roleManager.createTemplatedRole( "archiva-repository-observer", REPO_ID );
|
||||||
|
|
||||||
|
roleManagerControl.replay();
|
||||||
|
|
||||||
|
Configuration configuration = createConfigurationForEditing( createRepository() );
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( configuration );
|
||||||
|
archivaConfigurationControl.setReturnValue( configuration );
|
||||||
|
|
||||||
|
archivaConfiguration.save( configuration );
|
||||||
|
|
||||||
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
|
action.setRepoid( REPO_ID );
|
||||||
|
action.prepare();
|
||||||
|
assertEquals( REPO_ID, action.getRepoid() );
|
||||||
|
ManagedRepositoryConfiguration repository = action.getRepository();
|
||||||
|
populateRepository( repository );
|
||||||
|
repository.setName( "new repo name" );
|
||||||
|
|
||||||
|
String status = action.commit();
|
||||||
|
assertEquals( Action.SUCCESS, status );
|
||||||
|
|
||||||
|
ManagedRepositoryConfiguration newRepository = createRepository();
|
||||||
|
newRepository.setName( "new repo name" );
|
||||||
|
assertRepositoryEquals( repository, newRepository );
|
||||||
|
assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
|
||||||
|
|
||||||
|
roleManagerControl.verify();
|
||||||
|
archivaConfigurationControl.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertRepositoryEquals( ManagedRepositoryConfiguration expectedRepository,
|
||||||
|
ManagedRepositoryConfiguration actualRepository )
|
||||||
|
{
|
||||||
|
assertEquals( expectedRepository.getDaysOlder(), actualRepository.getDaysOlder() );
|
||||||
|
assertEquals( expectedRepository.getId(), actualRepository.getId() );
|
||||||
|
assertEquals( expectedRepository.getIndexDir(), actualRepository.getIndexDir() );
|
||||||
|
assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
|
||||||
|
assertEquals( expectedRepository.getLocation(), actualRepository.getLocation() );
|
||||||
|
assertEquals( expectedRepository.getName(), actualRepository.getName() );
|
||||||
|
assertEquals( expectedRepository.getRefreshCronExpression(), actualRepository.getRefreshCronExpression() );
|
||||||
|
assertEquals( expectedRepository.getRetentionCount(), actualRepository.getRetentionCount() );
|
||||||
|
assertEquals( expectedRepository.isDeleteReleasedSnapshots(), actualRepository.isDeleteReleasedSnapshots() );
|
||||||
|
assertEquals( expectedRepository.isScanned(), actualRepository.isScanned() );
|
||||||
|
assertEquals( expectedRepository.isReleases(), actualRepository.isReleases() );
|
||||||
|
assertEquals( expectedRepository.isSnapshots(), actualRepository.isSnapshots() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private Configuration createConfigurationForEditing( ManagedRepositoryConfiguration repositoryConfiguration )
|
||||||
|
{
|
||||||
|
Configuration configuration = new Configuration();
|
||||||
|
configuration.addManagedRepository( repositoryConfiguration );
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ManagedRepositoryConfiguration createRepository()
|
||||||
|
{
|
||||||
|
ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
|
||||||
|
r.setId( REPO_ID );
|
||||||
|
populateRepository( r );
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateRepository( ManagedRepositoryConfiguration repository )
|
||||||
|
{
|
||||||
|
repository.setId( REPO_ID );
|
||||||
|
repository.setName( "repo name" );
|
||||||
|
repository.setLocation( location.getAbsolutePath() );
|
||||||
|
repository.setLayout( "default" );
|
||||||
|
repository.setRefreshCronExpression( "* 0/5 * * * ?" );
|
||||||
|
repository.setDaysOlder( 31 );
|
||||||
|
repository.setRetentionCount( 20 );
|
||||||
|
repository.setReleases( true );
|
||||||
|
repository.setSnapshots( true );
|
||||||
|
repository.setScanned( false );
|
||||||
|
repository.setDeleteReleasedSnapshots( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,158 @@
|
||||||
|
package org.apache.maven.archiva.web.action.admin.repositories;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 com.opensymphony.xwork.Action;
|
||||||
|
|
||||||
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
|
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
|
||||||
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
|
||||||
|
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
|
||||||
|
import org.easymock.MockControl;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EditRemoteRepositoryActionTest
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class EditRemoteRepositoryActionTest
|
||||||
|
extends PlexusTestCase
|
||||||
|
{
|
||||||
|
private static final String REPO_ID = "remote-repo-ident";
|
||||||
|
|
||||||
|
private EditRemoteRepositoryAction action;
|
||||||
|
|
||||||
|
private MockControl archivaConfigurationControl;
|
||||||
|
|
||||||
|
private ArchivaConfiguration archivaConfiguration;
|
||||||
|
|
||||||
|
public void testEditRemoteRepository()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
Configuration configuration = createConfigurationForEditing( createRepository() );
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( configuration );
|
||||||
|
archivaConfigurationControl.setReturnValue( configuration );
|
||||||
|
archivaConfiguration.save( configuration );
|
||||||
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
|
action.setRepoid( REPO_ID );
|
||||||
|
action.prepare();
|
||||||
|
assertEquals( REPO_ID, action.getRepoid() );
|
||||||
|
RemoteRepositoryConfiguration repository = action.getRepository();
|
||||||
|
populateRepository( repository );
|
||||||
|
repository.setName( "new repo name" );
|
||||||
|
|
||||||
|
String status = action.commit();
|
||||||
|
assertEquals( Action.SUCCESS, status );
|
||||||
|
|
||||||
|
RemoteRepositoryConfiguration newRepository = createRepository();
|
||||||
|
newRepository.setName( "new repo name" );
|
||||||
|
assertRepositoryEquals( repository, newRepository );
|
||||||
|
assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories() );
|
||||||
|
|
||||||
|
archivaConfigurationControl.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testEditRemoteRepositoryInitialPage()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
Configuration configuration = createConfigurationForEditing( createRepository() );
|
||||||
|
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( configuration );
|
||||||
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
|
action.setRepoid( REPO_ID );
|
||||||
|
|
||||||
|
action.prepare();
|
||||||
|
assertEquals( REPO_ID, action.getRepoid() );
|
||||||
|
RemoteRepositoryConfiguration repository = action.getRepository();
|
||||||
|
assertNotNull( repository );
|
||||||
|
assertRepositoryEquals( repository, createRepository() );
|
||||||
|
|
||||||
|
String status = action.input();
|
||||||
|
assertEquals( Action.INPUT, status );
|
||||||
|
repository = action.getRepository();
|
||||||
|
assertRepositoryEquals( repository, createRepository() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSecureActionBundle()
|
||||||
|
throws SecureActionException
|
||||||
|
{
|
||||||
|
archivaConfiguration.getConfiguration();
|
||||||
|
archivaConfigurationControl.setReturnValue( new Configuration() );
|
||||||
|
archivaConfigurationControl.replay();
|
||||||
|
|
||||||
|
action.prepare();
|
||||||
|
SecureActionBundle bundle = action.getSecureActionBundle();
|
||||||
|
assertTrue( bundle.requiresAuthentication() );
|
||||||
|
assertEquals( 1, bundle.getAuthorizationTuples().size() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertRepositoryEquals( RemoteRepositoryConfiguration expectedRepository,
|
||||||
|
RemoteRepositoryConfiguration actualRepository )
|
||||||
|
{
|
||||||
|
assertEquals( expectedRepository.getId(), actualRepository.getId() );
|
||||||
|
assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
|
||||||
|
assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
|
||||||
|
assertEquals( expectedRepository.getName(), actualRepository.getName() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private Configuration createConfigurationForEditing( RemoteRepositoryConfiguration repositoryConfiguration )
|
||||||
|
{
|
||||||
|
Configuration configuration = new Configuration();
|
||||||
|
configuration.addRemoteRepository( repositoryConfiguration );
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RemoteRepositoryConfiguration createRepository()
|
||||||
|
{
|
||||||
|
RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration();
|
||||||
|
r.setId( REPO_ID );
|
||||||
|
populateRepository( r );
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateRepository( RemoteRepositoryConfiguration repository )
|
||||||
|
{
|
||||||
|
repository.setId( REPO_ID );
|
||||||
|
repository.setName( "repo name" );
|
||||||
|
repository.setUrl( "url" );
|
||||||
|
repository.setLayout( "default" );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setUp()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
action = (EditRemoteRepositoryAction) lookup( Action.class.getName(), "editRemoteRepositoryAction" );
|
||||||
|
|
||||||
|
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
|
||||||
|
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
|
||||||
|
action.setArchivaConfiguration( archivaConfiguration );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||||
|
|
||||||
|
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||||
|
|
||||||
|
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||||
|
<param name="Target" value="System.out"/>
|
||||||
|
<layout class="org.apache.log4j.PatternLayout">
|
||||||
|
<param name="ConversionPattern" value="%5p|%t|%5r|%-30c{1} - %m%n"/>
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- Help identify bugs during testing -->
|
||||||
|
<logger name="org.apache.maven.archiva">
|
||||||
|
<level value="debug"/>
|
||||||
|
</logger>
|
||||||
|
|
||||||
|
<logger name="org.codehaus.plexus.security">
|
||||||
|
<level value="info"/>
|
||||||
|
</logger>
|
||||||
|
|
||||||
|
<logger name="org.codehaus.plexus.PlexusContainer">
|
||||||
|
<level value="info"/>
|
||||||
|
</logger>
|
||||||
|
|
||||||
|
<logger name="JPOX">
|
||||||
|
<level value="warn"/>
|
||||||
|
</logger>
|
||||||
|
|
||||||
|
<logger name="JPOX.MetaData">
|
||||||
|
<level value="error"/>
|
||||||
|
</logger>
|
||||||
|
|
||||||
|
<logger name="JPOX.RDBMS.SQL">
|
||||||
|
<level value="error"/>
|
||||||
|
</logger>
|
||||||
|
|
||||||
|
<logger name="SQL">
|
||||||
|
<level value="error"/>
|
||||||
|
</logger>
|
||||||
|
|
||||||
|
<root>
|
||||||
|
<priority value ="debug" />
|
||||||
|
<appender-ref ref="console" />
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</log4j:configuration>
|
Loading…
Reference in New Issue