import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import java.util.List;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
/**
* @plexus.component role="com.opensymphony.xwork2.Action" role-hint="mergeAction" instantiation-strategy="per-lookup"
private List<ArtifactMetadata> conflictSourceArtifacts;
+ private List<ArtifactMetadata> conflictSourceArtifactsToBeDisplayed;
+
public String getConflicts()
{
targetRepoId = repoid + "-stage";
targetRepoId = repoid + "-stage";
conflictSourceArtifacts = repositoryMerger.getConflictsartifacts( targetRepoId, repoid );
this.repository = new ManagedRepositoryConfiguration();
+ setConflictSourceArtifactsToBeDisplayed( conflictSourceArtifacts );
}
public String getTargetRepoId()
{
this.conflictSourceArtifacts = conflictSourceArtifacts;
}
+
+ public List<ArtifactMetadata> getConflictSourceArtifactsToBeDisplayed()
+ {
+ return conflictSourceArtifactsToBeDisplayed;
+ }
+
+ public void setConflictSourceArtifactsToBeDisplayed( List<ArtifactMetadata> conflictSourceArtifacts )
+ throws Exception
+ {
+ this.conflictSourceArtifactsToBeDisplayed = new ArrayList<ArtifactMetadata>();
+ HashMap<String, ArtifactMetadata> map = new HashMap<String, ArtifactMetadata>();
+ for ( ArtifactMetadata metadata : conflictSourceArtifacts )
+ {
+ String metadataId = metadata.getNamespace() + metadata.getProject() + metadata.getProjectVersion() + metadata.getVersion();
+ map.put( metadataId, metadata );
+ }
+ Iterator iterator = map.keySet().iterator();
+
+ while ( iterator.hasNext() )
+ {
+ conflictSourceArtifactsToBeDisplayed.add( map.get(iterator.next() ));
+ }
+
+ }
}
{
private ManagedRepositoryConfiguration repository;
+ private ManagedRepositoryConfiguration stagingRepository;
+
private String repoid;
/**
if ( StringUtils.isNotBlank( repoid ) )
{
this.repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid );
+ this.stagingRepository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid +"-stage");
}
}
}
private String deleteRepository( boolean deleteContents )
- {
+ {
ManagedRepositoryConfiguration existingRepository = repository;
+ ManagedRepositoryConfiguration attachedStagingRepo = stagingRepository;
if ( existingRepository == null )
{
addActionError( "A repository with that id does not exist" );
cleanupRepositoryData( existingRepository );
removeRepository( repoid, configuration );
triggerAuditEvent( repoid, null, AuditEvent.DELETE_MANAGED_REPO );
+ if(attachedStagingRepo !=null)
+ {
+ cleanupRepositoryData( attachedStagingRepo );
+ removeRepository( repoid +"-stage", configuration );
+ triggerAuditEvent(repoid +"-stage", null, AuditEvent.DELETE_MANAGED_REPO );
+
+ }
result = saveConfiguration( configuration );
if ( result.equals( SUCCESS ) )
{
if ( deleteContents )
{
+ if(attachedStagingRepo !=null)
+ {
+ removeContents( attachedStagingRepo );
+ }
removeContents( existingRepository );
}
}
{
archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository( cleanupRepository.getId() );
}
- }
+ }
}
}
*/
private ManagedRepositoryConfiguration repository;
+ private ManagedRepositoryConfiguration stagingRepository;
+
private String repoid;
private final String action = "editRepository";
if ( StringUtils.isNotBlank( repoid ) )
{
repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid );
+ stagingRepository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid + "-stage" );
}
else if ( repository != null )
{
{
ManagedRepositoryConfiguration existingConfig =
archivaConfiguration.getConfiguration().findManagedRepositoryById( repository.getId() );
-
boolean resetStats = false;
// check if the location was changed
// We are in edit mode, remove the old repository configuration.
removeRepository( repository.getId(), configuration );
+ if ( stagingRepository != null )
+ {
+ removeRepository( stagingRepository.getId(), configuration );
+ }
// Save the repository configuration.
String result;
triggerAuditEvent( repository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO );
addRepositoryRoles( repository );
+ //update changes of the staging repo
if ( stageNeeded )
{
- ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig();
-// if(new File( stagingRepository.getLocation()).exists())
+
+ stagingRepository = getStageRepoConfig( configuration );
addRepository( stagingRepository, configuration );
- triggerAuditEvent( stagingRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO );
addRepositoryRoles( stagingRepository );
}
+ //delete staging repo when we dont need it
+ if ( !stageNeeded )
+ {
+ stagingRepository = getStageRepoConfig(configuration);
+ removeRepository( stagingRepository.getId(), configuration );
+ removeContents( stagingRepository );
+ removeRepositoryRoles( stagingRepository );
+ }
result = saveConfiguration( configuration );
if ( resetStats )
return result;
}
- private ManagedRepositoryConfiguration getStageRepoConfig()
+ private ManagedRepositoryConfiguration getStageRepoConfig( Configuration configuration )
+ {
+ for ( ManagedRepositoryConfiguration repoConf : configuration.getManagedRepositories() )
+ {
+ if ( repoConf.getId().equals( repository.getId() + "-stage" ) )
+ {
+ stagingRepository = repoConf;
+ removeRepository( repoConf .getId() , configuration);
+ updateStagingRepository( stagingRepository );
+ return stagingRepository;
+ }
+ }
+
+ stagingRepository = new ManagedRepositoryConfiguration();
+ updateStagingRepository( stagingRepository );
+
+ return stagingRepository;
+ }
+
+ private void updateStagingRepository( ManagedRepositoryConfiguration stagingRepository )
{
- ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
stagingRepository.setId( repository.getId() + "-stage" );
stagingRepository.setLayout( repository.getLayout() );
stagingRepository.setName( repository.getName() + "-stage" );
stagingRepository.setRetentionCount( repository.getRetentionCount() );
stagingRepository.setScanned( repository.isScanned() );
stagingRepository.setSnapshots( repository.isSnapshots() );
- return stagingRepository;
}
-
+
@Override
public void validate()
{
private void resetStatistics()
{
repositoryStatisticsManager.deleteStatistics( repository.getId() );
- }
+ }
public String getRepoid()
{
{
this.repositoryStatisticsManager = repositoryStatisticsManager;
}
+
+ public ManagedRepositoryConfiguration getStagingRepository()
+ {
+ return stagingRepository;
+ }
+
+ public void setStagingRepository( ManagedRepositoryConfiguration stagingRepository )
+ {
+ this.stagingRepository = stagingRepository;
+ }
}
<s:hidden name="repository.id"/>
<s:label label="ID" name="repository.id" />
<%@ include file="/WEB-INF/jsp/admin/include/repositoryForm.jspf" %>
- <s:checkbox name="stageNeeded" value="stageNeeded" label="Create stage repository"/>
+
+ <c:set var="stats" value="${stagingRepository == null}"/>
+ <jsp:useBean id="stats" type="java.lang.Boolean" scope="page"/>
+ <c:if
+ test='<%= !stats.booleanValue() %>'>
+ <s:checkbox name="stageNeeded" value="true" label="Create stage repository"/>
+ </c:if>
+ <c:if
+ test='<%= stats.booleanValue() %>'>
+ <s:checkbox name="stageNeeded" value="false" label="Create stage repository"/>
+ </c:if>
<s:submit value="Update Repository"/>
</s:form>
<strong>WARNING: The following are the artifacts in conflict.</strong>
</p>
</div>
- <c:forEach items="${conflictSourceArtifacts}" var="artifact">
+ <c:forEach items="${conflictSourceArtifactsToBeDisplayed}" var="artifact">
<tr>
<td>Artifact Id :</td>
- <td><code>${artifact.id}</code></td>
+ <%--<td><code>${artifact.id}</code></td>--%>
+ <td align="left"> <code>${artifact.namespace} ${" "} ${artifact.project} ${" "} ${artifact.version}</code></td>
</tr>
</c:forEach>
<tr>
import java.util.List;
/**
- * DeleteManagedRepositoryActionTest
+ * DeleteManagedRepositoryActionTest
*
* @version $Id$
*/
private MockControl archivaConfigurationControl;
private ArchivaConfiguration archivaConfiguration;
-
+
private static final String REPO_ID = "repo-ident";
private File location;
super.setUp();
action = new DeleteManagedRepositoryAction();
-
+
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
action.setArchivaConfiguration( archivaConfiguration );
-
+
roleManagerControl = MockControl.createControl( RoleManager.class );
roleManager = (RoleManager) roleManagerControl.getMock();
action.setRoleManager( roleManager );
archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( configuration );
+
+ Configuration stageRepoConfiguration = new Configuration();
+ stageRepoConfiguration.addManagedRepository( createSatingRepository() );
+ archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
+
archivaConfigurationControl.replay();
action.setRepoid( REPO_ID );
ManagedRepositoryConfiguration repository = action.getRepository();
assertNotNull( repository );
assertRepositoryEquals( repository, createRepository() );
-
+
String status = action.execute();
assertEquals( Action.SUCCESS, status );
-
+
repository = action.getRepository();
assertRepositoryEquals( repository, createRepository() );
assertEquals( Collections.singletonList( originalRepository ), configuration.getManagedRepositories() );
repositoryStatisticsManagerControl.replay();
prepareRoleManagerMock();
-
+
Configuration configuration = prepDeletionTest( createRepository(), 4 );
MockControl control = mockAuditListeners();
repositoryStatisticsManagerControl.replay();
prepareRoleManagerMock();
-
- Configuration configuration = prepDeletionTest( createRepository(), 4 );
-
+
+ Configuration configuration = prepDeletionTest( createRepository(), 4 );
+
MockControl control = mockAuditListeners();
MockControl metadataRepositoryControl = mockMetadataRepository();
String status = action.deleteContents();
-
+
assertEquals( Action.SUCCESS, status );
assertTrue( configuration.getManagedRepositories().isEmpty() );
control.verify();
metadataRepositoryControl.verify();
}
-
+
public void testDeleteRepositoryAndAssociatedProxyConnectors()
throws Exception
{
prepareRoleManagerMock();
assertEquals( 1, configuration.getProxyConnectors().size() );
-
+
MockControl control = mockAuditListeners();
MockControl metadataRepositoryControl = mockMetadataRepository();
String status = action.deleteContents();
-
+
assertEquals( Action.SUCCESS, status );
assertTrue( configuration.getManagedRepositories().isEmpty() );
control.verify();
metadataRepositoryControl.verify();
}
-
+
public void testDeleteRepositoryCancelled()
throws Exception
{
ManagedRepositoryConfiguration originalRepository = createRepository();
Configuration configuration = prepDeletionTest( originalRepository, 3 );
-
+
String status = action.execute();
assertEquals( Action.SUCCESS, status );
repositoryStatisticsManagerControl.verify();
}
-
- public void testDeleteRepositoryAndReposUnderRepoGroup()
- throws Exception
- {
- repositoryStatisticsManager.deleteStatistics( REPO_ID );
- repositoryStatisticsManagerControl.replay();
-
- Configuration configuration = prepDeletionTest( createRepository(), 5 );
- List<String> repoIds = new ArrayList<String>();
- repoIds.add( REPO_ID );
- configuration.addRepositoryGroup( createRepoGroup( repoIds, "repo.group" ) );
-
- prepareRoleManagerMock();
-
- assertEquals( 1, configuration.getRepositoryGroups().size() );
-
- MockControl control = mockAuditListeners();
- MockControl metadataRepositoryControl = mockMetadataRepository();
- String status = action.deleteContents();
- assertEquals( Action.SUCCESS, status );
-
- assertTrue( configuration.getManagedRepositories().isEmpty() );
- assertEquals( 0, configuration.getRepositoryGroups().get( 0 ).getRepositories().size() );
- assertFalse( location.exists() );
- repositoryStatisticsManagerControl.verify();
- control.verify();
- metadataRepositoryControl.verify();
- }
private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, int expectCountGetConfig )
throws RegistryException, IndeterminateConfigurationException
archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( configuration, expectCountGetConfig );
+ Configuration stageRepoConfiguration = new Configuration();
+ stageRepoConfiguration.addManagedRepository( createSatingRepository() );
+ archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
+
+
archivaConfiguration.save( configuration );
archivaConfigurationControl.replay();
return r;
}
+ private ManagedRepositoryConfiguration createSatingRepository()
+ {
+ ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
+ r.setId( REPO_ID +"-stage" );
+ r.setName( "repo name" );
+ r.setLocation( location.getAbsolutePath() );
+ r.setLayout( "default" );
+ r.setRefreshCronExpression( "* 0/5 * * * ?" );
+ r.setDaysOlder( 0 );
+ r.setRetentionCount( 0 );
+ r.setReleases( true );
+ r.setSnapshots( true );
+ r.setScanned( false );
+ r.setDeleteReleasedSnapshots( false );
+ return r;
+ }
+
private RemoteRepositoryConfiguration createRemoteRepository(String id, String url)
{
RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration();
r.setId( id );
r.setUrl( url );
r.setLayout( "default" );
-
+
return r;
}
-
+
private ProxyConnectorConfiguration createProxyConnector( String managedRepoId, String remoteRepoId )
{
ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
repoGroup.setId( repoGroupId );
repoGroup.setRepositories( repoIds );
-
+
return repoGroup;
}
-
+
private void prepareRoleManagerMock()
throws RoleManagerException
{
archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( configuration );
+ Configuration stageRepoConfiguration = new Configuration();
+ stageRepoConfiguration.addManagedRepository( createStagingRepository() );
+ archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
+
archivaConfigurationControl.replay();
action.setRepoid( REPO_ID );
{
roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
roleManagerControl.setReturnValue( false );
+
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID +"-stage" );
+ roleManagerControl.setReturnValue( false );
+
roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
roleManagerControl.setVoidCallable();
roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
roleManagerControl.setReturnValue( false );
+
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID +"-stage");
+ roleManagerControl.setReturnValue( false );
+
roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
roleManagerControl.setVoidCallable();
Configuration configuration = createConfigurationForEditing( createRepository() );
archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( configuration );
+
+ Configuration stageRepoConfiguration = new Configuration();
+ stageRepoConfiguration.addManagedRepository( createStagingRepository() );
+ archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
archivaConfigurationControl.setReturnValue( configuration );
archivaConfigurationControl.setReturnValue( configuration );
{
roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
roleManagerControl.setReturnValue( false );
+
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID +"-stage");
+ roleManagerControl.setReturnValue( false );
+
roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
roleManagerControl.setVoidCallable();
roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
roleManagerControl.setReturnValue( false );
+
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID +"-stage");
+ roleManagerControl.setReturnValue( false );
+
roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
roleManagerControl.setVoidCallable();
Configuration configuration = createConfigurationForEditing( createRepository() );
archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( configuration );
+ Configuration stageRepoConfiguration = new Configuration();
+ stageRepoConfiguration.addManagedRepository( createStagingRepository() );
+ archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
+
+
archivaConfigurationControl.setReturnValue( configuration );
archivaConfigurationControl.setReturnValue( configuration );
}
private Configuration createConfigurationForEditing( ManagedRepositoryConfiguration repositoryConfiguration )
+ throws Exception
{
Configuration configuration = new Configuration();
configuration.addManagedRepository( repositoryConfiguration );
+// configuration.addManagedRepository( createStagingRepository() );
return configuration;
}
return r;
}
+ private ManagedRepositoryConfiguration createStagingRepository()
+ throws IOException
+ {
+ ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
+ r.setId( REPO_ID + "-stage" );
+ populateStagingRepository( r );
+ return r;
+ }
+
private void populateRepository( ManagedRepositoryConfiguration repository )
throws IOException
{
repository.setScanned( false );
repository.setDeleteReleasedSnapshots( true );
}
+ private void populateStagingRepository( ManagedRepositoryConfiguration repository )
+ throws IOException
+ {
+ repository.setId( REPO_ID + "-stage");
+ repository.setName( "repo name" );
+ repository.setLocation( location.getCanonicalPath() );
+ 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 );
+ }
}