Skip to content

Commit

Permalink
Merge branch 'release/4.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberrolandvaltech committed Dec 21, 2020
2 parents 4fad352 + e5dc90c commit a07d933
Show file tree
Hide file tree
Showing 41 changed files with 666 additions and 92 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ develop, gh-pages, master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ develop ]
schedule:
- cron: '41 1 * * 6'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: [ 'java', 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# 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

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
5 changes: 5 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
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
- Convert GString values in binding methods (#140)

2020-10-07 3.3.0
- Allow to change primary type
- Documentation and example updates
Expand Down
10 changes: 6 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ Table of contents

# Requirements

AECU requires Java 8 and AEM 6.4 or above. For AEM 6.3 please install the last 1.x version of AECU. Groovy Console can be installed manually if [bundle install](#bundleInstall) is not used.
AECU requires Java 8 and AEM 6.5 or above. For AEM 6.3/6.4 please see below. Groovy Console can be installed manually if [bundle install](#bundleInstall) is not used.

| AEM Version | Groovy Console | AECU |
| ------------- | -------------- | --------- |
| 6.3 | 12.x | 1.x |
| 6.4 | 14.x, 13.x | 3.x, 2.x |
| 6.5 | 14.x, 13.x | 3.x, 2.x |
| AEM Cloud | 16.x <br/>14.x, 13.x | 4.x<br/> 3.x, 2.x |
| 6.5 | 16.x <br/>14.x, 13.x | 4.x<br/> 3.x, 2.x |
| 6.4 | 14.x, 13.x | 3.x, 2.x |
| 6.3 | 12.x | 1.x |

<a name="installation"></a>

Expand Down Expand Up @@ -345,6 +346,7 @@ def complexFilter = new ORFilter(
aecu.contentUpgradeBuilder()
.forDescendantResourcesOf("/content/we-retail/ca/en", false)
.filterWith(complexFilter)
.filterWith(new NOTFilter(new FilterByPathRegex(".*jcr:content.*")))
.doSetProperty("name", "value")
.run()
```
Expand Down
5 changes: 5 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Security Policy

## Reporting a Vulnerability

Please create an issue and provide details like the attack vector or examples for exploitation.
6 changes: 5 additions & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>3.3.0</version>
<version>4.0.0</version>
</parent>

<artifactId>aecu.api</artifactId>
Expand Down Expand Up @@ -86,6 +86,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package de.valtech.aecu.api.groovy.console.bindings;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import groovy.lang.GString;

/**
* Converts GString to String.
*
* @author Roland Gruber
*/
public class GStringConverter {

private GStringConverter() {
// no instantiation
}

/**
* Converts the input in case it is a GString.
*
* @param input input
* @return converted value
*/
public static Object convert(Object input) {
if (input instanceof GString) {
return ((GString) input).toString();
}
return input;
}

/**
* Converts the input in case it is a GString.
*
* @param input input
* @return converted value
*/
public static Map<String, Object> convert(Map<String, Object> input) {
if (input == null) {
return input;
}
Map<String, Object> output = new HashMap<>(input);
for (Map.Entry<String, Object> entry : input.entrySet()) {
if (entry.getValue() instanceof GString) {
output.put(entry.getKey(), convert(entry.getValue()));
}
}
return output;
}

/**
* Converts the input in case it is a GString.
*
* @param input input
* @return converted value
*/
public static Object[] convert(Object[] input) {
if (input == null) {
return input;
}
Object[] output = Arrays.copyOf(input, input.length);
for (int i = 0; i < output.length; i++) {
output[i] = convert(output[i]);
}
return output;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 - 2019 Valtech GmbH
* Copyright 2018 - 2020 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,
Expand All @@ -25,6 +25,8 @@
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;

import de.valtech.aecu.api.groovy.console.bindings.GStringConverter;

/**
* Filters resources by multi-value properties. It checks if the given values are contained in the
* resource's multi-value field, no exact match.
Expand All @@ -44,12 +46,12 @@ public class FilterByMultiValuePropContains implements FilterBy {
*/
public FilterByMultiValuePropContains(@Nonnull String name, @Nonnull Object[] values) {
this.name = name;
this.values = values;
this.values = GStringConverter.convert(values);
}

@Override
public boolean filter(@Nonnull Resource resource, StringBuilder output) {
ValueMap properties = resource.adaptTo(ValueMap.class);
ValueMap properties = resource.getValueMap();
if (properties != null) {
Object value = properties.get(name);
if (value != null && value.getClass().isArray()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

import javax.annotation.Nonnull;

import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;

import de.valtech.aecu.api.groovy.console.bindings.GStringConverter;

/**
* Filters resources by properties. You can define multiple properties that all need an exact match.
Expand All @@ -43,12 +45,12 @@ public class FilterByProperties implements FilterBy {
* @param conditionProperties list of properties to match (property name, property value)
*/
public FilterByProperties(@Nonnull Map<String, Object> conditionProperties) {
this.conditionProperties.putAll(conditionProperties);
this.conditionProperties.putAll(GStringConverter.convert(conditionProperties));
}

@Override
public boolean filter(@Nonnull Resource resource, StringBuilder output) {
ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class);
ValueMap properties = resource.getValueMap();
if (properties == null) {
output.append("WARNING: Could not get ModifiableValueMap of resource " + resource.getPath());
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;

import de.valtech.aecu.api.groovy.console.bindings.GStringConverter;

/**
* Filters resources by a given property. The filter only matches if the attribute exists and has
* the exact given value.
Expand All @@ -42,7 +44,7 @@ public class FilterByProperty implements FilterBy {
*/
public FilterByProperty(@Nonnull String name, Object value) {
this.name = name;
this.value = value;
this.value = GStringConverter.convert(value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Roxana Muresan
*/
@Version("4.3.0")
@Version("4.4.0")
package de.valtech.aecu.api.groovy.console.bindings;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright 2020 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.ValueMap;
import org.codehaus.groovy.runtime.GStringImpl;
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.FilterByMultiValuePropContains;
import groovy.lang.GString;

/**
* Tests FilterByMultiValuePropContains
*
* @author Roland Gruber
*
*/
@RunWith(MockitoJUnitRunner.class)
public class FilterByMultiValuePropContainsTest {

private static final String NAME1 = "name";
private static final String VALUE1 = "value";
private static final String NAME2 = "name2";
private static final String VALUE2 = "value2";
private static final String NAME3 = "name3";
private static final GString VALUE_G = new GStringImpl(new Object[] {2}, new String[] {"value"});

@Mock
private Resource resource;

@Mock
ValueMap values;

@Before
public void setup() {
when(resource.getValueMap()).thenReturn(values);
when(values.get(NAME1)).thenReturn(new Object[] {VALUE1, VALUE2});
when(values.get(NAME2)).thenReturn(new Object[] {VALUE2});
}

@Test
public void filterAttributeNull_filterValueEmpty() {
Object[] filterAttributes = new Object[0];
FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME1, filterAttributes);

assertTrue(filter.filter(resource, new StringBuilder()));
}

@Test
public void filterAttributeNull_filterValueNonNull() {
Object[] filterAttributes = new Object[] {VALUE1};
FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME3, filterAttributes);

assertFalse(filter.filter(resource, new StringBuilder()));
}

@Test
public void filterAttributeNonNull_filterValueNonNull() {
Object[] filterAttributes = new Object[] {VALUE1};
FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME1, filterAttributes);

assertTrue(filter.filter(resource, new StringBuilder()));
}

@Test
public void filterAttributeNonNull_filterValueMulti() {
Object[] filterAttributes = new Object[] {VALUE1, VALUE2};
FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME1, filterAttributes);

assertTrue(filter.filter(resource, new StringBuilder()));
}

@Test
public void filterAttributeGString() {
Object[] filterAttributes = new Object[] {VALUE_G};
FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME2, filterAttributes);

assertTrue(filter.filter(resource, new StringBuilder()));
}

}
Loading

0 comments on commit a07d933

Please sign in to comment.