-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.java
More file actions
732 lines (674 loc) · 31.9 KB
/
Main.java
File metadata and controls
732 lines (674 loc) · 31.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
// spotless:off Dependencies for JBang
//DEPS eu.maveniverse.maven.mima:context:2.4.35 eu.maveniverse.maven.mima.runtime:standalone-static:2.4.35
//DEPS org.apache.maven.indexer:search-backend-smo:7.1.6
//DEPS info.picocli:picocli:4.7.7
//DEPS org.yaml:snakeyaml:2.5
//DEPS org.jline:jline-console-ui:3.30.6 org.jline:jline-terminal-jni:3.30.6
//DEPS org.slf4j:slf4j-api:2.0.17 org.slf4j:slf4j-simple:2.0.17
//SOURCES Jpm.java config/AppInfo.java search/Search.java search/SearchSmoRestImpl.java search/SearchSmoApiImpl.java
//SOURCES util/CommandsParser.java util/FileUtils.java util/Resolver.java util/ScriptUtils.java util/SyncResult.java
//SOURCES util/Version.java
// spotless:on
package org.codejive.jpm;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import org.codejive.jpm.search.Search.Backends;
import org.codejive.jpm.util.SyncResult;
import org.codejive.jpm.util.Version;
import org.jline.consoleui.elements.InputValue;
import org.jline.consoleui.elements.ListChoice;
import org.jline.consoleui.elements.PageSizeType;
import org.jline.consoleui.elements.PromptableElementIF;
import org.jline.consoleui.elements.items.ListItemIF;
import org.jline.consoleui.elements.items.impl.ListItem;
import org.jline.consoleui.prompt.ConsolePrompt;
import org.jline.consoleui.prompt.ListResult;
import org.jline.consoleui.prompt.PromptResultItemIF;
import org.jline.consoleui.prompt.builder.PromptBuilder;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
import picocli.CommandLine.Unmatched;
/** Main class for the jpm command line tool. */
@Command(
name = "jpm",
mixinStandardHelpOptions = true,
versionProvider = Version.class,
description = "Simple command line tool for managing Maven artifacts",
subcommands = {
Main.Search.class,
Main.Install.class,
Main.Copy.class,
Main.PrintPath.class,
Main.Do.class,
Main.Clean.class,
Main.Build.class,
Main.Run.class,
Main.Test.class,
Main.Exec.class
})
public class Main {
static boolean verbose = false;
@Mixin VerboseMixin verboseMixin;
@Command(
name = "copy",
aliases = {"c"},
description =
"Resolves one or more artifacts and copies them and all their dependencies to a target directory. "
+ "By default jpm will try to create symbolic links to conserve space.\n\n"
+ "Example:\n jpm copy org.apache.httpcomponents:httpclient:4.5.14\n")
static class Copy implements Callable<Integer> {
@Mixin VerboseMixin verboseMixin;
@Mixin QuietMixin quietMixin;
@Mixin ArtifactsMixin artifactsMixin;
@Option(
names = {"-s", "--sync"},
description =
"Makes sure the target directory will only contain the mentioned artifacts and their dependencies, possibly removing other files present in the directory",
defaultValue = "false")
private boolean sync;
@Override
public Integer call() throws Exception {
SyncResult stats =
Jpm.builder()
.directory(artifactsMixin.directory)
.noLinks(artifactsMixin.noLinks)
.cacheDir(artifactsMixin.cacheDir)
.build()
.copy(
artifactsMixin.artifactNames,
artifactsMixin.getRepositoryMap(),
sync);
if (!quietMixin.quiet) {
printStats(stats);
}
return (Integer) 0;
}
}
@Command(
name = "search",
aliases = {"s"},
description =
"Without arguments this command will start an interactive search asking the user to "
+ "provide details of the artifact to look for and the actions to take. When provided "
+ "with an argument this command finds and returns the names of those artifacts that "
+ "match the given (partial) name.\n\n"
+ "Example:\n jpm search httpclient\n")
static class Search implements Callable<Integer> {
@Mixin VerboseMixin verboseMixin;
@Mixin QuietMixin quietMixin;
@Mixin DepsMixin depsMixin;
@Mixin AppInfoFileMixin appInfoFileMixin;
@Option(
names = {"-i", "--interactive"},
description = "Interactively search and select artifacts to install",
defaultValue = "false")
private boolean interactive;
@Option(
names = {"-m", "--max"},
description = "Maximum number of results to return")
private Integer max;
@Option(
names = {"-b", "--backend"},
description =
"The search backend to use. Supported values: ${COMPLETION-CANDIDATES}")
private Backends backend;
@Parameters(
paramLabel = "artifactPattern",
description = "Partial or full artifact name to search for.",
defaultValue = "")
private String artifactPattern;
@Override
public Integer call() throws Exception {
if (interactive || artifactPattern == null || artifactPattern.isEmpty()) {
if (max == null) {
max = (Integer) 100;
}
try (Terminal terminal = TerminalBuilder.builder().build()) {
while (true) {
ConsolePrompt.UiConfig cfg = new ConsolePrompt.UiConfig();
cfg.setCancellableFirstPrompt(true);
ConsolePrompt prompt = new ConsolePrompt(null, terminal, cfg);
Map<String, PromptResultItemIF> result = prompt.prompt(this::nextQuestion);
if (result.isEmpty()) {
break;
}
String selectedArtifact = getSelectedId(result, "item");
String artifactAction = getSelectedId(result, "action");
if ("install".equals(artifactAction)) {
SyncResult stats =
Jpm.builder()
.directory(depsMixin.directory)
.noLinks(depsMixin.noLinks)
.cacheDir(depsMixin.cacheDir)
.appFile(appInfoFileMixin.appInfoFile)
.build()
.install(
new String[] {selectedArtifact},
depsMixin.getRepositoryMap());
if (!quietMixin.quiet) {
printStats(stats);
}
} else if ("copy".equals(artifactAction)) {
SyncResult stats =
Jpm.builder()
.directory(depsMixin.directory)
.noLinks(depsMixin.noLinks)
.cacheDir(depsMixin.cacheDir)
.appFile(appInfoFileMixin.appInfoFile)
.build()
.copy(
new String[] {selectedArtifact},
depsMixin.getRepositoryMap(),
false);
if (!quietMixin.quiet) {
printStats(stats);
}
} else { // quit
break;
}
String finalAction = selectFinalAction(prompt);
if (!"again".equals(finalAction)) {
break;
}
artifactPattern = null;
}
}
} else {
if (max == null) {
max = (Integer) 20;
}
try {
String[] artifactNames = search(artifactPattern);
if (artifactNames.length > 0) {
Arrays.stream(artifactNames).forEach(System.out::println);
}
} catch (UncheckedIOException ex) {
System.err.println(ex.getCause().getMessage());
return 1;
}
}
return (Integer) 0;
}
String[] search(String artifactPattern) {
try {
return Jpm.builder()
.directory(depsMixin.directory)
.noLinks(depsMixin.noLinks)
.cacheDir(depsMixin.cacheDir)
.appFile(appInfoFileMixin.appInfoFile)
.build()
.search(artifactPattern, Math.min(max, 200), backend);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
List<PromptableElementIF> nextQuestion(Map<String, PromptResultItemIF> results) {
String pattern;
if (artifactPattern == null || artifactPattern.isEmpty()) {
if (!results.containsKey("input")) {
return List.of(stringElement("Search for:"));
}
pattern = results.get("input").getResult();
} else {
pattern = artifactPattern;
}
if (!results.containsKey("item")) {
String[] artifactNames = search(pattern);
return List.of(selectElement("Select artifact:", artifactNames));
}
if (!results.containsKey("action")) {
return List.of(selectArtifactActionElement());
} else if ("version".equals(getSelectedId(results, "action"))) {
results.remove("action");
pattern = getSelectedId(results, "item");
String[] artifactNames = search(pattern);
return List.of(selectElement("Select version:", artifactNames));
}
return null;
}
InputValue stringElement(String message) {
return new InputValue("input", message);
}
ListChoice selectElement(String message, String[] items) {
List<ListItemIF> itemList =
Arrays.stream(items)
.map(it -> new ListItem(it, it))
.collect(Collectors.toList());
return new ListChoice(message, "item", 10, PageSizeType.ABSOLUTE, itemList);
}
ListChoice selectArtifactActionElement() {
List<ListItemIF> itemList = new ArrayList<>();
itemList.add(new ListItem("Download & Install artifact", "install"));
itemList.add(new ListItem("Download & Copy artifact", "copy"));
itemList.add(new ListItem("Select different version", "version"));
itemList.add(new ListItem("Quit", "quit"));
return new ListChoice("What to do:", "action", 10, PageSizeType.ABSOLUTE, itemList);
}
String selectFinalAction(ConsolePrompt prompt) throws IOException {
PromptBuilder promptBuilder = prompt.getPromptBuilder();
promptBuilder
.createListPrompt()
.name("action")
.message("Next step:")
.newItem("quit")
.text("Quit")
.add()
.newItem("again")
.text("Search again")
.add()
.addPrompt();
Map<String, PromptResultItemIF> result = prompt.prompt(promptBuilder.build());
return getSelectedId(result, "action");
}
private static String getSelectedId(
Map<String, PromptResultItemIF> result, String itemName) {
return ((ListResult) result.get(itemName)).getSelectedId();
}
}
@Command(
name = "install",
aliases = {"i"},
description =
"This adds the given artifacts to the list of dependencies available in the app.yml file. "
+ "It then behaves just like 'copy --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 app.yml file). "
+ "If no artifacts are passed the app.yml file will be left untouched and only the existing dependencies in the file will be copied.\n\n"
+ "Example:\n jpm install org.apache.httpcomponents:httpclient:4.5.14\n")
static class Install implements Callable<Integer> {
@Mixin VerboseMixin verboseMixin;
@Mixin QuietMixin quietMixin;
@Mixin OptionalArtifactsMixin optionalArtifactsMixin;
@Mixin AppInfoFileMixin appInfoFileMixin;
@Override
public Integer call() throws Exception {
SyncResult stats =
Jpm.builder()
.directory(optionalArtifactsMixin.directory)
.noLinks(optionalArtifactsMixin.noLinks)
.cacheDir(optionalArtifactsMixin.cacheDir)
.appFile(appInfoFileMixin.appInfoFile)
.build()
.install(
optionalArtifactsMixin.artifactNames,
optionalArtifactsMixin.getRepositoryMap());
if (!quietMixin.quiet) {
printStats(stats);
}
return (Integer) 0;
}
}
@Command(
name = "path",
aliases = {"p"},
description =
"Resolves one or more artifacts and prints the full classpath to standard output. "
+ "If no artifacts are passed the classpath for the dependencies defined in the app.yml file will be printed instead.\n\n"
+ "Example:\n jpm path org.apache.httpcomponents:httpclient:4.5.14\n")
static class PrintPath implements Callable<Integer> {
@Mixin VerboseMixin verboseMixin;
@Mixin OptionalArtifactsMixin optionalArtifactsMixin;
@Mixin AppInfoFileMixin appInfoFileMixin;
@Override
public Integer call() throws Exception {
List<Path> files =
Jpm.builder()
.directory(optionalArtifactsMixin.directory)
.noLinks(optionalArtifactsMixin.noLinks)
.cacheDir(optionalArtifactsMixin.cacheDir)
.appFile(appInfoFileMixin.appInfoFile)
.build()
.path(
optionalArtifactsMixin.artifactNames,
optionalArtifactsMixin.getRepositoryMap());
if (!files.isEmpty()) {
String classpath =
files.stream()
.map(Path::toString)
.collect(Collectors.joining(File.pathSeparator));
System.out.print(classpath);
}
return (Integer) 0;
}
}
@Command(
name = "exec",
description =
"Executes a shell command that can use special tokens to deal with OS-specific quirks like paths."
+ " This means that commands can be written in a somewhat platform independent way and will work on Windows, Linux and MacOS.\n"
+ "\n"
+ "Supported tokens and what they expand to:\n"
+ " {{deps}} : the classpath of all dependencies defined in the app.yml file\n"
+ " {/} : the OS' file path separator\n"
+ " {:} : the OS' class path separator\n"
+ " {~} : the user's home directory using the OS' class path format\n"
+ " {;} : the OS' command separator\n"
+ " {./file/path} : a path using the OS' path format (must start with './'!)\n"
+ " {./lib:./ext} : a class path using the OS' class path format (must start with './'!)\n"
+ " @[ ... ] : writes contents to a file and inserts @<path-to-file> instead\n"
+ "\n"
+ "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."
+ " 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."
+ " Is the smart feature bothering you? Just use any of the other tokens besides {{deps}} and it will be turned off."
+ " 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"
+ "\n"
+ "Example:\n"
+ " jpm exec javac -cp @[{{deps}}] -d {./out/classes} --source-path {./src/main/java} App.java\n"
+ " jpm exec javac -cp {{deps}} -d out/classes --source-path src/main/java App.java\n"
+ " jpm exec @kotlinc -cp {{deps}} -d out/classes src/main/kotlin/App.kt\n")
static class Exec implements Callable<Integer> {
@Mixin VerboseMixin verboseMixin;
@Mixin DepsMixin depsMixin;
@Mixin QuietMixin quietMixin;
@Mixin AppInfoFileMixin appInfoFileMixin;
@Parameters(paramLabel = "command", description = "The command to execute", arity = "0..*")
private List<String> command;
@Override
public Integer call() throws Exception {
String cmd = String.join(" ", command);
try {
return Jpm.builder()
.directory(depsMixin.directory)
.noLinks(depsMixin.noLinks)
.cacheDir(depsMixin.cacheDir)
.appFile(appInfoFileMixin.appInfoFile)
.verbose(!quietMixin.quiet)
.build()
.executeCommand(cmd, depsMixin.getRepositoryMap());
} catch (Exception e) {
System.err.println(e.getMessage());
return 1;
}
}
}
@Command(
name = "do",
description =
"Executes an action command defined in the app.yml file."
+ " The command is executed using the same rules as the exec command, so it can use all the same tokens and features."
+ " You can also pass additional arguments to the action using -a or --arg followed by the argument value."
+ " You can chain multiple actions and their arguments in a single command line."
+ "\n"
+ "Example:\n"
+ " jpm do build\n"
+ " jpm do test --arg verbose\n"
+ " jpm do build -a --fresh test -a verbose\n")
static class Do implements Callable<Integer> {
@Mixin VerboseMixin verboseMixin;
@Mixin DepsMixin depsMixin;
@Mixin QuietMixin quietMixin;
@Mixin AppInfoFileMixin appInfoFileMixin;
@Option(
names = {"-l", "--list"},
description = "List all available actions",
defaultValue = "false")
private boolean list;
@Parameters(
paramLabel = "action",
description = "Name of the action to execute as defined in app.yml",
arity = "0..*",
index = "0")
private String actionName;
@Parameters(
paramLabel = "actionsAndArguments",
description =
"Optional additional actions and/or arguments to be passed to the action(s)",
arity = "0..*",
index = "1..*")
private ArrayList<String> actsAndArgs = new ArrayList<>();
@Override
public Integer call() throws Exception {
try {
if (list) {
List<String> actionNames =
Jpm.builder()
.directory(depsMixin.directory)
.noLinks(depsMixin.noLinks)
.cacheDir(depsMixin.cacheDir)
.appFile(appInfoFileMixin.appInfoFile)
.build()
.listActions();
if (actionNames.isEmpty()) {
if (!quietMixin.quiet) System.out.println("No actions defined in app.yml");
} else {
if (!quietMixin.quiet) System.out.println("Available actions:");
actionNames.forEach(n -> System.out.println(" " + n));
}
} else {
if (actionName == null || actionName.isEmpty()) {
System.err.println(
"Action name is required. Use --list to see available actions.");
return 1;
}
// Split the full arguments list in multiple actions and their arguments
int idx = 0;
actsAndArgs.add(0, actionName);
while (idx < actsAndArgs.size()) {
String action = actsAndArgs.get(idx);
if (action.startsWith("-")) {
System.err.println(
"Unexpected argument, was expecting an action name: " + action);
return 1;
}
idx++;
List<String> args = new ArrayList<>();
while (idx < actsAndArgs.size() && actsAndArgs.get(idx).startsWith("-")) {
String opt = actsAndArgs.get(idx);
if (opt.equals("-a") || opt.equals("--arg")) {
args.add(actsAndArgs.get(++idx));
} else if (opt.startsWith("-a=") || opt.startsWith("--arg=")) {
args.add(opt.substring(opt.indexOf('=') + 1));
} else {
System.err.println(
"Unexpected argument, was expecting an action argument like '-a' or '--arg', not: "
+ opt);
return 1;
}
idx++;
}
int exitCode =
Jpm.builder()
.directory(depsMixin.directory)
.noLinks(depsMixin.noLinks)
.cacheDir(depsMixin.cacheDir)
.appFile(appInfoFileMixin.appInfoFile)
.verbose(!quietMixin.quiet)
.build()
.executeAction(action, args, depsMixin.getRepositoryMap());
if (exitCode != 0) {
return exitCode;
}
}
}
} catch (Exception e) {
System.err.println(e.getMessage());
return 1;
}
return 0;
}
}
abstract static class DoAlias implements Callable<Integer> {
@Mixin VerboseMixin verboseMixin;
@Mixin DepsMixin depsMixin;
@Mixin AppInfoFileMixin appInfoFileMixin;
@Unmatched List<String> args = new ArrayList<>();
abstract String actionName();
@Override
public Integer call() throws Exception {
try {
// Use only unmatched args for pass-through to preserve ordering
return Jpm.builder()
.directory(depsMixin.directory)
.noLinks(depsMixin.noLinks)
.cacheDir(depsMixin.cacheDir)
.appFile(appInfoFileMixin.appInfoFile)
.build()
.executeAction(actionName(), args, depsMixin.getRepositoryMap());
} catch (Exception e) {
System.err.println(e.getMessage());
return 1;
}
}
}
@Command(
name = "clean",
description = "Executes the 'clean' action as defined in the app.yml file.")
static class Clean extends DoAlias {
@Override
String actionName() {
return "clean";
}
}
@Command(
name = "build",
description = "Executes the 'build' action as defined in the app.yml file.")
static class Build extends DoAlias {
@Override
String actionName() {
return "build";
}
}
@Command(
name = "run",
description = "Executes the 'run' action as defined in the app.yml file.")
static class Run extends DoAlias {
@Override
String actionName() {
return "run";
}
}
@Command(
name = "test",
description = "Executes the 'test' action as defined in the app.yml file.")
static class Test extends DoAlias {
@Override
String actionName() {
return "test";
}
}
static class DepsMixin {
@Option(
names = {"-d", "--directory"},
description = "Directory to copy artifacts to",
defaultValue = "deps")
Path directory;
@Option(
names = {"-L", "--no-links"},
description = "Always copy artifacts, don't try to create symlinks",
defaultValue = "false")
boolean noLinks;
@Option(
names = {"-r", "--repo"},
description =
"URL to additional repository to use when resolving artifacts. Can be preceded by a name and an equals sign, e.g. -r myrepo=https://my.repo.com/maven2. When needing to pass user and password you can set JPM_REPO_<name>_USER and JPM_REPO_<name>_PASSWORD environment variables.")
List<String> repositories = new ArrayList<>();
@Option(
names = {"-c", "--cache"},
description =
"Directory where downloaded artifacts will be cached (default: value of JPM_CACHE environment variable; whatever is set in Maven's settings.xml or $HOME/.m2/repository")
Path cacheDir;
Map<String, String> getRepositoryMap() {
Map<String, String> repoMap = new HashMap<>();
for (String repo : repositories) {
String name;
String url;
int eq = repo.indexOf('=');
if (eq >= 0) {
name = repo.substring(0, eq);
url = repo.substring(eq + 1);
} else {
name = "";
url = repo;
}
if (name.isEmpty()) {
try {
URL x = new URL(repo);
name = x.getHost();
} catch (MalformedURLException e) {
name = "repo" + (repoMap.size() + 1);
}
}
if (!url.isEmpty()) {
repoMap.put(name, url);
}
}
return repoMap;
}
}
static class ArtifactsMixin extends DepsMixin {
@Parameters(
paramLabel = "artifacts",
description =
"One or more artifacts to resolve. Artifacts have the format <group>:<artifact>[:<extension>[:<classifier>]]:<version>",
arity = "1..*")
private String[] artifactNames = {};
}
static class OptionalArtifactsMixin extends DepsMixin {
@Parameters(
paramLabel = "artifacts",
description =
"One or more artifacts to resolve. Artifacts have the format <group>:<artifact>[:<extension>[:<classifier>]]:<version>",
arity = "0..*")
private String[] artifactNames = {};
}
static class AppInfoFileMixin {
@Option(
names = {"-a", "--appinfo"},
description = "App info file to use (default './app.yml')")
Path appInfoFile;
}
static class VerboseMixin {
@Option(
names = {"-v", "--verbose"},
description = "Enable verbose output for debugging")
public void setVerbose(boolean verbose) {
Main.verbose = verbose;
}
}
static class QuietMixin {
@Option(
names = {"-q", "--quiet"},
description = "Don't output non-essential information",
defaultValue = "false")
private boolean quiet;
}
private static void printStats(SyncResult stats) {
System.err.printf(
"Artifacts new: %d, updated: %d, deleted: %d%n",
(Integer) stats.copied, (Integer) stats.updated, (Integer) stats.deleted);
}
static CommandLine.IExecutionExceptionHandler errorHandler =
(ex, commandLine, parseResult) -> {
System.err.println("Error: " + ex.getMessage());
if (verbose) {
ex.printStackTrace();
} else {
System.err.println(
"(Run with --verbose for more details. If you believe you found a bug in jpm, open an issue at https://github.com/codejive/java-jpm/issues)");
}
return commandLine.getCommandSpec().exitCodeOnExecutionException();
};
public static CommandLine getCommandLine() {
return new CommandLine(new Main())
.setStopAtPositional(true)
.setAllowOptionsAsOptionParameters(true)
.setAllowSubcommandsAsOptionParameters(true)
.setExecutionExceptionHandler(errorHandler);
}
/**
* Main entry point for the jpm command line tool.
*
* @param args The command line arguments.
*/
public static void main(String... args) {
getCommandLine().execute(args);
}
}