You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by si...@apache.org on 2019/04/30 17:05:49 UTC
[sling-org-apache-sling-feature-cpconverter] branch master updated:
initial prototype of json file indexer
This is an automated email from the ASF dual-hosted git repository.
simonetripodi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git
The following commit(s) were added to refs/heads/master by this push:
new 80e408f initial prototype of json file indexer
80e408f is described below
commit 80e408f851bb09ec66850aef3a834f4d1feb8141
Author: stripodi <st...@simos-mbp>
AuthorDate: Tue Apr 30 19:05:42 2019 +0200
initial prototype of json file indexer
---
.../ContentPackage2FeatureModelConverter.java | 18 +++--
.../sling/feature/cpconverter/RunmodeMapper.java | 76 ++++++++++++++++++++++
2 files changed, 89 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java b/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
index 6e0155d..94d9e24 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
@@ -179,7 +179,6 @@ public class ContentPackage2FeatureModelConverter {
}
private ArtifactId appendRunmode(ArtifactId id, String runMode) {
-
ArtifactId newId;
if (runMode == null) {
newId = id;
@@ -302,13 +301,20 @@ public class ContentPackage2FeatureModelConverter {
aclManager.addRepoinitExtension(getTargetFeature());
- seralize(getTargetFeature(), null);
+ RunmodeMapper runmodeMapper = RunmodeMapper.open(featureModelsOutputDirectory);
+
+ File featureModel = seralize(getTargetFeature(), null);
+ runmodeMapper.addOrUpdate(null, featureModel);
if (!runModes.isEmpty()) {
for (java.util.Map.Entry<String, Feature> runmodeEntry : runModes.entrySet()) {
- seralize(runmodeEntry.getValue(), runmodeEntry.getKey());
+ String runmode = runmodeEntry.getKey();
+ featureModel = seralize(runmodeEntry.getValue(), runmode);
+ runmodeMapper.addOrUpdate(runmode, featureModel);
}
}
+
+ runmodeMapper.save();
}
}
@@ -335,7 +341,7 @@ public class ContentPackage2FeatureModelConverter {
}
}
- private void seralize(Feature feature, String runMode) throws Exception {
+ private File seralize(Feature feature, String runMode) throws Exception {
StringBuilder fileName = new StringBuilder().append(feature.getId().getArtifactId());
String classifier = feature.getId().getClassifier();
@@ -349,7 +355,7 @@ public class ContentPackage2FeatureModelConverter {
logger.info("Conversion complete!", targetFile);
logger.info("Writing resulting Feature File to '{}'...", targetFile);
-
+
if ( idOverride != null ) {
ArtifactId idOverrride = appendRunmode(ArtifactId.parse(idOverride), runMode);
feature = feature.copy(idOverrride);
@@ -360,6 +366,8 @@ public class ContentPackage2FeatureModelConverter {
logger.info("'{}' Feature File successfully written!", targetFile);
}
+
+ return targetFile;
}
public void processSubPackage(String path, File contentPackage) throws Exception {
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/RunmodeMapper.java b/src/main/java/org/apache/sling/feature/cpconverter/RunmodeMapper.java
new file mode 100644
index 0000000..601974f
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/cpconverter/RunmodeMapper.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.sling.feature.cpconverter;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+final class RunmodeMapper {
+
+ private static final String FILENAME = "runmode.mapping";
+
+ public static RunmodeMapper open(File featureModelsOutputDirectory) throws IOException {
+ Properties properties = new Properties();
+
+ File runmodeMappingFile = new File(featureModelsOutputDirectory, FILENAME);
+ if (runmodeMappingFile.exists()) {
+ try (FileInputStream input = new FileInputStream(runmodeMappingFile)) {
+ properties.load(input);
+ }
+ }
+
+ return new RunmodeMapper(runmodeMappingFile, properties);
+ }
+
+ private static final String DEFAULT = "(default)";
+
+ private final File runmodeMappingFile;
+
+ private final Properties properties;
+
+ private RunmodeMapper(File runmodeMappingFile, Properties properties) {
+ this.runmodeMappingFile = runmodeMappingFile;
+ this.properties = properties;
+ }
+
+ public void addOrUpdate(String runmode, File jsonFile) {
+ if (runmode == null) {
+ runmode = DEFAULT;
+ }
+
+ String jsonFileName = jsonFile.getName();
+ String value = properties.getProperty(runmode);
+
+ if (value != null && !value.contains(jsonFileName)) {
+ value += ',' + jsonFileName;
+ } else {
+ value = jsonFileName;
+ }
+
+ properties.setProperty(runmode, value);
+ }
+
+ public void save() throws IOException {
+ try (FileOutputStream output = new FileOutputStream(runmodeMappingFile)) {
+ properties.store(output, "File edited by the Apache Sling Content Package to Sling Feature converter");
+ }
+ }
+
+}