Fix help and extend clean command
Examples:
$ spring clean --all org.springframework commons-logging
$ spring clean --all org.springframework:spring-tx
This commit is contained in:
parent
ca99e4d7b9
commit
737886e4da
|
|
@ -16,16 +16,25 @@
|
||||||
package org.springframework.bootstrap.cli;
|
package org.springframework.bootstrap.cli;
|
||||||
|
|
||||||
import java.io.File;
|
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;
|
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
|
* @author Dave Syer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class CleanCommand extends AbstractCommand {
|
public class CleanCommand extends OptionParsingCommand {
|
||||||
|
|
||||||
|
private OptionSpec<Void> allOption;
|
||||||
|
|
||||||
public CleanCommand() {
|
public CleanCommand() {
|
||||||
super("clean",
|
super("clean",
|
||||||
|
|
@ -33,7 +42,19 @@ public class CleanCommand extends AbstractCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... args) throws Exception {
|
public String getUsageHelp() {
|
||||||
|
return "[options] <dependencies>";
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 dir = System.getenv("GROOVY_HOME");
|
||||||
String userdir = System.getProperty("user.home");
|
String userdir = System.getProperty("user.home");
|
||||||
|
|
@ -54,12 +75,31 @@ public class CleanCommand extends AbstractCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
File grapes = new File(home, "grapes");
|
File grapes = new File(home, "grapes");
|
||||||
// TODO: add support for other packages as args
|
ArrayList<String> specs = new ArrayList<String>(options.nonOptionArguments());
|
||||||
String[] packages = new String[] { "org.springframework.bootstrap" };
|
if (!specs.contains("org.springframework.bootstrap")) {
|
||||||
for (String pkg : packages) {
|
specs.add(0, "org.springframework.bootstrap");
|
||||||
File file = new File(grapes, pkg);
|
}
|
||||||
|
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()) {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,8 @@ public class SpringBootstrapCli {
|
||||||
System.out.println("Available commands are:");
|
System.out.println("Available commands are:");
|
||||||
for (Command command : this.commands) {
|
for (Command command : this.commands) {
|
||||||
if (!command.isOptionCommand()) {
|
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()));
|
command.getDescription()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue