diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 8c880f21..754ac3b0 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -49,8 +49,8 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 +# - name: Autobuild +# uses: github/codeql-action/autobuild@v1 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -59,9 +59,8 @@ jobs: # and modify them (or add more) to build your code if your project # uses a compiled language - #- run: | - # make bootstrap - # make release + - run: | + mvn clean install - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 diff --git a/.travis.yml b/.travis.yml index dc007090..d15e90a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: java jdk: - - openjdk9 + - openjdk11 addons: sonarcloud: @@ -10,7 +10,7 @@ addons: secure: v0L2WG1NtMt4bXGRipEY9X23Glmz5ZldVCw7LaIUbUwKOB2AVghhUttZAsI0FBntsF0jRHJDk3L/4g45UZWSZOMRMl3lPm8NTHZLC4TmeDb00H/JXirh5ZghX+9KDiL1X8IF5xX6HRU8WO2XFnPhNR9kdh6JKSBwM2wEXADl8WNWLP7I8hB4hQ+gBdil1zOcT5vnyhc29zSU5EuBp4uZanlNhjry12tIOp/pZpdDO/pzF6m8T0DvGsgvlkZNWF16a0kazsLVWOYZ7QmjM8YDt6jVCNVQ+cImY/YPoq42OdvbIUfTazxiMS+P68Wel7ulH9FqzfHmz+SYPxQ1TfAQ2ltZO05ubQ5C2TScC+mipUkfbgqRr9RJUPkret+nUJ1WaQdf6+W3oZ6pTvn27s+XZFlWTbj6CcmgTPN8cCL5D+A9huvDOD2wWHkP7cquGSIuqh+Nc33K/EWR/BhY4ec2Xk/bjfoPTIE4tOuVyIZQLf64RxL0sRyitj4dZz+aRqhKiCaVKRtELqh8JoteYon+QPw/MF4UOalq+/QAFWvmgMeCouGxLwh2EPlK+3kXFO5tebRv67zLVesfVFCZgKWshTvUJ02kxKqy8HpocMTmoaIsRUHi2E5ucpbMxzKuJitpetrOHIjMNJQhfi0oW17zeB8i/oDwMIdNUGXPAU2MF1g= script: - - mvn test javadoc:javadoc -B + - mvn clean install javadoc:javadoc -B - sonar-scanner cache: diff --git a/HISTORY b/HISTORY index 8d8f55a8..1322b6b5 100644 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,7 @@ +2021-06-11 4.1.0 + - New filter methods: filterByNodeExists() and filterByNodeNotExists() + - Fixed Sonar issues (#156) + 2020-12-21 4.0.0 - Update to Groovy Console 16 and require AEM 6.5 (#135) - Fix for AEM Cloud in manual execution tool diff --git a/Readme.md b/Readme.md index c26ec1fb..4435b115 100644 --- a/Readme.md +++ b/Readme.md @@ -58,7 +58,7 @@ AECU requires Java 8 and AEM 6.5 or above. For AEM 6.3/6.4 please see below. Gro | AEM Version | Groovy Console | AECU | | ------------- | -------------- | --------- | | AEM Cloud | 16.x
14.x, 13.x | 4.x
3.x, 2.x | -| 6.5 | 16.x
14.x, 13.x | 4.x
3.x, 2.x | +| 6.5 (>=6.5.3) | 16.x
14.x, 13.x | 4.x
3.x, 2.x | | 6.4 | 14.x, 13.x | 3.x, 2.x | | 6.3 | 12.x | 1.x | @@ -122,6 +122,8 @@ All migration scripts need to be located in /var/groovyconsole/scripts/aecu. The an unlimited number of folders and files. E.g. organize your files by project or deployment. The content of the scripts is plain Groovy code that can be run via [Groovy Console](https://github.com/OlsonDigital/aem-groovy-console). +If your package containing the scripts is bundled in another package please make sure that this is done using "subPackages" in pom.xml. + There are just a few naming conventions: @@ -323,6 +325,23 @@ aecu.contentUpgradeBuilder() .run() ``` +#### Filter by Node Existence + +Filters resources by the (non-)existence of relative or absolute node path. + +* filterByNodeExists(String path): process if the given subnode or absolute node exists +* filterByNodeNotExists(String path): process if the given subnode or absolute node does not exist + +```java +aecu.contentUpgradeBuilder() + .forChildResourcesOf("/content/we-retail/ca/en") + .filterByNodeExists("jcr:content/meta") + .filterByNodeExists("/content") + .filterByNodeNotExists("jcr:content/meta") + .filterByNodeNotExists("/content") + .doSetProperty("name", "value") + .run() +``` #### Combine Multiple Filters You can combine filters with AND and OR to build more complex filters. diff --git a/api/pom.xml b/api/pom.xml index 69b12203..c2670f2e 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.0 + 4.1.0 aecu.api diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java index 4b136ce0..77c3a783 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java @@ -137,6 +137,22 @@ public interface ContentUpgrade { */ ContentUpgrade filterByNodeName(String nodeName); + /** + * Filters by node/subNode exists. + * + * @param path absolute or relative resource path + * @return upgrade object + */ + ContentUpgrade filterByNodeExists(String path); + + /** + * Filters by node/subNode not exists. + * + * @param path absolute or relative resource path + * @return upgrade object + */ + ContentUpgrade filterByNodeNotExists(String path); + /** * Filters by node name using regular expression. * @@ -191,9 +207,9 @@ public interface ContentUpgrade { /** * Joins a property value into a single value using the given separator. * - * @param name property name - * @param value property value fall back for empty arrays. Use null to delete the property. - * @param name separator (e.g. ",") + * @param name property name + * @param value property value fall back for empty arrays. Use null to delete the property. + * @param separator separator (e.g. ",") * @return upgrade object **/ ContentUpgrade doJoinProperty(String name, Object value, String separator); @@ -362,6 +378,7 @@ public interface ContentUpgrade { * Deletes the child resources if supplied. If no children are specified it deletes the resource * itself. * + * @param children names of child nodes * @return upgrade object */ ContentUpgrade doDeleteResource(String... children); diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ValidateAccessRights.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ValidateAccessRights.java index 75ae0ea2..f7f142a6 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ValidateAccessRights.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ValidateAccessRights.java @@ -235,6 +235,8 @@ public interface ValidateAccessRights { /** * Fail whole script execution on error. Script will stop after current aecu block. Subsequent * code will no longer be executed. + * + * @return access right validation builder */ ValidateAccessRights failOnError(); @@ -243,6 +245,7 @@ public interface ValidateAccessRights { * code will no longer be executed. * * @param fail if true fail script execution + * @return access right validation builder */ ValidateAccessRights failOnError(boolean fail); diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeExistence.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeExistence.java new file mode 100644 index 00000000..4c1e7dc8 --- /dev/null +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeExistence.java @@ -0,0 +1,74 @@ +/* + * Copyright 2021 Valtech GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and + * associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT + * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package de.valtech.aecu.api.groovy.console.bindings.filters; + + +import javax.annotation.Nonnull; + +import org.apache.commons.lang3.StringUtils; +import org.apache.sling.api.resource.Resource; + + +/** + * Filters resources by absolute or relative node path. Only resources that (not) exist in the + * repository are accepted. + * + * @author Vugar Aghayev + */ +public class FilterByNodeExistence implements FilterBy { + + private String path; + private boolean nodeExists; + + /** + * Constructor + * + * @param path absolute or relative resource path + * @param nodeExists node exists option + */ + public FilterByNodeExistence(@Nonnull String path, boolean nodeExists) { + this.path = path; + this.nodeExists = nodeExists; + } + + @Override + public boolean filter(@Nonnull Resource resource, StringBuilder output) { + if (StringUtils.isBlank(path)) { + return true; + } + + if (isAbsolutePath(path)) { + return (nodeExists && null != resource.getResourceResolver().getResource(path)) + || (!nodeExists && null == resource.getResourceResolver().getResource(path)); + } else { + return (nodeExists && null != resource.getChild(path)) || (!nodeExists && null == resource.getChild(path)); + } + } + + /** + * checks whether given path is absolute or not. + * + * @param path jcr path + * @return true if the given path is the absolute path. Otherwise false. + */ + private boolean isAbsolutePath(String path) { + return path.startsWith("/"); + } + +} diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/package-info.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/package-info.java index 0f2e97c9..f239716c 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/package-info.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/package-info.java @@ -22,7 +22,7 @@ * * @author Roxana Muresan */ -@Version("3.0.0") +@Version("3.1.0") package de.valtech.aecu.api.groovy.console.bindings.filters; import org.osgi.annotation.versioning.Version; diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/package-info.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/package-info.java index c2e153f1..9204a68f 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/package-info.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/package-info.java @@ -22,7 +22,7 @@ * * @author Roxana Muresan */ -@Version("4.4.0") +@Version("4.5.0") package de.valtech.aecu.api.groovy.console.bindings; import org.osgi.annotation.versioning.Version; diff --git a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeExistenceTest.java b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeExistenceTest.java new file mode 100644 index 00000000..5f4d1b88 --- /dev/null +++ b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeExistenceTest.java @@ -0,0 +1,152 @@ +/* + * Copyright 2021 Valtech GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and + * associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT + * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package de.valtech.aecu.core.groovy.console.bindings.filters; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ResourceResolver; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeExistence; + +/** + * @author Vugar Aghayev + */ +@RunWith(MockitoJUnitRunner.class) +public class FilterByNodeExistenceTest { + + @Mock + private ResourceResolver resolver; + + @Mock + private Resource resource; + + @Mock + private Resource relativePathResource; + + @Mock + private Resource absolutePathResource; + + @Before + public void setup() { + when(resource.getResourceResolver()).thenReturn(resolver); + when(resource.getChild("climbing-on-kalymnos-island--greece/jcr:content")).thenReturn(relativePathResource); + } + + @Test + public void filterNodeExists_whenNodeNotFound_returnFalse() { + + assertFalse(new FilterByNodeExistence("/content/we-retail/ca/climbing-on-kalymnos-island--greece/jcr:content", true) + .filter(resource, new StringBuilder())); + + assertFalse( + new FilterByNodeExistence("climbing-on-island--greece/jcr:content", true).filter(resource, new StringBuilder())); + } + + @Test + public void filterNodeExists_whenSubNodeFound_returnTrue() { + + assertTrue(new FilterByNodeExistence("climbing-on-kalymnos-island--greece/jcr:content", true).filter(resource, + new StringBuilder())); + + } + + @Test + public void filterNodeExists_whenAbsolutePathNodeFound_returnTrue() { + when(resource.getResourceResolver() + .getResource("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content")) + .thenReturn(absolutePathResource); + + assertTrue( + new FilterByNodeExistence("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content", + true).filter(resource, new StringBuilder())); + + } + + @Test + public void filterNodeExists_whenNodePathIsEmpty_returnTrue() { + + assertTrue(new FilterByNodeExistence("", true).filter(resource, new StringBuilder())); + + assertTrue(new FilterByNodeExistence(" ", true).filter(resource, new StringBuilder())); + + } + + @Test + public void filterNodeExists_whenNodePathIsNull_returnTrue() { + + assertTrue(new FilterByNodeExistence(null, true).filter(resource, new StringBuilder())); + + } + + @Test + public void filterNodeNotExist_whenNodeNotFound_returnTrue() { + + assertTrue(new FilterByNodeExistence("/content/we-retail/ca/climbing-on-kalymnos-island--greece/jcr:content", false) + .filter(resource, new StringBuilder())); + + assertTrue( + new FilterByNodeExistence("climbing-on-island--greece/jcr:content", false).filter(resource, new StringBuilder())); + } + + @Test + public void filterNodeNotExist_whenSubNodeFound_returnFalse() { + + assertFalse(new FilterByNodeExistence("climbing-on-kalymnos-island--greece/jcr:content", false).filter(resource, + new StringBuilder())); + + } + + @Test + public void filterNodeNotExist_whenAbsolutePathNodeFound_returnFalse() { + when(resource.getResourceResolver() + .getResource("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content")) + .thenReturn(absolutePathResource); + + assertFalse( + new FilterByNodeExistence("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content", + false).filter(resource, new StringBuilder())); + + } + + @Test + public void filterNodeNotExist_whenNodePathIsEmpty_returnTrue() { + + assertTrue(new FilterByNodeExistence("", false).filter(resource, new StringBuilder())); + + assertTrue(new FilterByNodeExistence(" ", false).filter(resource, new StringBuilder())); + + } + + @Test + public void filterNodeNotExist_whenNodePathIsNull_returnTrue() { + + assertTrue(new FilterByNodeExistence(null, false).filter(resource, new StringBuilder())); + + } + +} diff --git a/bundle/pom.xml b/bundle/pom.xml index 1cdcc80a..b5fd74e1 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0 + 4.1.0 aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index 07294c1a..1a63e123 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.0 + 4.1.0 aecu.core diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java index 5e4f96e0..40b0d7f0 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java @@ -43,6 +43,7 @@ import de.valtech.aecu.api.groovy.console.bindings.filters.FilterBy; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByHasProperty; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByMultiValuePropContains; +import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeExistence; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeName; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeNameRegex; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByPathRegex; @@ -188,6 +189,18 @@ public ContentUpgrade filterByNodeName(@Nonnull String nodeName) { return this; } + @Override + public ContentUpgrade filterByNodeExists(@Nonnull String path) { + addFilter(new FilterByNodeExistence(path, true)); + return this; + } + + @Override + public ContentUpgrade filterByNodeNotExists(@Nonnull String path) { + addFilter(new FilterByNodeExistence(path, false)); + return this; + } + @Override public ContentUpgrade filterByNodeNameRegex(@Nonnull String regex) { addFilter(new FilterByNodeNameRegex(regex)); diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/traversers/TraversData.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/traversers/TraversData.java index d9ddc58d..569a1f6c 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/traversers/TraversData.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/traversers/TraversData.java @@ -120,9 +120,14 @@ private void save(ResourceResolver resourceResolver) throws PersistenceException private void runActions(@Nonnull StringBuilder output, @Nonnull Resource resource, @Nonnull List actions) throws PersistenceException, AecuException { for (Action action : actions) { - String actionOutput = action.doAction(resource); - if (StringUtils.isNotBlank(actionOutput)) { - output.append(actionOutput + "\n"); + try { + String actionOutput = action.doAction(resource); + if (StringUtils.isNotBlank(actionOutput)) { + output.append(actionOutput + "\n"); + } + } catch (RuntimeException e) { + // wrap runtime exception to add the resource path (see also https://issues.apache.org/jira/browse/SLING-10063) + throw new AecuException("RuntimeException while performing action on resource '" + resource.getPath() + "'", e); } } } diff --git a/core/src/main/java/de/valtech/aecu/core/healthcheck/LastRunHealthCheck.java b/core/src/main/java/de/valtech/aecu/core/healthcheck/LastRunHealthCheck.java index 239caaeb..13dc9e5a 100644 --- a/core/src/main/java/de/valtech/aecu/core/healthcheck/LastRunHealthCheck.java +++ b/core/src/main/java/de/valtech/aecu/core/healthcheck/LastRunHealthCheck.java @@ -36,7 +36,7 @@ * @author Roland Gruber */ @Component(immediate = true, service = HealthCheck.class, property = {HealthCheck.TAGS + "=aecu", - HealthCheck.NAME + "=AECU Last Run", HealthCheck.MBEAN_NAME + "=aecuLastRunHCmBean"}) + HealthCheck.TAGS + "=aecu-last-run", HealthCheck.NAME + "=AECU Last Run", HealthCheck.MBEAN_NAME + "=aecuLastRunHCmBean"}) public class LastRunHealthCheck implements HealthCheck { @Reference diff --git a/core/src/main/java/de/valtech/aecu/core/installhook/AecuTrackerListener.java b/core/src/main/java/de/valtech/aecu/core/installhook/AecuTrackerListener.java index 7d7cabdd..bc5ba2c9 100644 --- a/core/src/main/java/de/valtech/aecu/core/installhook/AecuTrackerListener.java +++ b/core/src/main/java/de/valtech/aecu/core/installhook/AecuTrackerListener.java @@ -28,6 +28,8 @@ import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.vault.fs.api.ProgressTrackerListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import de.valtech.aecu.api.service.AecuService; @@ -39,6 +41,8 @@ */ public class AecuTrackerListener implements ProgressTrackerListener { + private static final Logger LOG = LoggerFactory.getLogger(AecuTrackerListener.class); + public static final String ALWAYS_SUFFIX = "always.groovy"; private static final Set ACTIONS = new HashSet<>(Arrays.asList("A", "M", "U")); @@ -91,14 +95,14 @@ public void onMessage(Mode mode, String action, String path) { return; } - if (StringUtils.endsWith(path, ALWAYS_SUFFIX)) { + if (StringUtils.endsWith(path, ALWAYS_SUFFIX) && isValid(path)) { logMessage(String.format("Adding %s due to having 'always' in name.", path)); paths.add(path); return; } if (!ACTIONS.contains(action) && isValid(path)) { - logMessage(String.format("Skipping %s due to non matching action '%s'", path, action)); + LOG.debug(String.format("Skipping %s due to non matching action '%s'", path, action)); return; } diff --git a/core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java b/core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java index cb38f1fd..1af6a41d 100644 --- a/core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java +++ b/core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java @@ -4,14 +4,12 @@ import java.io.PrintStream; import java.io.UnsupportedEncodingException; -import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.ResourceResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.base.Charsets; import com.icfolson.aem.groovy.console.api.context.ScriptContext; -import com.icfolson.aem.groovy.console.constants.GroovyConsoleConstants; /** * Script context to run Groovy Console scripts. @@ -26,24 +24,20 @@ public class AecuScriptContext implements ScriptContext { private ResourceResolver resolver; private ByteArrayOutputStream out = new ByteArrayOutputStream(); - private SlingHttpServletRequest request; - /** * Constructor * * @param script script content * @param resolver resolver - * @param request request */ - public AecuScriptContext(String script, ResourceResolver resolver, SlingHttpServletRequest request) { + public AecuScriptContext(String script, ResourceResolver resolver) { this.script = script; this.resolver = resolver; - this.request = request; } @Override public String getData() { - return request.getParameter(GroovyConsoleConstants.DATA); + return null; } @Override @@ -73,7 +67,7 @@ public String getScript() { @Override public String getUserId() { - return request.getResourceResolver().getUserID(); + return resolver.getUserID(); } } diff --git a/core/src/main/java/de/valtech/aecu/core/service/AecuServiceImpl.java b/core/src/main/java/de/valtech/aecu/core/service/AecuServiceImpl.java index dd3f58b8..03ad06b3 100644 --- a/core/src/main/java/de/valtech/aecu/core/service/AecuServiceImpl.java +++ b/core/src/main/java/de/valtech/aecu/core/service/AecuServiceImpl.java @@ -26,14 +26,9 @@ import java.util.List; import java.util.Set; -import javax.jcr.Binary; -import javax.jcr.Node; -import javax.jcr.RepositoryException; - import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.JcrConstants; -import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; @@ -192,9 +187,8 @@ public ExecutionResult execute(String path) throws AecuException { * @throws AecuException error running script */ private ExecutionResult executeScript(ResourceResolver resolver, String path) throws AecuException { - SlingHttpServletRequest slingRequest = new GroovyConsoleRequest(resolver); LOG.info("Executing script " + path); - ScriptContext scriptContext = new AecuScriptContext(loadScript(path, resolver), resolver, slingRequest); + ScriptContext scriptContext = new AecuScriptContext(loadScript(path, resolver), resolver); RunScriptResponse response = groovyConsoleService.runScript(scriptContext); boolean success = StringUtils.isBlank(response.getExceptionStackTrace()); if (success) { @@ -222,14 +216,14 @@ private ExecutionResult executeScript(ResourceResolver resolver, String path) th */ private String loadScript(String path, ResourceResolver resolver) throws AecuException { Resource resource = resolver.getResource(path + "/" + JcrConstants.JCR_CONTENT); - Binary binary; - try { - binary = resource.adaptTo(Node.class).getProperty(JcrConstants.JCR_DATA).getBinary(); - InputStream inputStream = binary.getStream(); - String script = IOUtils.toString(inputStream, StandardCharsets.UTF_8.name()); - binary.dispose(); - return script; - } catch (RepositoryException | IOException e) { + // https://sling.apache.org/documentation/the-sling-engine/resources.html#binary-support + try (InputStream inputStream = resource.adaptTo(InputStream.class)) { + if (inputStream == null) { + throw new IOException( + "Resource at '" + path + "' cannot be adapted to InputStream, it doesn't seem to contain binary data"); + } + return IOUtils.toString(inputStream, StandardCharsets.UTF_8); + } catch (IOException e) { throw new AecuException("Unable to read script", e); } } diff --git a/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleRequest.java b/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleRequest.java deleted file mode 100644 index 64b6456d..00000000 --- a/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleRequest.java +++ /dev/null @@ -1,488 +0,0 @@ -/* - * Copyright 2018 - 2019 Valtech GmbH - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.valtech.aecu.core.service; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.Principal; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; - -import javax.servlet.AsyncContext; -import javax.servlet.DispatcherType; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import javax.servlet.http.Part; - -import org.apache.sling.api.SlingHttpServletRequest; -import org.apache.sling.api.request.RequestDispatcherOptions; -import org.apache.sling.api.request.RequestParameter; -import org.apache.sling.api.request.RequestParameterMap; -import org.apache.sling.api.request.RequestPathInfo; -import org.apache.sling.api.request.RequestProgressTracker; -import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ResourceResolver; - -/** - * Dummy request that is used to execute the script. - * - * @author Roland Gruber - */ -public class GroovyConsoleRequest implements SlingHttpServletRequest { - - private ResourceResolver resolver; - - /** - * Constructor - * - * @param resolver resource resolver - */ - public GroovyConsoleRequest(ResourceResolver resolver) { - this.resolver = resolver; - } - - @Override - public String getAuthType() { - return null; - } - - @Override - public String getContextPath() { - return null; - } - - @Override - public Cookie[] getCookies() { - return new Cookie[0]; - } - - @Override - public long getDateHeader(String arg0) { - return 0; - } - - @Override - public String getHeader(String arg0) { - return null; - } - - @Override - public Enumeration getHeaderNames() { - return null; - } - - @Override - public Enumeration getHeaders(String arg0) { - return null; - } - - @Override - public int getIntHeader(String arg0) { - return 0; - } - - @Override - public String getMethod() { - return null; - } - - @Override - public String getPathInfo() { - return null; - } - - @Override - public String getPathTranslated() { - return null; - } - - @Override - public String getQueryString() { - return null; - } - - @Override - public String getRemoteUser() { - return null; - } - - @Override - public String getRequestURI() { - return null; - } - - @Override - public StringBuffer getRequestURL() { - return null; - } - - @Override - public String getRequestedSessionId() { - return null; - } - - @Override - public String getServletPath() { - return null; - } - - @Override - public HttpSession getSession() { - return null; - } - - @Override - public HttpSession getSession(boolean arg0) { - return null; - } - - @Override - public Principal getUserPrincipal() { - return null; - } - - @Override - public boolean isRequestedSessionIdFromCookie() { - return false; - } - - @Override - public boolean isRequestedSessionIdFromURL() { - return false; - } - - @Override - public boolean isRequestedSessionIdFromUrl() { - return false; - } - - @Override - public boolean isRequestedSessionIdValid() { - return false; - } - - @Override - public boolean isUserInRole(String arg0) { - return false; - } - - @Override - public Object getAttribute(String arg0) { - return null; - } - - @Override - public Enumeration getAttributeNames() { - return null; - } - - @Override - public String getCharacterEncoding() { - return null; - } - - @Override - public int getContentLength() { - return 0; - } - - @Override - public String getContentType() { - return null; - } - - @Override - public ServletInputStream getInputStream() throws IOException { - return null; - } - - @Override - public String getLocalAddr() { - return null; - } - - @Override - public String getLocalName() { - return null; - } - - @Override - public int getLocalPort() { - return 0; - } - - @Override - public Locale getLocale() { - return null; - } - - @Override - public Enumeration getLocales() { - return null; - } - - @Override - public String getParameter(String arg0) { - return null; - } - - @Override - public Map getParameterMap() { - return null; - } - - @Override - public Enumeration getParameterNames() { - return null; - } - - @Override - public String[] getParameterValues(String arg0) { - return new String[0]; - } - - @Override - public String getProtocol() { - return null; - } - - @Override - public BufferedReader getReader() throws IOException { - return null; - } - - @Override - public String getRealPath(String arg0) { - return null; - } - - @Override - public String getRemoteAddr() { - return null; - } - - @Override - public String getRemoteHost() { - return null; - } - - @Override - public int getRemotePort() { - return 0; - } - - @Override - public RequestDispatcher getRequestDispatcher(String arg0) { - return null; - } - - @Override - public String getScheme() { - return null; - } - - @Override - public String getServerName() { - return null; - } - - @Override - public int getServerPort() { - return 0; - } - - @Override - public boolean isSecure() { - return false; - } - - @Override - public void removeAttribute(String arg0) { - throw new UnsupportedOperationException("removeAttribute not implemented"); - } - - @Override - public void setAttribute(String arg0, Object arg1) { - throw new UnsupportedOperationException("setAttribute not implemented"); - } - - @Override - public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException { - throw new UnsupportedOperationException("setCharacterEncoding not implemented"); - } - - @Override - public T adaptTo(Class arg0) { - return null; - } - - @Override - public Cookie getCookie(String arg0) { - return null; - } - - @Override - public RequestDispatcher getRequestDispatcher(Resource arg0) { - return null; - } - - @Override - public RequestDispatcher getRequestDispatcher(String arg0, RequestDispatcherOptions arg1) { - return null; - } - - @Override - public RequestDispatcher getRequestDispatcher(Resource arg0, RequestDispatcherOptions arg1) { - return null; - } - - @Override - public RequestParameter getRequestParameter(String arg0) { - return null; - } - - @Override - public List getRequestParameterList() { - return Collections.emptyList(); - } - - @Override - public RequestParameterMap getRequestParameterMap() { - return null; - } - - @Override - public RequestParameter[] getRequestParameters(String arg0) { - return new RequestParameter[0]; - } - - @Override - public RequestPathInfo getRequestPathInfo() { - return null; - } - - @Override - public RequestProgressTracker getRequestProgressTracker() { - return null; - } - - @Override - public Resource getResource() { - return null; - } - - @Override - public ResourceBundle getResourceBundle(Locale arg0) { - return null; - } - - @Override - public ResourceBundle getResourceBundle(String arg0, Locale arg1) { - return null; - } - - @Override - public ResourceResolver getResourceResolver() { - return resolver; - } - - @Override - public String getResponseContentType() { - return null; - } - - @Override - public Enumeration getResponseContentTypes() { - return null; - } - - @Override - public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { - return false; - } - - @Override - public void login(String username, String password) throws ServletException { - // ignore - } - - @Override - public void logout() throws ServletException { - // ignore - } - - @Override - public Collection getParts() throws IOException, ServletException { - return Collections.emptyList(); - } - - @Override - public Part getPart(String name) throws IOException, ServletException { - return null; - } - - @Override - public ServletContext getServletContext() { - return null; - } - - @Override - public AsyncContext startAsync() { - return null; - } - - @Override - public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) { - return null; - } - - @Override - public boolean isAsyncStarted() { - return false; - } - - @Override - public boolean isAsyncSupported() { - return false; - } - - @Override - public AsyncContext getAsyncContext() { - return null; - } - - @Override - public DispatcherType getDispatcherType() { - return null; - } - -} diff --git a/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleResponse.java b/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleResponse.java deleted file mode 100644 index e0a0209c..00000000 --- a/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleResponse.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright 2019 Valtech GmbH - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.valtech.aecu.core.service; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Collection; -import java.util.Collections; -import java.util.Locale; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.Cookie; - -import org.apache.sling.api.SlingHttpServletResponse; - -/** - * Dummy response to execute the scripts. - * - * @author Roland Gruber - * - */ -public class GroovyConsoleResponse implements SlingHttpServletResponse { - - @Override - public void addCookie(Cookie cookie) { - // not used - } - - @Override - public boolean containsHeader(String name) { - return false; - } - - @Override - public String encodeURL(String url) { - return url; - } - - @Override - public String encodeRedirectURL(String url) { - return url; - } - - @Override - public String encodeUrl(String url) { - return url; - } - - @Override - public String encodeRedirectUrl(String url) { - return url; - } - - @Override - public void sendError(int sc, String msg) throws IOException { - // not used - } - - @Override - public void sendError(int sc) throws IOException { - // not used - } - - @Override - public void sendRedirect(String location) throws IOException { - // not used - } - - @Override - public void setDateHeader(String name, long date) { - // not used - } - - @Override - public void addDateHeader(String name, long date) { - // not used - } - - @Override - public void setHeader(String name, String value) { - // not used - } - - @Override - public void addHeader(String name, String value) { - // not used - } - - @Override - public void setIntHeader(String name, int value) { - // not used - } - - @Override - public void addIntHeader(String name, int value) { - // not used - } - - @Override - public void setStatus(int sc) { - // not used - } - - @Override - public void setStatus(int sc, String sm) { - // not used - } - - @Override - public int getStatus() { - return 200; - } - - @Override - public String getHeader(String name) { - return null; - } - - @Override - public Collection getHeaders(String name) { - return Collections.emptyList(); - } - - @Override - public Collection getHeaderNames() { - return Collections.emptyList(); - } - - @Override - public String getCharacterEncoding() { - return "UTF-8"; - } - - @Override - public String getContentType() { - return null; - } - - @Override - public ServletOutputStream getOutputStream() throws IOException { - return null; - } - - @Override - public PrintWriter getWriter() throws IOException { - return null; - } - - @Override - public void setCharacterEncoding(String charset) { - // not used - } - - @Override - public void setContentLength(int len) { - // not used - } - - @Override - public void setContentType(String type) { - // not used - } - - @Override - public void setBufferSize(int size) { - // not used - } - - @Override - public int getBufferSize() { - return 0; - } - - @Override - public void flushBuffer() throws IOException { - // not used - } - - @Override - public void resetBuffer() { - // not used - } - - @Override - public boolean isCommitted() { - return false; - } - - @Override - public void reset() { - // not used - } - - @Override - public void setLocale(Locale loc) { - // not used - } - - @Override - public Locale getLocale() { - return null; - } - - @Override - public T adaptTo(Class arg0) { - return null; - } - -} diff --git a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/servlet/AceAutocompleteServletTest.java b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/servlet/AceAutocompleteServletTest.java index a52b2803..0e37a857 100644 --- a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/servlet/AceAutocompleteServletTest.java +++ b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/servlet/AceAutocompleteServletTest.java @@ -62,8 +62,9 @@ public void test_getPublicMethodsOfClass_ofAecuBinding() assertNotNull(result); assertEquals(2, result.size()); - assertEquals("contentUpgradeBuilder", result.get(0).getName()); - assertEquals("validateAccessRights", result.get(1).getName()); + for (Method method : result) { + assertTrue("contentUpgradeBuilder".equals(method.getName()) || "validateAccessRights".equals(method.getName())); + } } @Test diff --git a/core/src/test/java/de/valtech/aecu/core/service/AecuServiceImplTest.java b/core/src/test/java/de/valtech/aecu/core/service/AecuServiceImplTest.java index 0f90feaf..3732d1bb 100644 --- a/core/src/test/java/de/valtech/aecu/core/service/AecuServiceImplTest.java +++ b/core/src/test/java/de/valtech/aecu/core/service/AecuServiceImplTest.java @@ -29,14 +29,12 @@ import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.jcr.Binary; -import javax.jcr.Node; -import javax.jcr.Property; import javax.jcr.RepositoryException; import org.apache.jackrabbit.JcrConstants; @@ -100,15 +98,6 @@ public class AecuServiceImplTest { @Mock private ScriptContext scriptContext = mock(ScriptContext.class); - @Mock - private Binary binary; - - @Mock - private Node node; - - @Mock - private Property property; - @Before public void setup() throws LoginException { Set runModes = new HashSet<>(); @@ -320,10 +309,7 @@ public void execute() throws AecuException, RepositoryException { when(resource.getName()).thenReturn(FILE1); when(scriptContext.getScript()).thenReturn(DIR); ByteArrayInputStream stream = new ByteArrayInputStream("test".getBytes()); - when(binary.getStream()).thenReturn(stream); - when(resource.adaptTo(Node.class)).thenReturn(node); - when(node.getProperty(JcrConstants.JCR_DATA)).thenReturn(property); - when(property.getBinary()).thenReturn(binary); + when(resource.adaptTo(InputStream.class)).thenReturn(stream); RunScriptResponse response = DefaultRunScriptResponse.fromResult(scriptContext, null, null, null); when(groovyConsoleService.runScript(Mockito.any())).thenReturn(response); diff --git a/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleRequestTest.java b/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleRequestTest.java deleted file mode 100644 index 60169fe5..00000000 --- a/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleRequestTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2018 Valtech GmbH - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.valtech.aecu.core.service; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; - -import javax.servlet.ServletException; - -import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ResourceResolver; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -/** - * Tests GroovyConsoleRequest - * - * @author Roland Gruber - * - */ -@RunWith(MockitoJUnitRunner.class) -public class GroovyConsoleRequestTest { - - @Mock - private ResourceResolver resolver; - - private GroovyConsoleRequest request; - - @Before - public void setup() { - request = new GroovyConsoleRequest(resolver); - } - - @Test - public void getResourceResolver() { - assertEquals(resolver, request.getResourceResolver()); - } - - @Test(expected = UnsupportedOperationException.class) - public void removeAttribute() { - request.removeAttribute(""); - } - - @Test(expected = UnsupportedOperationException.class) - public void setAttribute() { - request.setAttribute(null, ""); - } - - @Test(expected = UnsupportedOperationException.class) - public void setCharacterEncoding() throws UnsupportedEncodingException { - request.setCharacterEncoding(""); - } - - @Test - public void emptyMethods() throws IOException, ServletException { - assertNull(request.getAuthType()); - assertNull(request.getContextPath()); - assertEquals(0, request.getCookies().length); - assertEquals(0, request.getDateHeader("")); - assertNull(request.getHeader("")); - assertNull(request.getHeaderNames()); - assertNull(request.getHeaders("")); - assertEquals(0, request.getIntHeader("")); - assertNull(request.getMethod()); - assertNull(request.getPathInfo()); - assertNull(request.getPathTranslated()); - assertNull(request.getQueryString()); - assertNull(request.getRemoteUser()); - assertNull(request.getRequestURI()); - assertNull(request.getRequestURL()); - assertNull(request.getRequestedSessionId()); - assertNull(request.getServletPath()); - assertNull(request.getSession()); - assertNull(request.getSession(true)); - assertFalse(request.isRequestedSessionIdFromCookie()); - assertFalse(request.isRequestedSessionIdFromURL()); - assertFalse(request.isRequestedSessionIdFromUrl()); - assertFalse(request.isRequestedSessionIdValid()); - assertFalse(request.isUserInRole("")); - assertNull(request.getAttribute("")); - assertNull(request.getAttributeNames()); - assertNull(request.getCharacterEncoding()); - assertEquals(0, request.getContentLength()); - assertNull(request.getContentType()); - assertNull(request.getInputStream()); - assertNull(request.getLocalAddr()); - assertNull(request.getLocalName()); - assertEquals(0, request.getLocalPort()); - assertNull(request.getLocale()); - assertNull(request.getLocales()); - assertNull(request.getParameter("")); - assertNull(request.getParameterMap()); - assertNull(request.getParameterNames()); - assertEquals(0, request.getParameterValues("").length); - assertNull(request.getProtocol()); - assertNull(request.getReader()); - assertNull(request.getRealPath("")); - assertNull(request.getRemoteAddr()); - assertNull(request.getRemoteHost()); - assertEquals(0, request.getRemotePort()); - assertNull(request.getRequestDispatcher("")); - assertNull(request.getScheme()); - assertNull(request.getServerName()); - assertEquals(0, request.getServerPort()); - assertFalse(request.isSecure()); - assertNull(request.adaptTo(null)); - assertNull(request.getCookie("")); - assertNull(request.getRequestDispatcher((Resource) null)); - assertNull(request.getRequestDispatcher("", null)); - assertNull(request.getRequestDispatcher((Resource) null, null)); - assertNull(request.getRequestParameter("")); - assertEquals(0, request.getRequestParameterList().size()); - assertNull(request.getRequestParameterMap()); - assertEquals(0, request.getRequestParameters("").length); - assertNull(request.getRequestPathInfo()); - assertNull(request.getRequestProgressTracker()); - assertNull(request.getResource()); - assertNull(request.getResourceBundle(null)); - assertNull(request.getResourceBundle("", null)); - assertNull(request.getResponseContentType()); - assertNull(request.getResponseContentTypes()); - assertFalse(request.authenticate(null)); - request.login(null, null); - request.logout(); - assertEquals(0, request.getParts().size()); - assertNull(request.getPart(null)); - assertNull(request.getServletContext()); - assertNull(request.startAsync()); - assertNull(request.startAsync(null, null)); - assertFalse(request.isAsyncStarted()); - assertFalse(request.isAsyncSupported()); - assertNull(request.getAsyncContext()); - assertNull(request.getDispatcherType()); - } - -} diff --git a/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleResponseTest.java b/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleResponseTest.java deleted file mode 100644 index e1759fad..00000000 --- a/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleResponseTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2019 Valtech GmbH - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.valtech.aecu.core.service; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; - -import org.junit.Before; -import org.junit.Test; - -/** - * Tests GroovyConsoleResponse - * - * @author Roland Gruber - */ -public class GroovyConsoleResponseTest { - - private static final String TEST = "testval"; - - private GroovyConsoleResponse response; - - @Before - public void setup() { - response = new GroovyConsoleResponse(); - } - - @Test - public void setters() throws IOException { - response.addCookie(null); - response.sendError(0); - response.sendError(0, TEST); - response.sendRedirect(TEST); - response.setDateHeader(TEST, 0); - response.addDateHeader(TEST, 0); - response.setHeader(TEST, TEST); - response.addHeader(TEST, TEST); - response.setIntHeader(TEST, 0); - response.addIntHeader(TEST, 0); - response.setStatus(0); - response.setStatus(0, TEST); - response.setCharacterEncoding(TEST); - response.setContentLength(0); - response.setContentType(TEST); - response.setBufferSize(0); - response.flushBuffer(); - response.resetBuffer(); - response.reset(); - response.setLocale(null); - } - - @Test - public void getters() throws IOException { - assertFalse(response.containsHeader(null)); - assertEquals(TEST, response.encodeURL(TEST)); - assertEquals(TEST, response.encodeUrl(TEST)); - assertEquals(TEST, response.encodeRedirectURL(TEST)); - assertEquals(TEST, response.encodeRedirectUrl(TEST)); - assertEquals(200, response.getStatus()); - assertNull(response.getHeader(TEST)); - assertTrue(response.getHeaders(TEST).isEmpty()); - assertTrue(response.getHeaderNames().isEmpty()); - assertEquals("UTF-8", response.getCharacterEncoding()); - assertNull(response.getContentType()); - assertNull(response.getOutputStream()); - assertNull(response.getWriter()); - assertEquals(0, response.getBufferSize()); - assertFalse(response.isCommitted()); - assertNull(response.getLocale()); - assertNull(response.adaptTo(null)); - } - -} diff --git a/examples/pom.xml b/examples/pom.xml index 54d98f96..7b0af755 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0 + 4.1.0 aecu.examples diff --git a/pom.xml b/pom.xml index fb5f8e61..ce49196a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 4.0.0 + 4.1.0 AECU AEM Easy Content Upgrade https://github.com/valtech/aem-easy-content-upgrade @@ -12,6 +12,7 @@ api core + ui.apps.structure ui.apps bundle examples @@ -128,7 +129,10 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9.1 + 3.1.0 + + 8 + org.apache.maven.plugins @@ -237,7 +241,7 @@ com.day.jcr.vault content-package-maven-plugin - 1.0.2 + 1.0.4 http://${aem.host}:${aem.port}/crx/packmgr/service.jsp true @@ -249,7 +253,7 @@ org.apache.jackrabbit filevault-package-maven-plugin - 1.0.4 + 1.1.6 true @@ -341,7 +345,7 @@ org.owasp dependency-check-maven - 5.2.4 + 6.1.6 0 true @@ -501,7 +505,7 @@ com.adobe.aem uber-jar - 6.4.3 + 6.5.3 apis provided @@ -714,12 +718,12 @@ adobe Adobe Public Repository - http://repo.adobe.com/nexus/content/groups/public/ + https://repo.adobe.com/nexus/content/groups/public/ default central - http://repo1.maven.org/maven2 + https://repo1.maven.org/maven2 default false @@ -730,7 +734,7 @@ adobe Adobe Public Repository - http://repo.adobe.com/nexus/content/groups/public/ + https://repo.adobe.com/nexus/content/groups/public/ default diff --git a/sonar-project.properties b/sonar-project.properties index 72e27f60..8a16db93 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,7 +2,7 @@ sonar.projectKey=aecu # this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1. sonar.projectName=AEM Easy Content Upgrade -sonar.projectVersion=3.4.0-SNAPSHOT +sonar.projectVersion=4.1.0-SNAPSHOT # Encoding of the source code. Default is default system encoding sonar.sourceEncoding=UTF-8 diff --git a/ui.apps.structure/.gitignore b/ui.apps.structure/.gitignore new file mode 100644 index 00000000..b83d2226 --- /dev/null +++ b/ui.apps.structure/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/ui.apps.structure/pom.xml b/ui.apps.structure/pom.xml new file mode 100644 index 00000000..e542f116 --- /dev/null +++ b/ui.apps.structure/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + + de.valtech.aecu + aecu + 4.1.0 + + + aecu.ui.apps.structure + content-package + AECU - Repository Structure Package + + Empty package that defines the structure of the Adobe Experience Manager repository the Code packages in this project deploy into. + Any roots in the Code packages of this project should have their parent enumerated in the Filters list below. + + + + + + org.apache.jackrabbit + filevault-package-maven-plugin + true + + + none + + + /apps + /apps/sling + /apps/cq + /apps/dam + /apps/wcm + /apps/msm + /apps/settings + /home/users + /home/users/system + /var/workflow/models + /var/workflow/models/dam + /conf + /conf/global + /conf/global/settings + + + + + + diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index c9248268..8f484ac1 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0 + 4.1.0 aecu.ui.apps @@ -77,6 +77,17 @@ true true Valtech + + + de.valtech.aecu + aecu.ui.apps.structure + + + + + true + + merge_preserve /apps/valtech/aecu/(config|install)/.* @@ -126,5 +137,11 @@ aecu.api ${project.version} + + de.valtech.aecu + aecu.ui.apps.structure + ${project.version} + zip + diff --git a/ui.apps/src/main/content/jcr_root/var/aecu/_oak_index/.content.xml b/ui.apps/src/main/content/jcr_root/var/aecu/_oak_index/.content.xml index 72cb10b7..d680f4b6 100644 --- a/ui.apps/src/main/content/jcr_root/var/aecu/_oak_index/.content.xml +++ b/ui.apps/src/main/content/jcr_root/var/aecu/_oak_index/.content.xml @@ -1,4 +1,5 @@ \ No newline at end of file