Skip to content

Commit cdb9a0d

Browse files
committed
[jgitflow-maven-plugin] merging 'release/1.12.0' into 'master'
2 parents a1abddf + e314a2b commit cdb9a0d

22 files changed

Lines changed: 788 additions & 137 deletions

File tree

changes.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 https://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
2424
<body>
2525

26+
<release version="1.12.0" date="2020-06-28">
27+
<action type="add" dev="sseifert">
28+
Add httpdCloudManagerConditional and withAllCloudManagerConditional handlebars helper to build envrionment-conditional configuration for AEM cloud service..
29+
</action>
30+
<action type="add" dev="sseifert">
31+
conga-aem-maven-plugin: Add new parameter autoDependenciesMode which replaces/supercedes autoDependencies and autoDependenciesSeparateMutable flags.
32+
</action>
33+
<action type="update" dev="sseifert">
34+
conga-aem-maven-plugin: Generate unique package names for all packages depending on run modes.
35+
</action>
36+
</release>
37+
2638
<release version="1.11.4" date="2020-05-19">
2739
<action type="update" dev="sseifert">
2840
conga-aem-maven-plugin: Allow to provide separate credentials for package manager and Felix console.

conga-aem-plugin/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
<groupId>io.wcm.devops.conga.plugins</groupId>
3333
<artifactId>io.wcm.devops.conga.plugins.aem</artifactId>
34-
<version>1.11.4</version>
34+
<version>1.12.0</version>
3535
<packaging>jar</packaging>
3636

3737
<name>CONGA AEM Plugin</name>
@@ -73,7 +73,7 @@
7373
<dependency>
7474
<groupId>com.google.guava</groupId>
7575
<artifactId>guava</artifactId>
76-
<version>15.0</version>
76+
<version>29.0-jre</version>
7777
<scope>compile</scope>
7878
</dependency>
7979

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* #%L
3+
* wcm.io
4+
* %%
5+
* Copyright (C) 2020 wcm.io
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package io.wcm.devops.conga.plugins.aem.handlebars.helper;
21+
22+
import java.io.IOException;
23+
import java.util.List;
24+
import java.util.Map;
25+
import java.util.stream.Collectors;
26+
27+
import org.apache.commons.lang3.StringUtils;
28+
29+
import com.github.jknack.handlebars.Context;
30+
import com.github.jknack.handlebars.Options;
31+
import com.github.jknack.handlebars.Options.Buffer;
32+
import com.google.common.collect.ImmutableList;
33+
import com.google.common.collect.ImmutableMap;
34+
35+
import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin;
36+
import io.wcm.devops.conga.generator.spi.handlebars.context.HelperContext;
37+
import io.wcm.devops.conga.model.util.MapMerger;
38+
39+
/**
40+
* Checks if there is a conditional statement 'httpd.cloudManagerConditional' in the current context.
41+
* If yes iterates over all environments and renders the body for each with a merged model.
42+
* If no the body is rendered once with the default model.
43+
*/
44+
abstract class AbstractCloudManagerConditionalHelper implements HelperPlugin<Object> {
45+
46+
static final String HTTPD_KEY = "httpd";
47+
static final String CLOUD_MANAGER_CONDITIONAL_KEY = "cloudManagerConditional";
48+
static final List<String> ENVIRONMENTS = ImmutableList.of("dev", "stage", "prod");
49+
50+
@Override
51+
@SuppressWarnings("unchecked")
52+
public final Object apply(Object context, Options options, HelperContext pluginContext) throws IOException {
53+
Buffer buffer = options.buffer();
54+
55+
Context currentContext = options.context;
56+
if (context != null) {
57+
currentContext = Context.copy(options.context, context);
58+
}
59+
60+
// get tenants from context
61+
Object cloudManagerConditional = currentContext.get(HTTPD_KEY + "." + CLOUD_MANAGER_CONDITIONAL_KEY);
62+
63+
if (!(cloudManagerConditional instanceof Map)) {
64+
// no conditional statement - just render the body
65+
buffer.append(options.fn(currentContext));
66+
}
67+
else {
68+
// render body for each environment in conditional block with a merged context
69+
List<CloudManagerConditional> items = getCloudManagerConditional((Map<String, Object>)cloudManagerConditional);
70+
for (CloudManagerConditional item : items) {
71+
72+
// config inside httpd.cloudManagerConditional is considered to be prefixed with "httpd.", so wrap it around here for merging
73+
Map<String, Object> httpdWrapper = ImmutableMap.of(HTTPD_KEY, item.getConfig());
74+
Map<String, Object> mergedModel = MapMerger.merge(httpdWrapper, (Map<String, Object>)currentContext.model());
75+
76+
// remove cloudManagerConditional after merging the models
77+
Map<String, Object> mergedHttpd = (Map<String, Object>)mergedModel.get(HTTPD_KEY);
78+
if (mergedHttpd != null) {
79+
mergedHttpd.remove(CLOUD_MANAGER_CONDITIONAL_KEY);
80+
}
81+
82+
Context mergedContext = Context.copy(currentContext, mergedModel);
83+
CharSequence bodyContent = options.fn(mergedContext);
84+
85+
if (StringUtils.isNotBlank(bodyContent)) {
86+
renderBodyContent(buffer, bodyContent, item.getTargetEnvironment());
87+
}
88+
}
89+
}
90+
91+
return buffer;
92+
}
93+
94+
protected abstract void renderBodyContent(Buffer buffer, CharSequence bodyContent,
95+
String targetEnvironment) throws IOException;
96+
97+
private List<CloudManagerConditional> getCloudManagerConditional(Map<String, Object> cloudManagerConditional) {
98+
return ENVIRONMENTS.stream()
99+
.map(env -> new CloudManagerConditional(env, cloudManagerConditional.getOrDefault(env, ImmutableMap.of())))
100+
.collect(Collectors.toList());
101+
}
102+
103+
/**
104+
* Cloud manager conditional result per tenant and target environment.
105+
*/
106+
private static class CloudManagerConditional {
107+
108+
private final Map<String, Object> config;
109+
private final String targetEnvironment;
110+
111+
@SuppressWarnings("unchecked")
112+
CloudManagerConditional(String targetEnvironment, Object value) {
113+
this.targetEnvironment = targetEnvironment;
114+
if (value instanceof Map) {
115+
this.config = (Map<String, Object>)value;
116+
}
117+
else {
118+
this.config = ImmutableMap.of();
119+
}
120+
}
121+
122+
public String getTargetEnvironment() {
123+
return targetEnvironment;
124+
}
125+
126+
public Map<String, Object> getConfig() {
127+
return config;
128+
}
129+
130+
}
131+
132+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* #%L
3+
* wcm.io
4+
* %%
5+
* Copyright (C) 2020 wcm.io
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package io.wcm.devops.conga.plugins.aem.handlebars.helper;
21+
22+
import java.io.IOException;
23+
24+
import org.apache.commons.lang3.StringUtils;
25+
26+
import com.github.jknack.handlebars.Options.Buffer;
27+
28+
/**
29+
* Checks if there is a conditional statement 'httpd.cloudManagerConditional' in the current context.
30+
* If yes iterates over all environments and renders the body for each with a merged model,
31+
* each enclosed in an IfDefine statement.
32+
* If no the body is rendered once with the default model.
33+
*/
34+
public final class HttpdCloudManagerConditionalHelper extends AbstractCloudManagerConditionalHelper {
35+
36+
/**
37+
* Plugin/Helper name
38+
*/
39+
public static final String NAME = "httpdCloudManagerConditional";
40+
41+
@Override
42+
public String getName() {
43+
return NAME;
44+
}
45+
46+
@Override
47+
protected void renderBodyContent(Buffer buffer, CharSequence bodyContent,
48+
String targetEnvironment) throws IOException {
49+
buffer.append("<IfDefine ENVIRONMENT_").append(StringUtils.upperCase(targetEnvironment)).append(">");
50+
buffer.append(bodyContent);
51+
buffer.append("</IfDefine>\n");
52+
}
53+
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* #%L
3+
* wcm.io
4+
* %%
5+
* Copyright (C) 2020 wcm.io
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package io.wcm.devops.conga.plugins.aem.handlebars.helper;
21+
22+
import java.io.IOException;
23+
24+
import com.github.jknack.handlebars.Options.Buffer;
25+
26+
/**
27+
* Checks if there is a conditional statement 'httpd.cloudManagerConditional' in the current context.
28+
* If yes iterates over all environments and renders the body for each with a merged model.
29+
* If no the body is rendered once with the default model.
30+
*/
31+
public final class WithAllCloudManagerConditionalHelper extends AbstractCloudManagerConditionalHelper {
32+
33+
/**
34+
* Plugin/Helper name
35+
*/
36+
public static final String NAME = "withAllCloudManagerConditional";
37+
38+
@Override
39+
public String getName() {
40+
return NAME;
41+
}
42+
43+
@Override
44+
protected void renderBodyContent(Buffer buffer, CharSequence bodyContent,
45+
String targetEnvironment) throws IOException {
46+
buffer.append(bodyContent);
47+
}
48+
49+
}

conga-aem-plugin/src/main/resources/META-INF/services/io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ io.wcm.devops.conga.plugins.aem.handlebars.helper.AemHttpdFilterHelper
44
io.wcm.devops.conga.plugins.aem.handlebars.helper.OakAuthorizableUuidHelper
55
io.wcm.devops.conga.plugins.aem.handlebars.helper.OakPasswordHashHelper
66
io.wcm.devops.conga.plugins.aem.handlebars.helper.WebConsolePasswordHashHelper
7+
io.wcm.devops.conga.plugins.aem.handlebars.helper.HttpdCloudManagerConditionalHelper
78
io.wcm.devops.conga.plugins.aem.handlebars.helper.HttpHostHelper
8-
io.wcm.devops.conga.plugins.aem.handlebars.helper.HttpHostSslHelper
9+
io.wcm.devops.conga.plugins.aem.handlebars.helper.HttpHostSslHelper
10+
io.wcm.devops.conga.plugins.aem.handlebars.helper.WithAllCloudManagerConditionalHelper
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* #%L
3+
* wcm.io
4+
* %%
5+
* Copyright (C) 2020 wcm.io
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package io.wcm.devops.conga.plugins.aem.handlebars.helper;
21+
22+
import static io.wcm.devops.conga.plugins.aem.handlebars.helper.MockOptions.FN_RETURN;
23+
import static io.wcm.devops.conga.plugins.aem.handlebars.helper.TestUtils.assertHelper;
24+
25+
import java.io.IOException;
26+
import java.util.Map;
27+
28+
import org.junit.jupiter.api.BeforeEach;
29+
import org.junit.jupiter.api.Test;
30+
31+
import com.google.common.collect.ImmutableMap;
32+
33+
import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin;
34+
import io.wcm.devops.conga.generator.util.PluginManagerImpl;
35+
36+
class HttpdCloudManagerConditionalHelperTest {
37+
38+
private HelperPlugin<Object> helper;
39+
40+
@SuppressWarnings("unchecked")
41+
@BeforeEach
42+
void setUp() {
43+
helper = new PluginManagerImpl().get(HttpdCloudManagerConditionalHelper.NAME, HelperPlugin.class);
44+
}
45+
46+
@Test
47+
void testApply() throws IOException {
48+
Map<String, Object> model = ImmutableMap.of("httpd", ImmutableMap.of("serverName", "host1"));
49+
MockOptions options = new MockOptions(model);
50+
51+
assertHelper(FN_RETURN + "(" + model + ")", helper, null, options);
52+
}
53+
54+
@Test
55+
void testApplySeparateModel() throws IOException {
56+
Map<String, Object> model = ImmutableMap.of("httpd", ImmutableMap.of("serverName", "host1"));
57+
MockOptions options = new MockOptions();
58+
59+
assertHelper(FN_RETURN + "(" + model + ")", helper, model, options);
60+
}
61+
62+
@Test
63+
void testApplyWithCloudManagerConditional() throws IOException {
64+
Map<String, Object> model = ImmutableMap.of("httpd",
65+
ImmutableMap.of("serverName", "host0",
66+
"cloudManagerConditional", ImmutableMap.of(
67+
"dev", ImmutableMap.of("serverName", "host1"),
68+
"stage", ImmutableMap.of("serverName", "host2"),
69+
"prod", ImmutableMap.of())));
70+
MockOptions options = new MockOptions(model);
71+
72+
Map<String, Object> model_dev = ImmutableMap.of("httpd", ImmutableMap.of("serverName", "host1"));
73+
Map<String, Object> model_stage = ImmutableMap.of("httpd", ImmutableMap.of("serverName", "host2"));
74+
Map<String, Object> model_prod = ImmutableMap.of("httpd", ImmutableMap.of("serverName", "host0"));
75+
assertHelper("<IfDefine ENVIRONMENT_DEV>" + FN_RETURN + "(" + model_dev + ")</IfDefine>\n"
76+
+ "<IfDefine ENVIRONMENT_STAGE>" + FN_RETURN + "(" + model_stage + ")</IfDefine>\n"
77+
+ "<IfDefine ENVIRONMENT_PROD>" + FN_RETURN + "(" + model_prod + ")</IfDefine>\n",
78+
helper, null, options);
79+
}
80+
81+
}

0 commit comments

Comments
 (0)