Skip to content

Commit

Permalink
additional comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jan 9, 2024
1 parent c272631 commit 542d16e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@
import org.apache.sling.provisioning.model.Model;
import org.apache.sling.provisioning.model.RunMode;
import org.apache.sling.provisioning.model.Section;
import org.jetbrains.annotations.Nullable;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.wcm.devops.conga.plugins.sling.postprocessor.JsonOsgiConfigPostProcessor;

/**
* Helper class for reading JSON files.
* Transforms a combined JSON file to provisioning model with OSGi configurations and repoinit statements.
*/
public final class JsonOsgiConfigUtil {

Expand Down Expand Up @@ -89,6 +90,9 @@ public static Model readToProvisioningModel(File file) throws IOException {
return model;
}

/**
* Detect entries describing OSGi configurations and repoinit statements.
*/
@SuppressWarnings("unchecked")
private static void processEntry(Feature feature, String key, Object value) throws IOException {
Matcher configurationsKeyMatcher = KEY_PATTERN_CONFIGURATIONS.matcher(key);
Expand Down Expand Up @@ -118,14 +122,16 @@ private static void processEntry(Feature feature, String key, Object value) thro
}
}

private static String[] toRunModes(String runModesString) {
private static String @Nullable [] toRunModes(String runModesString) {
if (StringUtils.isBlank(runModesString)) {
return null;
}
return StringUtils.split(runModesString, ",");
}


/**
* Convert OSGi configurations to Provisioning model configurations with associated run modes.
*/
@SuppressWarnings("unchecked")
private static void processOsgiConfiguration(Feature feature, String[] runModes, Map<String, Object> configurations) throws IOException {
RunMode runMode = feature.getOrCreateRunMode(runModes);
Expand All @@ -146,6 +152,9 @@ private static void processOsgiConfiguration(Feature feature, String[] runModes,
}
}

/**
* Convert repoinit statements to Provisioning model additional sections with associated run modes.
*/
private static void processRepoInit(Feature feature, String[] runModes, Collection<String> repoinits) {
Section section = new Section(ProvisioningUtil.REPOINIT_SECTION);
feature.getAdditionalSections().add(section);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class JsonOsgiConfigPostProcessorTest {
void setUp(TestInfo testInfo) throws IOException {
underTest = new PluginManagerImpl().get(JsonOsgiConfigPostProcessor.NAME, PostProcessorPlugin.class);

// prepare target dirctory
// prepare target directory
targetDir = new File("target/JsonOsgiConfigPostProcessorTest_" + testInfo.getDisplayName());
if (targetDir.exists()) {
FileUtils.deleteDirectory(targetDir);
Expand All @@ -64,7 +64,7 @@ void setUp(TestInfo testInfo) throws IOException {
@Test
void testJsonFile() throws Exception {

// post process example valid provisioning file
// post process example JSON file
File provisioningFile = new File(targetDir, "sample.osgiconfig.json");
FileUtils.copyFile(new File(getClass().getResource("/osgi-config-json/sample.osgiconfig.json").toURI()), provisioningFile);
postProcess(provisioningFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ProvisioningOsgiConfigPostProcessorTest {
void setUp(TestInfo testInfo) throws IOException {
underTest = new PluginManagerImpl().get(ProvisioningOsgiConfigPostProcessor.NAME, PostProcessorPlugin.class);

// prepare target dirctory
// prepare target directory
targetDir = new File("target/ProvisioningOsgiConfigPostProcessorTest_" + testInfo.getDisplayName());
if (targetDir.exists()) {
FileUtils.deleteDirectory(targetDir);
Expand Down

0 comments on commit 542d16e

Please sign in to comment.