diff --git a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/CleanCommand.java b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/CleanCommand.java index d1d9cd432e..fdb4ba857f 100644 --- a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/CleanCommand.java +++ b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/CleanCommand.java @@ -16,16 +16,25 @@ package org.springframework.bootstrap.cli; import java.io.File; +import java.util.ArrayList; +import java.util.Collections; + +import joptsimple.OptionParser; +import joptsimple.OptionSet; +import joptsimple.OptionSpec; import org.apache.ivy.util.FileUtil; /** - * {@link Command} to 'clean' up grapes. + * {@link Command} to 'clean' up grapes, removing cached dependencies and forcing a + * download on the next attempt to resolve. * * @author Dave Syer * */ -public class CleanCommand extends AbstractCommand { +public class CleanCommand extends OptionParsingCommand { + + private OptionSpec allOption; public CleanCommand() { super("clean", @@ -33,7 +42,19 @@ public class CleanCommand extends AbstractCommand { } @Override - public void run(String... args) throws Exception { + public String getUsageHelp() { + return "[options] "; + } + + @Override + protected OptionParser createOptionParser() { + OptionParser parser = new OptionParser(); + this.allOption = parser.accepts("all", "Clean all files (not just snapshots)"); + return parser; + } + + @Override + protected void run(OptionSet options) throws Exception { String dir = System.getenv("GROOVY_HOME"); String userdir = System.getProperty("user.home"); @@ -54,12 +75,31 @@ public class CleanCommand extends AbstractCommand { } File grapes = new File(home, "grapes"); - // TODO: add support for other packages as args - String[] packages = new String[] { "org.springframework.bootstrap" }; - for (String pkg : packages) { - File file = new File(grapes, pkg); + ArrayList specs = new ArrayList(options.nonOptionArguments()); + if (!specs.contains("org.springframework.bootstrap")) { + specs.add(0, "org.springframework.bootstrap"); + } + for (String spec : specs) { + String group = spec; + String module = null; + if (spec.contains(":")) { + group = spec.substring(0, spec.indexOf(":")); + module = spec.substring(spec.indexOf(":") + 1); + } + File file = module == null ? new File(grapes, group) : new File(new File( + grapes, group), module); if (file.exists()) { - FileUtil.forceDelete(file); + if (options.has(this.allOption) + || group.equals("org.springframework.bootstrap")) { + FileUtil.forceDelete(file); + } else { + for (Object obj : FileUtil.listAll(file, Collections.emptyList())) { + File candidate = (File) obj; + if (candidate.getName().contains("SNAPSHOT")) { + FileUtil.forceDelete(candidate); + } + } + } } } diff --git a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/SpringBootstrapCli.java b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/SpringBootstrapCli.java index 1abbb67027..6fc6031e25 100644 --- a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/SpringBootstrapCli.java +++ b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/SpringBootstrapCli.java @@ -138,7 +138,8 @@ public class SpringBootstrapCli { System.out.println("Available commands are:"); for (Command command : this.commands) { if (!command.isOptionCommand()) { - System.out.println(String.format(" %1$-15s %2$s", command.getName(), + System.out.println(String.format("\n %1$s %2$-15s\n %3$s", + command.getName(), command.getUsageHelp(), command.getDescription())); } }