diff --git a/.travis.yml b/.travis.yml index 192f6fc..9a6362e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,10 +34,10 @@ script: # Remove wcm.io artefacts from repository before cache - rm -rf $HOME/.m2/repository/io/wcm -# exlude release tags like xyz-1.0.0 or xyz-1 +# exlude release tags like 1.0.0 branches: except: - - /^.*\-\d+(\.\d+\.\d+)?(\..*|\-.*)?$/ + - /^\d+(\.\d+\.\d+)?(\..*|\-.*)?$/ # Cache Maven Repository cache: diff --git a/changes.xml b/changes.xml index 293dd50..1dc3008 100644 --- a/changes.xml +++ b/changes.xml @@ -23,6 +23,12 @@ xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd"> + + + Update to latest CONGA SPI. + + + Always use BufferedInputStream to wrap FileInputStream. diff --git a/conga-sling-plugin/pom.xml b/conga-sling-plugin/pom.xml index 3692476..6277e86 100644 --- a/conga-sling-plugin/pom.xml +++ b/conga-sling-plugin/pom.xml @@ -25,13 +25,13 @@ io.wcm.devops io.wcm.devops.parent_toplevel - 1.0.6 + 1.0.10 io.wcm.devops.conga.plugins io.wcm.devops.conga.plugins.sling - 1.2.2 + 1.2.4 jar CONGA Sling Plugin @@ -53,7 +53,7 @@ io.wcm.devops.conga io.wcm.devops.conga.generator - 1.3.2 + 1.5.0 compile diff --git a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/OsgiConfigEscapingStrategy.java b/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/OsgiConfigEscapingStrategy.java index 846e234..4c1a1f8 100644 --- a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/OsgiConfigEscapingStrategy.java +++ b/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/OsgiConfigEscapingStrategy.java @@ -21,12 +21,15 @@ import java.io.IOException; import java.io.Writer; +import java.util.HashMap; +import java.util.Map; -import org.apache.commons.lang3.text.translate.AggregateTranslator; -import org.apache.commons.lang3.text.translate.CharSequenceTranslator; -import org.apache.commons.lang3.text.translate.LookupTranslator; +import org.apache.commons.text.translate.AggregateTranslator; +import org.apache.commons.text.translate.CharSequenceTranslator; +import org.apache.commons.text.translate.LookupTranslator; import io.wcm.devops.conga.generator.spi.handlebars.EscapingStrategyPlugin; +import io.wcm.devops.conga.generator.spi.handlebars.context.EscapingStrategyContext; import io.wcm.devops.conga.generator.util.FileUtil; /** @@ -47,40 +50,23 @@ public class OsgiConfigEscapingStrategy implements EscapingStrategyPlugin { * http://svn.apache.org/repos/asf/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java * method 'writeQuoted'. */ + private static final Map ESCAPE_OSGI_CONFIG_TRANSLATION = new HashMap<>(); + static { + ESCAPE_OSGI_CONFIG_TRANSLATION.put(" ", "\\ "); + ESCAPE_OSGI_CONFIG_TRANSLATION.put("\"", "\\\""); + ESCAPE_OSGI_CONFIG_TRANSLATION.put("\\", "\\\\"); + ESCAPE_OSGI_CONFIG_TRANSLATION.put("=", "\\="); + // well known escapes + ESCAPE_OSGI_CONFIG_TRANSLATION.put("\b", "\\b"); + ESCAPE_OSGI_CONFIG_TRANSLATION.put("\t", "\\t"); + ESCAPE_OSGI_CONFIG_TRANSLATION.put("\n", "\\n"); + ESCAPE_OSGI_CONFIG_TRANSLATION.put("\f", "\\f"); + ESCAPE_OSGI_CONFIG_TRANSLATION.put("\r", "\\r"); + } static final CharSequenceTranslator ESCAPE_OSGI_CONFIG = new AggregateTranslator( - new LookupTranslator( - new String[][] { - { - " ", "\\ " - }, - { - "\"", "\\\"" - }, - { - "\\", "\\\\" - }, - { - "=", "\\=" - }, - // well known escapes - { - "\b", "\\b" - }, - { - "\t", "\\t" - }, - { - "\n", "\\n" - }, - { - "\f", "\\f" - }, - { - "\r", "\\r" - } - }), - new CharSequenceTranslator() { + new LookupTranslator(ESCAPE_OSGI_CONFIG_TRANSLATION), + new CharSequenceTranslator() { @Override public int translate(CharSequence input, int index, Writer out) throws IOException { char c = input.charAt(index); @@ -92,7 +78,7 @@ public int translate(CharSequence input, int index, Writer out) throws IOExcepti return 0; } } - ); + ); @Override public String getName() { @@ -100,12 +86,12 @@ public String getName() { } @Override - public boolean accepts(String fileExtension) { + public boolean accepts(String fileExtension, EscapingStrategyContext pluginContext) { return FileUtil.matchesExtension(fileExtension, FILE_EXTENSION); } @Override - public String escape(CharSequence value) { + public String escape(CharSequence value, EscapingStrategyContext pluginContext) { return value == null ? null : ESCAPE_OSGI_CONFIG.translate(value); } diff --git a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/ProvisioningEscapingStrategy.java b/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/ProvisioningEscapingStrategy.java index 6cb21ac..c9f538b 100644 --- a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/ProvisioningEscapingStrategy.java +++ b/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/ProvisioningEscapingStrategy.java @@ -20,6 +20,7 @@ package io.wcm.devops.conga.plugins.sling.handlebars.escaping; import io.wcm.devops.conga.generator.spi.handlebars.EscapingStrategyPlugin; +import io.wcm.devops.conga.generator.spi.handlebars.context.EscapingStrategyContext; import io.wcm.devops.conga.generator.util.FileUtil; import io.wcm.devops.conga.plugins.sling.util.ProvisioningUtil; @@ -39,13 +40,13 @@ public String getName() { } @Override - public boolean accepts(String fileExtension) { + public boolean accepts(String fileExtension, EscapingStrategyContext pluginContext) { // currently only provisioning files with explicit extension are supported, not with "txt" return FileUtil.matchesExtension(fileExtension, ProvisioningUtil.FILE_EXTENSION); } @Override - public String escape(CharSequence value) { + public String escape(CharSequence value, EscapingStrategyContext pluginContext) { // use same escaping rules as for OSGi configurations return value == null ? null : OsgiConfigEscapingStrategy.ESCAPE_OSGI_CONFIG.translate(value); } diff --git a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/postprocessor/ProvisioningOsgiConfigPostProcessor.java b/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/postprocessor/ProvisioningOsgiConfigPostProcessor.java index 42a3594..0048b22 100644 --- a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/postprocessor/ProvisioningOsgiConfigPostProcessor.java +++ b/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/postprocessor/ProvisioningOsgiConfigPostProcessor.java @@ -22,10 +22,10 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Dictionary; import java.util.List; -import org.apache.commons.lang3.CharEncoding; import org.apache.felix.cm.file.ConfigurationHandler; import org.apache.sling.provisioning.model.Model; @@ -94,7 +94,7 @@ public FileContext accept(String path, Dictionary properties) th ConfigurationHandler.write(os, properties); } - return new FileContext().file(confFile).charset(CharEncoding.UTF_8); + return new FileContext().file(confFile).charset(StandardCharsets.UTF_8); } }); } diff --git a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/fileheader/OsgiConfigFileHeaderTest.java b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/fileheader/OsgiConfigFileHeaderTest.java index 3b63824..a69ad40 100644 --- a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/fileheader/OsgiConfigFileHeaderTest.java +++ b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/fileheader/OsgiConfigFileHeaderTest.java @@ -23,10 +23,10 @@ import static org.junit.Assert.assertTrue; import java.io.File; +import java.nio.charset.StandardCharsets; import java.util.List; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringUtils; import org.junit.Before; import org.junit.Test; @@ -53,7 +53,7 @@ public void setUp() { @Test public void testApply() throws Exception { File file = new File("target/generation-test/fileHeader.config"); - FileUtils.write(file, "myscript", CharEncoding.UTF_8); + FileUtils.write(file, "myscript", StandardCharsets.UTF_8); List lines = ImmutableList.of("**********", "", "Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim.", "**********"); FileHeaderContext context = new FileHeaderContext().commentLines(lines); @@ -62,7 +62,7 @@ public void testApply() throws Exception { assertTrue(underTest.accepts(fileContext, context)); underTest.apply(fileContext, context); - assertTrue(StringUtils.contains(FileUtils.readFileToString(file, CharEncoding.UTF_8), + assertTrue(StringUtils.contains(FileUtils.readFileToString(file, StandardCharsets.UTF_8), "# Der Jodelkaiser aus dem Oetztal ist wieder daheim.")); FileHeaderContext extractContext = underTest.extract(fileContext); diff --git a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/fileheader/ProvisioningFileHeaderTest.java b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/fileheader/ProvisioningFileHeaderTest.java index f2a4e94..3e7a029 100644 --- a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/fileheader/ProvisioningFileHeaderTest.java +++ b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/fileheader/ProvisioningFileHeaderTest.java @@ -23,10 +23,10 @@ import static org.junit.Assert.assertTrue; import java.io.File; +import java.nio.charset.StandardCharsets; import java.util.List; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringUtils; import org.junit.Before; import org.junit.Test; @@ -59,7 +59,7 @@ public void testApply() throws Exception { assertTrue(underTest.accepts(fileContext, context)); underTest.apply(fileContext, context); - assertTrue(StringUtils.contains(FileUtils.readFileToString(file, CharEncoding.UTF_8), + assertTrue(StringUtils.contains(FileUtils.readFileToString(file, StandardCharsets.UTF_8), "# Der Jodelkaiser\n# aus dem Oetztal\n# ist wieder daheim.\n")); FileHeaderContext extractContext = underTest.extract(fileContext); diff --git a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/OsgiConfigEscapingStrategyTest.java b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/OsgiConfigEscapingStrategyTest.java index f2c10c2..351584c 100644 --- a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/OsgiConfigEscapingStrategyTest.java +++ b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/OsgiConfigEscapingStrategyTest.java @@ -40,21 +40,21 @@ public void setUp() { @Test public void testValid() { - assertTrue(underTest.accepts("config")); + assertTrue(underTest.accepts("config", null)); } @Test public void testInvalid() { - assertFalse(underTest.accepts("txt")); + assertFalse(underTest.accepts("txt", null)); } @Test public void testEscape() { - assertEquals("\\ \\\"\\\\", underTest.escape(" \"\\")); - assertEquals("äöü߀/", underTest.escape("äöü߀/")); - assertEquals("aa\\=bb", underTest.escape("aa=bb")); - assertEquals("\\b\\t\\n\\f\\r", underTest.escape("\b\t\n\f\r")); - assertEquals("ab\\u0005c\\u0006", underTest.escape("ab\u0005c\u0006")); + assertEquals("\\ \\\"\\\\", underTest.escape(" \"\\", null)); + assertEquals("äöü߀/", underTest.escape("äöü߀/", null)); + assertEquals("aa\\=bb", underTest.escape("aa=bb", null)); + assertEquals("\\b\\t\\n\\f\\r", underTest.escape("\b\t\n\f\r", null)); + assertEquals("ab\\u0005c\\u0006", underTest.escape("ab\u0005c\u0006", null)); } } diff --git a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/ProvisioningEscapingStrategyTest.java b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/ProvisioningEscapingStrategyTest.java index a3f77b4..cb0f5d0 100644 --- a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/ProvisioningEscapingStrategyTest.java +++ b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/handlebars/escaping/ProvisioningEscapingStrategyTest.java @@ -40,14 +40,14 @@ public void setUp() { @Test public void testValid() { - assertTrue(underTest.accepts("provisioning")); - assertEquals("\\ \\\"\\\\", underTest.escape(" \"\\")); - assertEquals("äöü߀/", underTest.escape("äöü߀/")); + assertTrue(underTest.accepts("provisioning", null)); + assertEquals("\\ \\\"\\\\", underTest.escape(" \"\\", null)); + assertEquals("äöü߀/", underTest.escape("äöü߀/", null)); } @Test public void testInvalid() { - assertFalse(underTest.accepts("txt")); + assertFalse(underTest.accepts("txt", null)); } } diff --git a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/postprocessor/ProvisioningOsgiConfigPostProcessorTest.java b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/postprocessor/ProvisioningOsgiConfigPostProcessorTest.java index dab1919..a33fedc 100644 --- a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/postprocessor/ProvisioningOsgiConfigPostProcessorTest.java +++ b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/postprocessor/ProvisioningOsgiConfigPostProcessorTest.java @@ -30,11 +30,11 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.Dictionary; import java.util.UUID; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.CharEncoding; import org.apache.felix.cm.file.ConfigurationHandler; import org.junit.After; import org.junit.Before; @@ -43,6 +43,7 @@ import io.wcm.devops.conga.generator.spi.PostProcessorPlugin; import io.wcm.devops.conga.generator.spi.context.FileContext; +import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; import io.wcm.devops.conga.generator.spi.context.PostProcessorContext; import io.wcm.devops.conga.generator.util.PluginManagerImpl; @@ -100,7 +101,7 @@ public void testSimpleConfig() throws Exception { // post process provisioning example File provisioningFile = new File(targetDir, "simpleConfig.txt"); - FileUtils.write(provisioningFile, PROVISIONING_FILE, CharEncoding.UTF_8); + FileUtils.write(provisioningFile, PROVISIONING_FILE, StandardCharsets.UTF_8); postProcess(provisioningFile); // validate generated configs @@ -119,7 +120,7 @@ public void testSimpleConfigWithNewline() throws Exception { // post process provisioning example File provisioningFile = new File(targetDir, "simpleConfigWithNewline.txt"); - FileUtils.write(provisioningFile, PROVISIONING_FILE, CharEncoding.UTF_8); + FileUtils.write(provisioningFile, PROVISIONING_FILE, StandardCharsets.UTF_8); postProcess(provisioningFile); // validate generated configs @@ -132,10 +133,12 @@ private void postProcess(File provisioningFile) { // post-process FileContext fileContext = new FileContext() .file(provisioningFile) - .charset(CharEncoding.UTF_8); - PostProcessorContext context = new PostProcessorContext() + .charset(StandardCharsets.UTF_8); + PluginContextOptions pluginContextOptions = new PluginContextOptions() .pluginManager(new PluginManagerImpl()) .logger(LoggerFactory.getLogger(ProvisioningOsgiConfigPostProcessor.class)); + PostProcessorContext context = new PostProcessorContext() + .pluginContextOptions(pluginContextOptions); assertTrue(underTest.accepts(fileContext, context)); underTest.apply(fileContext, context); diff --git a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/validator/ProvisioningValidatorTest.java b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/validator/ProvisioningValidatorTest.java index 268b197..40fe13c 100644 --- a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/validator/ProvisioningValidatorTest.java +++ b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/validator/ProvisioningValidatorTest.java @@ -23,8 +23,8 @@ import static org.junit.Assert.assertTrue; import java.io.File; +import java.nio.charset.StandardCharsets; -import org.apache.commons.lang3.CharEncoding; import org.junit.Before; import org.junit.Test; @@ -45,7 +45,7 @@ public void setUp() { @Test public void testValid() throws Exception { File file = new File(getClass().getResource("/validProvisioning.txt").toURI()); - FileContext fileContext = new FileContext().file(file).charset(CharEncoding.UTF_8); + FileContext fileContext = new FileContext().file(file).charset(StandardCharsets.UTF_8); assertTrue(underTest.accepts(fileContext, null)); underTest.apply(fileContext, null); } @@ -53,7 +53,7 @@ public void testValid() throws Exception { @Test(expected = ValidationException.class) public void testInvalid() throws Exception { File file = new File(getClass().getResource("/invalidProvisioning.txt").toURI()); - FileContext fileContext = new FileContext().file(file).charset(CharEncoding.UTF_8); + FileContext fileContext = new FileContext().file(file).charset(StandardCharsets.UTF_8); assertTrue(underTest.accepts(fileContext, null)); underTest.apply(fileContext, null); } @@ -61,7 +61,7 @@ public void testInvalid() throws Exception { @Test public void testInvalidFileExtension() throws Exception { File file = new File(getClass().getResource("/noProvisioning.txt").toURI()); - FileContext fileContext = new FileContext().file(file).charset(CharEncoding.UTF_8); + FileContext fileContext = new FileContext().file(file).charset(StandardCharsets.UTF_8); assertFalse(underTest.accepts(fileContext, null)); } diff --git a/example/pom.xml b/example/pom.xml index fad849b..97c7420 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -26,7 +26,7 @@ io.wcm.maven io.wcm.maven.global-parent - 14 + 19 @@ -45,7 +45,7 @@ io.wcm.devops.conga conga-maven-plugin - 1.3.2 + 1.5.0 true @@ -53,7 +53,7 @@ io.wcm.devops.conga.plugins io.wcm.devops.conga.plugins.sling - 1.2.1-SNAPSHOT + 1.2.3-SNAPSHOT diff --git a/pom.xml b/pom.xml index 9884b94..dd791a3 100644 --- a/pom.xml +++ b/pom.xml @@ -23,17 +23,25 @@ io.wcm.devops io.wcm.devops.parent_toplevel - 1.0.6 + 1.0.10 io.wcm.devops.conga.plugins io.wcm.devops.conga.plugins.sling.root - 1.2.2 + 1.2.4 pom CONGA Sling Plugin Root POM for wcm.io CONGA Plugins for Apache Sling. + ${site.url}/${site.url.module.prefix}/ + + + scm:git:https://github.com/wcm-io-devops/conga-sling-plugin.git + scm:git:https://github.com/wcm-io-devops/conga-sling-plugin.git + https://github.com/wcm-io-devops/conga-sling-plugin + HEAD + conga/plugins/sling diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index a34e002..40c557e 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -21,6 +21,13 @@ This plugin extends [CONGA][conga] with: * Generate OSGi configurations in [Apache Felix Config Admin][felix-configadmin] file format +### Further Resources + +* [wcm.io CONGA training material with exercises](http://training.wcm.io/conga/) +* [adaptTo() 2015 Talk: CONGA - Configuration generation for Sling and AEM](https://adapt.to/2015/en/schedule/conga---configuration-generation-for-sling-and-aem.html) +* [adaptTo() 2017 Talk: Automate AEM Deployment with Ansible and wcm.io CONGA](https://adapt.to/2017/en/schedule/automate-aem-deployment-with-ansible-and-wcm-io-conga.html) + + [usage]: usage.html [extensions]: extensions.html