diff --git a/frontend-maven-plugin/src/it/environment-variables-file-missing/package.json b/frontend-maven-plugin/src/it/environment-variables-file-missing/package.json
new file mode 100644
index 000000000..a901828e4
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-file-missing/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "example",
+ "version": "0.0.1",
+ "scripts": {
+ "test": "node script.mjs"
+ }
+}
diff --git a/frontend-maven-plugin/src/it/environment-variables-file-missing/pom.xml b/frontend-maven-plugin/src/it/environment-variables-file-missing/pom.xml
new file mode 100644
index 000000000..3a696eabf
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-file-missing/pom.xml
@@ -0,0 +1,47 @@
+
+
+ 4.0.0
+
+ com.github.eirslett
+ example
+ 0
+ pom
+
+
+
+
+ com.github.eirslett
+ frontend-maven-plugin
+
+ @project.version@
+
+
+ target
+ ${project.basedir}/.env
+
+
+
+
+ install node and npm
+
+ install-node-and-npm
+
+
+ v16.17.1
+
+
+
+
+ npm test
+
+ npm
+
+
+ test
+
+
+
+
+
+
+
diff --git a/frontend-maven-plugin/src/it/environment-variables-file-missing/script.mjs b/frontend-maven-plugin/src/it/environment-variables-file-missing/script.mjs
new file mode 100644
index 000000000..c86570dba
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-file-missing/script.mjs
@@ -0,0 +1,3 @@
+'use strict';
+
+console.log(`ENVIRONMENT_VARIABLE_FILE_1: ${process.env.ENVIRONMENT_VARIABLE_FILE_1}`)
diff --git a/frontend-maven-plugin/src/it/environment-variables-file-missing/verify.groovy b/frontend-maven-plugin/src/it/environment-variables-file-missing/verify.groovy
new file mode 100644
index 000000000..cc58351c6
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-file-missing/verify.groovy
@@ -0,0 +1,10 @@
+assert new File(basedir, 'target/node').exists() : "Node was not installed in the custom install directory";
+assert new File(basedir, 'target/node/npm').exists() : "npm was not copied to the node directory";
+
+import org.codehaus.plexus.util.FileUtils;
+
+String buildLog = FileUtils.fileRead(new File(basedir, 'build.log'));
+
+assert buildLog.contains("File containing environment variables (configuration 'environmentFile') at '${basedir}/.env' could not be found, skipping it." as CharSequence) : 'environmentFile not missing'
+assert buildLog.contains('ENVIRONMENT_VARIABLE_FILE_1: undefined') : 'environmentFile should not working'
+assert buildLog.contains('BUILD SUCCESS') : 'build was not successful'
diff --git a/frontend-maven-plugin/src/it/environment-variables-file/.env b/frontend-maven-plugin/src/it/environment-variables-file/.env
new file mode 100644
index 000000000..13e046c38
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-file/.env
@@ -0,0 +1 @@
+ENVIRONMENT_VARIABLE_FILE_1=1
diff --git a/frontend-maven-plugin/src/it/environment-variables-file/package.json b/frontend-maven-plugin/src/it/environment-variables-file/package.json
new file mode 100644
index 000000000..a901828e4
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-file/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "example",
+ "version": "0.0.1",
+ "scripts": {
+ "test": "node script.mjs"
+ }
+}
diff --git a/frontend-maven-plugin/src/it/environment-variables-file/pom.xml b/frontend-maven-plugin/src/it/environment-variables-file/pom.xml
new file mode 100644
index 000000000..3a696eabf
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-file/pom.xml
@@ -0,0 +1,47 @@
+
+
+ 4.0.0
+
+ com.github.eirslett
+ example
+ 0
+ pom
+
+
+
+
+ com.github.eirslett
+ frontend-maven-plugin
+
+ @project.version@
+
+
+ target
+ ${project.basedir}/.env
+
+
+
+
+ install node and npm
+
+ install-node-and-npm
+
+
+ v16.17.1
+
+
+
+
+ npm test
+
+ npm
+
+
+ test
+
+
+
+
+
+
+
diff --git a/frontend-maven-plugin/src/it/environment-variables-file/script.mjs b/frontend-maven-plugin/src/it/environment-variables-file/script.mjs
new file mode 100644
index 000000000..c86570dba
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-file/script.mjs
@@ -0,0 +1,3 @@
+'use strict';
+
+console.log(`ENVIRONMENT_VARIABLE_FILE_1: ${process.env.ENVIRONMENT_VARIABLE_FILE_1}`)
diff --git a/frontend-maven-plugin/src/it/environment-variables-file/verify.groovy b/frontend-maven-plugin/src/it/environment-variables-file/verify.groovy
new file mode 100644
index 000000000..20064a7cc
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-file/verify.groovy
@@ -0,0 +1,9 @@
+assert new File(basedir, 'target/node').exists() : "Node was not installed in the custom install directory";
+assert new File(basedir, 'target/node/npm').exists() : "npm was not copied to the node directory";
+
+import org.codehaus.plexus.util.FileUtils;
+
+String buildLog = FileUtils.fileRead(new File(basedir, 'build.log'));
+
+assert buildLog.contains('ENVIRONMENT_VARIABLE_FILE_1: 1') : 'environmentFile not working'
+assert buildLog.contains('BUILD SUCCESS') : 'build was not successful'
diff --git a/frontend-maven-plugin/src/it/environment-variables-mixed/.env b/frontend-maven-plugin/src/it/environment-variables-mixed/.env
new file mode 100644
index 000000000..08d8d0f42
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-mixed/.env
@@ -0,0 +1,2 @@
+ENVIRONMENT_VARIABLE_FILE_1=1
+ENVIRONMENT_VARIABLE_OVERRIDE=2
diff --git a/frontend-maven-plugin/src/it/environment-variables-mixed/package.json b/frontend-maven-plugin/src/it/environment-variables-mixed/package.json
new file mode 100644
index 000000000..a901828e4
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-mixed/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "example",
+ "version": "0.0.1",
+ "scripts": {
+ "test": "node script.mjs"
+ }
+}
diff --git a/frontend-maven-plugin/src/it/environment-variables-mixed/pom.xml b/frontend-maven-plugin/src/it/environment-variables-mixed/pom.xml
new file mode 100644
index 000000000..ed36f37fb
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-mixed/pom.xml
@@ -0,0 +1,51 @@
+
+
+ 4.0.0
+
+ com.github.eirslett
+ example
+ 0
+ pom
+
+
+
+
+ com.github.eirslett
+ frontend-maven-plugin
+
+ @project.version@
+
+
+ target
+ ${project.basedir}/.env
+
+ 3
+ 4
+
+
+
+
+
+ install node and npm
+
+ install-node-and-npm
+
+
+ v16.17.1
+
+
+
+
+ npm test
+
+ npm
+
+
+ test
+
+
+
+
+
+
+
diff --git a/frontend-maven-plugin/src/it/environment-variables-mixed/script.mjs b/frontend-maven-plugin/src/it/environment-variables-mixed/script.mjs
new file mode 100644
index 000000000..d01f21900
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-mixed/script.mjs
@@ -0,0 +1,5 @@
+'use strict';
+
+console.log(`ENVIRONMENT_VARIABLE_FILE_1: ${process.env.ENVIRONMENT_VARIABLE_FILE_1}`)
+console.log(`ENVIRONMENT_VARIABLE_OVERRIDE: ${process.env.ENVIRONMENT_VARIABLE_OVERRIDE}`)
+console.log(`ENVIRONMENT_VARIABLE_4: ${process.env.ENVIRONMENT_VARIABLE_4}`)
diff --git a/frontend-maven-plugin/src/it/environment-variables-mixed/verify.groovy b/frontend-maven-plugin/src/it/environment-variables-mixed/verify.groovy
new file mode 100644
index 000000000..0e024d6e2
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables-mixed/verify.groovy
@@ -0,0 +1,11 @@
+assert new File(basedir, 'target/node').exists() : "Node was not installed in the custom install directory";
+assert new File(basedir, 'target/node/npm').exists() : "npm was not copied to the node directory";
+
+import org.codehaus.plexus.util.FileUtils;
+
+String buildLog = FileUtils.fileRead(new File(basedir, 'build.log'));
+
+assert buildLog.contains('ENVIRONMENT_VARIABLE_FILE_1: 1') : 'environmentFile not working'
+assert buildLog.contains('ENVIRONMENT_VARIABLE_OVERRIDE: 3') : 'environmentVariables not working overriding environmentFile'
+assert buildLog.contains('ENVIRONMENT_VARIABLE_4: 4') : 'environmentVariables not working'
+assert buildLog.contains('BUILD SUCCESS') : 'build was not successful'
diff --git a/frontend-maven-plugin/src/it/environment-variables/package.json b/frontend-maven-plugin/src/it/environment-variables/package.json
new file mode 100644
index 000000000..a901828e4
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "example",
+ "version": "0.0.1",
+ "scripts": {
+ "test": "node script.mjs"
+ }
+}
diff --git a/frontend-maven-plugin/src/it/environment-variables/pom.xml b/frontend-maven-plugin/src/it/environment-variables/pom.xml
new file mode 100644
index 000000000..432bdae83
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables/pom.xml
@@ -0,0 +1,49 @@
+
+
+ 4.0.0
+
+ com.github.eirslett
+ example
+ 0
+ pom
+
+
+
+
+ com.github.eirslett
+ frontend-maven-plugin
+
+ @project.version@
+
+
+ target
+
+ 1
+
+
+
+
+
+ install node and npm
+
+ install-node-and-npm
+
+
+ v16.17.1
+
+
+
+
+ npm test
+
+ npm
+
+
+ test
+
+
+
+
+
+
+
diff --git a/frontend-maven-plugin/src/it/environment-variables/script.mjs b/frontend-maven-plugin/src/it/environment-variables/script.mjs
new file mode 100644
index 000000000..40744af51
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables/script.mjs
@@ -0,0 +1,3 @@
+'use strict';
+
+console.log(`ENVIRONMENT_VARIABLE_1: ${process.env.ENVIRONMENT_VARIABLE_1}`)
diff --git a/frontend-maven-plugin/src/it/environment-variables/verify.groovy b/frontend-maven-plugin/src/it/environment-variables/verify.groovy
new file mode 100644
index 000000000..e0fe454a9
--- /dev/null
+++ b/frontend-maven-plugin/src/it/environment-variables/verify.groovy
@@ -0,0 +1,9 @@
+assert new File(basedir, 'target/node').exists() : "Node was not installed in the custom install directory";
+assert new File(basedir, 'target/node/npm').exists() : "npm was not copied to the node directory";
+
+import org.codehaus.plexus.util.FileUtils;
+
+String buildLog = FileUtils.fileRead(new File(basedir, 'build.log'));
+
+assert buildLog.contains('ENVIRONMENT_VARIABLE_1: 1') : 'environmentVariables not working'
+assert buildLog.contains('BUILD SUCCESS') : 'build was not successful'
diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/AbstractFrontendMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/AbstractFrontendMojo.java
index 2644835bf..10d532541 100644
--- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/AbstractFrontendMojo.java
+++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/AbstractFrontendMojo.java
@@ -1,8 +1,13 @@
package com.github.eirslett.maven.plugins.frontend.mojo;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoFailureException;
@@ -14,6 +19,7 @@
import com.github.eirslett.maven.plugins.frontend.lib.FrontendException;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
+import com.github.eirslett.maven.plugins.frontend.lib.PreExecutionException;
public abstract class AbstractFrontendMojo extends AbstractMojo {
@@ -48,7 +54,17 @@ public abstract class AbstractFrontendMojo extends AbstractMojo {
protected File installDirectory;
/**
- * Additional environment variables to pass to the build.
+ * File containing environment variables to be passed to the build. Environment variables passed via the
+ * {@link AbstractFrontendMojo#environmentVariables} will override the ones present inside the file.
+ *
+ * @since 1.16
+ */
+ @Parameter(property = "environmentFile", required = false)
+ protected File environmentFile;
+
+ /**
+ * Additional environment variables to pass to the build. If used alongside {@link AbstractFrontendMojo#environmentFile} then
+ * environment variables here will override the ones present inside the file.
*/
@Parameter
protected Map environmentVariables;
@@ -107,4 +123,40 @@ public void execute() throws MojoFailureException {
}
}
+ /**
+ * Computes the environment variables based on the configuration provided. It will first evaluate the
+ * {@link AbstractFrontendMojo#environmentFile} configuration and then the {@link AbstractFrontendMojo#environmentVariables}. In case
+ * the latter one contains environment variables also present in the file, they will be overwritten.
+ * In case the {@link AbstractFrontendMojo#environmentFile} configuration is done but the file cannot be found, an error is printed but
+ * the build will still continue!
+ *
+ * @return the aggregated environment variables, may be empty
+ * @throws PreExecutionException when working with the environment file an exception occurs
+ */
+ protected Map getEnvironmentVariables() throws PreExecutionException {
+ Map variables = new HashMap<>();
+
+ if (environmentFile != null) {
+ try (FileInputStream is = new FileInputStream(environmentFile)) {
+ Properties prop = new Properties();
+ prop.load(is);
+
+ for (Object key : prop.keySet()) {
+ variables.put((String) key, prop.getProperty((String) key));
+ }
+ } catch (FileNotFoundException err) {
+ getLog().error("File containing environment variables (configuration 'environmentFile') at '"
+ + environmentFile.getAbsolutePath() + "' could not be found, skipping it.");
+ } catch (IOException err) {
+ throw new PreExecutionException("Trying to read file containing environment variables (configuration 'environmentFile') at '"
+ + environmentFile.getAbsolutePath() + "' failed.", err);
+ }
+ }
+
+ if (environmentVariables != null) {
+ variables.putAll(environmentVariables);
+ }
+
+ return variables;
+ }
}
diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/BowerMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/BowerMojo.java
index 476ad5dee..3d12f3ac7 100644
--- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/BowerMojo.java
+++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/BowerMojo.java
@@ -1,6 +1,7 @@
package com.github.eirslett.maven.plugins.frontend.mojo;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
+import com.github.eirslett.maven.plugins.frontend.lib.PreExecutionException;
import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.execution.MavenSession;
@@ -42,9 +43,9 @@ protected boolean skipExecution() {
}
@Override
- protected synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
+ protected synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException, PreExecutionException {
ProxyConfig proxyConfig = getProxyConfig();
- factory.getBowerRunner(proxyConfig).execute(arguments, environmentVariables);
+ factory.getBowerRunner(proxyConfig).execute(arguments, getEnvironmentVariables());
}
private ProxyConfig getProxyConfig() {
diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/BunMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/BunMojo.java
index 997df3bac..f9a479f14 100644
--- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/BunMojo.java
+++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/BunMojo.java
@@ -1,6 +1,7 @@
package com.github.eirslett.maven.plugins.frontend.mojo;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
+import com.github.eirslett.maven.plugins.frontend.lib.PreExecutionException;
import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.execution.MavenSession;
@@ -56,13 +57,13 @@ protected boolean skipExecution() {
}
@Override
- public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
+ public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException, PreExecutionException {
File packageJson = new File(this.workingDirectory, "package.json");
if (this.buildContext == null || this.buildContext.hasDelta(packageJson)
|| !this.buildContext.isIncremental()) {
ProxyConfig proxyConfig = getProxyConfig();
factory.getBunRunner(proxyConfig, getRegistryUrl()).execute(this.arguments,
- this.environmentVariables);
+ getEnvironmentVariables());
} else {
getLog().info("Skipping bun install as package.json unchanged");
}
diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/EmberMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/EmberMojo.java
index 627083afc..cd5d123a0 100644
--- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/EmberMojo.java
+++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/EmberMojo.java
@@ -1,6 +1,7 @@
package com.github.eirslett.maven.plugins.frontend.mojo;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
+import com.github.eirslett.maven.plugins.frontend.lib.PreExecutionException;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -59,9 +60,9 @@ protected boolean skipExecution() {
}
@Override
- public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
+ public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException, PreExecutionException {
if (shouldExecute()) {
- factory.getEmberRunner().execute(arguments, environmentVariables);
+ factory.getEmberRunner().execute(arguments, getEnvironmentVariables());
if (outputdir != null) {
getLog().info("Refreshing files after ember: " + outputdir);
@@ -81,4 +82,4 @@ private boolean shouldExecute() {
return MojoUtils.shouldExecute(buildContext, triggerfiles, srcdir);
}
-}
\ No newline at end of file
+}
diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/GruntMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/GruntMojo.java
index 9c9f872ef..7d34c66a7 100644
--- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/GruntMojo.java
+++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/GruntMojo.java
@@ -1,6 +1,7 @@
package com.github.eirslett.maven.plugins.frontend.mojo;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
+import com.github.eirslett.maven.plugins.frontend.lib.PreExecutionException;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -59,9 +60,9 @@ protected boolean skipExecution() {
}
@Override
- public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
+ public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException, PreExecutionException {
if (shouldExecute()) {
- factory.getGruntRunner().execute(arguments, environmentVariables);
+ factory.getGruntRunner().execute(arguments, getEnvironmentVariables());
if (outputdir != null) {
getLog().info("Refreshing files after grunt: " + outputdir);
@@ -80,4 +81,4 @@ private boolean shouldExecute() {
return MojoUtils.shouldExecute(buildContext, triggerfiles, srcdir);
}
-}
\ No newline at end of file
+}
diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/GulpMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/GulpMojo.java
index 9fcb7dbb5..15f1f5d1f 100644
--- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/GulpMojo.java
+++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/GulpMojo.java
@@ -1,6 +1,7 @@
package com.github.eirslett.maven.plugins.frontend.mojo;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
+import com.github.eirslett.maven.plugins.frontend.lib.PreExecutionException;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -59,9 +60,9 @@ protected boolean skipExecution() {
}
@Override
- public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
+ public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException, PreExecutionException {
if (shouldExecute()) {
- factory.getGulpRunner().execute(arguments, environmentVariables);
+ factory.getGulpRunner().execute(arguments, getEnvironmentVariables());
if (outputdir != null) {
getLog().info("Refreshing files after gulp: " + outputdir);
diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/JspmMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/JspmMojo.java
index bee398d4c..3a7df692a 100644
--- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/JspmMojo.java
+++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/JspmMojo.java
@@ -1,6 +1,7 @@
package com.github.eirslett.maven.plugins.frontend.mojo;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
+import com.github.eirslett.maven.plugins.frontend.lib.PreExecutionException;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -32,8 +33,8 @@ protected boolean skipExecution() {
}
@Override
- protected synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
- factory.getJspmRunner().execute(arguments, environmentVariables);
+ protected synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException, PreExecutionException {
+ factory.getJspmRunner().execute(arguments, getEnvironmentVariables());
}
}
diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/KarmaRunMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/KarmaRunMojo.java
index 8d460afde..c7a461c23 100644
--- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/KarmaRunMojo.java
+++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/KarmaRunMojo.java
@@ -1,6 +1,7 @@
package com.github.eirslett.maven.plugins.frontend.mojo;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
+import com.github.eirslett.maven.plugins.frontend.lib.PreExecutionException;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@@ -28,7 +29,7 @@ protected boolean skipExecution() {
}
@Override
- public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
- factory.getKarmaRunner().execute("start " + karmaConfPath, environmentVariables);
+ public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException, PreExecutionException {
+ factory.getKarmaRunner().execute("start " + karmaConfPath, getEnvironmentVariables());
}
}
diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/NpmMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/NpmMojo.java
index 4868fc535..c79531075 100644
--- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/NpmMojo.java
+++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/NpmMojo.java
@@ -1,6 +1,7 @@
package com.github.eirslett.maven.plugins.frontend.mojo;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
+import com.github.eirslett.maven.plugins.frontend.lib.PreExecutionException;
import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.execution.MavenSession;
@@ -55,11 +56,11 @@ protected boolean skipExecution() {
}
@Override
- public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
+ public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException, PreExecutionException {
File packageJson = new File(workingDirectory, "package.json");
if (buildContext == null || buildContext.hasDelta(packageJson) || !buildContext.isIncremental()) {
ProxyConfig proxyConfig = getProxyConfig();
- factory.getNpmRunner(proxyConfig, getRegistryUrl()).execute(arguments, environmentVariables);
+ factory.getNpmRunner(proxyConfig, getRegistryUrl()).execute(arguments, getEnvironmentVariables());
} else {
getLog().info("Skipping npm install as package.json unchanged");
}
diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/NpxMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/NpxMojo.java
index c5a3249c9..c24eabe48 100644
--- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/NpxMojo.java
+++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/NpxMojo.java
@@ -1,6 +1,7 @@
package com.github.eirslett.maven.plugins.frontend.mojo;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
+import com.github.eirslett.maven.plugins.frontend.lib.PreExecutionException;
import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.execution.MavenSession;
@@ -55,11 +56,11 @@ protected boolean skipExecution() {
}
@Override
- public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
+ public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException, PreExecutionException {
File packageJson = new File(workingDirectory, "package.json");
if (buildContext == null || buildContext.hasDelta(packageJson) || !buildContext.isIncremental()) {
ProxyConfig proxyConfig = getProxyConfig();
- factory.getNpxRunner(proxyConfig, getRegistryUrl()).execute(arguments, environmentVariables);
+ factory.getNpxRunner(proxyConfig, getRegistryUrl()).execute(arguments, getEnvironmentVariables());
} else {
getLog().info("Skipping npm install as package.json unchanged");
}
diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/PnpmMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/PnpmMojo.java
index 6009168c3..7d5beb2bd 100644
--- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/PnpmMojo.java
+++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/PnpmMojo.java
@@ -1,6 +1,7 @@
package com.github.eirslett.maven.plugins.frontend.mojo;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
+import com.github.eirslett.maven.plugins.frontend.lib.PreExecutionException;
import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.execution.MavenSession;
@@ -55,11 +56,11 @@ protected boolean skipExecution() {
}
@Override
- public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
+ public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException, PreExecutionException {
File packageJson = new File(workingDirectory, "package.json");
if (buildContext == null || buildContext.hasDelta(packageJson) || !buildContext.isIncremental()) {
ProxyConfig proxyConfig = getProxyConfig();
- factory.getPnpmRunner(proxyConfig, getRegistryUrl()).execute(arguments, environmentVariables);
+ factory.getPnpmRunner(proxyConfig, getRegistryUrl()).execute(arguments, getEnvironmentVariables());
} else {
getLog().info("Skipping pnpm install as package.json unchanged");
}
diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/WebpackMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/WebpackMojo.java
index 9e8fb76e4..fd5c520fb 100644
--- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/WebpackMojo.java
+++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/WebpackMojo.java
@@ -1,6 +1,7 @@
package com.github.eirslett.maven.plugins.frontend.mojo;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
+import com.github.eirslett.maven.plugins.frontend.lib.PreExecutionException;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -59,9 +60,9 @@ protected boolean skipExecution() {
}
@Override
- public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
+ public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException, PreExecutionException {
if (shouldExecute()) {
- factory.getWebpackRunner().execute(arguments, environmentVariables);
+ factory.getWebpackRunner().execute(arguments, getEnvironmentVariables());
if (outputdir != null) {
getLog().info("Refreshing files after webpack: " + outputdir);
diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/YarnMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/YarnMojo.java
index dbfc9ff6d..daf84fde3 100644
--- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/YarnMojo.java
+++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/YarnMojo.java
@@ -2,6 +2,7 @@
import static com.github.eirslett.maven.plugins.frontend.mojo.YarnUtils.isYarnrcYamlFilePresent;
+import com.github.eirslett.maven.plugins.frontend.lib.PreExecutionException;
import java.io.File;
import java.util.Collections;
@@ -59,14 +60,14 @@ protected boolean skipExecution() {
}
@Override
- public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
+ public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException, PreExecutionException {
File packageJson = new File(this.workingDirectory, "package.json");
if (this.buildContext == null || this.buildContext.hasDelta(packageJson)
|| !this.buildContext.isIncremental()) {
ProxyConfig proxyConfig = getProxyConfig();
boolean isYarnBerry = isYarnrcYamlFilePresent(this.session, this.workingDirectory);
factory.getYarnRunner(proxyConfig, getRegistryUrl(), isYarnBerry).execute(this.arguments,
- this.environmentVariables);
+ getEnvironmentVariables());
} else {
getLog().info("Skipping yarn install as package.json unchanged");
}
diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/PreExecutionException.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/PreExecutionException.java
new file mode 100644
index 000000000..c612a0bd9
--- /dev/null
+++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/PreExecutionException.java
@@ -0,0 +1,11 @@
+package com.github.eirslett.maven.plugins.frontend.lib;
+
+public class PreExecutionException extends FrontendException {
+ public PreExecutionException(String message) {
+ super(message);
+ }
+
+ public PreExecutionException(String message, Throwable cause){
+ super(message, cause);
+ }
+}