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/04/30 16:52:20 UTC
[sling-scriptingbundle-maven-plugin] branch master updated:
SLING-9338 - Allow defining an exclusion list accepting folders or files
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-scriptingbundle-maven-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new a6d3a87 SLING-9338 - Allow defining an exclusion list accepting folders or files
a6d3a87 is described below
commit a6d3a873bb90a8ad874bcb23a7788dbee6ddcfc7
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Apr 30 18:51:32 2020 +0200
SLING-9338 - Allow defining an exclusion list accepting folders or files
* added two configuration properties that allow defining lists
of paths or patterns which can filter what files / folder are
included / excluded by the plugin
---
.../scriptingbundle/maven/plugin/MetadataMojo.java | 102 ++++++++--
.../maven/plugin/MetadataMojoTest.java | 224 +++++++++++++--------
src/test/resources/project-3/pom.xml | 49 +++++
.../includeexclude/includeexclude.jsp | 18 ++
.../scriptingbundle/includeexclude/selector.html | 0
.../includeexclude/includeexclude.html | 0
.../scriptingbundle/includeexclude/selector.jsp | 18 ++
7 files changed, 317 insertions(+), 94 deletions(-)
diff --git a/src/main/java/org/apache/sling/scriptingbundle/maven/plugin/MetadataMojo.java b/src/main/java/org/apache/sling/scriptingbundle/maven/plugin/MetadataMojo.java
index c5bfe5a..e82f61f 100644
--- a/src/main/java/org/apache/sling/scriptingbundle/maven/plugin/MetadataMojo.java
+++ b/src/main/java/org/apache/sling/scriptingbundle/maven/plugin/MetadataMojo.java
@@ -74,6 +74,48 @@ public class MetadataMojo extends AbstractMojo {
private Set<String> sourceDirectories;
/**
+ * Allows defining a list of included files and folders or patterns to filter which files should be included in the analysis for
+ * generating capabilities. By default all files are included.
+ *
+ * @since 0.2.0
+ */
+ @Parameter(property = "scriptingbundle.includes", defaultValue = "**")
+ private String[] includes;
+
+ /**
+ * Allows defining a list of excluded files and folders or patterns to filter which files should be excluded in the analysis for
+ * generating capabilities.
+ * <p>
+ * The following list provides the default excluded files and patterns:
+ * <dl>
+ * <dt>
+ * Miscellaneous typical temporary files
+ * </dt>
+ * <dd>
+ * **/*~, **/#*#, **/.#*, **/%*%, **/._*
+ * </dd>
+ * <dt>
+ * CVS
+ * </dt>
+ * <dd>**/CVS, **/CVS/**, **/.cvsignore</dd>
+ * <dt>Subversion</dt>
+ * <dd>**/.svn, **/.svn/**</dd>
+ * <dt>Bazaar</dt>
+ * <dd>**/.bzr, **/.bzr/**</dd>
+ * <dt>Mac</dt>
+ * <dd>**/.DS_Store</dd>
+ * <dt>Mercurial</dt>
+ * <dd>**/.hg, **/.hg/**</dd>
+ * <dt>git</dt>
+ * <dd>**/.git, **/.git/**</dd>
+ * </dl>
+ *
+ * @since 0.2.0
+ */
+ @Parameter(property = "scriptingbundle.excludes")
+ private String[] excludes;
+
+ /**
* Allows overriding the default extension to script engine mapping, in order to correctly generate the
* {@code sling.resourceType;scriptEngine} {@code Provide-Capability} attribute value. When configuring this mapping, please make
* sure to use the script extension as the key and one of the Script Engine's name (obtained from
@@ -146,6 +188,28 @@ public class MetadataMojo extends AbstractMojo {
static final Map<String, String> DEFAULT_EXTENSION_TO_SCRIPT_ENGINE_MAPPING;
static final Set<String> DEFAULT_SEARCH_PATHS;
static final Set<String> DEFAULT_SOURCE_DIRECTORIES;
+ static final String[] DEFAULT_EXCLUDES = {
+ // Miscellaneous typical temporary files
+ "**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*",
+
+ // CVS
+ "**/CVS", "**/CVS/**", "**/.cvsignore",
+
+ // Subversion
+ "**/.svn", "**/.svn/**",
+
+ // Bazaar
+ "**/.bzr", "**/.bzr/**",
+
+ // Mac
+ "**/.DS_Store",
+
+ // Mercurial
+ "**/.hg", "**/.hg/**",
+
+ // git
+ "**/.git", "**/.git/**",
+ };
static {
DEFAULT_EXTENSION_TO_SCRIPT_ENGINE_MAPPING = new HashMap<>();
@@ -188,12 +252,7 @@ public class MetadataMojo extends AbstractMojo {
}
return sdFile;
}).filter(sourceDirectory -> sourceDirectory.exists() && sourceDirectory.isDirectory()).forEach(sourceDirectory -> {
- DirectoryScanner scanner = new DirectoryScanner();
- scanner.setBasedir(sourceDirectory);
- scanner.setIncludes("**");
- scanner.setExcludes("**/*.class");
- scanner.addDefaultExcludes();
- scanner.scan();
+ DirectoryScanner scanner = getDirectoryScanner(sourceDirectory);
try {
for (String file : scanner.getIncludedFiles()) {
String fileName = FilenameUtils.getName(file);
@@ -219,12 +278,7 @@ public class MetadataMojo extends AbstractMojo {
if (searchPaths == null || searchPaths.isEmpty()) {
searchPaths = DEFAULT_SEARCH_PATHS;
}
- DirectoryScanner scanner = new DirectoryScanner();
- scanner.setBasedir(workDirectory);
- scanner.setIncludes("**");
- scanner.setExcludes("**/*.class");
- scanner.addDefaultExcludes();
- scanner.scan();
+ DirectoryScanner scanner = getDirectoryScanner(workDirectory);
Capabilities folderCapabilities = generateCapabilities(workDirectory.getAbsolutePath(), scanner);
providedResourceTypeCapabilities.addAll(folderCapabilities.getProvidedResourceTypeCapabilities());
providedScriptCapabilities.addAll(folderCapabilities.getProvidedScriptCapabilities());
@@ -239,6 +293,24 @@ public class MetadataMojo extends AbstractMojo {
}
@NotNull
+ private DirectoryScanner getDirectoryScanner(@NotNull File directory) {
+ DirectoryScanner scanner = new DirectoryScanner();
+ scanner.setBasedir(directory);
+ if (includes == null || includes.length == 0) {
+ scanner.setIncludes("**");
+ } else {
+ scanner.setIncludes(includes);
+ }
+ if (excludes == null || excludes.length == 0) {
+ scanner.setExcludes(DEFAULT_EXCLUDES);
+ } else {
+ scanner.setExcludes(excludes);
+ }
+ scanner.scan();
+ return scanner;
+ }
+
+ @NotNull
private Capabilities generateCapabilities(@NotNull String root, @NotNull DirectoryScanner scanner) {
Set<ProvidedResourceTypeCapability> providedResourceTypeCapabilities = new LinkedHashSet<>();
Set<ProvidedScriptCapability> providedScriptCapabilities = new LinkedHashSet<>();
@@ -246,7 +318,11 @@ public class MetadataMojo extends AbstractMojo {
FileProcessor fileProcessor = new FileProcessor(getLog(), searchPaths, scriptEngineMappings);
ResourceTypeFolderAnalyser resourceTypeFolderAnalyser = new ResourceTypeFolderAnalyser(getLog(), Paths.get(root), fileProcessor);
PathOnlyScriptAnalyser pathOnlyScriptAnalyser = new PathOnlyScriptAnalyser(getLog(), Paths.get(root), scriptEngineMappings, fileProcessor);
- Arrays.stream(scanner.getIncludedDirectories()).map(dir -> Paths.get(root, dir)).forEach(folder -> {
+ Set<String> includedDirectories = new HashSet<>();
+ for (String file : scanner.getIncludedFiles()) {
+ includedDirectories.add(FilenameUtils.getFullPath(file));
+ }
+ includedDirectories.stream().map(dir -> Paths.get(root, dir)).forEach(folder -> {
Capabilities resourceTypeCapabilities = resourceTypeFolderAnalyser.getCapabilities(folder);
providedResourceTypeCapabilities.addAll(resourceTypeCapabilities.getProvidedResourceTypeCapabilities());
requiredResourceTypeCapabilities.addAll(resourceTypeCapabilities.getRequiredResourceTypeCapabilities());
diff --git a/src/test/java/org/apache/sling/scriptingbundle/maven/plugin/MetadataMojoTest.java b/src/test/java/org/apache/sling/scriptingbundle/maven/plugin/MetadataMojoTest.java
index 8555dfc..15233d1 100644
--- a/src/test/java/org/apache/sling/scriptingbundle/maven/plugin/MetadataMojoTest.java
+++ b/src/test/java/org/apache/sling/scriptingbundle/maven/plugin/MetadataMojoTest.java
@@ -27,6 +27,7 @@ import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
+import org.apache.commons.io.FileUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.testing.MojoRule;
@@ -56,92 +57,153 @@ public class MetadataMojoTest {
@Test
public void testProject1() throws Exception {
MojoProject mojoProject = getMojoProject(getProjectLocation("project-1"));
- mojoProject.mojo.execute();
- Capabilities capabilities = mojoProject.mojo.getCapabilities();
- Set<ProvidedResourceTypeCapability> pExpected = new HashSet<>(Arrays.asList(
- // org/apache/sling/bar/1.0.0
- ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl").withScriptExtension("html").withVersion("1.0.0").build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl").withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
- , "100"))).build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl").withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
- , "200"))).build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl").withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
- , "depth2", "100"))).build(),
-
- // org/apache/sling/foo
- ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl").withScriptExtension("html").build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl").withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
- , "100"))).build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl").withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
- , "200"))).build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl").withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
- , "depth2", "100"))).build(),
-
- // org/apache/sling/foo/depth1/depth2/depth3
- ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1/depth2/depth3").withExtendsResourceType("org" +
- "/apache/sling/bar").build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1/depth2/depth3").withScriptEngine("htl").withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth3-selector"))).build(),
-
- // org.apache.sling.foobar/1.0.0
- ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withVersion("1.0.0").withExtendsResourceType("org/apache/sling/bar").build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
- , "100"))).build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
- , "200"))).build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
- , "depth2", "100"))).build(),
-
- // org.apache.sling.foobar
- ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withExtendsResourceType("org/apache/sling/bar").build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
- , "100"))).build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
- , "200"))).build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
- , "depth2", "100"))).build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withRequestMethod("GET").build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withRequestMethod("GET").withSelectors(new LinkedHashSet<>(Arrays.asList("test"))).build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withRequestMethod("GET").withSelectors(new LinkedHashSet<>(Arrays.asList("test"))).withRequestExtension("txt").build(),
- ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("test"))).withRequestExtension("txt").build(),
-
- // sling
- ProvidedResourceTypeCapability.builder().withResourceType("sling").withScriptEngine("htl").withScriptExtension("html").build(),
-
- // sling/test
- ProvidedResourceTypeCapability.builder().withResourceType("/libs/sling/test").withResourceType("sling/test").withScriptEngine("htl").withScriptExtension("html").build()
- ));
-
- Set<RequiredResourceTypeCapability> rExpected = new HashSet<>(Arrays.asList(
- RequiredResourceTypeCapability.builder().withResourceType("sling/default").withVersionRange(VersionRange.valueOf("[1.0.0,2.0.0)")).build(),
- RequiredResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").build(),
- RequiredResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withVersionRange(VersionRange.valueOf("[1.0.0,2.0.0)")).build()
- ));
- Set<ProvidedScriptCapability> providedScriptCapabilities = new HashSet<>(Arrays.asList(
- ProvidedScriptCapability.builder(mojoProject.mojo.getScriptEngineMappings())
- .withPath("/org.apache.sling.wrongbar/wrongbar.has.too.many.selectors.html").build()
- ));
- verifyCapabilities(capabilities, pExpected, rExpected, providedScriptCapabilities);
+ try {
+ mojoProject.mojo.execute();
+ Capabilities capabilities = mojoProject.mojo.getCapabilities();
+ Set<ProvidedResourceTypeCapability> pExpected = new HashSet<>(Arrays.asList(
+ // org/apache/sling/bar/1.0.0
+ ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
+ .withScriptExtension("html").withVersion("1.0.0").build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
+ .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+ , "100"))).build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
+ .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+ , "200"))).build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
+ .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+ , "depth2", "100"))).build(),
+
+ // org/apache/sling/foo
+ ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl")
+ .withScriptExtension("html").build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl")
+ .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+ , "100"))).build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl")
+ .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+ , "200"))).build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl")
+ .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+ , "depth2", "100"))).build(),
+
+ // org/apache/sling/foo/depth1/depth2/depth3
+ ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1/depth2/depth3")
+ .withExtendsResourceType("org" +
+ "/apache/sling/bar").build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1/depth2/depth3")
+ .withScriptEngine("htl").withScriptExtension("html")
+ .withSelectors(new LinkedHashSet<>(Arrays.asList("depth3-selector"))).build(),
+
+ // org.apache.sling.foobar/1.0.0
+ ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
+ .withScriptExtension("html").withVersion("1.0.0").withExtendsResourceType("org/apache/sling/bar").build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
+ .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+ , "100"))).build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
+ .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+ , "200"))).build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
+ .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+ , "depth2", "100"))).build(),
+
+ // org.apache.sling.foobar
+ ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar")
+ .withExtendsResourceType("org/apache/sling/bar").build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
+ .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+ , "100"))).build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
+ .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+ , "200"))).build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
+ .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+ , "depth2", "100"))).build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
+ .withScriptExtension("html").withRequestMethod("GET").build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
+ .withScriptExtension("html").withRequestMethod("GET").withSelectors(new LinkedHashSet<>(Arrays.asList("test")))
+ .build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
+ .withScriptExtension("html").withRequestMethod("GET").withSelectors(new LinkedHashSet<>(Arrays.asList("test")))
+ .withRequestExtension("txt").build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
+ .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("test")))
+ .withRequestExtension("txt").build(),
+
+ // sling
+ ProvidedResourceTypeCapability.builder().withResourceType("sling").withScriptEngine("htl").withScriptExtension("html")
+ .build(),
+
+ // sling/test
+ ProvidedResourceTypeCapability.builder().withResourceType("/libs/sling/test").withResourceType("sling/test")
+ .withScriptEngine("htl").withScriptExtension("html").build()
+ ));
+
+ Set<RequiredResourceTypeCapability> rExpected = new HashSet<>(Arrays.asList(
+ RequiredResourceTypeCapability.builder().withResourceType("sling/default")
+ .withVersionRange(VersionRange.valueOf("[1.0.0,2.0.0)")).build(),
+ RequiredResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").build(),
+ RequiredResourceTypeCapability.builder().withResourceType("org/apache/sling/bar")
+ .withVersionRange(VersionRange.valueOf("[1.0.0,2.0.0)")).build()
+ ));
+ Set<ProvidedScriptCapability> providedScriptCapabilities = new HashSet<>(Arrays.asList(
+ ProvidedScriptCapability.builder(mojoProject.mojo.getScriptEngineMappings())
+ .withPath("/org.apache.sling.wrongbar/wrongbar.has.too.many.selectors.html").build()
+ ));
+ verifyCapabilities(capabilities, pExpected, rExpected, providedScriptCapabilities);
+ } finally {
+ FileUtils.forceDeleteOnExit(new File(mojoProject.project.getBuild().getDirectory()));
+ }
}
@Test
public void testProject2() throws Exception {
MojoProject mojoProject = getMojoProject(getProjectLocation("project-2"));
- mojoProject.mojo.execute();
- Capabilities capabilities = mojoProject.mojo.getCapabilities();
- Map<String, String> scriptEngineMappings = mojoProject.mojo.getScriptEngineMappings();
- Set<ProvidedResourceTypeCapability> pExpected = new HashSet<>(Arrays.asList(
- ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/test").withScriptEngine("thymeleaf").withScriptExtension("html").build(),
- ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/test").withScriptEngine("rhino").withScriptExtension("js").withSelectors(new HashSet<>(Arrays.asList("merged"))).build(),
- ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/test2").withScriptEngine("jsp").withScriptExtension("jsp").withRequestExtension("html").build()
- ));
- Set<ProvidedScriptCapability> expectedScriptCapabilities = new HashSet<>(Arrays.asList(
- ProvidedScriptCapability.builder(scriptEngineMappings).withPath("/libs/sling/commons/template.html").build(),
- ProvidedScriptCapability.builder(scriptEngineMappings).withPath("/libs/sling/utils/initialiseWarpDrive.html").build()
- ));
- Set<RequiredResourceTypeCapability> expectedRequired = new HashSet<>(Arrays.asList(
- RequiredResourceTypeCapability.builder().withResourceType("sling/scripting/warpDrive").withVersionRange(VersionRange.valueOf("[1.0.0,2.0.0)")).build()
- ));
- verifyCapabilities(capabilities, pExpected, expectedRequired, expectedScriptCapabilities);
+ try {
+ mojoProject.mojo.execute();
+ Capabilities capabilities = mojoProject.mojo.getCapabilities();
+ Map<String, String> scriptEngineMappings = mojoProject.mojo.getScriptEngineMappings();
+ Set<ProvidedResourceTypeCapability> pExpected = new HashSet<>(Arrays.asList(
+ ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/test").withScriptEngine("thymeleaf")
+ .withScriptExtension("html").build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/test").withScriptEngine("rhino")
+ .withScriptExtension("js").withSelectors(new HashSet<>(Arrays.asList("merged"))).build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/test2").withScriptEngine("jsp")
+ .withScriptExtension("jsp").withRequestExtension("html").build()
+ ));
+ Set<ProvidedScriptCapability> expectedScriptCapabilities = new HashSet<>(Arrays.asList(
+ ProvidedScriptCapability.builder(scriptEngineMappings).withPath("/libs/sling/commons/template.html").build(),
+ ProvidedScriptCapability.builder(scriptEngineMappings).withPath("/libs/sling/utils/initialiseWarpDrive.html").build()
+ ));
+ Set<RequiredResourceTypeCapability> expectedRequired = new HashSet<>(Arrays.asList(
+ RequiredResourceTypeCapability.builder().withResourceType("sling/scripting/warpDrive")
+ .withVersionRange(VersionRange.valueOf("[1.0.0,2.0.0)")).build()
+ ));
+ verifyCapabilities(capabilities, pExpected, expectedRequired, expectedScriptCapabilities);
+ } finally {
+ FileUtils.forceDeleteOnExit(new File(mojoProject.project.getBuild().getDirectory()));
+ }
+ }
+
+ @Test
+ public void testIncludeExcludes() throws Exception {
+ MojoProject mojoProject = getMojoProject(getProjectLocation("project-3"));
+ try {
+ mojoProject.mojo.execute();
+ Capabilities capabilities = mojoProject.mojo.getCapabilities();
+ Set<ProvidedResourceTypeCapability> pExpected = new HashSet<>(Arrays.asList(
+ ProvidedResourceTypeCapability.builder().withResourceType("sling/scriptingbundle/includeexclude")
+ .withScriptEngine("htl").withScriptExtension("html").build(),
+ ProvidedResourceTypeCapability.builder().withResourceType("sling/scriptingbundle/includeexclude")
+ .withSelectors(new HashSet<>(Arrays.asList("selector"))).withScriptEngine("htl").withScriptExtension("html")
+ .build()
+ ));
+ verifyCapabilities(capabilities, pExpected, Collections.emptySet(), Collections.emptySet());
+ } finally {
+ FileUtils.forceDeleteOnExit(new File(mojoProject.project.getBuild().getDirectory()));
+ }
}
private void verifyCapabilities(Capabilities capabilities, Set<ProvidedResourceTypeCapability> pExpected,
diff --git a/src/test/resources/project-3/pom.xml b/src/test/resources/project-3/pom.xml
new file mode 100644
index 0000000..6a29f5a
--- /dev/null
+++ b/src/test/resources/project-3/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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>scriptingbundle-maven-plugin-project-1</artifactId>
+ <version>0.0.1</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>scriptingbundle-maven-plugin</artifactId>
+ <configuration>
+ <includes>**/*.html</includes>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>metadata</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/test/resources/project-3/src/main/resources/javax.script/sling/scriptingbundle/includeexclude/includeexclude.jsp b/src/test/resources/project-3/src/main/resources/javax.script/sling/scriptingbundle/includeexclude/includeexclude.jsp
new file mode 100644
index 0000000..40d389e
--- /dev/null
+++ b/src/test/resources/project-3/src/main/resources/javax.script/sling/scriptingbundle/includeexclude/includeexclude.jsp
@@ -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.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--%>
diff --git a/src/test/resources/project-3/src/main/resources/javax.script/sling/scriptingbundle/includeexclude/selector.html b/src/test/resources/project-3/src/main/resources/javax.script/sling/scriptingbundle/includeexclude/selector.html
new file mode 100644
index 0000000..e69de29
diff --git a/src/test/resources/project-3/src/main/scripts/sling/scriptingbundle/includeexclude/includeexclude.html b/src/test/resources/project-3/src/main/scripts/sling/scriptingbundle/includeexclude/includeexclude.html
new file mode 100644
index 0000000..e69de29
diff --git a/src/test/resources/project-3/src/main/scripts/sling/scriptingbundle/includeexclude/selector.jsp b/src/test/resources/project-3/src/main/scripts/sling/scriptingbundle/includeexclude/selector.jsp
new file mode 100644
index 0000000..40d389e
--- /dev/null
+++ b/src/test/resources/project-3/src/main/scripts/sling/scriptingbundle/includeexclude/selector.jsp
@@ -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.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--%>