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 3dfa00b Rename to FileUtils and use constants
3dfa00b is described below
commit 3dfa00b4b526d7e82a7b5fbca06d98b552fd6244
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Wed Apr 18 09:55:21 2018 +0200
Rename to FileUtils and use constants
---
.../feature/launcher/impl/FeatureProcessor.java | 2 +-
.../modelconverter/impl/FeatureToProvisioning.java | 2 +-
.../modelconverter/impl/ModelConverterTest.java | 8 +-
.../apache/sling/feature/support/FeatureUtil.java | 2 +-
.../io/{FeatureUtil.java => FileUtils.java} | 140 ++++++++++++---------
.../sling/feature/support/io/FeatureUtilTest.java | 2 +-
.../apache/sling/feature/maven/Preprocessor.java | 2 +-
7 files changed, 90 insertions(+), 68 deletions(-)
diff --git
a/featuremodel/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
b/featuremodel/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
index 6fd5fce..5741952 100644
---
a/featuremodel/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
+++
b/featuremodel/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
@@ -65,7 +65,7 @@ public class FeatureProcessor {
} else {
try (FeatureResolver resolver = new
FrameworkResolver(artifactManager, Collections.emptyMap())) {
app = FeatureUtil.assembleApplication(null, artifactManager,
resolver,
-
org.apache.sling.feature.support.io.FeatureUtil.getFeatureFiles(config.getHomeDirectory(),
config.getFeatureFiles()).toArray(new String[0]));
+
org.apache.sling.feature.support.io.FileUtils.getFeatureFiles(config.getHomeDirectory(),
config.getFeatureFiles()).toArray(new String[0]));
} catch (Exception ex) {
Main.LOG().error("Error while assembling application: {}",
ex.getMessage(), ex);
System.exit(1);
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 eb83353..fb565e9 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.FeatureUtil.getFeature(file.getAbsolutePath(),
am, SubstituteVariables.NONE);
+ org.apache.sling.feature.Feature feature =
org.apache.sling.feature.support.io.FileUtils.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 87867fb..9f57981 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
@@ -174,8 +174,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.FeatureUtil.getFeature(expectedFile,
artifactManager, SubstituteVariables.NONE);
- org.apache.sling.feature.Feature actual =
org.apache.sling.feature.support.io.FeatureUtil.getFeature(outFile.getAbsolutePath(),
artifactManager, SubstituteVariables.NONE);
+ 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);
assertFeaturesEqual(expected, actual);
}
@@ -205,8 +205,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.FeatureUtil.getFeature(expectedFile,
artifactManager, SubstituteVariables.NONE);
- org.apache.sling.feature.Feature actual =
org.apache.sling.feature.support.io.FeatureUtil.getFeature(outFile.getAbsolutePath(),
artifactManager, SubstituteVariables.NONE);
+ 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);
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 4533973..5778692 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
@@ -69,7 +69,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.FeatureUtil.getFeature(initFile,
artifactManager, SubstituteVariables.RESOLVE);
+ final Feature f =
org.apache.sling.feature.support.io.FileUtils.getFeature(initFile,
artifactManager, SubstituteVariables.RESOLVE);
features.add(f);
}
diff --git
a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/io/FeatureUtil.java
b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/io/FileUtils.java
similarity index 79%
rename from
featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/io/FeatureUtil.java
rename to
featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/io/FileUtils.java
index d059dda..9447457 100644
---
a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/io/FeatureUtil.java
+++
b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/io/FileUtils.java
@@ -31,47 +31,26 @@ 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 FeatureUtil {
+public class FileUtils {
- static final Comparator<String> FEATURE_PATH_COMP = new
Comparator<String>() {
+ /** The extension for a reference file. */
+ public static final String EXTENSION_REF_FILE = ".ref";
- @Override
- public int compare(final String o1, final String o2) {
- // windows path conversion
- final String key1 = o1.replace(File.separatorChar, '/');
- final String key2 = o2.replace(File.separatorChar, '/');
+ /** The extension for a feature file. */
+ public static final String EXTENSION_FEATURE_FILE = ".json";
- final int lastSlash1 = key1.lastIndexOf('/');
- final int lastSlash2 = key2.lastIndexOf('/');
- if ( lastSlash1 == -1 || lastSlash2 == -1 ) {
- return o1.compareTo(o2);
- }
- final String path1 = key1.substring(0, lastSlash1 + 1);
- final String path2 = key2.substring(0, lastSlash2 + 1);
- if ( path1.equals(path2) ) {
- return o1.compareTo(o2);
- }
- if ( path1.startsWith(path2) ) {
- return 1;
- } else if ( path2.startsWith(path1) ) {
- return -1;
- }
- return o1.compareTo(o2);
- }
- };
+ /** The default directory to search for features. */
+ public static final String DEFAULT_DIRECTORY = "features";
- private static void processDir(final List<String> paths, final File dir)
- throws IOException {
- for(final File f : dir.listFiles()) {
- if ( f.isFile() && !f.getName().startsWith(".")) {
- // check if file is a reference
- if ( f.getName().endsWith(".ref") ||
f.getName().endsWith(".json") ) {
- processFile(paths, f);
- }
- }
- }
- }
+ /** The default name of the feature file. */
+ public static final String DEFAULT_FEATURE_FILE = "feature" +
EXTENSION_FEATURE_FILE;
+ /**
+ * Parse a feature reference file
+ * @param file The file
+ * @return The referenced features
+ * @throws IOException If reading fails
+ */
public static List<String> parseFeatureRefFile(final File file)
throws IOException {
final List<String> result = new ArrayList<>();
@@ -89,48 +68,41 @@ public class FeatureUtil {
return result;
}
- private static void processFile(final List<String> paths, final File f)
- throws IOException {
- if ( f.getName().endsWith(".ref") ) {
- paths.addAll(parseFeatureRefFile(f));
- } else {
- paths.add(f.getAbsolutePath());
- }
- }
-
/**
* Get the list of feature files.
* If the provided list of files is {@code null} or an empty array, the
default is used.
* The default checks for the following places, the first one found is
used. If none is
* found an empty list is returned.
* <ol>
- * <li>A directory named {@code feature} in the current directory
- * <li>A file named {@code features.json} in the current directory
- * <li>A directory named {@code feature} in the home directory
- * <li>A file named {@code features.json} in the home directory
+ * <li>A directory named {@link #DEFAULT_DIRECTORY} in the current
directory
+ * <li>A file named {@link #DEFAULT_FEATURE_FILE} in the current
directory
+ * <li>A directory named {@link #DEFAULT_DIRECTORY} in the home directory
+ * <li>A file named {@link #DEFAULT_FEATURE_FILE} in the home directory
* </ol>
*
* The list of files is processed one after the other. If it is relative,
it is
* first tried to be resolved against the current directory and then
against the
* home directory.
- * If an entry denotes a directory, all children ending in {@code .json}
or {@code .ref} of that directory are read.
- * If a file ends in {@code .ref} the contents is read and every line not
starting with the
- * hash sign is considered a reference to a feature artifact.
+ * If an entry denotes a directory, all children ending in {@link
#EXTENSION_FEATURE_FILE} or
+ * {@link #EXTENSION_REF_FILE} of that directory are read.
+ * If a file ends in {@link #EXTENSION_REF_FILE} the contents is read and
every line not
+ * starting with the hash sign is considered a reference to a feature
artifact.
*
* @param homeDirectory If relative files should be resolved, this is the
directory to use
* @param files Optional list of files. If none is provided, a default is
used.
* @return The list of files.
* @throws IOException If an error occurs.
*/
- public static List<String> getFeatureFiles(final File homeDirectory, final
String... files) throws IOException {
+ public static List<String> getFeatureFiles(final File homeDirectory, final
String... files)
+ throws IOException {
String[] featureFiles = files;
if ( featureFiles == null || featureFiles.length == 0 ) {
// Default value - check feature directory otherwise features file
final File[] candidates = new File[] {
- new File(homeDirectory, "features"),
- new File(homeDirectory, "features.json"),
- new File("features"),
- new File("features.json")
+ new File(homeDirectory, DEFAULT_DIRECTORY),
+ new File(homeDirectory, DEFAULT_FEATURE_FILE),
+ new File(DEFAULT_DIRECTORY),
+ new File(DEFAULT_FEATURE_FILE)
};
File f = null;
for(final File c : candidates) {
@@ -161,9 +133,9 @@ public class FeatureUtil {
} else {
final File[] candidates = {
new File(homeDirectory, name),
- new File(homeDirectory, "features" +
File.separatorChar + name),
+ new File(homeDirectory, DEFAULT_DIRECTORY +
File.separatorChar + name),
new File(name),
- new File("features" + File.separatorChar + name),
+ new File(DEFAULT_DIRECTORY + File.separatorChar +
name),
};
for(final File c : candidates) {
if ( c.exists() && c.isFile() ) {
@@ -210,4 +182,54 @@ public class FeatureUtil {
return f;
}
}
+
+ static final Comparator<String> FEATURE_PATH_COMP = new
Comparator<String>() {
+
+ @Override
+ public int compare(final String o1, final String o2) {
+ // windows path conversion
+ final String key1 = o1.replace(File.separatorChar, '/');
+ final String key2 = o2.replace(File.separatorChar, '/');
+
+ final int lastSlash1 = key1.lastIndexOf('/');
+ final int lastSlash2 = key2.lastIndexOf('/');
+ if ( lastSlash1 == -1 || lastSlash2 == -1 ) {
+ return o1.compareTo(o2);
+ }
+ final String path1 = key1.substring(0, lastSlash1 + 1);
+ final String path2 = key2.substring(0, lastSlash2 + 1);
+ if ( path1.equals(path2) ) {
+ return o1.compareTo(o2);
+ }
+ if ( path1.startsWith(path2) ) {
+ return 1;
+ } else if ( path2.startsWith(path1) ) {
+ return -1;
+ }
+ return o1.compareTo(o2);
+ }
+ };
+
+ private static void processDir(final List<String> paths, final File dir)
+ throws IOException {
+ for(final File f : dir.listFiles()) {
+ if ( f.isFile() && !f.getName().startsWith(".")) {
+ // check if file is a reference
+ if ( f.getName().endsWith(EXTENSION_REF_FILE) ||
f.getName().endsWith(EXTENSION_FEATURE_FILE) ) {
+ processFile(paths, f);
+ }
+ }
+ }
+ }
+
+
+
+ private static void processFile(final List<String> paths, final File f)
+ throws IOException {
+ if ( f.getName().endsWith(EXTENSION_REF_FILE) ) {
+ paths.addAll(parseFeatureRefFile(f));
+ } else {
+ paths.add(f.getAbsolutePath());
+ }
+ }
}
diff --git
a/featuremodel/feature-support/src/test/java/org/apache/sling/feature/support/io/FeatureUtilTest.java
b/featuremodel/feature-support/src/test/java/org/apache/sling/feature/support/io/FeatureUtilTest.java
index 1df7822..cbc78e7 100644
---
a/featuremodel/feature-support/src/test/java/org/apache/sling/feature/support/io/FeatureUtilTest.java
+++
b/featuremodel/feature-support/src/test/java/org/apache/sling/feature/support/io/FeatureUtilTest.java
@@ -40,7 +40,7 @@ public class FeatureUtilTest {
};
final List<String> l = new ArrayList<>(Arrays.asList(files));
- Collections.sort(l, FeatureUtil.FEATURE_PATH_COMP);
+ Collections.sort(l, FileUtils.FEATURE_PATH_COMP);
for(int i=0; i<files.length; i++) {
assertEquals(files[i], l.get(i));
}
diff --git
a/featuremodel/osgifeature-maven-plugin/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
b/featuremodel/osgifeature-maven-plugin/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
index 9d7f6b6..a2665f8 100644
---
a/featuremodel/osgifeature-maven-plugin/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
+++
b/featuremodel/osgifeature-maven-plugin/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
@@ -235,7 +235,7 @@ public class Preprocessor {
for(final File file : files) {
try {
- final List<String> features =
org.apache.sling.feature.support.io.FeatureUtil.parseFeatureRefFile(file);
+ final List<String> features =
org.apache.sling.feature.support.io.FileUtils.parseFeatureRefFile(file);
if ( features.isEmpty() ) {
env.logger.debug("Empty feature ref file at " + file);
} else {
--
To stop receiving notification emails like this one, please contact
[email protected].