@@ -88,8 +88,9 @@ static class Copy implements Callable<Integer> {
8888 public Integer call () throws Exception {
8989 SyncResult stats =
9090 Jpm .builder ()
91- .directory (artifactsMixin .depsMixin .directory )
92- .noLinks (artifactsMixin .depsMixin .noLinks )
91+ .directory (artifactsMixin .directory )
92+ .noLinks (artifactsMixin .noLinks )
93+ .cacheDir (artifactsMixin .cacheDir )
9394 .build ()
9495 .copy (
9596 artifactsMixin .artifactNames ,
@@ -162,9 +163,12 @@ public Integer call() throws Exception {
162163 Jpm .builder ()
163164 .directory (depsMixin .directory )
164165 .noLinks (depsMixin .noLinks )
166+ .cacheDir (depsMixin .cacheDir )
165167 .appFile (appInfoFileMixin .appInfoFile )
166168 .build ()
167- .install (new String [] {selectedArtifact });
169+ .install (
170+ new String [] {selectedArtifact },
171+ depsMixin .getRepositoryMap ());
168172 if (!quietMixin .quiet ) {
169173 printStats (stats );
170174 }
@@ -173,9 +177,13 @@ public Integer call() throws Exception {
173177 Jpm .builder ()
174178 .directory (depsMixin .directory )
175179 .noLinks (depsMixin .noLinks )
180+ .cacheDir (depsMixin .cacheDir )
176181 .appFile (appInfoFileMixin .appInfoFile )
177182 .build ()
178- .copy (new String [] {selectedArtifact }, false );
183+ .copy (
184+ new String [] {selectedArtifact },
185+ depsMixin .getRepositoryMap (),
186+ false );
179187 if (!quietMixin .quiet ) {
180188 printStats (stats );
181189 }
@@ -211,6 +219,7 @@ String[] search(String artifactPattern) {
211219 return Jpm .builder ()
212220 .directory (depsMixin .directory )
213221 .noLinks (depsMixin .noLinks )
222+ .cacheDir (depsMixin .cacheDir )
214223 .appFile (appInfoFileMixin .appInfoFile )
215224 .build ()
216225 .search (artifactPattern , Math .min (max , 200 ), backend );
@@ -309,8 +318,9 @@ static class Install implements Callable<Integer> {
309318 public Integer call () throws Exception {
310319 SyncResult stats =
311320 Jpm .builder ()
312- .directory (optionalArtifactsMixin .depsMixin .directory )
313- .noLinks (optionalArtifactsMixin .depsMixin .noLinks )
321+ .directory (optionalArtifactsMixin .directory )
322+ .noLinks (optionalArtifactsMixin .noLinks )
323+ .cacheDir (optionalArtifactsMixin .cacheDir )
314324 .appFile (appInfoFileMixin .appInfoFile )
315325 .build ()
316326 .install (
@@ -339,8 +349,9 @@ static class PrintPath implements Callable<Integer> {
339349 public Integer call () throws Exception {
340350 List <Path > files =
341351 Jpm .builder ()
342- .directory (optionalArtifactsMixin .depsMixin .directory )
343- .noLinks (optionalArtifactsMixin .depsMixin .noLinks )
352+ .directory (optionalArtifactsMixin .directory )
353+ .noLinks (optionalArtifactsMixin .noLinks )
354+ .cacheDir (optionalArtifactsMixin .cacheDir )
344355 .appFile (appInfoFileMixin .appInfoFile )
345356 .build ()
346357 .path (
@@ -386,6 +397,7 @@ static class Exec implements Callable<Integer> {
386397 @ Mixin VerboseMixin verboseMixin ;
387398 @ Mixin DepsMixin depsMixin ;
388399 @ Mixin QuietMixin quietMixin ;
400+ @ Mixin AppInfoFileMixin appInfoFileMixin ;
389401
390402 @ Parameters (paramLabel = "command" , description = "The command to execute" , arity = "0..*" )
391403 private List <String > command ;
@@ -397,9 +409,11 @@ public Integer call() throws Exception {
397409 return Jpm .builder ()
398410 .directory (depsMixin .directory )
399411 .noLinks (depsMixin .noLinks )
412+ .cacheDir (depsMixin .cacheDir )
413+ .appFile (appInfoFileMixin .appInfoFile )
400414 .verbose (!quietMixin .quiet )
401415 .build ()
402- .executeCommand (cmd );
416+ .executeCommand (cmd , depsMixin . getRepositoryMap () );
403417 } catch (Exception e ) {
404418 System .err .println (e .getMessage ());
405419 return 1 ;
@@ -454,6 +468,7 @@ public Integer call() throws Exception {
454468 Jpm .builder ()
455469 .directory (depsMixin .directory )
456470 .noLinks (depsMixin .noLinks )
471+ .cacheDir (depsMixin .cacheDir )
457472 .appFile (appInfoFileMixin .appInfoFile )
458473 .build ()
459474 .listActions ();
@@ -499,10 +514,11 @@ public Integer call() throws Exception {
499514 Jpm .builder ()
500515 .directory (depsMixin .directory )
501516 .noLinks (depsMixin .noLinks )
517+ .cacheDir (depsMixin .cacheDir )
502518 .appFile (appInfoFileMixin .appInfoFile )
503519 .verbose (!quietMixin .quiet )
504520 .build ()
505- .executeAction (action , args );
521+ .executeAction (action , args , depsMixin . getRepositoryMap () );
506522 if (exitCode != 0 ) {
507523 return exitCode ;
508524 }
@@ -532,9 +548,10 @@ public Integer call() throws Exception {
532548 return Jpm .builder ()
533549 .directory (depsMixin .directory )
534550 .noLinks (depsMixin .noLinks )
551+ .cacheDir (depsMixin .cacheDir )
535552 .appFile (appInfoFileMixin .appInfoFile )
536553 .build ()
537- .executeAction (actionName (), args );
554+ .executeAction (actionName (), args , depsMixin . getRepositoryMap () );
538555 } catch (Exception e ) {
539556 System .err .println (e .getMessage ());
540557 return 1 ;
@@ -594,17 +611,19 @@ static class DepsMixin {
594611 description = "Always copy artifacts, don't try to create symlinks" ,
595612 defaultValue = "false" )
596613 boolean noLinks ;
597- }
598-
599- static class BaseArtifactsMixin {
600- @ Mixin DepsMixin depsMixin ;
601614
602615 @ Option (
603616 names = {"-r" , "--repo" },
604617 description =
605618 "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." )
606619 List <String > repositories = new ArrayList <>();
607620
621+ @ Option (
622+ names = {"-c" , "--cache" },
623+ description =
624+ "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" )
625+ Path cacheDir ;
626+
608627 Map <String , String > getRepositoryMap () {
609628 Map <String , String > repoMap = new HashMap <>();
610629 for (String repo : repositories ) {
@@ -634,7 +653,7 @@ Map<String, String> getRepositoryMap() {
634653 }
635654 }
636655
637- static class ArtifactsMixin extends BaseArtifactsMixin {
656+ static class ArtifactsMixin extends DepsMixin {
638657 @ Parameters (
639658 paramLabel = "artifacts" ,
640659 description =
@@ -643,7 +662,7 @@ static class ArtifactsMixin extends BaseArtifactsMixin {
643662 private String [] artifactNames = {};
644663 }
645664
646- static class OptionalArtifactsMixin extends BaseArtifactsMixin {
665+ static class OptionalArtifactsMixin extends DepsMixin {
647666 @ Parameters (
648667 paramLabel = "artifacts" ,
649668 description =
0 commit comments