diff --git a/cobigen/cobigen-textmerger/pom.xml b/cobigen/cobigen-textmerger/pom.xml index a554781814..ba7c95ba8f 100644 --- a/cobigen/cobigen-textmerger/pom.xml +++ b/cobigen/cobigen-textmerger/pom.xml @@ -2,7 +2,7 @@ 4.0.0 textmerger jar - 2.1.0 + 7.0.0 CobiGen - Text Merger Plug-in CobiGen - Text Merger Plug-in @@ -20,7 +20,7 @@ com.devonfw.cobigen core-api - 5.0.0 + [7.0.0,) @@ -31,7 +31,7 @@ com.devonfw.cobigen core-test - 5.0.0 + [7.0.0,) test diff --git a/cobigen/cobigen-textmerger/src/main/java/com/devonfw/cobigen/textmerger/TextMergerPluginActivator.java b/cobigen/cobigen-textmerger/src/main/java/com/devonfw/cobigen/textmerger/TextMergerPluginActivator.java index 44aa418e50..6c8d03feeb 100644 --- a/cobigen/cobigen-textmerger/src/main/java/com/devonfw/cobigen/textmerger/TextMergerPluginActivator.java +++ b/cobigen/cobigen-textmerger/src/main/java/com/devonfw/cobigen/textmerger/TextMergerPluginActivator.java @@ -2,23 +2,34 @@ import java.util.List; +import com.devonfw.cobigen.api.annotation.Activation; import com.devonfw.cobigen.api.extension.GeneratorPluginActivator; import com.devonfw.cobigen.api.extension.Merger; import com.devonfw.cobigen.api.extension.TriggerInterpreter; import com.google.common.collect.Lists; /** - * This Plugin Activator registers a merger, which only appends the patch text to the original existing file - * @author mbrunnli (06.04.2014) + * This plug-in activator registers a merger, which only appends the patch text to the original existing file */ +@Activation(byMergeStrategy = { TextMergerPluginActivator.TEXTMERGE_APPEND, + TextMergerPluginActivator.TEXTMERGE_APPEND_WITH_NEW_LINE, TextMergerPluginActivator.TEXTMERGE_OVERRIDE }) public class TextMergerPluginActivator implements GeneratorPluginActivator { + /** Merge strategy to append text parts (prefer patch) */ + static final String TEXTMERGE_OVERRIDE = "textmerge_override"; + + /** Merge strategy to append text parts while adding a new line before */ + static final String TEXTMERGE_APPEND_WITH_NEW_LINE = "textmerge_appendWithNewLine"; + + /** Merge strategy to append text parts (prefer base) */ + static final String TEXTMERGE_APPEND = "textmerge_append"; + @Override public List bindMerger() { List merger = Lists.newLinkedList(); - merger.add(new TextAppender("textmerge_append", false)); - merger.add(new TextAppender("textmerge_appendWithNewLine", true)); - merger.add(new TextAppender("textmerge_override", false)); + merger.add(new TextAppender(TEXTMERGE_APPEND, false)); + merger.add(new TextAppender(TEXTMERGE_APPEND_WITH_NEW_LINE, true)); + merger.add(new TextAppender(TEXTMERGE_OVERRIDE, false)); return merger; } diff --git a/cobigen/cobigen-textmerger/src/main/java/com/devonfw/cobigen/textmerger/anchorextension/MergeUtil.java b/cobigen/cobigen-textmerger/src/main/java/com/devonfw/cobigen/textmerger/anchorextension/MergeUtil.java index fe9b7b1cc3..025386dd4c 100644 --- a/cobigen/cobigen-textmerger/src/main/java/com/devonfw/cobigen/textmerger/anchorextension/MergeUtil.java +++ b/cobigen/cobigen-textmerger/src/main/java/com/devonfw/cobigen/textmerger/anchorextension/MergeUtil.java @@ -10,6 +10,8 @@ import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Helper class that implements a few very specific methods to help with working on maps and regular @@ -17,6 +19,9 @@ */ public class MergeUtil { + /** Logger instance. */ + private static final Logger LOG = LoggerFactory.getLogger(MergeUtil.class); + /** * Regular expression matching what correct anchors should look like. */ @@ -50,6 +55,8 @@ public class MergeUtil { * merge(File,String,String) * @param toSplit * The string that is to be split by anchors + * @param defaultMergeStrategy + * the default merge strategy to fall back * @return a LinkedHashMap which contains anchors as keys and the following text as values * @throws Exception * when an anchor contains a wrong definition @@ -58,13 +65,14 @@ public static LinkedHashMap splitByAnchors(String toSplit, Merge throws Exception { LinkedHashMap result = new LinkedHashMap<>(); toSplit.trim(); - if (!StringUtils.substring(toSplit, 0, StringUtils.ordinalIndexOf(toSplit, "\n", 1) - lineSepLength).trim() - .matches(anchorRegexTrimmed)) { + String firstLine = + StringUtils.substring(toSplit, 0, StringUtils.ordinalIndexOf(toSplit, "\n", 1) - lineSepLength + 1).trim(); + if (!firstLine.matches(anchorRegexTrimmed)) { + LOG.debug("Line {} does not match {}", firstLine, anchorRegexTrimmed); throw new Exception( "Incorrect document structure. Anchors are defined but there is no anchor at the start of the document.\n" + "See https://github.com/devonfw/cobigen/wiki/cobigen-textmerger#general and " - + "https://github.com/devonfw/cobigen/wiki/cobigen-textmerger#error-list " - + "for more details"); + + "https://github.com/devonfw/cobigen/wiki/cobigen-textmerger#error-list " + "for more details"); } toSplit = toSplit + System.lineSeparator() + "anchor:::anchorend" + System.lineSeparator(); @@ -227,7 +235,6 @@ public static ArrayList joinKeySetsRetainOrder(Map base, if (checkSame.retainAll(patch.keySet())) { int i = 0; int x = 0; - String tmp = ""; for (Anchor s : base.keySet()) { i++; diff --git a/documentation/master-cobigen.asciidoc b/documentation/master-cobigen.asciidoc index 249c55cfaa..ace127cc6c 100644 --- a/documentation/master-cobigen.asciidoc +++ b/documentation/master-cobigen.asciidoc @@ -22,7 +22,7 @@ DISCLAIMER: All Cobigen plugins are compatible with the latest release of Devonf * CobiGen - XML Plug-in v7.0.0 * CobiGen - TypeScript Plug-in v7.0.0 * CobiGen - Property Plug-in v7.0.0 -* CobiGen - Text Merger v2.1.0 +* CobiGen - Text Merger v7.0.0 * CobiGen - JSON Plug-in v7.0.0 * CobiGen - HTML Plug-in v7.0.0 * CobiGen - Open API Plug-in v7.0.0