import org.slf4j.LoggerFactory;
import java.io.IOException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.FileVisitOption;
+import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
try
{
- Files.find( parentDir, 3,
- ( path, basicFileAttributes ) -> path.getFileName( ).toString( ).startsWith( artifactName )
- && Files.isRegularFile( path ) ).forEach( this::deleteSilently );
+ deleteArtifactFiles( parentDir, 3, artifactName );
}
catch ( IOException e )
{
}
+ public static void deleteArtifactFiles(final Path directory, final int maxDepth, final String artifactName) throws IOException
+ {
+ Files.walkFileTree(directory, new HashSet<FileVisitOption>( ), maxDepth, new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile( Path file, BasicFileAttributes attrs) throws IOException {
+ if (file.getFileName().toString().startsWith(artifactName)) {
+ try {
+ Files.delete( file );
+ } catch (IOException e) {
+ // We do not stop, if an error occurs.
+ }
+ }
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
+
+ });
+ }
+
private void triggerAuditEvent( String repoId, String resource, String action )
{
String msg =
* under the License.
*/
+import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.common.utils.BaseFile;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.FileType;
*/
import org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.events.RepositoryListener;
import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
+import java.nio.file.FileVisitOption;
+import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
-import java.util.stream.Collectors;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
return StringUtils.substringAfterLast( getClass().getName(), "." );
}
- protected List<ArtifactMetadata> getArtifactMetadataFromDir( String repoId, String projectName, Path repoDir, Path vDir ) throws IOException
+ protected List<ArtifactMetadata> getArtifactMetadataFromDir( final String repoId, final String projectName, final Path repoDir, final Path vDir ) throws IOException
{
- Maven2RepositoryPathTranslator translator = new Maven2RepositoryPathTranslator( new ArrayList<>( ) );
- return Files.find(vDir, 1,
- (path, basicFileAttributes) -> basicFileAttributes.isRegularFile() && path.getFileName().toString().startsWith(projectName))
- .map( path ->
- translator.getArtifactForPath( repoId, repoDir.relativize( path ).toString() )
- ).collect( Collectors.toList());
+ final Maven2RepositoryPathTranslator translator = new Maven2RepositoryPathTranslator( new ArrayList<ArtifactMappingProvider>( ) );
+ final List<ArtifactMetadata> result = new ArrayList<>( );
+ Files.walkFileTree(vDir, new HashSet<FileVisitOption>( ), 1, new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile( Path file, BasicFileAttributes attrs) throws IOException {
+ if (file.getFileName().toString().startsWith(projectName)) {
+ ArtifactMetadata m = translator.getArtifactForPath( repoId, repoDir.relativize( file ).toString() );
+ result.add(m);
+ }
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
+
+ });
+ return result;
}
+
}
verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
- verify(metadataRepository, never()).removeArtifact(any(), any());
- verify(metadataRepository, never()).removeArtifact( any(), any(), any(), any(), any(MetadataFacet.class) );
+ verify(metadataRepository, never()).removeArtifact(any(ArtifactMetadata.class), any(String.class));
+ verify(metadataRepository, never()).removeArtifact( any(String.class), any(String.class), any(String.class), any(String.class), any(MetadataFacet.class) );
// check if the snapshot wasn't removed
verify(metadataRepository, times(1)).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
- verify(metadataRepository, never()).removeArtifact(any(), any());
+ verify(metadataRepository, never()).removeArtifact(any(ArtifactMetadata.class), any(String.class));
// check if the snapshot was removed
assertDeleted( projectRoot + "/2.3-SNAPSHOT" );