some low hanging fruit in the quest to improve the staging repository implementation

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1141002 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2011-06-29 08:41:07 +00:00
parent 506b6613ed
commit 31e93bb1c9
8 changed files with 86 additions and 55 deletions

View File

@ -24,6 +24,11 @@
<id>archiva-run-indexer</id>
<name>archiva-run-indexer</name>
<description>Run Archiva Indexer</description>
</operation>
<operation>
<id>archiva-merge-stage</id>
<name>archiva-merge-stage</name>
<description>Merge Stage Repository</description>
</operation>
<operation>
<id>archiva-delete-artifact</id>
@ -252,6 +257,12 @@
<operation>archiva-delete-metadata</operation>
<resource>${resource}</resource>
</permission>
<permission>
<id>archiva-merge-repository</id>
<name>Archiva Merge Repository</name>
<operation>archiva-merge-repository</operation>
<resource>${resource}</resource>
</permission>
</permissions>
<childTemplates>
<childTemplate>archiva-repository-observer</childTemplate>

View File

@ -38,12 +38,11 @@ import org.codehaus.plexus.taskqueue.TaskQueueException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
/**
* plexus.component role="com.opensymphony.xwork2.Action" role-hint="mergeAction" instantiation-strategy="per-lookup"
@ -104,7 +103,6 @@ public class MergeAction
}
public String doMerge()
throws Exception
{
RepositorySession repositorySession = repositorySessionFactory.createSession();
try
@ -132,10 +130,10 @@ public class MergeAction
return SUCCESS;
}
catch ( Exception ex )
catch ( Exception e )
{
ex.printStackTrace();
addActionError( "Error occurred while merging the repositories." );
log.error( e.getMessage(), e );
addActionError( "Error occurred while merging the repositories: " + e.getMessage() );
return ERROR;
}
finally
@ -175,10 +173,10 @@ public class MergeAction
return SUCCESS;
}
catch ( Exception ex )
catch ( Exception e )
{
ex.printStackTrace();
addActionError( "Error occurred while merging the repositories." );
log.error( e.getMessage(), e );
addActionError( "Error occurred while merging the repositories: " + e.getMessage() );
return ERROR;
}
finally
@ -288,12 +286,7 @@ public class MergeAction
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() ) );
}
conflictSourceArtifactsToBeDisplayed.addAll( map.values() );
}
private void mergeWithOutSnapshots( MetadataRepository metadataRepository, List<ArtifactMetadata> sourceArtifacts,

View File

@ -196,7 +196,7 @@ public class AddManagedRepositoryAction
else if ( repoId.toLowerCase().contains( "stage" ) )
{
addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
+ "], rpository id cannot contains word stage" );
+ "], repository id cannot contains word stage" );
}
if ( !validator.validate( repository.getRefreshCronExpression() ) )

View File

@ -41,13 +41,13 @@ import org.codehaus.redback.integration.interceptor.SecureActionException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
/**
* Shows the Repositories Tab for the administrator.
@ -150,7 +150,7 @@ public class RepositoriesAction
List<ManagedRepositoryConfiguration> managedRepositoriesList = new ArrayList<ManagedRepositoryConfiguration>();
for ( ManagedRepositoryConfiguration repoConfig : managedRepositories )
{
if ( !repoConfig.getId().contains( "stage" ) )
if ( !repoConfig.getId().endsWith( "-stage" ) )
{
managedRepositoriesList.add( repoConfig );
}

View File

@ -53,16 +53,14 @@
<s:label label="ID" name="repository.id" />
<%@ include file="/WEB-INF/jsp/admin/include/repositoryForm.jspf" %>
<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 id="stageNeeded" name="stageNeeded" value="false" label="Create stage repository"/>
</c:if>
<c:choose>
<c:when test="${empty(stagingRepository)}">
<s:checkbox id="stageNeeded" name="stageNeeded" value="false" label="Create stage repository"/>
</c:when>
<c:otherwise>
<s:checkbox name="stageNeeded" value="true" label="Create stage repository"/>
</c:otherwise>
</c:choose>
<s:submit value="Update Repository"/>
</s:form>

View File

@ -278,9 +278,8 @@
<c:set var="location" value="${repository.location}"/>
<jsp:useBean id="location" type="java.lang.String" scope="page"/>
<c:if
test='<%= !( (str.equalsIgnoreCase("internal") ) || (str.equalsIgnoreCase( "snapshots" )) ) &&
new File (new File(location ).getParent() ,str + "-stage" ).exists()%>'>
<%-- TODO: fix this hard coding - make stage repository configuration more transparent than the actual ManagedRepositoryConfiguration --%>
<c:if test='<%= new File (new File(location ).getParent() ,str + "-stage" ).exists()%>'>
<tr>
<th>
stage repository location
@ -289,23 +288,22 @@
${repository.location}${'-stage'}
</td>
</tr>
<tr>
<th>Merge Actions</th>
<td>
<redback:ifAuthorized permission="archiva-run-indexer">
<s:form action="merge" theme="simple">
<s:hidden name="repoid" value="%{#attr.repository.id}"/>
<%--<s:hidden name="repository" value="%{repository}"/>--%>
<table>
<tr>
<td><s:submit id="Merge" value="Merge"/></td>
</tr>
</table>
</s:form>
</redback:ifAuthorized>
</td>
</tr>
<redback:ifAuthorized permission="archiva-merge-repository" resource="${repository.id}">
<tr>
<th>Merge Actions</th>
<td>
<s:form action="merge" theme="simple">
<s:hidden name="repoid" value="%{#attr.repository.id}"/>
<%--<s:hidden name="repository" value="%{repository}"/>--%>
<table>
<tr>
<td><s:submit id="Merge" value="Merge"/></td>
</tr>
</table>
</s:form>
</td>
</tr>
</redback:ifAuthorized>
</c:if>

View File

@ -44,6 +44,7 @@ import org.codehaus.redback.integration.interceptor.SecureActionException;
import org.easymock.MockControl;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -131,6 +132,36 @@ public class DeleteManagedRepositoryActionTest
assertEquals( 1, bundle.getAuthorizationTuples().size() );
}
public void testDeleteRepositoryAndReposUnderRepoGroup()
throws Exception
{
repositoryStatisticsManager.deleteStatistics( metadataRepository, REPO_ID );
repositoryStatisticsManagerControl.replay();
Configuration configuration = prepDeletionTest( createRepository(), 6 );
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();
when( respositorySession.getRepository() ).thenReturn( metadataRepository );
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();
}
public void testDeleteRepositoryConfirmation()
throws Exception
{
@ -141,7 +172,7 @@ public class DeleteManagedRepositoryActionTest
archivaConfigurationControl.setReturnValue( configuration );
Configuration stageRepoConfiguration = new Configuration();
stageRepoConfiguration.addManagedRepository( createSatingRepository() );
stageRepoConfiguration.addManagedRepository( createStagingRepository() );
archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
archivaConfigurationControl.replay();
@ -292,7 +323,7 @@ public class DeleteManagedRepositoryActionTest
archivaConfigurationControl.setReturnValue( configuration, expectCountGetConfig );
Configuration stageRepoConfiguration = new Configuration();
stageRepoConfiguration.addManagedRepository( createSatingRepository() );
stageRepoConfiguration.addManagedRepository( createStagingRepository() );
archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
archivaConfiguration.save( configuration );
@ -351,7 +382,7 @@ public class DeleteManagedRepositoryActionTest
return r;
}
private ManagedRepositoryConfiguration createSatingRepository()
private ManagedRepositoryConfiguration createStagingRepository()
{
ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
r.setId( REPO_ID + "-stage" );

View File

@ -37,8 +37,6 @@ import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -51,6 +49,8 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import javax.inject.Inject;
import javax.inject.Named;
/**
* plexus.component role="org.apache.archiva.stagerepository.merge.RepositoryMerger" role-hint="maven2"