sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [sling-org-apache-sling-feature-io] 02/02: [Sling Feature Model] Refactor FeatureUtil out of the support module
Date Fri, 27 Apr 2018 09:56:01 GMT
This is an automated email from the ASF dual-hosted git repository.

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-io.git

commit 9a052aecbfac38cdaf947b5c09ae708e3509fc49
Author: David Bosschaert <david.bosschaert@gmail.com>
AuthorDate: Wed Apr 25 13:40:18 2018 +0100

    [Sling Feature Model] Refactor FeatureUtil out of the support module
    
    Also move the Resolver API to the resolver module.
---
 .../feature/io/{FileUtils.java => IOUtils.java}    | 44 ++++++++++++++++++++--
 .../io/{FeatureUtilTest.java => IOUtilsTest.java}  |  6 +--
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/io/FileUtils.java b/src/main/java/org/apache/sling/feature/io/IOUtils.java
similarity index 83%
rename from src/main/java/org/apache/sling/feature/io/FileUtils.java
rename to src/main/java/org/apache/sling/feature/io/IOUtils.java
index a54d933..70af38c 100644
--- a/src/main/java/org/apache/sling/feature/io/FileUtils.java
+++ b/src/main/java/org/apache/sling/feature/io/IOUtils.java
@@ -16,7 +16,13 @@
  */
 package org.apache.sling.feature.io;
 
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.io.json.FeatureJSONReader;
+import org.apache.sling.feature.io.json.FeatureJSONReader.SubstituteVariables;
+
 import java.io.File;
+import java.io.FileReader;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.util.ArrayList;
@@ -24,7 +30,7 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 
-public class FileUtils {
+public class IOUtils {
 
     /** The extension for a reference file. */
     public static final String EXTENSION_REF_FILE = ".ref";
@@ -155,8 +161,40 @@ public class FileUtils {
         return paths;
     }
 
-    static final Comparator<String> FEATURE_PATH_COMP = new Comparator<String>()
{
+    /**
+     * Read the feature
+     *
+     * @param url The feature url
+     * @param artifactManager The artifact manager to read the feature
+     * @param substituteVariables Variable substitution handling
+     * @return The read feature
+     * @throws IOException If reading fails
+     */
+    public static Feature getFeature(final String url,
+            final ArtifactManager artifactManager,
+            final SubstituteVariables substituteVariables)
+    throws IOException {
+        final ArtifactHandler featureArtifact = artifactManager.getArtifactHandler(url);
 
+        try (final FileReader r = new FileReader(featureArtifact.getFile())) {
+            final Feature f = FeatureJSONReader.read(r, featureArtifact.getUrl(), substituteVariables);
+            return f;
+        }
+    }
+
+    /**
+     * Get an artifact id for the Apache Felix framework
+     * @param version The version to use or {@code null} for the default version
+     * @return The artifact id
+     * @throws IllegalArgumentException If the provided version is invalid
+     */
+    public static ArtifactId getFelixFrameworkId(final String version) {
+        return new ArtifactId("org.apache.felix",
+                "org.apache.felix.framework",
+                version != null ? version : "5.6.10", null, null);
+    }
+
+    static final Comparator<String> FEATURE_PATH_COMP = new Comparator<String>()
{
         @Override
         public int compare(final String o1, final String o2) {
             // windows path conversion
@@ -194,8 +232,6 @@ public class FileUtils {
         }
     }
 
-
-
     private static void processFile(final List<String> paths, final File f)
     throws IOException {
         if ( f.getName().endsWith(EXTENSION_REF_FILE) ) {
diff --git a/src/test/java/org/apache/sling/feature/io/FeatureUtilTest.java b/src/test/java/org/apache/sling/feature/io/IOUtilsTest.java
similarity index 92%
rename from src/test/java/org/apache/sling/feature/io/FeatureUtilTest.java
rename to src/test/java/org/apache/sling/feature/io/IOUtilsTest.java
index e06b175..08ce172 100644
--- a/src/test/java/org/apache/sling/feature/io/FeatureUtilTest.java
+++ b/src/test/java/org/apache/sling/feature/io/IOUtilsTest.java
@@ -23,10 +23,10 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.sling.feature.io.FileUtils;
+import org.apache.sling.feature.io.IOUtils;
 import org.junit.Test;
 
-public class FeatureUtilTest {
+public class IOUtilsTest {
 
     @Test public void testFileSort() {
         final String[] files = new String[] {
@@ -41,7 +41,7 @@ public class FeatureUtilTest {
         };
 
         final List<String> l = new ArrayList<>(Arrays.asList(files));
-        Collections.sort(l, FileUtils.FEATURE_PATH_COMP);
+        Collections.sort(l, IOUtils.FEATURE_PATH_COMP);
         for(int i=0; i<files.length; i++) {
             assertEquals(files[i], l.get(i));
         }

-- 
To stop receiving notification emails like this one, please contact
davidb@apache.org.

Mime
View raw message