diff --git a/.travis.yml b/.travis.yml index 674b09ef28..382fa489ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ dist: bionic +os: linux language: java cache: directories: @@ -33,6 +34,24 @@ jobs: script: ./scripts/travis-build-test.sh if: (branch != gh-pages) AND (branch != dev_oomph_setup) AND (tag IS blank) jdk: openjdk11 + - name: Build & Test (openjdk11Windows) + language: bash + os: windows + cache: + directories: + - /c/ProgramData/chocolatey/lib/maven/apache-maven-3.6.3 + - /c/Program Files/OpenJDK/openjdk-11.0.8_10 + before_install: + - choco install openjdk11 --version 11.0.8.10 -y + - choco install maven --version 3.6.3 -y + - powershell refreshenv + - export PATH=${PATH}:"/c/ProgramData/chocolatey/lib/maven/apache-maven-3.6.3/bin" + - export PATH=${PATH}:"/c/Program Files/OpenJDK/openjdk-11.0.8_10/bin" + - export JAVA_HOME="/c/Program Files/OpenJDK/openjdk-11.0.8_10/" + install: [] + script: + - ./scripts/travis-build-test.sh + if: (branch != gh-pages) AND (branch != dev_oomph_setup) AND (tag IS blank) - name: Build docs as PDF install: [] script: ./scripts/travis-build-docs.sh @@ -53,4 +72,4 @@ jobs: install: [] script: ./scripts/travis-sync-docs.sh if: (branch = master) AND (type != pull_request) AND (fork = false) AND (tag IS blank) - jdk: openjdk11 + jdk: openjdk11 \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java b/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java index 2ab5b487f8..4bd3880670 100644 --- a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java +++ b/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java @@ -30,7 +30,7 @@ public JavaUtil() { /** * Returns the Object version of a Java primitive or the input if the input isn't a java primitive - * + * * @param simpleType * String * @return the corresponding object wrapper type simple name of the input if the input is the name of a diff --git a/cobigen/cobigen-propertyplugin/pom.xml b/cobigen/cobigen-propertyplugin/pom.xml index ef163c65ac..611eec3b69 100644 --- a/cobigen/cobigen-propertyplugin/pom.xml +++ b/cobigen/cobigen-propertyplugin/pom.xml @@ -2,7 +2,7 @@ 4.0.0 propertyplugin jar - 7.0.0 + 7.1.0 CobiGen - Property File Plug-In CobiGen - Property File Plug-In diff --git a/cobigen/cobigen-propertyplugin/src/main/java/com/devonfw/cobigen/propertyplugin/PropertyMerger.java b/cobigen/cobigen-propertyplugin/src/main/java/com/devonfw/cobigen/propertyplugin/PropertyMerger.java index a3c95e42b4..e0e962b4a1 100644 --- a/cobigen/cobigen-propertyplugin/src/main/java/com/devonfw/cobigen/propertyplugin/PropertyMerger.java +++ b/cobigen/cobigen-propertyplugin/src/main/java/com/devonfw/cobigen/propertyplugin/PropertyMerger.java @@ -7,8 +7,8 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -19,6 +19,7 @@ import com.devonfw.cobigen.api.exception.MergeException; import com.devonfw.cobigen.api.extension.Merger; +import com.devonfw.cobigen.api.util.SystemUtil; /** * The {@link PropertyMerger} merges two property files. One being provided as the base file and the second @@ -26,9 +27,6 @@ */ public class PropertyMerger implements Merger { - /** Line separator, e.g. for windows '\r\n' */ - public static final String LINE_SEPARATOR = java.lang.System.getProperty("line.separator"); - /** * Merger Type to be registered */ @@ -73,9 +71,11 @@ public String merge(File base, String patch, String targetCharset) throws MergeE throw new MergeException(base, "Could not read generated patch.", e); } Set conflicts = getConflictingProperties(baseProperties, patchProperties); - try { - BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(base), targetCharset)); - return concatContents(conflicts, br, patch); + try (FileInputStream in = new FileInputStream(base); + InputStreamReader reader = new InputStreamReader(in, targetCharset)) { + BufferedReader br = new BufferedReader(reader); + String lineDelimiter = SystemUtil.determineLineDelimiter(base.toPath(), targetCharset); + return concatContents(conflicts, br, patch, lineDelimiter); } catch (IOException e) { throw new MergeException(base, "Could not read base file.", e); } @@ -91,16 +91,18 @@ public String merge(File base, String patch, String targetCharset) throws MergeE * {@link BufferedReader} reading the base file * @param patch * which should be applied + * @param lineSeparator + * the line Separator to use for the file * @return merged file contents * @throws IOException * if the base file could not be read oder accessed * @author mbrunnli (11.03.2013) */ - private String concatContents(Set conflicts, BufferedReader baseFileReader, String patch) - throws IOException { + private String concatContents(Set conflicts, BufferedReader baseFileReader, String patch, + String lineSeparator) throws IOException { List recordedComments = new LinkedList<>(); - Map collection = new HashMap<>(); + Map collection = new LinkedHashMap<>(); String line; boolean lastLineWasComment = false; int count = 0; // count is used below to maintain uniqueness in the hash @@ -109,10 +111,10 @@ private String concatContents(Set conflicts, BufferedReader baseFileRead line = line.trim(); // adding key of the respective value to the collection if (line.startsWith("#")) { - collection.put("recordedComments" + count, LINE_SEPARATOR + line); + collection.put("recordedComments" + count, lineSeparator + line); if (lastLineWasComment) { String lastComment = recordedComments.remove(recordedComments.size() - 1); - recordedComments.add(lastComment + LINE_SEPARATOR + line); + recordedComments.add(lastComment + lineSeparator + line); } else { lastLineWasComment = true; recordedComments.add(line); @@ -120,7 +122,7 @@ private String concatContents(Set conflicts, BufferedReader baseFileRead } else { lastLineWasComment = false; if (!line.trim().isEmpty()) { - collection.put(line.substring(0, line.indexOf("=")), LINE_SEPARATOR + line); + collection.put(line.substring(0, line.indexOf("=")), lineSeparator + line); } } count++; @@ -131,28 +133,28 @@ private String concatContents(Set conflicts, BufferedReader baseFileRead String lastObservedComment = null; int observedEmptyLines = 0; count = 0; - for (String patchLine : patch.split(LINE_SEPARATOR)) { + for (String patchLine : patch.split(lineSeparator)) { m = p.matcher(patchLine); if (m.matches()) { // no conflicts if (!conflicts.contains(m.group(1))) { - collection.put(m.group(1), LINE_SEPARATOR + patchLine); + collection.put(m.group(1), lineSeparator + patchLine); observedEmptyLines = 0; } else { if (patchOverrides) { // override the original by patch file // patchLine; - collection.put(m.group(1), LINE_SEPARATOR + patchLine); + collection.put(m.group(1), lineSeparator + patchLine); observedEmptyLines = 0; } } } else if (patchLine.startsWith("#")) { // record comment over multiple lines if (lastObservedComment != null) { - lastObservedComment += LINE_SEPARATOR + patchLine; - collection.put("lastObservedComment" + count, LINE_SEPARATOR + lastObservedComment); + lastObservedComment += lineSeparator + patchLine; + collection.put("lastObservedComment" + count, lineSeparator + lastObservedComment); } else { lastObservedComment = patchLine; - collection.put("lastObservedComment" + count, LINE_SEPARATOR + lastObservedComment); + collection.put("lastObservedComment" + count, lineSeparator + lastObservedComment); } } else { if (lastObservedComment == null && patchLine.trim().isEmpty()) { @@ -162,16 +164,16 @@ private String concatContents(Set conflicts, BufferedReader baseFileRead // comment if not so if (lastObservedComment != null && !recordedComments.contains(lastObservedComment)) { for (int i = 0; i < observedEmptyLines; i++) { - collection.put("_blank" + count, LINE_SEPARATOR); + collection.put("_blank" + count, lineSeparator); } - collection.put("lastObservedComment" + count, LINE_SEPARATOR + lastObservedComment); + collection.put("lastObservedComment" + count, lineSeparator + lastObservedComment); } lastObservedComment = null; observedEmptyLines = 0; if (!patchLine.trim().isEmpty()) { // patchLine; - collection.put("patchLineNotEmpty" + count, LINE_SEPARATOR + patchLine); + collection.put("patchLineNotEmpty" + count, lineSeparator + patchLine); observedEmptyLines = 0; } } diff --git a/cobigen/cobigen-propertyplugin/src/test/java/com/devonfw/cobigen/propertyplugin/PropertyMergerTest.java b/cobigen/cobigen-propertyplugin/src/test/java/com/devonfw/cobigen/propertyplugin/PropertyMergerTest.java index 7b19ee8482..d332586c41 100644 --- a/cobigen/cobigen-propertyplugin/src/test/java/com/devonfw/cobigen/propertyplugin/PropertyMergerTest.java +++ b/cobigen/cobigen-propertyplugin/src/test/java/com/devonfw/cobigen/propertyplugin/PropertyMergerTest.java @@ -1,14 +1,13 @@ package com.devonfw.cobigen.propertyplugin; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.File; import java.io.FileReader; import org.apache.commons.io.IOUtils; -import org.junit.Assert; import org.junit.Test; -import com.devonfw.cobigen.propertyplugin.PropertyMerger; - import junit.framework.TestCase; /** @@ -32,10 +31,10 @@ public void testPropertyMergeOverride() throws Exception { PropertyMerger pMerger = new PropertyMerger("", true); String mergedPropFile = pMerger.merge(base, IOUtils.toString(new FileReader(new File(testFileRootPath + "Name.ftl"))), "UTF-8"); - Assert.assertTrue("NachNameOverride", mergedPropFile.contains("NachNameOverride")); - Assert.assertFalse("nachNameOriginal", mergedPropFile.contains("nachNameOriginal")); - Assert.assertTrue("FirstName", mergedPropFile.contains("firstName")); - Assert.assertTrue("lastName", mergedPropFile.contains("lastName")); + assertThat(mergedPropFile).contains("NachNameOverride"); + assertThat(mergedPropFile).doesNotContain("nachNameOriginal"); + assertThat(mergedPropFile).contains("firstName"); + assertThat(mergedPropFile).contains("lastName"); } /** @@ -49,10 +48,10 @@ public void testPropertyMergeWithoutOverride() throws Exception { PropertyMerger pMerger = new PropertyMerger("", false); String mergedPropFile = pMerger.merge(base, IOUtils.toString(new FileReader(new File(testFileRootPath + "Name.ftl"))), "UTF-8"); - Assert.assertFalse("NachNameOverride", mergedPropFile.contains("NachNameOverride")); - Assert.assertTrue("nachNameOriginal", mergedPropFile.contains("nachNameOriginal")); - Assert.assertTrue("FirstName", mergedPropFile.contains("firstName")); - Assert.assertTrue("lastName", mergedPropFile.contains("lastName")); + assertThat(mergedPropFile).doesNotContain("NachNameOverride"); + assertThat(mergedPropFile).contains("nachNameOriginal"); + assertThat(mergedPropFile).contains("firstName"); + assertThat(mergedPropFile).contains("lastName"); } } diff --git a/documentation/master-cobigen.asciidoc b/documentation/master-cobigen.asciidoc index 1c394b26d1..d4ece545c1 100644 --- a/documentation/master-cobigen.asciidoc +++ b/documentation/master-cobigen.asciidoc @@ -21,7 +21,7 @@ DISCLAIMER: All Cobigen plugins are compatible with the latest release of Devonf * CobiGen - Java Plug-in v7.0.0 * CobiGen - XML Plug-in v7.0.0 * CobiGen - TypeScript Plug-in v7.1.0 -* CobiGen - Property Plug-in v7.0.0 +* CobiGen - Property Plug-in v7.1.0 * CobiGen - Text Merger v7.1.0 * CobiGen - JSON Plug-in v7.0.0 * CobiGen - HTML Plug-in v7.0.0