Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jan 26, 2024
2 parents 73633ab + 16671f1 commit d5f7646
Show file tree
Hide file tree
Showing 30 changed files with 758 additions and 819 deletions.
9 changes: 9 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<body>

<release version="1.4.0" date="2024-01-26">
<action type="add" dev="sseifert" issue="7">
Add JsonOsgiConfigPostProcessor to support reading a combined set of OSGi configuration for run modes from .osgiconfig.json files.
</action>
<action type="update" dev="sseifert" issue="6">
ProvisioningOsgiConfigPostProcessor: Write OSGi configurations as .cfg.json files instead of .config files.
</action>
</release>

<release version="1.3.4" date="2023-11-20">
<action type="fix" dev="sseifert" issue="5">
Generate run modes for configurations in order as expected by AEM Analyser Plugin.
Expand Down
39 changes: 35 additions & 4 deletions conga-sling-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<parent>
<groupId>io.wcm.devops.conga.plugins</groupId>
<artifactId>io.wcm.devops.conga.plugins.sling.parent</artifactId>
<version>1.3.4</version>
<version>1.4.0</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

<groupId>io.wcm.devops.conga.plugins</groupId>
<artifactId>io.wcm.devops.conga.plugins.sling</artifactId>
<version>1.3.4</version>
<version>1.4.0</version>
<packaging>jar</packaging>

<name>CONGA Sling Plugin</name>
Expand Down Expand Up @@ -60,15 +60,14 @@
<dependency>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.generator</artifactId>
<version>1.16.2</version>
<version>1.17.0</version>
<scope>compile</scope>
</dependency>

<!-- Place this dependency always before the provisiong.model because this includes ConfigurationHandler as well -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.configadmin</artifactId>
<!-- Support latest config file format for reading, stick with version 1.8.4 for writing (ConfigurationHandler class is copied to this plugin) -->
<version>1.9.26</version>
<scope>compile</scope>
</dependency>
Expand All @@ -80,6 +79,38 @@
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.cm.json</artifactId>
<version>2.0.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.1.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.parsson</groupId>
<artifactId>parsson</artifactId>
<version>1.1.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.util.converter</artifactId>
<version>1.0.9</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion conga-sling-plugin/src/it/example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<plugin>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>conga-maven-plugin</artifactId>
<version>1.16.2</version>
<version>1.17.0</version>
<extensions>true</extensions>
<dependencies>

Expand Down
5 changes: 5 additions & 0 deletions conga-sling-plugin/src/it/example/src/main/roles/sling.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ files:
postProcessors:
- sling-provisioning-osgiconfig

- file: config-sample.osgiconfig.json
dir: osgi-config-from-json
template: config-sample.osgiconfig.json.hbs
postProcessors:
- sling-json-osgiconfig

# Defines configuration parameters and default values
config:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"configurations": {
"my.pid": {
"heapspaceMax": "{{jvm.heapspace.max}}",
"booleanProp": true,
"numberProp": 123,
"arrayProp": ["v1","v2","v3"],
"numberArrayProp": [1,2]
}
},
"configurations:mode1": {
"my.pid2": {
"stringProperty": "{{var1}}",
"stringProperty2": "{{var2}}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

my.pid
heapspaceMax="{{jvm.heapspace.max}}"
booleanProp=B"true"
numberProp=I"123"
arrayProp=["v1","v2","v3"]
numberArrayProp=I["1","2"]

[configurations runModes=mode1]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
package io.wcm.devops.conga.plugins.sling.fileheader;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import com.google.common.collect.ImmutableList;

import io.wcm.devops.conga.generator.GeneratorException;
import io.wcm.devops.conga.generator.plugins.fileheader.AbstractFileHeader;
import io.wcm.devops.conga.generator.spi.context.FileContext;
Expand Down Expand Up @@ -95,7 +94,7 @@ public FileHeaderContext extract(FileContext file) {
String[] contentLines = StringUtils.split(content, "\n");
if (contentLines.length > 0 && StringUtils.startsWith(contentLines[0], getCommentLinePrefix())) {
String fullComment = StringUtils.trim(StringUtils.substringAfter(contentLines[0], getCommentBlockStart()));
List<String> lines = ImmutableList.of(fullComment);
List<String> lines = Arrays.asList(fullComment);
return new FileHeaderContext().commentLines(lines);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* #%L
* wcm.io
* %%
* Copyright (C) 2024 wcm.io
* %%
* Licensed 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.
* #L%
*/
package io.wcm.devops.conga.plugins.sling.postprocessor;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
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;
import io.wcm.devops.conga.generator.spi.context.PostProcessorContext;
import io.wcm.devops.conga.plugins.sling.util.JsonOsgiConfigUtil;
import io.wcm.devops.conga.plugins.sling.util.ProvisioningUtil;

/**
* Transforms a combined JSON file containing OSGi configurations into individual OSGi configuration files.
*/
public class JsonOsgiConfigPostProcessor implements PostProcessorPlugin {

/**
* Plugin name
*/
public static final String NAME = "sling-json-osgiconfig";

/**
* File extension
*/
public static final String FILE_EXTENSION = ".osgiconfig.json";

@Override
public String getName() {
return NAME;
}

@Override
public boolean accepts(FileContext file, PostProcessorContext context) {
return StringUtils.endsWith(file.getFile().getName(), FILE_EXTENSION);
}

@Override
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
public List<FileContext> apply(FileContext fileContext, PostProcessorContext context) {
File file = fileContext.getFile();
try {
// read JSON file with combined configurations
Model model = JsonOsgiConfigUtil.readToProvisioningModel(file);

// generate OSGi configurations
List<FileContext> files = ProvisioningUtil.generateOsgiConfigurations(model, file.getParentFile(), context);

// delete provisioning file after transformation
Files.delete(file.toPath());

// return list of generated osgi configuration files
return files;
}
catch (IOException ex) {
throw new GeneratorException("Unable to parse JSON file with OSGi configurations.", ex);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
package io.wcm.devops.conga.plugins.sling.postprocessor;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Dictionary;
import java.nio.file.Files;
import java.util.List;

import org.apache.sling.provisioning.model.Model;
Expand All @@ -33,12 +31,11 @@
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.PostProcessorContext;
import io.wcm.devops.conga.plugins.sling.util.ConfigConsumer;
import io.wcm.devops.conga.plugins.sling.util.OsgiConfigUtil;
import io.wcm.devops.conga.plugins.sling.util.ProvisioningUtil;

/**
* Transforms a Sling Provisioning file into OSGi configurations (ignoring all other provisioning contents).
* Transforms a Sling Provisioning file into OSGi configuration files (.cfg.json).
* Repoinit statements are supported as well, all other provisioning contents are ignored
*/
public class ProvisioningOsgiConfigPostProcessor implements PostProcessorPlugin {

Expand All @@ -64,41 +61,17 @@ public List<FileContext> apply(FileContext fileContext, PostProcessorContext con
try {
// generate OSGi configurations
Model model = ProvisioningUtil.getModel(fileContext);
List<FileContext> files = generateOsgiConfigurations(model, file.getParentFile(), context);
List<FileContext> files = ProvisioningUtil.generateOsgiConfigurations(model, file.getParentFile(), context);

// delete provisioning file after transformation
file.delete();
Files.delete(file.toPath());

// return list of generated osgi configuration files
return files;
}
catch (IOException ex) {
throw new GeneratorException("Unable to post-process sling provisioning OSGi configurations.", ex);
throw new GeneratorException("Unable to post-process Sling Provisioning OSGi configurations.", ex);
}
}

/**
* Generate OSGi configuration for all feature and run modes.
* @param model Provisioning Model
* @param dir Target directory
* @param context Post processor context
*/
private List<FileContext> generateOsgiConfigurations(Model model, File dir, PostProcessorContext context) throws IOException {
return ProvisioningUtil.visitOsgiConfigurations(model, new ConfigConsumer<FileContext>() {
@Override
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
public FileContext accept(String path, Dictionary<String, Object> properties) throws IOException {
context.getLogger().info(" Generate {}", path);

File confFile = new File(dir, path);
confFile.getParentFile().mkdirs();
try (FileOutputStream os = new FileOutputStream(confFile)) {
OsgiConfigUtil.write(os, properties);
}

return new FileContext().file(confFile).charset(StandardCharsets.UTF_8);
}
});
}

}
Loading

0 comments on commit d5f7646

Please sign in to comment.