Skip to content

Commit

Permalink
ContentPackageOsgiConfigPostProcessor: Write OSGi configurations as .…
Browse files Browse the repository at this point in the history
…cfg.json files instead of .config files.
  • Loading branch information
stefanseifert committed Jan 9, 2024
1 parent 4da15f6 commit c4f21b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
2 changes: 1 addition & 1 deletion changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<release version="2.20.0" date="not released">
<action type="update" dev="sseifert">
TBD
ContentPackageOsgiConfigPostProcessor: Write OSGi configurations as .cfg.json files instead of .config files.
</action>
</release>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public Void accept(String path, Dictionary<String, Object> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand All @@ -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);
Expand Down

0 comments on commit c4f21b0

Please sign in to comment.