diff --git a/.gitignore b/.gitignore index 956ee98..cb0de5f 100644 --- a/.gitignore +++ b/.gitignore @@ -16,14 +16,19 @@ npm-debug.log .settings .externalToolBuilders .pmd +.eclipse-pmd .checkstyle .idea .vagrant *.iml .DS_Store +*.retry .rubygems .sass-cache .rubygems-gem-maven-plugin *.sublime-* *nbactions*.xml .temp/ +.vlt +.vlt-sync* +.brackets.json diff --git a/.travis.maven-settings.xml b/.travis.maven-settings.xml index b901939..4c9c6d3 100644 --- a/.travis.maven-settings.xml +++ b/.travis.maven-settings.xml @@ -31,7 +31,7 @@ central - http://repo1.maven.org/maven2/ + https://repo1.maven.org/maven2/ default true @@ -57,7 +57,7 @@ wcm-io-apache-intermediate-release - http://wcm.io/maven/repositories/apache-intermediate-release + https://wcm.io/maven/repositories/apache-intermediate-release default true @@ -83,7 +83,7 @@ apache-snapshots - http://repository.apache.org/snapshots + https://repository.apache.org/snapshots default false @@ -100,7 +100,7 @@ central - http://repo1.maven.org/maven2/ + https://repo1.maven.org/maven2/ default true @@ -126,7 +126,7 @@ wcm-io-apache-intermediate-release - http://wcm.io/maven/repositories/apache-intermediate-release + https://wcm.io/maven/repositories/apache-intermediate-release default true @@ -152,7 +152,7 @@ apache-snapshots - http://repository.apache.org/snapshots + https://repository.apache.org/snapshots default false diff --git a/.travis.yml b/.travis.yml index e7d14be..0d033d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ language: java jdk: -- oraclejdk8 +- openjdk8 - openjdk11 # Make sure travis can use container-based infrastructure diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..9acec44 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,37 @@ +@Library('pipeline-library') pipelineLibrary +@Library('pv-pipeline-library') pvPipelineLibrary + + +import io.wcm.devops.jenkins.pipeline.ssh.SSHTarget + +import static de.provision.devops.jenkins.pipeline.utils.ConfigConstants.* +import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* + +// See: +// https://github.com/pro-vision/jenkins-pv-pipeline-library +// https://github.com/pro-vision/jenkins-pv-pipeline-library/blob/master/docs/config-structure.md +// Also have a look at https://github.com/wcm-io-devops/jenkins-pipeline-library for further configuration options + +List triggers = defaults.getTriggers() +triggers.push(githubPush()) + +Map config = [ + (BUILD_WRAPPER): [ + (BUILD_WRAPPER_SSH_TARGETS): [new SSHTarget("ssh-wcm.io")] + ], + (PROPERTIES) : [ + (PROPERTIES_PIPELINE_TRIGGERS): triggers + ], + (STAGE_COMPILE): [ + (MAVEN): [ + (MAVEN_GOALS): ["clean", "deploy", "site-deploy"], + ] + ], + (STAGE_FEATURE_PREPARATION): [ + (STAGE_FEATURE_PREPARATION_MERGE): [ + (STAGE_FEATURE_PREPARATION_MERGE_ENABLED): false + ] + ] +] + +routeDefaultJenkinsFile(config) diff --git a/README.md b/README.md index b9e7d6c..83d13fd 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ - CONGA Plugin for Apache Sling + CONGA Plugin for Apache Sling ====== [![Build Status](https://travis-ci.org/wcm-io-devops/conga-sling-plugin.png?branch=develop)](https://travis-ci.org/wcm-io-devops/conga-sling-plugin) [![Code Coverage](https://codecov.io/gh/wcm-io-devops/conga-sling-plugin/branch/develop/graph/badge.svg)](https://codecov.io/gh/wcm-io-devops/conga-sling-plugin) -Documentation: http://devops.wcm.io/conga/plugins/sling/
+Documentation: https://devops.wcm.io/conga/plugins/sling/
Issues: https://wcm-io.atlassian.net/projects/WDCONGA
Wiki: https://wcm-io.atlassian.net/wiki/
Continuous Integration: https://travis-ci.org/conga-sling-plugin @@ -11,7 +11,7 @@ Continuous Integration: https://travis-ci.org/conga-sling-plugin ## Build from sources -If you want to build from sources make sure you have configured all [Maven Repositories](http://devops.wcm.io/maven.html) in your settings.xml. +If you want to build from sources make sure you have configured all [Maven Repositories](https://devops.wcm.io/maven.html) in your settings.xml. See [Travis Maven settings.xml](https://github.com/conga-sling-plugin/blob/master/.travis.maven-settings.xml) for an example with a full configuration. diff --git a/changes.xml b/changes.xml index 9d9c49a..e787f20 100644 --- a/changes.xml +++ b/changes.xml @@ -23,6 +23,15 @@ xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd"> + + + Add support for [:repoinit] sections when generating OSGi configurations from Sling Provisioning files. + + + Provisioning file format escaping rules: Escape variable expressions ${...} in values to ensure they are passed through and not interpreted as provisioning file variables. + + + Read Felix ConfigAdmin configuration files with latest version (1.9.14), but write it using the old file format form ConfigAdmin 1.8.4 to support AEM 6.1 and below. diff --git a/conga-sling-plugin/pom.xml b/conga-sling-plugin/pom.xml index 0833d97..740fdb7 100644 --- a/conga-sling-plugin/pom.xml +++ b/conga-sling-plugin/pom.xml @@ -19,19 +19,19 @@ #L% --> - + 4.0.0 io.wcm.devops io.wcm.devops.parent_toplevel - 1.1.4 + 1.2.2 io.wcm.devops.conga.plugins io.wcm.devops.conga.plugins.sling - 1.2.6 + 1.3.0 jar CONGA Sling Plugin @@ -62,14 +62,14 @@ org.apache.felix org.apache.felix.configadmin - 1.9.14 + 1.9.16 compile org.apache.sling org.apache.sling.provisioning.model - 1.8.4 + 1.8.6 compile 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 c9f538b..4d8cd34 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 @@ -19,6 +19,9 @@ */ package io.wcm.devops.conga.plugins.sling.handlebars.escaping; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + 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; @@ -34,6 +37,8 @@ public class ProvisioningEscapingStrategy implements EscapingStrategyPlugin { */ public static final String NAME = "sling-provisioning"; + private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\$\\{([^\\{\\}]+)\\}"); + @Override public String getName() { return NAME; @@ -47,8 +52,22 @@ public boolean accepts(String fileExtension, EscapingStrategyContext pluginConte @Override public String escape(CharSequence value, EscapingStrategyContext pluginContext) { + if (value == null) { + return null; + } + // use same escaping rules as for OSGi configurations - return value == null ? null : OsgiConfigEscapingStrategy.ESCAPE_OSGI_CONFIG.translate(value); + String escapedValue = OsgiConfigEscapingStrategy.ESCAPE_OSGI_CONFIG.translate(value); + + // escape variables ${...} with \${...} - otherwise lead to "Unknown variable" error when validating sling provisioning file + StringBuffer result = new StringBuffer(); + Matcher matcher = VARIABLE_PATTERN.matcher(escapedValue); + while (matcher.find()) { + matcher.appendReplacement(result, "\\\\\\$\\{" + matcher.group(1) + "\\}"); + } + matcher.appendTail(result); + + return result.toString(); } } 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 f94425b..e167b2e 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 @@ -28,6 +28,7 @@ import org.apache.sling.provisioning.model.Model; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.wcm.devops.conga.generator.GeneratorException; import io.wcm.devops.conga.generator.spi.PostProcessorPlugin; import io.wcm.devops.conga.generator.spi.context.FileContext; @@ -57,6 +58,7 @@ public boolean accepts(FileContext file, PostProcessorContext context) { } @Override + @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") public List apply(FileContext fileContext, PostProcessorContext context) { File file = fileContext.getFile(); try { @@ -80,11 +82,11 @@ public List apply(FileContext fileContext, PostProcessorContext con * @param model Provisioning Model * @param dir Target directory * @param context Post processor context - * @throws IOException */ private List generateOsgiConfigurations(Model model, File dir, PostProcessorContext context) throws IOException { return ProvisioningUtil.visitOsgiConfigurations(model, new ConfigConsumer() { @Override + @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") public FileContext accept(String path, Dictionary properties) throws IOException { context.getLogger().info(" Generate " + path); diff --git a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/util/ConfigurationHandler_ConfigAdmin184.java b/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/util/ConfigurationHandler_ConfigAdmin184.java index 1019308..d165d91 100644 --- a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/util/ConfigurationHandler_ConfigAdmin184.java +++ b/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/util/ConfigurationHandler_ConfigAdmin184.java @@ -42,6 +42,8 @@ import org.apache.felix.cm.file.FilePersistenceManager; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + /* * This file is COPIED from the sources of org.apache.felix.configadmin 1.8.4 * to write the configuration using the old (single line) array style, which is required to support @@ -66,7 +68,8 @@ * */ //CHECKSTYLE:OFF -@SuppressWarnings({ "unchecked", "unused", "javadoc" }) +@SuppressWarnings({ "unchecked", "unused", "javadoc", "PMD" }) +@SuppressFBWarnings({ "PERFORMANCE", "STYLE" }) class ConfigurationHandler_ConfigAdmin184 { protected static final String ENCODING = "UTF-8"; diff --git a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/util/ProvisioningUtil.java b/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/util/ProvisioningUtil.java index 69f2847..3d766d0 100644 --- a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/util/ProvisioningUtil.java +++ b/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/util/ProvisioningUtil.java @@ -38,6 +38,7 @@ import org.apache.sling.provisioning.model.ModelUtility; import org.apache.sling.provisioning.model.ModelUtility.ResolverOptions; import org.apache.sling.provisioning.model.RunMode; +import org.apache.sling.provisioning.model.Section; import org.apache.sling.provisioning.model.io.ModelReader; import com.google.common.collect.ImmutableList; @@ -60,6 +61,9 @@ public final class ProvisioningUtil { */ public static final String TEXT_FILE_EXTENSION = "txt"; + private static final String REPOINIT_SECTION = "repoinit"; + private static final String REPOINIT_PID = "org.apache.sling.jcr.repoinit.RepositoryInitializer"; + private ProvisioningUtil() { // static methods only } @@ -109,6 +113,8 @@ public static Model getModel(FileContext file) throws IOException { public static List visitOsgiConfigurations(Model model, ConfigConsumer consumer) throws IOException { List results = new ArrayList<>(); for (Feature feature : model.getFeatures()) { + + // OSGi configurations for (RunMode runMode : feature.getRunModes()) { for (Configuration configuration : runMode.getConfigurations()) { String path = getPathForConfiguration(configuration, runMode); @@ -118,6 +124,38 @@ public static List visitOsgiConfigurations(Model model, ConfigConsumer } } } + + // repoinit statements + for (Section section : feature.getAdditionalSections(REPOINIT_SECTION)) { + + // repoinit script + String script = section.getContents(); + if (StringUtils.isBlank(script)) { + continue; + } + + // associated run modes + String runModesString = section.getAttributes().get("runModes"); + RunMode runMode; + if (runModesString != null) { + runMode = new RunMode(StringUtils.split(runModesString, ",")); + } + else { + runMode = new RunMode(null); + } + + // prepare repoinit OSGi configuration + String pid = StringUtils.defaultString(feature.getName(), "conga") + + (runModesString != null ? "-" + StringUtils.replace(runModesString, ",", "-") : ""); + Configuration configuration = new Configuration(pid, REPOINIT_PID); + configuration.getProperties().put("scripts", new String[] { script }); + String path = getPathForConfiguration(configuration, runMode); + R result = consumer.accept(path, configuration.getProperties()); + if (result != null) { + results.add(result); + } + } + } return results; } 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 8bf85d1..c17755d 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 @@ -41,17 +41,17 @@ /** * WARNING: Test is disabled, see {@link OsgiConfigFileHeader} javadocs. */ -public class OsgiConfigFileHeaderTest { +class OsgiConfigFileHeaderTest { private FileHeaderPlugin underTest; @BeforeEach - public void setUp() { + void setUp() { underTest = new PluginManagerImpl().get(OsgiConfigFileHeader.NAME, FileHeaderPlugin.class); } @Test - public void testApply() throws Exception { + void testApply() throws Exception { File file = new File("target/generation-test/fileHeader.config"); FileUtils.write(file, "myscript", StandardCharsets.UTF_8); 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 d21e788..392f55e 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 @@ -38,17 +38,17 @@ import io.wcm.devops.conga.generator.spi.context.FileHeaderContext; import io.wcm.devops.conga.generator.util.PluginManagerImpl; -public class ProvisioningFileHeaderTest { +class ProvisioningFileHeaderTest { private FileHeaderPlugin underTest; @BeforeEach - public void setUp() { + void setUp() { underTest = new PluginManagerImpl().get(ProvisioningFileHeader.NAME, FileHeaderPlugin.class); } @Test - public void testApply() throws Exception { + void testApply() throws Exception { File file = new File("target/generation-test/fileHeader.txt"); FileUtils.copyFile(new File(getClass().getResource("/validProvisioning.txt").toURI()), file); 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 433d9bb..4c062fc 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 @@ -29,27 +29,27 @@ import io.wcm.devops.conga.generator.spi.handlebars.EscapingStrategyPlugin; import io.wcm.devops.conga.generator.util.PluginManagerImpl; -public class OsgiConfigEscapingStrategyTest { +class OsgiConfigEscapingStrategyTest { private EscapingStrategyPlugin underTest; @BeforeEach - public void setUp() { + void setUp() { underTest = new PluginManagerImpl().get(OsgiConfigEscapingStrategy.NAME, EscapingStrategyPlugin.class); } @Test - public void testValid() { + void testValid() { assertTrue(underTest.accepts("config", null)); } @Test - public void testInvalid() { + void testInvalid() { assertFalse(underTest.accepts("txt", null)); } @Test - public void testEscape() { + void testEscape() { assertEquals("\\ \\\"\\\\", underTest.escape(" \"\\", null)); assertEquals("äöü߀/", underTest.escape("äöü߀/", null)); assertEquals("aa\\=bb", underTest.escape("aa=bb", 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 ac59428..197efe5 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 @@ -29,24 +29,29 @@ import io.wcm.devops.conga.generator.spi.handlebars.EscapingStrategyPlugin; import io.wcm.devops.conga.generator.util.PluginManagerImpl; -public class ProvisioningEscapingStrategyTest { +class ProvisioningEscapingStrategyTest { private EscapingStrategyPlugin underTest; @BeforeEach - public void setUp() { + void setUp() { underTest = new PluginManagerImpl().get(ProvisioningEscapingStrategy.NAME, EscapingStrategyPlugin.class); } @Test - public void testValid() { + void testValid() { assertTrue(underTest.accepts("provisioning", null)); assertEquals("\\ \\\"\\\\", underTest.escape(" \"\\", null)); assertEquals("äöü߀/", underTest.escape("äöü߀/", null)); } @Test - public void testInvalid() { + void testEscapeVariables() { + assertEquals("\\${var1}\\ and\\ \\${var2}", underTest.escape("${var1} and ${var2}", null)); + } + + @Test + void testInvalid() { 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 9a63791..f5f7551 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 @@ -32,13 +32,12 @@ 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.felix.cm.file.ConfigurationHandler; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.LoggerFactory; import io.wcm.devops.conga.generator.spi.PostProcessorPlugin; @@ -47,30 +46,25 @@ import io.wcm.devops.conga.generator.spi.context.PostProcessorContext; import io.wcm.devops.conga.generator.util.PluginManagerImpl; -public class ProvisioningOsgiConfigPostProcessorTest { +class ProvisioningOsgiConfigPostProcessorTest { private PostProcessorPlugin underTest; private File targetDir; @BeforeEach - public void setUp() throws IOException { + void setUp(TestInfo testInfo) throws IOException { underTest = new PluginManagerImpl().get(ProvisioningOsgiConfigPostProcessor.NAME, PostProcessorPlugin.class); // prepare target dirctory - targetDir = new File("target/postprocessor-test_" + UUID.randomUUID().toString()); + targetDir = new File("target/postprocessor-test_" + testInfo.getDisplayName()); if (targetDir.exists()) { FileUtils.deleteDirectory(targetDir); } } - @AfterEach - public void tearDown() throws IOException { - FileUtils.deleteDirectory(targetDir); - } - @Test - public void testProvisioningExample() throws Exception { + void testProvisioningExample() throws Exception { // post process example valid provisioning file File provisioningFile = new File(targetDir, "provisioningExample.txt"); @@ -89,10 +83,21 @@ public void testProvisioningExample() throws Exception { assertExists("my.factory-my.pid.config"); assertExists("mode1/my.factory-my.pid2.config"); assertExists("mode2/my.pid2.config"); + + // validate repoinit statements + config = readConfig("org.apache.sling.jcr.repoinit.RepositoryInitializer-test.config"); + assertArrayEquals(new String[] {"create path /repoinit/test1\n" + + "create path /repoinit/test2\n" }, (String[])config.get("scripts")); + + config = readConfig("mode1/org.apache.sling.jcr.repoinit.RepositoryInitializer-test-mode1.config"); + assertArrayEquals(new String[] { "create service user mode1\n" }, (String[])config.get("scripts")); + + config = readConfig("mode1.mode2/org.apache.sling.jcr.repoinit.RepositoryInitializer-test-mode1-mode2.config"); + assertArrayEquals(new String[] { "create service user mode1_mode2" }, (String[])config.get("scripts")); } @Test - public void testSimpleConfig() throws Exception { + void testSimpleConfig() throws Exception { final String PROVISIONING_FILE = "[feature name=test]\n" + "[configurations]\n" + "com.example.ServiceConfiguration\n" @@ -111,7 +116,7 @@ public void testSimpleConfig() throws Exception { } @Test - public void testSimpleConfigWithNewline() throws Exception { + void testSimpleConfigWithNewline() throws Exception { final String PROVISIONING_FILE = "[feature name=test]\n" + "[configurations]\n" + "com.example.ServiceConfiguration\n" @@ -129,6 +134,19 @@ public void testSimpleConfigWithNewline() throws Exception { assertEquals("foo", config.get("foo")); } + @Test + void testEscapedVariable() throws Exception { + + // post process example valid provisioning file + File provisioningFile = new File(targetDir, "provisioningExample.txt"); + FileUtils.copyFile(new File(getClass().getResource("/validProvisioningEscapedVariable.txt").toURI()), provisioningFile); + postProcess(provisioningFile); + + // validate generated configs + Dictionary config = readConfig("my.pid.config"); + assertEquals("${var1} and ${var2}", config.get("stringProperty")); + } + private void postProcess(File provisioningFile) { // post-process FileContext fileContext = new FileContext() 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 8da1cc5..a0a3ed4 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 @@ -34,17 +34,17 @@ import io.wcm.devops.conga.generator.spi.context.FileContext; import io.wcm.devops.conga.generator.util.PluginManagerImpl; -public class ProvisioningValidatorTest { +class ProvisioningValidatorTest { private ValidatorPlugin underTest; @BeforeEach - public void setUp() { + void setUp() { underTest = new PluginManagerImpl().get(ProvisioningValidator.NAME, ValidatorPlugin.class); } @Test - public void testValid() throws Exception { + void testValid() throws Exception { File file = new File(getClass().getResource("/validProvisioning.txt").toURI()); FileContext fileContext = new FileContext().file(file).charset(StandardCharsets.UTF_8); assertTrue(underTest.accepts(fileContext, null)); @@ -52,7 +52,7 @@ public void testValid() throws Exception { } @Test - public void testInvalid() throws Exception { + void testInvalid() throws Exception { File file = new File(getClass().getResource("/invalidProvisioning.txt").toURI()); FileContext fileContext = new FileContext().file(file).charset(StandardCharsets.UTF_8); assertTrue(underTest.accepts(fileContext, null)); @@ -62,10 +62,18 @@ public void testInvalid() throws Exception { } @Test - public void testInvalidFileExtension() throws Exception { + void testInvalidFileExtension() throws Exception { File file = new File(getClass().getResource("/noProvisioning.txt").toURI()); FileContext fileContext = new FileContext().file(file).charset(StandardCharsets.UTF_8); assertFalse(underTest.accepts(fileContext, null)); } + @Test + void testEscapedVariable() throws Exception { + File file = new File(getClass().getResource("/validProvisioningEscapedVariable.txt").toURI()); + FileContext fileContext = new FileContext().file(file).charset(StandardCharsets.UTF_8); + assertTrue(underTest.accepts(fileContext, null)); + underTest.apply(fileContext, null); + } + } diff --git a/conga-sling-plugin/src/test/resources/validProvisioning.txt b/conga-sling-plugin/src/test/resources/validProvisioning.txt index c6b45b7..4d6de17 100644 --- a/conga-sling-plugin/src/test/resources/validProvisioning.txt +++ b/conga-sling-plugin/src/test/resources/validProvisioning.txt @@ -22,3 +22,14 @@ my.pid2 stringProperty="value4" + + +[:repoinit] +create path /repoinit/test1 +create path /repoinit/test2 + +[:repoinit runModes=mode1] +create service user mode1 + +[:repoinit runModes=mode1,mode2] +create service user mode1_mode2 diff --git a/conga-sling-plugin/src/test/resources/validProvisioningEscapedVariable.txt b/conga-sling-plugin/src/test/resources/validProvisioningEscapedVariable.txt new file mode 100644 index 0000000..a97d912 --- /dev/null +++ b/conga-sling-plugin/src/test/resources/validProvisioningEscapedVariable.txt @@ -0,0 +1,6 @@ +[feature name=test] + +[configurations] + + my.pid + stringProperty="\${var1} and \${var2}" diff --git a/example/pom.xml b/example/pom.xml index 6082baf..f12febb 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -20,13 +20,13 @@ --> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 io.wcm.maven io.wcm.maven.global-parent - 25 + 32 @@ -45,7 +45,7 @@ io.wcm.devops.conga conga-maven-plugin - 1.11.0 + 1.13.0 true @@ -53,7 +53,7 @@ io.wcm.devops.conga.plugins io.wcm.devops.conga.plugins.sling - 1.2.5-SNAPSHOT + 1.2.7-SNAPSHOT diff --git a/pom.xml b/pom.xml index b5c70d3..56bd173 100644 --- a/pom.xml +++ b/pom.xml @@ -17,19 +17,19 @@ #L% --> - + 4.0.0 io.wcm.devops io.wcm.devops.parent_toplevel - 1.1.4 + 1.2.2 io.wcm.devops.conga.plugins io.wcm.devops.conga.plugins.sling.root - 1.2.6 + 1.3.0 pom CONGA Sling Plugin diff --git a/src/site/markdown/extensions.md b/src/site/markdown/extensions.md index a1e859e..ab66a3c 100644 --- a/src/site/markdown/extensions.md +++ b/src/site/markdown/extensions.md @@ -22,5 +22,5 @@ The Sling Provisioning Model file format is described on the [Sling Website][sli You can use a Handlebars template to generate a provisioning file. When the post processor `sling-provisioning` is applied to this file the single Felix OSGi .config files are generated out of it and the provisioning file is deleted. -[conga-extensibility]: http://devops.wcm.io/conga/extensibility.html +[conga-extensibility]: https://devops.wcm.io/conga/extensibility.html [sling-slingstart]: https://sling.apache.org/documentation/development/slingstart.html diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 40c557e..7a66090 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -23,7 +23,7 @@ This plugin extends [CONGA][conga] with: ### Further Resources -* [wcm.io CONGA training material with exercises](http://training.wcm.io/conga/) +* [wcm.io CONGA training material with exercises](https://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) @@ -33,7 +33,7 @@ This plugin extends [CONGA][conga] with: [extensions]: extensions.html [apidocs]: conga-sling-plugin/apidocs/ [changelog]: changes-report.html -[conga]: http://devops.wcm.io/conga/ +[conga]: https://devops.wcm.io/conga/ [sling]: http://sling.apache.org/ [sling-provisioning]: https://sling.apache.org/documentation/development/slingstart.html [felix-configadmin]: http://felix.apache.org/documentation/subprojects/apache-felix-config-admin.html diff --git a/src/site/markdown/usage.md b/src/site/markdown/usage.md index fa20524..bbf726e 100644 --- a/src/site/markdown/usage.md +++ b/src/site/markdown/usage.md @@ -8,4 +8,4 @@ https://github.com/wcm-io-devops/conga-sling-plugin In a subdirectory `example`. -[conga-usage]: http://devops.wcm.io/conga/usage.html +[conga-usage]: https://devops.wcm.io/conga/usage.html diff --git a/src/site/site.xml b/src/site/site.xml index e135c2b..86001fd 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -20,12 +20,12 @@ --> + xsi:schemaLocation="http://maven.apache.org/DECORATION/1.8.0 http://maven.apache.org/xsd/decoration-1.8.0.xsd"> - ]]> + ]]>