Переглянути джерело

fix an issue with not removing project version when removing an artifact from Metadatarepository

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1345397 13f79535-47bb-0310-9956-ffa450edef68
tags/archiva-1.4-M3
Olivier Lamy 12 роки тому
джерело
коміт
eeed20ed36
13 змінених файлів з 184 додано та 26 видалено
  1. 1
    1
      archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java
  2. 5
    3
      archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
  3. 4
    1
      archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
  4. 1
    1
      archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java
  5. 74
    2
      archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
  6. 1
    0
      archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/META-INF/spring-context-test.xml
  7. 5
    0
      archiva-modules/metadata/metadata-repository-api/pom.xml
  8. 1
    0
      archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java
  9. 46
    0
      archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
  10. 5
    0
      archiva-modules/plugins/metadata-store-file/pom.xml
  11. 5
    0
      archiva-modules/plugins/metadata-store-jcr/pom.xml
  12. 35
    18
      archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java
  13. 1
    0
      archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java

+ 1
- 1
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java Переглянути файл

@@ -216,7 +216,7 @@ public abstract class AbstractRestService
}
else
{
sb.append( '.' ).append( artifact.getPackaging() );
sb.append( '.' ).append( artifact.getFileExtension() );
}

return sb.toString();

+ 5
- 3
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java Переглянути файл

@@ -204,7 +204,8 @@ public class DefaultBrowseService

try
{
return new VersionsList( new ArrayList<String>( getVersions( selectedRepos, groupId, artifactId ) ) );
Collection<String> versions = getVersions( selectedRepos, groupId, artifactId );
return new VersionsList( new ArrayList<String>( versions ) );
}
catch ( MetadataResolutionException e )
{
@@ -227,8 +228,9 @@ public class DefaultBrowseService

for ( String repoId : selectedRepos )
{
versions.addAll(
metadataResolver.resolveProjectVersions( repositorySession, repoId, groupId, artifactId ) );
Collection<String> projectVersions =
metadataResolver.resolveProjectVersions( repositorySession, repoId, groupId, artifactId );
versions.addAll( projectVersions );
}

List<String> sortedVersions = new ArrayList<String>( versions );

+ 4
- 1
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java Переглянути файл

@@ -717,7 +717,7 @@ public class DefaultRepositoriesService
for ( ArtifactMetadata artifactMetadata : artifacts )
{
// TODO: mismatch between artifact (snapshot) version and project (base) version here
if ( artifact.getVersion().equals( artifact.getVersion() ) )
if ( artifactMetadata.getVersion().equals( artifact.getVersion() ) )
{
metadataRepository.removeArtifact( artifactMetadata.getRepositoryId(),
artifactMetadata.getNamespace(), artifactMetadata.getProject(),
@@ -735,7 +735,10 @@ public class DefaultRepositoriesService
triggerAuditEvent( repositoryId, path, AuditEvent.REMOVE_FILE );
}
}

repositorySession.save();

repositorySession.close();
}

catch ( ContentNotFoundException e )

+ 1
- 1
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java Переглянути файл

@@ -55,7 +55,7 @@ public abstract class AbstractArchivaRestTest

// START SNIPPET: authz-header
// guest with an empty password
public String guestAuthzHeader =
public static String guestAuthzHeader =
"Basic " + org.apache.cxf.common.util.Base64Utility.encode( ( "guest" + ":" ).getBytes() );

// with an other login/password

+ 74
- 2
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java Переглянути файл

@@ -22,11 +22,13 @@ package org.apache.archiva.rest.services;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.common.utils.FileUtil;
import org.apache.archiva.rest.api.model.Artifact;
import org.apache.archiva.rest.api.model.VersionsList;
import org.apache.archiva.rest.api.services.BrowseService;
import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
import org.apache.archiva.rest.api.services.RepositoriesService;
import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
import org.fest.assertions.Assertions;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
@@ -133,17 +135,83 @@ public class RepositoriesServiceTest

BrowseService browseService = getBrowseService( authorizationHeader, false );

List<Artifact> artifacts =
browseService.getArtifactDownloadInfos( "org.apache.karaf.features", "org.apache.karaf.features.core",
"2.2.2", SOURCE_REPO_ID );

log.info( "artifacts: {}", artifacts );

Assertions.assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 2 );

VersionsList versionsList =
browseService.getVersionsList( "org.apache.karaf.features", "org.apache.karaf.features.core",
SOURCE_REPO_ID );
Assertions.assertThat( versionsList.getVersions() ).isNotNull().isNotEmpty().hasSize( 2 );

log.info( "artifacts.size: {}", artifacts.size() );

try
{
File artifactFile = new File(
"target/test-origin-repo/org/apache/karaf/features/org.apache.karaf.features.core/2.2.2/org.apache.karaf.features.core-2.2.2.jar" );

assertTrue( "artifact not exists:" + artifactFile.getPath(), artifactFile.exists() );

Artifact artifact = new Artifact();
artifact.setGroupId( "org.apache.karaf.features" );
artifact.setArtifactId( "org.apache.karaf.features.core" );
artifact.setVersion( "2.2.2" );
artifact.setPackaging( "jar" );
artifact.setContext( SOURCE_REPO_ID );

RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );

repositoriesService.deleteArtifact( artifact );

assertFalse( "artifact not deleted exists:" + artifactFile.getPath(), artifactFile.exists() );

artifacts =
browseService.getArtifactDownloadInfos( "org.apache.karaf.features", "org.apache.karaf.features.core",
"2.2.2", SOURCE_REPO_ID );

Assertions.assertThat( artifacts ).isNotNull().isEmpty();

versionsList = browseService.getVersionsList( "org.apache.karaf.features", "org.apache.karaf.features.core",
SOURCE_REPO_ID );

Assertions.assertThat( versionsList.getVersions() ).isNotNull().isNotEmpty().hasSize( 1 );

}
finally
{
cleanRepos();
}
}

@Test
@Ignore
public void deleteArtifactWithClassifier()
throws Exception
{
initSourceTargetRepo();

BrowseService browseService = getBrowseService( authorizationHeader, false );

List<Artifact> artifacts =
browseService.getArtifactDownloadInfos( "commons-logging", "commons-logging", "1.0.1", SOURCE_REPO_ID );

Assertions.assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 3 );

VersionsList versionsList =
browseService.getVersionsList( "commons-logging", "commons-logging", SOURCE_REPO_ID );
Assertions.assertThat( versionsList.getVersions() ).isNotNull().isNotEmpty().hasSize( 6 );

log.info( "artifacts.size: {}", artifacts.size() );

try
{
File artifactFile =
new File( "target/test-origin-repo/commons-logging/commons-logging/1.0.1/commons-logging-1.0.1.jar" );
File artifactFile = new File(
"target/test-origin-repo/commons-logging/commons-logging/1.0.1/commons-logging-1.0.1-javadoc.jar" );

assertTrue( "artifact not exists:" + artifactFile.getPath(), artifactFile.exists() );

@@ -151,6 +219,7 @@ public class RepositoriesServiceTest
artifact.setGroupId( "commons-logging" );
artifact.setArtifactId( "commons-logging" );
artifact.setVersion( "1.0.1" );
artifact.setClassifier( "javadoc" );
artifact.setPackaging( "jar" );
artifact.setContext( SOURCE_REPO_ID );

@@ -165,6 +234,8 @@ public class RepositoriesServiceTest

Assertions.assertThat( artifacts ).isNotNull().isEmpty();

Assertions.assertThat( versionsList.getVersions() ).isNotNull().isNotEmpty().hasSize( 5 );

}
finally
{
@@ -172,6 +243,7 @@ public class RepositoriesServiceTest
}
}


@Test
public void authorizedToDeleteArtifacts()
throws Exception

+ 1
- 0
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/META-INF/spring-context-test.xml Переглянути файл

@@ -77,6 +77,7 @@
<bean id="repository" class="org.apache.jackrabbit.core.RepositoryImpl" destroy-method="shutdown">
<constructor-arg ref="config"/>
</bean>

<bean id="config" class="org.apache.jackrabbit.core.config.RepositoryConfig" factory-method="create">
<constructor-arg value="${basedir}/src/test/repository.xml"/>
<constructor-arg value="${appserver.base}/jcr"/>

+ 5
- 0
archiva-modules/metadata/metadata-repository-api/pom.xml Переглянути файл

@@ -57,6 +57,11 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

+ 1
- 0
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java Переглянути файл

@@ -296,6 +296,7 @@ public class DefaultMetadataResolver
try
{
MetadataRepository metadataRepository = session.getRepository();

Collection<String> projectVersions = metadataRepository.getProjectVersions( repoId, namespace, projectId );
Collection<String> storageProjectVersions =
repositoryStorage.listProjectVersions( repoId, namespace, projectId,

+ 46
- 0
archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java Переглянути файл

@@ -32,8 +32,11 @@ import org.apache.archiva.metadata.model.Organization;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.Scm;
import org.fest.assertions.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@@ -64,6 +67,8 @@ public abstract class AbstractMetadataRepositoryTest

private static final String TEST_PROJECT_VERSION = "1.0";

private static final String TEST_PROJECT_VERSION_2_0 = "2.0";

private static final String TEST_FACET_ID = "test-facet-id";

private static final String TEST_NAME = "test/name";
@@ -78,6 +83,8 @@ public abstract class AbstractMetadataRepositoryTest

private static final String TEST_METADATA_VALUE = "test-metadata";

protected Logger log = LoggerFactory.getLogger( getClass() );

protected static Map<String, MetadataFacetFactory> createTestMetadataFacetFactories()
{
Map<String, MetadataFacetFactory> factories = new HashMap<String, MetadataFacetFactory>();
@@ -603,6 +610,7 @@ public abstract class AbstractMetadataRepositoryTest
public void testGetMetadataFacetsWhenEmpty()
throws Exception
{

List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
assertTrue( facets.isEmpty() );
}
@@ -1049,10 +1057,27 @@ public abstract class AbstractMetadataRepositoryTest
assertEquals( Collections.singletonList( artifact ), new ArrayList<ArtifactMetadata>(
repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );

repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION_2_0, artifact );

Collection<String> versions = repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );

log.info( "versions {}", versions );

Assertions.assertThat( versions ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "1.0", "2.0" );

repository.removeArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() );

versions = repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );

log.info( "versions {}", versions );

Assertions.assertThat( versions ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "2.0" );

assertTrue(
repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ).isEmpty() );

Assertions.assertThat( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
TEST_PROJECT_VERSION_2_0 ) ).isNotEmpty().hasSize( 1 );
}

@Test
@@ -1093,6 +1118,27 @@ public abstract class AbstractMetadataRepositoryTest
assertTrue( repository.getRootNamespaces( TEST_REPO_ID ).isEmpty() );
}


@Test
public void deleteVersion()
throws Exception
{
ArtifactMetadata artifact = createArtifact();
artifact.addFacet( new TestMetadataFacet( "value" ) );

repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );

repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );

assertEquals( Collections.singletonList( artifact ), new ArrayList<ArtifactMetadata>(
repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );

repository.removeArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() );

assertTrue(
repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ).isEmpty() );
}

private static ProjectMetadata createProject()
{
return createProject( TEST_NAMESPACE );

+ 5
- 0
archiva-modules/plugins/metadata-store-file/pom.xml Переглянути файл

@@ -70,6 +70,11 @@
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

+ 5
- 0
archiva-modules/plugins/metadata-store-jcr/pom.xml Переглянути файл

@@ -73,6 +73,11 @@
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>

+ 35
- 18
archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java Переглянути файл

@@ -35,6 +35,7 @@ import org.apache.archiva.metadata.model.Scm;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.MetadataRepositoryException;
import org.apache.archiva.metadata.repository.MetadataResolutionException;
import org.apache.commons.lang.StringUtils;
import org.apache.jackrabbit.commons.JcrUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -615,24 +616,6 @@ public class JcrMetadataRepository
return artifacts;
}

public void removeArtifact( String repositoryId, String namespace, String projectId, String projectVersion,
String id )
throws MetadataRepositoryException
{
try
{
Node root = getJcrSession().getRootNode();
String path = getArtifactPath( repositoryId, namespace, projectId, projectVersion, id );
if ( root.hasNode( path ) )
{
root.getNode( path ).remove();
}
}
catch ( RepositoryException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}
}

public void removeRepository( String repositoryId )
throws MetadataRepositoryException
@@ -994,6 +977,40 @@ public class JcrMetadataRepository
return getNodeNames( getProjectPath( repositoryId, namespace, projectId ), PROJECT_VERSION_NODE_TYPE );
}

public void removeArtifact( String repositoryId, String namespace, String projectId, String projectVersion,
String id )
throws MetadataRepositoryException
{
try
{
Node root = getJcrSession().getRootNode();
String path = getArtifactPath( repositoryId, namespace, projectId, projectVersion, id );
if ( root.hasNode( path ) )
{
root.getNode( path ).remove();
}

// remove version

path = getProjectPath( repositoryId, namespace, projectId );

Node nodeAtPath = root.getNode( path );

for ( Node node : JcrUtils.getChildNodes( nodeAtPath ) )
{
if ( node.isNodeType( PROJECT_VERSION_NODE_TYPE ) && StringUtils.equals( node.getName(),
projectVersion ) )
{
node.remove();
}
}
}
catch ( RepositoryException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}
}

public Collection<ArtifactMetadata> getArtifacts( String repositoryId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException

+ 1
- 0
archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java Переглянути файл

@@ -77,6 +77,7 @@ public class JcrMetadataRepositoryTest
this.repository = jcrMetadataRepository;
}


@After
public void tearDown()
throws Exception

Завантаження…
Відмінити
Зберегти