This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-htl-maven-plugin.git
commit f9b5d2d10b885046c07abe0d34e53a7aeb33ac29 Author: Radu Cotescu <[email protected]> AuthorDate: Mon Sep 5 09:38:13 2016 +0000 SLING-6028 - Replace Sightly references with HTL in both code and documentation git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1759219 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 175 +++++++++++++++ .../org/apache/sling/maven/htl/ValidateMojo.java | 250 +++++++++++++++++++++ .../META-INF/m2e/lifecycle-mapping-metadata.xml | 33 +++ .../org/apache/sling/maven/htl/ProjectStub.java | 34 +++ .../apache/sling/maven/htl/ValidateMojoTest.java | 118 ++++++++++ .../test-project/explicit-excludes.pom.xml | 52 +++++ .../test-project/explicit-includes.pom.xml | 52 +++++ .../test-project/fail-on-warnings.pom.xml | 53 +++++ .../src/main/resources/apps/projects/error.sly | 18 ++ .../src/main/resources/apps/projects/exclude.html | 18 ++ .../src/main/resources/apps/projects/script.html | 17 ++ .../src/main/resources/apps/projects/warning.sly | 19 ++ 12 files changed, 839 insertions(+) diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3516ad2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,175 @@ +<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ 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> + + <parent> + <groupId>org.apache.sling</groupId> + <artifactId>sling</artifactId> + <version>28</version> + <relativePath/> + </parent> + + <artifactId>htl-maven-plugin</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>maven-plugin</packaging> + + <name>Apache Sling HTL Maven Plugin</name> + <description>The Apache Sling HTL Maven Plugin provides support for validating HTML Template Language scripts from projects.</description> + + <scm> + <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/tooling/maven/htl-maven-plugin</connection> + <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/tooling/maven/htl-maven-plugin</developerConnection> + <url>http://svn.apache.org/viewvc/sling/trunk/tooling/maven/htl-maven-plugin</url> + </scm> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <maven.version>3.3.3</maven.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.scripting.sightly.compiler</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.5</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.5</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-artifact</artifactId> + <version>${maven.version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>${maven.version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-annotations</artifactId> + <version>3.4</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-utils</artifactId> + <version>3.0.24</version> + </dependency> + <dependency> + <groupId>org.sonatype.plexus</groupId> + <artifactId>plexus-build-api</artifactId> + <version>0.0.7</version> + </dependency> + + + <!-- Testing Dependencies --> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-container-default</artifactId> + <version>1.6</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.maven.plugin-testing</groupId> + <artifactId>maven-plugin-testing-harness</artifactId> + <version>3.3.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-compat</artifactId> + <scope>test</scope> + <version>${maven.version}</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-plugin</artifactId> + <version>3.4</version> + <executions> + <execution> + <id>mojo-descriptor</id> + <phase>process-classes</phase> + <goals> + <goal>descriptor</goal> + </goals> + </execution> + <execution> + <id>generated-helpmojo</id> + <goals> + <goal>helpmojo</goal> + </goals> + </execution> + </executions> + <configuration> + <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-component-metadata</artifactId> + <version>1.6</version> + <executions> + <execution> + <goals> + <goal>generate-metadata</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.rat</groupId> + <artifactId>apache-rat-plugin</artifactId> + <configuration> + <excludes> + <exclude>**/*.iml</exclude> + <exclude>**/target/**/*</exclude> + </excludes> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/src/main/java/org/apache/sling/maven/htl/ValidateMojo.java b/src/main/java/org/apache/sling/maven/htl/ValidateMojo.java new file mode 100644 index 0000000..826b2a4 --- /dev/null +++ b/src/main/java/org/apache/sling/maven/htl/ValidateMojo.java @@ -0,0 +1,250 @@ +/******************************************************************************* + * 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. + ******************************************************************************/ +package org.apache.sling.maven.htl; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.apache.sling.scripting.sightly.compiler.CompilationResult; +import org.apache.sling.scripting.sightly.compiler.CompilationUnit; +import org.apache.sling.scripting.sightly.compiler.CompilerMessage; +import org.apache.sling.scripting.sightly.compiler.SightlyCompiler; +import org.codehaus.plexus.util.Scanner; +import org.codehaus.plexus.util.StringUtils; +import org.sonatype.plexus.build.incremental.BuildContext; + +/** + * This goal validates Sightly scripts syntax. + */ +@Mojo( + name = "validate", + defaultPhase = LifecyclePhase.COMPILE, + threadSafe = true +) +public class ValidateMojo extends AbstractMojo { + + private static final String DEFAULT_INCLUDES = "**/*.html"; + private static final String DEFAULT_EXCLUDES = ""; + + @Component + private BuildContext buildContext; + + @Parameter(defaultValue = "${project}", readonly = true, required = true) + protected MavenProject project; + + /** + * Defines the root folder where this Mojo expects to find Sightly scripts to validate. + */ + @Parameter(property = "sourceDirectory", defaultValue = "${project.build.sourceDirectory}") + private File sourceDirectory; + + /** + * 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 + private String[] includes; + + /** + * List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents will be scanned + * (see the sourceDirectory configuration option). + */ + @Parameter + private String[] excludes; + + /** + * If set to "true" it will fail the build on compiler warnings. + */ + @Parameter(property = "failOnWarnings", defaultValue = "false") + private boolean failOnWarnings; + + private boolean hasWarnings = false; + private boolean hasErrors = false; + private String processedIncludes = null; + private String processedExcludes = null; + private List<File> processedFiles = Collections.emptyList(); + + private int sourceDirectoryLength = 0; + + public void execute() throws MojoExecutionException, MojoFailureException { + + long start = System.currentTimeMillis(); + + if (!sourceDirectory.isAbsolute()) { + sourceDirectory = new File(project.getBasedir(), sourceDirectory.getPath()); + } + if (!sourceDirectory.exists()) { + throw new MojoExecutionException( + String.format("Configured sourceDirectory={%s} does not exist.", sourceDirectory.getAbsolutePath())); + } + if (!sourceDirectory.isDirectory()) { + throw new MojoExecutionException( + String.format("Configured sourceDirectory={%s} is not a directory.", sourceDirectory.getAbsolutePath())); + } + + if ( !buildContext.hasDelta(sourceDirectory )) { + getLog().info("No files found to validate, skipping"); + return; + } + + // don't fail execution in Eclipse as it generates an error marker in the POM file, which is not desired + boolean mayFailExecution = !buildContext.getClass().getName().startsWith("org.eclipse.m2e"); + + sourceDirectoryLength = sourceDirectory.getAbsolutePath().length(); + processedIncludes = processIncludes(); + processedExcludes = processExcludes(); + try { + SightlyCompiler compiler = new SightlyCompiler(); + + Scanner scanner = buildContext.newScanner(sourceDirectory); + scanner.setExcludes(new String[] { processedExcludes } ); + scanner.setIncludes(new String[] { processedIncludes } ); + scanner.scan(); + + String[] includedFiles = scanner.getIncludedFiles(); + + processedFiles = new ArrayList<>(includedFiles.length); + for ( String includedFile : includedFiles ) { + processedFiles.add(new File(sourceDirectory, includedFile)); + } + Map<File, CompilationResult> compilationResults = new HashMap<>(); + for (File script : processedFiles) { + compilationResults.put(script, compiler.compile(getCompilationUnit(script))); + } + for (Map.Entry<File, CompilationResult> entry : compilationResults.entrySet()) { + File script = entry.getKey(); + CompilationResult result = entry.getValue(); + buildContext.removeMessages(script); + + if (result.getWarnings().size() > 0) { + for (CompilerMessage message : result.getWarnings()) { + buildContext.addMessage(script, message.getLine(), message.getColumn(), message.getMessage(), BuildContext.SEVERITY_WARNING, null); + } + hasWarnings = true; + } + if (result.getErrors().size() > 0) { + for (CompilerMessage message : result.getErrors()) { + String messageString = message.getMessage().replaceAll(System.lineSeparator(), ""); + buildContext.addMessage(script, message.getLine(), message.getColumn(), messageString, BuildContext.SEVERITY_ERROR, null); + } + hasErrors = true; + } + } + + getLog().info("Processed " + processedFiles.size() + " files in " + ( System.currentTimeMillis() - start ) + " milliseconds"); + + if (mayFailExecution && hasWarnings && failOnWarnings) { + throw new MojoFailureException("Compilation warnings were configured to fail the build."); + } + if (mayFailExecution && hasErrors) { + throw new MojoFailureException("Please check the reported syntax errors."); + } + } catch (IOException e) { + throw new MojoExecutionException(String.format("Cannot filter files from {%s} with includes {%s} and excludes {%s}.", + sourceDirectory.getAbsolutePath(), processedIncludes, processedExcludes), e); + } + + } + + public File getSourceDirectory() { + return sourceDirectory; + } + + public boolean shouldFailOnWarnings() { + return failOnWarnings; + } + + public boolean hasWarnings() { + return hasWarnings; + } + + public boolean hasErrors() { + return hasErrors; + } + + public String getIncludes() { + return processedIncludes; + } + + public String getExcludes() { + return processedExcludes; + } + + public List<File> getProcessedFiles() { + return processedFiles; + } + + private String processIncludes() { + if (includes == null) { + return DEFAULT_INCLUDES; + } + return join(includes, ','); + } + + private String processExcludes() { + if (excludes == null) { + return DEFAULT_EXCLUDES; + } + return join(excludes, ','); + } + + private String join(String[] array, char joinChar) { + StringBuilder stringBuilder = new StringBuilder(); + for (int index = 0; index < array.length; index++) { + stringBuilder.append(StringUtils.trim(array[index])); + if (index < array.length - 1) { + stringBuilder.append(joinChar); + } + } + return stringBuilder.toString(); + } + + private CompilationUnit getCompilationUnit(final File file) throws FileNotFoundException { + final Reader reader = new FileReader(file); + return new CompilationUnit() { + public String getScriptName() { + return file.getAbsolutePath().substring(sourceDirectoryLength); + } + + public Reader getScriptReader() { + return reader; + } + }; + } + + // visible for testing only + void setBuildContext(BuildContext buildContext) { + + this.buildContext = buildContext; + } +} diff --git a/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml b/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml new file mode 100644 index 0000000..a99b99f --- /dev/null +++ b/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml @@ -0,0 +1,33 @@ +<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ 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. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> +<lifecycleMappingMetadata> + <pluginExecutions> + <pluginExecution> + <pluginExecutionFilter> + <goals> + <goal>validate</goal> + </goals> + </pluginExecutionFilter> + <action> + <execute> + <runOnIncremental>true</runOnIncremental> + <runOnConfiguration>false</runOnConfiguration> + </execute> + </action> + </pluginExecution> + </pluginExecutions> +</lifecycleMappingMetadata> \ No newline at end of file diff --git a/src/test/java/org/apache/sling/maven/htl/ProjectStub.java b/src/test/java/org/apache/sling/maven/htl/ProjectStub.java new file mode 100644 index 0000000..aebef35 --- /dev/null +++ b/src/test/java/org/apache/sling/maven/htl/ProjectStub.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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. + ******************************************************************************/ +package org.apache.sling.maven.htl; + +import java.io.File; + +import org.apache.maven.model.Model; +import org.apache.maven.plugin.testing.stubs.MavenProjectStub; + +public class ProjectStub extends MavenProjectStub { + + public ProjectStub(File pomFile) { + readModel(pomFile); + setPomFile(pomFile); + Model model = getModel(); + setGroupId(model.getGroupId()); + setArtifactId(model.getArtifactId()); + setVersion(model.getVersion()); + } +} diff --git a/src/test/java/org/apache/sling/maven/htl/ValidateMojoTest.java b/src/test/java/org/apache/sling/maven/htl/ValidateMojoTest.java new file mode 100644 index 0000000..86d14eb --- /dev/null +++ b/src/test/java/org/apache/sling/maven/htl/ValidateMojoTest.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * 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. + ******************************************************************************/ +package org.apache.sling.maven.htl; + +import java.io.File; +import java.util.List; + +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.junit.Rule; +import org.junit.Test; +import org.sonatype.plexus.build.incremental.DefaultBuildContext; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +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"; + + @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 + .separator + TEST_PROJECT).getAbsolutePath()); + } + }; + + @Test + public void testExplicitIncludes() throws Exception { + File baseDir = new File(System.getProperty("basedir")); + ValidateMojo validateMojo = getMojo(baseDir, EXPLICIT_INCLUDES_POM); + try { + validateMojo.execute(); + } catch (MojoFailureException e) { + List<File> processedFiles = validateMojo.getProcessedFiles(); + assertEquals("Expected 2 files to process.", 2, processedFiles.size()); + assertTrue("Expected error.sly to be one of the processed files.", processedFiles.contains(new File(baseDir, ERROR_SLY))); + assertTrue("Expected warning.sly to be one of the processed files.", processedFiles.contains(new File(baseDir, WARNING_SLY))); + assertEquals("Expected compilation errors.", true, validateMojo.hasErrors()); + assertEquals("Expected compilation warnings.", true, validateMojo.hasWarnings()); + } + } + + @Test + public void testExplicitExcludes() throws Exception { + File baseDir = new File(System.getProperty("basedir")); + ValidateMojo validateMojo = getMojo(baseDir, EXPLICIT_EXCLUDES_POM); + validateMojo.execute(); + List<File> processedFiles = validateMojo.getProcessedFiles(); + assertEquals("Expected 1 file to process.", 1, processedFiles.size()); + assertTrue("Expected script.html to be the only processed file.", processedFiles.contains(new File(baseDir, SCRIPT_HTML))); + assertEquals("Did not expect compilation errors.", false, validateMojo.hasErrors()); + assertEquals("Did not expect compilation warnings.", false, validateMojo.hasWarnings()); + } + + @Test + public void testFailOnWarnings() throws Exception { + File baseDir = new File(System.getProperty("basedir")); + ValidateMojo validateMojo = getMojo(baseDir, FAIL_ON_WARNINGS_POM); + Exception exception = null; + try { + validateMojo.execute(); + } catch (MojoFailureException e) { + exception = e; + } + List<File> processedFiles = validateMojo.getProcessedFiles(); + assertNotNull("Expected a MojoFailureException.", exception); + assertEquals("Expected 1 file to process.", 1, processedFiles.size()); + assertTrue("Expected warning.sly to be one of the processed files.", processedFiles.contains(new File(baseDir, WARNING_SLY))); + assertEquals("Expected compilation warnings.", true, 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); + validateMojo.setLog(log); + buildContext.enableLogging(log); + validateMojo.setBuildContext(buildContext); + return validateMojo; + } + + +} diff --git a/src/test/resources/test-project/explicit-excludes.pom.xml b/src/test/resources/test-project/explicit-excludes.pom.xml new file mode 100644 index 0000000..4fb5fe7 --- /dev/null +++ b/src/test/resources/test-project/explicit-excludes.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-explicit-excludes</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>pom</packaging> + + <name>HTL Maven Plugin IT - Explicit excludes</name> + + <build> + <plugins> + <plugin> + <groupId>org.apache.sling</groupId> + <artifactId>htl-maven-plugin</artifactId> + <configuration> + <sourceDirectory>src/main/resources</sourceDirectory> + <!-- only script.html will be compiled --> + <excludes> + <exclude>**/exclude.html</exclude> + </excludes> + </configuration> + <executions> + <execution> + <id>validate-scripts</id> + <goals> + <goal>validate</goal> + </goals> + <phase>compile</phase> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/src/test/resources/test-project/explicit-includes.pom.xml b/src/test/resources/test-project/explicit-includes.pom.xml new file mode 100644 index 0000000..9e073da --- /dev/null +++ b/src/test/resources/test-project/explicit-includes.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-explicit-includes</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>pom</packaging> + + <name>HTL Maven Plugin IT - Explicit includes</name> + + <build> + <plugins> + <plugin> + <groupId>org.apache.sling</groupId> + <artifactId>htl-maven-plugin</artifactId> + <configuration> + <sourceDirectory>src/main/resources</sourceDirectory> + <!-- only *.sly files will be compiled --> + <includes> + <include>**/*.sly</include> + </includes> + </configuration> + <executions> + <execution> + <id>validate-scripts</id> + <goals> + <goal>validate</goal> + </goals> + <phase>compile</phase> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/src/test/resources/test-project/fail-on-warnings.pom.xml b/src/test/resources/test-project/fail-on-warnings.pom.xml new file mode 100644 index 0000000..f207e65 --- /dev/null +++ b/src/test/resources/test-project/fail-on-warnings.pom.xml @@ -0,0 +1,53 @@ +<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ 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-warnings</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>pom</packaging> + + <name>HTL Maven Plugin IT - Fail On Warnings</name> + + <build> + <plugins> + <plugin> + <groupId>org.apache.sling</groupId> + <artifactId>htl-maven-plugin</artifactId> + <configuration> + <sourceDirectory>src/main/resources</sourceDirectory> + <!-- only the warning.sly file will be compiled --> + <includes> + <include>**/warning.sly</include> + </includes> + <failOnWarnings>true</failOnWarnings> + </configuration> + <executions> + <execution> + <id>validate-scripts</id> + <goals> + <goal>validate</goal> + </goals> + <phase>compile</phase> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/src/test/resources/test-project/src/main/resources/apps/projects/error.sly b/src/test/resources/test-project/src/main/resources/apps/projects/error.sly new file mode 100644 index 0000000..ffe8613 --- /dev/null +++ b/src/test/resources/test-project/src/main/resources/apps/projects/error.sly @@ -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. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/--> +<!--/* Intentionally add a Sightly error here; this file should be compiled by the plugin and fail the build. */--> +${expression.notClosed diff --git a/src/test/resources/test-project/src/main/resources/apps/projects/exclude.html b/src/test/resources/test-project/src/main/resources/apps/projects/exclude.html new file mode 100644 index 0000000..95d56d6 --- /dev/null +++ b/src/test/resources/test-project/src/main/resources/apps/projects/exclude.html @@ -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. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> +<!--/* Intentionally add a Sightly error here; this file should not be compiled by the plugin. */--> +${expression.notClosed diff --git a/src/test/resources/test-project/src/main/resources/apps/projects/script.html b/src/test/resources/test-project/src/main/resources/apps/projects/script.html new file mode 100644 index 0000000..5df9256 --- /dev/null +++ b/src/test/resources/test-project/src/main/resources/apps/projects/script.html @@ -0,0 +1,17 @@ +<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ 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. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/--> +${this.is.an.expression @ i18n, locale='de'} diff --git a/src/test/resources/test-project/src/main/resources/apps/projects/warning.sly b/src/test/resources/test-project/src/main/resources/apps/projects/warning.sly new file mode 100644 index 0000000..fb79153 --- /dev/null +++ b/src/test/resources/test-project/src/main/resources/apps/projects/warning.sly @@ -0,0 +1,19 @@ +<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ 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. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> +<script> + var a = '${a}'; +</script> -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
