You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2018/04/18 08:12:16 UTC

[sling-whiteboard] branch master updated: Clean up file util

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 32620d4  Clean up file util
32620d4 is described below

commit 32620d4a57e14e87a9e766285d6e439760f4eed6
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Apr 18 10:12:08 2018 +0200

    Clean up file util
---
 .../modelconverter/impl/FeatureToProvisioning.java |  2 +-
 .../modelconverter/impl/ModelConverterTest.java    |  9 +++----
 .../apache/sling/feature/support/FeatureUtil.java  | 23 +++++++++++++++++-
 .../apache/sling/feature/support/io/FileUtils.java | 28 ----------------------
 4 files changed, 28 insertions(+), 34 deletions(-)

diff --git a/featuremodel/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/FeatureToProvisioning.java b/featuremodel/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/FeatureToProvisioning.java
index fb565e9..fd1d268 100644
--- a/featuremodel/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/FeatureToProvisioning.java
+++ b/featuremodel/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/FeatureToProvisioning.java
@@ -62,7 +62,7 @@ public class FeatureToProvisioning {
     static final String PROVISIONING_MODEL_NAME_VARIABLE = "provisioning.model.name";
 
     public static void convert(File file, String output, ArtifactManager am) throws IOException {
-        org.apache.sling.feature.Feature feature = org.apache.sling.feature.support.io.FileUtils.getFeature(file.getAbsolutePath(), am, SubstituteVariables.NONE);
+        org.apache.sling.feature.Feature feature = FeatureUtil.getFeature(file.getAbsolutePath(), am, SubstituteVariables.NONE);
 
         Object featureNameVar = feature.getVariables().remove(PROVISIONING_MODEL_NAME_VARIABLE);
         String featureName;
diff --git a/featuremodel/feature-modelconverter/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java b/featuremodel/feature-modelconverter/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java
index 9f57981..86705da 100644
--- a/featuremodel/feature-modelconverter/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java
+++ b/featuremodel/feature-modelconverter/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java
@@ -44,6 +44,7 @@ import org.apache.sling.feature.Configurations;
 import org.apache.sling.feature.Extension;
 import org.apache.sling.feature.ExtensionType;
 import org.apache.sling.feature.Extensions;
+import org.apache.sling.feature.support.FeatureUtil;
 import org.apache.sling.feature.support.artifact.ArtifactManager;
 import org.apache.sling.feature.support.artifact.ArtifactManagerConfig;
 import org.apache.sling.feature.support.json.FeatureJSONReader.SubstituteVariables;
@@ -174,8 +175,8 @@ public class ModelConverterTest {
         File outFile = files.get(0);
 
         String expectedFile = new File(getClass().getResource(expectedJSON).toURI()).getAbsolutePath();
-        org.apache.sling.feature.Feature expected = org.apache.sling.feature.support.io.FileUtils.getFeature(expectedFile, artifactManager, SubstituteVariables.NONE);
-        org.apache.sling.feature.Feature actual = org.apache.sling.feature.support.io.FileUtils.getFeature(outFile.getAbsolutePath(), artifactManager, SubstituteVariables.NONE);
+        org.apache.sling.feature.Feature expected = FeatureUtil.getFeature(expectedFile, artifactManager, SubstituteVariables.NONE);
+        org.apache.sling.feature.Feature actual = FeatureUtil.getFeature(outFile.getAbsolutePath(), artifactManager, SubstituteVariables.NONE);
         assertFeaturesEqual(expected, actual);
     }
 
@@ -205,8 +206,8 @@ public class ModelConverterTest {
         File outFile = files.get(0);
 
         String expectedFile = new File(getClass().getResource(expectedJSON).toURI()).getAbsolutePath();
-        org.apache.sling.feature.Feature expected = org.apache.sling.feature.support.io.FileUtils.getFeature(expectedFile, artifactManager, SubstituteVariables.NONE);
-        org.apache.sling.feature.Feature actual = org.apache.sling.feature.support.io.FileUtils.getFeature(outFile.getAbsolutePath(), artifactManager, SubstituteVariables.NONE);
+        org.apache.sling.feature.Feature expected = FeatureUtil.getFeature(expectedFile, artifactManager, SubstituteVariables.NONE);
+        org.apache.sling.feature.Feature actual = FeatureUtil.getFeature(outFile.getAbsolutePath(), artifactManager, SubstituteVariables.NONE);
         assertFeaturesEqual(expected, actual);
     }
 
diff --git a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/FeatureUtil.java b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/FeatureUtil.java
index 5778692..21dcc77 100644
--- a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/FeatureUtil.java
+++ b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/FeatureUtil.java
@@ -50,6 +50,27 @@ public class FeatureUtil {
     }
 
     /**
+     * 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;
+        }
+    }
+
+    /**
      * Assemble an application based on the given files.
      *
      * Read the features and assemble the application
@@ -69,7 +90,7 @@ public class FeatureUtil {
     throws IOException {
         final List<Feature> features = new ArrayList<>();
         for(final String initFile : featureFiles) {
-            final Feature f = org.apache.sling.feature.support.io.FileUtils.getFeature(initFile, artifactManager, SubstituteVariables.RESOLVE);
+            final Feature f = getFeature(initFile, artifactManager, SubstituteVariables.RESOLVE);
             features.add(f);
         }
 
diff --git a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/io/FileUtils.java b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/io/FileUtils.java
index 9447457..e3f23a1 100644
--- a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/io/FileUtils.java
+++ b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/io/FileUtils.java
@@ -17,7 +17,6 @@
 package org.apache.sling.feature.support.io;
 
 import java.io.File;
-import java.io.FileReader;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.util.ArrayList;
@@ -25,12 +24,6 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 
-import org.apache.sling.feature.Feature;
-import org.apache.sling.feature.support.artifact.ArtifactHandler;
-import org.apache.sling.feature.support.artifact.ArtifactManager;
-import org.apache.sling.feature.support.json.FeatureJSONReader;
-import org.apache.sling.feature.support.json.FeatureJSONReader.SubstituteVariables;
-
 public class FileUtils {
 
     /** The extension for a reference file. */
@@ -162,27 +155,6 @@ public class FileUtils {
         return paths;
     }
 
-    /**
-     * Read the feature
-     *
-     * @param file The feature file
-     * @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 file,
-            final ArtifactManager artifactManager,
-            final SubstituteVariables substituteVariables)
-    throws IOException {
-        final ArtifactHandler featureArtifact = artifactManager.getArtifactHandler(file);
-
-        try (final FileReader r = new FileReader(featureArtifact.getFile())) {
-            final Feature f = FeatureJSONReader.read(r, featureArtifact.getUrl(), substituteVariables);
-            return f;
-        }
-    }
-
     static final Comparator<String> FEATURE_PATH_COMP = new Comparator<String>() {
 
         @Override

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