poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1881914 - in /poi/trunk: build.xml src/excelant/poi-ant-contrib/ src/excelant/poi-ant-contrib/Bytes2Mega.java src/excelant/poi-ant-contrib/NextRelease.java src/excelant/poi-ant-contrib/PropertyReset.java
Date Tue, 22 Sep 2020 00:07:32 GMT
Author: kiwiwings
Date: Tue Sep 22 00:07:32 2020
New Revision: 1881914

URL: http://svn.apache.org/viewvc?rev=1881914&view=rev
Log:
Fix Ant javascript issues

Added:
    poi/trunk/src/excelant/poi-ant-contrib/
    poi/trunk/src/excelant/poi-ant-contrib/Bytes2Mega.java   (with props)
    poi/trunk/src/excelant/poi-ant-contrib/NextRelease.java   (with props)
    poi/trunk/src/excelant/poi-ant-contrib/PropertyReset.java   (with props)
Modified:
    poi/trunk/build.xml

Modified: poi/trunk/build.xml
URL: http://svn.apache.org/viewvc/poi/trunk/build.xml?rev=1881914&r1=1881913&r2=1881914&view=diff
==============================================================================
--- poi/trunk/build.xml (original)
+++ poi/trunk/build.xml Tue Sep 22 00:07:32 2020
@@ -91,12 +91,16 @@ under the License.
     <!-- issue warnings if source code contains unmappable characters for encoding ASCII
 -->
     <property name="java.source.encoding" value="UTF-8"/>
 
-    <scriptdef name="propertyreset" language="javascript"
-        description="Allows to assign @{property} new value">
+    <macrodef name="propertyreset">
         <attribute name="name"/>
         <attribute name="value"/>
-            project.setProperty(attributes.get("name"), attributes.get("value"));
-    </scriptdef>
+        <sequential>
+            <mkdir dir="build/poi-ant-contrib"/>
+            <javac srcdir="src/excelant/poi-ant-contrib" destdir="build/poi-ant-contrib"
includeantruntime="true"/>
+            <taskdef name="PropertyResetHelper" classname="PropertyReset" classpath="build/poi-ant-contrib"/>
+            <PropertyResetHelper name="@{name}" value="@{value}" />
+        </sequential>
+    </macrodef>
 
     <!--
       JVM system properties for running tests,
@@ -547,11 +551,12 @@ under the License.
         <echo message="Using Java: ${java.version}/${java.runtime.version}/${java.vm.version}/${java.vm.name}
from ${java.vm.vendor} on ${os.name}: ${os.version}" />
         <echo message="Building Apache POI version ${version.id} and RC: ${release.rc}"
/>
 
-        <scriptdef name="release_tag" language="javascript">
-            var rel = ("REL_"+project.getProperty("version.id")).toUpperCase().replace(/\W/g,"_");
-            project.setProperty("RELEASE_TAG", rel);
-        </scriptdef>
-        <release_tag/>
+        <loadresource property="RELEASE_TAG">
+            <string>REL_${version.id}</string>
+            <filterchain>
+                <replaceregex pattern="\W" replace="_" flags="g"/>
+            </filterchain>
+        </loadresource>
     </target>
 
     <target name="clean" description="Remove generated artefacts">
@@ -2650,12 +2655,8 @@ under the License.
             <format property="tstamp_next" pattern="yyyy-MM" offset="3" unit="month"/>
         </tstamp>
 
-        <scriptdef name="getnextrel" language="javascript">
-            var relCurr = new String(project.getProperty("version.id"));
-            var relNext = relCurr.replace(/[0-9]+$/, function(lastNum){ return new String(new
Number(lastNum)+1); });
-            project.setProperty("rel_next", relNext);
-        </scriptdef>
-        <getnextrel/>
+        <taskdef name="NextRelease" classname="NextRelease" classpath="build/poi-ant-contrib"/>
+        <NextRelease property="rel_next"/>
 
         <antcall target="-update-build.xml">
             <param name="version_id" value="${version.id}"/>
@@ -2778,15 +2779,17 @@ under the License.
         </tstamp>
 
 
-        <scriptdef name="getnextrel" language="javascript">
-            var relPrev = new String(project.getProperty("version.id"))
-                .replace(/([0-9]+)[^0-9]*$/, function(all,lastNum){ return new String(new
Number(lastNum)-1); });
-            project.setProperty("rel_prev", relPrev);
-            var fileDateIso = new String(project.getProperty("file_date"))
-                .replace(/([0-9]{4})([0-9]{2})([0-9]{2})/, "$1-$2-$3");
-            project.setProperty("file_date_iso", fileDateIso);
-        </scriptdef>
-        <getnextrel/>
+        <taskdef name="NextRelease" classname="NextRelease" classpath="build/poi-ant-contrib"/>
+        <NextRelease property="rel_prev" increment="-1"/>
+
+        <!-- we don't simply generate a new iso file date with tstamp,
+            but potentially use the date given as an argument to ant -->
+        <loadresource property="file_date_iso">
+            <string>${file_date}</string>
+            <filterchain>
+                <replaceregex pattern="([0-9]{4})([0-9]{2})([0-9]{2})" replace="\1-\2-\3"/>
+            </filterchain>
+        </loadresource>
 
         <replaceregexp file="build.gradle" match="( +version += +)'[^']+'" replace="\1'${version.id}'"/>
         <replaceregexp file="build.gradle" match="(japicmpversion += +)'[^']+'" replace="\1'${rel_prev}'"/>
@@ -2853,15 +2856,6 @@ under the License.
         </sequential>
     </macrodef>
 
-    <scriptdef name="bytes2mega" language="javascript"
-        description="Convert size in bytes to megabytes">
-        <attribute name="property"/>
-        <attribute name="bytes"/>
-        var bytes = Number(attributes.get("bytes"));
-        var mega = String((bytes/(1024.0*1024.0)).toFixed(2));
-        project.setProperty(attributes.get("property"), mega);
-    </scriptdef>
-
     <macrodef name="download-line">
         <attribute name="prop"/>
         <attribute name="dist"/>
@@ -2887,6 +2881,7 @@ under the License.
                 </filterchain>
             </loadfile>
 
+            <taskdef name="bytes2mega" classname="Bytes2Mega" classpath="build/poi-ant-contrib"/>
             <local name="fileSizeMb"/>
             <bytes2mega property="fileSizeMb" bytes="${fileSize}"/>
 

Added: poi/trunk/src/excelant/poi-ant-contrib/Bytes2Mega.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/excelant/poi-ant-contrib/Bytes2Mega.java?rev=1881914&view=auto
==============================================================================
--- poi/trunk/src/excelant/poi-ant-contrib/Bytes2Mega.java (added)
+++ poi/trunk/src/excelant/poi-ant-contrib/Bytes2Mega.java Tue Sep 22 00:07:32 2020
@@ -0,0 +1,42 @@
+/* ====================================================================
+   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.
+==================================================================== */
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+
+public class Bytes2Mega extends Task {
+    private final NumberFormat formatter = new DecimalFormat("#0.00");
+    private String property;
+    private int bytes;
+
+    public void setProperty(String property) {
+        this.property = property;
+    }
+
+    public void setBytes(int bytes) {
+        this.bytes = bytes;
+    }
+
+    public void execute() {
+        Project project = getProject();
+        double mega = bytes/(1024.*1024.);
+        project.setProperty(property, formatter.format(mega));
+    }
+}

Propchange: poi/trunk/src/excelant/poi-ant-contrib/Bytes2Mega.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: poi/trunk/src/excelant/poi-ant-contrib/NextRelease.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/excelant/poi-ant-contrib/NextRelease.java?rev=1881914&view=auto
==============================================================================
--- poi/trunk/src/excelant/poi-ant-contrib/NextRelease.java (added)
+++ poi/trunk/src/excelant/poi-ant-contrib/NextRelease.java Tue Sep 22 00:07:32 2020
@@ -0,0 +1,44 @@
+/* ====================================================================
+   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.
+==================================================================== */
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+
+public class NextRelease extends Task {
+    private final Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+).*");
+    private String property;
+    private int increment = 1;
+
+    public void setProperty(String property) {
+        this.property = property;
+    }
+
+    public void increment(int increment) {
+        this.increment = increment;
+    }
+
+    public void execute() {
+        Project project = getProject();
+        String relCurr = project.getProperty("version.id");
+        Matcher m = pattern.matcher(relCurr);
+        m.find();
+        project.setProperty(property, m.group(1)+"."+m.group(2)+"."+(Integer.parseInt(m.group(3))+increment));
+    }
+}

Propchange: poi/trunk/src/excelant/poi-ant-contrib/NextRelease.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: poi/trunk/src/excelant/poi-ant-contrib/PropertyReset.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/excelant/poi-ant-contrib/PropertyReset.java?rev=1881914&view=auto
==============================================================================
--- poi/trunk/src/excelant/poi-ant-contrib/PropertyReset.java (added)
+++ poi/trunk/src/excelant/poi-ant-contrib/PropertyReset.java Tue Sep 22 00:07:32 2020
@@ -0,0 +1,41 @@
+/* ====================================================================
+   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.
+==================================================================== */
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+
+public class PropertyReset extends Task {
+    private String name;
+    private String value;
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public void execute() {
+        Project project = getProject();
+        if (project.getUserProperty(name) != null) {
+            project.setUserProperty(name, value);
+        } else {
+            project.setProperty(name, value);
+        }
+    }
+}
\ No newline at end of file

Propchange: poi/trunk/src/excelant/poi-ant-contrib/PropertyReset.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message