From 8252e8aed05deccce891855ffc1face6b72e8d34 Mon Sep 17 00:00:00 2001 From: Dominik Przybyl Date: Mon, 2 Oct 2023 12:26:27 +0200 Subject: [PATCH] added data source support --- .../grammar/datasource/ContentDataSource.java | 16 ++++++++---- .../core/grammar/datasource/DataSource.java | 3 +-- .../grammar/datasource/DataSourceInvoker.java | 7 +++-- .../grammar/datasource/GroupsDataSource.java | 12 ++++----- .../grammar/datasource/LowerDataSource.java | 3 +-- .../grammar/datasource/NodesDataSource.java | 7 +++-- .../grammar/datasource/UpperDataSource.java | 3 +-- .../datasource/ValueMapDataSource.java | 18 ++++++++----- .../apm/core/logger/ProgressEntry.java | 2 +- .../com/cognifide/apm/core/grammar/ApmType.kt | 6 ++--- .../core/grammar/argument/ArgumentResolver.kt | 26 +++++++++++++++++-- 11 files changed, 65 insertions(+), 38 deletions(-) diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/ContentDataSource.java b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/ContentDataSource.java index 3cce5e9a..91775199 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/ContentDataSource.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/ContentDataSource.java @@ -19,17 +19,23 @@ */ package com.cognifide.apm.core.grammar.datasource; -import com.cognifide.apm.core.grammar.*; +import com.cognifide.apm.core.grammar.ApmEmpty; +import com.cognifide.apm.core.grammar.ApmList; +import com.cognifide.apm.core.grammar.ApmMap; +import com.cognifide.apm.core.grammar.ApmString; +import com.cognifide.apm.core.grammar.ApmType; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.osgi.service.component.annotations.Component; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - @Component public class ContentDataSource implements DataSource { diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/DataSource.java b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/DataSource.java index cbc145e1..6e026610 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/DataSource.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/DataSource.java @@ -20,9 +20,8 @@ package com.cognifide.apm.core.grammar.datasource; import com.cognifide.apm.core.grammar.ApmType; -import org.apache.sling.api.resource.ResourceResolver; - import java.util.List; +import org.apache.sling.api.resource.ResourceResolver; public interface DataSource { diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/DataSourceInvoker.java b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/DataSourceInvoker.java index e596df06..b17ce4cd 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/DataSourceInvoker.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/DataSourceInvoker.java @@ -20,16 +20,15 @@ package com.cognifide.apm.core.grammar.datasource; import com.cognifide.apm.core.grammar.ApmType; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.sling.api.resource.ResourceResolver; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; import org.osgi.service.component.annotations.ReferencePolicy; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - @Component(service = DataSourceInvoker.class) public class DataSourceInvoker { diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/GroupsDataSource.java b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/GroupsDataSource.java index cb9e7a8b..312b3a10 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/GroupsDataSource.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/GroupsDataSource.java @@ -1,16 +1,14 @@ package com.cognifide.apm.core.grammar.datasource; -import com.cognifide.apm.core.grammar.*; -import org.apache.commons.lang3.StringUtils; -import org.apache.sling.api.resource.ResourceResolver; -import org.osgi.service.component.annotations.Component; - +import com.cognifide.apm.core.grammar.ApmList; +import com.cognifide.apm.core.grammar.ApmString; +import com.cognifide.apm.core.grammar.ApmType; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.sling.api.resource.ResourceResolver; +import org.osgi.service.component.annotations.Component; @Component public class GroupsDataSource implements DataSource { diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/LowerDataSource.java b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/LowerDataSource.java index 01ddf7ee..4b656bde 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/LowerDataSource.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/LowerDataSource.java @@ -21,11 +21,10 @@ import com.cognifide.apm.core.grammar.ApmString; import com.cognifide.apm.core.grammar.ApmType; +import java.util.List; import org.apache.sling.api.resource.ResourceResolver; import org.osgi.service.component.annotations.Component; -import java.util.List; - @Component public class LowerDataSource implements DataSource { diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/NodesDataSource.java b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/NodesDataSource.java index 0d10e7f0..3c9caee2 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/NodesDataSource.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/NodesDataSource.java @@ -23,16 +23,15 @@ import com.cognifide.apm.core.grammar.ApmMap; import com.cognifide.apm.core.grammar.ApmString; import com.cognifide.apm.core.grammar.ApmType; -import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ResourceResolver; -import org.osgi.service.component.annotations.Component; - import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.StreamSupport; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ResourceResolver; +import org.osgi.service.component.annotations.Component; @Component public class NodesDataSource implements DataSource { diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/UpperDataSource.java b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/UpperDataSource.java index e72cac08..19705fef 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/UpperDataSource.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/UpperDataSource.java @@ -21,11 +21,10 @@ import com.cognifide.apm.core.grammar.ApmString; import com.cognifide.apm.core.grammar.ApmType; +import java.util.List; import org.apache.sling.api.resource.ResourceResolver; import org.osgi.service.component.annotations.Component; -import java.util.List; - @Component public class UpperDataSource implements DataSource { diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/ValueMapDataSource.java b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/ValueMapDataSource.java index 712c419f..e303f506 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/ValueMapDataSource.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/ValueMapDataSource.java @@ -19,16 +19,22 @@ */ package com.cognifide.apm.core.grammar.datasource; -import com.cognifide.apm.core.grammar.*; +import com.cognifide.apm.core.grammar.ApmInteger; +import com.cognifide.apm.core.grammar.ApmList; +import com.cognifide.apm.core.grammar.ApmMap; +import com.cognifide.apm.core.grammar.ApmString; +import com.cognifide.apm.core.grammar.ApmType; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ValueMap; import org.osgi.service.component.annotations.Component; -import java.io.InputStream; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.stream.Collectors; - @Component public class ValueMapDataSource implements DataSource { diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/logger/ProgressEntry.java b/app/aem/core/src/main/java/com/cognifide/apm/core/logger/ProgressEntry.java index 25fa80dc..9afaebc4 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/logger/ProgressEntry.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/logger/ProgressEntry.java @@ -74,7 +74,7 @@ public List getMessages() { @Override public List getPrettyMessages() { return messages.stream() - .map(message -> message.replaceAll("\n", "
").replaceAll("\t", "    ")) + .map(message -> message.replaceAll("\n", "
").replaceAll("\t", "    ")) .collect(Collectors.toList()); } diff --git a/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/ApmType.kt b/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/ApmType.kt index 8dce5814..361e972a 100644 --- a/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/ApmType.kt +++ b/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/ApmType.kt @@ -82,7 +82,7 @@ data class ApmList(val value: List) : ApmType() { } override fun prettyPrint(depth: Int, prefixDepth: Int): String { - return if (value.all { it is ApmString || it is ApmInteger }) { + return if (value.isEmpty() || value.all { it is ApmString || it is ApmInteger }) { value.joinToString( prefix = "\t".repeat(prefixDepth) + "[", postfix = "]" @@ -109,9 +109,9 @@ data class ApmMap(val value: Map) : ApmType() { } override fun prettyPrint(depth: Int, prefixDepth: Int): String { - return if (value.size == 1 + return if (value.isEmpty() || value.size == 1 && (value.values.all { it is ApmString || it is ApmInteger } - || value.values.filterIsInstance().first().value.all { it is ApmString || it is ApmInteger }) + || value.values.first { it is ApmList }.list!!.all { it is ApmString || it is ApmInteger }) ) { value.entries.joinToString( prefix = "\t".repeat(prefixDepth) + "{", diff --git a/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/argument/ArgumentResolver.kt b/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/argument/ArgumentResolver.kt index 6078b615..282c9ab5 100644 --- a/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/argument/ArgumentResolver.kt +++ b/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/argument/ArgumentResolver.kt @@ -20,8 +20,30 @@ package com.cognifide.apm.core.grammar.argument -import com.cognifide.apm.core.grammar.* -import com.cognifide.apm.core.grammar.antlr.ApmLangParser.* +import com.cognifide.apm.core.grammar.ApmEmpty +import com.cognifide.apm.core.grammar.ApmInteger +import com.cognifide.apm.core.grammar.ApmList +import com.cognifide.apm.core.grammar.ApmMap +import com.cognifide.apm.core.grammar.ApmPair +import com.cognifide.apm.core.grammar.ApmString +import com.cognifide.apm.core.grammar.ApmType +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.ArgumentContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.ArrayContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.ComplexArgumentsContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.DataSourceContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.ExpressionContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.FlagContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.NameContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.NamedArgumentContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.NamedArgumentsContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.NumberValueContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.PathContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.PrivilegeNameContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.RequiredArgumentContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.StringValueContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.StructureContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.StructureEntryContext +import com.cognifide.apm.core.grammar.antlr.ApmLangParser.VariableContext import com.cognifide.apm.core.grammar.common.getIdentifier import com.cognifide.apm.core.grammar.common.getKey import com.cognifide.apm.core.grammar.common.getPath