Skip to content

Commit 0ad2a28

Browse files
committed
Merge branch 'develop'
2 parents 14c5a56 + 71e985a commit 0ad2a28

File tree

12 files changed

+182
-16
lines changed

12 files changed

+182
-16
lines changed

changes.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
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.16.0" date="2023-07-03">
27+
<action type="add" dev="sseifert">
28+
Add new custom Handlebars expressions 'disallowProperty' which allows to block property names no longer supported.
29+
</action>
30+
</release>
31+
2632
<release version="1.15.0" date="2023-03-27">
2733
<action type="update" dev="sseifert">
2834
Switch to Java 11 as minimum version.

generator/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>io.wcm.devops.conga</groupId>
2727
<artifactId>io.wcm.devops.conga.parent</artifactId>
28-
<version>1.15.0</version>
28+
<version>1.16.0</version>
2929
<relativePath>../parent/pom.xml</relativePath>
3030
</parent>
3131

@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>io.wcm.devops.conga</groupId>
4646
<artifactId>io.wcm.devops.conga.model</artifactId>
47-
<version>1.15.0</version>
47+
<version>1.16.0</version>
4848
<scope>compile</scope>
4949
</dependency>
5050

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* #%L
3+
* wcm.io
4+
* %%
5+
* Copyright (C) 2023 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.generator.plugins.handlebars.helper;
21+
22+
import java.io.IOException;
23+
24+
import org.apache.commons.lang3.StringUtils;
25+
26+
import com.github.jknack.handlebars.Options;
27+
28+
import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin;
29+
import io.wcm.devops.conga.generator.spi.handlebars.context.HelperContext;
30+
31+
/**
32+
* Handlebars helper that ensures a given property is not set/present.
33+
* If it is, an exception is thrown with the property name.
34+
* Optionally, a second parameter can be provided with a custom error message.
35+
*/
36+
public final class DisallowPropertyHelper implements HelperPlugin<Object> {
37+
38+
/**
39+
* Plugin/Helper name
40+
*/
41+
public static final String NAME = "disallowProperty";
42+
43+
@Override
44+
public String getName() {
45+
return NAME;
46+
}
47+
48+
@Override
49+
public Object apply(Object context, Options options, HelperContext pluginContext) throws IOException {
50+
if (isPropertyPresent(context, options)) {
51+
String errorMessage = "Disallowed property is set: " + context;
52+
if (options.params.length > 0 && options.params[0] != null) {
53+
errorMessage = options.params[0].toString();
54+
}
55+
throw new IOException(errorMessage);
56+
}
57+
return null;
58+
}
59+
60+
private boolean isPropertyPresent(Object propertyNameExpression, Options options) {
61+
if (propertyNameExpression == null) {
62+
return false;
63+
}
64+
String propertyName = propertyNameExpression.toString();
65+
if (StringUtils.isBlank(propertyName)) {
66+
return false;
67+
}
68+
return options.get(propertyName) != null;
69+
}
70+
71+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
io.wcm.devops.conga.generator.plugins.handlebars.helper.ContainsHelper
2+
io.wcm.devops.conga.generator.plugins.handlebars.helper.DisallowPropertyHelper
23
io.wcm.devops.conga.generator.plugins.handlebars.helper.EachIfHelper
34
io.wcm.devops.conga.generator.plugins.handlebars.helper.EachIfEqualsHelper
45
io.wcm.devops.conga.generator.plugins.handlebars.helper.EnsurePropertiesHelper
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* #%L
3+
* wcm.io
4+
* %%
5+
* Copyright (C) 2023 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.generator.plugins.handlebars.helper;
21+
22+
import static io.wcm.devops.conga.generator.plugins.handlebars.helper.TestUtils.assertHelper;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertThrows;
25+
26+
import java.io.IOException;
27+
28+
import org.junit.jupiter.api.BeforeEach;
29+
import org.junit.jupiter.api.Test;
30+
31+
import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin;
32+
import io.wcm.devops.conga.generator.util.PluginManagerImpl;
33+
34+
class DisallowPropertyHelperTest {
35+
36+
private HelperPlugin<Object> helper;
37+
38+
@SuppressWarnings("unchecked")
39+
@BeforeEach
40+
void setUp() {
41+
helper = new PluginManagerImpl().get(DisallowPropertyHelper.NAME, HelperPlugin.class);
42+
}
43+
44+
@Test
45+
void testSetCase1() throws Exception {
46+
assertThrows(IOException.class, () -> {
47+
assertHelper(null, helper, "p1", new MockOptions()
48+
.withProperty("p1", "v1"));
49+
});
50+
}
51+
52+
@Test
53+
void testSetCase2() throws Exception {
54+
IOException ex = assertThrows(IOException.class, () -> {
55+
assertHelper(null, helper, "p1", new MockOptions("Custom Error Message")
56+
.withProperty("p1", "v1")
57+
.withProperty("p2", "v2")
58+
.withProperty("p3", "v3"));
59+
});
60+
assertEquals("Custom Error Message", ex.getMessage());
61+
}
62+
63+
@Test
64+
void testNotSetCase1() throws Exception {
65+
assertHelper(null, helper, "p1", new MockOptions());
66+
}
67+
68+
@Test
69+
void testNotSetCase2() throws Exception {
70+
assertHelper(null, helper, "p1", new MockOptions("Custom Error Message"));
71+
}
72+
73+
@Test
74+
void testNotSetCase3() throws Exception {
75+
assertHelper(null, helper, "p1", new MockOptions("Custom Error Message")
76+
.withProperty("p2", "v1"));
77+
}
78+
79+
}

model/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>io.wcm.devops.conga</groupId>
2727
<artifactId>io.wcm.devops.conga.parent</artifactId>
28-
<version>1.15.0</version>
28+
<version>1.16.0</version>
2929
<relativePath>../parent/pom.xml</relativePath>
3030
</parent>
3131

@@ -40,7 +40,7 @@
4040
<dependency>
4141
<groupId>io.wcm.devops.conga</groupId>
4242
<artifactId>io.wcm.devops.conga.resource</artifactId>
43-
<version>1.15.0</version>
43+
<version>1.16.0</version>
4444
<scope>compile</scope>
4545
</dependency>
4646

parent/pom.xml

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

3232
<groupId>io.wcm.devops.conga</groupId>
3333
<artifactId>io.wcm.devops.conga.parent</artifactId>
34-
<version>1.15.0</version>
34+
<version>1.16.0</version>
3535
<packaging>pom</packaging>
3636

3737
<name>CONGA</name>
@@ -75,7 +75,7 @@
7575
<dependency>
7676
<groupId>com.google.guava</groupId>
7777
<artifactId>guava</artifactId>
78-
<version>31.1-jre</version>
78+
<version>32.1.1-jre</version>
7979
</dependency>
8080

8181
<dependency>
@@ -87,7 +87,7 @@
8787
<dependency>
8888
<groupId>commons-io</groupId>
8989
<artifactId>commons-io</artifactId>
90-
<version>2.11.0</version>
90+
<version>2.13.0</version>
9191
</dependency>
9292

9393
<dependency>
@@ -116,7 +116,7 @@
116116
<dependency>
117117
<groupId>org.springframework</groupId>
118118
<artifactId>spring-core</artifactId>
119-
<version>5.3.26</version>
119+
<version>5.3.28</version>
120120
</dependency>
121121

122122
<dependency>

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
<parent>
2626
<groupId>io.wcm.devops.conga</groupId>
2727
<artifactId>io.wcm.devops.conga.parent</artifactId>
28-
<version>1.15.0</version>
28+
<version>1.16.0</version>
2929
<relativePath>parent/pom.xml</relativePath>
3030
</parent>
3131

3232
<groupId>io.wcm.devops.conga</groupId>
3333
<artifactId>io.wcm.devops.conga.root</artifactId>
34-
<version>1.15.0</version>
34+
<version>1.16.0</version>
3535
<packaging>pom</packaging>
3636

3737
<name>CONGA</name>

resource/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>io.wcm.devops.conga</groupId>
2727
<artifactId>io.wcm.devops.conga.parent</artifactId>
28-
<version>1.15.0</version>
28+
<version>1.16.0</version>
2929
<relativePath>../parent/pom.xml</relativePath>
3030
</parent>
3131

src/site/markdown/handlebars-helpers.md.vm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ Ensure that all properties with the given names are set. Build fails if this is
8888
```
8989

9090

91+
${symbol_pound}${symbol_pound}${symbol_pound} disallowProperty
92+
93+
Ensure that the given property is *not* set/present. It fails with an error message, if it is present. Optionally, a custom error message can be defined via a second parameter.
94+
95+
```
96+
{{ensureProperties "group1.prop1" "Property 'group1.prop1' is deprecated, please use 'XYZ' instead."}}
97+
```
98+
99+
91100

92101
[handlebars-quickstart]: handlebars-quickstart.html
93102
[extensibility]: extensibility.html

0 commit comments

Comments
 (0)