From c4f21b0d57d2e244e150eb65b732464ba46325a3 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Tue, 9 Jan 2024 15:03:22 +0100 Subject: [PATCH] ContentPackageOsgiConfigPostProcessor: Write OSGi configurations as .cfg.json files instead of .config files. --- changes.xml | 2 +- ...ContentPackageOsgiConfigPostProcessor.java | 2 +- ...entPackageOsgiConfigPostProcessorTest.java | 31 +++++-------------- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/changes.xml b/changes.xml index b89991d2..51d393a4 100644 --- a/changes.xml +++ b/changes.xml @@ -25,7 +25,7 @@ - TBD + ContentPackageOsgiConfigPostProcessor: Write OSGi configurations as .cfg.json files instead of .config files. diff --git a/conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/postprocessor/ContentPackageOsgiConfigPostProcessor.java b/conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/postprocessor/ContentPackageOsgiConfigPostProcessor.java index 90869484..4f84efd8 100644 --- a/conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/postprocessor/ContentPackageOsgiConfigPostProcessor.java +++ b/conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/postprocessor/ContentPackageOsgiConfigPostProcessor.java @@ -151,7 +151,7 @@ public Void accept(String path, Dictionary properties) throws IO context.getLogger().info(" Include " + contentPath); // write configuration to temporary file - File tempFile = File.createTempFile(NAME, ".config"); + File tempFile = File.createTempFile(NAME, ".cfg.json"); try (OutputStream os = new FileOutputStream(tempFile)) { OsgiConfigUtil.write(os, properties); } diff --git a/conga-aem-plugin/src/test/java/io/wcm/devops/conga/plugins/aem/postprocessor/ContentPackageOsgiConfigPostProcessorTest.java b/conga-aem-plugin/src/test/java/io/wcm/devops/conga/plugins/aem/postprocessor/ContentPackageOsgiConfigPostProcessorTest.java index f9e4dd45..8c1d578c 100644 --- a/conga-aem-plugin/src/test/java/io/wcm/devops/conga/plugins/aem/postprocessor/ContentPackageOsgiConfigPostProcessorTest.java +++ b/conga-aem-plugin/src/test/java/io/wcm/devops/conga/plugins/aem/postprocessor/ContentPackageOsgiConfigPostProcessorTest.java @@ -34,14 +34,14 @@ import java.io.ByteArrayInputStream; import java.io.File; -import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.Dictionary; import java.util.Map; import org.apache.commons.io.FileUtils; -import org.apache.felix.cm.file.ConfigurationHandler; +import org.apache.felix.cm.json.io.Configurations; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.LoggerFactory; @@ -103,24 +103,9 @@ void testPostProcess() throws Exception { File zipFile = new File(target, "test.zip"); assertTrue(zipFile.exists()); - try (InputStream is = new ByteArrayInputStream(getDataFromZip(zipFile, "jcr_root/apps/test/config/my.pid.config"))) { - - // check for initial comment line - is.mark(256); - final int firstChar = is.read(); - if (firstChar == '#') { - int b; - while ((b = is.read()) != '\n') { - if (b == -1) { - throw new IOException("Unable to read configuration."); - } - } - } - else { - is.reset(); - } - - Dictionary config = ConfigurationHandler.read(is); + try (InputStream is = new ByteArrayInputStream(getDataFromZip(zipFile, "jcr_root/apps/test/config/my.pid.cfg.json")); + InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { + Dictionary config = Configurations.buildReader().build(reader).readConfiguration(); assertEquals("value1", config.get("stringProperty")); assertArrayEquals(new String[] { "v1", "v2", "v3" @@ -129,9 +114,9 @@ void testPostProcess() throws Exception { assertEquals(999999999999L, config.get("longProperty")); } - assertTrue(ZipUtil.containsEntry(zipFile, "jcr_root/apps/test/config/my.factory-my.pid.config")); - assertTrue(ZipUtil.containsEntry(zipFile, "jcr_root/apps/test/config.mode1/my.factory-my.pid2.config")); - assertTrue(ZipUtil.containsEntry(zipFile, "jcr_root/apps/test/config.mode2/my.pid2.config")); + assertTrue(ZipUtil.containsEntry(zipFile, "jcr_root/apps/test/config/my.factory-my.pid.cfg.json")); + assertTrue(ZipUtil.containsEntry(zipFile, "jcr_root/apps/test/config.mode1/my.factory-my.pid2.cfg.json")); + assertTrue(ZipUtil.containsEntry(zipFile, "jcr_root/apps/test/config.mode2/my.pid2.cfg.json")); Document filterXml = getXmlFromZip(zipFile, "META-INF/vault/filter.xml"); assertXpathEvaluatesTo("/apps/test/config", "/workspaceFilter/filter[1]/@root", filterXml);