You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2020/03/11 13:58:14 UTC

[sling-htl-maven-plugin] branch master updated: SLING-9196 - Provide flag which allows the htl-maven-plugin to not fail a build

This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-htl-maven-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new d44ff7d  SLING-9196 - Provide flag which allows the htl-maven-plugin to not fail a build
d44ff7d is described below

commit d44ff7d4af148437812b95c83545cacde0bd00fd
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Wed Mar 11 14:58:01 2020 +0100

    SLING-9196 - Provide flag which allows the htl-maven-plugin to not fail a build
    
    * added a failOnErrors flag, which by default is set to true
---
 .../org/apache/sling/maven/htl/ValidateMojo.java   | 10 ++++-
 .../apache/sling/maven/htl/ValidateMojoTest.java   | 19 ++++++--
 .../test-project/fail-on-errors-false.pom.xml      | 52 ++++++++++++++++++++++
 3 files changed, 77 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/maven/htl/ValidateMojo.java b/src/main/java/org/apache/sling/maven/htl/ValidateMojo.java
index 7ebb99c..02f1f8a 100644
--- a/src/main/java/org/apache/sling/maven/htl/ValidateMojo.java
+++ b/src/main/java/org/apache/sling/maven/htl/ValidateMojo.java
@@ -106,6 +106,14 @@ public class ValidateMojo extends AbstractMojo {
     private boolean failOnWarnings;
 
     /**
+     * If set to "false" it will not fail the build on compiler errors, however the errors will still be logged.
+     *
+     * @since 2.0.0
+     */
+    @Parameter(property = "htl.failOnErrors", defaultValue = "true")
+    private boolean failOnErrors;
+
+    /**
      * If set to "true" it will generate the Java classes resulted from transpiling the HTL scripts to Java. The generated classes will
      * be stored in the folder identified by the {@code generatedJavaClassesDirectory} parameter.
      *
@@ -252,7 +260,7 @@ public class ValidateMojo extends AbstractMojo {
             if (mayFailExecution && hasWarnings && failOnWarnings) {
                 throw new MojoFailureException("Compilation warnings were configured to fail the build.");
             }
-            if (mayFailExecution && hasErrors) {
+            if (mayFailExecution && hasErrors && failOnErrors) {
                 throw new MojoFailureException("Please check the reported syntax errors.");
             }
         } catch (IOException e) {
diff --git a/src/test/java/org/apache/sling/maven/htl/ValidateMojoTest.java b/src/test/java/org/apache/sling/maven/htl/ValidateMojoTest.java
index c526a63..9f0f1c5 100644
--- a/src/test/java/org/apache/sling/maven/htl/ValidateMojoTest.java
+++ b/src/test/java/org/apache/sling/maven/htl/ValidateMojoTest.java
@@ -29,10 +29,11 @@ import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.testing.MojoRule;
-import org.apache.maven.plugin.testing.SilentLog;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuilder;
 import org.apache.maven.project.ProjectBuildingRequest;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.console.ConsoleLogger;
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.junit.After;
 import org.junit.Assert;
@@ -76,6 +77,7 @@ public class ValidateMojoTest {
     private static final String INVALID_OPTIONS_POM = "invalid-options.pom.xml";
     private static final String NON_DEFAULT_OPTIONS_POM = "non-default-options.pom.xml";
     private static final String DATA_SLY_TEST_CONSTANT_VALUES_POM_XML = "data-sly-test-constant-values.pom.xml";
+    private static final String FAIL_ON_ERRORS_FALSE_POM_XML = "fail-on-errors-false.pom.xml";
 
 
     @Rule
@@ -161,6 +163,18 @@ public class ValidateMojoTest {
     }
 
     @Test
+    public void testFailOnErrorsFalse() throws Exception {
+        File baseDir = new File(System.getProperty("basedir"));
+        ValidateMojo validateMojo = getMojo(baseDir, FAIL_ON_ERRORS_FALSE_POM_XML);
+        validateMojo.execute();
+        List<File> processedFiles = validateMojo.getProcessedFiles();
+        assertEquals("Expected 1 file to process.", 1, processedFiles.size());
+        assertTrue("Expected error.sly to be one of the processed files.", processedFiles.contains(new File(baseDir, ERROR_SLY)));
+        assertFalse("Did not expect compilation warnings.", validateMojo.hasWarnings());
+        assertTrue("Expected compilation errors.", validateMojo.hasErrors());
+    }
+
+    @Test
     public void testGenerateJavaClasses() throws Exception {
         File baseDir = new File(System.getProperty("basedir"));
         ValidateMojo validateMojo = getMojo(baseDir, GENERATE_JAVA_CLASSES_POM);
@@ -276,7 +290,7 @@ public class ValidateMojoTest {
     }
 
     private ValidateMojo getMojo(File baseDir, String pomFile, DefaultBuildContext buildContext) throws Exception {
-        SilentLog log = new SilentLog();
+        Logger log = new ConsoleLogger();
         if (buildContext == null) {
             buildContext = new DefaultBuildContext();
         }
@@ -287,7 +301,6 @@ public class ValidateMojoTest {
         MavenSession session = mojoRule.newMavenSession(project);
         MojoExecution execution = mojoRule.newMojoExecution("validate");
         ValidateMojo validateMojo = (ValidateMojo) mojoRule.lookupConfiguredMojo(session, execution);
-        validateMojo.setLog(log);
         validateMojo.setBuildContext(buildContext);
         return validateMojo;
     }
diff --git a/src/test/resources/test-project/fail-on-errors-false.pom.xml b/src/test/resources/test-project/fail-on-errors-false.pom.xml
new file mode 100644
index 0000000..423a334
--- /dev/null
+++ b/src/test/resources/test-project/fail-on-errors-false.pom.xml
@@ -0,0 +1,52 @@
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ~ 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.
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.sling</groupId>
+    <artifactId>htl-maven-plugin-it-fail-on-errors-false</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <name>HTL Maven Plugin IT - Default includes</name>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.sling</groupId>
+                <artifactId>htl-maven-plugin</artifactId>
+                <configuration>
+                    <sourceDirectory>src/main/resources</sourceDirectory>
+                    <includes>
+                        <include>**/error.sly</include>
+                    </includes>
+                    <failOnErrors>false</failOnErrors>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>validate-scripts</id>
+                        <goals>
+                            <goal>validate</goal>
+                        </goals>
+                        <phase>compile</phase>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>