From 81e390dd580d242810778388a3ca92b4aa3638dc Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Thu, 19 May 2022 18:12:26 +0200 Subject: [PATCH] [MINVOKER-288] Failed setup job cause skip rest of jobs --- .../invoker.properties | 18 +++++ src/it/MINVOKER-288-failed-setup-run/pom.xml | 68 ++++++++++++++++++ .../src/it/project1/pom.xml | 34 +++++++++ .../src/it/project2/pom.xml | 32 +++++++++ .../verify.groovy | 40 +++++++++++ .../invoker.properties | 18 +++++ .../MINVOKER-288-failed-setup-verify/pom.xml | 69 +++++++++++++++++++ .../src/it/project1/pom.xml | 34 +++++++++ .../src/it/project2/pom.xml | 32 +++++++++ .../verify.groovy | 40 +++++++++++ .../plugins/invoker/AbstractInvokerMojo.java | 27 +++++--- src/main/mdo/invocation.mdo | 5 ++ 12 files changed, 409 insertions(+), 8 deletions(-) create mode 100644 src/it/MINVOKER-288-failed-setup-run/invoker.properties create mode 100644 src/it/MINVOKER-288-failed-setup-run/pom.xml create mode 100644 src/it/MINVOKER-288-failed-setup-run/src/it/project1/pom.xml create mode 100644 src/it/MINVOKER-288-failed-setup-run/src/it/project2/pom.xml create mode 100644 src/it/MINVOKER-288-failed-setup-run/verify.groovy create mode 100644 src/it/MINVOKER-288-failed-setup-verify/invoker.properties create mode 100644 src/it/MINVOKER-288-failed-setup-verify/pom.xml create mode 100644 src/it/MINVOKER-288-failed-setup-verify/src/it/project1/pom.xml create mode 100644 src/it/MINVOKER-288-failed-setup-verify/src/it/project2/pom.xml create mode 100644 src/it/MINVOKER-288-failed-setup-verify/verify.groovy diff --git a/src/it/MINVOKER-288-failed-setup-run/invoker.properties b/src/it/MINVOKER-288-failed-setup-run/invoker.properties new file mode 100644 index 00000000..e64d99e0 --- /dev/null +++ b/src/it/MINVOKER-288-failed-setup-run/invoker.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.buildResult = failure diff --git a/src/it/MINVOKER-288-failed-setup-run/pom.xml b/src/it/MINVOKER-288-failed-setup-run/pom.xml new file mode 100644 index 00000000..af7aec20 --- /dev/null +++ b/src/it/MINVOKER-288-failed-setup-run/pom.xml @@ -0,0 +1,68 @@ + + + + + + 4.0.0 + + org.apache.maven.plugins.invoker + project-setup + 1.0-SNAPSHOT + pom + + Test to check that failed setup projects stop executing other projects. + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-invoker-plugin + @pom.version@ + + ${project.build.directory}/it + true + + project1 + + + */pom.xml + + + validate + + + + + integration-test + initialize + + run + + + + + + + + diff --git a/src/it/MINVOKER-288-failed-setup-run/src/it/project1/pom.xml b/src/it/MINVOKER-288-failed-setup-run/src/it/project1/pom.xml new file mode 100644 index 00000000..678a5349 --- /dev/null +++ b/src/it/MINVOKER-288-failed-setup-run/src/it/project1/pom.xml @@ -0,0 +1,34 @@ + + + + + + 4.0.0 + test + project1 + 0.1-SNAPSHOT + pom + + + UTF-8 + + + + diff --git a/src/it/MINVOKER-288-failed-setup-run/src/it/project2/pom.xml b/src/it/MINVOKER-288-failed-setup-run/src/it/project2/pom.xml new file mode 100644 index 00000000..a747a1ee --- /dev/null +++ b/src/it/MINVOKER-288-failed-setup-run/src/it/project2/pom.xml @@ -0,0 +1,32 @@ + + + + + + 4.0.0 + test + project2 + 0.1-SNAPSHOT + pom + + + UTF-8 + + diff --git a/src/it/MINVOKER-288-failed-setup-run/verify.groovy b/src/it/MINVOKER-288-failed-setup-run/verify.groovy new file mode 100644 index 00000000..92bed15a --- /dev/null +++ b/src/it/MINVOKER-288-failed-setup-run/verify.groovy @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * 'License'); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +File invokerReports = new File( new File(basedir, 'target'), 'invoker-reports' ) +assert invokerReports.exists() + +def build1 = new XmlSlurper().parse( new File( invokerReports, 'BUILD-project1.xml' ) ) + +assert build1.@result.text() == 'failure-build' +assert build1.@type.text() == 'setup' + +def build2 = new XmlSlurper().parse( new File( invokerReports, 'BUILD-project2.xml' ) ) + +assert build2.@result.text() == 'skipped' +assert build2.failureMessage.text() == 'Skipped due to setup job(s) failure' + +def testsuite = new XmlSlurper().parse( new File( invokerReports, 'TEST-project2.xml' ) ) + +assert testsuite.@skipped.text() == '1' +assert testsuite.testcase.skipped.text() == 'Skipped due to setup job(s) failure' + +def buildLog = new File( basedir, 'build.log' ).text +assert buildLog.contains('[INFO] Passed: 0, Failed: 1, Errors: 0, Skipped: 1') diff --git a/src/it/MINVOKER-288-failed-setup-verify/invoker.properties b/src/it/MINVOKER-288-failed-setup-verify/invoker.properties new file mode 100644 index 00000000..e64d99e0 --- /dev/null +++ b/src/it/MINVOKER-288-failed-setup-verify/invoker.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.buildResult = failure diff --git a/src/it/MINVOKER-288-failed-setup-verify/pom.xml b/src/it/MINVOKER-288-failed-setup-verify/pom.xml new file mode 100644 index 00000000..b1822dd1 --- /dev/null +++ b/src/it/MINVOKER-288-failed-setup-verify/pom.xml @@ -0,0 +1,69 @@ + + + + + + 4.0.0 + + org.apache.maven.plugins.invoker + project-setup + 1.0-SNAPSHOT + pom + + Test to check that failed setup projects stop executing other projects. + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-invoker-plugin + @pom.version@ + + ${project.build.directory}/it + true + + project1 + + + */pom.xml + + + validate + + + + + integration-test + initialize + + integration-test + verify + + + + + + + + diff --git a/src/it/MINVOKER-288-failed-setup-verify/src/it/project1/pom.xml b/src/it/MINVOKER-288-failed-setup-verify/src/it/project1/pom.xml new file mode 100644 index 00000000..678a5349 --- /dev/null +++ b/src/it/MINVOKER-288-failed-setup-verify/src/it/project1/pom.xml @@ -0,0 +1,34 @@ + + + + + + 4.0.0 + test + project1 + 0.1-SNAPSHOT + pom + + + UTF-8 + + + + diff --git a/src/it/MINVOKER-288-failed-setup-verify/src/it/project2/pom.xml b/src/it/MINVOKER-288-failed-setup-verify/src/it/project2/pom.xml new file mode 100644 index 00000000..a747a1ee --- /dev/null +++ b/src/it/MINVOKER-288-failed-setup-verify/src/it/project2/pom.xml @@ -0,0 +1,32 @@ + + + + + + 4.0.0 + test + project2 + 0.1-SNAPSHOT + pom + + + UTF-8 + + diff --git a/src/it/MINVOKER-288-failed-setup-verify/verify.groovy b/src/it/MINVOKER-288-failed-setup-verify/verify.groovy new file mode 100644 index 00000000..450fd574 --- /dev/null +++ b/src/it/MINVOKER-288-failed-setup-verify/verify.groovy @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +File invokerReports = new File( new File(basedir, "target"), 'invoker-reports' ) +assert invokerReports.exists() + +def build1 = new XmlSlurper().parse( new File( invokerReports, "BUILD-project1.xml" ) ) + +assert build1.@result.text() == "failure-build" +assert build1.@type.text() == "setup" + +def build2 = new XmlSlurper().parse( new File( invokerReports, "BUILD-project2.xml" ) ) + +assert build2.@result.text() == "skipped" +assert build2.failureMessage.text() == "Skipped due to setup job(s) failure" + +def testsuite = new XmlSlurper().parse( new File( invokerReports, "TEST-project2.xml" ) ) + +assert testsuite.@skipped.text() == "1" +assert testsuite.testcase.skipped.text() == "Skipped due to setup job(s) failure" + +def buildLog = new File( basedir, 'build.log' ).text +assert buildLog.contains('[INFO] Passed: 0, Failed: 1, Errors: 0, Skipped: 1') diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java index 74220aa9..81214247 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java +++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java @@ -826,16 +826,27 @@ else if ( lastModifiedRecursive( projectsDirectory ) <= lastModifiedRecursive( c getLog().info( "Setup done." ); } - // Afterwards run all other jobs. - List nonSetupBuildJobs = getNonSetupJobs( buildJobs ); - // We will run the non setup jobs with the configured - // parallelThreads number. - runBuilds( projectsDir, nonSetupBuildJobs, getParallelThreadsCount() ); - writeSummaryFile( nonSetupBuildJobs ); + List nonSetupBuildJobs = getNonSetupJobs( buildJobs ); - processResults( new InvokerSession( nonSetupBuildJobs ) ); + if ( setupBuildJobs.isEmpty() || setupBuildJobs.stream().allMatch( BuildJob::isNotError ) ) + { + // We will run the non setup jobs with the configured + // parallelThreads number. + runBuilds( projectsDir, nonSetupBuildJobs, getParallelThreadsCount() ); + } + else + { + for ( BuildJob buildJob : nonSetupBuildJobs ) + { + buildJob.setResult( BuildJob.Result.SKIPPED ); + buildJob.setFailureMessage( "Skipped due to setup job(s) failure" ); + writeBuildReport( buildJob ); + } + } + writeSummaryFile( buildJobs ); + processResults( new InvokerSession( buildJobs ) ); } private void setupActualMavenVersion() throws MojoExecutionException @@ -957,7 +968,7 @@ private void writeSummaryFile( List buildJobs ) { for ( BuildJob buildJob : buildJobs ) { - if ( !buildJob.getResult().equals( BuildJob.Result.SUCCESS ) ) + if ( !BuildJob.Result.SUCCESS.equals( buildJob.getResult() ) ) { writer.append( buildJob.getResult() ); writer.append( " [" ); diff --git a/src/main/mdo/invocation.mdo b/src/main/mdo/invocation.mdo index 4352c2e5..6529e7c6 100644 --- a/src/main/mdo/invocation.mdo +++ b/src/main/mdo/invocation.mdo @@ -133,6 +133,11 @@ under the License. { this.project = project; } + + public boolean isNotError() + { + return Result.SUCCESS.equals( result ) || Result.SKIPPED.equals( result ); + } ]]>