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 2015/09/16 19:59:02 UTC
[02/15] incubator-freemarker git commit: Added support for calling
some Java 6 functions (despite that we only require Java 5)
Added support for calling some Java 6 functions (despite that we only require Java 5)
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/2daf5f3d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/2daf5f3d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/2daf5f3d
Branch: refs/heads/2.3
Commit: 2daf5f3d78d15cfed55b93459ef31af9a1889db9
Parents: 26c1ff1
Author: ddekany <dd...@apache.org>
Authored: Mon Sep 14 02:23:29 2015 +0200
Committer: ddekany <dd...@apache.org>
Committed: Mon Sep 14 02:23:29 2015 +0200
----------------------------------------------------------------------
build.properties.sample | 1 +
build.xml | 35 ++++++++-
src/main/java/freemarker/core/_Java6.java | 35 +++++++++
src/main/java/freemarker/core/_Java6Impl.java | 45 ++++++++++++
.../java/freemarker/core/_JavaVersions.java | 77 ++++++++++++++++++++
5 files changed, 190 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2daf5f3d/build.properties.sample
----------------------------------------------------------------------
diff --git a/build.properties.sample b/build.properties.sample
index 82c818b..1a94745 100644
--- a/build.properties.sample
+++ b/build.properties.sample
@@ -1,4 +1,5 @@
# Copy this file to "build.properties" before editing!
# These propeties should point to the rt.jar-s of the respective J2SE versions:
boot.classpath.j2se1.5=C:/Program Files (x86)/Java/jdk1.5.0_16/jre/lib/rt.jar
+boot.classpath.j2se1.6=C:/Program Files/Java/jdk1.6.0_24/jre/lib/rt.jar
mvnCommand=C:/Program Files (x86)/maven3/bin/mvn.bat
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2daf5f3d/build.xml
----------------------------------------------------------------------
diff --git a/build.xml b/build.xml
index 03ac2fb..e6b84cc 100644
--- a/build.xml
+++ b/build.xml
@@ -24,9 +24,13 @@
<condition property="has.explicit.boot.classpath.j2se1.5">
<isset property="boot.classpath.j2se1.5"/>
</condition>
+ <condition property="has.explicit.boot.classpath.j2se1.6">
+ <isset property="boot.classpath.j2se1.6"/>
+ </condition>
<condition property="has.all.explicit.boot.classpaths">
<and>
<isset property="has.explicit.boot.classpath.j2se1.5"/>
+ <isset property="has.explicit.boot.classpath.j2se1.6"/>
</and>
</condition>
<available property="atLeastJDK8" classname="java.util.function.Predicate"/>
@@ -34,12 +38,17 @@
<!-- When boot.classpath.j2se* is missing, these will be the defaults: -->
<!-- Note: Target "dist" doesn't allow using these. -->
<property name="boot.classpath.j2se1.5" value="${sun.boot.class.path}" />
+ <property name="boot.classpath.j2se1.6" value="${sun.boot.class.path}" />
<!-- For checking the correctness of the boot.classpath.j2se* -->
<available classpath="${boot.classpath.j2se1.5}"
- classname="java.lang.Object" ignoresystemclasses="true"
+ classname="java.util.concurrent.ConcurrentHashMap" ignoresystemclasses="true"
property="boot.classpath.j2se1.5.correct"
/>
+ <available classpath="${boot.classpath.j2se1.6}"
+ classname="java.util.ServiceLoader" ignoresystemclasses="true"
+ property="boot.classpath.j2se1.6.correct"
+ />
<condition property="example.freemarker.jar.location"
value="freemarker.jar" else="build/freemarker.jar">
@@ -179,7 +188,17 @@
-->the <projectDir>/build.properties file, or wherever you <!--
-->set it.<!--
--></fail>
- <echo level="info">Using boot classpaths: 1.5: ${boot.classpath.j2se1.5}</echo>
+ <fail unless="boot.classpath.j2se1.6.correct"><!--
+ -->The "boot.classpath.j2se1.6" property value (${boot.classpath.j2se1.6}) <!--
+ -->seems to be an incorrect boot classpath. Please fix it in <!--
+ -->the <projectDir>/build.properties file, or wherever you <!--
+ -->set it.<!--
+ --></fail>
+ <echo level="info"><!--
+ -->Using boot classpaths:<!--
+ -->Java 5: ${boot.classpath.j2se1.5}; <!--
+ -->Java 6: ${boot.classpath.j2se1.6}<!--
+ --></echo>
<mkdir dir="build/classes" />
@@ -191,6 +210,7 @@
classpathref="ivy.dep"
bootclasspath="${boot.classpath.j2se1.5}"
excludes="
+ freemarker/core/_Java6Impl.java,
freemarker/ext/jsp/**,
freemarker/ext/servlet/**,
freemarker/cache/WebappTemplateLoader.java,
@@ -205,6 +225,15 @@
</src>
</javac>
+ <ivy:cachepath conf="build.base" pathid="ivy.dep" />
+ <javac srcdir="src/main/java" destdir="build/classes" deprecation="off"
+ debug="on" optimize="off" target="1.5" source="1.5" encoding="utf-8"
+ includeantruntime="false"
+ classpathref="ivy.dep"
+ bootclasspath="${boot.classpath.j2se1.6}"
+ includes="freemarker/core/_Java6Impl.java"
+ />
+
<rmic
base="build/classes" includes="freemarker/debug/impl/Rmi*Impl.class"
classpathref="ivy.dep"
@@ -331,7 +360,7 @@
includeantruntime="false"
classpath="build/classes"
classpathref="ivy.dep.build.test"
- bootclasspath="${boot.classpath.j2se1.5}"
+ bootclasspath="${boot.classpath.j2se1.6}"
/>
<copy toDir="build/test-classes">
<fileset dir="src/test/resources"
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2daf5f3d/src/main/java/freemarker/core/_Java6.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/_Java6.java b/src/main/java/freemarker/core/_Java6.java
new file mode 100644
index 0000000..8a49389
--- /dev/null
+++ b/src/main/java/freemarker/core/_Java6.java
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+package freemarker.core;
+
+import java.math.RoundingMode;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+
+/**
+ * Used internally only, might changes without notice!
+ * Used for accessing functionality that's only present in Java 6 or later.
+ */
+public interface _Java6 {
+
+ void setRoundingMode(DecimalFormat df, RoundingMode roundingMode);
+
+ void setExponentSeparator(DecimalFormatSymbols dfs, String exponentSeparator);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2daf5f3d/src/main/java/freemarker/core/_Java6Impl.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/_Java6Impl.java b/src/main/java/freemarker/core/_Java6Impl.java
new file mode 100644
index 0000000..ba2b21c
--- /dev/null
+++ b/src/main/java/freemarker/core/_Java6Impl.java
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package freemarker.core;
+
+import java.math.RoundingMode;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+
+/**
+ * Used internally only, might changes without notice!
+ * Used for accessing functionality that's only present in Java 6 or later.
+ */
+public final class _Java6Impl implements _Java6 {
+
+ public static final _Java6 INSTANCE = new _Java6Impl();
+
+ private _Java6Impl() {
+ // Not meant to be instantiated
+ }
+
+ public void setRoundingMode(DecimalFormat df, RoundingMode roundingMode) {
+ df.setRoundingMode(roundingMode);
+ }
+
+ public void setExponentSeparator(DecimalFormatSymbols dfs, String exponentSeparator) {
+ dfs.setExponentSeparator(exponentSeparator);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2daf5f3d/src/main/java/freemarker/core/_JavaVersions.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/_JavaVersions.java b/src/main/java/freemarker/core/_JavaVersions.java
new file mode 100644
index 0000000..244862d
--- /dev/null
+++ b/src/main/java/freemarker/core/_JavaVersions.java
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+package freemarker.core;
+
+import freemarker.log.Logger;
+import freemarker.template.Version;
+import freemarker.template.utility.SecurityUtilities;
+
+/**
+ * Used internally only, might changes without notice!
+ */
+public final class _JavaVersions {
+
+ private _JavaVersions() {
+ // Not meant to be instantiated
+ }
+
+ private static final boolean IS_AT_LEAST_6;
+ static {
+ boolean result = false;
+ String vStr = SecurityUtilities.getSystemProperty("java.version", null);
+ if (vStr != null) {
+ try {
+ Version v = new Version(vStr);
+ result = v.getMajor() == 1 && v.getMinor() >= 6 || v.getMajor() > 1;
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ if (vStr == null) {
+ try {
+ Class.forName("java.util.ServiceLoader");
+ result = true;
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ IS_AT_LEAST_6 = result;
+ }
+
+ static public final _Java6 JAVA_6;
+ static {
+ _Java6 java6;
+ if (IS_AT_LEAST_6) {
+ try {
+ java6 = (_Java6) Class.forName("freemarker.core._Java6Impl").getField("INSTANCE").get(null);
+ } catch (Exception e) {
+ try {
+ Logger.getLogger("freemarker.runtime").error("Failed to access Java 6 functionality", e);
+ } catch (Exception e2) {
+ // Suppressed
+ }
+ java6 = null;
+ }
+ } else {
+ java6 = null;
+ }
+ JAVA_6 = java6;
+ }
+
+}