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 2017/08/01 14:07:49 UTC

svn commit: r1803644 - in /sling/trunk/tooling/maven/htl-maven-plugin: ./ src/main/java/org/apache/sling/maven/htl/ src/test/java/org/apache/sling/maven/htl/ src/test/resources/test-project/

Author: radu
Date: Tue Aug  1 14:07:48 2017
New Revision: 1803644

URL: http://svn.apache.org/viewvc?rev=1803644&view=rev
Log:
SLING-7025 - htl-maven-plugin: Correctly state default values for include parameter

* applied slightly modified patch from Konrad Windszus

Added:
    sling/trunk/tooling/maven/htl-maven-plugin/src/test/resources/test-project/default-includes.pom.xml
Modified:
    sling/trunk/tooling/maven/htl-maven-plugin/pom.xml
    sling/trunk/tooling/maven/htl-maven-plugin/src/main/java/org/apache/sling/maven/htl/ValidateMojo.java
    sling/trunk/tooling/maven/htl-maven-plugin/src/test/java/org/apache/sling/maven/htl/ValidateMojoTest.java

Modified: sling/trunk/tooling/maven/htl-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/htl-maven-plugin/pom.xml?rev=1803644&r1=1803643&r2=1803644&view=diff
==============================================================================
--- sling/trunk/tooling/maven/htl-maven-plugin/pom.xml (original)
+++ sling/trunk/tooling/maven/htl-maven-plugin/pom.xml Tue Aug  1 14:07:48 2017
@@ -37,6 +37,10 @@
         <url>http://svn.apache.org/viewvc/sling/trunk/tooling/maven/htl-maven-plugin</url>
     </scm>
 
+    <prerequisites>
+        <maven>3.3.9</maven><!-- due to https://issues.apache.org/jira/browse/MNG-5440 -->
+    </prerequisites>
+
     <!-- Support for publishing the mvn site. -->
     <distributionManagement>
         <site>
@@ -47,15 +51,47 @@
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <maven.version>3.3.3</maven.version>
+        <maven.version>3.3.9</maven.version>
         <maven.site.path>${project.artifactId}-archives/${project.artifactId}-LATEST</maven.site.path>
     </properties>
 
+    <!-- force maven-plugin-testing-harness to use newer plexus container (https://issues.apache.org/jira/browse/MPLUGINTESTING-53) -->
+    <dependencyManagement>
+        <dependencies>
+            <!-- maven -->
+            <dependency>
+                <groupId>org.apache.maven</groupId>
+                <artifactId>maven-core</artifactId>
+                <version>${maven.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.maven</groupId>
+                <artifactId>maven-compat</artifactId>
+                <version>${maven.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.maven</groupId>
+                <artifactId>maven-model</artifactId>
+                <version>${maven.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.maven</groupId>
+                <artifactId>maven-plugin-api</artifactId>
+                <version>${maven.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.maven</groupId>
+                <artifactId>maven-aether-provider</artifactId>
+                <version>${maven.version}</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
     <dependencies>
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
-            <version>1.0.7-SNAPSHOT</version>
+            <version>1.0.9-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>commons-io</groupId>

Modified: sling/trunk/tooling/maven/htl-maven-plugin/src/main/java/org/apache/sling/maven/htl/ValidateMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/htl-maven-plugin/src/main/java/org/apache/sling/maven/htl/ValidateMojo.java?rev=1803644&r1=1803643&r2=1803644&view=diff
==============================================================================
--- sling/trunk/tooling/maven/htl-maven-plugin/src/main/java/org/apache/sling/maven/htl/ValidateMojo.java (original)
+++ sling/trunk/tooling/maven/htl-maven-plugin/src/main/java/org/apache/sling/maven/htl/ValidateMojo.java Tue Aug  1 14:07:48 2017
@@ -72,7 +72,7 @@ public class ValidateMojo extends Abstra
      * List of files to include. Specified as fileset patterns which are relative to the input directory whose contents will be scanned
      * (see the sourceDirectory configuration option).
      */
-    @Parameter
+    @Parameter(defaultValue = DEFAULT_INCLUDES)
     private String[] includes;
 
     /**
@@ -215,8 +215,9 @@ public class ValidateMojo extends Abstra
     }
 
     private String processIncludes() {
+        // since default = "" leads to null deal with that as well here
         if (includes == null) {
-            return DEFAULT_INCLUDES;
+            return "";
         }
         return join(includes, ',');
     }

Modified: sling/trunk/tooling/maven/htl-maven-plugin/src/test/java/org/apache/sling/maven/htl/ValidateMojoTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/htl-maven-plugin/src/test/java/org/apache/sling/maven/htl/ValidateMojoTest.java?rev=1803644&r1=1803643&r2=1803644&view=diff
==============================================================================
--- sling/trunk/tooling/maven/htl-maven-plugin/src/test/java/org/apache/sling/maven/htl/ValidateMojoTest.java (original)
+++ sling/trunk/tooling/maven/htl-maven-plugin/src/test/java/org/apache/sling/maven/htl/ValidateMojoTest.java Tue Aug  1 14:07:48 2017
@@ -19,10 +19,18 @@ package org.apache.sling.maven.htl;
 import java.io.File;
 import java.util.List;
 
+import org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionRequest;
+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.eclipse.aether.DefaultRepositorySystemSession;
+import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonatype.plexus.build.incremental.DefaultBuildContext;
@@ -33,20 +41,22 @@ import static org.junit.Assert.assertTru
 
 public class ValidateMojoTest {
 
-    public static final String ERROR_SLY = "src/main/resources/apps/projects/error.sly";
-    public static final String WARNING_SLY = "src/main/resources/apps/projects/warning.sly";
-    public static final String SCRIPT_HTML = "src/main/resources/apps/projects/script.html";
-    public static final String TEST_PROJECT = "test-project";
-    public static final String EXPLICIT_INCLUDES_POM = "explicit-includes.pom.xml";
-    public static final String EXPLICIT_EXCLUDES_POM = "explicit-excludes.pom.xml";
-    public static final String FAIL_ON_WARNINGS_POM = "fail-on-warnings.pom.xml";
+    private static final String ERROR_SLY = "src/main/resources/apps/projects/error.sly";
+    private static final String WARNING_SLY = "src/main/resources/apps/projects/warning.sly";
+    private static final String SCRIPT_HTML = "src/main/resources/apps/projects/script.html";
+    private static final String EXCLUDE_HTML = "src/main/resources/apps/projects/exclude.html";
+    private static final String TEST_PROJECT = "test-project";
+    private static final String EXPLICIT_INCLUDES_POM = "explicit-includes.pom.xml";
+    private static final String EXPLICIT_EXCLUDES_POM = "explicit-excludes.pom.xml";
+    private static final String FAIL_ON_WARNINGS_POM = "fail-on-warnings.pom.xml";
+    private static final String DEFAULT_INCLUDES_POM = "default-includes.pom.xml";
 
     @Rule
     public MojoRule mojoRule = new MojoRule() {
         @Override
         protected void before() throws Throwable {
             super.before();
-            /**
+            /*
              * Make sure the base directory is initialised properly for this test
              */
             System.setProperty("basedir", new File("src" + File.separator + "test" + File.separator + "resources" + File
@@ -99,20 +109,51 @@ public class ValidateMojoTest {
         assertEquals("Expected compilation warnings.", true, validateMojo.hasWarnings());
     }
 
+    @Test
+    public void testDefaultIncludes() throws Exception {
+        File baseDir = new File(System.getProperty("basedir"));
+        ValidateMojo validateMojo = getMojo(baseDir, DEFAULT_INCLUDES_POM);
+        Exception exception = null;
+        try {
+            validateMojo.execute();
+        } catch (MojoFailureException e) {
+            exception = e;
+        }
+        List<File> processedFiles = validateMojo.getProcessedFiles();
+        assertNotNull("Expected a MojoFailureException.", exception);
+        assertEquals("Expected 2 files to process.", 2, processedFiles.size());
+        assertTrue("Expected exclude.html to be one of the processed files.", processedFiles.contains(new File(baseDir, EXCLUDE_HTML)));
+        assertTrue("Expected script.html to be one of the processed files.", processedFiles.contains(new File(baseDir, SCRIPT_HTML)));
+        assertEquals("Did not expect compilation warnings.", false, validateMojo.hasWarnings());
+    }
+
     private ValidateMojo getMojo(File baseDir, String pomFile) throws Exception {
         SilentLog log = new SilentLog();
         DefaultBuildContext buildContext = new DefaultBuildContext();
 
-        File pom = new File(baseDir, pomFile);
-        ValidateMojo validateMojo = new ValidateMojo();
-        mojoRule.configureMojo(validateMojo, mojoRule.extractPluginConfiguration("htl-maven-plugin", pom));
-        MavenProject mavenProject = new ProjectStub(pom);
-        mojoRule.setVariableValueToObject(validateMojo, "project", mavenProject);
+        // use lookupConfiguredMojo to also consider default values (https://issues.apache.org/jira/browse/MPLUGINTESTING-23)
+        // similar to MojoRule#lookupConfiguredMojo(File, String) but with custom pom file name
+        MavenProject project = readMavenProject(baseDir, pomFile);
+        MavenSession session = mojoRule.newMavenSession(project);
+        MojoExecution execution = mojoRule.newMojoExecution("validate");
+        ValidateMojo validateMojo = (ValidateMojo) mojoRule.lookupConfiguredMojo(session, execution);
         validateMojo.setLog(log);
         buildContext.enableLogging(log);
         validateMojo.setBuildContext(buildContext);
         return validateMojo;
     }
 
-
+    /**
+     * Copied from {@code org.apache.maven.plugin.testing.readMavenProject(...)} but customized to allow custom pom names
+     */
+    private MavenProject readMavenProject(File basedir, String pomFileName) throws Exception {
+        File pom = new File(basedir, pomFileName);
+        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
+        request.setBaseDirectory(basedir);
+        ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
+        configuration.setRepositorySession(new DefaultRepositorySystemSession());
+        MavenProject project = mojoRule.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
+        Assert.assertNotNull(project);
+        return project;
+    }
 }

Added: sling/trunk/tooling/maven/htl-maven-plugin/src/test/resources/test-project/default-includes.pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/htl-maven-plugin/src/test/resources/test-project/default-includes.pom.xml?rev=1803644&view=auto
==============================================================================
--- sling/trunk/tooling/maven/htl-maven-plugin/src/test/resources/test-project/default-includes.pom.xml (added)
+++ sling/trunk/tooling/maven/htl-maven-plugin/src/test/resources/test-project/default-includes.pom.xml Tue Aug  1 14:07:48 2017
@@ -0,0 +1,49 @@
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ~ 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-default-includes</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>
+                    <!-- only exclude.html will be compiled -->
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>validate-scripts</id>
+                        <goals>
+                            <goal>validate</goal>
+                        </goals>
+                        <phase>compile</phase>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>