Skip to content

Commit

Permalink
Merge pull request #346 from pwielgolaski/#214
Browse files Browse the repository at this point in the history
Passthrough additional environment variables (by l337r007) merge on top of master
  • Loading branch information
eirslett committed Jan 24, 2016
2 parents 7cb27f1 + 87adc91 commit b07071a
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Map;

public abstract class AbstractFrontendMojo extends AbstractMojo {

Expand All @@ -35,6 +36,13 @@ public abstract class AbstractFrontendMojo extends AbstractMojo {
@Parameter(property = "installDirectory", required = false)
protected File installDirectory;


/**
* Additional environment variables to pass to the build.
*/
@Parameter
protected Map<String, String> environmentVariables;

/**
* Determines if this execution should be skipped.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ protected boolean skipExecution() {
@Override
protected void execute(FrontendPluginFactory factory) throws TaskRunnerException {
ProxyConfig proxyConfig = MojoUtils.getProxyConfig(session, decrypter);
factory.getBowerRunner(proxyConfig).execute(arguments);
factory.getBowerRunner(proxyConfig).execute(arguments, environmentVariables);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected boolean skipExecution() {
@Override
public void execute(FrontendPluginFactory factory) throws TaskRunnerException {
if (shouldExecute()) {
factory.getEmberRunner().execute(arguments);
factory.getEmberRunner().execute(arguments, environmentVariables);

if (outputdir != null) {
getLog().info("Refreshing files after ember: " + outputdir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected boolean skipExecution() {
@Override
public void execute(FrontendPluginFactory factory) throws TaskRunnerException {
if (shouldExecute()) {
factory.getGruntRunner().execute(arguments);
factory.getGruntRunner().execute(arguments, environmentVariables);

if (outputdir != null) {
getLog().info("Refreshing files after grunt: " + outputdir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected boolean skipExecution() {
@Override
public void execute(FrontendPluginFactory factory) throws TaskRunnerException {
if (shouldExecute()) {
factory.getGulpRunner().execute(arguments);
factory.getGulpRunner().execute(arguments, environmentVariables);

if (outputdir != null) {
getLog().info("Refreshing files after gulp: " + outputdir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected boolean skipExecution() {

@Override
protected void execute(FrontendPluginFactory factory) throws TaskRunnerException {
factory.getJspmRunner().execute(arguments);
factory.getJspmRunner().execute(arguments, environmentVariables);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected boolean skipExecution() {
@Override
public void execute(FrontendPluginFactory factory) throws TaskRunnerException {
try {
factory.getKarmaRunner().execute("start " + karmaConfPath);
factory.getKarmaRunner().execute("start " + karmaConfPath, environmentVariables);
}
catch (TaskRunnerException e) {
if (testFailureIgnore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void execute(FrontendPluginFactory factory) throws TaskRunnerException {
File packageJson = new File(workingDirectory, "package.json");
if (buildContext == null || buildContext.hasDelta(packageJson) || !buildContext.isIncremental()) {
ProxyConfig proxyConfig = MojoUtils.getProxyConfig(session, decrypter);
factory.getNpmRunner(proxyConfig).execute(arguments);
factory.getNpmRunner(proxyConfig).execute(arguments, environmentVariables);
} else {
getLog().info("Skipping npm install as package.json unchanged");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected boolean skipExecution() {
@Override
public void execute(FrontendPluginFactory factory) throws TaskRunnerException {
if (shouldExecute()) {
factory.getWebpackRunner().execute(arguments);
factory.getWebpackRunner().execute(arguments, environmentVariables);

if (outputdir != null) {
getLog().info("Refreshing files after webpack: " + outputdir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import java.util.ArrayList;
import java.util.List;

public interface BowerRunner {
void execute(String args) throws TaskRunnerException;
}
public interface BowerRunner extends NodeTaskRunner {}

final class DefaultBowerRunner extends NodeTaskExecutor implements BowerRunner {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.github.eirslett.maven.plugins.frontend.lib;

public interface EmberRunner {
void execute(String args) throws TaskRunnerException;
}
public interface EmberRunner extends NodeTaskRunner {}

final class DefaultEmberRunner extends NodeTaskExecutor implements EmberRunner {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import java.util.Arrays;

public interface GruntRunner {
void execute(String args) throws TaskRunnerException;
}
public interface GruntRunner extends NodeTaskRunner {}

final class DefaultGruntRunner extends NodeTaskExecutor implements GruntRunner {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import java.util.Arrays;

public interface GulpRunner {
void execute(String args) throws TaskRunnerException;
}
public interface GulpRunner extends NodeTaskRunner {}

final class DefaultGulpRunner extends NodeTaskExecutor implements GulpRunner {
private static final String TASK_LOCATION = "node_modules/gulp/bin/gulp.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.github.eirslett.maven.plugins.frontend.lib;

public interface JspmRunner {
void execute(String args) throws TaskRunnerException;
}

public interface JspmRunner extends NodeTaskRunner {}

final class DefaultJspmRunner extends NodeTaskExecutor implements JspmRunner {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import java.util.Arrays;

public interface KarmaRunner {
void execute(String args) throws TaskRunnerException;
}
public interface KarmaRunner extends NodeTaskRunner {}

final class DefaultKarmaRunner extends NodeTaskExecutor implements KarmaRunner {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private boolean nodeIsAlreadyInstalled() {
NodeExecutorConfig executorConfig = new InstallNodeExecutorConfig(config);
File nodeFile = executorConfig.getNodePath();
if(nodeFile.exists()){
final String version = new NodeExecutor(executorConfig, Arrays.asList("--version")).executeAndGetResult();
final String version = new NodeExecutor(executorConfig, Arrays.asList("--version"), null).executeAndGetResult();

if(version.equals(nodeVersion)){
logger.info("Node " + version + " is already installed.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

final class NodeExecutor {
private final ProcessExecutor executor;

public NodeExecutor(NodeExecutorConfig config, List<String> arguments){
public NodeExecutor(NodeExecutorConfig config, List<String> arguments, Map<String, String> additionalEnvironment){
final String node = config.getNodePath().getAbsolutePath();
List<String> localPaths = new ArrayList<String>();
localPaths.add(config.getNodePath().getParent());
this.executor = new ProcessExecutor(
config.getWorkingDirectory(),
localPaths,
Utils.prepend(node, arguments),
config.getPlatform());
config.getPlatform(),
additionalEnvironment);
}

public String executeAndGetResult() throws ProcessExecutionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static com.github.eirslett.maven.plugins.frontend.lib.Utils.implode;
import static com.github.eirslett.maven.plugins.frontend.lib.Utils.normalize;
import static com.github.eirslett.maven.plugins.frontend.lib.Utils.prepend;
import java.util.Map;

abstract class NodeTaskExecutor {
private static final String DS = "//";
Expand Down Expand Up @@ -48,13 +49,13 @@ private static String getTaskNameFromLocation(String taskLocation) {
}


public final void execute(String args) throws TaskRunnerException {
public final void execute(String args, Map<String, String> environment) throws TaskRunnerException {
final String absoluteTaskLocation = getAbsoluteTaskLocation();
final List<String> arguments = getArguments(args);
logger.info("Running " + taskToString(taskName, arguments) + " in " + config.getWorkingDirectory());

try {
final int result = new NodeExecutor(config, prepend(absoluteTaskLocation, arguments)).executeAndRedirectOutput(logger);
final int result = new NodeExecutor(config, prepend(absoluteTaskLocation, arguments), environment).executeAndRedirectOutput(logger);
if (result != 0) {
throw new TaskRunnerException(taskToString(taskName, arguments) + " failed. (error code " + result + ")");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import java.util.Map;

interface NodeTaskRunner {
void execute(String args, Map<String,String> environment) throws TaskRunnerException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import java.util.ArrayList;
import java.util.List;

public interface NpmRunner {
void execute(String args) throws TaskRunnerException;
}
public interface NpmRunner extends NodeTaskRunner {}

final class DefaultNpmRunner extends NodeTaskExecutor implements NpmRunner {
static final String TASK_NAME = "npm";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ final class ProcessExecutor {
private final List<String> command;
private final ProcessBuilder processBuilder;
private final Platform platform;
private final Map<String, String> additionalEnvironment;

public ProcessExecutor(File workingDirectory, List<String> paths, List<String> command, Platform platform){
public ProcessExecutor(File workingDirectory, List<String> paths, List<String> command, Platform platform, Map<String, String> additionalEnvironment){
this.workingDirectory = workingDirectory;
this.localPaths = paths;
this.command = command;
this.platform = platform;
this.additionalEnvironment = additionalEnvironment;

this.processBuilder = createProcessBuilder();
}
Expand Down Expand Up @@ -97,6 +99,9 @@ private ProcessBuilder createProcessBuilder(){
}
environment.put(pathVarName, pathBuilder.toString());

if (additionalEnvironment != null) {
environment.putAll(additionalEnvironment);
}
return pbuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import java.util.ArrayList;

public interface WebpackRunner {
void execute(String args) throws TaskRunnerException;
}
public interface WebpackRunner extends NodeTaskRunner {}

final class DefaultWebpackRunner extends NodeTaskExecutor implements WebpackRunner {

Expand Down

0 comments on commit b07071a

Please sign in to comment.