Skip to content

Commit 495f50d

Browse files
committed
chore: removed "run" commands
It broke the "do one thing and do it well" philosophy, especially when it was hard to do it well.
1 parent 2d8dc9d commit 495f50d

File tree

3 files changed

+7
-87
lines changed

3 files changed

+7
-87
lines changed

src/main/java/org/codejive/jpm/Jpm.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,6 @@ public List<Path> path(String[] artifactNames)
8888
}
8989
}
9090

91-
public int run(String name, String[] args) throws IOException, InterruptedException {
92-
String cmdString = JpmProject.read().commands.get(name);
93-
if (cmdString == null) {
94-
throw new IllegalArgumentException("Command not found: " + name);
95-
}
96-
String[] quotedArgs =
97-
Arrays.stream(args)
98-
.map(a -> a.contains(" ") ? "\"" + a + "\"" : a)
99-
.toArray(String[]::new);
100-
String extraArgs = String.join(" ", quotedArgs);
101-
String[] cmd;
102-
if (isWindows()) {
103-
cmd = new String[] {"cmd", "/c", String.join(" ", cmdString, extraArgs)};
104-
} else {
105-
cmd = new String[] {"/bin/sh", "-c", String.join(" ", cmdString, extraArgs)};
106-
}
107-
return new ProcessBuilder(cmd).inheritIO().start().waitFor();
108-
}
109-
11091
private static String[] getArtifacts(String[] artifactNames, JpmProject prj) {
11192
String[] deps;
11293
if (artifactNames.length > 0) {

src/main/java/org/codejive/jpm/Main.java

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.*;
1414
import java.util.concurrent.Callable;
1515
import java.util.stream.Collectors;
16-
import org.codejive.jpm.json.JpmProject;
1716
import org.codejive.jpm.util.SyncStats;
1817
import picocli.CommandLine;
1918
import picocli.CommandLine.Command;
@@ -26,13 +25,7 @@
2625
mixinStandardHelpOptions = true,
2726
version = "jpm 0.1",
2827
description = "Simple command line tool for managing Maven artifacts",
29-
subcommands = {
30-
Main.Copy.class,
31-
Main.Sync.class,
32-
Main.Install.class,
33-
Main.PrintPath.class,
34-
Main.Run.class
35-
})
28+
subcommands = {Main.Copy.class, Main.Sync.class, Main.Install.class, Main.PrintPath.class})
3629
public class Main {
3730

3831
@Command(
@@ -91,9 +84,9 @@ public Integer call() throws Exception {
9184
name = "install",
9285
aliases = {"i"},
9386
description =
94-
"This adds the given artifacts to the list of dependencies available in the jpm.json file. "
95-
+ "It then behaves just like 'sync' and copies all artifacts in that list and all their dependencies to the target directory while at the same time removing any artifacts that are no longer needed (ie the ones that are not mentioned in the jpm.json file)."
96-
+ "If no artifacts are passed the jpm.json file will be left untouched and only the existing dependencies in the file will be copied.\n\n"
87+
"This adds the given artifacts to the list of dependencies available in the deps.json file. "
88+
+ "It then behaves just like 'sync' and copies all artifacts in that list and all their dependencies to the target directory while at the same time removing any artifacts that are no longer needed (ie the ones that are not mentioned in the deps.json file)."
89+
+ "If no artifacts are passed the deps.json file will be left untouched and only the existing dependencies in the file will be copied.\n\n"
9790
+ "Example:\n jpm install org.apache.httpcomponents:httpclient:4.5.14\n")
9891
static class Install implements Callable<Integer> {
9992
@Mixin QuietMixin quietMixin;
@@ -119,7 +112,7 @@ public Integer call() throws Exception {
119112
aliases = {"p"},
120113
description =
121114
"Resolves one or more artifacts and prints the full classpath to standard output. "
122-
+ "If no artifacts are passed the classpath for the dependencies defined in the jpm.json file will be printed instead.\n\n"
115+
+ "If no artifacts are passed the classpath for the dependencies defined in the deps.json file will be printed instead.\n\n"
123116
+ "Example:\n jpm path org.apache.httpcomponents:httpclient:4.5.14\n")
124117
static class PrintPath implements Callable<Integer> {
125118
@Mixin OptionalArtifactsMixin optionalArtifactsMixin;
@@ -143,54 +136,6 @@ public Integer call() throws Exception {
143136
}
144137
}
145138

146-
@Command(
147-
name = "run",
148-
aliases = {"r"},
149-
description =
150-
"Run given command defined in the jpm.json project file\n\n"
151-
+ "Example:\n jpm run run-me\n")
152-
static class Run implements Callable<Integer> {
153-
@Parameters(
154-
paramLabel = "name",
155-
description =
156-
"The name of the command to run. Commands are defined in the jpm.json project file",
157-
index = "0",
158-
arity = "0..1")
159-
private String name;
160-
161-
@Parameters(
162-
paramLabel = "arguments",
163-
description = "Optional list of additional arguments",
164-
index = "1..*",
165-
arity = "0..*")
166-
private String[] args = {};
167-
168-
@Override
169-
public Integer call() throws Exception {
170-
if (name == null) {
171-
Map<String, String> cmds = JpmProject.read().commands;
172-
if (cmds.isEmpty()) {
173-
System.err.println("No commands defined in the jpm.json project file");
174-
} else {
175-
System.err.println("Available commands:");
176-
for (String cmd : cmds.keySet()) {
177-
System.err.println(" " + cmd);
178-
System.err.println(" " + cmds.get(cmd));
179-
}
180-
}
181-
return 0;
182-
}
183-
try {
184-
return Jpm.builder().build().run(name, args);
185-
} catch (IllegalArgumentException e) {
186-
System.err.printf(
187-
"No command with the name '%s' exists in the jpm.json project file%n",
188-
name);
189-
return 1;
190-
}
191-
}
192-
}
193-
194139
static class CopyMixin {
195140
@Option(
196141
names = {"-d", "--directory"},

src/main/java/org/codejive/jpm/json/JpmProject.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212

1313
public class JpmProject {
1414
public Map<String, String> dependencies;
15-
public Map<String, String> commands;
1615

1716
public static JpmProject read() throws IOException {
18-
Path prjJson = Path.of("jpm.json");
17+
Path prjJson = Path.of("deps.json");
1918
JpmProject prj;
2019
if (Files.isRegularFile(prjJson)) {
2120
try (Reader in = Files.newBufferedReader(prjJson)) {
@@ -30,16 +29,11 @@ public static JpmProject read() throws IOException {
3029
} else {
3130
prj.dependencies = new TreeMap<>(prj.dependencies);
3231
}
33-
if (prj.commands == null) {
34-
prj.commands = new TreeMap<>();
35-
} else {
36-
prj.commands = new TreeMap<>(prj.commands);
37-
}
3832
return prj;
3933
}
4034

4135
public static void write(JpmProject prj) throws IOException {
42-
Path prjJson = Path.of("jpm.json");
36+
Path prjJson = Path.of("deps.json");
4337
try (Writer out = Files.newBufferedWriter(prjJson)) {
4438
Gson parser = new GsonBuilder().setPrettyPrinting().create();
4539
parser.toJson(prj, out);

0 commit comments

Comments
 (0)