11package com .github .eirslett .maven .plugins .frontend .lib ;
22
3- import org .slf4j .Logger ;
4- import org .slf4j .LoggerFactory ;
3+ import static com .github .eirslett .maven .plugins .frontend .lib .Utils .implode ;
4+ import static com .github .eirslett .maven .plugins .frontend .lib .Utils .normalize ;
5+ import static com .github .eirslett .maven .plugins .frontend .lib .Utils .prepend ;
56
67import java .io .File ;
78import java .util .ArrayList ;
8- import java .util .Arrays ;
99import java .util .Collections ;
10+ import java .util .HashMap ;
1011import java .util .List ;
11-
12- import static com .github .eirslett .maven .plugins .frontend .lib .Utils .implode ;
13- import static com .github .eirslett .maven .plugins .frontend .lib .Utils .normalize ;
14- import static com .github .eirslett .maven .plugins .frontend .lib .Utils .prepend ;
1512import java .util .Map ;
1613
14+ import org .slf4j .Logger ;
15+ import org .slf4j .LoggerFactory ;
16+
1717abstract class NodeTaskExecutor {
1818 private static final String DS = "//" ;
1919 private static final String AT = "@" ;
20-
20+
2121 private final Logger logger ;
2222 private final String taskName ;
2323 private String taskLocation ;
2424 private final ArgumentsParser argumentsParser ;
2525 private final NodeExecutorConfig config ;
26+ private final Map <String , String > proxy ;
2627
2728 public NodeTaskExecutor (NodeExecutorConfig config , String taskLocation ) {
2829 this (config , taskLocation , Collections .<String >emptyList ());
@@ -37,11 +38,16 @@ public NodeTaskExecutor(NodeExecutorConfig config, String taskLocation, List<Str
3738 }
3839
3940 public NodeTaskExecutor (NodeExecutorConfig config , String taskName , String taskLocation , List <String > additionalArguments ) {
41+ this (config , taskName , taskLocation , additionalArguments , Collections .<String , String >emptyMap ());
42+ }
43+
44+ public NodeTaskExecutor (NodeExecutorConfig config , String taskName , String taskLocation , List <String > additionalArguments , Map <String , String > proxy ) {
4045 this .logger = LoggerFactory .getLogger (getClass ());
4146 this .config = config ;
4247 this .taskName = taskName ;
4348 this .taskLocation = taskLocation ;
4449 this .argumentsParser = new ArgumentsParser (additionalArguments );
50+ this .proxy = proxy ;
4551 }
4652
4753 private static String getTaskNameFromLocation (String taskLocation ) {
@@ -55,7 +61,14 @@ public final void execute(String args, Map<String, String> environment) throws T
5561 logger .info ("Running " + taskToString (taskName , arguments ) + " in " + config .getWorkingDirectory ());
5662
5763 try {
58- final int result = new NodeExecutor (config , prepend (absoluteTaskLocation , arguments ), environment ).executeAndRedirectOutput (logger );
64+ Map <String , String > internalEnvironment = new HashMap <>();
65+ if (environment != null && !environment .isEmpty ()) {
66+ internalEnvironment .putAll (environment );
67+ }
68+ if (!proxy .isEmpty ()) {
69+ internalEnvironment .putAll (proxy );
70+ }
71+ final int result = new NodeExecutor (config , prepend (absoluteTaskLocation , arguments ), internalEnvironment ).executeAndRedirectOutput (logger );
5972 if (result != 0 ) {
6073 throw new TaskRunnerException (taskToString (taskName , arguments ) + " failed. (error code " + result + ")" );
6174 }
0 commit comments