Skip to content

Commit

Permalink
Merge pull request #34 from openweb-nl/develop
Browse files Browse the repository at this point in the history
Create release version 1.15
  • Loading branch information
mxdrenthe authored Nov 27, 2023
2 parents a3e2faf + eee1e06 commit e93fca7
Show file tree
Hide file tree
Showing 103 changed files with 581 additions and 3,426 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven

on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B verify --file pom.xml

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
- name: Maven Dependency Tree Dependency Submission
uses: advanced-security/maven-dependency-submission-action@multi-module
21 changes: 5 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Project for Hippo Updaters Maven Plugin
This project is designed for Hippo developers to have an easy way to create updaters in groovy, without being bothered with the bootstrap xml.
This project is designed for Hippo developers to have an easy way to create updaters in groovy, without being bothered with the repository data yaml.

For use the updaters are located in their own submodule. Nicely separated from other bootstrap.
They are groovy scripts, so the editor can easily provide autocomplete and stuff, configured by Annotations.
Expand Down Expand Up @@ -34,7 +34,6 @@ To add mixin(s) (since 1.14):
```
## Use of the maven plugin
In the build section of the (new) module containing the groovy updater scripts, define the execution of the plugin
*For Hippo 12 use the *'generate-yaml'* goal.*
```xml
<plugin>
<groupId>nl.openweb.hippo.updater</groupId>
Expand All @@ -45,7 +44,7 @@ In the build section of the (new) module containing the groovy updater scripts,
<id>default-resources</id>
<phase>compile</phase>
<goals>
<goal>generate-xml</goal>
<goal>generate-yaml</goal>
</goals>
</execution>
</executions>
Expand All @@ -59,12 +58,9 @@ In the build section of the (new) module containing the groovy updater scripts,
* **targetDir**
* where to generate the bootstrap
```(default: ${project.build.outputDirectory})```
* **defaultContentRoot** (since 1.12)
* **defaultContentRoot**
* default contentroot value _(registry/queue)_
```(default: queue)```
* **initializeNamePrefix**
* prefix in the ecm-extension.xml nodenames
```(default:hippo-updater-) ```
* **yamlContentPath** (since 1.13)
* relative path for the yaml queue bootstrap files
```(default: hcm-content/configuration/update)```
Expand All @@ -73,7 +69,7 @@ In the build section of the (new) module containing the groovy updater scripts,
```(default: hcm-config/configuration/update)```


When using a separate module in Hippo 12, don't forget to place an hcm-module.yaml in the project.
When using a separate module, don't forget to place an hcm-module.yaml in the project.
```yaml
group:
name: hippoproject
Expand Down Expand Up @@ -131,15 +127,8 @@ set the system property `groovy.sync.watchedModules` in the cargo container.
</configuration>
</plugin>
```
### Log4j
### Log4j2
Add an info logging level for nl.openweb.hippo.groovy to your development log4j configuration
```xml
<logger name="nl.openweb.hippo.groovy" additivity="false">
<level value="info"/>
<appender-ref ref="messages"/>
</logger>
```
**Log4j2:**
```xml
<Logger name="nl.openweb.hippo.groovy" additivity="false" level="info">
<AppenderRef ref="messages"/>
Expand Down
2 changes: 1 addition & 1 deletion annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.lang.annotation.Target;

/**
* Bootstrap annotation to define properties in the hippoecm-extension.xml
* Bootstrap annotation to define where to bootstrap the script
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
Expand All @@ -32,7 +32,7 @@ enum ContentRoot {
QUEUE("queue"),
REGISTRY("registry");

private String value;
private final String value;

ContentRoot(String value) {
this.value = value;
Expand All @@ -46,9 +46,16 @@ public String toString() {

ContentRoot contentroot() default ContentRoot.DEFAULT;

double sequence() default 99999.0d;

/**
* reload the script
* applies if contentroot is queue, and a version is defined.
* @return
*/
boolean reload() default false;

/**
* if the reload is set to true, the version will be used for bootstrapping
* @return
*/
String version() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Updater {
enum LogTarget {
DEFAULT(""),
LOG_FILES("LOG FILES"),
REPOSITORY("REPOSITORY");

private final String value;

LogTarget(String value) {
this.value = value;
}

@Override
public String toString() {
return value;
}
}
String name();

String description() default "";
Expand All @@ -44,4 +60,6 @@
long throttle() default 1000L;

String mixin() default "";

LogTarget logTarget() default LogTarget.DEFAULT;
}
12 changes: 2 additions & 10 deletions bootstrapgenerator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand All @@ -45,7 +41,7 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
</dependency>

Expand All @@ -69,10 +65,6 @@
<artifactId>jcr</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down Expand Up @@ -101,4 +93,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,21 @@
import nl.openweb.hippo.groovy.annotations.Bootstrap;
import nl.openweb.hippo.groovy.annotations.Exclude;
import nl.openweb.hippo.groovy.annotations.Updater;

import static nl.openweb.hippo.groovy.model.Constants.Files.GROOVY_EXTENSION;

public abstract class Generator {
protected static final String NEWLINE = "\n";
private static final List<Class<?>> ANNOTATED_CLASSES = Arrays.asList(Exclude.class, Bootstrap.class, Updater.class, Bootstrap.ContentRoot.class);
private static final String HIPPO_CONFIGURATION_UPDATE_PATH_PREFIX = "/hippo:configuration/hippo:update/hippo:";
private static final String REGEX_WHITESPACE = "\\s*";
private static final String REGEX_ANNOTATIONS_SNIPPET = "(?:[\\w\\W]+[\\n|;]" + REGEX_WHITESPACE + "import [\\w.]+[;|\\n]+)?(?=[\\w\\W]*@[\\w.]*Updater)([\\w\\W]*)(?=(?:public )?class \\w+ extends [\\w\\W]+" + REGEX_WHITESPACE + "\\{)";
private static final String REGEX_ATTR_NAME = "([A-Za-z]\\w*)";
private static final String REGEX_ATTR_VALUE_SINGLEQUOTE = "('.*?(?<!\\\\)('))";
private static final String REGEX_ATTR_VALUE_QUOTE = "(\".*?(?<!\\\\)(\"))";
private static final String REGEX_ATTR_VALUE_TRIPQUOTE = "('''([\\s\\S]*)''')";
private static final String REGEX_ATTR_VALUE_SIMPLE = "true|false|([^,^\\)]+)";
private static final String REGEX_COMMA = "\\s*,*\\s*";
private static final String REGEX_COMMA = REGEX_WHITESPACE + ",*" + REGEX_WHITESPACE;
private static final String REGEX_ATTR_VALUE = "("
+ REGEX_ATTR_VALUE_SINGLEQUOTE
+ "|"
Expand All @@ -57,32 +59,54 @@ public abstract class Generator {
+ REGEX_ATTR_VALUE_SIMPLE
+ ")?";
private static final String REGEX_ATTRIBUTES = REGEX_WHITESPACE + REGEX_ATTR_NAME + REGEX_WHITESPACE + "=" + REGEX_WHITESPACE + REGEX_ATTR_VALUE + REGEX_COMMA;
private static final String ANNOTATION_PAYLOAD = REGEX_WHITESPACE + "(\\((" + REGEX_ATTRIBUTES + ")*\\))?";
private static final String ANNOTATION_PAYLOAD = "(?:" + REGEX_WHITESPACE + "\\((" + REGEX_ATTRIBUTES + ")*\\))?";

protected static Bootstrap.ContentRoot defaultContentRoot = Bootstrap.ContentRoot.QUEUE;

protected Generator() {
}

public static List<String> getAnnotations(final String script){
//Strip comments
String codeBlock = script.replaceAll("\\s/\\*[\\w\\W]*\\*/", StringUtils.EMPTY);
if(codeBlock.startsWith("/*")) {
codeBlock = StringUtils.substringAfter(codeBlock, "*/");
}
codeBlock = codeBlock.replaceAll("\\n//.*", StringUtils.EMPTY);
final Matcher matcher = Pattern.compile(REGEX_ANNOTATIONS_SNIPPET).matcher(codeBlock);
final List<String> annotationStrings = new ArrayList<>();
if(matcher.find()) {
final String snippet = matcher.group(1);
for (final Class<?> annotationClass : getAnnotationClasses()) {
final String annotation = getAnnotation(snippet, annotationClass);
if (StringUtils.isNotBlank(annotation)) {
annotationStrings.add(annotation);
}
}
}
return annotationStrings;
}

public static String stripAnnotations(final String script) {
return stripAnnotations(script, false);
}

public static String stripAnnotations(final String script, final boolean keepSpaces) {
String result = script;
for (String annotation : getAnnotations(script)) {
result = result.replace("\n" + annotation, StringUtils.EMPTY);
result = result.replace(annotation, StringUtils.EMPTY);
}
for (final Class<?> aClass : getAnnotationClasses()) {
if (result.contains(aClass.getPackage().getName()) &&
result.contains(aClass.getSimpleName())) {
result = stripAnnotation(result, aClass.getSimpleName());
result = stripAnnotation(result, aClass.getCanonicalName());
result = result.replaceAll("import\\s*" + aClass.getCanonicalName() + "\\s*[;]?\n", "");
}
result = result.replaceAll("import" + REGEX_WHITESPACE + aClass.getCanonicalName() + REGEX_WHITESPACE + "[;]?\n", StringUtils.EMPTY);
}
if (keepSpaces) {
int scriptClassStartLine = getClassStartLineNr(script);
int strippedClassStartLine = getClassStartLineNr(result);
String addition = StringUtils.repeat(NEWLINE, scriptClassStartLine - strippedClassStartLine);
result = result.replaceFirst("\nclass ", addition + "\nclass ");
} else {
result = result.replaceAll("(\n){3,}", "\n\n");
}
return result;
}
Expand All @@ -99,13 +123,6 @@ private static int getClassStartLineNr(final String script) {
return lineNr;
}

private static String stripAnnotation(final String script, final String className) {
final String regex = getAnnotationRegex(className);
String s = script.replaceAll(regex, StringUtils.EMPTY);
s = s.replaceAll("(\n){3,}", "\n\n");
return s;
}

public static String getAnnotation(final String script, final String className) {
final String regex = getAnnotationRegex(className);
Matcher matcher = Pattern.compile(regex).matcher(script);
Expand All @@ -117,7 +134,7 @@ private static String getAnnotationRegex(final String className) {
return annotationName + ANNOTATION_PAYLOAD;
}

public static String getAnnotation(final String script, final Class clazz) {
public static String getAnnotation(final String script, final Class<?> clazz) {
String simple = getAnnotation(script, clazz.getSimpleName());

return StringUtils.isNotBlank(simple) ?
Expand All @@ -141,7 +158,7 @@ public static List<File> getGroovyFiles(final File dir) {
final List<File> allFiles = new ArrayList<>();
if (groovyFiles != null) {
allFiles.addAll(Arrays.asList(groovyFiles));
Collections.sort(allFiles, Comparator.comparing(File::getName));
allFiles.sort(Comparator.comparing(File::getName));
}
if (directories != null) {
Arrays.stream(directories)
Expand Down

This file was deleted.

Loading

0 comments on commit e93fca7

Please sign in to comment.