From a121e7c95ca06cce1cffcd245ccdb2076e83ebb3 Mon Sep 17 00:00:00 2001 From: Stefano Vetrini Date: Wed, 11 Jan 2017 16:35:49 +0100 Subject: [PATCH 1/3] Fix #552: added maven.frontend.failOnError property and moved maven.test.failure.ignore property from KarmaRunMojo to AbstractFrontendMojo to manage integration-test phases updated README.md and CHANGELOG.md --- CHANGELOG.md | 4 ++ README.md | 28 ++++++++++- frontend-maven-plugin/pom.xml | 5 ++ .../src/it/example project/package.json | 3 ++ .../src/it/example project/pom.xml | 45 ++++++++++++++++++ .../src/it/example project/verify.groovy | 2 + .../src/it/yarn-integration/verify.groovy | 1 - .../frontend/mojo/AbstractFrontendMojo.java | 46 ++++++++++++++++--- .../plugins/frontend/mojo/KarmaRunMojo.java | 20 +------- 9 files changed, 126 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eaa32ff4c..b9b63fe67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Changelog +### 1.4 + +* Add maven.frontend.failOnError and maven.test.failure.ignore flags to best manage integration-test + ### 1.3 * Fix `yarn` for Windows diff --git a/README.md b/README.md index abf874ffe..b7b274af9 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Include the plugin as a dependency in your Maven project. Change `LATEST_VERSION ## Usage -Have a look at the [example project](https://github.com/eirslett/frontend-maven-plugin/tree/master/frontend-maven-plugin/src/it/example%20project), +Have a look at the [example project](frontend-maven-plugin/src/it/example%20project), to see how it should be set up: https://github.com/eirslett/frontend-maven-plugin/blob/master/frontend-maven-plugin/src/it/example%20project/pom.xml - [Installing node and npm](#installing-node-and-npm) @@ -71,6 +71,7 @@ to see how it should be set up: https://github.com/eirslett/frontend-maven-plugi - [Installation Directory](#installation-directory) - [Proxy Settings](#proxy-settings) - [Environment variables](#environment-variables) + - [Ignoring Failure](#ignoring-failure) - [Skipping Execution](#skipping-execution) **Recommendation:** _Try to run all your tasks via npm scripts instead of running bower, grunt, gulp etc. directly._ @@ -191,6 +192,7 @@ By default, colors will be shown in the log. **Notice:** _Remember to gitignore the `node_modules` folder, unless you actually want to commit it. Npm packages will always be installed in `node_modules` next to your `package.json`, which is default npm behavior._ + ### Running yarn As with npm above, all node packaged modules will be installed in the `node_modules` folder in your [working directory](#working-directory). @@ -445,6 +447,28 @@ tag of an execution like this: ``` +#### Ignoring Failure + +**Ignoring failed tests:** If you want to ignore test failures in specific execution you can set that using the property `maven.test.failure.ignore` in configuration tag of an execution like this: + +```xml + + true + +``` + +If you want to generally ignore tests run maven with the `-Dmaven.test.failure.ignore=true` flag, test/integration-test results will not stop the build. + +**Ignoring other failures:** If you need to ignore other failures you can set that using the property `maven.frontend.failOnError` in configuration tag of an execution like this: + +```xml + + true + +``` + +If you want to ignore all failures run maven with the `-Dmaven.frontend.failOnError=true` flag. + #### Skipping Execution Each frontend build tool and package manager allows skipping execution. @@ -476,7 +500,7 @@ these are set they check for changes in your source files before being run. See ## Helper scripts During development, it's convenient to have the "npm", "bower", "grunt", "gulp" and "karma" commands -available on the command line. If you want that, use [those helper scripts](https://github.com/eirslett/frontend-maven-plugin/tree/master/frontend-maven-plugin/src/it/example%20project/helper-scripts)! +available on the command line. If you want that, use [those helper scripts](frontend-maven-plugin/src/it/example%20project/helper-scripts)! ## To build this project: diff --git a/frontend-maven-plugin/pom.xml b/frontend-maven-plugin/pom.xml index 5c232f283..2da3bc94a 100644 --- a/frontend-maven-plugin/pom.xml +++ b/frontend-maven-plugin/pom.xml @@ -121,6 +121,11 @@ run verify + + + verify + + diff --git a/frontend-maven-plugin/src/it/example project/package.json b/frontend-maven-plugin/src/it/example project/package.json index eb72a1dd5..79d1e4491 100644 --- a/frontend-maven-plugin/src/it/example project/package.json +++ b/frontend-maven-plugin/src/it/example project/package.json @@ -26,6 +26,9 @@ }, "scripts": { "prebuild": "npm install", + "pre-test": "echo pre-integration-test-success", + "test": "return 1", + "post-test": "echo post-integration-test-success", "build": "gulp" } } diff --git a/frontend-maven-plugin/src/it/example project/pom.xml b/frontend-maven-plugin/src/it/example project/pom.xml index e281197a5..68c43f51e 100644 --- a/frontend-maven-plugin/src/it/example project/pom.xml +++ b/frontend-maven-plugin/src/it/example project/pom.xml @@ -103,6 +103,51 @@ + + + npm-pre-integration-test + + npm + + + run pre-test + + pre-integration-test + + + npm-integration-test-failSafeTest + + npm + + + run test + true + + integration-test + + + npm-integration-test-failOnError + + npm + + + run test + false + + integration-test + + + npm-post-integration-test + + npm + + + run post-test + true + + post-integration-test + + diff --git a/frontend-maven-plugin/src/it/example project/verify.groovy b/frontend-maven-plugin/src/it/example project/verify.groovy index a36508ecb..5a4124f25 100644 --- a/frontend-maven-plugin/src/it/example project/verify.groovy +++ b/frontend-maven-plugin/src/it/example project/verify.groovy @@ -6,4 +6,6 @@ assert buildLog.contains('gulp runs as expected') : 'gulp failed to run as expec assert buildLog.contains('Running against local jspm install.') : 'jspm failed to run as expected' assert buildLog.contains('5 files lint free.') : 'grunt failed to run as expected' assert buildLog.contains('Executed 1 of 1 SUCCESS') : 'karma failed to run as expected' +assert buildLog.contains('post-integration-test-success') : 'failOnError does not works as expected' +assert buildLog.contains('testFailureIgnore property is ignored in non test phases') : 'testFailureIgnore does not works as expected' assert buildLog.contains('BUILD SUCCESS') : 'build was not successful' \ No newline at end of file diff --git a/frontend-maven-plugin/src/it/yarn-integration/verify.groovy b/frontend-maven-plugin/src/it/yarn-integration/verify.groovy index 35bef4389..2b1e0ed01 100644 --- a/frontend-maven-plugin/src/it/yarn-integration/verify.groovy +++ b/frontend-maven-plugin/src/it/yarn-integration/verify.groovy @@ -5,5 +5,4 @@ assert new File(basedir, 'node_modules/less/package.json').exists() : "Less depe import org.codehaus.plexus.util.FileUtils; String buildLog = FileUtils.fileRead(new File(basedir, 'build.log')); - 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 475cca294..69a914d8f 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,8 @@ package com.github.eirslett.maven.plugins.frontend.mojo; -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 java.io.File; +import java.util.Map; + import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoFailureException; @@ -12,8 +12,9 @@ import org.eclipse.aether.RepositorySystemSession; import org.slf4j.LoggerFactory; -import java.io.File; -import java.util.Map; +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; public abstract class AbstractFrontendMojo extends AbstractMojo { @@ -26,6 +27,21 @@ public abstract class AbstractFrontendMojo extends AbstractMojo { @Parameter(property = "skipTests", required = false, defaultValue = "false") protected Boolean skipTests; + /** + * Specifies if the build will fail if there are errors during a frontend execution or not. + * + * @parameter property="maven.frontend.failOnError" default-value="true" + * @since 1.4 + */ + @Parameter(property = "maven.frontend.failOnError", required = false, defaultValue = "true") + protected boolean failOnError; + + /** + * Whether you should continue build when some test will fail (default is false) + */ + @Parameter(property = "maven.test.failure.ignore", required = false, defaultValue = "false") + protected boolean testFailureIgnore; + /** * The base directory for running all Node commands. (Usually the directory that contains package.json) */ @@ -81,6 +97,9 @@ private boolean isTestingPhase() { @Override public void execute() throws MojoFailureException { + if (testFailureIgnore && !isTestingPhase()){ + LoggerFactory.getLogger(AbstractFrontendMojo.class).warn("testFailureIgnore property is ignored in non test phases"); + } if (!(skipTestPhase() || skipExecution())) { if (installDirectory == null) { installDirectory = workingDirectory; @@ -92,7 +111,7 @@ public void execute() throws MojoFailureException { new RepositoryCacheResolver(repositorySystemSession) )); } catch (TaskRunnerException e) { - throw new MojoFailureException("Failed to run task", e); + failOnError( "Failed to run task", e ); } catch (FrontendException e) { throw MojoUtils.toMojoFailureException(e); } @@ -100,4 +119,19 @@ public void execute() throws MojoFailureException { LoggerFactory.getLogger(AbstractFrontendMojo.class).info("Skipping test phase."); } } + + protected void failOnError(String prefix, Exception e) throws MojoFailureException { + if (!failOnError || (testFailureIgnore && isTestingPhase()) ){ + if ((testFailureIgnore && isTestingPhase())){ + LoggerFactory.getLogger(AbstractFrontendMojo.class) + .warn("There are ignored test failures/errors for: " + workingDirectory); + } + LoggerFactory.getLogger(AbstractFrontendMojo.class).error(prefix + ": " + e.getMessage(), e); + }else { + if (e instanceof RuntimeException) { + throw (RuntimeException) e; + } + throw new MojoFailureException(prefix + ": " + e.getMessage(), e); + } + } } 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 d4c37d9bd..10c8df880 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 @@ -5,7 +5,6 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import org.slf4j.LoggerFactory; @Mojo(name="karma", defaultPhase = LifecyclePhase.TEST) @@ -17,12 +16,6 @@ public final class KarmaRunMojo extends AbstractFrontendMojo { @Parameter(defaultValue = "karma.conf.js", property = "karmaConfPath") private String karmaConfPath; - /** - * Whether you should continue build when some test will fail (default is false) - */ - @Parameter(property = "maven.test.failure.ignore", required = false, defaultValue = "false") - private Boolean testFailureIgnore; - /** * Skips execution of this mojo. */ @@ -36,17 +29,6 @@ protected boolean skipExecution() { @Override public void execute(FrontendPluginFactory factory) throws TaskRunnerException { - try { - factory.getKarmaRunner().execute("start " + karmaConfPath, environmentVariables); - } - catch (TaskRunnerException e) { - if (testFailureIgnore) { - LoggerFactory.getLogger(KarmaRunMojo.class) - .warn("There are ignored test failures/errors for: " + workingDirectory); - } - else { - throw e; - } - } + factory.getKarmaRunner().execute("start " + karmaConfPath, environmentVariables); } } From 4a8ff2ac53e4975a7458f8e93197b9fe24441756 Mon Sep 17 00:00:00 2001 From: Julien Carsique Date: Mon, 20 Feb 2017 16:17:48 +0100 Subject: [PATCH 2/3] format --- .gitignore | 1 + frontend-maven-plugin/pom.xml | 271 ++++++++--------- .../src/it/example project/package.json | 6 +- .../src/it/example project/pom.xml | 283 +++++++++--------- .../frontend/mojo/AbstractFrontendMojo.java | 221 +++++++------- 5 files changed, 389 insertions(+), 393 deletions(-) diff --git a/.gitignore b/.gitignore index 98723f799..71867a0fa 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ target .project .metadata .recommenders +bin diff --git a/frontend-maven-plugin/pom.xml b/frontend-maven-plugin/pom.xml index 2da3bc94a..b407f1fe3 100644 --- a/frontend-maven-plugin/pom.xml +++ b/frontend-maven-plugin/pom.xml @@ -1,154 +1,157 @@ - - 4.0.0 - - frontend-plugins - com.github.eirslett - 1.4-SNAPSHOT - + + 4.0.0 + + frontend-plugins + com.github.eirslett + 1.4-SNAPSHOT + - frontend-maven-plugin - maven-plugin + frontend-maven-plugin + maven-plugin - Maven Frontend Plugin - - 3.1.0 - + Maven Frontend Plugin + + 3.1.0 + - + This Maven plugin lets you install Node/NPM locally for your project, install dependencies with NPM, install dependencies with bower or jspm, run Grunt or gulp tasks, and/or run Karma tests. - - - com.github.eirslett - frontend-plugin-core - ${project.parent.version} - + + + com.github.eirslett + frontend-plugin-core + ${project.parent.version} + - - org.apache.maven - maven-core - 3.1.0 - provided - + + org.apache.maven + maven-core + 3.1.0 + provided + - - org.apache.maven - maven-plugin-api - 3.1.0 - + + org.apache.maven + maven-plugin-api + 3.1.0 + - - org.apache.maven.plugin-tools - maven-plugin-annotations - 3.2 - + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.2 + - - org.sonatype.plexus - plexus-build-api - 0.0.7 - - + + org.sonatype.plexus + plexus-build-api + 0.0.7 + + - - - - org.apache.maven.plugins - maven-plugin-plugin - 3.2 - - true - - - - mojo-descriptor - process-classes - - descriptor - - - frontend - - - - + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.2 + + true + + + + mojo-descriptor + process-classes + + descriptor + + + frontend + + + + - - - org.codehaus.mojo - mrm-maven-plugin - 1.0-beta-2 - - - - start - stop - - - - - repository.proxy.url - - - - org.apache.maven.plugins - maven-invoker-plugin - 2.0.0 + + + org.codehaus.mojo + mrm-maven-plugin + 1.0-beta-2 + + + + start + stop + + + + + repository.proxy.url + + + + org.apache.maven.plugins + maven-invoker-plugin + 2.0.0 - - true - src/it - ${project.build.directory}/it - src/it/settings.xml - ${project.build.directory}/local-repo - true - verify - - ${repository.proxy.url} - - + + true + src/it + ${project.build.directory}/it + src/it/settings.xml + ${project.build.directory}/local-repo + true + verify + + ${repository.proxy.url} + + - - - integration-test - - install - run - verify - - - - verify - - - - - - - + + + integration-test + + install + run + verify + + + + verify + + + + + + + - - - Skip tests - - skipTests - - - - - org.apache.maven.plugins - maven-invoker-plugin - - true - - - - - - + + + Skip tests + + + skipTests + + + + + + org.apache.maven.plugins + maven-invoker-plugin + + true + + + + + + diff --git a/frontend-maven-plugin/src/it/example project/package.json b/frontend-maven-plugin/src/it/example project/package.json index 79d1e4491..dd59b6571 100644 --- a/frontend-maven-plugin/src/it/example project/package.json +++ b/frontend-maven-plugin/src/it/example project/package.json @@ -26,9 +26,9 @@ }, "scripts": { "prebuild": "npm install", - "pre-test": "echo pre-integration-test-success", - "test": "return 1", - "post-test": "echo post-integration-test-success", + "pre-test": "echo pre-integration-test-success", + "test": "return 1", + "post-test": "echo post-integration-test-success", "build": "gulp" } } diff --git a/frontend-maven-plugin/src/it/example project/pom.xml b/frontend-maven-plugin/src/it/example project/pom.xml index 68c43f51e..efbe48237 100644 --- a/frontend-maven-plugin/src/it/example project/pom.xml +++ b/frontend-maven-plugin/src/it/example project/pom.xml @@ -1,155 +1,156 @@ - - 4.0.0 + + 4.0.0 - com.github.eirslett - example - 0 - pom + com.github.eirslett + example + 0 + pom - - - - com.github.eirslett - frontend-maven-plugin - - @project.version@ + + + + com.github.eirslett + frontend-maven-plugin + + @project.version@ - + - - install node and npm - - install-node-and-npm - - - - v4.6.0 - 2.15.9 - - + + install node and npm + + install-node-and-npm + + + + v4.6.0 + 2.15.9 + + - - npm install - - npm - - - - install - - + + npm install + + npm + + + + install + + - - npm run build - - npm - - - run build - - - - - bower install - - bower - - - install - - + + npm run build + + npm + + + run build + + - - jspm install - - jspm - - - --version - - + + bower install + + bower + + + install + + - - grunt build - - grunt - - - --no-color - - + + jspm install + + jspm + + + --version + + - - gulp build - generate-resources - - gulp - - - - production - - - + + grunt build + + grunt + + + --no-color + + - - javascript tests - - karma - - - src/test/javascript/karma.conf.ci.js - - + + gulp build + generate-resources + + gulp + + + + production + + + - - - npm-pre-integration-test - - npm - - - run pre-test - - pre-integration-test - - - npm-integration-test-failSafeTest - - npm - - - run test - true - - integration-test - - - npm-integration-test-failOnError - - npm - - - run test - false - - integration-test - - - npm-post-integration-test - - npm - - - run post-test - true - - post-integration-test - + + javascript tests + + karma + + + src/test/javascript/karma.conf.ci.js + + - - - - + + + npm-pre-integration-test + + npm + + + run pre-test + + pre-integration-test + + + npm-integration-test-failSafeTest + + npm + + + run test + true + + integration-test + + + npm-integration-test-failOnError + + npm + + + run test + false + + integration-test + + + npm-post-integration-test + + npm + + + run post-test + true + + post-integration-test + + + + + + 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 69a914d8f..556ff1567 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 @@ -18,120 +18,111 @@ public abstract class AbstractFrontendMojo extends AbstractMojo { - @Component - protected MojoExecution execution; - - /** - * Whether you should skip while running in the test phase (default is false) - */ - @Parameter(property = "skipTests", required = false, defaultValue = "false") - protected Boolean skipTests; - - /** - * Specifies if the build will fail if there are errors during a frontend execution or not. - * - * @parameter property="maven.frontend.failOnError" default-value="true" - * @since 1.4 - */ - @Parameter(property = "maven.frontend.failOnError", required = false, defaultValue = "true") - protected boolean failOnError; - - /** - * Whether you should continue build when some test will fail (default is false) - */ - @Parameter(property = "maven.test.failure.ignore", required = false, defaultValue = "false") - protected boolean testFailureIgnore; - - /** - * The base directory for running all Node commands. (Usually the directory that contains package.json) - */ - @Parameter(defaultValue = "${basedir}", property = "workingDirectory", required = false) - protected File workingDirectory; - - /** - * The base directory for installing node and npm. - */ - @Parameter(property = "installDirectory", required = false) - protected File installDirectory; - - - /** - * Additional environment variables to pass to the build. - */ - @Parameter - protected Map environmentVariables; - - @Parameter( - defaultValue = "${project}", - readonly = true - ) - private MavenProject project; - - @Parameter( - defaultValue = "${repositorySystemSession}", - readonly = true - ) - private RepositorySystemSession repositorySystemSession; - - /** - * Determines if this execution should be skipped. - */ - private boolean skipTestPhase() { - return skipTests && isTestingPhase(); - } - - /** - * Determines if the current execution is during a testing phase (e.g., "test" or "integration-test"). - */ - private boolean isTestingPhase() { - String phase = execution.getLifecyclePhase(); - return phase!=null && (phase.equals("test") || phase.equals("integration-test")); - } - - protected abstract void execute(FrontendPluginFactory factory) throws FrontendException; - - /** - * Implemented by children to determine if this execution should be skipped. - */ - protected abstract boolean skipExecution(); - - @Override - public void execute() throws MojoFailureException { - if (testFailureIgnore && !isTestingPhase()){ - LoggerFactory.getLogger(AbstractFrontendMojo.class).warn("testFailureIgnore property is ignored in non test phases"); - } - if (!(skipTestPhase() || skipExecution())) { - if (installDirectory == null) { - installDirectory = workingDirectory; - } - try { - execute(new FrontendPluginFactory( - workingDirectory, - installDirectory, - new RepositoryCacheResolver(repositorySystemSession) - )); - } catch (TaskRunnerException e) { - failOnError( "Failed to run task", e ); - } catch (FrontendException e) { - throw MojoUtils.toMojoFailureException(e); - } - } else { - LoggerFactory.getLogger(AbstractFrontendMojo.class).info("Skipping test phase."); + @Component + protected MojoExecution execution; + + /** + * Whether you should skip while running in the test phase (default is false) + */ + @Parameter(property = "skipTests", required = false, defaultValue = "false") + protected Boolean skipTests; + + /** + * Specifies if the build will fail if there are errors during a frontend execution or not. + * + * @parameter property="maven.frontend.failOnError" default-value="true" + * @since 1.4 + */ + @Parameter(property = "maven.frontend.failOnError", required = false, defaultValue = "true") + protected boolean failOnError; + + /** + * Whether you should continue build when some test will fail (default is false) + */ + @Parameter(property = "maven.test.failure.ignore", required = false, defaultValue = "false") + protected boolean testFailureIgnore; + + /** + * The base directory for running all Node commands. (Usually the directory that contains package.json) + */ + @Parameter(defaultValue = "${basedir}", property = "workingDirectory", required = false) + protected File workingDirectory; + + /** + * The base directory for installing node and npm. + */ + @Parameter(property = "installDirectory", required = false) + protected File installDirectory; + + /** + * Additional environment variables to pass to the build. + */ + @Parameter + protected Map environmentVariables; + + @Parameter(defaultValue = "${project}", readonly = true) + private MavenProject project; + + @Parameter(defaultValue = "${repositorySystemSession}", readonly = true) + private RepositorySystemSession repositorySystemSession; + + /** + * Determines if this execution should be skipped. + */ + private boolean skipTestPhase() { + return skipTests && isTestingPhase(); + } + + /** + * Determines if the current execution is during a testing phase (e.g., "test" or "integration-test"). + */ + private boolean isTestingPhase() { + String phase = execution.getLifecyclePhase(); + return phase != null && (phase.equals("test") || phase.equals("integration-test")); + } + + protected abstract void execute(FrontendPluginFactory factory) throws FrontendException; + + /** + * Implemented by children to determine if this execution should be skipped. + */ + protected abstract boolean skipExecution(); + + @Override + public void execute() throws MojoFailureException { + if (testFailureIgnore && !isTestingPhase()) { + LoggerFactory.getLogger(AbstractFrontendMojo.class) + .warn("testFailureIgnore property is ignored in non test phases"); + } + if (!(skipTestPhase() || skipExecution())) { + if (installDirectory == null) { + installDirectory = workingDirectory; + } + try { + execute(new FrontendPluginFactory(workingDirectory, installDirectory, + new RepositoryCacheResolver(repositorySystemSession))); + } catch (TaskRunnerException e) { + failOnError("Failed to run task", e); + } catch (FrontendException e) { + throw MojoUtils.toMojoFailureException(e); + } + } else { + LoggerFactory.getLogger(AbstractFrontendMojo.class).info("Skipping test phase."); + } + } + + protected void failOnError(String prefix, Exception e) throws MojoFailureException { + if (!failOnError || (testFailureIgnore && isTestingPhase())) { + if ((testFailureIgnore && isTestingPhase())) { + LoggerFactory.getLogger(AbstractFrontendMojo.class) + .warn("There are ignored test failures/errors for: " + workingDirectory); + } + LoggerFactory.getLogger(AbstractFrontendMojo.class).error(prefix + ": " + e.getMessage(), e); + } else { + if (e instanceof RuntimeException) { + throw (RuntimeException) e; + } + throw new MojoFailureException(prefix + ": " + e.getMessage(), e); + } } - } - - protected void failOnError(String prefix, Exception e) throws MojoFailureException { - if (!failOnError || (testFailureIgnore && isTestingPhase()) ){ - if ((testFailureIgnore && isTestingPhase())){ - LoggerFactory.getLogger(AbstractFrontendMojo.class) - .warn("There are ignored test failures/errors for: " + workingDirectory); - } - LoggerFactory.getLogger(AbstractFrontendMojo.class).error(prefix + ": " + e.getMessage(), e); - }else { - if (e instanceof RuntimeException) { - throw (RuntimeException) e; - } - throw new MojoFailureException(prefix + ": " + e.getMessage(), e); - } - } } From 39bcb48ea6e248776bdd9fc189406ba690739257 Mon Sep 17 00:00:00 2001 From: Julien Carsique Date: Mon, 20 Feb 2017 16:37:20 +0100 Subject: [PATCH 3/3] Fix #552: review PR #553, add failOnError and maven.test.failure.ignore properties fix integration-test eval failOnError depending on the property set and isTestingPhase() --- frontend-maven-plugin/pom.xml | 5 -- .../src/it/example project/invoker.properties | 1 + .../frontend/mojo/AbstractFrontendMojo.java | 61 ++++++++++--------- 3 files changed, 33 insertions(+), 34 deletions(-) create mode 100644 frontend-maven-plugin/src/it/example project/invoker.properties diff --git a/frontend-maven-plugin/pom.xml b/frontend-maven-plugin/pom.xml index b407f1fe3..fb229d200 100644 --- a/frontend-maven-plugin/pom.xml +++ b/frontend-maven-plugin/pom.xml @@ -122,11 +122,6 @@ run verify - - - verify - - diff --git a/frontend-maven-plugin/src/it/example project/invoker.properties b/frontend-maven-plugin/src/it/example project/invoker.properties new file mode 100644 index 000000000..e2a44e3c0 --- /dev/null +++ b/frontend-maven-plugin/src/it/example project/invoker.properties @@ -0,0 +1 @@ +invoker.goals = clean verify 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 556ff1567..e02c0bfda 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 @@ -10,7 +10,6 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.eclipse.aether.RepositorySystemSession; -import org.slf4j.LoggerFactory; import com.github.eirslett.maven.plugins.frontend.lib.FrontendException; import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory; @@ -28,18 +27,12 @@ public abstract class AbstractFrontendMojo extends AbstractMojo { protected Boolean skipTests; /** - * Specifies if the build will fail if there are errors during a frontend execution or not. + * Set this to true to ignore a failure during testing. Its use is NOT RECOMMENDED, but quite convenient on + * occasion. * - * @parameter property="maven.frontend.failOnError" default-value="true" * @since 1.4 */ - @Parameter(property = "maven.frontend.failOnError", required = false, defaultValue = "true") - protected boolean failOnError; - - /** - * Whether you should continue build when some test will fail (default is false) - */ - @Parameter(property = "maven.test.failure.ignore", required = false, defaultValue = "false") + @Parameter(property = "maven.test.failure.ignore", defaultValue = "false") protected boolean testFailureIgnore; /** @@ -78,7 +71,7 @@ private boolean skipTestPhase() { */ private boolean isTestingPhase() { String phase = execution.getLifecyclePhase(); - return phase != null && (phase.equals("test") || phase.equals("integration-test")); + return "test".equals(phase) || "integration-test".equals(phase); } protected abstract void execute(FrontendPluginFactory factory) throws FrontendException; @@ -88,11 +81,31 @@ private boolean isTestingPhase() { */ protected abstract boolean skipExecution(); + /** + * Whether to raise an error or a failure if the execution fails. If unset, execution will fail if not in a testing + * phase. + * + * @since 1.4 + * @see #isTestingPhase() + */ + @Parameter(property = "failOnError") + protected Boolean failOnError; + + /** + * @since 1.4 + * @see #failOnError + */ + protected boolean isFailOnError() { + if (failOnError == null) { + failOnError = !isTestingPhase(); + } + return failOnError; + } + @Override public void execute() throws MojoFailureException { if (testFailureIgnore && !isTestingPhase()) { - LoggerFactory.getLogger(AbstractFrontendMojo.class) - .warn("testFailureIgnore property is ignored in non test phases"); + getLog().info("testFailureIgnore property is ignored in non test phases"); } if (!(skipTestPhase() || skipExecution())) { if (installDirectory == null) { @@ -102,27 +115,17 @@ public void execute() throws MojoFailureException { execute(new FrontendPluginFactory(workingDirectory, installDirectory, new RepositoryCacheResolver(repositorySystemSession))); } catch (TaskRunnerException e) { - failOnError("Failed to run task", e); + if (!isFailOnError() || testFailureIgnore && isTestingPhase()) { + getLog().error("There are test failures.\nFailed to run task: " + e.getMessage(), e); + } else { + throw new MojoFailureException("Failed to run task", e); + } } catch (FrontendException e) { throw MojoUtils.toMojoFailureException(e); } } else { - LoggerFactory.getLogger(AbstractFrontendMojo.class).info("Skipping test phase."); + getLog().info("Skipping execution."); } } - protected void failOnError(String prefix, Exception e) throws MojoFailureException { - if (!failOnError || (testFailureIgnore && isTestingPhase())) { - if ((testFailureIgnore && isTestingPhase())) { - LoggerFactory.getLogger(AbstractFrontendMojo.class) - .warn("There are ignored test failures/errors for: " + workingDirectory); - } - LoggerFactory.getLogger(AbstractFrontendMojo.class).error(prefix + ": " + e.getMessage(), e); - } else { - if (e instanceof RuntimeException) { - throw (RuntimeException) e; - } - throw new MojoFailureException(prefix + ": " + e.getMessage(), e); - } - } }