JCRVLT-392 enable Travis build for Java8/11 on Linux and Windows

fix some tests to run also on Windows/Java 11
This closes #31

git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/commons/filevault-package-maven-plugin/trunk@1870006 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/.ratignore b/.ratignore
index bc7858d..e0a39c2 100644
--- a/.ratignore
+++ b/.ratignore
@@ -6,4 +6,5 @@
 src/test/resources/test-projects/**/.dummy
 src/test/resources/test-projects/**/*.lst
 src/test/resources/test-projects/**/*.MF
-.mvn/**
\ No newline at end of file
+.mvn/**
+.no-defender.sh
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..56f1ca5
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,67 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+
+# use https://github.com/DanySK/Gravis-CI for Maven Builds on Windows
+
+# Java is not yet supported on Windows, so the build would block.
+# You do not need any setup from Travis, use a plain bash build
+language: bash
+# Enable them all, if you need them.
+os:
+  - linux
+#  - osx
+  - windows
+env:
+  global:
+    # This is a convenience variable for shortening download commands
+    - GRAVIS="https://raw.githubusercontent.com/DanySK/Gravis-CI/master/"
+    # If you use Windows, you may want to disable Windows Defender. It slows down the builds
+    # dramatically, also during cache setup. From a Tanzinul Islam's idea: http://bit.ly/348VPYS,
+    # This work around disables it before caching
+    - NO_WIN_DEFENDER=$(curl "${GRAVIS}.disable-windows-defender.sh" --output .no-defender.sh && source .no-defender.sh)
+  matrix:
+    # List any JDK you want to build your software with.
+    # You can see the list of supported environments by installing Jabba and using ls-remote:
+    # https://github.com/shyiko/jabba#usage
+    # Partial versions are allowed. They are dynamically resoved by launching jabba ls-remote,
+    # filtering for the provided JDK string, then picking the *first* match. This is useful if
+    # the intent is to target the latest release of some Java major release, or if the latest
+    # available build differs among platforms.
+    - JDK="adopt@1.8"
+    - JDK="adopt@1.11"
+    # cannot build with latest JDK yet, because source=6 is no longer supported in the ITs
+    # - JDK="adopt@1.13"
+before_install:
+  # Download the script
+  - curl "${GRAVIS}.install-jdk-travis.sh" --output ~/.install-jdk-travis.sh
+  # Download, install, configue the JDK, and export the configuration to the current shell
+  - source ~/.install-jdk-travis.sh
+  - curl "${GRAVIS}.install-maven.sh" --output ~/.install-maven.sh
+  # Download, install, configue the JDK, and export the configuration to the current shell
+  - source ~/.install-maven.sh
+# This is your main script
+script:
+  # Just an example. Do what you deem useful
+  - mvn verify -B
+# If you use Gradle, cleanup the build cache from lock/temporary files
+before_cache:
+  #- curl "${GRAVIS}.clean_gradle_cache.sh" --output ~/.clean_gradle_cache.sh
+  #- bash ~/.clean_gradle_cache.sh
+cache:
+  directories:
+    # This avoids re-downloading the JDK every time, but Travis recommends not to do it
+    # - $HOME/.jabba/
+    # Cache Maven repo
+    - $HOME/.m2
\ No newline at end of file
diff --git a/README.md b/README.md
index d964985..b78f5d2 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
+[![Build Status](https://travis-ci.org/apache/jackrabbit-filevault-package-maven-plugin.svg?branch=trunk)](https://travis-ci.org/apache/jackrabbit-filevault-package-maven-plugin)
+
 Welcome to Apache Jackrabbit FileVault Package Maven Plugin
 ===========================================================
 
diff --git a/pom.xml b/pom.xml
index 3490091..87f6e2d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -91,6 +91,11 @@
         <url>https://issues.apache.org/jira/browse/JCRVLT</url>
     </issueManagement>
 
+    <ciManagement>
+        <system>Travis</system>
+        <url>https://travis-ci.org/apache/jackrabbit-filevault-package-maven-plugin</url>
+    </ciManagement>
+
     <!-- ====================================================================== -->
     <!-- B U I L D   D E F I N I T I O N                                        -->
     <!-- ====================================================================== -->
@@ -247,6 +252,7 @@
                         <configuration>
                             <basedir>${project.basedir}</basedir>
                             <excludesFile>${project.basedir}/.ratignore</excludesFile>
+                            <consoleOutput>true</consoleOutput>
                         </configuration>
                     </execution>
                 </executions>
diff --git a/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
index d3c999a..e71023d 100644
--- a/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
+++ b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
@@ -27,7 +27,6 @@
 import java.nio.file.Files;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
-import java.time.ZoneOffset;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Date;
diff --git a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojoTest.java b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojoTest.java
index 2caa9ab..b24b78c 100644
--- a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojoTest.java
+++ b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojoTest.java
@@ -22,9 +22,12 @@
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Properties;
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
@@ -38,8 +41,8 @@
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.archiver.jar.ManifestException;
+import org.hamcrest.Matchers;
 import org.junit.Assert;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class GenerateMetadataMojoTest {
@@ -91,23 +94,34 @@
         mojo.project = new MavenProject();
         Properties vaultProperties = new Properties();
         File outputFile = File.createTempFile("filevault-test-", null);
-        String expectedManifest = 
-           "Manifest-Version: 1.0\r\n" + 
-           "Implementation-Title: empty-project\r\n" + 
-           "Content-Package-Roots: \r\n" + 
-           "Implementation-Version: 0\r\n" + 
-           "Content-Package-Dependencies: somegroup:dependency:1.0\r\n" + 
-           "Build-Jdk-Spec: 1.8\r\n" + 
-           "Content-Package-Type: application\r\n" + 
-           "Created-By: Apache Jackrabbit FileVault - Package Maven Plugin\r\n" + 
-           "Content-Package-Id: mygroup:mypackage:1.4\r\n" + 
-           "Content-Package-Description: \r\n" + 
-           "\r\n";
+        
+        Map<String, Pattern> expectedAttributes = new HashMap<>();
+        expectedAttributes.put("Manifest-Version", Pattern.compile("1\\.0"));
+        expectedAttributes.put("Implementation-Title", Pattern.compile("empty-project"));
+        expectedAttributes.put("Implementation-Version", Pattern.compile("0")); // project.version
+        expectedAttributes.put("Content-Package-Roots", Pattern.compile(""));
+        expectedAttributes.put("Content-Package-Dependencies", Pattern.compile("somegroup:dependency:1.0"));
+        expectedAttributes.put("Build-Jdk-Spec", Pattern.compile(".*"));
+        expectedAttributes.put("Content-Package-Type", Pattern.compile("application"));
+        // this includes the version in case the pom.properties is already created which shouldn't be the case here
+        expectedAttributes.put("Created-By", Pattern.compile("Apache Jackrabbit FileVault - Package Maven Plugin"));
+        expectedAttributes.put("Content-Package-Id", Pattern.compile("mygroup:mypackage:1\\.4"));
+        expectedAttributes.put("Content-Package-Description", Pattern.compile("")); 
         try {
             mojo.writeManifest(outputFile, "somegroup:dependency:1.0", null, vaultProperties);
-            try (Reader reader = new InputStreamReader(new FileInputStream(outputFile), StandardCharsets.UTF_8)) {
-                Assert.assertEquals(expectedManifest, IOUtils.toString(reader));
+            try (InputStream input = new FileInputStream(outputFile)) {
+                Manifest manifest = new Manifest(input);
+                Attributes attributes = manifest.getMainAttributes();
+                for (Map.Entry<Object, Object> attribute : attributes.entrySet()) {
+                    Pattern expectedAttributeValuePattern = expectedAttributes.get(attribute.getKey().toString());
+                    if (expectedAttributeValuePattern == null) {
+                        Assert.fail("Found unexpected attribute " + attribute.getKey() + " in Manifest");
+                    }
+                    Assert.assertThat("Found unexpected attribute value for " + attribute.getKey(), (String)attribute.getValue(), Matchers.matchesPattern(expectedAttributeValuePattern));
+                    expectedAttributes.remove(attribute.getKey().toString());
+                }
             }
+            Assert.assertThat("Not found expected attributes in manifest", expectedAttributes, Matchers.anEmptyMap());
         } finally {
             outputFile.delete();
         }
diff --git a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/GenerateMetadataMultiModuleIT.java b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/GenerateMetadataMultiModuleIT.java
index 72846a8..d4fd533 100644
--- a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/GenerateMetadataMultiModuleIT.java
+++ b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/GenerateMetadataMultiModuleIT.java
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.filevault.maven.packaging.it;
 
+import java.nio.file.Paths;
+
 import org.junit.Test;
 
 public class GenerateMetadataMultiModuleIT {
@@ -33,7 +35,7 @@
                 .setVerifyPackageContents(false)
                 .build()
                 .verifyExpectedFilterInWorkDirectory("container/target/vault-work")
-                .verifyExpectedLogLines(); // make sure validation runs
+                .verifyExpectedLogLines(Paths.get("target", "vault-work", "META-INF", "vault", "filter.xml").toString()); // make sure validation runs
     }
 
     /**
diff --git a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ProjectBuilder.java b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ProjectBuilder.java
index d3f5c90..c35e680 100644
--- a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ProjectBuilder.java
+++ b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ProjectBuilder.java
@@ -376,7 +376,7 @@
                     throw new IllegalArgumentException("At least " + placeholderIndex + " placeholder values need to be given, but only "+ placeholderValues.length + " received.");
                 }
                 // replace current item in iterator with the new value
-                expectedLogLine = matcher.replaceAll(placeholderValues[placeholderIndex]);
+                expectedLogLine = matcher.replaceAll(Matcher.quoteReplacement(placeholderValues[placeholderIndex]));
             }
             // update list
             assertThat("Could not find the expected log line in the output '" + logTxtFile +"'", actualLogLines, Matchers.hasItem(expectedLogLine));
diff --git a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidateFilesIT.java b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidateFilesIT.java
index 121f086..0dbe2f0 100644
--- a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidateFilesIT.java
+++ b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidateFilesIT.java
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.filevault.maven.packaging.it;
 
 import java.io.IOException;
+import java.nio.file.Paths;
 
 import org.apache.maven.it.VerificationException;
 import org.junit.Test;
@@ -31,7 +32,7 @@
                 .setTestGoals("clean", "process-classes") // make sure the validate-files mojo is not skipped
                 .setBuildExpectedToFail(true)
                 .build()
-                .verifyExpectedLogLines("target/vault-work/META-INF/vault/filter.xml");
+                .verifyExpectedLogLines(Paths.get("target","vault-work","META-INF","vault","filter.xml").toString());
     }
 
     @Test
diff --git a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidatePackageIT.java b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidatePackageIT.java
index 8641c19..7372ced 100644
--- a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidatePackageIT.java
+++ b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidatePackageIT.java
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.filevault.maven.packaging.it;
 
 import java.io.IOException;
+import java.nio.file.Paths;
 
 import org.apache.maven.it.VerificationException;
 import org.junit.Test;
@@ -30,7 +31,7 @@
                 .setTestProjectDir(TEST_PROJECT_NAME + projectName)
                 .setBuildExpectedToFail(true)
                 .build()
-                .verifyExpectedLogLines("META-INF/vault/filter.xml");
+                .verifyExpectedLogLines(Paths.get("META-INF", "vault", "filter.xml").toString());
     }
 
     @Test
diff --git a/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt b/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt
index 5334e24..9f12a90 100644
--- a/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt
+++ b/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt
@@ -1 +1 @@
-[WARNING] ValidationViolation: "jackrabbit-filter: Filter root's ancestor '/apps/bundles/install' is not covered by any of the specified dependencies nor a valid root.", filePath=target/vault-work/META-INF/vault/filter.xml
\ No newline at end of file
+[WARNING] ValidationViolation: "jackrabbit-filter: Filter root's ancestor '/apps/bundles/install' is not covered by any of the specified dependencies nor a valid root.", filePath=%0%
\ No newline at end of file