diff options
8 files changed, 68 insertions, 12 deletions
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo index 1af52dd63..0187601c2 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo @@ -476,6 +476,13 @@ <defaultValue>true</defaultValue> </field> <field> + <name>blockRedeployments</name> + <version>1.0.0+</version> + <type>boolean</type> + <description>True if re-deployment of artifacts already in the repository will be blocked.</description> + <defaultValue>false</defaultValue> + </field> + <field> <name>snapshots</name> <version>1.0.0+</version> <type>boolean</type> diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml b/archiva-modules/archiva-base/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml index 12473f3f1..51b54f82f 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml @@ -9,6 +9,7 @@ <layout>default</layout> <releases>true</releases> <snapshots>false</snapshots> + <blockRedeployments>true</blockRedeployments> <scanned>true</scanned> <refreshCronExpression>0 0 * * * ?</refreshCronExpression> <daysOlder>30</daysOlder> @@ -20,6 +21,7 @@ <layout>default</layout> <releases>false</releases> <snapshots>true</snapshots> + <blockRedeployments>false</blockRedeployments> <scanned>true</scanned> <refreshCronExpression>0 0\,30 * * * ?</refreshCronExpression> <daysOlder>30</daysOlder> diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java index b51bc7f94..97151c816 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java @@ -52,13 +52,15 @@ public class AddManagedRepositoryAction { this.repository = new ManagedRepositoryConfiguration(); this.repository.setReleases( false ); - this.repository.setScanned( false ); + this.repository.setScanned( false ); + this.repository.setBlockRedeployments( false ); } public String input() { this.repository.setReleases( true ); this.repository.setScanned( true ); + this.repository.setBlockRedeployments( true ); return INPUT; } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/repositoryForm.jspf b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/repositoryForm.jspf index 4c7f44191..4e58c73c8 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/repositoryForm.jspf +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/repositoryForm.jspf @@ -28,6 +28,7 @@ <s:textfield name="repository.daysOlder" label="Repository Purge By Days Older Than" size="5"/> <s:textfield name="repository.retentionCount" label="Repository Purge By Retention Count" size="5"/> <s:checkbox name="repository.releases" value="repository.releases" label="Releases Included"/> +<s:checkbox name="repository.blockRedeployments" value="repository.blockRedeployments" label="Block Re-deployments of Released Artifacts"/> <s:checkbox name="repository.snapshots" value="repository.snapshots" label="Snapshots Included"/> <s:checkbox name="repository.scanned" value="repository.scanned" label="Scannable"/> <s:checkbox name="repository.deleteReleasedSnapshots" value="repository.deleteReleasedSnapshots" diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java index e020d7f4a..a297659f5 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java @@ -485,7 +485,7 @@ public class ArchivaDavResourceFactory String resourcePath = logicalResource.getPath(); // check if target repo is enabled for releases - // we suppose that release-artifacts can deployed only to repos enabled for releases + // we suppose that release-artifacts can be deployed only to repos enabled for releases if ( managedRepository.getRepository().isReleases() && !repositoryRequest.isMetadata( resourcePath ) && !repositoryRequest.isSupportFile( resourcePath ) ) { @@ -496,10 +496,10 @@ public class ArchivaDavResourceFactory if ( !VersionUtil.isSnapshot( artifact.getVersion() ) ) { - // check if artifact already exists - if ( managedRepository.hasContent( artifact ) ) + // check if artifact already exists and if artifact re-deployment to the repository is allowed + if ( managedRepository.hasContent( artifact ) && managedRepository.getRepository().isBlockRedeployments() ) { - log.warn( "Overwriting released artifacts is not allowed." ); + log.warn( "Overwriting released artifacts in repository '" + managedRepository.getId() + "' is not allowed." ); throw new DavException( HttpServletResponse.SC_CONFLICT, "Overwriting released artifacts is not allowed." ); } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java index a0ec2c811..c7bccf47e 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java @@ -119,12 +119,14 @@ public abstract class AbstractRepositoryServletTestCase response.getResponseCode() ); } - protected ManagedRepositoryConfiguration createManagedRepository( String id, String name, File location ) + protected ManagedRepositoryConfiguration createManagedRepository( String id, String name, File location, boolean blockRedeployments ) { ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration(); repo.setId( id ); repo.setName( name ); repo.setLocation( location.getAbsolutePath() ); + repo.setBlockRedeployments( blockRedeployments ); + return repo; } @@ -182,7 +184,7 @@ public abstract class AbstractRepositoryServletTestCase repoRootInternal = new File( appserverBase, "data/repositories/internal" ); Configuration config = archivaConfiguration.getConfiguration(); - config.addManagedRepository( createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal ) ); + config.addManagedRepository( createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal, true ) ); saveConfiguration( archivaConfiguration ); CacheManager.getInstance().removeCache( "url-failures-cache" ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletDeployTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletDeployTest.java index 2e8a7ad8e..8a6640014 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletDeployTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletDeployTest.java @@ -27,6 +27,8 @@ import java.io.File; import java.io.InputStream; import javax.servlet.http.HttpServletResponse; + +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.webdav.httpunit.MkColMethodWebRequest; @@ -98,6 +100,46 @@ public class RepositoryServletDeployTest assertResponseConflictError( response ); } + public void testReleaseArtifactsRedeploymentIsAllowed() + throws Exception + { + setupCleanRepo( repoRootInternal ); + + ManagedRepositoryConfiguration managedRepo = archivaConfiguration.getConfiguration().findManagedRepositoryById( REPOID_INTERNAL ); + managedRepo.setBlockRedeployments( false ); + + saveConfiguration( archivaConfiguration ); + + String putUrl = "http://machine.com/repository/internal" + ARTIFACT_DEFAULT_LAYOUT; + String metadataUrl = "http://machine.com/repository/internal/path/to/artifact/maven-metadata.xml"; + String checksumUrl = "http://machine.com/repository/internal" + ARTIFACT_DEFAULT_LAYOUT + ".sha1"; + + InputStream is = getClass().getResourceAsStream( "/artifact.jar" ); + // verify that the file exists in resources-dir + assertNotNull( "artifact.jar inputstream", is ); + + // send request #1 and verify it's successful + WebRequest request = new PutMethodWebRequest( putUrl, is, "application/octet-stream" ); + WebResponse response = sc.getResponse( request ); + assertResponseCreated( response ); + + is = getClass().getResourceAsStream( "/artifact.jar.sha1" ); + request = new PutMethodWebRequest( checksumUrl, is, "application/octet-stream" ); + response = sc.getResponse( request ); + assertResponseCreated( response ); + + is = getClass().getResourceAsStream( "/maven-metadata.xml" ); + request = new PutMethodWebRequest( metadataUrl, is, "application/octet-stream" ); + response = sc.getResponse( request ); + assertResponseCreated( response ); + + // send request #2 and verify it's blocked + is = getClass().getResourceAsStream( "/artifact.jar" ); + request = new PutMethodWebRequest( putUrl, is, "application/octet-stream" ); + response = sc.getResponse( request ); + assertResponseNoContent( response ); + } + public void testReleaseArtifactsRedeploymentInvalidPath() throws Exception { diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletRepositoryGroupTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletRepositoryGroupTest.java index 13b8fc871..ca9706a45 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletRepositoryGroupTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletRepositoryGroupTest.java @@ -90,8 +90,8 @@ public class RepositoryServletRepositoryGroupTest repoRootFirst = new File( appserverBase, "data/repositories/" + MANAGED_REPO_FIRST ); repoRootLast = new File( appserverBase, "data/repositories/" + MANAGED_REPO_LAST ); - configuration.addManagedRepository( createManagedRepository( MANAGED_REPO_FIRST, "First Test Repo", repoRootFirst ) ); - configuration.addManagedRepository( createManagedRepository( MANAGED_REPO_LAST, "Last Test Repo", repoRootLast ) ); + configuration.addManagedRepository( createManagedRepository( MANAGED_REPO_FIRST, "First Test Repo", repoRootFirst, true ) ); + configuration.addManagedRepository( createManagedRepository( MANAGED_REPO_LAST, "Last Test Repo", repoRootLast, true ) ); List<String> managedRepoIds = new ArrayList<String>(); managedRepoIds.add( MANAGED_REPO_FIRST ); @@ -101,11 +101,11 @@ public class RepositoryServletRepositoryGroupTest // Create the repository group with an invalid managed repository repoRootInvalid = new File( appserverBase, "data/repositories/" + MANAGED_REPO_INVALID ); - ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepository( MANAGED_REPO_INVALID, "Invalid Test Repo", repoRootInvalid ); + ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepository( MANAGED_REPO_INVALID, "Invalid Test Repo", repoRootInvalid, true ); - configuration.addManagedRepository( createManagedRepository( MANAGED_REPO_FIRST, "First Test Repo", repoRootFirst ) ); + configuration.addManagedRepository( createManagedRepository( MANAGED_REPO_FIRST, "First Test Repo", repoRootFirst, true ) ); configuration.addManagedRepository( managedRepositoryConfiguration ); - configuration.addManagedRepository( createManagedRepository( MANAGED_REPO_LAST, "Last Test Repo", repoRootLast ) ); + configuration.addManagedRepository( createManagedRepository( MANAGED_REPO_LAST, "Last Test Repo", repoRootLast, true ) ); List<String> invalidManagedRepoIds = new ArrayList<String>(); invalidManagedRepoIds.add( MANAGED_REPO_FIRST ); |