diff --git a/pom.xml b/pom.xml index 5d351dd..0425d97 100644 --- a/pom.xml +++ b/pom.xml @@ -18,14 +18,14 @@ ~ under the License. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> + 4.0.0 org.apache.sling sling - 46 + 60 - 4.0.0 scriptingbundle-maven-plugin 0.5.3-SNAPSHOT @@ -37,100 +37,33 @@ which can be used to populate the Provide-Capability and Require-Capability bundle headers. https://sling.apache.org/components/scriptingbundle-maven-plugin/ + + ${maven.version} + + scm:git:https://gitbox.apache.org/repos/asf/sling-scriptingbundle-maven-plugin.git scm:git:https://gitbox.apache.org/repos/asf/sling-scriptingbundle-maven-plugin.git - https://github.com/apache/sling-scriptingbundle-maven-plugin/tree/${project.scm.tag} HEAD + https://github.com/apache/sling-scriptingbundle-maven-plugin/tree/${project.scm.tag} + + + staging + file:${project.build.directory}/staging + + + 8 - 3.6.0 + 3.8.8 12344664,12347157,12348422,12350010,12350474,12350606 ${project.artifactId}-archives/${project.artifactId}-LATEST 2021-12-16T14:04:46Z apache/sling-scriptingbundle-maven-plugin - - ${maven.version} - - - - - - org.apache.maven.plugins - maven-plugin-plugin - - - mojo-descriptor - process-classes - - descriptor - - - - generated-helpmojo - - helpmojo - - - - - true - - - - org.apache.rat - apache-rat-plugin - - - **/*.iml - **/target/**/* - src/site/markdown/** - src/test/resources/**/extends - src/test/resources/**/requires - src/test/resources/**/wrongbar - src/test/resources/extends/* - src/test/resources/requires/* - - - - - org.apache.maven.plugins - maven-scm-publish-plugin - - ${user.home}/maven-sites/${maven.site.path} - true - - - - com.github.spotbugs - spotbugs-maven-plugin - 4.3.0 - - Max - true - src/test/resources/spotbugs-exclude.xml - - - - find-bugs - process-classes - - check - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - - @@ -157,7 +90,7 @@ org.apache.maven - maven-aether-provider + maven-artifact ${maven.version} @@ -167,23 +100,33 @@ org.jetbrains annotations + provided org.apache.maven maven-plugin-api + provided org.apache.maven maven-model + provided org.apache.maven maven-core + provided org.apache.maven maven-compat + provided + + + org.apache.maven + maven-artifact + provided org.apache.maven.plugin-tools @@ -200,8 +143,8 @@ org.apache.sling org.apache.sling.scripting.spi - compile 1.0.2 + compile org.apache.sling @@ -248,6 +191,12 @@ 3.0.22 compile + + commons-io + commons-io + 2.16.1 + compile + org.apache.maven.plugin-testing maven-plugin-testing-harness @@ -267,6 +216,80 @@ + + + + org.apache.maven.plugins + maven-plugin-plugin + + true + + + + mojo-descriptor + + descriptor + + process-classes + + + generated-helpmojo + + helpmojo + + + + + + org.apache.rat + apache-rat-plugin + + + **/*.iml + **/target/**/* + src/site/markdown/** + src/test/resources/**/extends + src/test/resources/**/requires + src/test/resources/**/wrongbar + src/test/resources/extends/* + src/test/resources/requires/* + + + + + org.apache.maven.plugins + maven-scm-publish-plugin + + ${user.home}/maven-sites/${maven.site.path} + true + + + + com.github.spotbugs + spotbugs-maven-plugin + 4.3.0 + + Max + true + src/test/resources/spotbugs-exclude.xml + + + + find-bugs + + check + + process-classes + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + @@ -286,11 +309,4 @@ - - - staging - file:${project.build.directory}/staging - - - diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/bnd/BndLogger.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/bnd/BndLogger.java index fb96b12..1baa07f 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/bnd/BndLogger.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/bnd/BndLogger.java @@ -1,28 +1,27 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.bnd; -import org.apache.sling.scriptingbundle.plugin.processor.Logger; -import org.jetbrains.annotations.NotNull; - import aQute.lib.exceptions.Exceptions; import aQute.service.reporter.Reporter; +import org.apache.sling.scriptingbundle.plugin.processor.Logger; +import org.jetbrains.annotations.NotNull; public class BndLogger implements Logger { diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPlugin.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPlugin.java index d7893cc..652a893 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPlugin.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPlugin.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.bnd; import java.io.IOException; @@ -35,15 +35,14 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.commons.lang3.StringUtils; -import org.apache.sling.scriptingbundle.plugin.capability.Capabilities; -import org.apache.sling.scriptingbundle.plugin.processor.Constants; -import org.apache.sling.scriptingbundle.plugin.processor.Logger; - import aQute.bnd.osgi.Analyzer; import aQute.bnd.service.AnalyzerPlugin; import aQute.bnd.service.Plugin; import aQute.service.reporter.Reporter; +import org.apache.commons.lang3.StringUtils; +import org.apache.sling.scriptingbundle.plugin.capability.Capabilities; +import org.apache.sling.scriptingbundle.plugin.processor.Constants; +import org.apache.sling.scriptingbundle.plugin.processor.Logger; public class BundledScriptsScannerPlugin implements AnalyzerPlugin, Plugin { @@ -66,35 +65,44 @@ public boolean analyzeJar(Analyzer analyzer) throws Exception { Files.createDirectories(workDirectory); Set includes = getConfiguredIncludes(); Set excludes = getConfiguredExcludes(); - getConfiguredSourceDirectories().stream().map(sourceDirectory -> { - Path sourceDirectoryPath = Paths.get(sourceDirectory); - if (!Files.exists(sourceDirectoryPath)) { - sourceDirectoryPath = Paths.get(analyzer.get(PROJECT_ROOT_FOLDER), sourceDirectory); - } - return sourceDirectoryPath; - }).filter(sourceDirectoryPath -> Files.exists(sourceDirectoryPath) && Files.isDirectory(sourceDirectoryPath)).forEach(sourceDirectoryPath -> { - try (Stream includedFiles = walkPath(sourceDirectoryPath, includes, excludes)) { - includedFiles.forEach( - file -> { - try { - if (!Files.isDirectory(file)) { - Path workingCopy = Paths.get(workDirectory.toString(), sourceDirectoryPath.relativize(file).toString()); - Files.createDirectories(workingCopy.getParent()); - Files.copy(file, workingCopy, StandardCopyOption.REPLACE_EXISTING); + getConfiguredSourceDirectories().stream() + .map(sourceDirectory -> { + Path sourceDirectoryPath = Paths.get(sourceDirectory); + if (!Files.exists(sourceDirectoryPath)) { + sourceDirectoryPath = Paths.get(analyzer.get(PROJECT_ROOT_FOLDER), sourceDirectory); + } + return sourceDirectoryPath; + }) + .filter(sourceDirectoryPath -> + Files.exists(sourceDirectoryPath) && Files.isDirectory(sourceDirectoryPath)) + .forEach(sourceDirectoryPath -> { + try (Stream includedFiles = walkPath(sourceDirectoryPath, includes, excludes)) { + includedFiles.forEach(file -> { + try { + if (!Files.isDirectory(file)) { + Path workingCopy = Paths.get( + workDirectory.toString(), + sourceDirectoryPath.relativize(file).toString()); + Files.createDirectories(workingCopy.getParent()); + Files.copy(file, workingCopy, StandardCopyOption.REPLACE_EXISTING); + } + } catch (IOException e) { + logger.error("Cannot copy file into working directory.", e); } - } catch (IOException e) { - logger.error("Cannot copy file into working directory.", e); - } + }); + } catch (IOException e) { + logger.error("Cannot analyse source folders.", e); } - ); - } catch (IOException e) { - logger.error("Cannot analyse source folders.", e); - } - }); + }); scriptEngineMappings = getConfiguredScriptEngineMappings(); - capabilities = Capabilities - .fromFileSystemTree(workDirectory, walkPath(workDirectory, includes, excludes), logger, - getConfiguredSearchPaths(), scriptEngineMappings, getMissingRequirementsOptional(), inContentPackage); + capabilities = Capabilities.fromFileSystemTree( + workDirectory, + walkPath(workDirectory, includes, excludes), + logger, + getConfiguredSearchPaths(), + scriptEngineMappings, + getMissingRequirementsOptional(), + inContentPackage); String providedCapabilitiesDefinition = capabilities.getProvidedCapabilitiesString(); String requiredCapabilitiesDefinition = capabilities.getRequiredCapabilitiesString(); @@ -137,7 +145,9 @@ public Map getScriptEngineMappings() { private Set getConfiguredSourceDirectories() { String sourceDirectoriesCSV = pluginProperties.get(Constants.BND_SOURCE_DIRECTORIES); if (StringUtils.isNotEmpty(sourceDirectoriesCSV)) { - return Collections.unmodifiableSet(Arrays.stream(sourceDirectoriesCSV.split(",")).map(String::trim).collect(Collectors.toSet())); + return Collections.unmodifiableSet(Arrays.stream(sourceDirectoriesCSV.split(",")) + .map(String::trim) + .collect(Collectors.toSet())); } return Constants.DEFAULT_SOURCE_DIRECTORIES; } @@ -145,20 +155,23 @@ private Set getConfiguredSourceDirectories() { private Set getConfiguredExcludes() { String excludesCSV = pluginProperties.get(Constants.BND_EXCLUDES); if (StringUtils.isNotEmpty(excludesCSV)) { - return Collections.unmodifiableSet(Arrays.stream(excludesCSV.split(",")).map(String::trim) - .map(pattern -> FileSystems.getDefault().getPathMatcher(GLOB + pattern)).collect( - Collectors.toSet())); + return Collections.unmodifiableSet(Arrays.stream(excludesCSV.split(",")) + .map(String::trim) + .map(pattern -> FileSystems.getDefault().getPathMatcher(GLOB + pattern)) + .collect(Collectors.toSet())); } - return Collections.unmodifiableSet(Constants.DEFAULT_EXCLUDES.stream().map(pattern -> FileSystems.getDefault().getPathMatcher(GLOB + pattern)) + return Collections.unmodifiableSet(Constants.DEFAULT_EXCLUDES.stream() + .map(pattern -> FileSystems.getDefault().getPathMatcher(GLOB + pattern)) .collect(Collectors.toSet())); } private Set getConfiguredIncludes() { String includesCSV = pluginProperties.get(Constants.BND_INCLUDES); if (StringUtils.isNotEmpty(includesCSV)) { - return Collections.unmodifiableSet(Arrays.stream(includesCSV.split(",")).map(String::trim) - .map(pattern -> FileSystems.getDefault().getPathMatcher(GLOB + pattern)).collect( - Collectors.toSet())); + return Collections.unmodifiableSet(Arrays.stream(includesCSV.split(",")) + .map(String::trim) + .map(pattern -> FileSystems.getDefault().getPathMatcher(GLOB + pattern)) + .collect(Collectors.toSet())); } return Collections.emptySet(); } @@ -167,8 +180,9 @@ private Map getConfiguredScriptEngineMappings() { HashMap mappings = new HashMap<>(Constants.DEFAULT_EXTENSION_TO_SCRIPT_ENGINE_MAPPING); String scriptEngineMappingsCSV = pluginProperties.get(Constants.BND_SCRIPT_ENGINE_MAPPINGS); if (StringUtils.isNotEmpty(scriptEngineMappingsCSV)) { - List extensionEngineMappings = - Arrays.stream(scriptEngineMappingsCSV.split(",")).map(String::trim).collect(Collectors.toList()); + List extensionEngineMappings = Arrays.stream(scriptEngineMappingsCSV.split(",")) + .map(String::trim) + .collect(Collectors.toList()); extensionEngineMappings.forEach(mapping -> { String[] mappingArray = mapping.split(":"); if (mappingArray.length != 2) { @@ -184,7 +198,9 @@ private Map getConfiguredScriptEngineMappings() { private Set getConfiguredSearchPaths() { String searchPathsString = pluginProperties.get(Constants.BND_SEARCH_PATHS); if (StringUtils.isNotEmpty(searchPathsString)) { - return Collections.unmodifiableSet(Arrays.stream(searchPathsString.split(",")).map(String::trim).collect(Collectors.toSet())); + return Collections.unmodifiableSet(Arrays.stream(searchPathsString.split(",")) + .map(String::trim) + .collect(Collectors.toSet())); } return Constants.DEFAULT_SEARCH_PATHS; } @@ -192,30 +208,36 @@ private Set getConfiguredSearchPaths() { private boolean getMissingRequirementsOptional() { String missingRequirementsOptionalString = pluginProperties.get(Constants.BND_MISSING_REQUIREMENTS_OPTIONAL); if (missingRequirementsOptionalString != null) { - missingRequirementsOptionalString = missingRequirementsOptionalString.trim().toLowerCase(); + missingRequirementsOptionalString = + missingRequirementsOptionalString.trim().toLowerCase(); return !"false".equals(missingRequirementsOptionalString); } return true; } private Stream walkPath(Path path, Set includes, Set excludes) throws IOException { - return Files.walk(path).filter(file -> { - boolean include = includes.isEmpty(); - Optional includeOptions = includes.stream().filter(pathMatcher -> pathMatcher.matches(file)).findFirst(); - if (includeOptions.isPresent()) { - include = true; - } - Optional excludeOptions = excludes.stream().filter(pathMatcher -> pathMatcher.matches(file)).findFirst(); - if (excludeOptions.isPresent()) { - include = false; - } - return include; - }).flatMap(file -> { - if (!Files.isDirectory(file)) { - return Stream.of(file, file.getParent()); - } - return Stream.of(file); - }); + return Files.walk(path) + .filter(file -> { + boolean include = includes.isEmpty(); + Optional includeOptions = includes.stream() + .filter(pathMatcher -> pathMatcher.matches(file)) + .findFirst(); + if (includeOptions.isPresent()) { + include = true; + } + Optional excludeOptions = excludes.stream() + .filter(pathMatcher -> pathMatcher.matches(file)) + .findFirst(); + if (excludeOptions.isPresent()) { + include = false; + } + return include; + }) + .flatMap(file -> { + if (!Files.isDirectory(file)) { + return Stream.of(file, file.getParent()); + } + return Stream.of(file); + }); } - } diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/Capabilities.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/Capabilities.java index 4cf9179..4791153 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/Capabilities.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/Capabilities.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.capability; import java.nio.file.Files; @@ -27,6 +27,8 @@ import java.util.Set; import java.util.stream.Stream; +import aQute.bnd.header.Attrs; +import aQute.bnd.header.Parameters; import org.apache.sling.api.servlets.ServletResolverConstants; import org.apache.sling.scriptingbundle.plugin.processor.Constants; import org.apache.sling.scriptingbundle.plugin.processor.FileProcessor; @@ -36,15 +38,13 @@ import org.jetbrains.annotations.NotNull; import org.osgi.framework.VersionRange; -import aQute.bnd.header.Attrs; -import aQute.bnd.header.Parameters; - public class Capabilities { private final Set providedResourceTypeCapabilities; private final Set providedScriptCapabilities; private final Set requiredResourceTypeCapabilities; - public static final Capabilities EMPTY = new Capabilities(Collections.emptySet(), Collections.emptySet(), Collections.emptySet()); + public static final Capabilities EMPTY = + new Capabilities(Collections.emptySet(), Collections.emptySet(), Collections.emptySet()); public Capabilities( @NotNull Set providedResourceTypeCapabilities, @@ -72,24 +72,22 @@ public Capabilities( for (ProvidedResourceTypeCapability capability : getProvidedResourceTypeCapabilities()) { Attrs attributes = new Attrs(); attributes.putTyped(Constants.CAPABILITY_RESOURCE_TYPE_AT, capability.getResourceTypes()); - Optional.ofNullable(capability.getScriptEngine()).ifPresent(scriptEngine -> - attributes.put(Constants.CAPABILITY_SCRIPT_ENGINE_AT, scriptEngine) - ); - Optional.ofNullable(capability.getScriptExtension()).ifPresent(scriptExtension -> - attributes.put(Constants.CAPABILITY_SCRIPT_EXTENSION_AT, scriptExtension) - ); - Optional.ofNullable(capability.getVersion()).ifPresent(version -> - attributes.putTyped(Constants.CAPABILITY_VERSION_AT, new aQute.bnd.version.Version(version.toString())) - ); - Optional.ofNullable(capability.getExtendsResourceType()).ifPresent(extendedResourceType -> - attributes.put(Constants.CAPABILITY_EXTENDS_AT, extendedResourceType) - ); - Optional.ofNullable(capability.getRequestMethod()).ifPresent(method -> - attributes.put(Constants.CAPABILITY_METHODS_AT, method) - ); - Optional.ofNullable(capability.getRequestExtension()).ifPresent(requestExtension -> - attributes.put(Constants.CAPABILITY_EXTENSIONS_AT, requestExtension) - ); + Optional.ofNullable(capability.getScriptEngine()) + .ifPresent(scriptEngine -> attributes.put(Constants.CAPABILITY_SCRIPT_ENGINE_AT, scriptEngine)); + Optional.ofNullable(capability.getScriptExtension()) + .ifPresent(scriptExtension -> + attributes.put(Constants.CAPABILITY_SCRIPT_EXTENSION_AT, scriptExtension)); + Optional.ofNullable(capability.getVersion()) + .ifPresent(version -> attributes.putTyped( + Constants.CAPABILITY_VERSION_AT, new aQute.bnd.version.Version(version.toString()))); + Optional.ofNullable(capability.getExtendsResourceType()) + .ifPresent(extendedResourceType -> + attributes.put(Constants.CAPABILITY_EXTENDS_AT, extendedResourceType)); + Optional.ofNullable(capability.getRequestMethod()) + .ifPresent(method -> attributes.put(Constants.CAPABILITY_METHODS_AT, method)); + Optional.ofNullable(capability.getRequestExtension()) + .ifPresent( + requestExtension -> attributes.put(Constants.CAPABILITY_EXTENSIONS_AT, requestExtension)); if (!capability.getSelectors().isEmpty()) { attributes.putTyped(Constants.CAPABILITY_SELECTORS_AT, capability.getSelectors()); } @@ -111,15 +109,27 @@ public Capabilities( for (RequiredResourceTypeCapability capability : getRequiredResourceTypeCapabilities()) { Attrs attributes = new Attrs(); - StringBuilder filterValue = new StringBuilder("(&(!(" + ServletResolverConstants.SLING_SERVLET_SELECTORS + "=*))"); + StringBuilder filterValue = + new StringBuilder("(&(!(" + ServletResolverConstants.SLING_SERVLET_SELECTORS + "=*))"); VersionRange versionRange = capability.getVersionRange(); if (versionRange != null) { - filterValue.append("(&").append(versionRange.toFilterString("version")).append("(").append(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES).append( - "=").append(capability.getResourceType()).append(")))"); + filterValue + .append("(&") + .append(versionRange.toFilterString("version")) + .append("(") + .append(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES) + .append("=") + .append(capability.getResourceType()) + .append(")))"); } else { - filterValue.append("(").append(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES).append("=").append(capability.getResourceType()).append("))"); + filterValue + .append("(") + .append(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES) + .append("=") + .append(capability.getResourceType()) + .append("))"); } - + attributes.put(aQute.bnd.osgi.Constants.FILTER_DIRECTIVE, filterValue.toString()); if (capability.isOptional()) { attributes.put(aQute.bnd.osgi.Constants.RESOLUTION_DIRECTIVE, aQute.bnd.osgi.Constants.OPTIONAL); @@ -129,18 +139,22 @@ public Capabilities( return parameters.toString(); } - public static @NotNull Capabilities fromFileSystemTree(@NotNull Path root, @NotNull Stream files, @NotNull Logger logger, - @NotNull Set searchPaths, - @NotNull Map scriptEngineMappings, - boolean missingRequirementsOptional, - boolean inContentPackage) { + public static @NotNull Capabilities fromFileSystemTree( + @NotNull Path root, + @NotNull Stream files, + @NotNull Logger logger, + @NotNull Set searchPaths, + @NotNull Map scriptEngineMappings, + boolean missingRequirementsOptional, + boolean inContentPackage) { Set providedResourceTypeCapabilities = new LinkedHashSet<>(); Set providedScriptCapabilities = new LinkedHashSet<>(); Set requiredResourceTypeCapabilities = new LinkedHashSet<>(); FileProcessor fileProcessor = new FileProcessor(logger, searchPaths, scriptEngineMappings); - ResourceTypeFolderAnalyser resourceTypeFolderAnalyser = new ResourceTypeFolderAnalyser(logger, root, fileProcessor, inContentPackage); - PathOnlyScriptAnalyser - pathOnlyScriptAnalyser = new PathOnlyScriptAnalyser(logger, root, scriptEngineMappings, fileProcessor, inContentPackage); + ResourceTypeFolderAnalyser resourceTypeFolderAnalyser = + new ResourceTypeFolderAnalyser(logger, root, fileProcessor, inContentPackage); + PathOnlyScriptAnalyser pathOnlyScriptAnalyser = + new PathOnlyScriptAnalyser(logger, root, scriptEngineMappings, fileProcessor, inContentPackage); files.forEach(path -> { if (Files.isDirectory(path)) { Capabilities resourceTypeCapabilities = resourceTypeFolderAnalyser.getCapabilities(path); @@ -156,15 +170,17 @@ public Capabilities( if (missingRequirementsOptional) { Set unresolvedRequiredResourceTypeCapabilities = new LinkedHashSet<>(requiredResourceTypeCapabilities); - providedResourceTypeCapabilities.forEach(providedResourceTypeCapability -> unresolvedRequiredResourceTypeCapabilities - .removeIf( - requiredResourceTypeCapability -> requiredResourceTypeCapability.isSatisfied(providedResourceTypeCapability))); + providedResourceTypeCapabilities.forEach(providedResourceTypeCapability -> + unresolvedRequiredResourceTypeCapabilities.removeIf(requiredResourceTypeCapability -> + requiredResourceTypeCapability.isSatisfied(providedResourceTypeCapability))); requiredResourceTypeCapabilities.forEach(requiredResourceTypeCapability -> { if (unresolvedRequiredResourceTypeCapabilities.contains(requiredResourceTypeCapability)) { - required.add( - RequiredResourceTypeCapability.builder().withResourceType(requiredResourceTypeCapability.getResourceType()) - .withVersionRange(requiredResourceTypeCapability.getVersionRange()).withIsOptional().build()); + required.add(RequiredResourceTypeCapability.builder() + .withResourceType(requiredResourceTypeCapability.getResourceType()) + .withVersionRange(requiredResourceTypeCapability.getVersionRange()) + .withIsOptional() + .build()); } else { required.add(requiredResourceTypeCapability); } @@ -174,5 +190,4 @@ public Capabilities( } return new Capabilities(providedResourceTypeCapabilities, providedScriptCapabilities, required); } - } diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedResourceTypeCapability.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedResourceTypeCapability.java index 0495be8..607356c 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedResourceTypeCapability.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedResourceTypeCapability.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.capability; import java.util.Arrays; @@ -41,10 +41,15 @@ public class ProvidedResourceTypeCapability { private final String requestMethod; private final List selectors; - private ProvidedResourceTypeCapability(@NotNull Set resourceTypes, @Nullable String scriptEngine, - @Nullable String scriptExtension, @Nullable String extendsResourceType, - @Nullable Version version, @Nullable String requestExtension, @Nullable String requestMethod, - @NotNull List selectors) { + private ProvidedResourceTypeCapability( + @NotNull Set resourceTypes, + @Nullable String scriptEngine, + @Nullable String scriptExtension, + @Nullable String extendsResourceType, + @Nullable Version version, + @Nullable String requestExtension, + @Nullable String requestMethod, + @NotNull List selectors) { this.resourceTypes = resourceTypes; this.scriptEngine = scriptEngine; this.scriptExtension = scriptExtension; @@ -101,9 +106,15 @@ public List getSelectors() { @Override public int hashCode() { - return Objects - .hash(resourceTypes, scriptEngine, scriptExtension, version, requestExtension, extendsResourceType, requestMethod, - selectors); + return Objects.hash( + resourceTypes, + scriptEngine, + scriptExtension, + version, + requestExtension, + extendsResourceType, + requestMethod, + selectors); } @Override @@ -113,11 +124,14 @@ public boolean equals(Object obj) { } if (obj instanceof ProvidedResourceTypeCapability) { ProvidedResourceTypeCapability other = (ProvidedResourceTypeCapability) obj; - return Objects.equals(resourceTypes, other.resourceTypes) && Objects.equals(scriptEngine, other.scriptEngine) && - Objects.equals(scriptExtension, other.scriptExtension) && - Objects.equals(version, other.version) && Objects.equals(requestExtension, other.requestExtension) && - Objects.equals(extendsResourceType, other.extendsResourceType) && Objects.equals(requestMethod, other.requestMethod) && - Objects.equals(selectors, other.selectors); + return Objects.equals(resourceTypes, other.resourceTypes) + && Objects.equals(scriptEngine, other.scriptEngine) + && Objects.equals(scriptExtension, other.scriptExtension) + && Objects.equals(version, other.version) + && Objects.equals(requestExtension, other.requestExtension) + && Objects.equals(extendsResourceType, other.extendsResourceType) + && Objects.equals(requestMethod, other.requestMethod) + && Objects.equals(selectors, other.selectors); } return false; } @@ -125,12 +139,17 @@ public boolean equals(Object obj) { @Override public String toString() { return String.format( - "%s{resourceTypes=%s, scriptEngine=%s, scriptEngineExtension=%s, version=%s, selectors=%s, requestExtension=%s, " + - "requestMethod=%s, extendsResourceType=%s}", - this.getClass().getSimpleName(), resourceTypes, scriptEngine, scriptExtension, version, selectors, requestExtension, + "%s{resourceTypes=%s, scriptEngine=%s, scriptEngineExtension=%s, version=%s, selectors=%s, requestExtension=%s, " + + "requestMethod=%s, extendsResourceType=%s}", + this.getClass().getSimpleName(), + resourceTypes, + scriptEngine, + scriptExtension, + version, + selectors, + requestExtension, requestMethod, - extendsResourceType - ); + extendsResourceType); } public static class Builder { @@ -217,10 +236,16 @@ public Builder fromCapability(@NotNull ProvidedResourceTypeCapability capability return this; } - public ProvidedResourceTypeCapability build() { - return new ProvidedResourceTypeCapability(resourceTypes, scriptEngine, scriptExtension, extendsResourceType, version, - requestExtension, requestMethod, selectors); + return new ProvidedResourceTypeCapability( + resourceTypes, + scriptEngine, + scriptExtension, + extendsResourceType, + version, + requestExtension, + requestMethod, + selectors); } } } diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedScriptCapability.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedScriptCapability.java index 2a6380a..92b2f01 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedScriptCapability.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedScriptCapability.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.capability; import java.util.Map; @@ -30,7 +30,8 @@ public class ProvidedScriptCapability { private final String scriptExtension; private final String scriptEngine; - private ProvidedScriptCapability(@NotNull String path, @NotNull String scriptExtension, @NotNull String scriptEngine) { + private ProvidedScriptCapability( + @NotNull String path, @NotNull String scriptExtension, @NotNull String scriptEngine) { this.path = path; this.scriptExtension = scriptExtension; this.scriptEngine = scriptEngine; @@ -64,16 +65,18 @@ public boolean equals(Object obj) { } if (obj instanceof ProvidedScriptCapability) { ProvidedScriptCapability other = (ProvidedScriptCapability) obj; - return Objects.equals(path, other.path) && Objects.equals(scriptExtension, other.scriptExtension) && - Objects.equals(scriptEngine, other.scriptEngine); + return Objects.equals(path, other.path) + && Objects.equals(scriptExtension, other.scriptExtension) + && Objects.equals(scriptEngine, other.scriptEngine); } return false; } @Override public String toString() { - return String.format("%s { path=%s; scriptExtension=%s; scriptEngine=%s }", ProvidedScriptCapability.class.getSimpleName(), path, - scriptExtension, scriptEngine); + return String.format( + "%s { path=%s; scriptExtension=%s; scriptEngine=%s }", + ProvidedScriptCapability.class.getSimpleName(), path, scriptExtension, scriptEngine); } public static class Builder { @@ -92,8 +95,8 @@ public ProvidedScriptCapability build() { String extension = path.substring(lastDotIndex + 1); String scriptEngine = scriptEngineMappings.get(extension); if (StringUtils.isEmpty(scriptEngine)) { - throw new IllegalStateException(String.format("Path %s does not seem to have an extension mapped to a script engine.", - path)); + throw new IllegalStateException( + String.format("Path %s does not seem to have an extension mapped to a script engine.", path)); } return new ProvidedScriptCapability(path, extension, scriptEngine); } @@ -106,5 +109,4 @@ public ProvidedScriptCapability.Builder withPath(String path) { return this; } } - } diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/RequiredResourceTypeCapability.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/RequiredResourceTypeCapability.java index b7a2df2..4a37255 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/RequiredResourceTypeCapability.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/RequiredResourceTypeCapability.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.capability; import java.util.List; @@ -33,7 +33,8 @@ public class RequiredResourceTypeCapability { private final VersionRange versionRange; private final boolean isOptional; - private RequiredResourceTypeCapability(@NotNull String resourceType, @Nullable VersionRange versionRange, boolean isOptional) { + private RequiredResourceTypeCapability( + @NotNull String resourceType, @Nullable VersionRange versionRange, boolean isOptional) { this.resourceType = resourceType; this.versionRange = versionRange; this.isOptional = isOptional; @@ -78,8 +79,9 @@ public boolean isSatisfied(@NotNull ProvidedResourceTypeCapability providedResou @Override public String toString() { - return String.format("%s{resourceType=%s, versionRange=%s, isOptional=%s}", this.getClass().getSimpleName(), - resourceType, versionRange, isOptional); + return String.format( + "%s{resourceType=%s, versionRange=%s, isOptional=%s}", + this.getClass().getSimpleName(), resourceType, versionRange, isOptional); } @Override @@ -94,7 +96,9 @@ public boolean equals(Object obj) { } if (obj instanceof RequiredResourceTypeCapability) { RequiredResourceTypeCapability other = (RequiredResourceTypeCapability) obj; - return Objects.equals(resourceType, other.resourceType) && Objects.equals(versionRange, other.versionRange) && Objects.equals(isOptional, other.isOptional); + return Objects.equals(resourceType, other.resourceType) + && Objects.equals(versionRange, other.versionRange) + && Objects.equals(isOptional, other.isOptional); } return false; } @@ -125,6 +129,5 @@ public Builder withIsOptional() { this.isOptional = true; return this; } - } - + } } diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/maven/MavenLogger.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/maven/MavenLogger.java index 77235fa..2e7b00e 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/maven/MavenLogger.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/maven/MavenLogger.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.maven; import org.apache.maven.plugin.logging.Log; diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojo.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojo.java index 1a562e4..3bc8fdb 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojo.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojo.java @@ -1,23 +1,25 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.maven; +import javax.script.ScriptEngineFactory; + import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -32,8 +34,6 @@ import java.util.Map; import java.util.Set; -import javax.script.ScriptEngineFactory; - import org.apache.commons.io.FilenameUtils; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -52,8 +52,7 @@ * {@code org.apache.sling.scriptingbundle.maven.plugin.Provide-Capability} which can be used to generate the * corresponding OSGi bundle headers for bundles providing scripts executable by a {@link javax.script.ScriptEngine}. */ -@Mojo(name = "metadata", - defaultPhase = LifecyclePhase.PREPARE_PACKAGE) +@Mojo(name = "metadata", defaultPhase = LifecyclePhase.PREPARE_PACKAGE) public class MetadataMojo extends AbstractMojo { @Parameter(defaultValue = "${project}", readonly = true, required = true) @@ -186,28 +185,32 @@ public void execute() { if (sourceDirectories.isEmpty()) { sourceDirectories = new HashSet<>(Constants.DEFAULT_SOURCE_DIRECTORIES); } - sourceDirectories.stream().map(sourceDirectory -> { - Path sourceDirectoryPath = Paths.get(sourceDirectory); - if (!Files.exists(sourceDirectoryPath)) { - sourceDirectoryPath = Paths.get(project.getBasedir().getAbsolutePath(), sourceDirectory); - } - return sourceDirectoryPath; - }).filter(sourceDirectory -> Files.exists(sourceDirectory) && Files.isDirectory(sourceDirectory)).forEach(sourceDirectoryPath -> { - DirectoryScanner scanner = getDirectoryScanner(sourceDirectoryPath.toFile()); - Arrays.stream(scanner.getIncludedFiles()).map(sourceDirectoryPath::resolve).forEach( - file -> { - try { - if (!Files.isDirectory(file)) { - Path workingCopy = workDirectory.resolve(sourceDirectoryPath.relativize(file)); - Files.createDirectories(workingCopy.getParent()); - Files.copy(file, workingCopy, StandardCopyOption.REPLACE_EXISTING); - } - } catch (IOException e) { - logger.error("Cannot copy file into working directory.", e); - } + sourceDirectories.stream() + .map(sourceDirectory -> { + Path sourceDirectoryPath = Paths.get(sourceDirectory); + if (!Files.exists(sourceDirectoryPath)) { + sourceDirectoryPath = Paths.get(project.getBasedir().getAbsolutePath(), sourceDirectory); } - ); - }); + return sourceDirectoryPath; + }) + .filter(sourceDirectory -> Files.exists(sourceDirectory) && Files.isDirectory(sourceDirectory)) + .forEach(sourceDirectoryPath -> { + DirectoryScanner scanner = getDirectoryScanner(sourceDirectoryPath.toFile()); + Arrays.stream(scanner.getIncludedFiles()) + .map(sourceDirectoryPath::resolve) + .forEach(file -> { + try { + if (!Files.isDirectory(file)) { + Path workingCopy = + workDirectory.resolve(sourceDirectoryPath.relativize(file)); + Files.createDirectories(workingCopy.getParent()); + Files.copy(file, workingCopy, StandardCopyOption.REPLACE_EXISTING); + } + } catch (IOException e) { + logger.error("Cannot copy file into working directory.", e); + } + }); + }); Map mappings = new HashMap<>(Constants.DEFAULT_EXTENSION_TO_SCRIPT_ENGINE_MAPPING); if (scriptEngineMappings != null) { mappings.putAll(scriptEngineMappings); @@ -222,20 +225,25 @@ public void execute() { scannerPaths.add(FilenameUtils.getFullPath(file)); } capabilities = Capabilities.fromFileSystemTree( - workDirectory, - scannerPaths.stream().map(workDirectory::resolve), - logger, - searchPaths, - scriptEngineMappings, - missingRequirementsOptional, - inContentPackage - ); + workDirectory, + scannerPaths.stream().map(workDirectory::resolve), + logger, + searchPaths, + scriptEngineMappings, + missingRequirementsOptional, + inContentPackage); String providedCapabilitiesDefinition = capabilities.getProvidedCapabilitiesString(); String requiredCapabilitiesDefinition = capabilities.getRequiredCapabilitiesString(); - project.getProperties().put("org.apache.sling.scriptingbundle.maven.plugin." + org.osgi.framework.Constants.PROVIDE_CAPABILITY, - providedCapabilitiesDefinition); - project.getProperties().put("org.apache.sling.scriptingbundle.maven.plugin." + org.osgi.framework.Constants.REQUIRE_CAPABILITY, - requiredCapabilitiesDefinition); + project.getProperties() + .put( + "org.apache.sling.scriptingbundle.maven.plugin." + + org.osgi.framework.Constants.PROVIDE_CAPABILITY, + providedCapabilitiesDefinition); + project.getProperties() + .put( + "org.apache.sling.scriptingbundle.maven.plugin." + + org.osgi.framework.Constants.REQUIRE_CAPABILITY, + requiredCapabilitiesDefinition); } catch (IOException e) { logger.error("Unable to generate working directory.", e); } @@ -266,5 +274,4 @@ Capabilities getCapabilities() { Map getScriptEngineMappings() { return scriptEngineMappings; } - } diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Constants.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Constants.java index 0c38ba8..46b1a18 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Constants.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Constants.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.processor; import java.nio.file.Paths; @@ -32,8 +32,8 @@ public final class Constants { private Constants() {} - public static final Set METHODS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("TRACE", "OPTIONS", "GET", "HEAD", "POST", "PUT", - "DELETE", "PATCH"))); + public static final Set METHODS = Collections.unmodifiableSet( + new HashSet<>(Arrays.asList("TRACE", "OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE", "PATCH"))); public static final String EXTENDS_FILE = "extends"; public static final String REQUIRES_FILE = "requires"; public static final String CAPABILITY_NS = "sling.servlet"; @@ -62,27 +62,36 @@ private Constants() {} public static final Set DEFAULT_SEARCH_PATHS; public static final Set DEFAULT_SOURCE_DIRECTORIES; public static final Set DEFAULT_EXCLUDES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( - // Miscellaneous typical temporary files - "**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*", + // Miscellaneous typical temporary files + "**/*~", + "**/#*#", + "**/.#*", + "**/%*%", + "**/._*", - // CVS - "**/CVS", "**/CVS/**", "**/.cvsignore", + // CVS + "**/CVS", + "**/CVS/**", + "**/.cvsignore", - // Subversion - "**/.svn", "**/.svn/**", + // Subversion + "**/.svn", + "**/.svn/**", - // Bazaar - "**/.bzr", "**/.bzr/**", + // Bazaar + "**/.bzr", + "**/.bzr/**", - // Mac - "**/.DS_Store", + // Mac + "**/.DS_Store", - // Mercurial - "**/.hg", "**/.hg/**", + // Mercurial + "**/.hg", + "**/.hg/**", - // git - "**/.git", "**/.git/**" - ))); + // git + "**/.git", + "**/.git/**"))); static { HashMap scriptEngineMapping = new HashMap<>(); @@ -102,9 +111,8 @@ private Constants() {} DEFAULT_EXTENSION_TO_SCRIPT_ENGINE_MAPPING = Collections.unmodifiableMap(scriptEngineMapping); DEFAULT_SEARCH_PATHS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("/libs", "/apps"))); - DEFAULT_SOURCE_DIRECTORIES = - Collections.unmodifiableSet(new HashSet<>(Arrays.asList(Paths.get("src", "main", "scripts").toString(), Paths.get("src", - "main", "resources", "javax.script").toString()))); + DEFAULT_SOURCE_DIRECTORIES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( + Paths.get("src", "main", "scripts").toString(), + Paths.get("src", "main", "resources", "javax.script").toString()))); } - } diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessor.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessor.java index d7d1dbf..c71f875 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessor.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessor.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.processor; import java.io.IOException; @@ -33,6 +33,9 @@ import java.util.Optional; import java.util.Set; +import aQute.bnd.header.Attrs; +import aQute.bnd.header.OSGiHeader; +import aQute.bnd.header.Parameters; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.vault.util.PlatformNameFormat; @@ -43,90 +46,99 @@ import org.jetbrains.annotations.NotNull; import org.osgi.framework.VersionRange; -import aQute.bnd.header.Attrs; -import aQute.bnd.header.OSGiHeader; -import aQute.bnd.header.Parameters; - public class FileProcessor { private final Logger log; private final Set searchPaths; private final Map scriptEngineMappings; - private static final Collection EXTENDS_ALLOWED_ATTRIBUTE_NAMES = Arrays.asList(aQute.bnd.osgi.Constants.RESOLUTION_DIRECTIVE, aQute.bnd.osgi.Constants.VERSION_ATTRIBUTE); - private static final Collection REQUIRES_ALLOWED_ATTRIBUTE_NAMES = Arrays.asList(aQute.bnd.osgi.Constants.RESOLUTION_DIRECTIVE, aQute.bnd.osgi.Constants.VERSION_ATTRIBUTE); + private static final Collection EXTENDS_ALLOWED_ATTRIBUTE_NAMES = + Arrays.asList(aQute.bnd.osgi.Constants.RESOLUTION_DIRECTIVE, aQute.bnd.osgi.Constants.VERSION_ATTRIBUTE); + private static final Collection REQUIRES_ALLOWED_ATTRIBUTE_NAMES = + Arrays.asList(aQute.bnd.osgi.Constants.RESOLUTION_DIRECTIVE, aQute.bnd.osgi.Constants.VERSION_ATTRIBUTE); - public FileProcessor(Logger log, Set searchPaths, Map scriptEngineMappings) { this.log = log; this.searchPaths = searchPaths; this.scriptEngineMappings = scriptEngineMappings; } - public void processExtendsFile(@NotNull ResourceType resourceType, @NotNull Path file, - @NotNull Set providedCapabilities, - @NotNull Set requiredCapabilities) throws IllegalArgumentException { + public void processExtendsFile( + @NotNull ResourceType resourceType, + @NotNull Path file, + @NotNull Set providedCapabilities, + @NotNull Set requiredCapabilities) + throws IllegalArgumentException { try { List extendedResources = Files.readAllLines(file, StandardCharsets.UTF_8); if (extendedResources.size() == 1) { - processExtendedResourceType(resourceType, file, providedCapabilities, requiredCapabilities, extendedResources.get(0)); + processExtendedResourceType( + resourceType, file, providedCapabilities, requiredCapabilities, extendedResources.get(0)); } else { - throw new IllegalArgumentException(String.format("The file '%s' must contain one line only (not multiple ones)", file)); + throw new IllegalArgumentException( + String.format("The file '%s' must contain one line only (not multiple ones)", file)); } } catch (IOException e) { throw new UncheckedIOException(String.format("Unable to read file %s.", file.toString()), e); } } - private void processExtendedResourceType(@NotNull ResourceType resourceType, @NotNull Path extendsFile, - @NotNull Set providedCapabilities, - @NotNull Set requiredCapabilities, @NotNull String extendedResource) { + private void processExtendedResourceType( + @NotNull ResourceType resourceType, + @NotNull Path extendsFile, + @NotNull Set providedCapabilities, + @NotNull Set requiredCapabilities, + @NotNull String extendedResource) { Parameters parameters = OSGiHeader.parseHeader(extendedResource); if (parameters.size() != 1) { - throw new IllegalArgumentException(String.format("The file '%s' must contain one clause only (not multiple ones separated by ',')", - extendsFile)); + throw new IllegalArgumentException(String.format( + "The file '%s' must contain one clause only (not multiple ones separated by ',')", extendsFile)); } Entry extendsParameter = parameters.entrySet().iterator().next(); for (String attributeName : extendsParameter.getValue().keySet()) { if (!EXTENDS_ALLOWED_ATTRIBUTE_NAMES.contains(attributeName)) { - throw new IllegalArgumentException(String.format("Found unsupported attribute/directive '%s' in file '%s'. Only the following attributes or directives may be used in the extends file: %s", attributeName, - extendsFile, String.join(",", EXTENDS_ALLOWED_ATTRIBUTE_NAMES))); + throw new IllegalArgumentException(String.format( + "Found unsupported attribute/directive '%s' in file '%s'. Only the following attributes or directives may be used in the extends file: %s", + attributeName, extendsFile, String.join(",", EXTENDS_ALLOWED_ATTRIBUTE_NAMES))); } } - String extendedResourceType = FilenameUtils.normalize(extendsParameter.getKey(), true); - boolean isOptional = aQute.bnd.osgi.Constants.OPTIONAL.equals(extendsParameter.getValue().get(aQute.bnd.osgi.Constants.RESOLUTION_DIRECTIVE)); + String extendedResourceType = FilenameUtils.normalize(extendsParameter.getKey()); + boolean isOptional = aQute.bnd.osgi.Constants.OPTIONAL.equals( + extendsParameter.getValue().get(aQute.bnd.osgi.Constants.RESOLUTION_DIRECTIVE)); Set searchPathResourceTypes = processSearchPathResourceTypes(resourceType); - Optional rootCapability = providedCapabilities.stream().filter(capability -> - capability.getResourceTypes().equals(searchPathResourceTypes) && capability.getSelectors().isEmpty() && - StringUtils.isEmpty(capability.getRequestMethod()) && StringUtils.isEmpty(capability.getRequestExtension()) - ).findFirst(); + Optional rootCapability = providedCapabilities.stream() + .filter(capability -> capability.getResourceTypes().equals(searchPathResourceTypes) + && capability.getSelectors().isEmpty() + && StringUtils.isEmpty(capability.getRequestMethod()) + && StringUtils.isEmpty(capability.getRequestExtension())) + .findFirst(); rootCapability.ifPresent(capability -> { providedCapabilities.remove(capability); - ProvidedResourceTypeCapability replacement = - ProvidedResourceTypeCapability.builder().fromCapability(capability) - .withExtendsResourceType(extendedResourceType).build(); + ProvidedResourceTypeCapability replacement = ProvidedResourceTypeCapability.builder() + .fromCapability(capability) + .withExtendsResourceType(extendedResourceType) + .build(); providedCapabilities.add(replacement); - }); if (!rootCapability.isPresent()) { - providedCapabilities.add( - ProvidedResourceTypeCapability.builder() - .withResourceTypes(processSearchPathResourceTypes(resourceType)) - .withVersion(resourceType.getVersion()) - .withExtendsResourceType(extendedResourceType) - .build()); + providedCapabilities.add(ProvidedResourceTypeCapability.builder() + .withResourceTypes(processSearchPathResourceTypes(resourceType)) + .withVersion(resourceType.getVersion()) + .withExtendsResourceType(extendedResourceType) + .build()); } RequiredResourceTypeCapability.Builder requiredBuilder = RequiredResourceTypeCapability.builder().withResourceType(extendedResourceType); if (isOptional) { requiredBuilder.withIsOptional(); } - extractVersionRange(extendsFile, requiredBuilder, extendsParameter.getValue().getVersion()); + extractVersionRange( + extendsFile, requiredBuilder, extendsParameter.getValue().getVersion()); requiredCapabilities.add(requiredBuilder.build()); } - void processRequiresFile(@NotNull Path requiresFile, - @NotNull Set requiredCapabilities) { + void processRequiresFile( + @NotNull Path requiresFile, @NotNull Set requiredCapabilities) { try { List requiredResourceTypes = Files.readAllLines(requiresFile, StandardCharsets.UTF_8); processRequiredResourceTypes(requiresFile, requiredCapabilities, requiredResourceTypes); @@ -135,36 +147,46 @@ void processRequiresFile(@NotNull Path requiresFile, } } - private void processRequiredResourceTypes(@NotNull Path requiresFile, @NotNull Set requiredCapabilities, - List requiredResourceTypes) { + private void processRequiredResourceTypes( + @NotNull Path requiresFile, + @NotNull Set requiredCapabilities, + List requiredResourceTypes) { for (String requiredResourceType : requiredResourceTypes) { Parameters parameters = OSGiHeader.parseHeader(requiredResourceType); if (parameters.size() != 1) { - throw new IllegalArgumentException(String.format("Each line in file '%s' must contain one clause only (not multiple ones separated by ',')", + throw new IllegalArgumentException(String.format( + "Each line in file '%s' must contain one clause only (not multiple ones separated by ',')", requiresFile)); } - Entry requiresParameter = parameters.entrySet().iterator().next(); + Entry requiresParameter = + parameters.entrySet().iterator().next(); for (String attributeName : requiresParameter.getValue().keySet()) { if (!REQUIRES_ALLOWED_ATTRIBUTE_NAMES.contains(attributeName)) { - throw new IllegalArgumentException(String.format("Found unsupported attribute/directive '%s' in file '%s'. Only the following attributes or directives may be used in the requires file: %s", attributeName, - requiresFile, String.join(",", REQUIRES_ALLOWED_ATTRIBUTE_NAMES))); + throw new IllegalArgumentException(String.format( + "Found unsupported attribute/directive '%s' in file '%s'. Only the following attributes or directives may be used in the requires file: %s", + attributeName, requiresFile, String.join(",", REQUIRES_ALLOWED_ATTRIBUTE_NAMES))); } } String resourceType = FilenameUtils.normalize(requiresParameter.getKey(), true); - boolean isOptional = aQute.bnd.osgi.Constants.OPTIONAL.equals(requiresParameter.getValue().get(aQute.bnd.osgi.Constants.RESOLUTION_DIRECTIVE)); + boolean isOptional = aQute.bnd.osgi.Constants.OPTIONAL.equals( + requiresParameter.getValue().get(aQute.bnd.osgi.Constants.RESOLUTION_DIRECTIVE)); RequiredResourceTypeCapability.Builder requiredBuilder = RequiredResourceTypeCapability.builder().withResourceType(resourceType); if (isOptional) { requiredBuilder.withIsOptional(); } - extractVersionRange(requiresFile, requiredBuilder, requiresParameter.getValue().getVersion()); + extractVersionRange( + requiresFile, requiredBuilder, requiresParameter.getValue().getVersion()); requiredCapabilities.add(requiredBuilder.build()); } } - public void processScriptFile(@NotNull Path resourceTypeDirectory, @NotNull Path scriptPath, - @NotNull ResourceType resourceType, @NotNull Set providedCapabilities, - boolean inContentPackage) { + public void processScriptFile( + @NotNull Path resourceTypeDirectory, + @NotNull Path scriptPath, + @NotNull ResourceType resourceType, + @NotNull Set providedCapabilities, + boolean inContentPackage) { String filePath = scriptPath.toString(); String extension = FilenameUtils.getExtension(filePath); if (StringUtils.isNotEmpty(extension)) { @@ -175,14 +197,17 @@ public void processScriptFile(@NotNull Path resourceTypeDirectory, @NotNull Path List selectors = new ArrayList<>(); if (pathSegments > 1) { for (int i = 0; i < pathSegments - 1; i++) { - selectors.add(inContentPackage ? - PlatformNameFormat.getRepositoryName(relativeResourceTypeFolder.getName(i).toString()) : - relativeResourceTypeFolder.getName(i).toString() - ); + selectors.add( + inContentPackage + ? PlatformNameFormat.getRepositoryName(relativeResourceTypeFolder + .getName(i) + .toString()) + : relativeResourceTypeFolder.getName(i).toString()); } } String scriptFileName = scriptFile.toString(); - Script script = Script.parseScript(inContentPackage ? PlatformNameFormat.getRepositoryPath(scriptFileName) : scriptFileName); + Script script = Script.parseScript( + inContentPackage ? PlatformNameFormat.getRepositoryPath(scriptFileName) : scriptFileName); if (script != null) { String scriptEngine = scriptEngineMappings.get(script.getScriptExtension()); if (scriptEngine != null) { @@ -190,20 +215,21 @@ public void processScriptFile(@NotNull Path resourceTypeDirectory, @NotNull Path Set searchPathProcessesResourceTypes = processSearchPathResourceTypes(resourceType); if (scriptName != null) { if (!resourceType.getResourceLabel().equals(scriptName) - || script.getRequestMethod() != null) { + || script.getRequestMethod() != null) { selectors.add(script.getName()); } } Optional extendsCapability = Optional.empty(); - if (selectors.isEmpty() && StringUtils.isEmpty(script.getRequestExtension()) && - StringUtils.isEmpty(script.getRequestMethod())) { - extendsCapability = - providedCapabilities.stream() - .filter(capability -> StringUtils.isNotEmpty(capability.getExtendsResourceType()) && - capability.getResourceTypes().equals(searchPathProcessesResourceTypes) && - capability.getSelectors().isEmpty() && - StringUtils.isEmpty(capability.getRequestExtension()) && - StringUtils.isEmpty(capability.getRequestMethod())).findAny(); + if (selectors.isEmpty() + && StringUtils.isEmpty(script.getRequestExtension()) + && StringUtils.isEmpty(script.getRequestMethod())) { + extendsCapability = providedCapabilities.stream() + .filter(capability -> StringUtils.isNotEmpty(capability.getExtendsResourceType()) + && capability.getResourceTypes().equals(searchPathProcessesResourceTypes) + && capability.getSelectors().isEmpty() + && StringUtils.isEmpty(capability.getRequestExtension()) + && StringUtils.isEmpty(capability.getRequestMethod())) + .findAny(); } ProvidedResourceTypeCapability.Builder builder = ProvidedResourceTypeCapability.builder() .withResourceTypes(searchPathProcessesResourceTypes) @@ -214,17 +240,18 @@ public void processScriptFile(@NotNull Path resourceTypeDirectory, @NotNull Path .withScriptEngine(scriptEngine) .withScriptExtension(script.getScriptExtension()); extendsCapability.ifPresent(capability -> { - builder.withExtendsResourceType(capability.getExtendsResourceType()); - providedCapabilities.remove(capability); - } - ); + builder.withExtendsResourceType(capability.getExtendsResourceType()); + providedCapabilities.remove(capability); + }); providedCapabilities.add(builder.build()); } else { log.debug(String.format("Cannot find a script engine mapping for script %s.", scriptPath)); } } else { - log.debug(String.format("Skipping file %s not denoting a script as it does not follow the filename patterns outlined " + - "at https://sling.apache.org/documentation/the-sling-engine/url-to-script-resolution.html#script-naming-conventions", scriptPath)); + log.debug(String.format( + "Skipping file %s not denoting a script as it does not follow the filename patterns outlined " + + "at https://sling.apache.org/documentation/the-sling-engine/url-to-script-resolution.html#script-naming-conventions", + scriptPath)); } } else { throw new IllegalArgumentException(String.format("Invalid path given: '%s'.", scriptPath)); @@ -250,8 +277,10 @@ private Set processSearchPathResourceTypes(@NotNull ResourceType resourc return resourceTypes; } - private void extractVersionRange(@NotNull Path requiresFile, @NotNull RequiredResourceTypeCapability.Builder requiredBuilder, - String version) { + private void extractVersionRange( + @NotNull Path requiresFile, + @NotNull RequiredResourceTypeCapability.Builder requiredBuilder, + String version) { try { if (version != null) { requiredBuilder.withVersionRange(VersionRange.valueOf(version.substring(version.indexOf('=') + 1))); @@ -261,17 +290,19 @@ private void extractVersionRange(@NotNull Path requiresFile, @NotNull RequiredRe } } - public void processVaultFile(@NotNull Path entry, @NotNull ResourceType resourceType, - @NotNull Set providedCapabilities, - @NotNull Set requiredCapabilities) { + public void processVaultFile( + @NotNull Path entry, + @NotNull ResourceType resourceType, + @NotNull Set providedCapabilities, + @NotNull Set requiredCapabilities) { try { VaultContentXmlReader reader = new VaultContentXmlReader(entry); Optional slingResourceSuperType = reader.getSlingResourceSuperType(); - slingResourceSuperType.ifPresent( - resourceSuperType -> processExtendedResourceType(resourceType, entry, providedCapabilities, requiredCapabilities, - resourceSuperType)); + slingResourceSuperType.ifPresent(resourceSuperType -> processExtendedResourceType( + resourceType, entry, providedCapabilities, requiredCapabilities, resourceSuperType)); if (!reader.getSlingRequiredResourceTypes().isEmpty()) { - processRequiredResourceTypes(entry, requiredCapabilities, new ArrayList<>(reader.getSlingRequiredResourceTypes())); + processRequiredResourceTypes( + entry, requiredCapabilities, new ArrayList<>(reader.getSlingRequiredResourceTypes())); } } catch (IOException e) { throw new UncheckedIOException(String.format("Unable to read file %s.", entry), e); diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Logger.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Logger.java index 1795156..5073bae 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Logger.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Logger.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.processor; import org.jetbrains.annotations.NotNull; @@ -68,5 +68,4 @@ public interface Logger { * @param message the message */ void debug(@NotNull String message); - } diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/PathOnlyScriptAnalyser.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/PathOnlyScriptAnalyser.java index 666a04c..56f19d3 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/PathOnlyScriptAnalyser.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/PathOnlyScriptAnalyser.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.processor; import java.nio.file.Files; @@ -43,8 +43,12 @@ public class PathOnlyScriptAnalyser { private final FileProcessor fileProcessor; private final boolean inContentPackage; - public PathOnlyScriptAnalyser(@NotNull Logger logger, @NotNull Path scriptsDirectory, @NotNull Map scriptEngineMappings, - @NotNull FileProcessor fileProcessor, boolean inContentPackage) { + public PathOnlyScriptAnalyser( + @NotNull Logger logger, + @NotNull Path scriptsDirectory, + @NotNull Map scriptEngineMappings, + @NotNull FileProcessor fileProcessor, + boolean inContentPackage) { this.scriptsDirectory = scriptsDirectory; this.isNotAResourceTypeFolder = new ResourceTypeFolderPredicate(logger, inContentPackage).negate(); this.scriptEngineMappings = scriptEngineMappings; @@ -70,18 +74,21 @@ public PathOnlyScriptAnalyser(@NotNull Logger logger, @NotNull Path scriptsDirec String name = fileName.toString(); int dotLastIndex = name.lastIndexOf('.'); if (dotLastIndex > -1 && dotLastIndex != name.length() - 1) { - String scriptPath = FilenameUtils.normalize("/" + scriptsDirectory.relativize(file).toString(), true); + String scriptPath = FilenameUtils.normalize("/" + scriptsDirectory.relativize(file), true); if (inContentPackage) { scriptPath = PlatformNameFormat.getRepositoryPath(scriptPath); } - ProvidedScriptCapability providedScriptCapability = - ProvidedScriptCapability.builder(scriptEngineMappings).withPath(scriptPath).build(); + ProvidedScriptCapability providedScriptCapability = ProvidedScriptCapability.builder( + scriptEngineMappings) + .withPath(scriptPath) + .build(); Path requires = parent.resolve(Constants.REQUIRES_FILE); Set requiredCapabilities = new HashSet<>(); if (Files.exists(requires)) { fileProcessor.processRequiresFile(requires, requiredCapabilities); } - return new Capabilities(Collections.emptySet(), + return new Capabilities( + Collections.emptySet(), new HashSet<>(Arrays.asList(providedScriptCapability)), requiredCapabilities); } diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderAnalyser.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderAnalyser.java index d1df4df..0faff13 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderAnalyser.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderAnalyser.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.processor; import java.io.IOException; @@ -36,7 +36,6 @@ import org.apache.sling.scriptingbundle.plugin.capability.RequiredResourceTypeCapability; import org.jetbrains.annotations.NotNull; - public class ResourceTypeFolderAnalyser { private final Logger logger; @@ -45,8 +44,11 @@ public class ResourceTypeFolderAnalyser { private final FileProcessor fileProcessor; private final boolean inContentPackage; - public ResourceTypeFolderAnalyser(@NotNull Logger logger, @NotNull Path scriptsDirectory, @NotNull FileProcessor fileProcessor, - boolean inContentPackage) { + public ResourceTypeFolderAnalyser( + @NotNull Logger logger, + @NotNull Path scriptsDirectory, + @NotNull FileProcessor fileProcessor, + boolean inContentPackage) { this.logger = logger; this.scriptsDirectory = scriptsDirectory; this.resourceTypeFolderPredicate = new ResourceTypeFolderPredicate(logger, inContentPackage); @@ -57,46 +59,52 @@ public ResourceTypeFolderAnalyser(@NotNull Logger logger, @NotNull Path scriptsD public Capabilities getCapabilities(@NotNull Path resourceTypeDirectory) { Set providedCapabilities = new LinkedHashSet<>(); Set requiredCapabilities = new LinkedHashSet<>(); - if (resourceTypeDirectory.startsWith(scriptsDirectory) && resourceTypeFolderPredicate.test(resourceTypeDirectory)) { + if (resourceTypeDirectory.startsWith(scriptsDirectory) + && resourceTypeFolderPredicate.test(resourceTypeDirectory)) { try (DirectoryStream resourceTypeDirectoryStream = Files.newDirectoryStream(resourceTypeDirectory)) { Path relativeResourceTypeDirectory = scriptsDirectory.relativize(resourceTypeDirectory); - final ResourceType resourceType = - ResourceType.parseResourceType( - FilenameUtils.normalize(inContentPackage ? - PlatformNameFormat.getRepositoryPath(relativeResourceTypeDirectory.toString()) : - relativeResourceTypeDirectory.toString(), - true - ) - ); + final ResourceType resourceType = ResourceType.parseResourceType(FilenameUtils.normalize( + inContentPackage + ? PlatformNameFormat.getRepositoryPath(relativeResourceTypeDirectory.toString()) + : relativeResourceTypeDirectory.toString(), + true)); resourceTypeDirectoryStream.forEach(entry -> { if (Files.isRegularFile(entry)) { Path file = entry.getFileName(); if (file != null) { if (Constants.EXTENDS_FILE.equals(file.toString())) { - fileProcessor.processExtendsFile(resourceType, entry, providedCapabilities, requiredCapabilities); + fileProcessor.processExtendsFile( + resourceType, entry, providedCapabilities, requiredCapabilities); } else if (Constants.REQUIRES_FILE.equals(file.toString())) { fileProcessor.processRequiresFile(entry, requiredCapabilities); - } else if (org.apache.jackrabbit.vault.util.Constants.DOT_CONTENT_XML.equals(file.toString())) { - fileProcessor.processVaultFile(entry, resourceType, providedCapabilities, requiredCapabilities); + } else if (org.apache.jackrabbit.vault.util.Constants.DOT_CONTENT_XML.equals( + file.toString())) { + fileProcessor.processVaultFile( + entry, resourceType, providedCapabilities, requiredCapabilities); } else { - fileProcessor.processScriptFile(resourceTypeDirectory, entry, resourceType, providedCapabilities, inContentPackage); + fileProcessor.processScriptFile( + resourceTypeDirectory, + entry, + resourceType, + providedCapabilities, + inContentPackage); } } } else if (Files.isDirectory(entry) && !resourceTypeFolderPredicate.test(entry)) { - try (Stream selectorFilesStream = Files.walk(entry).filter(Files::isRegularFile).filter(file -> { - Path fileParent = file.getParent(); - while (!resourceTypeDirectory.equals(fileParent)) { - if (resourceTypeFolderPredicate.test(fileParent)) { - return false; - } - fileParent = fileParent.getParent(); - } - return true; - })) { - selectorFilesStream.forEach( - file -> fileProcessor.processScriptFile(resourceTypeDirectory, file, resourceType, - providedCapabilities, inContentPackage) - ); + try (Stream selectorFilesStream = Files.walk(entry) + .filter(Files::isRegularFile) + .filter(file -> { + Path fileParent = file.getParent(); + while (!resourceTypeDirectory.equals(fileParent)) { + if (resourceTypeFolderPredicate.test(fileParent)) { + return false; + } + fileParent = fileParent.getParent(); + } + return true; + })) { + selectorFilesStream.forEach(file -> fileProcessor.processScriptFile( + resourceTypeDirectory, file, resourceType, providedCapabilities, inContentPackage)); } catch (IOException e) { logger.error(String.format("Unable to scan folder %s.", entry.toString()), e); } diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderPredicate.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderPredicate.java index fe92ca4..041787b 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderPredicate.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderPredicate.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.processor; import java.io.IOException; @@ -73,29 +73,25 @@ public boolean test(Path folder) { Path fileName = path.getFileName(); if (fileName != null) { String childName = fileName.toString(); - Script script = Script.parseScript(inContentPackage ? PlatformNameFormat.getRepositoryPath(childName) : childName); - if ( - Constants.EXTENDS_FILE.equals(childName) || - org.apache.jackrabbit.vault.util.Constants.DOT_CONTENT_XML.equals(childName) && new VaultContentXmlReader(path).getSlingResourceSuperType().isPresent() || - ( - script != null && - ( - resourceTypeLabel.equals(script.getName()) || - ( - script.getName() == null && - ( - "html".equals(script.getRequestExtension()) || "GET".equals(script.getRequestMethod()) - ) - ) - ) - ) - ) { + Script script = Script.parseScript( + inContentPackage ? PlatformNameFormat.getRepositoryPath(childName) : childName); + if (Constants.EXTENDS_FILE.equals(childName) + || org.apache.jackrabbit.vault.util.Constants.DOT_CONTENT_XML.equals(childName) + && new VaultContentXmlReader(path) + .getSlingResourceSuperType() + .isPresent() + || (script != null + && (resourceTypeLabel.equals(script.getName()) + || (script.getName() == null + && ("html".equals(script.getRequestExtension()) + || "GET".equals(script.getRequestMethod())))))) { return true; } } } } catch (IOException e) { - logger.error(String.format("Could not check if folder %s denotes a resource type.", folder.toString()), e); + logger.error( + String.format("Could not check if folder %s denotes a resource type.", folder.toString()), e); } } return false; diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Script.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Script.java index 2837c7a..11dd405 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Script.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Script.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.processor; import org.jetbrains.annotations.NotNull; @@ -28,8 +28,11 @@ public class Script { private final String requestMethod; private final String scriptExtension; - private Script(@Nullable String name, @Nullable String requestExtension, @Nullable String requestMethod, - @NotNull String scriptExtension) { + private Script( + @Nullable String name, + @Nullable String requestExtension, + @Nullable String requestMethod, + @NotNull String scriptExtension) { this.name = name; this.requestExtension = requestExtension; this.requestMethod = requestMethod; @@ -89,6 +92,4 @@ static Script parseScript(@NotNull String fileName) { } return new Script(name, requestExtension, requestMethod, scriptExtension); } - - } diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/filevault/VaultContentXmlReader.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/filevault/VaultContentXmlReader.java index edee6bc..d11dcb4 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/filevault/VaultContentXmlReader.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/filevault/VaultContentXmlReader.java @@ -1,23 +1,29 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.processor.filevault; +import javax.jcr.PropertyType; +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + import java.io.BufferedReader; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -30,12 +36,6 @@ import java.util.Optional; import java.util.Set; -import javax.jcr.PropertyType; -import javax.xml.XMLConstants; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.spi.commons.name.NameConstants; import org.apache.jackrabbit.vault.util.DocViewProperty; @@ -74,43 +74,49 @@ public VaultContentXmlReader(@NotNull Path path) throws IOException { try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) { DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(new InputSource(reader)); - NodeList nodeList = document.getElementsByTagNameNS(NameConstants.JCR_ROOT.getNamespaceURI(), - NameConstants.JCR_ROOT.getLocalName()); + NodeList nodeList = document.getElementsByTagNameNS( + NameConstants.JCR_ROOT.getNamespaceURI(), NameConstants.JCR_ROOT.getLocalName()); if (nodeList.getLength() == 1 && nodeList.item(0).equals(document.getDocumentElement())) { - String resourceSuperTypeRawValue = document.getDocumentElement().getAttributeNS(JcrResourceConstants.SLING_NAMESPACE_URI, - Constants.SLING_RESOURCE_SUPER_TYPE_XML_LOCAL_NAME); + String resourceSuperTypeRawValue = document.getDocumentElement() + .getAttributeNS( + JcrResourceConstants.SLING_NAMESPACE_URI, + Constants.SLING_RESOURCE_SUPER_TYPE_XML_LOCAL_NAME); if (StringUtils.isNotEmpty(resourceSuperTypeRawValue)) { - DocViewProperty resourceSuperTypeDocViewProperty = - DocViewProperty.parse(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, resourceSuperTypeRawValue); - if ((resourceSuperTypeDocViewProperty.type == PropertyType.STRING || - resourceSuperTypeDocViewProperty.type == PropertyType.UNDEFINED) && !resourceSuperTypeDocViewProperty.isMulti) { + DocViewProperty resourceSuperTypeDocViewProperty = DocViewProperty.parse( + JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, resourceSuperTypeRawValue); + if ((resourceSuperTypeDocViewProperty.type == PropertyType.STRING + || resourceSuperTypeDocViewProperty.type == PropertyType.UNDEFINED) + && !resourceSuperTypeDocViewProperty.isMulti) { this.resourceSuperType = resourceSuperTypeDocViewProperty.values[0]; } else { - throw new IllegalArgumentException(String.format("Invalid %s property value (%s) in file %s.", - JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, resourceSuperTypeRawValue, path)); + throw new IllegalArgumentException(String.format( + "Invalid %s property value (%s) in file %s.", + JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, + resourceSuperTypeRawValue, + path)); } } else { this.resourceSuperType = null; } - String requiredResourceTypesRawValue = - document.getDocumentElement().getAttributeNS(JcrResourceConstants.SLING_NAMESPACE_URI - , Constants.SLING_REQUIRED_RESOURCE_TYPES_XML_LOCAL_NAME); + String requiredResourceTypesRawValue = document.getDocumentElement() + .getAttributeNS( + JcrResourceConstants.SLING_NAMESPACE_URI, + Constants.SLING_REQUIRED_RESOURCE_TYPES_XML_LOCAL_NAME); if (StringUtils.isNotEmpty(requiredResourceTypesRawValue)) { - DocViewProperty requiredResourceTypesDocViewProperty = - DocViewProperty.parse(Constants.SLING_REQUIRED_RESOURCE_TYPES, - requiredResourceTypesRawValue); - if (requiredResourceTypesDocViewProperty.isMulti && - (requiredResourceTypesDocViewProperty.type == PropertyType.STRING || - requiredResourceTypesDocViewProperty.type == PropertyType.UNDEFINED)) { + DocViewProperty requiredResourceTypesDocViewProperty = DocViewProperty.parse( + Constants.SLING_REQUIRED_RESOURCE_TYPES, requiredResourceTypesRawValue); + if (requiredResourceTypesDocViewProperty.isMulti + && (requiredResourceTypesDocViewProperty.type == PropertyType.STRING + || requiredResourceTypesDocViewProperty.type == PropertyType.UNDEFINED)) { requiredResourceTypes.addAll(Arrays.asList(requiredResourceTypesDocViewProperty.values)); } else { - throw new IllegalArgumentException(String.format("Invalid %s property value (%s) in file %s.", + throw new IllegalArgumentException(String.format( + "Invalid %s property value (%s) in file %s.", Constants.SLING_REQUIRED_RESOURCE_TYPES, requiredResourceTypesRawValue, path)); } } - } else { throw new IllegalArgumentException(String.format( "Path %s does not seem to provide a Docview format - https://jackrabbit.apache.org/filevault/docview.html.", @@ -119,8 +125,6 @@ public VaultContentXmlReader(@NotNull Path path) throws IOException { } catch (ParserConfigurationException | SAXException e) { throw new IOException(e); } - - } @NotNull @@ -150,8 +154,9 @@ public boolean equals(Object obj) { } if (obj instanceof VaultContentXmlReader) { VaultContentXmlReader other = (VaultContentXmlReader) obj; - return Objects.equals(path, other.path) && Objects.equals(resourceSuperType, other.resourceSuperType) && - Objects.equals(requiredResourceTypes, other.requiredResourceTypes); + return Objects.equals(path, other.path) + && Objects.equals(resourceSuperType, other.resourceSuperType) + && Objects.equals(requiredResourceTypes, other.requiredResourceTypes); } return false; } diff --git a/src/test/java/org/apache/sling/scriptingbundle/plugin/AbstractPluginTest.java b/src/test/java/org/apache/sling/scriptingbundle/plugin/AbstractPluginTest.java index ee5adb2..1d8dede 100644 --- a/src/test/java/org/apache/sling/scriptingbundle/plugin/AbstractPluginTest.java +++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/AbstractPluginTest.java @@ -1,26 +1,23 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - import java.util.Arrays; import java.util.Collections; import java.util.HashSet; @@ -35,13 +32,16 @@ import org.osgi.framework.Version; import org.osgi.framework.VersionRange; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + /** Common base class for both Bnd plugin and Maven plugin */ public abstract class AbstractPluginTest { protected static final Set FILEVAULT_PROJECTS = new HashSet<>(Arrays.asList("filevault-1")); public abstract PluginExecution executePluginOnProject(String projectName) throws Exception; - + public abstract void cleanUp(String projectName) throws Exception; @Test @@ -52,100 +52,192 @@ public void testProject1() throws Exception { Map scriptEngineMappings = execution.getScriptEngineMappings(); Set pExpected = new HashSet<>(Arrays.asList( // org/apache/sling/bar/1.0.0 - ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl") - .withScriptExtension("html").withVersion(new Version("1.0.0")).build(), - ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl") - .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1" - , "100")).build(), - ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl") - .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1" - , "200")).build(), - ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl") - .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1" - , "depth2", "100")).build(), - + ProvidedResourceTypeCapability.builder() + .withResourceType("org/apache/sling/bar") + .withScriptEngine("htl") + .withScriptExtension("html") + .withVersion(new Version("1.0.0")) + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org/apache/sling/bar") + .withScriptEngine("htl") + .withScriptExtension("html") + .withVersion(new Version("1.0.0")) + .withSelectors(Arrays.asList("depth1", "100")) + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org/apache/sling/bar") + .withScriptEngine("htl") + .withScriptExtension("html") + .withVersion(new Version("1.0.0")) + .withSelectors(Arrays.asList("depth1", "200")) + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org/apache/sling/bar") + .withScriptEngine("htl") + .withScriptExtension("html") + .withVersion(new Version("1.0.0")) + .withSelectors(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(Arrays.asList("depth1" - , "100")).build(), - ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl") - .withScriptExtension("html").withSelectors(Arrays.asList("depth1" - , "200")).build(), - - ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl") - .withScriptExtension("html").withSelectors(Arrays.asList("depth1" - , "depth1", "depth3")).build(), - ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl") - .withScriptExtension("html").withSelectors(Arrays.asList("depth1" - , "depth2", "100")).build(), - + ProvidedResourceTypeCapability.builder() + .withResourceType("org/apache/sling/foo") + .withScriptEngine("htl") + .withScriptExtension("html") + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org/apache/sling/foo") + .withScriptEngine("htl") + .withScriptExtension("html") + .withSelectors(Arrays.asList("depth1", "100")) + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org/apache/sling/foo") + .withScriptEngine("htl") + .withScriptExtension("html") + .withSelectors(Arrays.asList("depth1", "200")) + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org/apache/sling/foo") + .withScriptEngine("htl") + .withScriptExtension("html") + .withSelectors(Arrays.asList("depth1", "depth1", "depth3")) + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org/apache/sling/foo") + .withScriptEngine("htl") + .withScriptExtension("html") + .withSelectors(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(Arrays.asList("depth3-selector")).build(), - + 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(Arrays.asList("depth3-selector")) + .build(), + // org.apache.sling.foobar/1.0.0 - ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl") - .withScriptExtension("html").withVersion(new Version("1.0.0")).withExtendsResourceType("org/apache/sling/bar").build(), - ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl") - .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1" - , "100")).build(), - ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl") - .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1" - , "200")).build(), - ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl") - .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1" - , "depth2", "100")).build(), - + ProvidedResourceTypeCapability.builder() + .withResourceType("org.apache.sling.foobar") + .withScriptEngine("htl") + .withScriptExtension("html") + .withVersion(new Version("1.0.0")) + .withExtendsResourceType("org/apache/sling/bar") + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org.apache.sling.foobar") + .withScriptEngine("htl") + .withScriptExtension("html") + .withVersion(new Version("1.0.0")) + .withSelectors(Arrays.asList("depth1", "100")) + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org.apache.sling.foobar") + .withScriptEngine("htl") + .withScriptExtension("html") + .withVersion(new Version("1.0.0")) + .withSelectors(Arrays.asList("depth1", "200")) + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org.apache.sling.foobar") + .withScriptEngine("htl") + .withScriptExtension("html") + .withVersion(new Version("1.0.0")) + .withSelectors(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(Arrays.asList("depth1" - , "100")).build(), - ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl") - .withScriptExtension("html").withSelectors(Arrays.asList("depth1" - , "200")).build(), - ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl") - .withScriptExtension("html").withSelectors(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(Arrays.asList("test")) - .build(), - ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl") - .withScriptExtension("html").withRequestMethod("GET").withSelectors(Arrays.asList("test")) - .withRequestExtension("txt").build(), - ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl") - .withScriptExtension("html").withSelectors(Arrays.asList("test")) - .withRequestExtension("txt").build(), - + 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(Arrays.asList("depth1", "100")) + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org.apache.sling.foobar") + .withScriptEngine("htl") + .withScriptExtension("html") + .withSelectors(Arrays.asList("depth1", "200")) + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org.apache.sling.foobar") + .withScriptEngine("htl") + .withScriptExtension("html") + .withSelectors(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(Arrays.asList("test")) + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org.apache.sling.foobar") + .withScriptEngine("htl") + .withScriptExtension("html") + .withRequestMethod("GET") + .withSelectors(Arrays.asList("test")) + .withRequestExtension("txt") + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("org.apache.sling.foobar") + .withScriptEngine("htl") + .withScriptExtension("html") + .withSelectors(Arrays.asList("test")) + .withRequestExtension("txt") + .build(), + // sling - ProvidedResourceTypeCapability.builder().withResourceType("sling").withScriptEngine("htl").withScriptExtension("html") + 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() - )); - + ProvidedResourceTypeCapability.builder() + .withResourceType("/libs/sling/test") + .withResourceType("sling/test") + .withScriptEngine("htl") + .withScriptExtension("html") + .build())); + Set rExpected = new HashSet<>(Arrays.asList( - RequiredResourceTypeCapability.builder().withResourceType("sling/default") - .withVersionRange(VersionRange.valueOf("[1.0.0,2.0.0)")).withIsOptional().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)")).withIsOptional().build() - )); - Set sExpected = new HashSet<>(Arrays.asList( - ProvidedScriptCapability.builder(scriptEngineMappings) - .withPath("/org.apache.sling.wrongbar/wrongbar.has.too.many.selectors.html").build() - )); + RequiredResourceTypeCapability.builder() + .withResourceType("sling/default") + .withVersionRange(VersionRange.valueOf("[1.0.0,2.0.0)")) + .withIsOptional() + .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)")) + .withIsOptional() + .build())); + Set sExpected = + new HashSet<>(Arrays.asList(ProvidedScriptCapability.builder(scriptEngineMappings) + .withPath("/org.apache.sling.wrongbar/wrongbar.has.too.many.selectors.html") + .build())); verifyCapabilities(capabilities, pExpected, rExpected, sExpected); } finally { cleanUp("project-1"); @@ -159,21 +251,36 @@ public void testProject2() throws Exception { Capabilities capabilities = execution.getCapabilities(); Map scriptEngineMappings = execution.getScriptEngineMappings(); Set 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(Arrays.asList("merged")).build(), - ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/test2").withScriptEngine("jsp") - .withScriptExtension("jsp").withRequestExtension("html").build() - )); + ProvidedResourceTypeCapability.builder() + .withResourceType("libs/sling/test") + .withScriptEngine("thymeleaf") + .withScriptExtension("html") + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("libs/sling/test") + .withScriptEngine("rhino") + .withScriptExtension("js") + .withSelectors(Arrays.asList("merged")) + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("libs/sling/test2") + .withScriptEngine("jsp") + .withScriptExtension("jsp") + .withRequestExtension("html") + .build())); Set 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 expectedRequired = new HashSet<>(Arrays.asList( - RequiredResourceTypeCapability.builder().withResourceType("sling/scripting/warpDrive") - .withVersionRange(VersionRange.valueOf("[1.0.0,2.0.0)")).withIsOptional().build() - )); + ProvidedScriptCapability.builder(scriptEngineMappings) + .withPath("/libs/sling/commons/template.html") + .build(), + ProvidedScriptCapability.builder(scriptEngineMappings) + .withPath("/libs/sling/utils/initialiseWarpDrive.html") + .build())); + Set expectedRequired = + new HashSet<>(Arrays.asList(RequiredResourceTypeCapability.builder() + .withResourceType("sling/scripting/warpDrive") + .withVersionRange(VersionRange.valueOf("[1.0.0,2.0.0)")) + .withIsOptional() + .build())); verifyCapabilities(capabilities, pExpected, expectedRequired, expectedScriptCapabilities); } finally { cleanUp("project-2"); @@ -186,12 +293,17 @@ public void testIncludeExcludes() throws Exception { PluginExecution execution = executePluginOnProject("project-3"); Capabilities capabilities = execution.getCapabilities(); Set pExpected = new HashSet<>(Arrays.asList( - ProvidedResourceTypeCapability.builder().withResourceType("sling/scriptingbundle/includeexclude") - .withScriptEngine("htl").withScriptExtension("html").build(), - ProvidedResourceTypeCapability.builder().withResourceType("sling/scriptingbundle/includeexclude") - .withSelectors(Arrays.asList("selector")).withScriptEngine("htl").withScriptExtension("html") - .build() - )); + ProvidedResourceTypeCapability.builder() + .withResourceType("sling/scriptingbundle/includeexclude") + .withScriptEngine("htl") + .withScriptExtension("html") + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceType("sling/scriptingbundle/includeexclude") + .withSelectors(Arrays.asList("selector")) + .withScriptEngine("htl") + .withScriptExtension("html") + .build())); verifyCapabilities(capabilities, pExpected, Collections.emptySet(), Collections.emptySet()); } finally { cleanUp("project-3"); @@ -204,19 +316,38 @@ public void testFileVault1() throws Exception { PluginExecution execution = executePluginOnProject("filevault-1"); Capabilities capabilities = execution.getCapabilities(); Set pExpected = new HashSet<>(Arrays.asList( - ProvidedResourceTypeCapability.builder().withResourceTypes("my-scripts/image", "/apps/my-scripts/image") - .withScriptEngine("htl").withScriptExtension("html").withExtendsResourceType("generic/image").build(), - ProvidedResourceTypeCapability.builder().withResourceTypes("my-scripts/teaser", "/apps/my-scripts/teaser") - .withScriptEngine("htl").withScriptExtension("html").build(), - ProvidedResourceTypeCapability.builder().withResourceTypes("my-scripts/escaped:test", "/apps/my-scripts/escaped:test") - .withScriptEngine("htl").withScriptExtension("html").build() - )); + ProvidedResourceTypeCapability.builder() + .withResourceTypes("my-scripts/image", "/apps/my-scripts/image") + .withScriptEngine("htl") + .withScriptExtension("html") + .withExtendsResourceType("generic/image") + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceTypes("my-scripts/teaser", "/apps/my-scripts/teaser") + .withScriptEngine("htl") + .withScriptExtension("html") + .build(), + ProvidedResourceTypeCapability.builder() + .withResourceTypes("my-scripts/escaped:test", "/apps/my-scripts/escaped:test") + .withScriptEngine("htl") + .withScriptExtension("html") + .build())); Set rExpected = new HashSet<>(Arrays.asList( - RequiredResourceTypeCapability.builder().withResourceType("generic/image").withIsOptional().build(), - RequiredResourceTypeCapability.builder().withResourceType("required/one").withIsOptional().build(), - RequiredResourceTypeCapability.builder().withResourceType("required/two").withIsOptional().build(), - RequiredResourceTypeCapability.builder().withResourceType("my-scripts/image").build() - )); + RequiredResourceTypeCapability.builder() + .withResourceType("generic/image") + .withIsOptional() + .build(), + RequiredResourceTypeCapability.builder() + .withResourceType("required/one") + .withIsOptional() + .build(), + RequiredResourceTypeCapability.builder() + .withResourceType("required/two") + .withIsOptional() + .build(), + RequiredResourceTypeCapability.builder() + .withResourceType("my-scripts/image") + .build())); verifyCapabilities(capabilities, pExpected, rExpected, Collections.emptySet()); } finally { cleanUp("filevault-1"); @@ -228,26 +359,37 @@ public void testProject4() throws Exception { try { PluginExecution execution = executePluginOnProject("project-4"); Capabilities capabilities = execution.getCapabilities(); - Set pExpected = new HashSet<>(Arrays.asList( - ProvidedResourceTypeCapability.builder().withResourceTypes("components/test", "/apps/components/test") - .withScriptEngine("htl").withScriptExtension("html").build() - )); - Set rExpected = new HashSet<>(Arrays.asList( - RequiredResourceTypeCapability.builder().withResourceType("components/testhelper").build() - )); + Set pExpected = + new HashSet<>(Arrays.asList(ProvidedResourceTypeCapability.builder() + .withResourceTypes("components/test", "/apps/components/test") + .withScriptEngine("htl") + .withScriptExtension("html") + .build())); + Set rExpected = + new HashSet<>(Arrays.asList(RequiredResourceTypeCapability.builder() + .withResourceType("components/testhelper") + .build())); verifyCapabilities(capabilities, pExpected, rExpected, Collections.emptySet()); } finally { cleanUp("project-4"); } } - private void verifyCapabilities(Capabilities capabilities, Set pExpected, Set rExpected, Set sExpected) { - Set provided = new HashSet<>(capabilities.getProvidedResourceTypeCapabilities()); + private void verifyCapabilities( + Capabilities capabilities, + Set pExpected, + Set rExpected, + Set sExpected) { + Set provided = + new HashSet<>(capabilities.getProvidedResourceTypeCapabilities()); StringBuilder missingProvided = new StringBuilder(); for (ProvidedResourceTypeCapability capability : pExpected) { boolean removed = provided.remove(capability); if (!removed) { - missingProvided.append("Missing capability: ").append(capability.toString()).append(System.lineSeparator()); + missingProvided + .append("Missing capability: ") + .append(capability.toString()) + .append(System.lineSeparator()); } } if (missingProvided.length() > 0) { @@ -255,19 +397,26 @@ private void verifyCapabilities(Capabilities capabilities, Set 0) { fail(extraProvided.toString()); } - - Set required = new HashSet<>(capabilities.getRequiredResourceTypeCapabilities()); + + Set required = + new HashSet<>(capabilities.getRequiredResourceTypeCapabilities()); assertEquals(rExpected.size(), required.size()); StringBuilder missingRequired = new StringBuilder(); for (RequiredResourceTypeCapability capability : rExpected) { boolean removed = required.remove(capability); if (!removed) { - missingRequired.append("Missing required capability: ").append(capability.toString()).append(System.lineSeparator()); + missingRequired + .append("Missing required capability: ") + .append(capability.toString()) + .append(System.lineSeparator()); } } if (missingRequired.length() > 0) { @@ -275,19 +424,26 @@ private void verifyCapabilities(Capabilities capabilities, Set 0) { fail(extraRequired.toString()); } - - Set providedScriptCapabilities = new HashSet<>(capabilities.getProvidedScriptCapabilities()); + + Set providedScriptCapabilities = + new HashSet<>(capabilities.getProvidedScriptCapabilities()); assertEquals(sExpected.size(), providedScriptCapabilities.size()); StringBuilder missingProvidedScripts = new StringBuilder(); for (ProvidedScriptCapability capability : sExpected) { boolean removed = providedScriptCapabilities.remove(capability); if (!removed) { - missingProvidedScripts.append("Missing script capability: ").append(capability.toString()).append(System.lineSeparator()); + missingProvidedScripts + .append("Missing script capability: ") + .append(capability.toString()) + .append(System.lineSeparator()); } } if (missingProvidedScripts.length() > 0) { @@ -295,7 +451,10 @@ private void verifyCapabilities(Capabilities capabilities, Set 0) { fail(extraProvidedScripts.toString()); diff --git a/src/test/java/org/apache/sling/scriptingbundle/plugin/PluginExecution.java b/src/test/java/org/apache/sling/scriptingbundle/plugin/PluginExecution.java index 8c17036..b23d661 100644 --- a/src/test/java/org/apache/sling/scriptingbundle/plugin/PluginExecution.java +++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/PluginExecution.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin; import java.util.Map; @@ -39,5 +39,4 @@ public Capabilities getCapabilities() { public Map getScriptEngineMappings() { return scriptEngineMappings; } - } diff --git a/src/test/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPluginTest.java b/src/test/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPluginTest.java index 12a2976..0de70ee 100644 --- a/src/test/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPluginTest.java +++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPluginTest.java @@ -1,25 +1,23 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.bnd; -import static org.junit.Assert.assertNotNull; - import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -27,12 +25,13 @@ import java.nio.file.Paths; import java.util.jar.Manifest; +import aQute.bnd.osgi.Builder; +import aQute.bnd.osgi.Jar; import org.apache.commons.io.FileUtils; import org.apache.sling.scriptingbundle.plugin.AbstractPluginTest; import org.apache.sling.scriptingbundle.plugin.PluginExecution; -import aQute.bnd.osgi.Builder; -import aQute.bnd.osgi.Jar; +import static org.junit.Assert.assertNotNull; public class BundledScriptsScannerPluginTest extends AbstractPluginTest { @@ -70,5 +69,4 @@ public PluginExecution executePluginOnProject(String projectName) throws Excepti return new PluginExecution(plugin.getCapabilities(), plugin.getScriptEngineMappings()); } } - } diff --git a/src/test/java/org/apache/sling/scriptingbundle/plugin/capability/CapabilityTest.java b/src/test/java/org/apache/sling/scriptingbundle/plugin/capability/CapabilityTest.java index bce37c6..ae7a3f8 100644 --- a/src/test/java/org/apache/sling/scriptingbundle/plugin/capability/CapabilityTest.java +++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/capability/CapabilityTest.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.capability; import java.util.Collections; @@ -41,7 +41,8 @@ public void testGetProvidedCapabilitiesString() { .build()); // TODO: add script capabilities Capabilities caps = new Capabilities(resourceTypeCaps, Collections.emptySet(), Collections.emptySet()); - String expectedHeaderValue = "sling.servlet;sling.servlet.resourceTypes:List=\"my/type,/libs/my/type\";version:Version=\"2.1.0\";sling.servlet.methods=POST;sling.servlet.extensions=json;sling.servlet.selectors:List=\"selector1,selector\\,2\""; + String expectedHeaderValue = + "sling.servlet;sling.servlet.resourceTypes:List=\"my/type,/libs/my/type\";version:Version=\"2.1.0\";sling.servlet.methods=POST;sling.servlet.extensions=json;sling.servlet.selectors:List=\"selector1,selector\\,2\""; Assert.assertEquals(expectedHeaderValue, caps.getProvidedCapabilitiesString()); } @@ -57,8 +58,9 @@ public void testGetRequiredCapabilitiesString() { .withResourceType("/other/type") .build()); Capabilities caps = new Capabilities(Collections.emptySet(), Collections.emptySet(), resourceTypeCaps); - String expectedHeaderValue = "sling.servlet;filter:=\"(&(!(sling.servlet.selectors=*))(&(&(version=*)(!(version<=1.0.0))(!(version>=3.0.0)))(sling.servlet.resourceTypes=my/type)))\";resolution:=optional" + - ",sling.servlet;filter:=\"(&(!(sling.servlet.selectors=*))(sling.servlet.resourceTypes=/other/type))\""; + String expectedHeaderValue = + "sling.servlet;filter:=\"(&(!(sling.servlet.selectors=*))(&(&(version=*)(!(version<=1.0.0))(!(version>=3.0.0)))(sling.servlet.resourceTypes=my/type)))\";resolution:=optional" + + ",sling.servlet;filter:=\"(&(!(sling.servlet.selectors=*))(sling.servlet.resourceTypes=/other/type))\""; Assert.assertEquals(expectedHeaderValue, caps.getRequiredCapabilitiesString()); } } diff --git a/src/test/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojoTest.java b/src/test/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojoTest.java index 7b1327e..d016f01 100644 --- a/src/test/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojoTest.java +++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojoTest.java @@ -1,28 +1,25 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.maven; import java.io.File; import java.nio.file.Paths; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; import org.apache.commons.io.FileUtils; import org.apache.maven.execution.MavenSession; @@ -45,7 +42,8 @@ public void after() { } private MojoProject getMojoProject(String projectName) throws Exception { - File projectDirectory = Paths.get("src", "test", "resources", projectName).toFile(); + File projectDirectory = + Paths.get("src", "test", "resources", projectName).toFile(); MavenProject project = mojoRule.readMavenProject(projectDirectory); MavenSession session = mojoRule.newMavenSession(project); if (FILEVAULT_PROJECTS.contains(projectName)) { diff --git a/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessorTest.java b/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessorTest.java index 6b38dfe..9e38cfa 100644 --- a/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessorTest.java +++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessorTest.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.processor; import java.nio.file.Path; @@ -41,7 +41,10 @@ public class FileProcessorTest { @Before public void setUp() { - processor = new FileProcessor(new Slf4jLogger(), Constants.DEFAULT_SEARCH_PATHS, Constants.DEFAULT_EXTENSION_TO_SCRIPT_ENGINE_MAPPING); + processor = new FileProcessor( + new Slf4jLogger(), + Constants.DEFAULT_SEARCH_PATHS, + Constants.DEFAULT_EXTENSION_TO_SCRIPT_ENGINE_MAPPING); providedCapabilities = new HashSet<>(); requiredCapabilities = new HashSet<>(); } @@ -54,33 +57,42 @@ public void testExtendsValid() { RequiredResourceTypeCapability expectedRequiredCapability = RequiredResourceTypeCapability.builder() .withResourceType("org/apache/sling/bar") .withVersionRange(new VersionRange("[1.0.0,2.0.0)")) - .withIsOptional().build(); - Assert.assertEquals(expectedRequiredCapability, requiredCapabilities.iterator().next()); + .withIsOptional() + .build(); + Assert.assertEquals( + expectedRequiredCapability, requiredCapabilities.iterator().next()); Assert.assertEquals(1, providedCapabilities.size()); ProvidedResourceTypeCapability expectedProvidedCapability = ProvidedResourceTypeCapability.builder() .withResourceTypes(new HashSet<>(Arrays.asList("my/resource", "/apps/my/resource"))) .withVersion(MY_RESOURCE_TYPE.getVersion()) .withExtendsResourceType("org/apache/sling/bar") .build(); - Assert.assertEquals(expectedProvidedCapability, providedCapabilities.iterator().next()); + Assert.assertEquals( + expectedProvidedCapability, providedCapabilities.iterator().next()); } @Test public void testExtendsMultipleClauses() { Path extendsFile = Paths.get("src", "test", "resources", "extends", "multiple-clauses"); - Assert.assertThrows(IllegalArgumentException.class, () -> { processor.processExtendsFile(MY_RESOURCE_TYPE, extendsFile, providedCapabilities, requiredCapabilities); }); + Assert.assertThrows(IllegalArgumentException.class, () -> { + processor.processExtendsFile(MY_RESOURCE_TYPE, extendsFile, providedCapabilities, requiredCapabilities); + }); } @Test public void testExtendsInvalidAttributes() { Path extendsFile = Paths.get("src", "test", "resources", "extends", "invalid-attributes"); - Assert.assertThrows(IllegalArgumentException.class, () -> { processor.processExtendsFile(MY_RESOURCE_TYPE, extendsFile, providedCapabilities, requiredCapabilities); }); + Assert.assertThrows(IllegalArgumentException.class, () -> { + processor.processExtendsFile(MY_RESOURCE_TYPE, extendsFile, providedCapabilities, requiredCapabilities); + }); } @Test public void testExtendsMultipleLines() { Path extendsFile = Paths.get("src", "test", "resources", "extends", "multiple-lines"); - Assert.assertThrows(IllegalArgumentException.class, () -> { processor.processExtendsFile(MY_RESOURCE_TYPE, extendsFile, providedCapabilities, requiredCapabilities); }); + Assert.assertThrows(IllegalArgumentException.class, () -> { + processor.processExtendsFile(MY_RESOURCE_TYPE, extendsFile, providedCapabilities, requiredCapabilities); + }); } @Test @@ -91,20 +103,25 @@ public void testRequiresValid() { RequiredResourceTypeCapability expectedCapability = RequiredResourceTypeCapability.builder() .withResourceType("org/apache/sling/bar") .withVersionRange(new VersionRange("[1.0.0,2.0.0)")) - .withIsOptional().build(); + .withIsOptional() + .build(); Assert.assertEquals(expectedCapability, requiredCapabilities.iterator().next()); } @Test public void testRequiresMultipleClauses() { Path requiresFile = Paths.get("src", "test", "resources", "requires", "multiple-clauses"); - Assert.assertThrows(IllegalArgumentException.class, () -> { processor.processRequiresFile(requiresFile, requiredCapabilities); }); + Assert.assertThrows(IllegalArgumentException.class, () -> { + processor.processRequiresFile(requiresFile, requiredCapabilities); + }); } @Test public void testRequiresInvalidAttributes() { Path requiresFile = Paths.get("src", "test", "resources", "extends", "invalid-attributes"); - Assert.assertThrows(IllegalArgumentException.class, () -> { processor.processRequiresFile(requiresFile, requiredCapabilities); }); + Assert.assertThrows(IllegalArgumentException.class, () -> { + processor.processRequiresFile(requiresFile, requiredCapabilities); + }); } @Test @@ -121,7 +138,8 @@ public void testScriptValid() { .withScriptEngine("htl") .withScriptExtension("html") .build(); - Assert.assertEquals(expectedProvidedCapability, providedCapabilities.iterator().next()); + Assert.assertEquals( + expectedProvidedCapability, providedCapabilities.iterator().next()); } @Test @@ -154,15 +172,18 @@ public void testMainScriptSelector() { .withScriptExtension("html") .build(); - Assert.assertEquals(new HashSet<>(Arrays.asList(expectedProvidedCapability1, expectedProvidedCapability2)), providedCapabilities); + Assert.assertEquals( + new HashSet<>(Arrays.asList(expectedProvidedCapability1, expectedProvidedCapability2)), + providedCapabilities); } @Test public void testScriptUnknownExtension() { - Path resourceTypeFolder = Paths.get("scripts", "apps", "my", "resource", "2.0"); + Path resourceTypeFolder = Paths.get("scripts", "apps", "my", "resource", "2.0"); Path script = Paths.get("scripts", "apps", "my", "resource", "2.0", "selectorb", "selectora.POST.abc"); processor.processScriptFile(resourceTypeFolder, script, MY_RESOURCE_TYPE, providedCapabilities, false); - // this must not throw an exception but a WARN should be emitted in the log to make users aware of potential misconfigurations + // this must not throw an exception but a WARN should be emitted in the log to make users aware of potential + // misconfigurations Assert.assertEquals(0, providedCapabilities.size()); } } diff --git a/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/ScriptTest.java b/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/ScriptTest.java index f28c59f..4746abe 100644 --- a/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/ScriptTest.java +++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/ScriptTest.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.processor; import org.junit.Assert; diff --git a/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/Slf4jLogger.java b/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/Slf4jLogger.java index 393e396..7452fa3 100644 --- a/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/Slf4jLogger.java +++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/Slf4jLogger.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.processor; import org.jetbrains.annotations.NotNull; @@ -23,7 +23,7 @@ public class Slf4jLogger implements Logger { private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Slf4jLogger.class); - + @Override public void error(@NotNull String message) { logger.error(message); diff --git a/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/filevault/VaultContentXmlReaderTest.java b/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/filevault/VaultContentXmlReaderTest.java index fb5f702..ffe8433 100644 --- a/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/filevault/VaultContentXmlReaderTest.java +++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/filevault/VaultContentXmlReaderTest.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.scriptingbundle.plugin.processor.filevault; import java.io.IOException; @@ -23,14 +23,9 @@ import java.util.Arrays; import java.util.Optional; -import org.apache.sling.scriptingbundle.plugin.processor.Slf4jLogger; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; @@ -38,37 +33,46 @@ public class VaultContentXmlReaderTest { @Test public void testReader() throws IOException { - VaultContentXmlReader vaultContentXmlReader = new VaultContentXmlReader(Paths.get("src/test/resources" + - "/filevault-1/src/main/content/jcr_root/apps/my-scripts/image/.content.xml")); + VaultContentXmlReader vaultContentXmlReader = new VaultContentXmlReader(Paths.get( + "src/test/resources" + "/filevault-1/src/main/content/jcr_root/apps/my-scripts/image/.content.xml")); Optional resourceSuperType = vaultContentXmlReader.getSlingResourceSuperType(); assertTrue(resourceSuperType.isPresent()); assertEquals("generic/image", resourceSuperType.get()); - assertTrue( - vaultContentXmlReader.getSlingRequiredResourceTypes().size() == 2 && - vaultContentXmlReader.getSlingRequiredResourceTypes().containsAll(Arrays.asList("required/one", "required/two")) - ); - + assertTrue(vaultContentXmlReader.getSlingRequiredResourceTypes().size() == 2 + && vaultContentXmlReader + .getSlingRequiredResourceTypes() + .containsAll(Arrays.asList("required/one", "required/two"))); } @Test public void multipleValueResourceSuperType() throws IOException { - IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> new VaultContentXmlReader( - Paths.get("src/test/resources/filevault-docview-examples/multiple-resource-super-type.xml"))); + IllegalArgumentException iae = assertThrows( + IllegalArgumentException.class, + () -> new VaultContentXmlReader( + Paths.get("src/test/resources/filevault-docview-examples/multiple-resource-super-type.xml"))); assertTrue(iae.getMessage().contains("Invalid sling:resourceSuperType property value ([generic/image])")); } @Test public void singleValueRequiredResourceTypes() throws IOException { - IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> new VaultContentXmlReader( - Paths.get("src/test/resources/filevault-docview-examples/single-value-required-resource-types.xml"))); - assertTrue(iae.getMessage().contains("Invalid sling:requiredResourceTypes property value (required/one,required/two)")); + IllegalArgumentException iae = assertThrows( + IllegalArgumentException.class, + () -> new VaultContentXmlReader(Paths.get( + "src/test/resources/filevault-docview-examples/single-value-required-resource-types.xml"))); + assertTrue(iae.getMessage() + .contains("Invalid sling:requiredResourceTypes property value (required/one,required/two)")); } @Test public void notADocView() throws IOException { - IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> new VaultContentXmlReader( - Paths.get("src/test/resources/filevault-docview-examples/not-a-docview.xml"))); - assertTrue(iae.getMessage().contains("does not seem to provide a Docview format - https://jackrabbit.apache.org/filevault/docview.html")); + IllegalArgumentException iae = assertThrows( + IllegalArgumentException.class, + () -> new VaultContentXmlReader( + Paths.get("src/test/resources/filevault-docview-examples/not-a-docview.xml"))); + assertTrue( + iae.getMessage() + .contains( + "does not seem to provide a Docview format - https://jackrabbit.apache.org/filevault/docview.html")); } }