}
else
{
- sb.append( '.' ).append( artifact.getPackaging() );
+ sb.append( '.' ).append( artifact.getFileExtension() );
}
return sb.toString();
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 )
{
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 );
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(),
triggerAuditEvent( repositoryId, path, AuditEvent.REMOVE_FILE );
}
}
+
repositorySession.save();
+
+ repositorySession.close();
}
catch ( ContentNotFoundException e )
// 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
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;
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() );
artifact.setGroupId( "commons-logging" );
artifact.setArtifactId( "commons-logging" );
artifact.setVersion( "1.0.1" );
+ artifact.setClassifier( "javadoc" );
artifact.setPackaging( "jar" );
artifact.setContext( SOURCE_REPO_ID );
Assertions.assertThat( artifacts ).isNotNull().isEmpty();
+ Assertions.assertThat( versionsList.getVersions() ).isNotNull().isNotEmpty().hasSize( 5 );
+
}
finally
{
}
}
+
@Test
public void authorizedToDeleteArtifacts()
throws Exception
<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"/>
<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>
try
{
MetadataRepository metadataRepository = session.getRepository();
+
Collection<String> projectVersions = metadataRepository.getProjectVersions( repoId, namespace, projectId );
Collection<String> storageProjectVersions =
repositoryStorage.listProjectVersions( repoId, namespace, projectId,
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;
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";
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>();
public void testGetMetadataFacetsWhenEmpty()
throws Exception
{
+
List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
assertTrue( facets.isEmpty() );
}
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
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 );
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.easytesting</groupId>
+ <artifactId>fest-assert</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.easytesting</groupId>
+ <artifactId>fest-assert</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<testResources>
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;
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
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
this.repository = jcrMetadataRepository;
}
+
@After
public void tearDown()
throws Exception