Skip to content

Commit 99a247e

Browse files
Copilotquintesse
andcommitted
Address PR feedback: remove run command, rename scripts to actions, change ${path} to ${deps}
Co-authored-by: quintesse <778793+quintesse@users.noreply.github.com>
1 parent 2d737db commit 99a247e

3 files changed

Lines changed: 33 additions & 70 deletions

File tree

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

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@
4848
Main.Search.class,
4949
Main.Install.class,
5050
Main.PrintPath.class,
51-
Main.Do.class,
52-
Main.Run.class
51+
Main.Do.class
5352
})
5453
public class Main {
5554

@@ -318,26 +317,26 @@ public Integer call() throws Exception {
318317
@Command(
319318
name = "do",
320319
description =
321-
"Executes a script command defined in the app.yml file. Scripts can use variable substitution for classpath.\n\n"
320+
"Executes an action command defined in the app.yml file. Actions can use variable substitution for classpath.\n\n"
322321
+ "Example:\n jpm do build\n jpm do test\n")
323322
static class Do implements Callable<Integer> {
324323
@Mixin CopyMixin copyMixin;
325324

326325
@Parameters(
327-
paramLabel = "scriptName",
328-
description = "Name of the script to execute as defined in app.yml",
326+
paramLabel = "actionName",
327+
description = "Name of the action to execute as defined in app.yml",
329328
arity = "1")
330-
private String scriptName;
329+
private String actionName;
331330

332331
@Override
333332
public Integer call() throws Exception {
334333
AppInfo appInfo = AppInfo.read();
335-
String command = appInfo.getScript(scriptName);
334+
String command = appInfo.getAction(actionName);
336335

337336
if (command == null) {
338-
System.err.println("Script '" + scriptName + "' not found in app.yml");
339-
if (!appInfo.getScriptNames().isEmpty()) {
340-
System.err.println("Available scripts: " + String.join(", ", appInfo.getScriptNames()));
337+
System.err.println("Action '" + actionName + "' not found in app.yml");
338+
if (!appInfo.getActionNames().isEmpty()) {
339+
System.err.println("Available actions: " + String.join(", ", appInfo.getActionNames()));
341340
}
342341
return 1;
343342
}
@@ -359,43 +358,7 @@ public Integer call() throws Exception {
359358
}
360359
}
361360

362-
@Command(
363-
name = "run",
364-
description =
365-
"Alias for 'jpm do run'. Executes the 'run' script defined in the app.yml file.\n\n"
366-
+ "Example:\n jpm run\n")
367-
static class Run implements Callable<Integer> {
368-
@Mixin CopyMixin copyMixin;
369-
370-
@Override
371-
public Integer call() throws Exception {
372-
AppInfo appInfo = AppInfo.read();
373-
String command = appInfo.getScript("run");
374-
375-
if (command == null) {
376-
System.err.println("Script 'run' not found in app.yml");
377-
if (!appInfo.getScriptNames().isEmpty()) {
378-
System.err.println("Available scripts: " + String.join(", ", appInfo.getScriptNames()));
379-
}
380-
return 1;
381-
}
382-
383-
// Get the classpath for variable substitution using app.yml dependencies
384-
List<Path> classpath = Collections.emptyList();
385-
try {
386-
classpath = Jpm.builder()
387-
.directory(copyMixin.directory)
388-
.noLinks(copyMixin.noLinks)
389-
.build()
390-
.path(new String[0]); // Empty array means use dependencies from app.yml
391-
} catch (Exception e) {
392-
// If we can't get the classpath, continue with empty list
393-
System.err.println("Warning: Could not resolve classpath: " + e.getMessage());
394-
}
395361

396-
return ScriptUtils.executeScript(command, classpath);
397-
}
398-
}
399362

400363
static class CopyMixin {
401364
@Option(
@@ -462,8 +425,8 @@ public static void main(String... args) {
462425
// Handle common aliases
463426
if (args.length > 0) {
464427
String firstArg = args[0];
465-
if ("compile".equals(firstArg) || "test".equals(firstArg)) {
466-
// Convert "jpm compile" to "jpm do compile" and "jpm test" to "jpm do test"
428+
if ("compile".equals(firstArg) || "test".equals(firstArg) || "run".equals(firstArg)) {
429+
// Convert "jpm compile", "jpm test", "jpm run" to "jpm do <command>"
467430
String[] newArgs = new String[args.length + 1];
468431
newArgs[0] = "do";
469432
System.arraycopy(args, 0, newArgs, 1, args.length);

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class AppInfo {
1919
private Map<String, Object> yaml = new TreeMap<>();
2020
public Map<String, String> dependencies = new TreeMap<>();
21-
public Map<String, String> scripts = new TreeMap<>();
21+
public Map<String, String> actions = new TreeMap<>();
2222

2323
/** The official name of the app.yml file. */
2424
public static final String APP_INFO_FILE = "app.yml";
@@ -35,22 +35,22 @@ public String[] getDependencyGAVs() {
3535
}
3636

3737
/**
38-
* Returns the script command for the given script name.
38+
* Returns the action command for the given action name.
3939
*
40-
* @param scriptName The name of the script
41-
* @return The script command or null if not found
40+
* @param actionName The name of the action
41+
* @return The action command or null if not found
4242
*/
43-
public String getScript(String scriptName) {
44-
return scripts.get(scriptName);
43+
public String getAction(String actionName) {
44+
return actions.get(actionName);
4545
}
4646

4747
/**
48-
* Returns all available script names.
48+
* Returns all available action names.
4949
*
50-
* @return A set of script names
50+
* @return A set of action names
5151
*/
52-
public java.util.Set<String> getScriptNames() {
53-
return scripts.keySet();
52+
public java.util.Set<String> getActionNames() {
53+
return actions.keySet();
5454
}
5555

5656
/**
@@ -78,12 +78,12 @@ public static AppInfo read() throws IOException {
7878
appInfo.dependencies.put(entry.getKey(), entry.getValue().toString());
7979
}
8080
}
81-
// Parse scripts section
82-
if (appInfo.yaml.containsKey("scripts")
83-
&& appInfo.yaml.get("scripts") instanceof Map) {
84-
Map<String, Object> scripts = (Map<String, Object>) appInfo.yaml.get("scripts");
85-
for (Map.Entry<String, Object> entry : scripts.entrySet()) {
86-
appInfo.scripts.put(entry.getKey(), entry.getValue().toString());
81+
// Parse actions section
82+
if (appInfo.yaml.containsKey("actions")
83+
&& appInfo.yaml.get("actions") instanceof Map) {
84+
Map<String, Object> actions = (Map<String, Object>) appInfo.yaml.get("actions");
85+
for (Map.Entry<String, Object> entry : actions.entrySet()) {
86+
appInfo.actions.put(entry.getKey(), entry.getValue().toString());
8787
}
8888
}
8989
return appInfo;
@@ -104,7 +104,7 @@ public static void write(AppInfo appInfo) throws IOException {
104104
Yaml yaml = new Yaml(dopts);
105105
// WARNING awful code ahead
106106
appInfo.yaml.put("dependencies", (Map<String, Object>) (Map) appInfo.dependencies);
107-
appInfo.yaml.put("scripts", (Map<String, Object>) (Map) appInfo.scripts);
107+
appInfo.yaml.put("actions", (Map<String, Object>) (Map) appInfo.actions);
108108
yaml.dump(appInfo.yaml, out);
109109
}
110110
}

src/main/java/org/codejive/jpm/util/ScriptUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ScriptUtils {
1414
* Executes a script command with variable substitution and path conversion.
1515
*
1616
* @param command The command to execute
17-
* @param classpath The classpath to use for ${path} substitution
17+
* @param classpath The classpath to use for ${deps} substitution
1818
* @return The exit code of the executed command
1919
* @throws IOException if an error occurred during execution
2020
* @throws InterruptedException if the execution was interrupted
@@ -37,21 +37,21 @@ public static int executeScript(String command, List<Path> classpath)
3737
* Processes a command by performing variable substitution and path conversion.
3838
*
3939
* @param command The raw command
40-
* @param classpath The classpath to use for ${path} substitution
40+
* @param classpath The classpath to use for ${deps} substitution
4141
* @return The processed command
4242
*/
4343
private static String processCommand(String command, List<Path> classpath) {
4444
String result = command;
4545

46-
// Substitute ${path} with the classpath
47-
if (result.contains("${path}")) {
46+
// Substitute ${deps} with the classpath
47+
if (result.contains("${deps}")) {
4848
String classpathStr = "";
4949
if (classpath != null && !classpath.isEmpty()) {
5050
classpathStr = classpath.stream()
5151
.map(Path::toString)
5252
.collect(Collectors.joining(File.pathSeparator));
5353
}
54-
result = result.replace("${path}", classpathStr);
54+
result = result.replace("${deps}", classpathStr);
5555
}
5656

5757
// Convert Unix-style paths to Windows if needed

0 commit comments

Comments
 (0)