Skip to content

Commit

Permalink
Passthrough additional environment variables
Browse files Browse the repository at this point in the history
Squashed, rebased version of eirslett#214
  • Loading branch information
wherget authored and Oleg Golberg committed Jul 31, 2015
1 parent ac09c66 commit c8a15ac
Show file tree
Hide file tree
Showing 20 changed files with 111 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

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

@Mojo(name = "bower", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
public final class BowerMojo extends AbstractFrontendMojo {

Expand All @@ -15,6 +18,12 @@ public final class BowerMojo extends AbstractFrontendMojo {
@Parameter(defaultValue = "install", property = "frontend.bower.arguments", required = false)
private String arguments;

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

/**
* Skips execution of this mojo.
*/
Expand All @@ -28,6 +37,6 @@ protected boolean isSkipped() {

@Override
protected void execute(FrontendPluginFactory factory) throws TaskRunnerException {
factory.getBowerRunner().execute(arguments);
factory.getBowerRunner().execute(arguments, environmentVariables);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Mojo(name="ember", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
public final class EmberMojo extends AbstractFrontendMojo {
Expand Down Expand Up @@ -44,6 +45,12 @@ public final class EmberMojo extends AbstractFrontendMojo {
@Parameter(property = "outputdir")
private File outputdir;

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

/**
* Skips execution of this mojo.
*/
Expand All @@ -61,7 +68,7 @@ protected boolean isSkipped() {
@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 @@ -2,6 +2,12 @@

import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;


import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand All @@ -11,6 +17,7 @@
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Mojo(name="grunt", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
public final class GruntMojo extends AbstractFrontendMojo {
Expand Down Expand Up @@ -44,6 +51,12 @@ public final class GruntMojo extends AbstractFrontendMojo {
@Parameter(property = "outputdir")
private File outputdir;

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

/**
* Skips execution of this mojo.
*/
Expand All @@ -61,7 +74,7 @@ protected boolean isSkipped() {
@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 @@ -11,6 +11,7 @@
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Mojo(name="gulp", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
public final class GulpMojo extends AbstractFrontendMojo {
Expand Down Expand Up @@ -44,6 +45,12 @@ public final class GulpMojo extends AbstractFrontendMojo {
@Parameter(property = "outputdir")
private File outputdir;

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

/**
* Skips execution of this mojo.
*/
Expand All @@ -61,7 +68,7 @@ protected boolean isSkipped() {
@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 @@ -10,6 +10,7 @@
import org.apache.maven.plugins.annotations.Parameter;

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

@Mojo(name="jspm", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
public class JspmMojo extends AbstractFrontendMojo {
Expand All @@ -26,14 +27,20 @@ public class JspmMojo extends AbstractFrontendMojo {
@Parameter(property = "skip.jspm", defaultValue = "false")
private Boolean skip;

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

@Override
protected boolean isSkipped() {
return this.skip;
}

@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
@@ -1,7 +1,13 @@
package com.github.eirslett.maven.plugins.frontend.mojo;

import java.util.Map;

import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand Down Expand Up @@ -29,6 +35,12 @@ public final class KarmaRunMojo extends AbstractFrontendMojo {
@Parameter(property = "testFailureIgnore", required = false, defaultValue = "false")
private Boolean testFailureIgnore;

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

/**
* Skips execution of this mojo.
*/
Expand All @@ -47,7 +59,7 @@ public void execute(FrontendPluginFactory factory) throws TaskRunnerException {
LoggerFactory.getLogger(KarmaRunMojo.class).info("Skipping karma tests.");
}
else {
factory.getKarmaRunner().execute("start " + karmaConfPath);
factory.getKarmaRunner().execute("start " + karmaConfPath, environmentVariables);
}
}
catch (TaskRunnerException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand All @@ -12,6 +13,7 @@
import org.sonatype.plexus.build.incremental.BuildContext;

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

@Mojo(name="npm", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
public final class NpmMojo extends AbstractFrontendMojo {
Expand All @@ -22,6 +24,12 @@ public final class NpmMojo extends AbstractFrontendMojo {
@Parameter(defaultValue = "install", property = "frontend.npm.arguments", required = false)
private String arguments;

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

@Parameter(property = "session", defaultValue = "${session}", readonly = true)
private MavenSession session;

Expand All @@ -47,7 +55,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 @@ -11,6 +11,7 @@
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Mojo(name="webpack", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
public final class WebpackMojo extends AbstractFrontendMojo {
Expand Down Expand Up @@ -53,6 +54,12 @@ public final class WebpackMojo extends AbstractFrontendMojo {
@Component
private BuildContext buildContext;

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

@Override
protected boolean isSkipped() {
return this.skip;
Expand All @@ -61,7 +68,7 @@ protected boolean isSkipped() {
@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
@@ -1,7 +1,9 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import java.util.Map;

public interface BowerRunner {
void execute(String args) throws TaskRunnerException;
public void execute(String args, Map<String, String> environment) throws TaskRunnerException;
}

final class DefaultBowerRunner extends NodeTaskExecutor implements BowerRunner {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import java.util.Map;

public interface EmberRunner {
void execute(String args) throws TaskRunnerException;
public void execute(String args, Map<String, String> environment) throws TaskRunnerException;
}

final class DefaultEmberRunner extends NodeTaskExecutor implements EmberRunner {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import java.util.Arrays;
import java.util.Map;

public interface GruntRunner {
void execute(String args) throws TaskRunnerException;
public void execute(String args, Map<String, String> environment) throws TaskRunnerException;
}

final class DefaultGruntRunner extends NodeTaskExecutor implements GruntRunner {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import java.util.Arrays;
import java.util.Map;

public interface GulpRunner {
void execute(String args) throws TaskRunnerException;
public void execute(String args, Map<String, String> environment) throws TaskRunnerException;
}

final class DefaultGulpRunner extends NodeTaskExecutor implements GulpRunner {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import java.util.Map;

public interface JspmRunner {
void execute(String args) throws TaskRunnerException;
void execute(String args, Map<String, String> environment) throws TaskRunnerException;
}


final class DefaultJspmRunner extends NodeTaskExecutor implements JspmRunner {

static final String TASK_LOCATION = "node_modules/jspm/jspm.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import java.util.Arrays;
import java.util.Map;

public interface KarmaRunner {
void execute(String args) throws TaskRunnerException;
public void execute(String args, Map<String, String> environment) throws TaskRunnerException;
}

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,11 +4,12 @@

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());
Expand All @@ -17,7 +18,8 @@ public NodeExecutor(NodeExecutorConfig config, List<String> arguments){
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 @@ -8,6 +8,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static com.github.eirslett.maven.plugins.frontend.lib.Utils.implode;
import static com.github.eirslett.maven.plugins.frontend.lib.Utils.normalize;
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
Loading

0 comments on commit c8a15ac

Please sign in to comment.