Added command to purge Spring Data artifacts from the local repository.
This commit is contained in:
@@ -17,6 +17,7 @@ package org.springframework.data.release.build;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -41,6 +42,7 @@ import org.springframework.util.Assert;
|
||||
public class BuildOperations {
|
||||
|
||||
private final PluginRegistry<BuildSystem, Project> buildSystems;
|
||||
private final MavenProperties properties;
|
||||
|
||||
/**
|
||||
* Updates all inter-project dependencies based on the given {@link TrainIteration} and release {@link Phase}.
|
||||
@@ -122,6 +124,10 @@ public class BuildOperations {
|
||||
return doWithBuildSystem(iteration, (system, module) -> system.prepareVersion(module, phase));
|
||||
}
|
||||
|
||||
public Path getLocalRepository() {
|
||||
return properties.getLocalRepository().toPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the release for the given {@link ModuleIteration} and deploys it to the staging repository.
|
||||
*
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@@ -92,6 +93,32 @@ public class Workspace {
|
||||
});
|
||||
}
|
||||
|
||||
public void purge(Path path, Predicate<Path> filter) throws IOException {
|
||||
|
||||
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
|
||||
if (filter.test(file)) {
|
||||
Files.delete(file);
|
||||
}
|
||||
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||
|
||||
if (filter.test(dir)) {
|
||||
Files.delete(dir);
|
||||
}
|
||||
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the directory for the given {@link Project}.
|
||||
*
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.release.CliComponent;
|
||||
import org.springframework.data.release.build.BuildOperations;
|
||||
import org.springframework.data.release.utils.Logger;
|
||||
import org.springframework.shell.core.CommandMarker;
|
||||
import org.springframework.shell.core.annotation.CliCommand;
|
||||
@@ -33,6 +34,7 @@ import org.springframework.shell.core.annotation.CliCommand;
|
||||
public class WorkspaceCommands implements CommandMarker {
|
||||
|
||||
private final Workspace workspace;
|
||||
private final BuildOperations build;
|
||||
private final Logger logger;
|
||||
|
||||
@CliCommand("workspace cleanup")
|
||||
@@ -43,4 +45,19 @@ public class WorkspaceCommands implements CommandMarker {
|
||||
|
||||
workspace.cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all Spring Data artifacts from the local repository.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@CliCommand("workspace purge artifacts")
|
||||
public void purge() throws IOException {
|
||||
|
||||
logger.log("Workspace", "Cleaning up workspace directory at %s.",
|
||||
workspace.getWorkingDirectory().getAbsolutePath());
|
||||
|
||||
workspace.purge(build.getLocalRepository(),
|
||||
path -> build.getLocalRepository().relativize(path).startsWith("org/springframework/data"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user