You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2017/05/07 16:12:52 UTC

[1/3] incubator-freemarker git commit: Changed FileTestCase again... now it works even if the resources/classes of the same package are loaded from multiple directories.

Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 7486e23b3 -> d373a34d3


Changed FileTestCase again... now it works even if the resources/classes of the same package are loaded from multiple directories.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/6a2b2ad5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/6a2b2ad5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/6a2b2ad5

Branch: refs/heads/3
Commit: 6a2b2ad57633cf1f142bb45a65149c786cae986b
Parents: 7486e23
Author: ddekany <dd...@apache.org>
Authored: Sun May 7 17:52:05 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Sun May 7 17:52:05 2017 +0200

----------------------------------------------------------------------
 .../apache/freemarker/core/Configuration.java   |   8 +-
 .../freemarker/core/util/_StringUtil.java       |  13 ++
 .../org/apache/freemarker/core/ASTTest.java     |   7 +-
 .../freemarker/core/util/StringUtilTest.java    |  11 ++
 .../test/servlet/Model2TesterServlet.java       |   3 +
 .../test/templatesuite/TemplateTestCase.java    |  76 ++++----
 .../freemarker/test/util/FileTestCase.java      | 176 ++++++++++++-------
 7 files changed, 177 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/6a2b2ad5/src/main/java/org/apache/freemarker/core/Configuration.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/Configuration.java b/src/main/java/org/apache/freemarker/core/Configuration.java
index df15c0f..e97014f 100644
--- a/src/main/java/org/apache/freemarker/core/Configuration.java
+++ b/src/main/java/org/apache/freemarker/core/Configuration.java
@@ -98,12 +98,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
  *
  * <p>This class is meant to be used in a singleton pattern. That is, you create an instance of this at the beginning of
  * the application life-cycle with {@link Configuration.Builder}, set its settings
- * (either
- * with
- * the
- * setter methods like {@link Configuration.Builder#setTemplateLoader(TemplateLoader)} or by loading a
- * {@code .properties} file and use that with {@link Configuration.Builder#setSettings(Properties)}}), and
- * then
+ * (either with the setter methods like {@link Configuration.Builder#setTemplateLoader(TemplateLoader)} or by loading a
+ * {@code .properties} file and use that with {@link Configuration.Builder#setSettings(Properties)}}), and then
  * use that single instance everywhere in your application. Frequently re-creating {@link Configuration} is a typical
  * and grave mistake from performance standpoint, as the {@link Configuration} holds the template cache, and often also
  * the class introspection cache, which then will be lost. (Note that, naturally, having multiple long-lived instances,

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/6a2b2ad5/src/main/java/org/apache/freemarker/core/util/_StringUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/util/_StringUtil.java b/src/main/java/org/apache/freemarker/core/util/_StringUtil.java
index 50c1874..b53aae8 100644
--- a/src/main/java/org/apache/freemarker/core/util/_StringUtil.java
+++ b/src/main/java/org/apache/freemarker/core/util/_StringUtil.java
@@ -1658,5 +1658,18 @@ public class _StringUtil {
     public static boolean isUpperUSASCII(char c) {
         return c >= 'A' && c <= 'Z';
     }
+
+    private static final Pattern NORMALIZE_EOLS_REGEXP = Pattern.compile("\\r\\n?+");
+
+    /**
+     * Converts all non UN*X End-Of-Line character sequences (CR and CRLF) to UN*X format (LF).
+     * Returns {@code null} for {@code null} input.
+     */
+    public static String normalizeEOLs(String s) {
+        if (s == null) {
+            return null;
+        }
+        return NORMALIZE_EOLS_REGEXP.matcher(s).replaceAll("\n");
+    }
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/6a2b2ad5/src/test/java/org/apache/freemarker/core/ASTTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/ASTTest.java b/src/test/java/org/apache/freemarker/core/ASTTest.java
index ff67cfb..5a6526e 100644
--- a/src/test/java/org/apache/freemarker/core/ASTTest.java
+++ b/src/test/java/org/apache/freemarker/core/ASTTest.java
@@ -21,7 +21,6 @@ package org.apache.freemarker.core;
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.net.URL;
 
 import org.apache.freemarker.core.ASTPrinter.Options;
 import org.apache.freemarker.core.util._StringUtil;
@@ -91,8 +90,10 @@ public class ASTTest extends FileTestCase {
                 ASTPrinter.getASTAsString(templateName,
                         TestUtil.removeFTLCopyrightComment(
                                 normalizeLineBreaks(
-                                        loadTestTextResource(new URL(getTestClassDirectory(), templateName))
-                        )), ops));
+                                        loadTestTextResource(
+                                                getTestFileURL(
+                                                        getExpectedContentFileDirectoryResourcePath(), templateName)))
+                        ), ops));
     }
     
     private String normalizeLineBreaks(final String s) throws FileNotFoundException, IOException {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/6a2b2ad5/src/test/java/org/apache/freemarker/core/util/StringUtilTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/util/StringUtilTest.java b/src/test/java/org/apache/freemarker/core/util/StringUtilTest.java
index 0df8394..2a0ae9d 100644
--- a/src/test/java/org/apache/freemarker/core/util/StringUtilTest.java
+++ b/src/test/java/org/apache/freemarker/core/util/StringUtilTest.java
@@ -388,5 +388,16 @@ public class StringUtilTest {
         _StringUtil.RTFEnc(in, sw);
         assertEquals(expected, sw.toString());
     }
+
+    @Test
+    public void testNormalizeEOLs() {
+        assertNull(_StringUtil.normalizeEOLs(null));
+        assertEquals("", _StringUtil.normalizeEOLs(""));
+        assertEquals("x", _StringUtil.normalizeEOLs("x"));
+        assertEquals("x\ny", _StringUtil.normalizeEOLs("x\ny"));
+        assertEquals("x\ny", _StringUtil.normalizeEOLs("x\r\ny"));
+        assertEquals("x\ny", _StringUtil.normalizeEOLs("x\ry"));
+        assertEquals("\n\n\n\n\n\n", _StringUtil.normalizeEOLs("\n\r\r\r\n\r\n\r"));
+    }
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/6a2b2ad5/src/test/java/org/apache/freemarker/test/servlet/Model2TesterServlet.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/test/servlet/Model2TesterServlet.java b/src/test/java/org/apache/freemarker/test/servlet/Model2TesterServlet.java
index 9a39705..b69a33c 100644
--- a/src/test/java/org/apache/freemarker/test/servlet/Model2TesterServlet.java
+++ b/src/test/java/org/apache/freemarker/test/servlet/Model2TesterServlet.java
@@ -22,6 +22,7 @@ package org.apache.freemarker.test.servlet;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 
+import javax.el.ExpressionFactory;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -104,6 +105,8 @@ public class Model2TesterServlet extends HttpServlet {
         
         final String paramViewServlet = req.getParameter(VIEW_SERVLET_PARAM_NAME);
         if (paramViewServlet == null) {
+            LOG.info("Found ExpressionFactory at: {}", ExpressionFactory.class.getResource("ExpressionFactory"
+                    + ".class")); //!!T
             req.getRequestDispatcher(viewPath).forward(req, resp);
         } else {
             final RequestDispatcher requestDispatcher = getServletContext().getNamedDispatcher(paramViewServlet);

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/6a2b2ad5/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java b/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java
index 2a24b5b..07bf0ca 100644
--- a/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java
+++ b/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java
@@ -24,7 +24,6 @@ import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.math.BigDecimal;
 import java.math.BigInteger;
-import java.net.URL;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
@@ -413,7 +412,7 @@ public class TemplateTestCase extends FileTestCase {
         }
         
         if (out != null) {
-            assertExpectedFileEqualsString(getName(), out.toString());
+            assertExpectedFileEqualsString(expectedFileName, out.toString());
         }
     }
 
@@ -424,19 +423,14 @@ public class TemplateTestCase extends FileTestCase {
     }
 
     @Override
-    protected URL getExpectedFileDirectory() throws IOException {
-        return new URL(super.getExpectedFileDirectory(), "expected/");
+    protected String getExpectedContentFileDirectoryResourcePath() throws IOException {
+        return joinResourcePaths(super.getExpectedContentFileDirectoryResourcePath(), "expected");
     }
 
     @Override
-    protected Charset getTestResourceCharset() {
+    protected Charset getTestResourceDefaultCharset() {
         return confB.getOutputEncoding() != null ? confB.getOutputEncoding() : StandardCharsets.UTF_8;
     }
-    
-    @Override
-    protected URL getExpectedFileFor(String testCaseFileName) throws IOException {
-        return new URL(getExpectedFileDirectory(), expectedFileName);
-    }
 
     static class TestBoolean implements TemplateBooleanModel, TemplateScalarModel {
         @Override
@@ -449,40 +443,40 @@ public class TemplateTestCase extends FileTestCase {
             return "de";
         }
     }
-    
+
     static class TestMethod implements TemplateMethodModel {
-      @Override
-    public Object exec(List arguments) {
-          return "x";
-      }
+        @Override
+        public Object exec(List arguments) {
+            return "x";
+        }
     }
-    
+
     static class TestNode implements TemplateNodeModel {
-      
-      @Override
-    public String getNodeName() {
-          return "name";
-      }
-                    
-      @Override
-    public TemplateNodeModel getParentNode() {
-          return null;
-      }
-    
-      @Override
-    public String getNodeType() {
-          return "element";
-      }
-    
-      @Override
-    public TemplateSequenceModel getChildNodes() {
-          return null;
-      }
-      
-      @Override
-    public String getNodeNamespace() {
-          return null;
-      }
+
+        @Override
+        public String getNodeName() {
+            return "name";
+        }
+
+        @Override
+        public TemplateNodeModel getParentNode() {
+            return null;
+        }
+
+        @Override
+        public String getNodeType() {
+            return "element";
+        }
+
+        @Override
+        public TemplateSequenceModel getChildNodes() {
+            return null;
+        }
+
+        @Override
+        public String getNodeNamespace() {
+            return null;
+        }
     }
 
    public Object getTestMapBean() {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/6a2b2ad5/src/test/java/org/apache/freemarker/test/util/FileTestCase.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/test/util/FileTestCase.java b/src/test/java/org/apache/freemarker/test/util/FileTestCase.java
index 144592a..ba13558 100644
--- a/src/test/java/org/apache/freemarker/test/util/FileTestCase.java
+++ b/src/test/java/org/apache/freemarker/test/util/FileTestCase.java
@@ -20,22 +20,19 @@
 package org.apache.freemarker.test.util;
 
 import java.io.File;
-import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
 import java.net.URL;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
+import org.apache.freemarker.core.util._NullArgumentException;
 import org.apache.freemarker.core.util._StringUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
@@ -44,20 +41,22 @@ import junit.framework.TestCase;
  */
 public abstract class FileTestCase extends TestCase {
 
+    public static final Logger LOG = LoggerFactory.getLogger(FileTestCase.class);
+
     public FileTestCase(String name) {
         super(name);
     }
 
     protected void assertExpectedFileEqualsString(String expectedFileName, String actualContent) {
         try {
-            final URL expectedFile = getExpectedFileFor(expectedFileName);
+            final URL expectedFile = getExpectedContentFileURL(expectedFileName);
             
             try {
                 multilineAssertEquals(loadTestTextResource(expectedFile), actualContent);
-            } catch (AssertionFailedError e) {
-                File actualFile = getActualFileFor(expectedFileName);
-                if (actualFile == null) {
-                    saveString(actualFile, actualContent);
+            } catch (AssertionFailedError | FileNotFoundException e) {
+                File actualFile = getActualContentFileFor(expectedFile);
+                if (actualFile != null) {
+                    FileUtils.write(actualFile, actualContent);
                     reportActualFileSaved(actualFile);
                 }
 
@@ -69,8 +68,8 @@ public abstract class FileTestCase extends TestCase {
     }
 
     private void multilineAssertEquals(String expected, String actual) {
-        String normExpected = normalizeNewLines(expected);
-        final String normActual = normalizeNewLines(actual);
+        String normExpected = _StringUtil.normalizeEOLs(expected);
+        final String normActual = _StringUtil.normalizeEOLs(actual);
         
         // Ignore final line-break difference:
         if (normActual.endsWith("\n") && !normExpected.endsWith("\n")) {
@@ -82,65 +81,127 @@ public abstract class FileTestCase extends TestCase {
         assertEquals(normExpected, normActual);
     }
 
-    private String normalizeNewLines(String s) {
-        return _StringUtil.replace(s, "\r\n", "\n").replace('\r', '\n');
+    protected void reportActualFileSaved(File actualContentFile) {
+        LOG.info("Saved actual output of the failed test to here: {}", actualContentFile.getAbsolutePath());
     }
 
-    private void saveString(File actualFile, String actualContents) throws IOException {
-        Writer w = new OutputStreamWriter(new FileOutputStream(actualFile), StandardCharsets.UTF_8);
-        try {
-            w.write(actualContents);
-        } finally {
-            w.close();
+    /**
+     * Convenience method for calling {@link #getTestFileURL(String, String)} with {@link
+     * #getExpectedContentFileDirectoryResourcePath()} as the first argument.
+     */
+    protected final URL getExpectedContentFileURL(String expectedContentFileName) throws IOException {
+        return getTestFileURL(getExpectedContentFileDirectoryResourcePath(), expectedContentFileName);
+    }
+
+    /**
+     * Gets the URL of the test file that contains the expected result.
+     *
+     * @param directoryResourcePath
+     *         The class-loader resource path of the containing directory; if relative, it's interpreted relatively to
+     *         the package of {@link #getTestResourcesBaseClass()}.
+     *
+     * @return Not {@code null}; if the file isn't found, throw {@link FileNotFoundException}
+     *
+     * @throws FileNotFoundException
+     *         If the requested file wasn't found.
+     */
+    protected final URL getTestFileURL(String directoryResourcePath, String fileName) throws IOException {
+        _NullArgumentException.check("directoryResourcePath", directoryResourcePath);
+        _NullArgumentException.check("testCaseFileName", fileName);
+
+        Class baseClass = getTestResourcesBaseClass();
+        String resourcePath = joinResourcePaths(directoryResourcePath, fileName);
+        // It's important that we only query an URL for the file (not for the parent package directory), because the
+        // parent URL can depend on the file name if the class loader uses multiple directories/jars.
+        URL resource = baseClass.getResource(resourcePath);
+        if (resource == null) {
+            throw new FileNotFoundException("Class-loader resource not found for: "
+                    + "baseClass: " + baseClass.getName() + "; "
+                    + "resourcePath (shown quoted): " + _StringUtil.jQuote(resourcePath));
         }
+        return resource;
     }
 
-    protected URL getExpectedFileFor(String testCaseFileName) throws IOException {
-        return new URL(getExpectedFileDirectory(), testCaseFileName);
+    /**
+     * Concatenates two resource paths, taking care of the edge cases due to leading and trailing "/"
+     * characters in them.
+     */
+    protected final String joinResourcePaths(String dirPath, String tailPath) {
+        if (tailPath.startsWith("/") || dirPath.isEmpty()) {
+            return tailPath;
+        }
+        return dirPath.endsWith("/") ? dirPath + tailPath : dirPath + "/" + tailPath;
     }
 
     /**
-     * @return {@code null} if there's no place to write the actual files to
+     * Gets the actual content file to create which belongs to an expected content file. Actual content files are
+     * created when the expected and the actual content differs.
+     *
+     * @return {@code null} if there's no place to write the files that contain the actual content
      */
-    protected File getActualFileFor(String testCaseFileName) throws IOException {
-        File actualFileDirectory = getActualFileDirectory();
-        if (actualFileDirectory == null) {
+    protected File getActualContentFileFor(URL expectedContentFile) throws IOException {
+        _NullArgumentException.check("expectedContentFile", expectedContentFile);
+
+        File actualContentFileDir = getActualContentFileDirectory(expectedContentFile);
+        if (actualContentFileDir == null) {
             return null;
         }
-        return new File(actualFileDirectory, deduceActualFileName(testCaseFileName));
+
+        String expectedContentFileName = expectedContentFile.getPath();
+        int lastSlashIdx = expectedContentFileName.lastIndexOf('/');
+        if (lastSlashIdx != -1) {
+            expectedContentFileName = expectedContentFileName.substring(lastSlashIdx + 1);
+        }
+
+        return new File(actualContentFileDir, deduceActualContentFileName(expectedContentFileName));
     }
-    
-    private String deduceActualFileName(String testCaseFileName) {
-        int lastDotIdx = testCaseFileName.lastIndexOf('.');
+
+    /**
+     * Deduces the actual content file name from the expected content file name.
+     *
+     * @return Not {@code null}
+     */
+    protected String deduceActualContentFileName(String expectedContentFileName) {
+        _NullArgumentException.check("expectedContentFileName", expectedContentFileName);
+
+        int lastDotIdx = expectedContentFileName.lastIndexOf('.');
         return lastDotIdx == -1
-                ? testCaseFileName + ".actual" 
-                : testCaseFileName.substring(0, lastDotIdx) + "-actual" + testCaseFileName.substring(lastDotIdx);
+                ? expectedContentFileName + ".actual"
+                : expectedContentFileName.substring(0, lastDotIdx) + "-actual" + expectedContentFileName.substring(lastDotIdx);
     }
 
     /**
-     * The URL of the directory that contains the expected files; must end with "/" or "/." or else relative paths won't
-     * be resolved correctly.
+     * The class loader resource path of the directory that contains the expected files; must start and end with "/"!
      */
-    protected URL getExpectedFileDirectory() throws IOException {
-        return getTestClassDirectory();
+    protected String getExpectedContentFileDirectoryResourcePath() throws IOException {
+        return getTestClassDirectoryResourcePath();
     }
 
     /**
      * @return {@code null} if there's no directory to write the actual files to
      */
-    protected File getActualFileDirectory() throws IOException {
-        return FileUtils.toFile(getExpectedFileDirectory());
+    protected File getActualContentFileDirectory(URL expectedFile) throws IOException {
+        return FileUtils.toFile(expectedFile).getParentFile();
     }
 
-    @SuppressFBWarnings(value="UI_INHERITANCE_UNSAFE_GETRESOURCE", justification="By design relative to subclass")
-    protected final URL getTestClassDirectory() throws IOException {
-        URL url = getClass().getResource(".");
-        if (url == null) throw new IOException("Couldn't get resource URL for \".\"");
-        return url;
+    /**
+     * The class loader resource path of the directory that contains the test files; must not end with "/"!
+     */
+    protected String getTestClassDirectoryResourcePath() throws IOException {
+        return "";
+    }
+
+    /**
+     * Resource paths are loaded using this class's {@link Class#getResourceAsStream(String)} method; thus, if
+     * {@link #getTestClassDirectoryResourcePath()} and such return a relative paths, they will be relative to the
+     * package of this class.
+     */
+    protected Class getTestResourcesBaseClass() {
+        return getClass();
     }
 
     protected String loadTestTextResource(URL resource) throws IOException {
-        return loadTestTextResource(resource, getTestResourceCharset());
+        return loadTestTextResource(resource, getTestResourceDefaultCharset());
     }
     
     protected String loadTestTextResource(URL resource, Charset charset) throws IOException {
@@ -148,27 +209,8 @@ public abstract class FileTestCase extends TestCase {
                 IOUtils.toString(resource, charset.name()));
     }
     
-    protected Charset getTestResourceCharset() {
+    protected Charset getTestResourceDefaultCharset() {
         return StandardCharsets.UTF_8;
     }
-    
-    protected void reportActualFileSaved(File f) {
-        System.out.println("Note: Saved actual output of the failed test to here: " + f.getAbsolutePath());
-    }
-   
-    private static String loadString(InputStream in, Charset charset) throws IOException {
-        Reader r = new InputStreamReader(in, charset);
-        StringBuilder sb = new StringBuilder(1024);
-        try {
-            char[] buf = new char[4096];
-            int ln;
-            while ((ln = r.read(buf)) != -1) {
-                sb.append(buf, 0, ln);
-            }
-        } finally {
-            r.close();
-        }
-        return sb.toString();
-    }
-    
+
 }


[2/3] incubator-freemarker git commit: (Added ant report-ide-deps task)

Posted by dd...@apache.org.
(Added ant report-ide-deps task)


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/2995feda
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/2995feda
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/2995feda

Branch: refs/heads/3
Commit: 2995fedae0643e3b11ddb4cfa3d60e87724392f6
Parents: 6a2b2ad
Author: ddekany <dd...@apache.org>
Authored: Sun May 7 17:52:28 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Sun May 7 17:52:28 2017 +0200

----------------------------------------------------------------------
 build.xml | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2995feda/build.xml
----------------------------------------------------------------------
diff --git a/build.xml b/build.xml
index 3fa5393..3270ff9 100644
--- a/build.xml
+++ b/build.xml
@@ -992,6 +992,14 @@ Proceed? </input>
     <ivy:report todir="build/deps-report" />
   </target>
   
+  <target name="report-ide-deps"
+    description="Creates a HTML document that summarizes the dependencies."
+  >
+    <mkdir dir="build/ide-deps-report" />
+    <ivy:resolve conf="IDE" />
+    <ivy:report todir="build/ide-deps-report" />
+  </target>
+  
   <target name="ide-dependencies" depends="jar"
     description="If your IDE has no Ivy support, this generates ide-lib/*.jar for it">
     <mkdir dir="ide-dependencies" />


[3/3] incubator-freemarker git commit: Very primitive, work in progress Gradle build script. Note the custom gradlew script, which works without gardlew-wrapper.jar; it's copied from Apache Bigtop (https://github.com/apache/bigtop/blob/master/gradle/wrap

Posted by dd...@apache.org.
Very primitive, work in progress Gradle build script. Note the custom gradlew script, which works without gardlew-wrapper.jar; it's copied from Apache Bigtop (https://github.com/apache/bigtop/blob/master/gradle/wrapper/gradle-wrapper.properties), but adds Cygwin support to it.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/d373a34d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/d373a34d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/d373a34d

Branch: refs/heads/3
Commit: d373a34d323826900e16ca2c36ad455deeabceb7
Parents: 2995fed
Author: ddekany <dd...@apache.org>
Authored: Sun May 7 18:11:14 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Sun May 7 18:12:37 2017 +0200

----------------------------------------------------------------------
 README-gradle.md                         |  13 ++
 build.gradle                             | 131 +++++++++++++++
 gradle/wrapper/gradle-wrapper.jar        | Bin 0 -> 50518 bytes
 gradle/wrapper/gradle-wrapper.properties |   6 +
 gradlew                                  | 233 ++++++++++++++++++++++++++
 gradlew.bat                              |  90 ++++++++++
 settings.gradle                          |  20 +++
 7 files changed, 493 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d373a34d/README-gradle.md
----------------------------------------------------------------------
diff --git a/README-gradle.md b/README-gradle.md
new file mode 100644
index 0000000..8b0fe67
--- /dev/null
+++ b/README-gradle.md
@@ -0,0 +1,13 @@
+The current gradle build is work in progress, so use the Ant build, as
+described in README.md!
+
+To build the project, go to the project home directory, and issue:
+
+    ./gradlew jar test
+  
+On Windows this won't work if you are using an Apache source release (as
+opposed to checking the project out from Git), as due to Apache policy
+restricton `gradle\wrapper\gradle-wrapper.jar` is missing from that. So you
+have to download that very common artifact from somewhere manually. On
+UN*X-like systems (and from under Cygwin shell) you don't need that jar, as
+our custom `gradlew` shell script does everything itself.

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d373a34d/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..1a86c94
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,131 @@
+/*
+ * 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.
+ */
+
+plugins {
+    id "ca.coglinc.javacc" version "2.4.0"
+}
+
+apply plugin: "java"
+
+version = "3.0.0-nightly"
+
+repositories {
+    // mavenLocal()
+    mavenCentral()
+}
+
+configurations.all {
+    // We use SLF4J with Logback binding, so exclude any other SLF4J bindings:
+    exclude group: "org.slf4j", module: "slf4j-log4j12"
+    exclude group: "org.slf4j", module: "slf4j-jdk14"
+
+    // We use xxx-over-slf4j to substitute logging libraries, so exclude them:
+    exclude group: "log4j", module: "log4j"
+    exclude group: "commons-logging", module: "commons-logging"
+
+    // xml-apis is part of the Java SE version for a good while; prevent old libraries pulling it in:
+    exclude group: "xml-apis", module: "xml-apis"
+}
+
+configurations.testCompile {
+    // Jetty pulls in its own version of Servlet/JSP classes, so don't inherit these from the "compile" configuration:
+    exclude group: "javax.servlet.jsp", module: "jsp-api"
+    exclude group: "javax.servlet.jsp", module: "servlet-api"
+}
+
+dependencies {
+    def jettyVersion = "7.6.16.v20140903"
+    def slf4jVersion = "1.7.22"
+    def springVersion = "2.5.6.SEC03"
+
+    compile "com.google.guava:guava:20.0"
+
+    compile "jaxen:jaxen:1.0-FCS"
+    compile "saxpath:saxpath:1.0-FCS"
+    compile "xalan:xalan:2.7.0"
+
+    compile "org.slf4j:slf4j-api:$slf4jVersion"
+
+    compile "org.zeroturnaround:javarebel-sdk:1.2.2"
+
+    // TODO @SuppressFBWarnings-s should be removed before build, then this dependency is only needed for the IDE
+    compile "com.google.code.findbugs:annotations:3.0.0"
+
+    // TODO These will be moved to the freemarker-serlvet module:
+    compile "javax.servlet.jsp:jsp-api:2.1"
+    compile "javax.servlet:servlet-api:2.5"
+
+    // Test:
+
+    testCompile "junit:junit:4.12"
+    testCompile "org.hamcrest:hamcrest-library:1.3"
+
+    testCompile "ch.qos.logback:logback-classic:1.1.8"
+    testCompile "org.slf4j:jcl-over-slf4j:$slf4jVersion"
+
+    testCompile "commons-io:commons-io:2.2"
+    testCompile "com.google.guava:guava-jdk5:17.0"
+
+    testCompile "org.eclipse.jetty:jetty-server:$jettyVersion"
+    testCompile "org.eclipse.jetty:jetty-webapp:$jettyVersion"
+    testCompile "org.eclipse.jetty:jetty-jsp:$jettyVersion"
+    testCompile "org.eclipse.jetty:jetty-util:$jettyVersion"
+
+    testCompile("displaytag:displaytag:1.2") {
+        exclude group: "com.lowagie", module: "itext"
+    }
+
+    testCompile "org.springframework:spring-core:$springVersion"
+    testCompile "org.springframework:spring-test:$springVersion"
+}
+
+compileJava {
+    // TODO This will be 1.7 when freemarker-core-java8 is separated
+    sourceCompatibility = "1.8"
+    targetCompatibility = "1.8"
+
+    options.encoding = "UTF-8"
+}
+
+compileTestJava {
+    sourceCompatibility = "1.8"
+    targetCompatibility = "1.8"
+
+    options.encoding = "UTF-8"
+}
+
+compileJavacc {
+    arguments = [ grammar_encoding: "UTF-8" ]
+    doLast {
+        // TODO Some filtering is needed on the output - see in the original Ant build
+
+        // Note: The Gradle JavaCC plugin automatically removes generated java files that are already in
+        // src/main/java, so we don't need to get rid of ParseException.java and TokenMgrError.java (unlike in Ant)
+    }
+}
+
+jar {
+    // TODO Use bnd - see in the Ant build
+    manifest {
+        attributes(
+                // TODO There were more here in the Ant build
+                "Implementation-Title": "Apache FreeMarker",
+                "Implementation-Version": project.version)
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d373a34d/gradle/wrapper/gradle-wrapper.jar
----------------------------------------------------------------------
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..b979729
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d373a34d/gradle/wrapper/gradle-wrapper.properties
----------------------------------------------------------------------
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..561a5b0
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Wed May 03 11:59:02 CEST 2017
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d373a34d/gradlew
----------------------------------------------------------------------
diff --git a/gradlew b/gradlew
new file mode 100644
index 0000000..e53f798
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,233 @@
+#!/usr/bin/env bash
+
+# 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.
+
+##
+## Tries to recreate Gradle's gradlew command in pure bash.
+## This way you don't have to worry about binaries in your build.
+##
+## Depdencies
+## unzip
+##
+
+set -e
+set -o pipefail
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+    MAX_FD="maximum"
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+bin=`dirname "$0"`
+bin=`cd "$bin">/dev/null; pwd`
+
+if [ -e "$bin/gradle/wrapper/gradle-wrapper.properties" ]; then
+  . "$bin/gradle/wrapper/gradle-wrapper.properties"
+else
+  # the location that the wrapper is at doesn't have a properties
+  # check PWD, gradlew may be shared
+  if [ -e "$PWD/gradle/wrapper/gradle-wrapper.properties" ]; then
+    . "$PWD/gradle/wrapper/gradle-wrapper.properties"
+  else
+    echo "Unable to locate gradle-wrapper.properties.  Not at $PWD/gradle/wrapper/gradle-wrapper.properties or $bin/gradle/wrapper/gradle-wrapper.properties" 1>&2
+    exit 1
+  fi
+fi
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+darwin=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+esac
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$darwin" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# does not match gradle's hash
+# waiting for http://stackoverflow.com/questions/26642077/java-biginteger-in-bash-rewrite-gradlew
+hash() {
+  local input="$1"
+  if $darwin; then
+    md5 -q -s "$1"
+  else
+    echo -n "$1" | md5sum  | cut -d" " -f1
+  fi
+}
+
+dist_path() {
+  local dir=$(basename $distributionUrl | sed 's;.zip;;g')
+  local id=$(hash "$distributionUrl")
+
+  echo "$HOME/.gradle/${distributionPath:-wrapper/dists}/$dir/$id"
+}
+
+zip_path() {
+  local dir=$(basename $distributionUrl | sed 's;.zip;;g')
+  local id=$(hash "$distributionUrl")
+
+  echo "$HOME/.gradle/${zipStorePath:-wrapper/dists}/$dir/$id"
+}
+
+download() {
+  local base_path=$(dist_path)
+  local file_name=$(basename $distributionUrl)
+  local dir_name=$(echo "$file_name" | sed 's;-bin.zip;;g' | sed 's;-src.zip;;g' |sed 's;-all.zip;;g')
+
+  if [ ! -d "$base_path" ]; then
+    mkdir -p "$base_path"
+  else
+    # if data already exists, it means we failed to do this before
+    # so cleanup last run and try again
+    rm -rf $base_path/*
+  fi
+
+  # download dist. curl on mac doesn't like the cert provided...
+  local zip_path=$(zip_path)
+  curl --insecure -L -o "$zip_path/$file_name" "$distributionUrl"
+
+  pushd "$base_path"
+    touch "$file_name.lck"
+    unzip "$zip_path/$file_name" 1> /dev/null
+    touch "$file_name.ok"
+  popd
+}
+
+is_cached() {
+  local file_name=$(basename $distributionUrl)
+
+  [ -e "$(dist_path)/$file_name.ok" ]
+}
+
+lib_path() {
+  local base_path=$(dist_path)
+  local file_name=$(basename $distributionUrl | sed 's;-bin.zip;;g' | sed 's;-src.zip;;g' |sed 's;-all.zip;;g')
+
+  echo "$base_path/$file_name/lib"
+}
+
+classpath() {
+  local dir=$(lib_path)
+  local cp=$(ls -1 $dir/*.jar | tr '\n' ':')
+  echo "$dir:$cp"
+}
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+    JVM_OPTS=("$@")
+}
+
+main() {
+  if ! is_cached; then
+    download
+  fi
+
+  eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+  JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+  dynclasspath="$(classpath)"
+  if [ "$cygwin" = "true" ]; then
+    JAVACMD=$(cygpath --unix "$JAVACMD")
+    if [ -n "$dynclasspath" ]; then
+      # We assume that JAVACMD points to the Windows native java
+      dynclasspath=$(cygpath --path --windows "$dynclasspath")
+    fi
+  fi
+  
+  "$JAVACMD" "${JVM_OPTS[@]}" -cp "$dynclasspath" org.gradle.launcher.GradleMain "$@"
+}
+
+main "$@"

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d373a34d/gradlew.bat
----------------------------------------------------------------------
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..8a0b282
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d373a34d/settings.gradle
----------------------------------------------------------------------
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..4c372f2
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+rootProject.name = 'freemarker'