sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-fsresource] 17/29: SLING-6440 use ManifestHeader to parse directives
Date Tue, 07 Nov 2017 09:38:50 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.fsresource-2.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git

commit 94499336c2bc1a393a94ebe97b26dc4b8ef14041
Author: Stefan Seifert <sseifert@apache.org>
AuthorDate: Wed Mar 8 16:36:17 2017 +0000

    SLING-6440 use ManifestHeader to parse directives
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/fsresource@1786016
13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  6 ++++
 .../internal/InitialContentImportOptions.java      | 33 +++++++++-------------
 .../internal/InitialContentImportOptionsTest.java  |  4 +--
 3 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/pom.xml b/pom.xml
index def0725..f7f45c8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -139,6 +139,12 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
+            <version>2.2.0</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.fscontentparser</artifactId>
             <version>1.0.0-SNAPSHOT</version>
             <scope>compile</scope>
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/InitialContentImportOptions.java
b/src/main/java/org/apache/sling/fsprovider/internal/InitialContentImportOptions.java
index 5353d0f..52de538 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/InitialContentImportOptions.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/InitialContentImportOptions.java
@@ -19,13 +19,14 @@
 package org.apache.sling.fsprovider.internal;
 
 import java.util.Arrays;
-import java.util.HashMap;
+import java.util.Collections;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.commons.osgi.ManifestHeader;
+import org.apache.sling.commons.osgi.ManifestHeader.Entry;
 
 class InitialContentImportOptions {
 
@@ -46,25 +47,19 @@ class InitialContentImportOptions {
     private final Set<String> ignoreImportProviders;
     
     public InitialContentImportOptions(String optionsString) {
-        Map<String,String> options = parseOptions(optionsString);
-        overwrite = BooleanUtils.toBoolean(options.get(OVERWRITE_DIRECTIVE));
-        ignoreImportProviders = new HashSet<>(Arrays.asList(StringUtils.split(StringUtils.defaultString(options.get(IGNORE_CONTENT_READERS_DIRECTIVE)))));
-    }
-    
-    private static Map<String,String> parseOptions(String optionsString) {
-        Map<String,String> options = new HashMap<>();
-        String[] optionsList = StringUtils.split(optionsString, ";");
-        if (optionsList != null) {
-            for (String keyValueString : optionsList) {
-                String[] keyValue = StringUtils.splitByWholeSeparator(keyValueString, ":=");
-                if (keyValue.length == 2) {
-                    options.put(StringUtils.trim(keyValue[0]), StringUtils.trim(keyValue[1]));
-                }
-            }
+        ManifestHeader header = ManifestHeader.parse("/dummy/path;" + optionsString);
+        Entry[] entries = header.getEntries();
+        if (entries.length > 0) {
+            overwrite = BooleanUtils.toBoolean(entries[0].getDirectiveValue(OVERWRITE_DIRECTIVE));
+            String ignoreImportProvidersString = StringUtils.defaultString(entries[0].getDirectiveValue(IGNORE_CONTENT_READERS_DIRECTIVE));
+            ignoreImportProviders = new HashSet<>(Arrays.asList(StringUtils.split(ignoreImportProvidersString,
",")));
+        }
+        else {
+            overwrite = false;
+            ignoreImportProviders = Collections.emptySet();
         }
-        return options;
     }
-
+    
     public boolean isOverwrite() {
         return overwrite;
     }
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/InitialContentImportOptionsTest.java
b/src/test/java/org/apache/sling/fsprovider/internal/InitialContentImportOptionsTest.java
index 513c51f..3a0d166 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/InitialContentImportOptionsTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/InitialContentImportOptionsTest.java
@@ -44,9 +44,9 @@ public class InitialContentImportOptionsTest {
 
     @Test
     public void testOptions1() {
-        InitialContentImportOptions underTest = new InitialContentImportOptions("overwrite:=true;ignoreImportProviders:=xml,json");
+        InitialContentImportOptions underTest = new InitialContentImportOptions("overwrite:=true;ignoreImportProviders:=\"xml,json\"");
         assertTrue(underTest.isOverwrite());
-        assertEquals(ImmutableSet.of("xml,json"), underTest.getIgnoreImportProviders());
+        assertEquals(ImmutableSet.of("xml","json"), underTest.getIgnoreImportProviders());
     }
 
     @Test

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message