From cd648d5899584cd99711984373f30e5b97cee8e5 Mon Sep 17 00:00:00 2001 From: Joost O Date: Mon, 11 Oct 2021 10:21:56 +0200 Subject: [PATCH 01/15] Feature/#15 reserved words break functionality (#20) * Extend test to expose problem * Rewrite functionality to extract and strip Annotations * Fix regex for edge case annotation detection --- .../nl/openweb/hippo/groovy/Generator.java | 36 +++++++++++++++---- .../hippo/groovy/ScriptClassFactory.java | 21 +++-------- .../src/test/java/GeneratorTest.java | 15 ++++++++ .../src/test/resources/sub/updater3.xml | 4 +-- .../src/test/resources/sub/updater3.yaml | 4 +-- .../src/test/resources/updater3.groovy | 2 +- .../src/test/resources/updater3.xml | 2 +- .../src/test/resources/updater3.yaml | 2 +- pom.xml | 2 +- 9 files changed, 58 insertions(+), 30 deletions(-) diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/Generator.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/Generator.java index 30c688d..13ca2c6 100644 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/Generator.java +++ b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/Generator.java @@ -34,12 +34,14 @@ 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> 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_ANNOTATIONS_SNIPPET = "(?:[\\w\\W]+[\\n|;]\\s*import [\\w\\.]+[;|\\n]+)?(?=[\\w\\W]*@[\\w\\.]*Updater)(?:([\\w\\W]*)(?=(?:(?:public )?class \\w+ extends [\\w\\W]+\\s*\\{)))"; private static final String REGEX_WHITESPACE = "\\s*"; private static final String REGEX_ATTR_NAME = "([A-Za-z]\\w*)"; private static final String REGEX_ATTR_VALUE_SINGLEQUOTE = "('.*?(? 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 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\\s*" + aClass.getCanonicalName() + "\\s*[;]?\n", ""); } 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; } diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/ScriptClassFactory.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/ScriptClassFactory.java index 216123d..f2a5589 100644 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/ScriptClassFactory.java +++ b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/ScriptClassFactory.java @@ -35,6 +35,7 @@ import static java.util.stream.Collectors.toList; import static nl.openweb.hippo.groovy.Generator.NEWLINE; import static nl.openweb.hippo.groovy.Generator.getAnnotationClasses; +import static nl.openweb.hippo.groovy.Generator.getAnnotations; import static nl.openweb.hippo.groovy.Generator.stripAnnotations; public class ScriptClassFactory { @@ -93,14 +94,9 @@ public static ScriptClass getInterpretingClass(final File file, final boolean ke script = readFileEnsuringLinuxLineEnding(file); String imports = getAnnotationClasses().stream() - .map(clazz -> "import " + clazz.getCanonicalName() + ";") + .map(clazz -> "import " + clazz.getCanonicalName() + ";" + LINE_END_LINUX) .collect(joining()); - - String interpretCode = imports + script.replaceAll("import .+\n", "") - .replaceAll("package\\s.*\n", "") - .replaceAll("extends\\s.*\\{[^\\u001a]*", "{}"); - - interpretCode = scrubAnnotations(interpretCode); + String interpretCode = imports + getAnnotations(script).stream().collect(joining(LINE_END_LINUX)) + LINE_END_LINUX + "class InterpretClass {}"; script = stripAnnotations(script, keepLineCount); final ScriptClass scriptClass = new ScriptClass(file, groovyClassLoader.parseClass(interpretCode), script); validateScriptClass(scriptClass); @@ -113,19 +109,12 @@ public static ScriptClass getInterpretingClass(final File file, final boolean ke public static String readFileEnsuringLinuxLineEnding(final File file) throws IOException { String content = FileUtils.fileRead(file); if (content.contains(LINE_END_MAC)) { - content = content.replaceAll(LINE_END_WINDOWS, LINE_END_LINUX) - .replaceAll(LINE_END_MAC, LINE_END_LINUX); + content = content.replace(LINE_END_WINDOWS, LINE_END_LINUX) + .replace(LINE_END_MAC, LINE_END_LINUX); } return content.replaceAll("[\\t ]+" + NEWLINE, NEWLINE); } - private static String scrubAnnotations(final String interpretCode) { - String possibleAnnotationNames = getAnnotationClasses().stream() - .map(annotation -> annotation.getCanonicalName().replace(".", "\\.") + "|" + annotation.getSimpleName()) - .collect(joining("|")); - return interpretCode.replaceAll("@((?!" + possibleAnnotationNames + ")[\\w]+)([\\s]+|(\\([^\\)]*\\)))", ""); - } - public static List getScriptClasses(File sourceDir) { return Generator.getGroovyFiles(sourceDir).stream().map(ScriptClassFactory::getInterpretingClass) .filter(script -> script.isValid() && !script.isExcluded()).collect(toList()); diff --git a/bootstrapgenerator/src/test/java/GeneratorTest.java b/bootstrapgenerator/src/test/java/GeneratorTest.java index 6757d7e..2aaf524 100644 --- a/bootstrapgenerator/src/test/java/GeneratorTest.java +++ b/bootstrapgenerator/src/test/java/GeneratorTest.java @@ -83,6 +83,21 @@ public void extractAnnotation() throws URISyntaxException, IOException { assertEquals(bootstrapFull2, fullBootstrap2); } + @Test + public void getAnnotations() throws URISyntaxException, IOException { + URL testfileUrl = getClass().getResource("updater.groovy"); + URL testfileUrl2 = getClass().getResource("updater-noimport.groovy"); + + String content = ScriptClassFactory.readFileEnsuringLinuxLineEnding(new File(testfileUrl.toURI())); + String content2 = ScriptClassFactory.readFileEnsuringLinuxLineEnding(new File(testfileUrl2.toURI())); + + final List annotations = Generator.getAnnotations(content); + final List annotations2 = Generator.getAnnotations(content2); + + assertEquals(2, annotations.size(), "Not correct count of annotations found"); + assertEquals(2, annotations2.size(), "Not correct count of annotations found"); + } + @Test public void getAnnotationClassesTest() throws Exception { List> classes = getAnnotationClasses(); diff --git a/bootstrapgenerator/src/test/resources/sub/updater3.xml b/bootstrapgenerator/src/test/resources/sub/updater3.xml index f3d277e..5042e11 100644 --- a/bootstrapgenerator/src/test/resources/sub/updater3.xml +++ b/bootstrapgenerator/src/test/resources/sub/updater3.xml @@ -25,13 +25,13 @@ import javax.xml.bind.annotation.XmlAccessorOrder /* Also, there is some other annotation * you never know if there is another thing working it - * Of course, maybe it could break using:( in a comment + * Of course, maybe it could break using:@Updater( in a comment */ @XmlElement @XmlAccessorOrder( value = XmlAccessOrder.ALPHABETICAL ) -// +//@Exclude class TestSubUpdater3 extends BaseNodeUpdateVisitor { boolean doUpdate(Node node) { log.info "manipulate node < > & an %^&* /> {}", node.path diff --git a/bootstrapgenerator/src/test/resources/sub/updater3.yaml b/bootstrapgenerator/src/test/resources/sub/updater3.yaml index b0a1dfb..e69be4d 100644 --- a/bootstrapgenerator/src/test/resources/sub/updater3.yaml +++ b/bootstrapgenerator/src/test/resources/sub/updater3.yaml @@ -15,13 +15,13 @@ /* Also, there is some other annotation * you never know if there is another thing working it - * Of course, maybe it could break using:( in a comment + * Of course, maybe it could break using:@Updater( in a comment */ @XmlElement @XmlAccessorOrder( value = XmlAccessOrder.ALPHABETICAL ) - // + //@Exclude class TestSubUpdater3 extends BaseNodeUpdateVisitor { boolean doUpdate(Node node) { log.info "manipulate node < > & an %^&* /> {}", node.path diff --git a/bootstrapgenerator/src/test/resources/updater3.groovy b/bootstrapgenerator/src/test/resources/updater3.groovy index 80cb87e..e1903ee 100644 --- a/bootstrapgenerator/src/test/resources/updater3.groovy +++ b/bootstrapgenerator/src/test/resources/updater3.groovy @@ -6,7 +6,7 @@ import javax.jcr.Node import nl.openweb.hippo.groovy.annotations.Bootstrap.ContentRoot; @Bootstrap(contentroot = ContentRoot.QUEUE, sequence = 99999.0d, reload = true, version = "2") @Updater(name = "Test Updater 3", path = "", xpath = "//element(*, hippo:document)" - , description = "Test thing", batchSize = 1L, throttle = 200L, dryRun = true, parameters = "{prop: val}") + , description = "Test things, like reserved words as import or others", batchSize = 1L, throttle = 200L, dryRun = true, parameters = "{prop: val}") class TestUpdater3 extends BaseNodeUpdateVisitor { boolean doUpdate(Node node) { diff --git a/bootstrapgenerator/src/test/resources/updater3.xml b/bootstrapgenerator/src/test/resources/updater3.xml index 06d2a12..764ee93 100644 --- a/bootstrapgenerator/src/test/resources/updater3.xml +++ b/bootstrapgenerator/src/test/resources/updater3.xml @@ -7,7 +7,7 @@ 1 - Test thing + Test things, like reserved words as import or others true diff --git a/bootstrapgenerator/src/test/resources/updater3.yaml b/bootstrapgenerator/src/test/resources/updater3.yaml index 79b900b..a7cedff 100644 --- a/bootstrapgenerator/src/test/resources/updater3.yaml +++ b/bootstrapgenerator/src/test/resources/updater3.yaml @@ -1,7 +1,7 @@ /hippo:configuration/hippo:update/hippo:queue/Test Updater 3: jcr:primaryType: hipposys:updaterinfo hipposys:batchsize: 1 - hipposys:description: Test thing + hipposys:description: Test things, like reserved words as import or others hipposys:dryrun: true hipposys:parameters: '{prop: val}' hipposys:query: //element(*, hippo:document) diff --git a/pom.xml b/pom.xml index fc4c700..f7031dd 100644 --- a/pom.xml +++ b/pom.xml @@ -409,7 +409,7 @@ hippo-maven2 Hippo Maven 2 - http://maven.onehippo.com/maven2/ + https://maven.onehippo.com/maven2/ false From 38b7b042d08f08824f8b7c8dd04fca3967039e9e Mon Sep 17 00:00:00 2001 From: Joost O Date: Mon, 11 Oct 2021 10:30:15 +0200 Subject: [PATCH 02/15] mark mojos threadsafe (#22) --- .../hippo/groovy/maven/GroovyToUpdaterBootstrapDefault.java | 2 +- .../openweb/hippo/groovy/maven/GroovyToUpdaterXmlBootstrap.java | 2 +- .../hippo/groovy/maven/GroovyToUpdaterYamlBootstrap.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrapDefault.java b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrapDefault.java index e095c41..194331e 100644 --- a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrapDefault.java +++ b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrapDefault.java @@ -24,7 +24,7 @@ * @deprecated since yaml and xml have their own Mojo now */ @Deprecated -@Mojo(name = "generate") +@Mojo(name = "generate", threadSafe = true) public class GroovyToUpdaterBootstrapDefault extends GroovyToUpdaterBootstrap { @Override protected ScriptProcessor getProcessorBase() { diff --git a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterXmlBootstrap.java b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterXmlBootstrap.java index 528370c..837516c 100644 --- a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterXmlBootstrap.java +++ b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterXmlBootstrap.java @@ -20,7 +20,7 @@ import nl.openweb.hippo.groovy.maven.processor.ScriptProcessor; import nl.openweb.hippo.groovy.maven.processor.ScriptProcessorXML; -@Mojo(name = "generate-xml") +@Mojo(name = "generate-xml", threadSafe = true) public class GroovyToUpdaterXmlBootstrap extends GroovyToUpdaterBootstrap { @Override protected ScriptProcessor getProcessorBase() { diff --git a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterYamlBootstrap.java b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterYamlBootstrap.java index 122edec..e6ccb13 100644 --- a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterYamlBootstrap.java +++ b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterYamlBootstrap.java @@ -21,7 +21,7 @@ import nl.openweb.hippo.groovy.maven.processor.ScriptProcessor; import nl.openweb.hippo.groovy.maven.processor.ScriptProcessorYAML; -@Mojo(name = "generate-yaml") +@Mojo(name = "generate-yaml", threadSafe = true) public class GroovyToUpdaterYamlBootstrap extends GroovyToUpdaterBootstrap { @Parameter(defaultValue = "hcm-content/configuration/update", property = "yamlContentPath") private String yamlContentPath; From 6c8c63cc820f54df166750664d98b40991eacea3 Mon Sep 17 00:00:00 2001 From: Joost O Date: Mon, 8 Nov 2021 13:57:43 +0100 Subject: [PATCH 03/15] update dependencies and major fixes (#21) * update dependencies * Add useful example to force reload cnd * Remove xml-generating support * Update some codestyle issues * Add some smartass functionality to update scripts using a json file for parameters * Improve some issues code analysis brought up * Update to new major version * Update jackrabbit version --- README.md | 21 +- annotations/pom.xml | 2 +- .../hippo/groovy/annotations/Bootstrap.java | 15 +- bootstrapgenerator/pom.xml | 6 +- .../nl/openweb/hippo/groovy/Generator.java | 23 +- .../java/nl/openweb/hippo/groovy/Marshal.java | 53 ---- .../hippo/groovy/ScriptClassFactory.java | 23 +- .../nl/openweb/hippo/groovy/XmlGenerator.java | 230 --------------- .../openweb/hippo/groovy/YamlGenerator.java | 2 +- .../openweb/hippo/groovy/model/Constants.java | 29 +- .../hippo/groovy/model/DefaultBootstrap.java | 4 +- .../openweb/hippo/groovy/model/jaxb/Node.java | 229 --------------- .../hippo/groovy/model/jaxb/Property.java | 191 ------------- .../hippo/groovy/model/jaxb/package-info.java | 25 -- .../src/test/java/GeneratorTest.java | 20 +- .../src/test/java/XmlGeneratorTest.java | 160 ----------- .../src/test/java/YamlGeneratorTest.java | 9 +- .../CleanupPermanentFormdata.groovy.content | 2 +- .../src/test/resources/hippoecm-extension.xml | 42 --- .../resulting-hippoecm-extension.xml | 267 ------------------ .../test/resources/sub-hippoecm-extension.xml | 48 ---- .../test/resources/sub/annotatestrip.groovy | 2 +- .../src/test/resources/sub/annotatestrip.xml | 80 ------ .../src/test/resources/sub/updater2.xml | 36 --- .../src/test/resources/sub/updater3.xml | 50 ---- .../resources/target/hippoecm-extension.xml | 26 -- .../test/resources/updater-noimport.groovy | 2 +- .../src/test/resources/updater.groovy | 2 +- .../src/test/resources/updater.xml | 42 --- .../src/test/resources/updater2.groovy | 2 +- .../src/test/resources/updater2.xml | 42 --- .../src/test/resources/updater3.groovy | 2 +- .../src/test/resources/updater3.xml | 42 --- .../resources/updaterdata/updater4.groovy | 2 +- .../test/resources/updaterdata/updater4.xml | 62 ---- .../resources/updaterdata/updater5.groovy | 2 +- .../test/resources/updaterdata/updater5.xml | 62 ---- .../resources/updaterdata/updater6.groovy | 2 +- .../test/resources/updaterdata/updater6.xml | 62 ---- .../resources/updaterdata/updater7.groovy | 2 +- .../test/resources/updaterdata/updater7.xml | 58 ---- mavenplugin/pom.xml | 2 +- .../maven/GroovyToUpdaterBootstrap.java | 8 +- .../GroovyToUpdaterBootstrapDefault.java | 34 --- .../maven/GroovyToUpdaterXmlBootstrap.java | 29 -- .../maven/processor/ScriptProcessor.java | 10 +- .../maven/processor/ScriptProcessorXML.java | 100 ------- .../maven/processor/ScriptProcessorYAML.java | 5 +- ...java => GroovyToUpdaterBootstrapTest.java} | 60 +--- .../groovy/maven/ScriptProcessorTest.java | 30 -- .../src/test/projects/pom-to-test-xml-2.xml | 61 ---- .../src/test/projects/pom-to-test-xml.xml | 58 ---- .../src/test/projects/pom-to-test-yaml-2.xml | 1 - .../src/test/projects/pom-to-test-yaml.xml | 3 - .../src/main/resources/hippoecm-extension.xml | 39 --- .../src/main/scripts/hippoecm-extension.xml | 23 -- .../projects/src/main/scripts/updater2.groovy | 2 +- .../target_xml/hippoecm-extension.xml | 150 ---------- .../resources/target_xml/sub/updater2.xml | 36 --- .../resources/target_xml/sub/updater3.xml | 36 --- ...he_updater_with_spaces_in_the_filename.xml | 54 ---- .../src/test/resources/target_xml/updater.xml | 38 --- .../test/resources/target_xml/updater2.xml | 42 --- .../test/resources/target_xml/updater3.xml | 33 --- .../test/resources/target_xml/updater4.xml | 54 ---- .../hippoecm-extension.xml | 150 ---------- pom.xml | 74 ++--- sampleproject/pom.xml | 4 +- .../src/main/resources/hippoecm-extension.xml | 39 --- sampleproject/src/main/scripts/cleanup.groovy | 2 +- sampleproject/src/main/scripts/cndreload.json | 8 + .../src/main/scripts/hippoecm-extension.xml | 39 --- .../src/main/scripts/parameters_updater3.json | 2 +- .../src/main/scripts/reloadcnd.groovy | 135 +++++++++ .../src/main/scripts/updater2.groovy | 2 +- updatersync/pom.xml | 4 +- .../hippo/groovy/GroovyFilesService.java | 6 +- .../hippo/groovy/GroovyFilesServiceImpl.java | 16 +- .../groovy/GroovyFilesServiceModule.java | 9 +- .../hippo/groovy/util/WatchFilesUtils.java | 20 +- .../hippo/groovy/watch/FileSystemPoller.java | 26 +- .../hippo/groovy/watch/FileSystemWatcher.java | 49 ++-- .../groovy/watch/GlobFileNameMatcher.java | 6 +- .../groovy/watch/GroovyFilesWatcher.java | 86 +++--- .../watch/GroovyFilesWatcherJcrConfig.java | 20 +- .../groovy/watch/SubDirectoriesWatcher.java | 20 +- .../resources/groovyfiles-service-module.xml | 100 ------- .../groovyfiles-service-module.yaml | 2 +- .../src/main/resources/hippoecm-extension.xml | 51 ---- .../groovy/GroovyFilesServiceImplTest.java | 11 +- .../src/test/resources/updater-ext.groovy | 2 +- .../src/test/resources/updater-script.groovy | 2 +- updatersync/src/test/resources/updater.groovy | 2 +- 93 files changed, 408 insertions(+), 3368 deletions(-) delete mode 100644 bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/Marshal.java delete mode 100644 bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/XmlGenerator.java delete mode 100644 bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/jaxb/Node.java delete mode 100644 bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/jaxb/Property.java delete mode 100644 bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/jaxb/package-info.java delete mode 100644 bootstrapgenerator/src/test/java/XmlGeneratorTest.java delete mode 100644 bootstrapgenerator/src/test/resources/hippoecm-extension.xml delete mode 100644 bootstrapgenerator/src/test/resources/resulting-hippoecm-extension.xml delete mode 100644 bootstrapgenerator/src/test/resources/sub-hippoecm-extension.xml delete mode 100644 bootstrapgenerator/src/test/resources/sub/annotatestrip.xml delete mode 100644 bootstrapgenerator/src/test/resources/sub/updater2.xml delete mode 100644 bootstrapgenerator/src/test/resources/sub/updater3.xml delete mode 100644 bootstrapgenerator/src/test/resources/target/hippoecm-extension.xml delete mode 100644 bootstrapgenerator/src/test/resources/updater.xml delete mode 100644 bootstrapgenerator/src/test/resources/updater2.xml delete mode 100644 bootstrapgenerator/src/test/resources/updater3.xml delete mode 100644 bootstrapgenerator/src/test/resources/updaterdata/updater4.xml delete mode 100644 bootstrapgenerator/src/test/resources/updaterdata/updater5.xml delete mode 100644 bootstrapgenerator/src/test/resources/updaterdata/updater6.xml delete mode 100644 bootstrapgenerator/src/test/resources/updaterdata/updater7.xml delete mode 100644 mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrapDefault.java delete mode 100644 mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterXmlBootstrap.java delete mode 100644 mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/processor/ScriptProcessorXML.java rename mavenplugin/src/test/java/nl/openweb/hippo/groovy/maven/{GroovyToUpdaterXmlBootstrapTest.java => GroovyToUpdaterBootstrapTest.java} (61%) delete mode 100644 mavenplugin/src/test/projects/pom-to-test-xml-2.xml delete mode 100644 mavenplugin/src/test/projects/pom-to-test-xml.xml delete mode 100644 mavenplugin/src/test/projects/src/main/resources/hippoecm-extension.xml delete mode 100644 mavenplugin/src/test/projects/src/main/scripts/hippoecm-extension.xml delete mode 100644 mavenplugin/src/test/resources/target_xml/hippoecm-extension.xml delete mode 100644 mavenplugin/src/test/resources/target_xml/sub/updater2.xml delete mode 100644 mavenplugin/src/test/resources/target_xml/sub/updater3.xml delete mode 100644 mavenplugin/src/test/resources/target_xml/the_updater_with_spaces_in_the_filename.xml delete mode 100644 mavenplugin/src/test/resources/target_xml/updater.xml delete mode 100644 mavenplugin/src/test/resources/target_xml/updater2.xml delete mode 100644 mavenplugin/src/test/resources/target_xml/updater3.xml delete mode 100644 mavenplugin/src/test/resources/target_xml/updater4.xml delete mode 100644 mavenplugin/src/test/resources/target_xml2_overlay/hippoecm-extension.xml delete mode 100644 sampleproject/src/main/resources/hippoecm-extension.xml create mode 100644 sampleproject/src/main/scripts/cndreload.json delete mode 100644 sampleproject/src/main/scripts/hippoecm-extension.xml create mode 100644 sampleproject/src/main/scripts/reloadcnd.groovy delete mode 100644 updatersync/src/main/resources/groovyfiles-service-module.xml delete mode 100644 updatersync/src/main/resources/hippoecm-extension.xml diff --git a/README.md b/README.md index e2a1c4b..b5d71da 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 nl.openweb.hippo.updater @@ -45,7 +44,7 @@ In the build section of the (new) module containing the groovy updater scripts, default-resources compile - generate-xml + generate-yaml @@ -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)``` @@ -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 @@ -131,15 +127,8 @@ set the system property `groovy.sync.watchedModules` in the cargo container. ``` -### Log4j +### Log4j2 Add an info logging level for nl.openweb.hippo.groovy to your development log4j configuration -```xml - - - - -``` -**Log4j2:** ```xml diff --git a/annotations/pom.xml b/annotations/pom.xml index 0775aba..f002894 100644 --- a/annotations/pom.xml +++ b/annotations/pom.xml @@ -19,7 +19,7 @@ groovy-updater nl.openweb.hippo.updater - 1.14-SNAPSHOT + 2.0-SNAPSHOT 4.0.0 diff --git a/annotations/src/main/java/nl/openweb/hippo/groovy/annotations/Bootstrap.java b/annotations/src/main/java/nl/openweb/hippo/groovy/annotations/Bootstrap.java index 6953667..59bad89 100644 --- a/annotations/src/main/java/nl/openweb/hippo/groovy/annotations/Bootstrap.java +++ b/annotations/src/main/java/nl/openweb/hippo/groovy/annotations/Bootstrap.java @@ -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) @@ -32,7 +32,7 @@ enum ContentRoot { QUEUE("queue"), REGISTRY("registry"); - private String value; + private final String value; ContentRoot(String value) { this.value = value; @@ -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 ""; } diff --git a/bootstrapgenerator/pom.xml b/bootstrapgenerator/pom.xml index 9792d53..2a59adf 100644 --- a/bootstrapgenerator/pom.xml +++ b/bootstrapgenerator/pom.xml @@ -19,7 +19,7 @@ groovy-updater nl.openweb.hippo.updater - 1.14-SNAPSHOT + 2.0-SNAPSHOT 4.0.0 @@ -69,10 +69,6 @@ jcr compile - - org.glassfish.jaxb - jaxb-runtime - org.junit.jupiter junit-jupiter-engine diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/Generator.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/Generator.java index 13ca2c6..2155b84 100644 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/Generator.java +++ b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/Generator.java @@ -41,14 +41,14 @@ public abstract class Generator { protected static final String NEWLINE = "\n"; private static final List> 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_ANNOTATIONS_SNIPPET = "(?:[\\w\\W]+[\\n|;]\\s*import [\\w\\.]+[;|\\n]+)?(?=[\\w\\W]*@[\\w\\.]*Updater)(?:([\\w\\W]*)(?=(?:(?:public )?class \\w+ extends [\\w\\W]+\\s*\\{)))"; 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 = "('.*?(? getAnnotations(final String script){ //Strip comments - String codeBlock = script.replaceAll("\\s\\/\\*[\\w\\W]*\\*\\/", StringUtils.EMPTY); + String codeBlock = script.replaceAll("\\s/\\*[\\w\\W]*\\*/", StringUtils.EMPTY); if(codeBlock.startsWith("/*")) { codeBlock = StringUtils.substringAfter(codeBlock, "*/"); } - codeBlock = codeBlock.replaceAll("\\n\\/\\/.*", StringUtils.EMPTY); + codeBlock = codeBlock.replaceAll("\\n//.*", StringUtils.EMPTY); final Matcher matcher = Pattern.compile(REGEX_ANNOTATIONS_SNIPPET).matcher(codeBlock); final List annotationStrings = new ArrayList<>(); if(matcher.find()) { @@ -98,7 +98,7 @@ public static String stripAnnotations(final String script, final boolean keepSpa result = result.replace(annotation, StringUtils.EMPTY); } for (final Class aClass : getAnnotationClasses()) { - 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); @@ -123,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); @@ -141,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) ? @@ -165,7 +158,7 @@ public static List getGroovyFiles(final File dir) { final List 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) diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/Marshal.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/Marshal.java deleted file mode 100644 index 3050f2f..0000000 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/Marshal.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2019 Open Web IT B.V. (https://www.openweb.nl/) - * - * 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. - */ - -package nl.openweb.hippo.groovy; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; - -import com.sun.xml.bind.marshaller.CharacterEscapeHandler; -import com.sun.xml.bind.marshaller.MinimumEscapeHandler; - -import nl.openweb.hippo.groovy.model.jaxb.Node; -import nl.openweb.hippo.groovy.model.jaxb.Property; - -public class Marshal { - - public static final String CDATA_START = " { - boolean cdata = new String(chars).trim().startsWith(CDATA_START); - if (cdata) { - writer.write(chars, start, length); - } else { - MinimumEscapeHandler.theInstance.escape(chars, start, length, isAttVal, writer); - } - }); - return marshaller; - } -} diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/ScriptClassFactory.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/ScriptClassFactory.java index f2a5589..dc97518 100644 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/ScriptClassFactory.java +++ b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/ScriptClassFactory.java @@ -22,6 +22,7 @@ import javax.jcr.NamespaceException; +import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.spi.NameFactory; import org.apache.jackrabbit.spi.commons.conversion.NameParser; import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl; @@ -42,19 +43,19 @@ public class ScriptClassFactory { private static final String LINE_END_WINDOWS = "\r\n"; private static final String LINE_END_LINUX = "\n"; private static final String LINE_END_MAC = "\r"; - private static final NamespaceMapping namespaceResolver = new NamespaceMapping(); - private static final NameFactory nameFactory = NameFactoryImpl.getInstance(); - private static GroovyClassLoader groovyClassLoader = new GroovyClassLoader(); + private static final NamespaceMapping NAMESPACE_MAPPING = new NamespaceMapping(); + private static final NameFactory NAME_FACTORY = NameFactoryImpl.getInstance(); + private static final GroovyClassLoader GROOVY_CLASS_LOADER = new GroovyClassLoader(); private ScriptClassFactory() { //No instantiating of this class } - private static NamespaceMapping getNamespaceResolver() throws NamespaceException { - if (!namespaceResolver.hasPrefix("")) { - namespaceResolver.setMapping("", ""); + private static NamespaceMapping getNamespaceMapping() throws NamespaceException { + if (!NAMESPACE_MAPPING.hasPrefix(StringUtils.EMPTY)) { + NAMESPACE_MAPPING.setMapping(StringUtils.EMPTY, StringUtils.EMPTY); } - return namespaceResolver; + return NAMESPACE_MAPPING; } private static void validateScriptClass(final ScriptClass scriptClass) { @@ -64,7 +65,7 @@ private static void validateScriptClass(final ScriptClass scriptClass) { final String name = scriptClass.getUpdater().name(); try { - NameParser.parse(name, getNamespaceResolver(), nameFactory); + NameParser.parse(name, getNamespaceMapping(), NAME_FACTORY); } catch (Exception e) { throw new ScriptParseException("Error parsing the updater name for: " + scriptClass.getFile().getAbsolutePath(), e); } @@ -88,7 +89,7 @@ public static ScriptClass getInterpretingClass(final File file) { * @return a fake class with the Bootstrap and Updater annotations */ public static ScriptClass getInterpretingClass(final File file, final boolean keepLineCount) { - groovyClassLoader.clearCache(); + GROOVY_CLASS_LOADER.clearCache(); String script; try { script = readFileEnsuringLinuxLineEnding(file); @@ -96,9 +97,9 @@ public static ScriptClass getInterpretingClass(final File file, final boolean ke String imports = getAnnotationClasses().stream() .map(clazz -> "import " + clazz.getCanonicalName() + ";" + LINE_END_LINUX) .collect(joining()); - String interpretCode = imports + getAnnotations(script).stream().collect(joining(LINE_END_LINUX)) + LINE_END_LINUX + "class InterpretClass {}"; + String interpretCode = imports + String.join(LINE_END_LINUX, getAnnotations(script)) + LINE_END_LINUX + "class InterpretClass {}"; script = stripAnnotations(script, keepLineCount); - final ScriptClass scriptClass = new ScriptClass(file, groovyClassLoader.parseClass(interpretCode), script); + final ScriptClass scriptClass = new ScriptClass(file, GROOVY_CLASS_LOADER.parseClass(interpretCode), script); validateScriptClass(scriptClass); return scriptClass; } catch (IOException e) { diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/XmlGenerator.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/XmlGenerator.java deleted file mode 100644 index 13cada0..0000000 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/XmlGenerator.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright 2019 Open Web IT B.V. (https://www.openweb.nl/) - * - * 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. - */ - -package nl.openweb.hippo.groovy; - -import java.io.File; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Stream; - -import javax.xml.bind.JAXB; - -import org.apache.commons.lang3.StringUtils; - -import nl.openweb.hippo.groovy.annotations.Bootstrap; -import nl.openweb.hippo.groovy.annotations.Updater; -import nl.openweb.hippo.groovy.model.Constants; -import nl.openweb.hippo.groovy.model.Constants.ValueType; -import nl.openweb.hippo.groovy.model.ScriptClass; -import nl.openweb.hippo.groovy.model.jaxb.Node; -import nl.openweb.hippo.groovy.model.jaxb.Property; -import static nl.openweb.hippo.groovy.Marshal.CDATA_START; -import static nl.openweb.hippo.groovy.model.Constants.Files.ECM_EXTENSIONS_NAME; -import static nl.openweb.hippo.groovy.model.Constants.Files.XML_EXTENSION; -import static nl.openweb.hippo.groovy.model.Constants.NodeType.HIPPO_INITIALIZEFOLDER; -import static nl.openweb.hippo.groovy.model.Constants.NodeType.HIPPO_INITIALIZEITEM; -import static nl.openweb.hippo.groovy.model.Constants.PropertyName.HIPPOSYS_SCRIPT; -import static nl.openweb.hippo.groovy.model.Constants.PropertyName.HIPPO_CONTENTRESOURCE; -import static nl.openweb.hippo.groovy.model.Constants.PropertyName.HIPPO_CONTENTROOT; -import static nl.openweb.hippo.groovy.model.Constants.PropertyName.HIPPO_RELOADONSTARTUP; -import static nl.openweb.hippo.groovy.model.Constants.PropertyName.HIPPO_SEQUENCE; -import static nl.openweb.hippo.groovy.model.Constants.PropertyName.HIPPO_VERSION; -import static nl.openweb.hippo.groovy.model.Constants.PropertyName.JCR_MIXIN_TYPES; -import static nl.openweb.hippo.groovy.model.Constants.PropertyName.JCR_PRIMARY_TYPE; - -/** - * Generator to parse a groovy file to the bootstrap xmls - */ -public final class XmlGenerator extends Generator { - - public static final String CDATA_END = "]]>"; - public static final String SEPARATOR = "/"; - - private XmlGenerator() { - super(); - } - - /** - * Parse file to updater node - * - * @param sourceDir the directory to read the resources from - * @param script the script to use for source - * @return Node object representing the groovy updater to marshall to xml - */ - public static Node getUpdateScriptNode(final File sourceDir, final ScriptClass script) { - final Updater updater = script.getUpdater(); - final Node rootnode = XmlGenerator.createNode(updater.name()); - final List properties = rootnode.getNodeOrProperty(); - final Map propertiesForUpdater = PropertyCollector.getPropertiesForUpdater(script, sourceDir); - for (Map.Entry entry : propertiesForUpdater.entrySet()) { - String valueType = getValueType(entry); - Object value = entry.getValue(); - if (HIPPOSYS_SCRIPT.equals(entry.getKey())) { - value = wrap(value.toString()); - } - properties.add(createProperty(entry.getKey(), value, valueType)); - } - return rootnode; - } - - private static String getValueType(final Map.Entry entry) { - if (JCR_PRIMARY_TYPE.equals(entry.getKey()) || JCR_MIXIN_TYPES.equals(entry.getKey())) { - return ValueType.NAME; - } else if (entry.getValue() instanceof Long) { - return ValueType.LONG; - } else if (entry.getValue() instanceof Boolean) { - return ValueType.BOOLEAN; - } - return ValueType.STRING; - } - - private static void addStringPropertyIfNotEmpty(final List properties, final String name, final String value) { - if (StringUtils.isNotBlank(value)) { - properties.add(createProperty(name, value, ValueType.STRING)); - } - } - - /** - * Wrap string with empty lines - * - * @param content - * @return the content starting and ending with a newline character - *

- * "" - */ - private static String wrap(final String content) { - return CDATA_START + NEWLINE + content + NEWLINE + CDATA_END; - } - - public static Property createProperty(final String name, final Object value, final String type) { - final Property property = new Property(); - property.setName(name); - property.setType(type); - addValueToProperty(property, value); - return property; - } - - public static Property addValueToProperty(final Property property, final Object value) { - if(value instanceof List) { - List list = (List) value; - for (Object objectValue : list) { - property.getValue().add(objectValue.toString()); - } - property.setMultiple(true); - return property; - } - property.getValue().add(value.toString()); - return property; - } - - /** - * Generate files to generate a node model for the hippoecm-extension.xml - * - * @param sourcePath sourcepath of groovy files - * @param targetDir the target where the ecmExtensions from resources would be - * @param scriptClasses groovy files, need to be relative to the source path - * @param updaterNamePrefix prefix for the initialize items nodes @return Node object representing the - * hippoecm-extension to marshall to xml - * @return the Node object for the ecm-extensions - */ - public static Node getEcmExtensionNode(final File sourcePath, final File targetDir, final List scriptClasses, final String updaterNamePrefix) { - final List properties; - final Node rootnode; - final Node ecmExtensionsScriptNode = getExistingEcmExtensions(sourcePath); - final Node ecmExtensionTargetNode = getExistingEcmExtensions(targetDir); - - rootnode = createNode(Constants.NodeType.HIPPO_INITIALIZE); - properties = rootnode.getNodeOrProperty(); - properties.add(createProperty(JCR_PRIMARY_TYPE, HIPPO_INITIALIZEFOLDER, ValueType.STRING)); - - final Stream sourceStream = Stream.concat(ecmExtensionsScriptNode == null ? Stream.empty() : ecmExtensionsScriptNode.getSubnodes().stream(), - ecmExtensionTargetNode == null ? Stream.empty() : ecmExtensionTargetNode.getSubnodes().stream()); - - Stream.concat(sourceStream, scriptClasses.stream().map(script -> createInitializeItem(sourcePath, script, updaterNamePrefix)).filter(Objects::nonNull)) - .sorted(Comparator.comparingDouble(node -> Double.valueOf(node.getPropertyByName(HIPPO_SEQUENCE).getSingleValue()))) - .distinct() - .forEach(properties::add); - return rootnode; - } - - private static Node getExistingEcmExtensions(final File sourcePath) { - final File extensions = new File(sourcePath, ECM_EXTENSIONS_NAME); - if (extensions.exists()) { - return JAXB.unmarshal(extensions, Node.class); - } - return null; - } - - /** - * Create initialize item for the given file - * - * @param sourcePath sourcepath of groovy files - * @param scriptClass groovy files, need to be relative to the source path - * @param namePrefix prefix for the initialize items nodes - * @return Node object representing the initializeitem node for the hippoecm-extension to marshall to xml - */ - private static Node createInitializeItem(final File sourcePath, final ScriptClass scriptClass, final String namePrefix) { - final Bootstrap bootstrap = scriptClass.getBootstrap(true); - - final String resource = getUpdateScriptXmlFilename(sourcePath, scriptClass.getFile()); - final Node initNode = createNode(namePrefix + resource); - final List properties = initNode.getNodeOrProperty(); - - Bootstrap.ContentRoot contentroot = getContentroot(bootstrap); - - properties.add(createProperty(JCR_PRIMARY_TYPE, HIPPO_INITIALIZEITEM, ValueType.NAME)); - addStringPropertyIfNotEmpty(properties, HIPPO_CONTENTRESOURCE, resource); - properties.add(createProperty(HIPPO_CONTENTROOT, getUpdatePath(contentroot), ValueType.STRING)); - properties.add(createProperty(HIPPO_SEQUENCE, bootstrap.sequence(), ValueType.DOUBLE)); - if (bootstrap.reload()) { - properties.add(createProperty(HIPPO_RELOADONSTARTUP, bootstrap.reload(), ValueType.BOOLEAN)); - } - addStringPropertyIfNotEmpty(properties, HIPPO_VERSION, bootstrap.version()); - return initNode; - } - - /** - * Get update script xml filename - * - * @param basePath path to make returning path relative to - * @param file File object for the groovy script - * @return the path, relative to the basePath, converted \ to /, with xml extension - */ - public static String getUpdateScriptXmlFilename(final File basePath, final File file) { - final String fileName = file.getAbsolutePath().substring(basePath.getAbsolutePath().length() + 1); - return sanitizeFileName(fileName) + XML_EXTENSION; - } - - /** - * Utility method to create a Node with given name - * - * @param name name for the node - * @return Node with given name - */ - public static Node createNode(final String name) { - final Node node = new Node(); - String initName = name; - if (initName.endsWith(XML_EXTENSION)) { - initName = initName.substring(0, initName.length() - XML_EXTENSION.length()); - } - initName = initName.replaceAll(SEPARATOR, "-"); - node.setName(initName); - return node; - } -} diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/YamlGenerator.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/YamlGenerator.java index d5558ef..66a4eed 100644 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/YamlGenerator.java +++ b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/YamlGenerator.java @@ -46,7 +46,7 @@ protected YamlGenerator() { * * @param sourceDir the directory to read the resources from * @param scriptClass class to use for source - * @return Node object representing the groovy updater to marshall to xml + * @return Mapping object representing the groovy updater to write out as yaml */ public static Map> getUpdateYamlScript(final File sourceDir, final ScriptClass scriptClass) { Map properties = PropertyCollector.getPropertiesForUpdater(scriptClass, sourceDir); diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/Constants.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/Constants.java index feb27b5..0d64a13 100644 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/Constants.java +++ b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/Constants.java @@ -17,25 +17,23 @@ package nl.openweb.hippo.groovy.model; /** - * Constants for generating bootstrap xml + * Constants for generating bootstrap files */ public final class Constants { private Constants() { //no public construction } - public final class Files { + public static final class Files { private Files() { //no public construction } public static final String GROOVY_EXTENSION = ".groovy"; - public static final String XML_EXTENSION = ".xml"; public static final String YAML_EXTENSION = ".yaml"; - public static final String ECM_EXTENSIONS_NAME = "hippoecm-extension.xml"; } - public final class PropertyName { + public static final class PropertyName { private PropertyName() { //no public construction } @@ -50,33 +48,14 @@ private PropertyName() { public static final String HIPPOSYS_THROTTLE = "hipposys:throttle"; public static final String HIPPOSYS_DESCRIPTION = "hipposys:description"; public static final String HIPPOSYS_PATH = "hipposys:path"; - public static final String HIPPO_SEQUENCE = "hippo:sequence"; - public static final String HIPPO_CONTENTRESOURCE = "hippo:contentresource"; - public static final String HIPPO_CONTENTROOT = "hippo:contentroot"; - public static final String HIPPO_RELOADONSTARTUP = "hippo:reloadonstartup"; - public static final String HIPPO_VERSION = "hippo:version"; } - public final class NodeType { + public static final class NodeType { private NodeType() { //no public construction } public static final String HIPPOSYS_UPDATERINFO = "hipposys:updaterinfo"; - public static final String HIPPO_INITIALIZEITEM = "hippo:initializeitem"; - public static final String HIPPO_INITIALIZE = "hippo:initialize"; - public static final String HIPPO_INITIALIZEFOLDER = "hippo:initializefolder"; - } - - public final class ValueType { - private ValueType() { - //no public construction - } - public static final String STRING = "String"; - public static final String NAME = "Name"; - public static final String LONG = "Long"; - public static final String BOOLEAN = "Boolean"; - public static final String DOUBLE = "Double"; } } diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/DefaultBootstrap.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/DefaultBootstrap.java index 29894dd..fd453d9 100644 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/DefaultBootstrap.java +++ b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/DefaultBootstrap.java @@ -28,9 +28,9 @@ private DefaultBootstrap() { //no instantiating } - private static final Bootstrap bootstrap = DefaultBootstrap.class.getAnnotation(Bootstrap.class); + private static final Bootstrap BOOTSTRAP = DefaultBootstrap.class.getAnnotation(Bootstrap.class); public static Bootstrap getBootstrap() { - return bootstrap; + return BOOTSTRAP; } } diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/jaxb/Node.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/jaxb/Node.java deleted file mode 100644 index 74f5831..0000000 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/jaxb/Node.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright 2019 Open Web IT B.V. (https://www.openweb.nl/) - * - * 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. - */ - -package nl.openweb.hippo.groovy.model.jaxb; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElements; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlSchemaType; -import javax.xml.bind.annotation.XmlTransient; -import javax.xml.bind.annotation.XmlType; -import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - -import nl.openweb.hippo.groovy.model.Constants; - -/** - *

- * Java class for anonymous complex type. - *

- *

- * The following schema fragment specifies the expected content contained within this class. - *

- *

- * <complexType>
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <choice maxOccurs="unbounded" minOccurs="0">
- *         <element ref="{http://www.jcp.org/jcr/sv/1.0}node"/>
- *         <element ref="{http://www.jcp.org/jcr/sv/1.0}property"/>
- *       </choice>
- *       <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}NMTOKEN" />
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
- */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = {"nodeOrProperty"}) -@XmlRootElement(name = "node") -public class Node { - - @XmlElements({@XmlElement(name = "node", type = Node.class), @XmlElement(name = "property", type = Property.class)}) - protected List nodeOrProperty; - - @XmlTransient - protected List subnodes; - @XmlTransient - protected List properties; - - @XmlAttribute(name = "name", namespace = "http://www.jcp.org/jcr/sv/1.0", required = true) - @XmlJavaTypeAdapter(CollapsedStringAdapter.class) - @XmlSchemaType(name = "NMTOKEN") - protected String name; - - /** - * Gets the value of the nodeOrProperty property. - *

- * This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to - * the returned list will be present inside the JAXB object. This is why there is not a - * set method for the nodeOrProperty property. - *

- *

- * For example, to add a new item, do as follows: - *

- *
-     * getNodeOrProperty().add(newItem);
-     * 
- *

- * Objects of the following type(s) are allowed in the list {@link Node } {@link Property } - *

- * - * @return List of nodes and properties - */ - public List getNodeOrProperty() { - if (nodeOrProperty == null) { - nodeOrProperty = new ArrayList<>(); - } - return this.nodeOrProperty; - } - - /** - * @param nodeName Name of a subnode to be fetched. - * @return the fist subnode with of the given name and null if there is not any node with this name - */ - public Node getSubnodeByName(String nodeName) { - Node result = null; - List subnodesList = getSubnodesByName(nodeName); - if (!subnodesList.isEmpty()) { - result = subnodesList.get(0); - } - return result; - } - - /** - * @param nodeName Name of a subnodes to be fetched. - * @return returns a list of all subnodes of the given name and an empty list if there is not any. - */ - public List getSubnodesByName(String nodeName) { - List result = new ArrayList<>(); - List subnodesList = getSubnodes(); - for (Node node : subnodesList) { - if (nodeName.equals(node.getName())) { - result.add(node); - } - } - return result; - } - - public List getSubnodesByType(String nodeType) { - List result = new ArrayList<>(); - List subnodesList = getSubnodes(); - for (Node node : subnodesList) { - Property nodeTypeProperty = node.getPropertyByName(Constants.PropertyName.JCR_PRIMARY_TYPE); - if (nodeType.equals(nodeTypeProperty.getSingleValue())) { - result.add(node); - } - } - return result; - } - - public Property getPropertyByName(String propertyName) { - Property result = null; - List propertiesList = getProperties(); - for (Property property : propertiesList) { - if (propertyName.equals(property.getName())) { - result = property; - break; - } - } - return result; - } - - public List getSubnodes() { - if (subnodes == null) { - subnodes = new ArrayList<>(); - List list = getNodeOrProperty(); - for (Object object : list) { - if (object instanceof Node) { - subnodes.add((Node) object); - } - } - } - return this.subnodes; - } - - public List getProperties() { - if (properties == null) { - properties = new ArrayList<>(); - List list = getNodeOrProperty(); - for (Object object : list) { - if (object instanceof Property) { - properties.add((Property) object); - } - } - } - return this.properties; - } - - /** - * Gets the value of the name property. - * - * @return possible object is {@link String } - */ - public String getName() { - return name; - } - - /** - * Sets the value of the name property. - * - * @param value allowed object is {@link String } - */ - public void setName(String value) { - this.name = value; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - final Node node = (Node) o; - - return new EqualsBuilder() - .append(nodeOrProperty, node.nodeOrProperty) - .append(subnodes, node.subnodes) - .append(properties, node.properties) - .append(name, node.name) - .isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(nodeOrProperty) - .append(subnodes) - .append(properties) - .append(name) - .toHashCode(); - } -} diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/jaxb/Property.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/jaxb/Property.java deleted file mode 100644 index 1e066ac..0000000 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/jaxb/Property.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright 2019 Open Web IT B.V. (https://www.openweb.nl/) - * - * 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. - */ - -package nl.openweb.hippo.groovy.model.jaxb; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlSchemaType; -import javax.xml.bind.annotation.XmlType; -import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - -/** - *

- * Java class for anonymous complex type. - *

- *

- * The following schema fragment specifies the expected content contained within this class. - *

- *

- * <complexType>
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element ref="{http://www.jcp.org/jcr/sv/1.0}value" maxOccurs="unbounded" minOccurs="0"/>
- *       </sequence>
- *       <attribute name="multiple" type="{http://www.w3.org/2001/XMLSchema}boolean" />
- *       <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}NMTOKEN" />
- *       <attribute name="type" use="required" type="{http://www.w3.org/2001/XMLSchema}NCName" />
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
- */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = {"value"}) -@XmlRootElement(name = "property") -public class Property { - - protected List value; - @XmlAttribute(name = "multiple", namespace = "http://www.jcp.org/jcr/sv/1.0") - protected Boolean multiple; - @XmlAttribute(name = "name", namespace = "http://www.jcp.org/jcr/sv/1.0", required = true) - @XmlJavaTypeAdapter(CollapsedStringAdapter.class) - @XmlSchemaType(name = "NMTOKEN") - protected String name; - @XmlAttribute(name = "type", namespace = "http://www.jcp.org/jcr/sv/1.0", required = true) - @XmlJavaTypeAdapter(CollapsedStringAdapter.class) - @XmlSchemaType(name = "NCName") - protected String type; - - /** - * Gets the value of the value property. - *

- *

- * This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to - * the returned list will be present inside the JAXB object. This is why there is not a - * set method for the value property. - *

- *

- * For example, to add a new item, do as follows: - *

- *

-     * getValue().add(newItem);
-     * 
- *

- *

- *

- * Objects of the following type(s) are allowed in the list {@link String } - */ - public List getValue() { - if (value == null) { - value = new ArrayList<>(); - } - return this.value; - } - - public String getSingleValue() { - String result = null; - List values = getValue(); - if (!values.isEmpty()) { - result = values.get(0); - } - return result; - } - - /** - * Gets the value of the multiple property. - * - * @return possible object is {@link Boolean } - */ - public Boolean isMultiple() { - return multiple; - } - - /** - * Sets the value of the multiple property. - * - * @param value allowed object is {@link Boolean } - */ - public void setMultiple(Boolean value) { - this.multiple = value; - } - - /** - * Gets the value of the name property. - * - * @return possible object is {@link String } - */ - public String getName() { - return name; - } - - /** - * Sets the value of the name property. - * - * @param value allowed object is {@link String } - */ - public void setName(String value) { - this.name = value; - } - - /** - * Gets the value of the type property. - * - * @return possible object is {@link String } - */ - public String getType() { - return type; - } - - /** - * Sets the value of the type property. - * - * @param value allowed object is {@link String } - */ - public void setType(String value) { - this.type = value; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - final Property property = (Property) o; - - return new EqualsBuilder() - .append(value, property.value) - .append(multiple, property.multiple) - .append(name, property.name) - .append(type, property.type) - .isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(value) - .append(multiple) - .append(name) - .append(type) - .toHashCode(); - } -} diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/jaxb/package-info.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/jaxb/package-info.java deleted file mode 100644 index ededfdc..0000000 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/jaxb/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2019 Open Web IT B.V. (https://www.openweb.nl/) - * - * 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. - */ - -@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.jcp.org/jcr/sv/1.0", - elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, - xmlns = { - @XmlNs(prefix = "sv", namespaceURI = "http://www.jcp.org/jcr/sv/1.0") - } -) -package nl.openweb.hippo.groovy.model.jaxb; - -import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/bootstrapgenerator/src/test/java/GeneratorTest.java b/bootstrapgenerator/src/test/java/GeneratorTest.java index 2aaf524..9881566 100644 --- a/bootstrapgenerator/src/test/java/GeneratorTest.java +++ b/bootstrapgenerator/src/test/java/GeneratorTest.java @@ -35,13 +35,15 @@ public class GeneratorTest { + public static final String EMPTY_STRING = ""; + @BeforeAll public static void setup() { Generator.setDefaultContentRoot(Bootstrap.ContentRoot.QUEUE); } @Test - public void extractAnnotation() throws URISyntaxException, IOException { + void extractAnnotation() throws URISyntaxException, IOException { URL testfileUrl = getClass().getResource("updater.groovy"); URL testfileUrl2 = getClass().getResource("updater-noimport.groovy"); @@ -67,24 +69,24 @@ public void extractAnnotation() throws URISyntaxException, IOException { String updaterExpected = "@Updater(name = \"Test Updater\",\n" + " xpath = \"//element(*, hippo:document)\",\n" + " description=" + descriptionExample + ", path = \"\", parameters = \" \")"; - String bootstrapExpected = "@Bootstrap(reload = true, sequence = 99999.0d)"; - String bootstrapFull2 = "@nl.openweb.hippo.groovy.annotations.Bootstrap(sequence = 99999.0d)"; + String bootstrapExpected = "@Bootstrap(reload = true)"; + String bootstrapFull2 = "@nl.openweb.hippo.groovy.annotations.Bootstrap"; String updaterFull2 = "@nl.openweb.hippo.groovy.annotations.Updater(name = \"Test Updater noimport\",\n" + " xpath = \"//element(*, hippo:document)\",\n" + " description=\"\", path = \"\", parameters = \" \")"; assertEquals(updaterExpected, updater); assertEquals(bootstrapExpected, bootstrap); - assertEquals("", fullUpdater); - assertEquals("", fullBootstrap); - assertEquals("", updater2); - assertEquals("", bootstrap2); + assertEquals(EMPTY_STRING, fullUpdater); + assertEquals(EMPTY_STRING, fullBootstrap); + assertEquals(EMPTY_STRING, updater2); + assertEquals(EMPTY_STRING, bootstrap2); assertEquals(updaterFull2, fullUpdater2); assertEquals(bootstrapFull2, fullBootstrap2); } @Test - public void getAnnotations() throws URISyntaxException, IOException { + void getAnnotations() throws URISyntaxException, IOException { URL testfileUrl = getClass().getResource("updater.groovy"); URL testfileUrl2 = getClass().getResource("updater-noimport.groovy"); @@ -99,7 +101,7 @@ public void getAnnotations() throws URISyntaxException, IOException { } @Test - public void getAnnotationClassesTest() throws Exception { + void getAnnotationClassesTest() { List> classes = getAnnotationClasses(); assertEquals(4, classes.size()); diff --git a/bootstrapgenerator/src/test/java/XmlGeneratorTest.java b/bootstrapgenerator/src/test/java/XmlGeneratorTest.java deleted file mode 100644 index 5ea39b5..0000000 --- a/bootstrapgenerator/src/test/java/XmlGeneratorTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2019 Open Web IT B.V. (https://www.openweb.nl/) - * - * 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. - */ - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.StringWriter; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Files; -import java.util.List; - -import javax.xml.bind.JAXBException; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import nl.openweb.hippo.groovy.Generator; -import nl.openweb.hippo.groovy.ScriptClassFactory; -import nl.openweb.hippo.groovy.XmlGenerator; -import nl.openweb.hippo.groovy.annotations.Bootstrap; -import nl.openweb.hippo.groovy.model.ScriptClass; -import nl.openweb.hippo.groovy.model.jaxb.Node; -import static nl.openweb.hippo.groovy.Marshal.getMarshaller; -import static nl.openweb.hippo.groovy.ScriptClassFactory.getInterpretingClass; -import static nl.openweb.hippo.groovy.ScriptClassFactory.readFileEnsuringLinuxLineEnding; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class XmlGeneratorTest { - - final File sourceDir = new File(getClass().getResource("/").toURI()); - - public XmlGeneratorTest() throws URISyntaxException { - } - - @BeforeEach - public void setup() { - Generator.setDefaultContentRoot(Bootstrap.ContentRoot.QUEUE); - } - - @Test - public void testScrubbingAnnotations() throws JAXBException, IOException, URISyntaxException { - checkGeneration("sub/annotatestrip"); - } - - @Test - public void testUpdatescriptCreating() throws URISyntaxException, IOException, JAXBException { - checkGeneration("updater"); - checkGeneration("updater2"); - checkGeneration("updater3"); - checkGeneration("sub/updater2"); - checkGeneration("sub/updater3"); - checkGeneration("updaterdata/updater4"); - checkGeneration("updaterdata/updater5"); - checkGeneration("updaterdata/updater6"); - checkGeneration("updaterdata/updater7"); - } - - private void checkGeneration(String name) throws URISyntaxException, IOException, JAXBException { - URL testfileUrl = getClass().getResource(name + ".groovy"); - URL testfileResultUrl = getClass().getResource(name + ".xml"); - - File file = new File(testfileUrl.toURI()); - File resultFile = new File(testfileResultUrl.toURI()); - - Utilities.enforceWindowsFileEndings(file); - - Node updateScriptNode = XmlGenerator.getUpdateScriptNode(sourceDir, getInterpretingClass(file)); - StringWriter writer = new StringWriter(); - - getMarshaller().marshal(updateScriptNode, writer); - final String xml = writer.toString(); - - String expectedContent = readFileEnsuringLinuxLineEnding(resultFile); - assertEquals(expectedContent, xml, "failed xml parsing of " + name); - } - - @Test - public void generateHippoEcmExtensions() throws URISyntaxException, IOException, JAXBException { - URI resourceURI = getClass().getResource("").toURI(); - File root = new File(resourceURI); - List scriptClasses = ScriptClassFactory.getScriptClasses(root); - Node node = XmlGenerator.getEcmExtensionNode(root, new File(root, "target"), scriptClasses, "my-updater-prefix-"); - - StringWriter writer = new StringWriter(); - - getMarshaller().marshal(node, writer); - final String xml = writer.toString(); - URL testfileResultUrl = getClass().getResource("resulting-hippoecm-extension.xml"); - File resultFile = new File(testfileResultUrl.toURI()); - - String expectedContent = readFileEnsuringLinuxLineEnding(resultFile); - assertEquals(expectedContent, xml); - } - - @Test - public void generateNewHippoEcmExtensions() throws URISyntaxException, IOException, JAXBException { - URI resourceURI = getClass().getResource("sub").toURI(); - File root = new File(resourceURI); - List scriptClasses = ScriptClassFactory.getScriptClasses(root); - Node node = XmlGenerator.getEcmExtensionNode(root, new File(root, "target"), scriptClasses, "my-updater-prefix-"); - - StringWriter writer = new StringWriter(); - - getMarshaller().marshal(node, writer); - final String xml = writer.toString(); - URL testfileResultUrl = getClass().getResource("sub-hippoecm-extension.xml"); - File resultFile = new File(testfileResultUrl.toURI()); - - String expectedContent = readFileEnsuringLinuxLineEnding(resultFile); - assertEquals(expectedContent, xml); - - // Do it again, multiple runs shouldn't generate duplicates - File intermediate = Files.createTempDirectory("test").toFile(); - FileWriter fileWriter = new FileWriter(new File(intermediate, "hippoecm-extension.xml")); - getMarshaller().marshal(node, fileWriter); - - Node node2 = XmlGenerator.getEcmExtensionNode(root, intermediate, scriptClasses, "my-updater-prefix-"); - StringWriter writer2 = new StringWriter(); - intermediate.delete(); - getMarshaller().marshal(node2, writer2); - final String xml2 = writer2.toString(); - - assertEquals(xml, xml2); - } - - @Test - public void checkEcmExtensionGeneration() throws URISyntaxException, JAXBException, IOException, ClassNotFoundException { - Generator.setDefaultContentRoot(Bootstrap.ContentRoot.REGISTRY); - URI resourceURI = getClass().getResource("sub").toURI(); - File root = new File(resourceURI); - List scriptClasses = ScriptClassFactory.getScriptClasses(root); - Node node = XmlGenerator.getEcmExtensionNode(root, new File(root, "target"), scriptClasses, "my-updater-prefix-"); - - StringWriter writer = new StringWriter(); - - getMarshaller().marshal(node, writer); - final String xml = writer.toString(); - URL testfileResultUrl = getClass().getResource("sub-hippoecm-extension.xml"); - File resultFile = new File(testfileResultUrl.toURI()); - - String unExpectedContent = readFileEnsuringLinuxLineEnding(resultFile); - assertNotEquals(unExpectedContent, xml); - } -} diff --git a/bootstrapgenerator/src/test/java/YamlGeneratorTest.java b/bootstrapgenerator/src/test/java/YamlGeneratorTest.java index 1fd825a..df10d8b 100644 --- a/bootstrapgenerator/src/test/java/YamlGeneratorTest.java +++ b/bootstrapgenerator/src/test/java/YamlGeneratorTest.java @@ -19,7 +19,6 @@ import java.net.URISyntaxException; import java.net.URL; -import javax.xml.bind.JAXBException; import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.BeforeEach; @@ -47,12 +46,12 @@ public void setup() { } @Test - public void testScrubbingAnnotations() throws JAXBException, IOException, URISyntaxException { + public void testScrubbingAnnotations() throws IOException, URISyntaxException { checkGeneration("sub/annotatestrip"); } @Test - public void testUpdatescriptCreating() throws URISyntaxException, IOException, JAXBException { + public void testUpdatescriptCreating() throws URISyntaxException, IOException { checkGeneration("updater"); checkGeneration("updater2"); checkGeneration("updater3"); @@ -64,7 +63,7 @@ public void testUpdatescriptCreating() throws URISyntaxException, IOException, J checkGeneration("updaterdata/updater7"); } - private void checkGeneration(String name) throws URISyntaxException, IOException, JAXBException { + private void checkGeneration(String name) throws URISyntaxException, IOException { URL testfileUrl = getClass().getResource(name + ".groovy"); URL testfileResultUrlYaml = getClass().getResource(name + ".yaml"); @@ -80,7 +79,7 @@ private void checkGeneration(String name) throws URISyntaxException, IOException } @Test - public void checkDefaultingContentRootYamlFile() throws URISyntaxException, IOException, JAXBException { + public void checkDefaultingContentRootYamlFile() throws URISyntaxException, IOException { Generator.setDefaultContentRoot(Bootstrap.ContentRoot.REGISTRY); URL testfileUrl = getClass().getResource("updater.groovy"); URL testfileResultUrlYaml = getClass().getResource("updater.yaml"); diff --git a/bootstrapgenerator/src/test/resources/edge-cases/CleanupPermanentFormdata.groovy.content b/bootstrapgenerator/src/test/resources/edge-cases/CleanupPermanentFormdata.groovy.content index f1def83..bc5fc37 100644 --- a/bootstrapgenerator/src/test/resources/edge-cases/CleanupPermanentFormdata.groovy.content +++ b/bootstrapgenerator/src/test/resources/edge-cases/CleanupPermanentFormdata.groovy.content @@ -23,7 +23,7 @@ import org.onehippo.repository.update.BaseNodeUpdateVisitor import javax.jcr.Node import javax.jcr.RepositoryException -@Bootstrap(sequence = 32000d, contentroot = Bootstrap.ContentRoot.REGISTRY) +@Bootstrap(contentroot = Bootstrap.ContentRoot.REGISTRY) @Updater(name = 'Cleanup \'permanent\' formdata', xpath = "//formdata/permanent/*//element(*,hst:formdata)[@hst:creationtime - - - hippo:initializefolder - - - - hippo:initializeitem - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 30900.02 - - - true - - - - - hippo:initializeitem - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.02 - - - true - - - - - diff --git a/bootstrapgenerator/src/test/resources/resulting-hippoecm-extension.xml b/bootstrapgenerator/src/test/resources/resulting-hippoecm-extension.xml deleted file mode 100644 index eaa07b5..0000000 --- a/bootstrapgenerator/src/test/resources/resulting-hippoecm-extension.xml +++ /dev/null @@ -1,267 +0,0 @@ - - - - hippo:initializefolder - - - - hippo:initializeitem - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 30900.01 - - - true - - - - - hippo:initializeitem - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 30900.02 - - - true - - - - - hippo:initializeitem - - - the_updater_with_spaces_in_the_filename.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - true - - - - - hippo:initializeitem - - - updater-noimport.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - - - hippo:initializeitem - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - true - - - - - hippo:initializeitem - - - updater3.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - true - - - 2 - - - - - hippo:initializeitem - - - sub/updater2.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - - - hippo:initializeitem - - - sub/updater3.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - - - hippo:initializeitem - - - updaterdata/updater4.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - true - - - 2 - - - - - hippo:initializeitem - - - updaterdata/updater5.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - true - - - 2 - - - - - hippo:initializeitem - - - updaterdata/updater6.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - true - - - 2 - - - - - hippo:initializeitem - - - updaterdata/updater7.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - true - - - 2 - - - - - hippo:initializeitem - - - sub/annotatestrip.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.00005 - - - - - hippo:initializeitem - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.02 - - - true - - - - - hippo:initializeitem - - - updater2.xml - - - /hippo:configuration/hippo:update/hippo:registry - - - 99999.1 - - - true - - - 1.6 - - - diff --git a/bootstrapgenerator/src/test/resources/sub-hippoecm-extension.xml b/bootstrapgenerator/src/test/resources/sub-hippoecm-extension.xml deleted file mode 100644 index fec870c..0000000 --- a/bootstrapgenerator/src/test/resources/sub-hippoecm-extension.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - hippo:initializefolder - - - - hippo:initializeitem - - - updater2.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - - - hippo:initializeitem - - - updater3.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - - - hippo:initializeitem - - - annotatestrip.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.00005 - - - diff --git a/bootstrapgenerator/src/test/resources/sub/annotatestrip.groovy b/bootstrapgenerator/src/test/resources/sub/annotatestrip.groovy index ace0ae2..2c2dd3a 100644 --- a/bootstrapgenerator/src/test/resources/sub/annotatestrip.groovy +++ b/bootstrapgenerator/src/test/resources/sub/annotatestrip.groovy @@ -11,7 +11,7 @@ import javax.jcr.RepositoryException import javax.jcr.Session import javax.jcr.Value -@Bootstrap(sequence = 99999.00005d) +@Bootstrap @Updater(name = "Set some property", xpath = "content/documents//element(*,hippotaxonomy:classifiable)[@jcr:primaryType='project:communication' or @jcr:primaryType='project:listing' or @jcr:primaryType='project:newsdocument' or @jcr:primaryType='project:simpledocument' or @jcr:primaryType='project:richtextdocument' or @jcr:primaryType='project:services' or @jcr:primaryType='project:diydocument']") class SetSomeDocumentProperty extends BaseNodeUpdateVisitor { diff --git a/bootstrapgenerator/src/test/resources/sub/annotatestrip.xml b/bootstrapgenerator/src/test/resources/sub/annotatestrip.xml deleted file mode 100644 index b2e08f0..0000000 --- a/bootstrapgenerator/src/test/resources/sub/annotatestrip.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - hipposys:updaterinfo - - - 10 - - - false - - - content/documents//element(*,hippotaxonomy:classifiable)[@jcr:primaryType='project:communication' or @jcr:primaryType='project:listing' or @jcr:primaryType='project:newsdocument' or @jcr:primaryType='project:simpledocument' or @jcr:primaryType='project:richtextdocument' or @jcr:primaryType='project:services' or @jcr:primaryType='project:diydocument'] - - - properties - - @Override - void initialize(Session session) throws RepositoryException { - properties = new HashSet<>() - Node theNode = session.getNode("/content/taxonomies/propertytietaxonomy/propertytietaxonomy/properties") - addKeyAndCallChildsIfCorrectType(theNode) - } - - void addKeyAndCallChildsIfCorrectType(Node node){ - if(node != null && node.primaryNodeType.name == "hippotaxonomy:category"){ - properties.add(node.getProperty("hippotaxonomy:key").string) - NodeIterator iterator = node.nodes - while (iterator.hasNext()){ - addKeyAndCallChildsIfCorrectType(iterator.nextNode()) - } - } - } - - @Override - boolean doUpdate(Node node) { - if(! node.hasProperty("hippotaxonomy:keys")){ - log.info "node at ${node.path} has no hippotaxonomy:keys property, skipping" - return false - } - boolean value = isTagged(node.getProperty("hippotaxonomy:keys")) - node.setProperty("myproject:tag", value) - log.info "set tag to ${value} on path ${node.path}" - return true - } - - private boolean isTagged(Property property){ - for(Value value : property.values){ - if(properties.contains(value.string)){ - return true - } - } - return false - } - - boolean undoUpdate(Node node) { - node.getProperty("myproject:tag").remove() - return true - } -} -]]> - - - 1000 - - diff --git a/bootstrapgenerator/src/test/resources/sub/updater2.xml b/bootstrapgenerator/src/test/resources/sub/updater2.xml deleted file mode 100644 index c7bc835..0000000 --- a/bootstrapgenerator/src/test/resources/sub/updater2.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - hipposys:updaterinfo - - - 10 - - - false - - - //element(*, hippo:document) - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 1000 - - diff --git a/bootstrapgenerator/src/test/resources/sub/updater3.xml b/bootstrapgenerator/src/test/resources/sub/updater3.xml deleted file mode 100644 index 5042e11..0000000 --- a/bootstrapgenerator/src/test/resources/sub/updater3.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - hipposys:updaterinfo - - - 10 - - - false - - - //element(*, hippo:document) - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 1000 - - diff --git a/bootstrapgenerator/src/test/resources/target/hippoecm-extension.xml b/bootstrapgenerator/src/test/resources/target/hippoecm-extension.xml deleted file mode 100644 index dc4313d..0000000 --- a/bootstrapgenerator/src/test/resources/target/hippoecm-extension.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - hippo:initializefolder - - - - hippo:initializeitem - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 30900.01 - - - true - - - - - - diff --git a/bootstrapgenerator/src/test/resources/updater-noimport.groovy b/bootstrapgenerator/src/test/resources/updater-noimport.groovy index ebdda44..b7d0e72 100644 --- a/bootstrapgenerator/src/test/resources/updater-noimport.groovy +++ b/bootstrapgenerator/src/test/resources/updater-noimport.groovy @@ -17,7 +17,7 @@ @nl.openweb.hippo.groovy.annotations.Updater(name = "Test Updater noimport", xpath = "//element(*, hippo:document)", description="", path = "", parameters = " ") -@nl.openweb.hippo.groovy.annotations.Bootstrap(sequence = 99999.0d) +@nl.openweb.hippo.groovy.annotations.Bootstrap class TestUpdater extends org.onehippo.repository.update.BaseNodeUpdateVisitor { boolean doUpdate(javax.jcr.Node node) { log.info "manipulate node < > & an %^&* /> {}", node.path diff --git a/bootstrapgenerator/src/test/resources/updater.groovy b/bootstrapgenerator/src/test/resources/updater.groovy index 529fafa..23a4c6d 100644 --- a/bootstrapgenerator/src/test/resources/updater.groovy +++ b/bootstrapgenerator/src/test/resources/updater.groovy @@ -10,7 +10,7 @@ import javax.jcr.Node (It should allow any notations, for the stripping etc.. for example a description on how the XPath query should be like //element(*, hippo:document)[mixin:types='project:example'] or the parameters field, describing like: { "foobar": [ "bar", "foo"]}''', path = "", parameters = " ") -@Bootstrap(reload = true, sequence = 99999.0d) +@Bootstrap(reload = true) class TestUpdater extends BaseNodeUpdateVisitor { boolean doUpdate(Node node) { log.info "manipulate node < > & an %^&* /> {}", node.path diff --git a/bootstrapgenerator/src/test/resources/updater.xml b/bootstrapgenerator/src/test/resources/updater.xml deleted file mode 100644 index 3c7ede2..0000000 --- a/bootstrapgenerator/src/test/resources/updater.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - hipposys:updaterinfo - - - 10 - - - This script can be used to do anything. - (It should allow any notations, for the stripping etc.. - for example a description on how the XPath query should be like //element(*, hippo:document)[mixin:types='project:example'] - or the parameters field, describing like: { "foobar": [ "bar", "foo"]} - - - false - - - //element(*, hippo:document) - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 1000 - - diff --git a/bootstrapgenerator/src/test/resources/updater2.groovy b/bootstrapgenerator/src/test/resources/updater2.groovy index cdc755b..bb27253 100644 --- a/bootstrapgenerator/src/test/resources/updater2.groovy +++ b/bootstrapgenerator/src/test/resources/updater2.groovy @@ -4,7 +4,7 @@ import org.onehippo.repository.update.BaseNodeUpdateVisitor import javax.jcr.Node -@Bootstrap(contentroot = Bootstrap.ContentRoot.REGISTRY, sequence = 99999.1d, reload = true, version = "1.6") +@Bootstrap(contentroot = Bootstrap.ContentRoot.REGISTRY, reload = true, version = "1.6") @Updater(name = "Test Updater 2", path = "/content", description = "Test thing", batchSize = 1L, throttle = 200L, dryRun = true, parameters = "{prop: val}") class TestUpdater2 extends BaseNodeUpdateVisitor { boolean doUpdate(Node node) { diff --git a/bootstrapgenerator/src/test/resources/updater2.xml b/bootstrapgenerator/src/test/resources/updater2.xml deleted file mode 100644 index e541893..0000000 --- a/bootstrapgenerator/src/test/resources/updater2.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - hipposys:updaterinfo - - - 1 - - - Test thing - - - true - - - {prop: val} - - - /content - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 200 - - diff --git a/bootstrapgenerator/src/test/resources/updater3.groovy b/bootstrapgenerator/src/test/resources/updater3.groovy index e1903ee..23d389c 100644 --- a/bootstrapgenerator/src/test/resources/updater3.groovy +++ b/bootstrapgenerator/src/test/resources/updater3.groovy @@ -4,7 +4,7 @@ import org.onehippo.repository.update.BaseNodeUpdateVisitor import javax.jcr.Node import nl.openweb.hippo.groovy.annotations.Bootstrap.ContentRoot; -@Bootstrap(contentroot = ContentRoot.QUEUE, sequence = 99999.0d, reload = true, version = "2") +@Bootstrap(contentroot = ContentRoot.QUEUE, reload = true, version = "2") @Updater(name = "Test Updater 3", path = "", xpath = "//element(*, hippo:document)" , description = "Test things, like reserved words as import or others", batchSize = 1L, throttle = 200L, dryRun = true, parameters = "{prop: val}") diff --git a/bootstrapgenerator/src/test/resources/updater3.xml b/bootstrapgenerator/src/test/resources/updater3.xml deleted file mode 100644 index 764ee93..0000000 --- a/bootstrapgenerator/src/test/resources/updater3.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - hipposys:updaterinfo - - - 1 - - - Test things, like reserved words as import or others - - - true - - - {prop: val} - - - //element(*, hippo:document) - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 200 - - diff --git a/bootstrapgenerator/src/test/resources/updaterdata/updater4.groovy b/bootstrapgenerator/src/test/resources/updaterdata/updater4.groovy index fba7846..82cdfc3 100644 --- a/bootstrapgenerator/src/test/resources/updaterdata/updater4.groovy +++ b/bootstrapgenerator/src/test/resources/updaterdata/updater4.groovy @@ -23,7 +23,7 @@ import org.onehippo.repository.update.BaseNodeUpdateVisitor import javax.jcr.Node import nl.openweb.hippo.groovy.annotations.Bootstrap.ContentRoot; -@Bootstrap(contentroot = ContentRoot.QUEUE, sequence = 99999.0d, reload = true, version = "2") +@Bootstrap(contentroot = ContentRoot.QUEUE, reload = true, version = "2") @Updater(name = "Test Updater 4", path = "", xpath = "//element(*, hippo:document)" , description = "Test thing", batchSize = 1L, throttle = 200L, dryRun = true, parameters = "parameters/updater4.json") diff --git a/bootstrapgenerator/src/test/resources/updaterdata/updater4.xml b/bootstrapgenerator/src/test/resources/updaterdata/updater4.xml deleted file mode 100644 index 2e3dbb8..0000000 --- a/bootstrapgenerator/src/test/resources/updaterdata/updater4.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - hipposys:updaterinfo - - - 1 - - - Test thing - - - true - - - { - "testcontent": "mytestcontent" -} - - - //element(*, hippo:document) - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 200 - - diff --git a/bootstrapgenerator/src/test/resources/updaterdata/updater5.groovy b/bootstrapgenerator/src/test/resources/updaterdata/updater5.groovy index 7162b83..f7cccc3 100644 --- a/bootstrapgenerator/src/test/resources/updaterdata/updater5.groovy +++ b/bootstrapgenerator/src/test/resources/updaterdata/updater5.groovy @@ -23,7 +23,7 @@ import org.onehippo.repository.update.BaseNodeUpdateVisitor import javax.jcr.Node import nl.openweb.hippo.groovy.annotations.Bootstrap.ContentRoot; -@Bootstrap(contentroot = ContentRoot.QUEUE, sequence = 99999.0d, reload = true, version = "2") +@Bootstrap(contentroot = ContentRoot.QUEUE, reload = true, version = "2") @Updater(name = "Test Updater 5", path = "", xpath = "//element(*, hippo:document)" , description = "Test thing", batchSize = 1L, throttle = 200L, dryRun = true, parameters = "/updaterdata/parameters/updater4.json") diff --git a/bootstrapgenerator/src/test/resources/updaterdata/updater5.xml b/bootstrapgenerator/src/test/resources/updaterdata/updater5.xml deleted file mode 100644 index 8da3d78..0000000 --- a/bootstrapgenerator/src/test/resources/updaterdata/updater5.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - hipposys:updaterinfo - - - 1 - - - Test thing - - - true - - - { - "testcontent": "mytestcontent" -} - - - //element(*, hippo:document) - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 200 - - diff --git a/bootstrapgenerator/src/test/resources/updaterdata/updater6.groovy b/bootstrapgenerator/src/test/resources/updaterdata/updater6.groovy index 3823bbd..a7c6b9e 100644 --- a/bootstrapgenerator/src/test/resources/updaterdata/updater6.groovy +++ b/bootstrapgenerator/src/test/resources/updaterdata/updater6.groovy @@ -24,7 +24,7 @@ import org.onehippo.repository.update.BaseNodeUpdateVisitor import javax.jcr.Node import nl.openweb.hippo.groovy.annotations.Bootstrap.ContentRoot -@Bootstrap(contentroot = ContentRoot.QUEUE, sequence = 99999.0d, reload = true, version = "2") +@Bootstrap(contentroot = ContentRoot.QUEUE, reload = true, version = "2") @Updater(name = "Test Updater 6", path = "", xpath = "//element(*, hippo:document)" , description = "Test Mixin", batchSize = 1L, throttle = 200L, dryRun = true , mixin = "mixin:test, mixin:test1,mixin:test2, mixin:test3, mixin:test4") diff --git a/bootstrapgenerator/src/test/resources/updaterdata/updater6.xml b/bootstrapgenerator/src/test/resources/updaterdata/updater6.xml deleted file mode 100644 index 499bff3..0000000 --- a/bootstrapgenerator/src/test/resources/updaterdata/updater6.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - hipposys:updaterinfo - - - 1 - - - Test Mixin - - - true - - - mixin:test - mixin:test1 - mixin:test2 - mixin:test3 - mixin:test4 - - - //element(*, hippo:document) - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 200 - - diff --git a/bootstrapgenerator/src/test/resources/updaterdata/updater7.groovy b/bootstrapgenerator/src/test/resources/updaterdata/updater7.groovy index 365287d..24e239c 100644 --- a/bootstrapgenerator/src/test/resources/updaterdata/updater7.groovy +++ b/bootstrapgenerator/src/test/resources/updaterdata/updater7.groovy @@ -24,7 +24,7 @@ import org.onehippo.repository.update.BaseNodeUpdateVisitor import javax.jcr.Node import nl.openweb.hippo.groovy.annotations.Bootstrap.ContentRoot -@Bootstrap(contentroot = ContentRoot.QUEUE, sequence = 99999.0d, reload = true, version = "2") +@Bootstrap(contentroot = ContentRoot.QUEUE, reload = true, version = "2") @Updater(name = "Test Updater 7", path = "", xpath = "//element(*, hippo:document)" , description = "Test Mixin", batchSize = 1L, throttle = 200L, dryRun = true , mixin = "mixin:test") diff --git a/bootstrapgenerator/src/test/resources/updaterdata/updater7.xml b/bootstrapgenerator/src/test/resources/updaterdata/updater7.xml deleted file mode 100644 index f472ea9..0000000 --- a/bootstrapgenerator/src/test/resources/updaterdata/updater7.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - hipposys:updaterinfo - - - 1 - - - Test Mixin - - - true - - - mixin:test - - - //element(*, hippo:document) - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 200 - - diff --git a/mavenplugin/pom.xml b/mavenplugin/pom.xml index 709b004..504a29a 100644 --- a/mavenplugin/pom.xml +++ b/mavenplugin/pom.xml @@ -19,7 +19,7 @@ groovy-updater nl.openweb.hippo.updater - 1.14-SNAPSHOT + 2.0-SNAPSHOT 4.0.0 diff --git a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrap.java b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrap.java index f5a6c1f..8cd0d76 100644 --- a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrap.java +++ b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrap.java @@ -19,8 +19,6 @@ import java.io.File; import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.annotations.Parameter; @@ -37,12 +35,10 @@ public abstract class GroovyToUpdaterBootstrap extends AbstractMojo { private File sourceDir; @Parameter(defaultValue = "${project.build.outputDirectory}", property = "targetDir") private File targetDir; - @Parameter(defaultValue = "hippo-updater-", property = "initializeNamePrefix") - private String initializeNamePrefix; @Parameter(defaultValue = "queue", property = "defaultContentRoot") private String defaultContentRoot; - public void execute() throws MojoExecutionException, MojoFailureException { + public void execute() { logPluginConfigurationItems(); getLog().info("Add outputDirectory to classpath for project files: " + targetDir.getPath()); getProcessor().processUpdateScripts(); @@ -52,7 +48,6 @@ protected void logPluginConfigurationItems() { final Log log = getLog(); log.info("sourceDir: " + sourceDir.getAbsolutePath()); log.info("targetDir: " + targetDir.getAbsolutePath()); - log.info("initializeNamePrefix: " + initializeNamePrefix); } private ScriptProcessor getProcessor() { @@ -60,7 +55,6 @@ private ScriptProcessor getProcessor() { processor.setLog(getLog()); processor.setTargetDir(targetDir); processor.setSourceDir(sourceDir); - processor.setInitializeNamePrefix(initializeNamePrefix); Generator.setDefaultContentRoot(defaultContentRoot.equalsIgnoreCase("registry") ? Bootstrap.ContentRoot.REGISTRY : Bootstrap.ContentRoot.QUEUE); return processor; diff --git a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrapDefault.java b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrapDefault.java deleted file mode 100644 index 194331e..0000000 --- a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrapDefault.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2019 Open Web IT B.V. (https://www.openweb.nl/) - * - * 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. - */ -package nl.openweb.hippo.groovy.maven; - -import org.apache.maven.plugins.annotations.Mojo; - -import nl.openweb.hippo.groovy.maven.processor.ScriptProcessor; -import nl.openweb.hippo.groovy.maven.processor.ScriptProcessorXML; - -/** - * @deprecated since yaml and xml have their own Mojo now - */ -@Deprecated -@Mojo(name = "generate", threadSafe = true) -public class GroovyToUpdaterBootstrapDefault extends GroovyToUpdaterBootstrap { - @Override - protected ScriptProcessor getProcessorBase() { - getLog().warn("The goal \"generate\" is deprecated, move to \"generate-xml\" or \"generate-yaml\""); - return new ScriptProcessorXML(); - } -} diff --git a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterXmlBootstrap.java b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterXmlBootstrap.java deleted file mode 100644 index 837516c..0000000 --- a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterXmlBootstrap.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2019 Open Web IT B.V. (https://www.openweb.nl/) - * - * 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. - */ -package nl.openweb.hippo.groovy.maven; - -import org.apache.maven.plugins.annotations.Mojo; - -import nl.openweb.hippo.groovy.maven.processor.ScriptProcessor; -import nl.openweb.hippo.groovy.maven.processor.ScriptProcessorXML; - -@Mojo(name = "generate-xml", threadSafe = true) -public class GroovyToUpdaterXmlBootstrap extends GroovyToUpdaterBootstrap { - @Override - protected ScriptProcessor getProcessorBase() { - return new ScriptProcessorXML(); - } -} diff --git a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/processor/ScriptProcessor.java b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/processor/ScriptProcessor.java index f14e692..9b04939 100644 --- a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/processor/ScriptProcessor.java +++ b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/processor/ScriptProcessor.java @@ -18,7 +18,6 @@ import java.io.File; import java.util.List; -import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; import nl.openweb.hippo.groovy.model.ScriptClass; @@ -29,18 +28,17 @@ public abstract class ScriptProcessor { protected Log log; protected File sourceDir; protected File targetDir; - protected String initializeNamePrefix; /** * Generate updater files from groovy scripts * * @return list of valid parsed groovy files */ - public List processUpdateScripts() throws MojoExecutionException { + public List processUpdateScripts() { return processUpdateScripts(getScriptClasses(sourceDir)); } - public abstract List processUpdateScripts(final List scriptClasses) throws MojoExecutionException; + public abstract List processUpdateScripts(final List scriptClasses); /** * Generate updater files from groovy scripts @@ -76,8 +74,4 @@ public void setSourceDir(final File sourceDir) { public void setTargetDir(final File targetDir) { this.targetDir = targetDir; } - - public void setInitializeNamePrefix(final String initializeNamePrefix) { - this.initializeNamePrefix = initializeNamePrefix; - } } diff --git a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/processor/ScriptProcessorXML.java b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/processor/ScriptProcessorXML.java deleted file mode 100644 index a384dd0..0000000 --- a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/processor/ScriptProcessorXML.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2019 Open Web IT B.V. (https://www.openweb.nl/) - * - * 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. - */ -package nl.openweb.hippo.groovy.maven.processor; - -import java.io.File; -import java.util.List; - -import javax.xml.bind.JAXBException; - -import org.apache.maven.plugin.MojoExecutionException; - -import nl.openweb.hippo.groovy.model.ScriptClass; -import nl.openweb.hippo.groovy.model.jaxb.Node; -import static nl.openweb.hippo.groovy.Marshal.getMarshaller; -import static nl.openweb.hippo.groovy.XmlGenerator.getEcmExtensionNode; -import static nl.openweb.hippo.groovy.XmlGenerator.getUpdateScriptNode; -import static nl.openweb.hippo.groovy.XmlGenerator.getUpdateScriptXmlFilename; -import static nl.openweb.hippo.groovy.model.Constants.Files.ECM_EXTENSIONS_NAME; - -public class ScriptProcessorXML extends ScriptProcessor { - - /** - * Write hippoecm-extension.xml file - * - * @param parsedScriptClasses list of scriptclasses to use in the generation - * @throws MojoExecutionException - */ - private void writeEcmExtensions(final List parsedScriptClasses) throws MojoExecutionException { - final Node ecmExtensionNode = getEcmExtensionNode(sourceDir, targetDir, parsedScriptClasses, initializeNamePrefix); - if (ecmExtensionNode == null) { - throw new MojoExecutionException("No input for " + ECM_EXTENSIONS_NAME); - } - targetDir.mkdirs(); - - marshal(ecmExtensionNode, new File(targetDir, ECM_EXTENSIONS_NAME)); - } - - /** - * Generate updater xml files from groovy scripts - * - * @param scriptClassList groovy scripts to parse - * @return list of valid parsed groovy files - */ - @Override - public List processUpdateScripts(final List scriptClassList) throws MojoExecutionException { - List scriptClasses = processGroovyScripts(scriptClassList); - writeEcmExtensions(scriptClasses); - return scriptClasses; - } - - /** - * Generate updater xml from groovy file - * - * @param script groovy script to parse - * @return parsing successful - */ - @Override - protected boolean processUpdateScript(final ScriptClass script) { - getLog().debug("Converting " + script.getFile().getAbsolutePath() + " to updater xml"); - final Node updateScriptNode = getUpdateScriptNode(sourceDir, script); - if (updateScriptNode == null) { - getLog().warn("Skipping file: " + script.getFile().getAbsolutePath() + ", not a valid updatescript"); - return false; - } - final File targetFile = new File(targetDir, getUpdateScriptXmlFilename(sourceDir, script.getFile())); - targetFile.getParentFile().mkdirs(); - getLog().info("Write " + targetFile.getAbsolutePath()); - return marshal(updateScriptNode, targetFile); - } - - /** - * Write the node in XML style to the file - * - * @param node - * @param file - * @return result of writing to the file - */ - protected boolean marshal(final Node node, final File file) { - try { - getMarshaller().marshal(node, file); - return true; - } catch (final JAXBException e) { - getLog().error("Failed to make xml: " + file.getAbsolutePath(), e); - return false; - } - } -} diff --git a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/processor/ScriptProcessorYAML.java b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/processor/ScriptProcessorYAML.java index 46ccb25..07459f0 100644 --- a/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/processor/ScriptProcessorYAML.java +++ b/mavenplugin/src/main/java/nl/openweb/hippo/groovy/maven/processor/ScriptProcessorYAML.java @@ -22,7 +22,6 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.plugin.MojoExecutionException; import nl.openweb.hippo.groovy.annotations.Bootstrap; import nl.openweb.hippo.groovy.model.ScriptClass; @@ -35,13 +34,13 @@ public class ScriptProcessorYAML extends ScriptProcessor { protected String yamlConfigurationPath; /** - * Generate updater xml files from groovy scripts + * Generate updater yaml files from groovy scripts * * @param groovyFiles groovy scripts to parse * @return list of valid parsed groovy files */ @Override - public List processUpdateScripts(final List groovyFiles) throws MojoExecutionException { + public List processUpdateScripts(final List groovyFiles) { return processGroovyScripts(groovyFiles); } diff --git a/mavenplugin/src/test/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterXmlBootstrapTest.java b/mavenplugin/src/test/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrapTest.java similarity index 61% rename from mavenplugin/src/test/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterXmlBootstrapTest.java rename to mavenplugin/src/test/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrapTest.java index 4a1eed8..c134dda 100644 --- a/mavenplugin/src/test/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterXmlBootstrapTest.java +++ b/mavenplugin/src/test/java/nl/openweb/hippo/groovy/maven/GroovyToUpdaterBootstrapTest.java @@ -44,8 +44,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -public class GroovyToUpdaterXmlBootstrapTest { - private static Logger logger = LoggerFactory.getLogger(GroovyToUpdaterXmlBootstrapTest.class); +public class GroovyToUpdaterBootstrapTest { @Rule public MojoRule rule = new MojoRule() { @Override @@ -62,28 +61,6 @@ protected void after() { @Rule public TestResources resources = new TestResources(); - // @Test - public void noottest() throws URISyntaxException, IOException, MojoFailureException, MojoExecutionException { - GroovyToUpdaterXmlBootstrap gtuxb = new GroovyToUpdaterXmlBootstrap(); - Map pluginContext = new HashMap<>(); - File input = new File(getClass().getResource("/src/scripts").toURI()); - File output = new File(new File(getClass().getResource("/").toURI()), "mvn_xml_output"); - pluginContext.put("defaultContentRoot", "registry"); - pluginContext.put("sourceDir", input); - pluginContext.put("targetDir", output); - gtuxb.setPluginContext(pluginContext); - gtuxb.logPluginConfigurationItems(); - if (output.exists()) { - FileUtils.deleteDirectory(output); - assertFalse(output.exists()); - } - output.mkdirs(); - gtuxb.execute(); - File xml_expected = new File(getClass().getResource("/target_xml").toURI()); - - compareFolders(xml_expected, output); - } - private Mojo getMojo(String goal, File pomFile) { MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest(); @@ -100,41 +77,6 @@ private Mojo getMojo(String goal, File pomFile) { return null; } - @Test - public void testXml() throws Exception { - File basedir = resources.getBasedir(""); - File target = new File(basedir, "target/classes"); - File pom = new File(basedir, "pom-to-test-xml.xml"); - target.mkdirs(); - - FileUtils.copyFile(new File(basedir, "src/main/resources/hippoecm-extension.xml"), new File(target, "hippoecm-extension.xml")); - - runMojo(pom, "generate-xml"); - - File xml_expected = new File(getClass().getResource("/target_xml").toURI()); - compareFolders(xml_expected, target); - } - - @Test - public void testXml2() throws Exception { - File basedir = resources.getBasedir(""); - File target = new File(basedir, "target/classes2"); - File pom = new File(basedir, "pom-to-test-xml-2.xml"); - target.mkdirs(); - - FileUtils.copyFile(new File(basedir, "src/main/resources/hippoecm-extension.xml"), new File(target, "hippoecm-extension.xml")); - - runMojo(pom, "generate-xml"); - - File xml_expected_original = new File(getClass().getResource("/target_xml").toURI()); - File xml_expected_overlay = new File(getClass().getResource("/target_xml2_overlay").toURI()); - File xml_expected = new File(basedir, "target_xml"); - xml_expected.mkdirs(); - FileUtils.copyDirectory(xml_expected_original, xml_expected); - FileUtils.copyDirectory(xml_expected_overlay, xml_expected); - compareFolders(xml_expected, target); - } - @Test public void testYaml() throws Exception { File basedir = resources.getBasedir(""); diff --git a/mavenplugin/src/test/java/nl/openweb/hippo/groovy/maven/ScriptProcessorTest.java b/mavenplugin/src/test/java/nl/openweb/hippo/groovy/maven/ScriptProcessorTest.java index a395747..8194c2c 100644 --- a/mavenplugin/src/test/java/nl/openweb/hippo/groovy/maven/ScriptProcessorTest.java +++ b/mavenplugin/src/test/java/nl/openweb/hippo/groovy/maven/ScriptProcessorTest.java @@ -30,7 +30,6 @@ import org.slf4j.LoggerFactory; import nl.openweb.hippo.groovy.maven.processor.ScriptProcessor; -import nl.openweb.hippo.groovy.maven.processor.ScriptProcessorXML; import nl.openweb.hippo.groovy.maven.processor.ScriptProcessorYAML; import static nl.openweb.hippo.groovy.ScriptClassFactory.getScriptClasses; import static nl.openweb.tools.Tools.compareFolders; @@ -41,38 +40,9 @@ public class ScriptProcessorTest { static Logger logger = LoggerFactory.getLogger(ScriptProcessorTest.class); ScriptProcessor processor; - @Test - public void testXML() throws URISyntaxException, MojoExecutionException, IOException { - processor = new ScriptProcessorXML(); - processor.setInitializeNamePrefix("sampleproject-update-"); - processor.setLog(new SystemStreamLog()); - - File input = new File(getClass().getResource("/src/main/scripts").toURI()); - File xml_output = new File(new File(getClass().getResource("/").toURI()), "xml_output"); - - File resource = new File(getClass() - .getResource("/src/main/resources/hippoecm-extension.xml").toURI()); - File targetResource = new File(xml_output, "hippoecm-extension.xml"); - if (xml_output.exists()) { - FileUtils.deleteDirectory(xml_output); - assertFalse(xml_output.exists()); - } - //Preparation: existing ecm-extension.xml in target - targetResource.mkdirs(); - Files.copy(resource.toPath(), targetResource.toPath(), StandardCopyOption.REPLACE_EXISTING); - processor.setSourceDir(input); - processor.setTargetDir(xml_output); - - processor.processUpdateScripts(getScriptClasses(input)); - File xml_expected = new File(getClass().getResource("/target_xml").toURI()); - - compareFolders(xml_expected, xml_output); - } - @Test public void testYaml() throws URISyntaxException, MojoExecutionException, IOException { processor = new ScriptProcessorYAML(); - processor.setInitializeNamePrefix("my-hippo-updater-"); processor.setLog(new SystemStreamLog()); File input = new File(getClass().getResource("/src/main/scripts").toURI()); diff --git a/mavenplugin/src/test/projects/pom-to-test-xml-2.xml b/mavenplugin/src/test/projects/pom-to-test-xml-2.xml deleted file mode 100644 index 8da2757..0000000 --- a/mavenplugin/src/test/projects/pom-to-test-xml-2.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - 4.0.0 - - org.apache.maven.plugin.my.unit - project-to-test - 1.12-SNAPSHOT - jar - Test MyMojo - - - - junit - junit - 3.8.1 - test - - - - - - - nl.openweb.hippo.updater - groovy-updater-maven-plugin - ${project.version} - - - ${project.build.outputDirectory}2 - sampleproject-update- - registry - - - - default-resources - compile - - generate-xml - - - - - - - \ No newline at end of file diff --git a/mavenplugin/src/test/projects/pom-to-test-xml.xml b/mavenplugin/src/test/projects/pom-to-test-xml.xml deleted file mode 100644 index 0b09f92..0000000 --- a/mavenplugin/src/test/projects/pom-to-test-xml.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - 4.0.0 - - org.apache.maven.plugin.my.unit - project-to-test - 1.12-SNAPSHOT - jar - Test MyMojo - - - - junit - junit - 3.8.1 - test - - - - - - - nl.openweb.hippo.updater - groovy-updater-maven-plugin - ${project.version} - - sampleproject-update- - - - - default-resources - compile - - generate-xml - - - - - - - \ No newline at end of file diff --git a/mavenplugin/src/test/projects/pom-to-test-yaml-2.xml b/mavenplugin/src/test/projects/pom-to-test-yaml-2.xml index 84fb773..4d0c3eb 100644 --- a/mavenplugin/src/test/projects/pom-to-test-yaml-2.xml +++ b/mavenplugin/src/test/projects/pom-to-test-yaml-2.xml @@ -43,7 +43,6 @@ registry ${project.build.outputDirectory}2 - sampleproject-update- diff --git a/mavenplugin/src/test/projects/pom-to-test-yaml.xml b/mavenplugin/src/test/projects/pom-to-test-yaml.xml index 917d81d..167cd0e 100644 --- a/mavenplugin/src/test/projects/pom-to-test-yaml.xml +++ b/mavenplugin/src/test/projects/pom-to-test-yaml.xml @@ -40,9 +40,6 @@ nl.openweb.hippo.updater groovy-updater-maven-plugin ${project.version} - - sampleproject-update- - default-resources diff --git a/mavenplugin/src/test/projects/src/main/resources/hippoecm-extension.xml b/mavenplugin/src/test/projects/src/main/resources/hippoecm-extension.xml deleted file mode 100644 index b1d89ad..0000000 --- a/mavenplugin/src/test/projects/src/main/resources/hippoecm-extension.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - hippo:initializefolder - - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 30900.01 - - - true - - - - - - diff --git a/mavenplugin/src/test/projects/src/main/scripts/hippoecm-extension.xml b/mavenplugin/src/test/projects/src/main/scripts/hippoecm-extension.xml deleted file mode 100644 index 6575944..0000000 --- a/mavenplugin/src/test/projects/src/main/scripts/hippoecm-extension.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - hippo:initializefolder - - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 30900.02 - - - true - - - - - - diff --git a/mavenplugin/src/test/projects/src/main/scripts/updater2.groovy b/mavenplugin/src/test/projects/src/main/scripts/updater2.groovy index cdc755b..bb27253 100644 --- a/mavenplugin/src/test/projects/src/main/scripts/updater2.groovy +++ b/mavenplugin/src/test/projects/src/main/scripts/updater2.groovy @@ -4,7 +4,7 @@ import org.onehippo.repository.update.BaseNodeUpdateVisitor import javax.jcr.Node -@Bootstrap(contentroot = Bootstrap.ContentRoot.REGISTRY, sequence = 99999.1d, reload = true, version = "1.6") +@Bootstrap(contentroot = Bootstrap.ContentRoot.REGISTRY, reload = true, version = "1.6") @Updater(name = "Test Updater 2", path = "/content", description = "Test thing", batchSize = 1L, throttle = 200L, dryRun = true, parameters = "{prop: val}") class TestUpdater2 extends BaseNodeUpdateVisitor { boolean doUpdate(Node node) { diff --git a/mavenplugin/src/test/resources/target_xml/hippoecm-extension.xml b/mavenplugin/src/test/resources/target_xml/hippoecm-extension.xml deleted file mode 100644 index fa59731..0000000 --- a/mavenplugin/src/test/resources/target_xml/hippoecm-extension.xml +++ /dev/null @@ -1,150 +0,0 @@ - - - - hippo:initializefolder - - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 30900.01 - - - true - - - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 30900.02 - - - true - - - - - hippo:initializeitem - - - the_updater_with_spaces_in_the_filename.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - true - - - - - hippo:initializeitem - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - true - - - - - hippo:initializeitem - - - updater3.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - - - hippo:initializeitem - - - updater4.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - true - - - 3.6 - - - - - hippo:initializeitem - - - sub/updater2.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - - - hippo:initializeitem - - - sub/updater3.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 99999.0 - - - - - hippo:initializeitem - - - updater2.xml - - - /hippo:configuration/hippo:update/hippo:registry - - - 99999.1 - - - true - - - 1.6 - - - diff --git a/mavenplugin/src/test/resources/target_xml/sub/updater2.xml b/mavenplugin/src/test/resources/target_xml/sub/updater2.xml deleted file mode 100644 index 7f091cd..0000000 --- a/mavenplugin/src/test/resources/target_xml/sub/updater2.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - hipposys:updaterinfo - - - 10 - - - false - - - //element(*, hippo:document) - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 1000 - - diff --git a/mavenplugin/src/test/resources/target_xml/sub/updater3.xml b/mavenplugin/src/test/resources/target_xml/sub/updater3.xml deleted file mode 100644 index d1f13dc..0000000 --- a/mavenplugin/src/test/resources/target_xml/sub/updater3.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - hipposys:updaterinfo - - - 10 - - - false - - - //element(*, hippo:document) - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 1000 - - diff --git a/mavenplugin/src/test/resources/target_xml/the_updater_with_spaces_in_the_filename.xml b/mavenplugin/src/test/resources/target_xml/the_updater_with_spaces_in_the_filename.xml deleted file mode 100644 index a3e4c55..0000000 --- a/mavenplugin/src/test/resources/target_xml/the_updater_with_spaces_in_the_filename.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - hipposys:updaterinfo - - - 10 - - - false - - - //element(*, hippo:document) - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 1000 - - diff --git a/mavenplugin/src/test/resources/target_xml/updater.xml b/mavenplugin/src/test/resources/target_xml/updater.xml deleted file mode 100644 index 7bfc888..0000000 --- a/mavenplugin/src/test/resources/target_xml/updater.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - hipposys:updaterinfo - - - 10 - - - false - - - //element(*, hippo:document) - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 1000 - - diff --git a/mavenplugin/src/test/resources/target_xml/updater2.xml b/mavenplugin/src/test/resources/target_xml/updater2.xml deleted file mode 100644 index b9b4ccb..0000000 --- a/mavenplugin/src/test/resources/target_xml/updater2.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - hipposys:updaterinfo - - - 1 - - - Test thing - - - true - - - {prop: val} - - - /content - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 200 - - diff --git a/mavenplugin/src/test/resources/target_xml/updater3.xml b/mavenplugin/src/test/resources/target_xml/updater3.xml deleted file mode 100644 index cf0e3d6..0000000 --- a/mavenplugin/src/test/resources/target_xml/updater3.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - hipposys:updaterinfo - - - 10 - - - false - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 1000 - - diff --git a/mavenplugin/src/test/resources/target_xml/updater4.xml b/mavenplugin/src/test/resources/target_xml/updater4.xml deleted file mode 100644 index fa2dc33..0000000 --- a/mavenplugin/src/test/resources/target_xml/updater4.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - hipposys:updaterinfo - - - 10 - - - false - - - //element(*, hippo:document) - - - & an %^&* /> {}", node.path - return true - } - - boolean undoUpdate(Node node) { - throw new UnsupportedOperationException('Updater does not implement undoUpdate method') - } -} -]]> - - - 1000 - - diff --git a/mavenplugin/src/test/resources/target_xml2_overlay/hippoecm-extension.xml b/mavenplugin/src/test/resources/target_xml2_overlay/hippoecm-extension.xml deleted file mode 100644 index 997621b..0000000 --- a/mavenplugin/src/test/resources/target_xml2_overlay/hippoecm-extension.xml +++ /dev/null @@ -1,150 +0,0 @@ - - - - hippo:initializefolder - - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 30900.01 - - - true - - - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 30900.02 - - - true - - - - - hippo:initializeitem - - - the_updater_with_spaces_in_the_filename.xml - - - /hippo:configuration/hippo:update/hippo:registry - - - 99999.0 - - - true - - - - - hippo:initializeitem - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:registry - - - 99999.0 - - - true - - - - - hippo:initializeitem - - - updater3.xml - - - /hippo:configuration/hippo:update/hippo:registry - - - 99999.0 - - - - - hippo:initializeitem - - - updater4.xml - - - /hippo:configuration/hippo:update/hippo:registry - - - 99999.0 - - - true - - - 3.6 - - - - - hippo:initializeitem - - - sub/updater2.xml - - - /hippo:configuration/hippo:update/hippo:registry - - - 99999.0 - - - - - hippo:initializeitem - - - sub/updater3.xml - - - /hippo:configuration/hippo:update/hippo:registry - - - 99999.0 - - - - - hippo:initializeitem - - - updater2.xml - - - /hippo:configuration/hippo:update/hippo:registry - - - 99999.1 - - - true - - - 1.6 - - - diff --git a/pom.xml b/pom.xml index f7031dd..480ce21 100644 --- a/pom.xml +++ b/pom.xml @@ -20,12 +20,12 @@ nl.openweb.hippo.updater groovy-updater - 1.14-SNAPSHOT + 2.0-SNAPSHOT pom Groovy updater This project is designed for Hippo developers to have an easy way to create updaters in groovy, without - being bothered with the bootstrap xml + being bothered with the repository data yaml https://github.com/openweb-nl/hippo-groovy-updater @@ -74,38 +74,39 @@ - 2.6 - 3.9 - 2.5.6 - 1.24 - 4.2.8 - 2.4.0-b180830.0438 + 2.11.0 + 3.12.0 + 3.0.9 + 1.29 + 12.6.18 + 12.6.18 2.0 - 5.4.2 - 5.4.2 - 2.16.2 - 3.6.1 - 3.1.1 - 3.8.0 - 3.0.1 + 5.8.1 + 5.8.1 + 2.21.7 + 3.8.3 + 3.2.0 + 3.8.1 + 3.2.1 2.5.3 - 3.1.0 - 1.6 + 3.3.1 + 3.0.1 3.0.0-M1 - 3.0.0-M2 + 3.0.0 3.1.0 3.0.0-M1 - 3.1.1 - 3.1.0 - 3.7.1 - 3.0.0-M3 - 3.6.0 - 3.6.0 - 0.8.1 - 3.2.0 + 3.2.0 + 3.2.0 + 3.9.1 + 3.0.0-M5 + 3.6.1 + 3.6.1 + 0.8.7 + 3.4.1 + 1.5.4 UTF-8 - 1.7.26 - 5.0.0-M2 + 1.7.32 + 6.3.2 @@ -141,11 +142,6 @@ groovy ${groovy.version} - - org.glassfish.jaxb - jaxb-runtime - ${glassfish.jaxb-runtime.version} - org.onehippo.cms7 hippo-repository-dependencies @@ -153,6 +149,12 @@ pom runtime + + org.onehippo.cms7 + hippo-services + ${hippo.services.version} + provided + javax.jcr jcr @@ -189,6 +191,12 @@ ${slf4j.version} test + + org.apache.sling + org.apache.sling.testing.jcr-mock + ${apache.sling.version} + test + diff --git a/sampleproject/pom.xml b/sampleproject/pom.xml index a7534b6..7e7d5ff 100644 --- a/sampleproject/pom.xml +++ b/sampleproject/pom.xml @@ -19,7 +19,7 @@ groovy-updater nl.openweb.hippo.updater - 1.14-SNAPSHOT + 2.0-SNAPSHOT 4.0.0 @@ -66,7 +66,6 @@ ${project.build.scriptSourceDirectory} ${project.build.outputDirectory} - sampleproject-update- hcm-content/configuration/update @@ -74,7 +73,6 @@ default-resources compile - generate-xml generate-yaml diff --git a/sampleproject/src/main/resources/hippoecm-extension.xml b/sampleproject/src/main/resources/hippoecm-extension.xml deleted file mode 100644 index b1d89ad..0000000 --- a/sampleproject/src/main/resources/hippoecm-extension.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - hippo:initializefolder - - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 30900.01 - - - true - - - - - - diff --git a/sampleproject/src/main/scripts/cleanup.groovy b/sampleproject/src/main/scripts/cleanup.groovy index c15c442..38b71a9 100755 --- a/sampleproject/src/main/scripts/cleanup.groovy +++ b/sampleproject/src/main/scripts/cleanup.groovy @@ -24,7 +24,7 @@ import org.onehippo.repository.update.BaseNodeUpdateVisitor import javax.jcr.Node import javax.jcr.RepositoryException -@Bootstrap(sequence = 50000d, reload = true, version = "1") +@Bootstrap(reload = true, version = "1") @Updater(name = "Cleanup Nodes no longer needed", xpath = "/jcr:root") class Cleanup extends BaseNodeUpdateVisitor { diff --git a/sampleproject/src/main/scripts/cndreload.json b/sampleproject/src/main/scripts/cndreload.json new file mode 100644 index 0000000..a172b8c --- /dev/null +++ b/sampleproject/src/main/scripts/cndreload.json @@ -0,0 +1,8 @@ +{ + "cnd": [ + { + "namespaceURI": "http://www.example.com/example/nt/1.0", + "cndcontent": "<'example'='http://www.example.com/example/nt/1.0'>\n<'hippo'='http://www.onehippo.org/jcr/hippo/nt/2.0.4'>\n<'hippostd'='http://www.onehippo.org/jcr/hippostd/nt/2.0'>\n<'hippostdpubwf'='http://www.onehippo.org/jcr/hippostdpubwf/nt/1.0'>\n<'hippotranslation'='http://www.onehippo.org/jcr/hippotranslation/nt/1.0'>\n\n[example:basedocument] > hippo:document, hippostd:publishableSummary, hippostdpubwf:document\n orderable\n\n[example:article] > example:basedocument, hippostd:relaxed, hippotranslation:translated\n orderable\n\n[example:compoundOne] > hippo:compound, hippostd:relaxed\n orderable\n\n[example:compoundTwo] > hippo:compound, hippostd:relaxed\n orderable\n\n[example:wrapper] > hippo:compound, hippostd:relaxed\n orderable\n" + } + ] +} \ No newline at end of file diff --git a/sampleproject/src/main/scripts/hippoecm-extension.xml b/sampleproject/src/main/scripts/hippoecm-extension.xml deleted file mode 100644 index 37587e1..0000000 --- a/sampleproject/src/main/scripts/hippoecm-extension.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - hippo:initializefolder - - - - updater.xml - - - /hippo:configuration/hippo:update/hippo:queue - - - 30900.02 - - - true - - - - - - diff --git a/sampleproject/src/main/scripts/parameters_updater3.json b/sampleproject/src/main/scripts/parameters_updater3.json index 5ca3ad0..1fc2c63 100644 --- a/sampleproject/src/main/scripts/parameters_updater3.json +++ b/sampleproject/src/main/scripts/parameters_updater3.json @@ -1,3 +1,3 @@ { - 'prop': 'val' + "prop": "val" } \ No newline at end of file diff --git a/sampleproject/src/main/scripts/reloadcnd.groovy b/sampleproject/src/main/scripts/reloadcnd.groovy new file mode 100644 index 0000000..03cd6d1 --- /dev/null +++ b/sampleproject/src/main/scripts/reloadcnd.groovy @@ -0,0 +1,135 @@ +package resourcebundles + +import nl.openweb.hippo.groovy.annotations.Bootstrap +import nl.openweb.hippo.groovy.annotations.Updater +import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader +import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefWriter +import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException +import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl +import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry +import org.apache.jackrabbit.spi.QNodeTypeDefinition +import org.hippoecm.repository.jackrabbit.HippoCompactNodeTypeDefReader +import org.hippoecm.repository.jackrabbit.HippoNodeTypeRegistry +import org.hippoecm.repository.util.JcrCompactNodeTypeDefWriter +import org.onehippo.repository.update.BaseNodeUpdateVisitor + +import javax.jcr.NamespaceRegistry +import javax.jcr.Node +import javax.jcr.RepositoryException +import javax.jcr.Session + +@Bootstrap(contentroot = Bootstrap.ContentRoot.REGISTRY) +@Updater( + name = "Update cnd's'", + description = '''This is a workaround script to reload cnd's without checks. +Ideal to remove doctypes from cnd's or change inheritence structures ''', + parameters = "cndreload.json" +) +class CndReloader extends BaseNodeUpdateVisitor { + List> cnds + def iterator + Session session + NamespaceRegistry namespaceRegistry + HippoNodeTypeRegistry nodeTypeRegistry + + @Override + void initialize(final Session session) throws RepositoryException { + super.initialize(session) + NodeTypeRegistry.disableCheckForReferencesInContentException = true; + namespaceRegistry = session.getWorkspace().getNamespaceRegistry(); + nodeTypeRegistry = (HippoNodeTypeRegistry) ((NodeTypeManagerImpl) session.getWorkspace().getNodeTypeManager()).getNodeTypeRegistry() + } + + @Override + Node firstNode(Session session) throws RepositoryException { + this.session = session + cnds = parametersMap.get("cnd") + iterator = cnds.iterator() + return nextNode() + } + + @Override + Node nextNode() throws RepositoryException { + if (iterator.hasNext()) { + def mapping = iterator.next() + def namespaceURI = mapping.get("namespaceURI") + def cndContent = mapping.get("cndcontent") + try { + updateCnd(namespaceURI, cndContent) + } + + catch (Exception e) { + log.error("Failed to update cnd for '${namespaceURI}', moving on!\n${e.getMessage()}") + visitorContext.reportFailed(namespaceURI) + } + return session.getRootNode() + } + return null; + } + + void updateCnd(String namespaceUri, String cndContent) { + final CompactNodeTypeDefReader cndReader = + new HippoCompactNodeTypeDefReader(new StringReader(cndContent), namespaceUri, namespaceRegistry) + String existingContent = JcrCompactNodeTypeDefWriter.compactNodeTypeDef(session.getWorkspace(), namespaceRegistry.getPrefix(namespaceUri)) + + final List ntdList = cndReader.getNodeTypeDefinitions(); + + importNodeTypes(ntdList) + + final CompactNodeTypeDefReader currentCndReader = + new HippoCompactNodeTypeDefReader(new StringReader(existingContent), namespaceUri, namespaceRegistry) + final List existingNtdList = currentCndReader.getNodeTypeDefinitions() + removeOldMappings(existingNtdList, ntdList) + } + + private void importNodeTypes(List ntdList) { + for (QNodeTypeDefinition ntd : ntdList) { + try { + if (!nodeTypeRegistry.isRegistered(ntd.name)) { + log.debug("Registering node type {}", ntd.name) + if(!visitorContext.dryRun) { + nodeTypeRegistry.registerNodeType(ntd); + } + } else { + log.debug("Replacing node type {}", ntd.name); + if(!visitorContext.dryRun) { + nodeTypeRegistry.ignoreNextConflictingContent(); + nodeTypeRegistry.reregisterNodeType(ntd); + } + } + } catch (InvalidNodeTypeDefException e) { + throw new RepositoryException("Invalid node type definition for node type ${ntd.name}", e); + } + } + } + + @Override + boolean doUpdate(Node node) throws RepositoryException { + return false + } + + @Override + boolean undoUpdate(Node node) throws RepositoryException, UnsupportedOperationException { + return false + } + + void removeOldMappings(List oldContent, List newContent) { + log.debug("attempting removing of old definitions") + for (QNodeTypeDefinition nodeTypeDefinition : oldContent) { + def name = nodeTypeDefinition.name.localName + def contained = false + for (QNodeTypeDefinition newDefinition : newContent) { + if(name == newDefinition.name.localName){ + contained = true + break + } + } + if(!contained) { + log.debug("nodetype not found in new definition ${name}, removing") + if (!visitorContext.dryRun) { + nodeTypeRegistry.unregisterNodeType(nodeTypeDefinition.name); + } + } + } + } +} \ No newline at end of file diff --git a/sampleproject/src/main/scripts/updater2.groovy b/sampleproject/src/main/scripts/updater2.groovy index 2b4d4e7..ab9880a 100644 --- a/sampleproject/src/main/scripts/updater2.groovy +++ b/sampleproject/src/main/scripts/updater2.groovy @@ -20,7 +20,7 @@ import org.onehippo.repository.update.BaseNodeUpdateVisitor import javax.jcr.Node -@Bootstrap(contentroot = Bootstrap.ContentRoot.REGISTRY, sequence = 99999.1d, reload = true, version = "2") +@Bootstrap(contentroot = Bootstrap.ContentRoot.REGISTRY, reload = true, version = "2") @Updater(name = "Test Updater 2", path = "/content", description = "Test thing", batchSize = 1L, throttle = 200L, dryRun = true, parameters = "{prop: val}") class TestUpdater2 extends BaseNodeUpdateVisitor { boolean doUpdate(Node node) { diff --git a/updatersync/pom.xml b/updatersync/pom.xml index 4cfedef..6109146 100644 --- a/updatersync/pom.xml +++ b/updatersync/pom.xml @@ -19,7 +19,7 @@ groovy-updater nl.openweb.hippo.updater - 1.14-SNAPSHOT + 2.0-SNAPSHOT 4.0.0 @@ -42,7 +42,6 @@ org.onehippo.cms7 hippo-services - 3.2.2 provided @@ -67,7 +66,6 @@ org.apache.sling org.apache.sling.testing.jcr-mock - 1.4.4 test diff --git a/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesService.java b/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesService.java index b3d420c..e4bc125 100644 --- a/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesService.java +++ b/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesService.java @@ -36,11 +36,9 @@ package nl.openweb.hippo.groovy; import java.io.File; -import java.io.IOException; import javax.jcr.RepositoryException; import javax.jcr.Session; -import javax.xml.bind.JAXBException; import org.onehippo.cms7.services.SingletonService; import org.onehippo.cms7.services.WhiteboardService; @@ -49,7 +47,7 @@ @WhiteboardService public interface GroovyFilesService { - void importGroovyFiles(Session session, File file) throws IOException, RepositoryException; + void importGroovyFiles(Session session, File file); - boolean importGroovyFile(Session session, File file) throws IOException, RepositoryException, JAXBException; + boolean importGroovyFile(Session session, File file) throws RepositoryException; } \ No newline at end of file diff --git a/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesServiceImpl.java b/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesServiceImpl.java index 4febc44..4cbb47d 100644 --- a/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesServiceImpl.java +++ b/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesServiceImpl.java @@ -35,7 +35,6 @@ package nl.openweb.hippo.groovy; import java.io.File; -import java.io.IOException; import java.util.List; import java.util.Map; @@ -44,7 +43,6 @@ import javax.jcr.Session; import javax.jcr.Value; import javax.jcr.ValueFormatException; -import javax.xml.bind.JAXBException; import org.apache.jackrabbit.value.BooleanValue; import org.apache.jackrabbit.value.LongValue; @@ -69,7 +67,7 @@ public class GroovyFilesServiceImpl implements GroovyFilesService { - private static final Logger log = LoggerFactory.getLogger(GroovyFilesServiceImpl.class); + private static final Logger LOGGER = LoggerFactory.getLogger(GroovyFilesServiceImpl.class); private static void warnAndThrow(final String message, final Object... args) { throw new GroovyFileException(warn(message, args)); @@ -77,13 +75,13 @@ private static void warnAndThrow(final String message, final Object... args) { private static String warn(final String message, final Object... args) { String warning = String.format(message, args); - log.warn(warning); + LOGGER.warn(warning); return warning; } private static String info(final String message, final Object... args) { String warning = String.format(message, args); - log.info(warning); + LOGGER.info(warning); return warning; } @@ -97,7 +95,7 @@ private static String info(final String message, final Object... args) { */ private static boolean setUpdateScriptJcrNode(Node parent, File file) throws RepositoryException { ScriptClass scriptClass = getInterpretingClass(file, true); - if (!scriptClass.isValid()) { + if (scriptClass == null || !scriptClass.isValid()) { return false; } final Updater updater = scriptClass.getUpdater(); @@ -147,7 +145,7 @@ private Node getRegistryNode(Session session) throws RepositoryException { return scriptRegistry; } - public void importGroovyFiles(Session session, File file) throws IOException, RepositoryException { + public void importGroovyFiles(Session session, File file) { List groovyFiles = getGroovyFiles(file); for (File groovyFile : groovyFiles) { importGroovyFiles(session, groovyFile); @@ -160,11 +158,9 @@ public void importGroovyFiles(Session session, File file) throws IOException, Re * @param session jcr session tu use * @param file file to transform * @return success - * @throws IOException * @throws RepositoryException - * @throws JAXBException */ - public boolean importGroovyFile(Session session, File file) throws IOException, RepositoryException, JAXBException { + public boolean importGroovyFile(Session session, File file) throws RepositoryException { return setUpdateScriptJcrNode(getRegistryNode(session), file); } } diff --git a/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesServiceModule.java b/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesServiceModule.java index 7ef4c1e..658dea5 100644 --- a/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesServiceModule.java +++ b/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesServiceModule.java @@ -46,7 +46,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import nl.openweb.hippo.groovy.watch.GlobFileNameMatcher; import nl.openweb.hippo.groovy.watch.GroovyFilesWatcher; import nl.openweb.hippo.groovy.watch.GroovyFilesWatcherConfig; import nl.openweb.hippo.groovy.watch.GroovyFilesWatcherJcrConfig; @@ -54,7 +53,7 @@ @RequiresService(types = AutoReloadService.class, optional = true) public class GroovyFilesServiceModule extends AbstractReconfigurableDaemonModule { - private static final Logger LOG = LoggerFactory.getLogger(GroovyFilesServiceModule.class); + private static final Logger LOGGER = LoggerFactory.getLogger(GroovyFilesServiceModule.class); private GroovyFilesServiceImpl service; private GroovyFilesWatcherConfig config; private GroovyFilesWatcher watcher; @@ -78,11 +77,7 @@ protected void onConfigurationChange(final Node moduleConfig) throws RepositoryE @Override protected void doInitialize(final Session session) { - final GlobFileNameMatcher watchedFiles = new GlobFileNameMatcher(); - watchedFiles.includeFiles(config.getIncludedFiles()); - watchedFiles.excludeDirectories(config.getExcludedDirectories()); - - LOG.debug("Starting Service for checking Groovy"); + LOGGER.debug("Starting Service for checking Groovy"); service = new GroovyFilesServiceImpl(); HippoServiceRegistry.registerService(service, GroovyFilesService.class); diff --git a/updatersync/src/main/java/nl/openweb/hippo/groovy/util/WatchFilesUtils.java b/updatersync/src/main/java/nl/openweb/hippo/groovy/util/WatchFilesUtils.java index 3fe7e3d..da4bfe7 100644 --- a/updatersync/src/main/java/nl/openweb/hippo/groovy/util/WatchFilesUtils.java +++ b/updatersync/src/main/java/nl/openweb/hippo/groovy/util/WatchFilesUtils.java @@ -58,7 +58,7 @@ public class WatchFilesUtils { public static final String[] DEFAULT_WATCHED_MODULES = {}; public static final Long DEFAULT_WATCH_DELAY_MILLIS = 500L; public static final Long DEFAULT_MAX_FILE_LENGTH_KB = 256L; - private static final Logger log = LoggerFactory.getLogger(WatchFilesUtils.class); + private static final Logger LOGGER = LoggerFactory.getLogger(WatchFilesUtils.class); private WatchFilesUtils() { //no creation of the instance @@ -69,15 +69,15 @@ public static Path getProjectBaseDir() { if (projectBaseDir != null && !projectBaseDir.isEmpty()) { final Path baseDir = FileSystems.getDefault().getPath(projectBaseDir); if (baseDir.toFile().isDirectory()) { - if (log.isDebugEnabled()) { - log.debug("Basedir found: {}", baseDir); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Basedir found: {}", baseDir); } return baseDir; } else { - log.warn("Watching groovy files is disabled: environment variable '{}' does not point to a directory", PROJECT_BASEDIR_PROPERTY); + LOGGER.warn("Watching groovy files is disabled: environment variable '{}' does not point to a directory", PROJECT_BASEDIR_PROPERTY); } } else { - log.info("Watching groovy files is disabled: environment variable '{}' not set or empty", PROJECT_BASEDIR_PROPERTY); + LOGGER.info("Watching groovy files is disabled: environment variable '{}' not set or empty", PROJECT_BASEDIR_PROPERTY); } return null; } @@ -86,8 +86,8 @@ public static List getGroovyFilesDirectories(final Path projectBaseDir, final GroovyFilesWatcherConfig config) { List filesDirectories = new ArrayList<>(config.getWatchedModules().size()); - if (log.isDebugEnabled()) { - log.debug("getting groovy file directories"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("getting groovy file directories"); } for (String watchedModule : config.getWatchedModules()) { final Path modulePath = projectBaseDir.resolve(watchedModule); @@ -96,12 +96,12 @@ public static List getGroovyFilesDirectories(final Path projectBaseDir, paths.add(modulePath.resolve(RESOURCE_FILES_LOCATION_IN_MODULE)); List pathList = paths.stream().filter(Files::isDirectory).collect(Collectors.toList()); filesDirectories.addAll(pathList); - if (log.isDebugEnabled()) { - log.debug("Found {} paths to add for watching. {}", pathList.size(), pathList.stream().map(Path::toString) + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Found {} paths to add for watching. {}", pathList.size(), pathList.stream().map(Path::toString) .collect(Collectors.joining(", "))); } if (pathList.isEmpty()) { - log.warn("Cannot watch groovy files in module '{}': it does not contain directory '{}' or {}", + LOGGER.warn("Cannot watch groovy files in module '{}': it does not contain directory '{}' or {}", watchedModule, SCRIPT_FILES_LOCATION_IN_MODULE, RESOURCE_FILES_LOCATION_IN_MODULE); } } diff --git a/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/FileSystemPoller.java b/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/FileSystemPoller.java index 125dba7..074c58c 100644 --- a/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/FileSystemPoller.java +++ b/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/FileSystemPoller.java @@ -40,7 +40,7 @@ */ public class FileSystemPoller implements FileSystemObserver, FileAlterationListener { - private static final Logger log = LoggerFactory.getLogger(FileSystemPoller.class); + private static final Logger LOGGER = LoggerFactory.getLogger(FileSystemPoller.class); private final FileFilter fileNameFilter; private final Map listeners; @@ -60,8 +60,8 @@ public FileSystemPoller(final FileFilter fileNameFilter, final long pollingDelay @Override public synchronized void registerDirectory(final Path directory, final FileSystemListener listener) throws IOException { - if (log.isDebugEnabled()) { - log.debug("Registering {}", directory); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Registering {}", directory); } final FileAlterationObserver observer = new FileAlterationObserver(directory.toFile(), this.fileNameFilter); @@ -87,10 +87,10 @@ public void onStart(final FileAlterationObserver observer) { final Path observedPath = observer.getDirectory().toPath(); listenerForCurrentChange = listeners.get(observedPath); if (listenerForCurrentChange != null) { - log.debug("Start collecting changes in {}", observedPath); + LOGGER.debug("Start collecting changes in {}", observedPath); listenerForCurrentChange.fileSystemChangesStarted(); } else { - log.warn("Ignoring file system changes in unknown directory: {}", observedPath); + LOGGER.warn("Ignoring file system changes in unknown directory: {}", observedPath); } } @@ -98,7 +98,7 @@ public void onStart(final FileAlterationObserver observer) { public void onDirectoryCreate(final File directory) { if (listenerForCurrentChange != null) { final Path path = directory.toPath(); - log.debug("Create directory {}", path); + LOGGER.debug("Create directory {}", path); listenerForCurrentChange.directoryCreated(path); } } @@ -107,7 +107,7 @@ public void onDirectoryCreate(final File directory) { public void onDirectoryChange(final File directory) { if (listenerForCurrentChange != null) { final Path path = directory.toPath(); - log.debug("Change directory {}", path); + LOGGER.debug("Change directory {}", path); listenerForCurrentChange.directoryModified(path); } } @@ -116,7 +116,7 @@ public void onDirectoryChange(final File directory) { public void onDirectoryDelete(final File directory) { if (listenerForCurrentChange != null) { final Path path = directory.toPath(); - log.debug("Delete directory {}", path); + LOGGER.debug("Delete directory {}", path); listenerForCurrentChange.directoryDeleted(path); } } @@ -125,7 +125,7 @@ public void onDirectoryDelete(final File directory) { public void onFileCreate(final File file) { if (listenerForCurrentChange != null) { final Path path = file.toPath(); - log.debug("Create file {}", path); + LOGGER.debug("Create file {}", path); listenerForCurrentChange.fileCreated(path); } } @@ -134,7 +134,7 @@ public void onFileCreate(final File file) { public void onFileChange(final File file) { if (listenerForCurrentChange != null) { final Path path = file.toPath(); - log.debug("Change file {}", path); + LOGGER.debug("Change file {}", path); listenerForCurrentChange.fileModified(path); } } @@ -143,7 +143,7 @@ public void onFileChange(final File file) { public void onFileDelete(final File file) { if (listenerForCurrentChange != null) { final Path path = file.toPath(); - log.debug("Delete file {}", path); + LOGGER.debug("Delete file {}", path); listenerForCurrentChange.fileDeleted(path); } } @@ -151,7 +151,7 @@ public void onFileDelete(final File file) { @Override public void onStop(final FileAlterationObserver observer) { if (listenerForCurrentChange != null) { - log.debug("Stop collecting changes in {}", observer.getDirectory()); + LOGGER.debug("Stop collecting changes in {}", observer.getDirectory()); listenerForCurrentChange.fileSystemChangesStopped(); } } @@ -163,7 +163,7 @@ public void shutdown() { } catch (IllegalStateException ignored) { // throw when the monitor was already stopped } catch (Exception e) { - log.debug("Ignored error while shutting down", e); + LOGGER.debug("Ignored error while shutting down", e); } } } diff --git a/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/FileSystemWatcher.java b/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/FileSystemWatcher.java index 494b93e..e316aa7 100644 --- a/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/FileSystemWatcher.java +++ b/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/FileSystemWatcher.java @@ -50,9 +50,9 @@ public class FileSystemWatcher implements FileSystemObserver, Runnable { static final int POLLING_TIME_MILLIS = 100; - private static final Logger log = LoggerFactory.getLogger(SubDirectoriesWatcher.class); + private static final Logger LOGGER = LoggerFactory.getLogger(FileSystemWatcher.class); private static final Thread.UncaughtExceptionHandler UNCAUGHT_EXCEPTION_HANDLER = - (exceptionThread, exception) -> log.warn("FileSystemWatcher '{}' crashed", exceptionThread.getName(), exception); + (exceptionThread, exception) -> LOGGER.warn("FileSystemWatcher '{}' crashed", exceptionThread.getName(), exception); private static int instanceCounter = 0; /** * The {@link WatchService} used by this class has a percularity: when a directory is moved, the associated watch @@ -85,7 +85,7 @@ public void registerDirectory(final Path directory, final FileSystemListener lis changesProcessors.put(directory, new ChangesProcessor(listener)); registerRecursively(directory); } else { - log.debug("Do not observe ignored directory {}", directory); + LOGGER.debug("Do not observe ignored directory {}", directory); } } @@ -117,12 +117,12 @@ public FileVisitResult preVisitDirectory(final Path visitedDirectory, final Basi @Override public void run() { try { - log.info("Watch started, polling every {} ms", POLLING_TIME_MILLIS); + LOGGER.info("Watch started, polling every {} ms", POLLING_TIME_MILLIS); while (fileSystemWatcherThread.isAlive()) { processChanges(); } } catch (ClosedWatchServiceException e) { - log.info("Watch closed", e); + LOGGER.info("Watch closed", e); } finally { IOUtils.closeQuietly(watcher); } @@ -130,20 +130,20 @@ public void run() { private void processChanges() { try { - log.info("Waiting for changes... {}", fileSystemWatcherThread.isAlive() ? "YES" : "NO"); + LOGGER.info("Waiting for changes... {}", fileSystemWatcherThread.isAlive() ? "YES" : "NO"); watchChange(); pollForMoreChanges(); stopProcessingChanges(); } catch (ClosedWatchServiceException e) { throw e; } catch (Exception e) { - log.warn("Exception while processing watch keys: {}", e.toString(), e); + LOGGER.warn("Exception while processing watch keys: {}", e, e); } } private void watchChange() throws InterruptedException { final WatchKey key = watcher.take(); - log.debug("Change found for '{}'", key.watchable()); + LOGGER.debug("Change found for '{}'", key.watchable()); processWatchKey(key); } @@ -156,17 +156,17 @@ private void pollForMoreChanges() throws InterruptedException { List polledKeys = new ArrayList<>(); final long startPolling = System.currentTimeMillis(); while (keepPolling) { - log.debug("Waiting {} ms for more changes...", POLLING_TIME_MILLIS); + LOGGER.debug("Waiting {} ms for more changes...", POLLING_TIME_MILLIS); WatchKey key = watcher.poll(POLLING_TIME_MILLIS, TimeUnit.MILLISECONDS); if (key == null) { keepPolling = false; } else { - log.debug("Found change for '{}' found during extra polling time", key.watchable()); + LOGGER.debug("Found change for '{}' found during extra polling time", key.watchable()); polledKeys.add(key); } } - if (log.isDebugEnabled()) { - log.debug("Polled '{}' more changes during '{}' ms", polledKeys.size(), String.valueOf(System.currentTimeMillis() - startPolling)); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Polled '{}' more changes during '{}' ms", polledKeys.size(), System.currentTimeMillis() - startPolling); } for (WatchKey polledKey : polledKeys) { processWatchKey(polledKey); @@ -177,9 +177,9 @@ private void processWatchKey(final WatchKey key) { try { final Path watchedDirectory = watchedPaths.get(key); if (watchedDirectory == null) { - log.warn("Ignoring watch event for unknown directory: {}", key.watchable()); + LOGGER.warn("Ignoring watch event for unknown directory: {}", key.watchable()); } else { - log.debug("Processing watch key for '{}'", watchedDirectory); + LOGGER.debug("Processing watch key for '{}'", watchedDirectory); processFileSystemChanges(watchedDirectory, key); } } finally { @@ -191,7 +191,7 @@ private void processFileSystemChanges(final Path watchedDirectory, final WatchKe final ChangesProcessor processor = getChangesProcessorOrNull(watchedDirectory); if (processor == null) { - log.warn("Ignoring change in {}: no change processor found", watchedDirectory); + LOGGER.warn("Ignoring change in {}: no change processor found", watchedDirectory); return; } @@ -201,12 +201,12 @@ private void processFileSystemChanges(final Path watchedDirectory, final WatchKe final WatchEvent.Kind kind = event.kind(); final Object eventContext = event.context(); - if (log.isDebugEnabled()) { - log.debug("Processing {} {} in {}", kind.name(), eventContext, watchedDirectory); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Processing {} {} in {}", kind.name(), eventContext, watchedDirectory); } if (kind == StandardWatchEventKinds.OVERFLOW) { - log.info("event overflow in {}. Reimporting and registering watchedDirectory '{}' to avoid half synced state", + LOGGER.info("event overflow in {}. Reimporting and registering watchedDirectory '{}' to avoid half synced state", watchedDirectory, watchedDirectory); if (watchedDirectory.toFile().exists()) { registerQuietly(watchedDirectory); @@ -219,8 +219,7 @@ private void processFileSystemChanges(final Path watchedDirectory, final WatchKe } private void processEvent(final Path watchedDirectory, final ChangesProcessor processor, final WatchEvent.Kind kind, final Path eventContext) { - final Path changedRelPath = eventContext; - final Path changedAbsPath = watchedDirectory.resolve(changedRelPath); + final Path changedAbsPath = watchedDirectory.resolve(eventContext); final boolean isDirectory = isDirectory(changedAbsPath, kind); if (watchedFiles.matches(changedAbsPath, isDirectory)) { if (isDirectory && kind == StandardWatchEventKinds.ENTRY_CREATE) { @@ -228,7 +227,7 @@ private void processEvent(final Path watchedDirectory, final ChangesProcessor pr } processor.processChange(kind, changedAbsPath, isDirectory); } else { - log.debug("Skipping excluded path {}", changedAbsPath); + LOGGER.debug("Skipping excluded path {}", changedAbsPath); } } @@ -261,7 +260,7 @@ private void registerQuietly(final Path changedAbsPath) { try { registerRecursively(changedAbsPath); } catch (IOException e) { - log.error("Failed to register changed directory '{}'. Changes in this directory will not be picked up.", changedAbsPath, e); + LOGGER.error("Failed to register changed directory '{}'. Changes in this directory will not be picked up.", changedAbsPath, e); } } @@ -274,7 +273,7 @@ public synchronized void shutdown() { Thread.currentThread().interrupt(); } catch (IOException e) { // ignore, but don't wait for the thread - log.debug("Ignoring exception while closing watcher", e); + LOGGER.debug("Ignoring exception while closing watcher", e); } } @@ -312,11 +311,11 @@ private void processDirectoryChange(final WatchEvent.Kind kind, final Path ch listener.directoryDeleted(changedAbsPath); } else if (kind == StandardWatchEventKinds.OVERFLOW) { if (changedAbsPath.toFile().exists()) { - log.info("Having an event overflow for '{}'. Entire directory '{}' will be recreated", + LOGGER.info("Having an event overflow for '{}'. Entire directory '{}' will be recreated", changedAbsPath, changedAbsPath); listener.directoryCreated(changedAbsPath); } else { - log.info("Having an event overflow for non existing directory '{}'. Directory '{}' will be removed", + LOGGER.info("Having an event overflow for non existing directory '{}'. Directory '{}' will be removed", changedAbsPath, changedAbsPath); listener.directoryDeleted(changedAbsPath); } diff --git a/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/GlobFileNameMatcher.java b/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/GlobFileNameMatcher.java index 09ac3b0..ae94c96 100644 --- a/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/GlobFileNameMatcher.java +++ b/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/GlobFileNameMatcher.java @@ -37,7 +37,7 @@ public class GlobFileNameMatcher implements FileFilter { private static final String GLOB_SYNTAX = "glob:"; - static Logger log = LoggerFactory.getLogger(GlobFileNameMatcher.class); + private static final Logger LOGGER = LoggerFactory.getLogger(GlobFileNameMatcher.class); private final List includedFiles; private final List excludedDirs; @@ -61,7 +61,7 @@ public void includeFiles(final List fileNameGlobPatterns) { try { includeFiles(pattern); } catch (IllegalArgumentException e) { - log.warn("Ignoring file name glob pattern '{}': {}", pattern, e.getMessage()); + LOGGER.warn("Ignoring file name glob pattern '{}': {}", pattern, e.getMessage()); } } } @@ -75,7 +75,7 @@ public void excludeDirectories(final List fileNameGlobPattern) { try { excludeDirectories(pattern); } catch (IllegalArgumentException e) { - log.warn("Ignoring file name glob pattern '{}': {}", pattern, e.getMessage()); + LOGGER.warn("Ignoring file name glob pattern '{}': {}", pattern, e.getMessage()); } } } diff --git a/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/GroovyFilesWatcher.java b/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/GroovyFilesWatcher.java index ed979fb..6688ec3 100644 --- a/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/GroovyFilesWatcher.java +++ b/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/GroovyFilesWatcher.java @@ -17,17 +17,21 @@ */ package nl.openweb.hippo.groovy.watch; +import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.jcr.RepositoryException; import javax.jcr.Session; -import javax.xml.bind.JAXBException; +import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +46,7 @@ */ public class GroovyFilesWatcher implements SubDirectoriesWatcher.PathChangesListener { - private static final Logger log = LoggerFactory.getLogger(GroovyFilesWatcher.class); + private static final Logger LOGGER = LoggerFactory.getLogger(GroovyFilesWatcher.class); private final GroovyFilesWatcherConfig config; private final GroovyFilesService service; @@ -64,7 +68,7 @@ private FileSystemObserver observeFileSystemIfNeeded() { return null; } if (config.getWatchedModules().isEmpty()) { - log.info("Watching groovy files is disabled: no modules configured to watch in {}", projectBaseDir); + LOGGER.info("Watching groovy files is disabled: no modules configured to watch in {}", projectBaseDir); } else { return observeFileSystem(projectBaseDir); } @@ -76,21 +80,21 @@ private FileSystemObserver observeFileSystem(final Path projectBaseDir) { try { fsObserver = createFileSystemObserver(); } catch (Exception e) { - log.error("Watching groovy files is disabled: cannot create file system observer", e); + LOGGER.error("Watching groovy files is disabled: cannot create file system observer", e); return null; } List groovyFilesDirectories = WatchFilesUtils.getGroovyFilesDirectories(projectBaseDir, config); - if (log.isDebugEnabled()) { - log.debug("Observe {} paths: {}", groovyFilesDirectories.size(), groovyFilesDirectories.stream().map(Path::toString) + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Observe {} paths: {}", groovyFilesDirectories.size(), groovyFilesDirectories.stream().map(Path::toString) .collect(Collectors.joining(", "))); } for (Path groovyFilesDirectory : groovyFilesDirectories) { try { - log.info("About to listen to directories: {}", groovyFilesDirectory); + LOGGER.info("About to listen to directories: {}", groovyFilesDirectory); SubDirectoriesWatcher.watch(groovyFilesDirectory, fsObserver, this); } catch (Exception e) { - log.error("Failed to watch or import groovy files in module '{}'", groovyFilesDirectory.toString(), e); + LOGGER.error("Failed to watch or import groovy files in module '{}'", groovyFilesDirectory, e); } } return fsObserver; @@ -102,11 +106,11 @@ private FileSystemObserver createFileSystemObserver() throws IOException { watchedFiles.excludeDirectories(config.getExcludedDirectories()); if (useWatchService()) { - log.info("Using file system watcher"); + LOGGER.info("Using file system watcher"); return new FileSystemWatcher(watchedFiles); } else { long watchDelayMillis = config.getWatchDelayMillis(); - log.info("Using file system poller (delay: {} ms)", watchDelayMillis); + LOGGER.info("Using file system poller (delay: {} ms)", watchDelayMillis); return new FileSystemPoller(watchedFiles, watchDelayMillis); } } @@ -117,7 +121,7 @@ private boolean useWatchService() { try { matcher.include(pattern); } catch (IllegalArgumentException e) { - log.warn("Ignoring OS name '{}': {}. On this OS files will be watched using file system polling.", + LOGGER.warn("Ignoring OS name '{}': {}. On this OS files will be watched using file system polling.", pattern, e.getMessage()); } } @@ -135,52 +139,66 @@ public void onPathsChanged(final Path watchedRootDir, final Set changedPat Set processedPaths = new HashSet<>(changedPaths.size()); try { for (Path changedPath : changedPaths) { - final Path relChangedDir = watchedRootDir.relativize(changedPath); - - reloadGroovyFile(processedPaths, changedPath, relChangedDir); + final Path relevantScriptPath = getRelevantScriptPath(changedPath); + final Path relChangedDir = watchedRootDir.relativize(relevantScriptPath); + reloadGroovyFile(processedPaths, relevantScriptPath, relChangedDir); } if (!processedPaths.isEmpty()) { session.save(); } } catch (RepositoryException e) { - if (log.isDebugEnabled()) { - log.info("Failed to reload groovy files from '{}', resetting session and trying to reimport whole bundle(s)", + if (LOGGER.isDebugEnabled()) { + LOGGER.info("Failed to reload groovy files from '{}', resetting session and trying to reimport whole bundle(s)", changedPaths, e); - } else if (log.isInfoEnabled()) { - log.info("Failed to reload groovy files from '{}' : '{}', resetting session and trying to reimport whole bundle(s)", + } else if (LOGGER.isInfoEnabled()) { + LOGGER.info("Failed to reload groovy files from '{}' : '{}', resetting session and trying to reimport whole bundle(s)", changedPaths, e.getMessage()); } resetSilently(session); tryReimportBundles(watchedRootDir, changedPaths); + } catch (IOException e) { + LOGGER.info("Failure on reading files", e); } final long endTime = System.currentTimeMillis(); - log.info("Replacing groovy file took {} ms", endTime - startTime); + LOGGER.info("Replacing groovy file took {} ms", endTime - startTime); + } + + private static Path getRelevantScriptPath(final Path path) throws IOException { + if(path.endsWith(".groovy")){ + return path; + } else { + try(final Stream files = Files.walk(path.getParent())) { + return files.filter(file -> containsPathForParameters(file, path)).findFirst().orElse(null); + } + } + } + + private static boolean containsPathForParameters(final Path path, final Path parameters) { + try { + final File file = path.toFile(); + return file.isFile() && FileUtils.readFileToString(file, StandardCharsets.UTF_8).contains(parameters.getFileName().toString()); + } catch (IOException e) { + LOGGER.info("failed to read {}", path, e); + } + return false; } private void reloadGroovyFile(final Set processedPaths, final Path changedPath, final Path relChangedDir) throws RepositoryException { - log.info("Reloading groovyfile '{}'", relChangedDir); + LOGGER.info("Reloading groovyfile '{}'", relChangedDir); try { if (service.importGroovyFile(session, changedPath.toFile())) { processedPaths.add(changedPath); } else { - log.info("** Failed to process '{}' as a groovy updater", relChangedDir); + LOGGER.info("** Failed to process '{}' as a groovy updater", relChangedDir); } - } catch (IOException e) { - // we do not have to take action. An IOException is the result of a concurrent change (delete/move) - // during creation or processing of the archive. The change will trigger a new import - log.debug("IOException during importing '{}'. This is typically the result of a file that is deleted" + - "during the import of a directory. This delete will trigger an event shortly after this" + - " exception.", changedPath, e); } catch (NullPointerException e) { // sigh....because org.apache.jackrabbit.vault.util.FileInputSource.getByteStream() returns null // on a IOException (for example when a file is deleted during processing) I get an NPE I cannot avoid, // however, it is just similar to the IOException above, typically the result of an event that will // be processed shortly after this exception. Hence, ignore - log.debug("NullPointerException we cannot avoid because org.apache.jackrabbit.vault.util.FileInputSource.getByteStream() " + + LOGGER.debug("NullPointerException we cannot avoid because org.apache.jackrabbit.vault.util.FileInputSource.getByteStream() " + "returns null on IOException. We can ignore this event since it is the result of an event that will " + " be processed shortly after this exception. Hence, ignore change path '{}'", changedPath, e); - } catch (JAXBException e) { - log.error("JAXBException in import", e); } } @@ -193,7 +211,7 @@ private void resetSilently(final Session session) { try { session.refresh(false); } catch (RepositoryException e) { - log.debug("Ignoring that session.refresh(false) failed", e); + LOGGER.debug("Ignoring that session.refresh(false) failed", e); } } @@ -205,13 +223,13 @@ private void tryReimportBundles(final Path watchedRootDir, final Set chang final String bundleName = relChangedDir.getName(0).toString(); final Path bundleRootDir = watchedRootDir.resolve(bundleName); if (reimportedBundleRoots.add(bundleRootDir)) { - log.info("Reimporting bundle '{}'", bundleName); + LOGGER.info("Reimporting bundle '{}'", bundleName); service.importGroovyFiles(session, bundleRootDir.toFile()); } } session.save(); - } catch (GroovyFileException | RepositoryException | IOException e) { - log.warn("Failed to reimport groovy file bundles {}, resetting session", reimportedBundleRoots, e); + } catch (GroovyFileException | RepositoryException e) { + LOGGER.warn("Failed to reimport groovy file bundles {}, resetting session", reimportedBundleRoots, e); resetSilently(session); } } diff --git a/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/GroovyFilesWatcherJcrConfig.java b/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/GroovyFilesWatcherJcrConfig.java index 061b629..77fbed6 100644 --- a/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/GroovyFilesWatcherJcrConfig.java +++ b/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/GroovyFilesWatcherJcrConfig.java @@ -34,7 +34,7 @@ public class GroovyFilesWatcherJcrConfig implements GroovyFilesWatcherConfig { - private static final Logger log = LoggerFactory.getLogger(GroovyFilesWatcherJcrConfig.class); + private static final Logger LOGGER = LoggerFactory.getLogger(GroovyFilesWatcherJcrConfig.class); private static final String INCLUDED_FILES = "includedFiles"; private static final String EXCLUDED_DIRECTORIES = "excludedDirectories"; @@ -44,12 +44,12 @@ public class GroovyFilesWatcherJcrConfig implements GroovyFilesWatcherConfig { private static final String MAX_FILE_LENGTH_KB = "maxFileLengthKb"; private static final String PARAM_PREFIX = "groovy.sync."; - private List watchedModules; - private List includedFiles; - private List excludedDirs; - private List useWatchServiceOnOsNames; - private long watchDelayMillis; - private long maxFileLengthBytes; + private final List watchedModules; + private final List includedFiles; + private final List excludedDirs; + private final List useWatchServiceOnOsNames; + private final long watchDelayMillis; + private final long maxFileLengthBytes; public GroovyFilesWatcherJcrConfig(final Node configNode) throws RepositoryException { watchedModules = getMultipleStringConfig(configNode, WATCHED_MODULES_PROPERTY, WatchFilesUtils.DEFAULT_WATCHED_MODULES); @@ -63,8 +63,8 @@ public GroovyFilesWatcherJcrConfig(final Node configNode) throws RepositoryExcep private List getMultipleStringConfig(final Node configNode, final String propertyName, final String[] defaultValue) { String[] values = getMultipleStringPropertyOrDefault(configNode, propertyName, defaultValue); String[] systemPropertyChecked = getMultipleStringFromSystemProperty(propertyName, values); - if (log.isDebugEnabled()) { - log.debug("Configuration value for {} = {}", propertyName, StringUtils.join(systemPropertyChecked, ";")); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Configuration value for {} = {}", propertyName, StringUtils.join(systemPropertyChecked, ";")); } return Collections.unmodifiableList(Arrays.asList(systemPropertyChecked)); } @@ -78,7 +78,7 @@ private String[] getMultipleStringPropertyOrDefault(final Node configNode, final try { return getMultipleStringProperty(configNode, propertyName, defaultValue); } catch (RepositoryException e) { - log.warn("Error reading configuration property '{}' at {}, using default value instead: {}", + LOGGER.warn("Error reading configuration property '{}' at {}, using default value instead: {}", propertyName, JcrUtils.getNodePathQuietly(configNode), Arrays.asList(defaultValue), e); return defaultValue; } diff --git a/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/SubDirectoriesWatcher.java b/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/SubDirectoriesWatcher.java index 6e159b9..5a189b4 100644 --- a/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/SubDirectoriesWatcher.java +++ b/updatersync/src/main/java/nl/openweb/hippo/groovy/watch/SubDirectoriesWatcher.java @@ -36,7 +36,7 @@ */ class SubDirectoriesWatcher implements FileSystemListener { - private static final Logger log = LoggerFactory.getLogger(SubDirectoriesWatcher.class); + private static final Logger LOGGER = LoggerFactory.getLogger(SubDirectoriesWatcher.class); private static final DirectoryStream.Filter DIRECTORY_FILTER = path -> path.toFile().isDirectory(); @@ -80,7 +80,7 @@ private static void removeSubPaths(final SortedSet sortedPaths) { private void observeSubDirectories(final Path directory) throws IOException { try (DirectoryStream subDirectories = Files.newDirectoryStream(directory, DIRECTORY_FILTER)) { for (Path subDirectory : subDirectories) { - log.info("Watching directory: {}", subDirectory); + LOGGER.info("Watching directory: {}", subDirectory); fsObserver.registerDirectory(subDirectory, this); } } @@ -155,33 +155,33 @@ public void fileSystemChangesStopped() { } private void notifyStart() { - log.debug("Start change"); + LOGGER.debug("Start change"); try { listener.onStart(); } catch (RuntimeException e) { - log.warn("Exception by listener '{}' when change started", listener, e); + LOGGER.warn("Exception by listener '{}' when change started", listener, e); } } private void notifyPathsChanged(final Set changedPaths) { - log.debug("Paths changed: {}", changedPaths); + LOGGER.debug("Paths changed: {}", changedPaths); try { listener.onPathsChanged(rootDirectory, changedPaths); } catch (RuntimeException e) { - if (log.isDebugEnabled()) { - log.warn("Exception by listener '{}' while processing paths {}", listener, changedPaths, e); + if (LOGGER.isDebugEnabled()) { + LOGGER.warn("Exception by listener '{}' while processing paths {}", listener, changedPaths, e); } else { - log.warn("Exception by listener '{}' while processing paths {} : {}", listener, changedPaths, e.getMessage()); + LOGGER.warn("Exception by listener '{}' while processing paths {} : {}", listener, changedPaths, e.getMessage()); } } } private void notifyStop() { - log.debug("Stop change"); + LOGGER.debug("Stop change"); try { listener.onStop(); } catch (RuntimeException e) { - log.warn("Exception by listener '{}' when change stopped", listener, e); + LOGGER.warn("Exception by listener '{}' when change stopped", listener, e); } } diff --git a/updatersync/src/main/resources/groovyfiles-service-module.xml b/updatersync/src/main/resources/groovyfiles-service-module.xml deleted file mode 100644 index 877beb0..0000000 --- a/updatersync/src/main/resources/groovyfiles-service-module.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - - hipposys:module - - - nl.openweb.hippo.groovy.GroovyFilesServiceModule - - - - hipposys:moduleconfig - - - - .arch-ids - - BitKeeper - - .bzr - - CVS - - _darcs - .darcsrepo - - .git - - .hg - - .metadata - - RCS - - SCCS - - .svn - - - *.groovy - - - Linux - - - - 500 - - - 256 - - - updater - - - diff --git a/updatersync/src/main/resources/hcm-config/groovyfiles-service-module.yaml b/updatersync/src/main/resources/hcm-config/groovyfiles-service-module.yaml index 73ec833..95522b5 100644 --- a/updatersync/src/main/resources/hcm-config/groovyfiles-service-module.yaml +++ b/updatersync/src/main/resources/hcm-config/groovyfiles-service-module.yaml @@ -31,7 +31,7 @@ definitions: 'RCS', '.svn', ] - includedFiles: ['*.groovy'] + includedFiles: ['*.groovy', '*.json'] # Disabled: Windows* # # Two JDK issues are annoying enough to disable the Watch Service on Windows for now: diff --git a/updatersync/src/main/resources/hippoecm-extension.xml b/updatersync/src/main/resources/hippoecm-extension.xml deleted file mode 100644 index 9819c01..0000000 --- a/updatersync/src/main/resources/hippoecm-extension.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - hippo:initializefolder - - - - hippo:initializeitem - - - groovyfiles-service-module.xml - - - /hippo:configuration/hippo:modules - - - 90000 - - - - - - hippo:initializeitem - - - /hippo:configuration/hippo:modules/autoexport/hippo:moduleconfig/autoexport:excluded - - - /hippo:configuration/hippo:update/** - - - 90000 - - - \ No newline at end of file diff --git a/updatersync/src/test/java/nl/openweb/hippo/groovy/GroovyFilesServiceImplTest.java b/updatersync/src/test/java/nl/openweb/hippo/groovy/GroovyFilesServiceImplTest.java index f6e3990..1dd5d5e 100644 --- a/updatersync/src/test/java/nl/openweb/hippo/groovy/GroovyFilesServiceImplTest.java +++ b/updatersync/src/test/java/nl/openweb/hippo/groovy/GroovyFilesServiceImplTest.java @@ -28,7 +28,6 @@ import javax.jcr.PropertyIterator; import javax.jcr.RepositoryException; import javax.jcr.Session; -import javax.xml.bind.JAXBException; import org.apache.sling.testing.mock.jcr.MockJcr; import org.junit.jupiter.api.BeforeEach; @@ -40,7 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; class GroovyFilesServiceImplTest { - private GroovyFilesServiceImpl service = new GroovyFilesServiceImpl(); + private final GroovyFilesServiceImpl service = new GroovyFilesServiceImpl(); private Session session; private Node scriptRoot; @@ -56,7 +55,7 @@ void setup() throws RepositoryException { } @Test - void importGroovyFileReimport() throws URISyntaxException, RepositoryException, JAXBException, IOException { + void importGroovyFileReimport() throws URISyntaxException, RepositoryException, IOException { URL testfileUrl = getClass().getResource("/updater.groovy"); URL testfileProperties = getClass().getResource("/updater.properties"); @@ -71,7 +70,7 @@ void importGroovyFileReimport() throws URISyntaxException, RepositoryException, } @Test - void importGroovyFile() throws URISyntaxException, RepositoryException, JAXBException, IOException { + void importGroovyFile() throws URISyntaxException, RepositoryException, IOException { URL testfileUrl = getClass().getResource("/updater.groovy"); URL testfileProperties = getClass().getResource("/updater.properties"); @@ -85,7 +84,7 @@ void importGroovyFile() throws URISyntaxException, RepositoryException, JAXBExce } @Test - void importGroovyFileScript() throws URISyntaxException, RepositoryException, JAXBException, IOException { + void importGroovyFileScript() throws URISyntaxException, RepositoryException, IOException { URL testfileUrl = getClass().getResource("/updater-script.groovy"); URL testfileProperties = getClass().getResource("/updater.properties"); File file = new File(testfileUrl.toURI()); @@ -100,7 +99,7 @@ void importGroovyFileScript() throws URISyntaxException, RepositoryException, JA } @Test - void importGroovyFileWithParametersFile() throws URISyntaxException, RepositoryException, JAXBException, IOException { + void importGroovyFileWithParametersFile() throws URISyntaxException, RepositoryException, IOException { URL testfileUrl = getClass().getResource("/updater-ext.groovy"); URL testfileProperties = getClass().getResource("/updater.properties"); diff --git a/updatersync/src/test/resources/updater-ext.groovy b/updatersync/src/test/resources/updater-ext.groovy index b414876..7a97ece 100644 --- a/updatersync/src/test/resources/updater-ext.groovy +++ b/updatersync/src/test/resources/updater-ext.groovy @@ -11,7 +11,7 @@ import javax.jcr.Node (It should allow any notations, for the stripping etc.. for example a description on how the XPath query should be like //element(*, hippo:document)[mixin:types='project:example'] or the parameters field, describing like: { "foobar": [ "bar", "foo"]}''', path = "") -@Bootstrap(reload = true, sequence = 99999.0d) +@Bootstrap(reload = true) class TestUpdater extends BaseNodeUpdateVisitor { boolean doUpdate(Node node) { log.info "manipulate node < > & an %^&* /> {}", node.path diff --git a/updatersync/src/test/resources/updater-script.groovy b/updatersync/src/test/resources/updater-script.groovy index 5d080d9..4a0cc3f 100644 --- a/updatersync/src/test/resources/updater-script.groovy +++ b/updatersync/src/test/resources/updater-script.groovy @@ -11,7 +11,7 @@ import javax.jcr.Node for example a description on how the XPath query should be like //element(*, hippo:document)[mixin:types='project:example'] or the parameters field, describing like: { "foobar": [ "bar", "foo"]}''', path = "") -@Bootstrap(reload = true, sequence = 99999.0d) +@Bootstrap(reload = true) class TestUpdater extends BaseNodeUpdateVisitor { boolean doUpdate(Node node) { log.info "manipulate node < > & an %^&* /> {}", node.path diff --git a/updatersync/src/test/resources/updater.groovy b/updatersync/src/test/resources/updater.groovy index b379564..c548378 100644 --- a/updatersync/src/test/resources/updater.groovy +++ b/updatersync/src/test/resources/updater.groovy @@ -11,7 +11,7 @@ import javax.jcr.Node (It should allow any notations, for the stripping etc.. for example a description on how the XPath query should be like //element(*, hippo:document)[mixin:types='project:example'] or the parameters field, describing like: { "foobar": [ "bar", "foo"]}''', path = "") -@Bootstrap(reload = true, sequence = 99999.0d) +@Bootstrap(reload = true) class TestUpdater extends BaseNodeUpdateVisitor { boolean doUpdate(Node node) { log.info "manipulate node < > & an %^&* /> {}", node.path From a113e6f1eb701305780eb1290f6229f6f3f59947 Mon Sep 17 00:00:00 2001 From: Joost <32291838+Joostvzanden@users.noreply.github.com> Date: Sun, 22 Jan 2023 16:36:26 +0100 Subject: [PATCH 04/15] feature/log-target-support (#24) * feature/log-target-support added possibility to add log target to annotation * Use enum for logtarget Co-authored-by: joost van zanden Co-authored-by: Joost Oudeman --- .../hippo/groovy/annotations/Updater.java | 18 +++++++++++++ .../hippo/groovy/PropertyCollector.java | 7 ++++- .../openweb/hippo/groovy/model/Constants.java | 1 + .../src/test/java/YamlGeneratorTest.java | 9 ++++--- .../updaterdata/updater-logtarget.groovy | 18 +++++++++++++ .../updaterdata/updater-logtarget.yaml | 26 +++++++++++++++++++ 6 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 bootstrapgenerator/src/test/resources/updaterdata/updater-logtarget.groovy create mode 100644 bootstrapgenerator/src/test/resources/updaterdata/updater-logtarget.yaml diff --git a/annotations/src/main/java/nl/openweb/hippo/groovy/annotations/Updater.java b/annotations/src/main/java/nl/openweb/hippo/groovy/annotations/Updater.java index 94cb015..296456a 100644 --- a/annotations/src/main/java/nl/openweb/hippo/groovy/annotations/Updater.java +++ b/annotations/src/main/java/nl/openweb/hippo/groovy/annotations/Updater.java @@ -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 ""; @@ -44,4 +60,6 @@ long throttle() default 1000L; String mixin() default ""; + + LogTarget logTarget() default LogTarget.DEFAULT; } diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/PropertyCollector.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/PropertyCollector.java index ad0a5dd..30d0543 100644 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/PropertyCollector.java +++ b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/PropertyCollector.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.InvalidPathException; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; @@ -31,6 +32,7 @@ import static nl.openweb.hippo.groovy.model.Constants.PropertyName.HIPPOSYS_BATCHSIZE; import static nl.openweb.hippo.groovy.model.Constants.PropertyName.HIPPOSYS_DESCRIPTION; import static nl.openweb.hippo.groovy.model.Constants.PropertyName.HIPPOSYS_DRYRUN; +import static nl.openweb.hippo.groovy.model.Constants.PropertyName.HIPPOSYS_LOGTARGET; import static nl.openweb.hippo.groovy.model.Constants.PropertyName.HIPPOSYS_PARAMETERS; import static nl.openweb.hippo.groovy.model.Constants.PropertyName.HIPPOSYS_PATH; import static nl.openweb.hippo.groovy.model.Constants.PropertyName.HIPPOSYS_QUERY; @@ -56,7 +58,7 @@ private static String getValueOrFileContent(final ScriptClass script, final File if (file.exists()) { try { return ScriptClassFactory.readFileEnsuringLinuxLineEnding(file); - } catch (IOException e) { + } catch (IOException | InvalidPathException e) { //do nothing, it's fine } } @@ -78,6 +80,9 @@ public static Map getPropertiesForUpdater(ScriptClass script, Fi if (StringUtils.isNotBlank(updater.mixin())) { addPropertyIfNotEmpty(properties, JCR_MIXIN_TYPES, createMultiValueProperty(updater.mixin())); } + if (StringUtils.isNotBlank(updater.logTarget().toString())) { + addPropertyIfNotEmpty(properties, HIPPOSYS_LOGTARGET, updater.logTarget().toString()); + } addPropertyIfNotEmpty(properties, HIPPOSYS_PARAMETERS, getValueOrFileContent(script, sourceDir, updater.parameters())); if (StringUtils.isBlank(updater.xpath())) { addPropertyIfNotEmpty(properties, HIPPOSYS_PATH, updater.path()); diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/Constants.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/Constants.java index 0d64a13..961eb53 100644 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/Constants.java +++ b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/model/Constants.java @@ -42,6 +42,7 @@ private PropertyName() { public static final String JCR_MIXIN_TYPES = "jcr:mixinTypes"; public static final String HIPPOSYS_BATCHSIZE = "hipposys:batchsize"; public static final String HIPPOSYS_DRYRUN = "hipposys:dryrun"; + public static final String HIPPOSYS_LOGTARGET = "hipposys:logtarget"; public static final String HIPPOSYS_PARAMETERS = "hipposys:parameters"; public static final String HIPPOSYS_QUERY = "hipposys:query"; public static final String HIPPOSYS_SCRIPT = "hipposys:script"; diff --git a/bootstrapgenerator/src/test/java/YamlGeneratorTest.java b/bootstrapgenerator/src/test/java/YamlGeneratorTest.java index df10d8b..e4fa3f6 100644 --- a/bootstrapgenerator/src/test/java/YamlGeneratorTest.java +++ b/bootstrapgenerator/src/test/java/YamlGeneratorTest.java @@ -33,7 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; -public class YamlGeneratorTest { +class YamlGeneratorTest { final File sourceDir = new File(getClass().getResource("/").toURI()); @@ -46,12 +46,12 @@ public void setup() { } @Test - public void testScrubbingAnnotations() throws IOException, URISyntaxException { + void testScrubbingAnnotations() throws IOException, URISyntaxException { checkGeneration("sub/annotatestrip"); } @Test - public void testUpdatescriptCreating() throws URISyntaxException, IOException { + void testUpdatescriptCreating() throws URISyntaxException, IOException { checkGeneration("updater"); checkGeneration("updater2"); checkGeneration("updater3"); @@ -61,6 +61,7 @@ public void testUpdatescriptCreating() throws URISyntaxException, IOException { checkGeneration("updaterdata/updater5"); checkGeneration("updaterdata/updater6"); checkGeneration("updaterdata/updater7"); + checkGeneration("updaterdata/updater-logtarget"); } private void checkGeneration(String name) throws URISyntaxException, IOException { @@ -79,7 +80,7 @@ private void checkGeneration(String name) throws URISyntaxException, IOException } @Test - public void checkDefaultingContentRootYamlFile() throws URISyntaxException, IOException { + void checkDefaultingContentRootYamlFile() throws URISyntaxException, IOException { Generator.setDefaultContentRoot(Bootstrap.ContentRoot.REGISTRY); URL testfileUrl = getClass().getResource("updater.groovy"); URL testfileResultUrlYaml = getClass().getResource("updater.yaml"); diff --git a/bootstrapgenerator/src/test/resources/updaterdata/updater-logtarget.groovy b/bootstrapgenerator/src/test/resources/updaterdata/updater-logtarget.groovy new file mode 100644 index 0000000..3a7b143 --- /dev/null +++ b/bootstrapgenerator/src/test/resources/updaterdata/updater-logtarget.groovy @@ -0,0 +1,18 @@ +import nl.openweb.hippo.groovy.annotations.Bootstrap +import nl.openweb.hippo.groovy.annotations.Updater +import org.onehippo.repository.update.BaseNodeUpdateVisitor + +import javax.jcr.Node + +@Bootstrap(contentroot = Bootstrap.ContentRoot.REGISTRY, reload = true, version = "1.6") +@Updater(name = "Test Updater Log Target", path = "/content", description = "Test thing", batchSize = 1L, throttle = 200L, dryRun = true, parameters = "{prop: val}", logTarget = Updater.LogTarget.REPOSITORY) +class TestUpdaterLogTarget extends BaseNodeUpdateVisitor { + boolean doUpdate(Node node) { + log.info "manipulate node < > & an %^&* /> {}", node.path + return true + } + + boolean undoUpdate(Node node) { + throw new UnsupportedOperationException('Updater does not implement undoUpdate method') + } +} \ No newline at end of file diff --git a/bootstrapgenerator/src/test/resources/updaterdata/updater-logtarget.yaml b/bootstrapgenerator/src/test/resources/updaterdata/updater-logtarget.yaml new file mode 100644 index 0000000..baa14e1 --- /dev/null +++ b/bootstrapgenerator/src/test/resources/updaterdata/updater-logtarget.yaml @@ -0,0 +1,26 @@ +definitions: + config: + /hippo:configuration/hippo:update/hippo:registry/Test Updater Log Target: + jcr:primaryType: hipposys:updaterinfo + hipposys:batchsize: 1 + hipposys:description: Test thing + hipposys:dryrun: true + hipposys:logtarget: REPOSITORY + hipposys:parameters: '{prop: val}' + hipposys:path: /content + hipposys:script: |- + import org.onehippo.repository.update.BaseNodeUpdateVisitor + + import javax.jcr.Node + + class TestUpdaterLogTarget extends BaseNodeUpdateVisitor { + boolean doUpdate(Node node) { + log.info "manipulate node < > & an %^&* /> {}", node.path + return true + } + + boolean undoUpdate(Node node) { + throw new UnsupportedOperationException('Updater does not implement undoUpdate method') + } + } + hipposys:throttle: 200 From 0309784f13b03cb0fc0b554470956594e801c55d Mon Sep 17 00:00:00 2001 From: Joost O Date: Sun, 22 Jan 2023 16:37:23 +0100 Subject: [PATCH 05/15] update dependencies (#25) --- pom.xml | 26 +++++++++---------- sampleproject/pom.xml | 6 ----- .../hippo/groovy/GroovyFilesService.java | 5 ---- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 480ce21..728dfd2 100644 --- a/pom.xml +++ b/pom.xml @@ -76,15 +76,15 @@ 2.11.0 3.12.0 - 3.0.9 - 1.29 - 12.6.18 - 12.6.18 + 3.0.14 + 1.33 + 15.1.3 + 15.1.3 2.0 - 5.8.1 - 5.8.1 - 2.21.7 - 3.8.3 + 5.9.2 + 5.9.2 + 2.21.14 + 3.8.7 3.2.0 3.8.1 3.2.1 @@ -99,13 +99,13 @@ 3.2.0 3.9.1 3.0.0-M5 - 3.6.1 - 3.6.1 + 3.7.1 + 3.7.1 0.8.7 - 3.4.1 - 1.5.4 + 3.5.0 + 1.6.0 UTF-8 - 1.7.32 + 2.0.6 6.3.2 diff --git a/sampleproject/pom.xml b/sampleproject/pom.xml index 7e7d5ff..9bcd9a8 100644 --- a/sampleproject/pom.xml +++ b/sampleproject/pom.xml @@ -81,10 +81,4 @@ - - - openweb-maven-releases - https://maven.open-web.nl/content/repositories/releases/ - - \ No newline at end of file diff --git a/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesService.java b/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesService.java index e4bc125..3dd7634 100644 --- a/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesService.java +++ b/updatersync/src/main/java/nl/openweb/hippo/groovy/GroovyFilesService.java @@ -40,11 +40,6 @@ import javax.jcr.RepositoryException; import javax.jcr.Session; -import org.onehippo.cms7.services.SingletonService; -import org.onehippo.cms7.services.WhiteboardService; - -@SingletonService -@WhiteboardService public interface GroovyFilesService { void importGroovyFiles(Session session, File file); From a3a7e8d8014e5735949c4b18aad3b2321a79a1c2 Mon Sep 17 00:00:00 2001 From: Michel Drenthe Date: Wed, 25 Jan 2023 21:36:56 +0100 Subject: [PATCH 06/15] slf4j-log4j12 has been renamed/relocated to slf4j-reload4 --- mavenplugin/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mavenplugin/pom.xml b/mavenplugin/pom.xml index 504a29a..1b9adf8 100644 --- a/mavenplugin/pom.xml +++ b/mavenplugin/pom.xml @@ -56,7 +56,7 @@ org.slf4j - slf4j-log4j12 + slf4j-reload4j test diff --git a/pom.xml b/pom.xml index 728dfd2..f978016 100644 --- a/pom.xml +++ b/pom.xml @@ -187,7 +187,7 @@ org.slf4j - slf4j-log4j12 + slf4j-reload4j ${slf4j.version} test From fbf1ef6661840bce5bf9cac518da25cf6b4e1a49 Mon Sep 17 00:00:00 2001 From: Michel Drenthe Date: Wed, 25 Jan 2023 21:47:44 +0100 Subject: [PATCH 07/15] Upgrade Groovy to version 4 --- bootstrapgenerator/pom.xml | 2 +- pom.xml | 4 ++-- updatersync/pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bootstrapgenerator/pom.xml b/bootstrapgenerator/pom.xml index 2a59adf..6415730 100644 --- a/bootstrapgenerator/pom.xml +++ b/bootstrapgenerator/pom.xml @@ -45,7 +45,7 @@ ${project.version} - org.codehaus.groovy + org.apache.groovy groovy diff --git a/pom.xml b/pom.xml index 728dfd2..6178c12 100644 --- a/pom.xml +++ b/pom.xml @@ -76,7 +76,7 @@ 2.11.0 3.12.0 - 3.0.14 + 4.0.8 1.33 15.1.3 15.1.3 @@ -138,7 +138,7 @@ ${plexus-utils.version} - org.codehaus.groovy + org.apache.groovy groovy ${groovy.version} diff --git a/updatersync/pom.xml b/updatersync/pom.xml index 6109146..c707d91 100644 --- a/updatersync/pom.xml +++ b/updatersync/pom.xml @@ -55,7 +55,7 @@ compile - org.codehaus.groovy + org.apache.groovy groovy provided From 2ad301632df0db1f38cb9ce3cbf5f418ce31311e Mon Sep 17 00:00:00 2001 From: Michel Drenthe Date: Thu, 26 Jan 2023 07:41:01 +0100 Subject: [PATCH 08/15] Add github pipeline to project --- .github/workflows/maven.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..9522de8 --- /dev/null +++ b/.github/workflows/maven.yml @@ -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: Update dependency graph + uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 From 5a1b7feec8704377a5dbb65c9de8ce5c21600549 Mon Sep 17 00:00:00 2001 From: Michel Drenthe Date: Wed, 25 Jan 2023 21:42:59 +0100 Subject: [PATCH 09/15] Removal of plexus plugin Apache: https://cwiki.apache.org/confluence/display/MAVEN/Plexus-utils+replacement Informs to remove the plexus plugin and replace features with there commons plugins --- .../java/nl/openweb/hippo/groovy/ScriptClassFactory.java | 5 +++-- .../src/test/java/ScriptClassFactoryTest.java | 5 +++-- bootstrapgenerator/src/test/java/Utilities.java | 7 ++++--- bootstrapgenerator/src/test/java/YamlGeneratorTest.java | 6 +++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/ScriptClassFactory.java b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/ScriptClassFactory.java index dc97518..17b06cf 100644 --- a/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/ScriptClassFactory.java +++ b/bootstrapgenerator/src/main/java/nl/openweb/hippo/groovy/ScriptClassFactory.java @@ -18,16 +18,17 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.Charset; import java.util.List; import javax.jcr.NamespaceException; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.spi.NameFactory; import org.apache.jackrabbit.spi.commons.conversion.NameParser; import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl; import org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping; -import org.codehaus.plexus.util.FileUtils; import groovy.lang.GroovyClassLoader; import nl.openweb.hippo.groovy.exception.ScriptParseException; @@ -108,7 +109,7 @@ public static ScriptClass getInterpretingClass(final File file, final boolean ke } public static String readFileEnsuringLinuxLineEnding(final File file) throws IOException { - String content = FileUtils.fileRead(file); + String content = FileUtils.readFileToString(file, Charset.defaultCharset()); if (content.contains(LINE_END_MAC)) { content = content.replace(LINE_END_WINDOWS, LINE_END_LINUX) .replace(LINE_END_MAC, LINE_END_LINUX); diff --git a/bootstrapgenerator/src/test/java/ScriptClassFactoryTest.java b/bootstrapgenerator/src/test/java/ScriptClassFactoryTest.java index 438a03e..9356218 100644 --- a/bootstrapgenerator/src/test/java/ScriptClassFactoryTest.java +++ b/bootstrapgenerator/src/test/java/ScriptClassFactoryTest.java @@ -18,8 +18,9 @@ import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.Charset; -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -43,7 +44,7 @@ private void testWithName(String updaterName) throws IOException, URISyntaxExcep final File tempFile = File.createTempFile("updater", "mysuffix"); tempFile.deleteOnExit(); - FileUtils.fileWrite(tempFile, content.replace("Test Updater", updaterName)); + FileUtils.writeStringToFile(tempFile,content.replace("Test Updater", updaterName), Charset.defaultCharset()); ScriptClassFactory.getInterpretingClass(tempFile); } diff --git a/bootstrapgenerator/src/test/java/Utilities.java b/bootstrapgenerator/src/test/java/Utilities.java index e52a591..753d58d 100644 --- a/bootstrapgenerator/src/test/java/Utilities.java +++ b/bootstrapgenerator/src/test/java/Utilities.java @@ -16,13 +16,14 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.Charset; -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; public class Utilities { public static void enforceWindowsFileEndings(File file) throws IOException { - String content = FileUtils.fileRead(file); + String content = FileUtils.readFileToString(file, Charset.defaultCharset()); String lfContent = content.replaceAll("\r\n", "\n"); - FileUtils.fileWrite(file, lfContent.replaceAll("\n", "\r\n")); + FileUtils.writeStringToFile(file,lfContent.replaceAll("\n", "\r\n"), Charset.defaultCharset()); } } diff --git a/bootstrapgenerator/src/test/java/YamlGeneratorTest.java b/bootstrapgenerator/src/test/java/YamlGeneratorTest.java index e4fa3f6..f941fd1 100644 --- a/bootstrapgenerator/src/test/java/YamlGeneratorTest.java +++ b/bootstrapgenerator/src/test/java/YamlGeneratorTest.java @@ -18,9 +18,9 @@ import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.Charset; - -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -91,7 +91,7 @@ void checkDefaultingContentRootYamlFile() throws URISyntaxException, IOException final String yaml = getYamlString(YamlGenerator.getUpdateYamlScript(sourceDir, getInterpretingClass(file))); - String unExpectedContentYaml = FileUtils.fileRead(resultFileYaml); + String unExpectedContentYaml = FileUtils.readFileToString(resultFileYaml, Charset.defaultCharset()); assertNotEquals("failed yaml parsing of updater", unExpectedContentYaml, yaml); } } From 0b4179ed9c63c7a5524f5cb60cff0255f5651e8d Mon Sep 17 00:00:00 2001 From: Michel Drenthe Date: Wed, 25 Jan 2023 21:45:07 +0100 Subject: [PATCH 10/15] Adding pom file adjustments --- bootstrapgenerator/pom.xml | 4 ---- pom.xml | 6 ------ 2 files changed, 10 deletions(-) diff --git a/bootstrapgenerator/pom.xml b/bootstrapgenerator/pom.xml index 6415730..7543b1b 100644 --- a/bootstrapgenerator/pom.xml +++ b/bootstrapgenerator/pom.xml @@ -31,10 +31,6 @@ commons-io commons-io - - org.codehaus.plexus - plexus-utils - org.apache.commons commons-lang3 diff --git a/pom.xml b/pom.xml index 27791fe..32d3e5a 100644 --- a/pom.xml +++ b/pom.xml @@ -102,7 +102,6 @@ 3.7.1 3.7.1 0.8.7 - 3.5.0 1.6.0 UTF-8 2.0.6 @@ -132,11 +131,6 @@ ${maven.plugin.annotations.version} provided - - org.codehaus.plexus - plexus-utils - ${plexus-utils.version} - org.apache.groovy groovy From 939047e1e546afebfc6349aa3a40fd1bdb45297a Mon Sep 17 00:00:00 2001 From: Michel Drenthe Date: Thu, 26 Jan 2023 07:37:53 +0100 Subject: [PATCH 11/15] Add space between parameters --- bootstrapgenerator/src/test/java/Utilities.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrapgenerator/src/test/java/Utilities.java b/bootstrapgenerator/src/test/java/Utilities.java index 753d58d..a512532 100644 --- a/bootstrapgenerator/src/test/java/Utilities.java +++ b/bootstrapgenerator/src/test/java/Utilities.java @@ -24,6 +24,6 @@ public class Utilities { public static void enforceWindowsFileEndings(File file) throws IOException { String content = FileUtils.readFileToString(file, Charset.defaultCharset()); String lfContent = content.replaceAll("\r\n", "\n"); - FileUtils.writeStringToFile(file,lfContent.replaceAll("\n", "\r\n"), Charset.defaultCharset()); + FileUtils.writeStringToFile(file, lfContent.replaceAll("\n", "\r\n"), Charset.defaultCharset()); } } From 9b08823af75a7fd7e17d9564c26ace0f83deb1b3 Mon Sep 17 00:00:00 2001 From: Michel Drenthe Date: Thu, 26 Jan 2023 07:50:27 +0100 Subject: [PATCH 12/15] Change version of dependency graph --- .github/workflows/maven.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9522de8..b31e137 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -31,5 +31,5 @@ jobs: 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: Update dependency graph - uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 + - name: Maven Dependency Tree Dependency Submission + uses: advanced-security/maven-dependency-submission-action@v2.0.1 From 96bdfda2a21421bd4f7ef52a7f7f99df5ae1a068 Mon Sep 17 00:00:00 2001 From: Michel Drenthe Date: Thu, 26 Jan 2023 08:04:08 +0100 Subject: [PATCH 13/15] Not working action removed --- .github/workflows/maven.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index b31e137..0ab493f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,7 +29,3 @@ jobs: 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@v2.0.1 From 605be866be4135e2c2b3a5bc6e98d1b53d8588ca Mon Sep 17 00:00:00 2001 From: Michel Drenthe Date: Thu, 26 Jan 2023 08:08:37 +0100 Subject: [PATCH 14/15] Try multi module version --- .github/workflows/maven.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 0ab493f..9440d52 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,3 +29,7 @@ jobs: 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 From cf164fc3f202823d185b72b42a4573685c2cea10 Mon Sep 17 00:00:00 2001 From: Michel Drenthe Date: Thu, 26 Jan 2023 08:20:15 +0100 Subject: [PATCH 15/15] Add provided scope to maven-plugin-api dependency Resolves issue #27 --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 27791fe..948a50d 100644 --- a/pom.xml +++ b/pom.xml @@ -125,6 +125,7 @@ org.apache.maven maven-plugin-api ${maven.plugin.api.version} + provided org.apache.maven.plugin-tools