Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jul 3, 2023
2 parents 14c5a56 + 71e985a commit 0ad2a28
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 16 deletions.
6 changes: 6 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 https://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="1.16.0" date="2023-07-03">
<action type="add" dev="sseifert">
Add new custom Handlebars expressions 'disallowProperty' which allows to block property names no longer supported.
</action>
</release>

<release version="1.15.0" date="2023-03-27">
<action type="update" dev="sseifert">
Switch to Java 11 as minimum version.
Expand Down
4 changes: 2 additions & 2 deletions generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.parent</artifactId>
<version>1.15.0</version>
<version>1.16.0</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand All @@ -44,7 +44,7 @@
<dependency>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.model</artifactId>
<version>1.15.0</version>
<version>1.16.0</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* #%L
* wcm.io
* %%
* Copyright (C) 2023 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.generator.plugins.handlebars.helper;

import java.io.IOException;

import org.apache.commons.lang3.StringUtils;

import com.github.jknack.handlebars.Options;

import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin;
import io.wcm.devops.conga.generator.spi.handlebars.context.HelperContext;

/**
* Handlebars helper that ensures a given property is not set/present.
* If it is, an exception is thrown with the property name.
* Optionally, a second parameter can be provided with a custom error message.
*/
public final class DisallowPropertyHelper implements HelperPlugin<Object> {

/**
* Plugin/Helper name
*/
public static final String NAME = "disallowProperty";

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

@Override
public Object apply(Object context, Options options, HelperContext pluginContext) throws IOException {
if (isPropertyPresent(context, options)) {
String errorMessage = "Disallowed property is set: " + context;
if (options.params.length > 0 && options.params[0] != null) {
errorMessage = options.params[0].toString();
}
throw new IOException(errorMessage);
}
return null;
}

private boolean isPropertyPresent(Object propertyNameExpression, Options options) {
if (propertyNameExpression == null) {
return false;
}
String propertyName = propertyNameExpression.toString();
if (StringUtils.isBlank(propertyName)) {
return false;
}
return options.get(propertyName) != null;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
io.wcm.devops.conga.generator.plugins.handlebars.helper.ContainsHelper
io.wcm.devops.conga.generator.plugins.handlebars.helper.DisallowPropertyHelper
io.wcm.devops.conga.generator.plugins.handlebars.helper.EachIfHelper
io.wcm.devops.conga.generator.plugins.handlebars.helper.EachIfEqualsHelper
io.wcm.devops.conga.generator.plugins.handlebars.helper.EnsurePropertiesHelper
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* #%L
* wcm.io
* %%
* Copyright (C) 2023 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.generator.plugins.handlebars.helper;

import static io.wcm.devops.conga.generator.plugins.handlebars.helper.TestUtils.assertHelper;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin;
import io.wcm.devops.conga.generator.util.PluginManagerImpl;

class DisallowPropertyHelperTest {

private HelperPlugin<Object> helper;

@SuppressWarnings("unchecked")
@BeforeEach
void setUp() {
helper = new PluginManagerImpl().get(DisallowPropertyHelper.NAME, HelperPlugin.class);
}

@Test
void testSetCase1() throws Exception {
assertThrows(IOException.class, () -> {
assertHelper(null, helper, "p1", new MockOptions()
.withProperty("p1", "v1"));
});
}

@Test
void testSetCase2() throws Exception {
IOException ex = assertThrows(IOException.class, () -> {
assertHelper(null, helper, "p1", new MockOptions("Custom Error Message")
.withProperty("p1", "v1")
.withProperty("p2", "v2")
.withProperty("p3", "v3"));
});
assertEquals("Custom Error Message", ex.getMessage());
}

@Test
void testNotSetCase1() throws Exception {
assertHelper(null, helper, "p1", new MockOptions());
}

@Test
void testNotSetCase2() throws Exception {
assertHelper(null, helper, "p1", new MockOptions("Custom Error Message"));
}

@Test
void testNotSetCase3() throws Exception {
assertHelper(null, helper, "p1", new MockOptions("Custom Error Message")
.withProperty("p2", "v1"));
}

}
4 changes: 2 additions & 2 deletions model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.parent</artifactId>
<version>1.15.0</version>
<version>1.16.0</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand All @@ -40,7 +40,7 @@
<dependency>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.resource</artifactId>
<version>1.15.0</version>
<version>1.16.0</version>
<scope>compile</scope>
</dependency>

Expand Down
8 changes: 4 additions & 4 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.parent</artifactId>
<version>1.15.0</version>
<version>1.16.0</version>
<packaging>pom</packaging>

<name>CONGA</name>
Expand Down Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
<version>32.1.1-jre</version>
</dependency>

<dependency>
Expand All @@ -87,7 +87,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<version>2.13.0</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -116,7 +116,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.26</version>
<version>5.3.28</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<parent>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.parent</artifactId>
<version>1.15.0</version>
<version>1.16.0</version>
<relativePath>parent/pom.xml</relativePath>
</parent>

<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.root</artifactId>
<version>1.15.0</version>
<version>1.16.0</version>
<packaging>pom</packaging>

<name>CONGA</name>
Expand Down
2 changes: 1 addition & 1 deletion resource/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.parent</artifactId>
<version>1.15.0</version>
<version>1.16.0</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down
9 changes: 9 additions & 0 deletions src/site/markdown/handlebars-helpers.md.vm
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ Ensure that all properties with the given names are set. Build fails if this is
```


${symbol_pound}${symbol_pound}${symbol_pound} disallowProperty

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.

```
{{ensureProperties "group1.prop1" "Property 'group1.prop1' is deprecated, please use 'XYZ' instead."}}
```



[handlebars-quickstart]: handlebars-quickstart.html
[extensibility]: extensibility.html
Expand Down
4 changes: 2 additions & 2 deletions tooling/conga-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.parent</artifactId>
<version>1.15.0</version>
<version>1.16.0</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>

Expand All @@ -40,7 +40,7 @@
<dependency>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.generator</artifactId>
<version>1.15.0</version>
<version>1.16.0</version>
<scope>compile</scope>
</dependency>

Expand Down
6 changes: 3 additions & 3 deletions tooling/conga-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.parent</artifactId>
<version>1.15.0</version>
<version>1.16.0</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>

Expand All @@ -40,7 +40,7 @@
<site.url.module.prefix>tooling/conga-maven-plugin</site.url.module.prefix>

<!-- Versions -->
<maven-plugin-plugin.version>3.8.1</maven-plugin-plugin.version>
<maven-plugin-plugin.version>3.9.0</maven-plugin-plugin.version>

<!-- Enable recording of coverage during execution of maven-invoker-plugin -->
<jacoco.propertyName>invoker.mavenOpts</jacoco.propertyName>
Expand All @@ -56,7 +56,7 @@
<dependency>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.generator</artifactId>
<version>1.15.0</version>
<version>1.16.0</version>
<scope>compile</scope>
</dependency>

Expand Down

0 comments on commit 0ad2a28

Please sign in to comment.