|
4 | 4 | //DEPS org.yaml:snakeyaml:2.4 |
5 | 5 | //DEPS org.jline:jline-console-ui:3.30.5 org.jline:jline-terminal-jni:3.30.5 |
6 | 6 | //DEPS org.slf4j:slf4j-api:2.0.17 org.slf4j:slf4j-simple:2.0.17 |
7 | | -//SOURCES Jpm.java config/AppInfo.java util/FileUtils.java util/Resolver.java util/ScriptUtils.java |
8 | | -//SOURCES util/SearchResult.java util/SearchUtils.java util/SyncStats.java util/Version.java |
| 7 | +//SOURCES Jpm.java config/AppInfo.java util/CommandsParser.java util/FileUtils.java util/Resolver.java |
| 8 | +//SOURCES util/ScriptUtils.java util/SearchResult.java util/SearchUtils.java util/SyncStats.java util/Version.java |
9 | 9 | // spotless:on |
10 | 10 |
|
11 | 11 | package org.codejive.jpm; |
|
49 | 49 | Main.Search.class, |
50 | 50 | Main.Install.class, |
51 | 51 | Main.PrintPath.class, |
| 52 | + Main.Exec.class, |
52 | 53 | Main.Do.class, |
53 | 54 | Main.Clean.class, |
54 | 55 | Main.Build.class, |
@@ -331,11 +332,67 @@ public Integer call() throws Exception { |
331 | 332 | } |
332 | 333 | } |
333 | 334 |
|
| 335 | + @Command( |
| 336 | + name = "exec", |
| 337 | + description = |
| 338 | + "Executes a shell command that can use special tokens to deal with OS-specific quirks like paths." |
| 339 | + + " This means that commands can be written in a somewhat platform independent way and will work on Windows, Linux and MacOS.\n" |
| 340 | + + "\n" |
| 341 | + + "Supported tokens and what they expand to:\n" |
| 342 | + + " {{deps}} : the classpath of all dependencies defined in the app.yml file\n" |
| 343 | + + " {/} : the OS' file path separator\n" |
| 344 | + + " {:} : the OS' class path separator\n" |
| 345 | + + " {~} : the user's home directory using the OS' class path format\n" |
| 346 | + + " {;} : the OS' command separator\n" |
| 347 | + + " {./file/path} : a path using the OS' path format (must start with './'!)\n" |
| 348 | + + " {./lib:./ext} : a class path using the OS' class path format (must start with './'!)\n" |
| 349 | + + " @[ ... ] : writes contents to a file and inserts @<path-to-file> instead\n" |
| 350 | + + "\n" |
| 351 | + + "In actuality the command is pretty smart and will try to do the right thing, as long as {{deps}} is the only token you use." |
| 352 | + + " In the examples below the first line shows how to do it the hard way, by specifying everything manually, while the second line shows how much easier it is when you can rely on the built-in smart feature." |
| 353 | + + " Is the smart feature bothering you? Just use any of the other tokens besides {{deps}} and it will be turned off." |
| 354 | + + " By default args files will only be considered for Java commands that are know to support them (java, javac, javadoc, etc), but you can indicate that your command supports it as well by adding a single @ as the first character of the command.\n" |
| 355 | + + "\n" |
| 356 | + + "Example:\n" |
| 357 | + + " jpm exec javac -cp @[{{deps}}] -d {./out/classes} --source-path {./src/main/java} App.java\n" |
| 358 | + + " jpm exec javac -cp {{deps}} -d out/classes --source-path src/main/java App.java\n" |
| 359 | + + " jpm exec @kotlinc -cp {{deps}} -d out/classes src/main/kotlin/App.kt\n") |
| 360 | + static class Exec implements Callable<Integer> { |
| 361 | + @Mixin DepsMixin depsMixin; |
| 362 | + @Mixin QuietMixin quietMixin; |
| 363 | + |
| 364 | + @Parameters(paramLabel = "command", description = "The command to execute", arity = "0..*") |
| 365 | + private List<String> command; |
| 366 | + |
| 367 | + @Override |
| 368 | + public Integer call() throws Exception { |
| 369 | + String cmd = String.join(" ", command); |
| 370 | + try { |
| 371 | + return Jpm.builder() |
| 372 | + .directory(depsMixin.directory) |
| 373 | + .noLinks(depsMixin.noLinks) |
| 374 | + .verbose(!quietMixin.quiet) |
| 375 | + .build() |
| 376 | + .executeCommand(cmd); |
| 377 | + } catch (Exception e) { |
| 378 | + System.err.println(e.getMessage()); |
| 379 | + return 1; |
| 380 | + } |
| 381 | + } |
| 382 | + } |
| 383 | + |
334 | 384 | @Command( |
335 | 385 | name = "do", |
336 | 386 | description = |
337 | | - "Executes an action command defined in the app.yml file.\n\n" |
338 | | - + "Example:\n jpm do build\n jpm do test --arg verbose\n") |
| 387 | + "Executes an action command defined in the app.yml file." |
| 388 | + + " The command is executed using the same rules as the exec command, so it can use all the same tokens and features." |
| 389 | + + " You can also pass additional arguments to the action using -a or --arg followed by the argument value." |
| 390 | + + " You can chain multiple actions and their arguments in a single command line." |
| 391 | + + "\n" |
| 392 | + + "Example:\n" |
| 393 | + + " jpm do build\n" |
| 394 | + + " jpm do test --arg verbose\n" |
| 395 | + + " jpm do build -a --fresh test -a verbose\n") |
339 | 396 | static class Do implements Callable<Integer> { |
340 | 397 | @Mixin DepsMixin depsMixin; |
341 | 398 | @Mixin QuietMixin quietMixin; |
|
0 commit comments