import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
import org.apache.archiva.repository.maven2.MavenManagedRepository;
+import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import javax.inject.Inject;
import javax.inject.Named;
+import java.io.IOException;
import java.net.URISyntaxException;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
/**
* ManagedDefaultRepositoryContentTest
{
return repoContent.toPath( reference );
}
+
+ private Path setupRepoCopy( String source, String target) throws IOException
+ {
+ Path defaultRepo = getRepositoryPath( source );
+ Path newRepo = defaultRepo.getParent( ).resolve( target );
+ FileUtils.copyDirectory( defaultRepo.toFile( ), newRepo.toFile( ) );
+
+ MavenManagedRepository repository = createRepository( "testRepo", "Unit Test Repo", newRepo );
+
+ FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
+ fileType.addPattern( "**/*.xml" );
+ assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
+
+ fileTypes.afterConfigurationChange( null, "fileType", null );
+
+ repoContent = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, fileTypes, fileLockManager);
+ return newRepo;
+
+ }
+
+ @Test
+ public void testDeleteArtifactWithType() throws IOException
+ {
+ Path deleteRepo = setupRepoCopy( "delete-repository", "delete-repository-2" );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
+
+ ArtifactReference ref = new ArtifactReference( );
+ ref.setGroupId( "org.apache.maven" );
+ ref.setArtifactId( "samplejar" );
+ ref.setVersion( "1.0" );
+ ref.setType( "jar" );
+
+ repoContent.deleteArtifact( ref );
+
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
+ assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
+ assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
+ assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
+
+
+ }
+
+
+ @Test
+ public void testDeleteArtifactWithClassifier() throws IOException
+ {
+ Path deleteRepo = setupRepoCopy( "default-repository", "default-repository-2" );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
+
+ ArtifactReference ref = new ArtifactReference( );
+ ref.setGroupId( "org.apache.maven" );
+ ref.setArtifactId( "samplejar" );
+ ref.setVersion( "1.0" );
+ ref.setClassifier( "source" );
+ ref.setType( "jar" );
+
+ repoContent.deleteArtifact( ref );
+
+ assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
+ assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
+
+ }
+
+ @Test
+ public void testDeleteArtifactWithoutType() throws IOException
+ {
+ Path deleteRepo = setupRepoCopy( "default-repository", "default-repository-2" );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
+
+ ArtifactReference ref = new ArtifactReference( );
+ ref.setGroupId( "org.apache.maven" );
+ ref.setArtifactId( "samplejar" );
+ ref.setVersion( "1.0" );
+
+ repoContent.deleteArtifact( ref );
+
+ assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) );
+ assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar" ) ) );
+
+ }
}
--- /dev/null
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>A</artifactId>
+ <version>1.0</version>
+ <name>Maven Test Repository Artifact Discovery</name>
+ <packaging>war</packaging>
+</project>
--- /dev/null
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>C</artifactId>
+ <version>1.0</version>
+ <name>Maven Test Repository Artifact Discovery</name>
+ <!-- default packaging is jar -->
+ <!--packaging>jar</packaging-->
+</project>
--- /dev/null
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>C</artifactId>
+ <version>1.0</version>
+ <name>Maven Test Repository Artifact Discovery</name>
+ <!-- specified packaging -->
+ <packaging>jar</packaging>
+</project>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<metadata>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>samplejar</artifactId>
+ <version>6.0-SNAPSHOT</version>
+ <versioning>
+ <release>2.0</release>
+ <latest>6.0-SNAPSHOT</latest>
+ <snapshot>
+ <buildNumber>26</buildNumber>
+ </snapshot>
+ <versions>
+ <version>6.0-SNAPSHOT</version>
+ <version>6.0-20060311.093250-41</version>
+ <version>6.0-20060311.183228-42</version>
+ <version>6.0-20060311.183228-40</version>
+ <version>6.0-20060311.183228-37</version>
+ <version>6.0-20060311.183228-30</version>
+ <version>6.0-20060311.183228-29</version>
+ <version>6.0-20060311.183228-6</version>
+ <version>6.0-20060311.183228-9</version>
+ <version>6.0-20060311.183228-10</version>
+ <version>6.0-20060313.001659-43</version>
+ <version>6.0-20060313.001659-41</version>
+ <version>6.0-20060313.001659-38</version>
+ <version>6.0-20060313.001659-31</version>
+ <version>6.0-20060313.001659-30</version>
+ <version>6.0-20060313.001659-7</version>
+ <version>6.0-20060313.001659-10</version>
+ <version>6.0-20060313.001659-11</version>
+ </versions>
+ <lastUpdated>20060313010719</lastUpdated>
+ </versioning>
+</metadata>