This is an automated email from the ASF dual-hosted git repository.

edimitrova pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 0a6be7e  Substitute ant script and scriptdef with custom ant tasks 
patch by Ekaterina Dimitrova; reviewed by Michaem Semb Wever for CASSANDRA-17224
0a6be7e is described below

commit 0a6be7e4128406a0e3e0f85b54c5e8cae3cd7052
Author: Ekaterina Dimitrova <[email protected]>
AuthorDate: Wed Jan 5 21:07:01 2022 -0500

    Substitute ant script and scriptdef with custom ant tasks
    patch by Ekaterina Dimitrova; reviewed by Michaem Semb Wever for 
CASSANDRA-17224
---
 build.xml                                 | 68 +++++++------------------------
 test/anttasks/EchoEclipseProjectLibs.java | 66 ++++++++++++++++++++++++++++++
 test/anttasks/KeepBriefBrief.java         | 43 +++++++++++++++++++
 test/anttasks/TestHelper.java             | 55 +++++++++++++++++++++++++
 4 files changed, 179 insertions(+), 53 deletions(-)

diff --git a/build.xml b/build.xml
index 3464973..69c96cf 100644
--- a/build.xml
+++ b/build.xml
@@ -55,6 +55,7 @@
     <property name="test.classlistprefix" value="unit"/>
     <property name="benchmark.name" value=""/>
     <property name="test.methods" value=""/>
+    <property name="test.anttasks.src" value="${test.dir}/anttasks"/>
     <property name="test.unit.src" value="${test.dir}/unit"/>
     <property name="test.long.src" value="${test.dir}/long"/>
     <property name="test.burn.src" value="${test.dir}/burn"/>
@@ -149,15 +150,13 @@
          If it's an individual test print the output from the test under the 
assumption someone is debugging the test
          and wants to know what is going on without having to context switch 
to the log file that is generated.
          Debug level output still needs to be retrieved from the log file.  -->
-    <script language="javascript">
-        if (project.getProperty("cassandra.keepBriefBrief") == null)
-        {
-            if (project.getProperty("test.name").equals("*Test"))
-                project.setProperty("cassandra.keepBriefBrief", "true");
-            else
-                project.setProperty("cassandra.keepBriefBrief", "false");
-        }
-    </script>
+    <macrodef name="keepbrief">
+        <sequential>
+                <javac srcdir="test/anttasks" destdir="${test.classes}" 
includeantruntime="true"/>
+                <taskdef name="KeepBriefBrief" 
classname="org.apache.cassandra.anttasks.KeepBriefBrief" 
classpath="${test.classes}"/>
+                <KeepBriefBrief property="cassandra.keepBriefBrief"/>
+        </sequential>
+    </macrodef>
 
     <condition property="java.version.8">
         <equals arg1="${ant.java.version}" arg2="1.8"/>
@@ -508,7 +507,7 @@
           <dependency groupId="org.hdrhistogram" artifactId="HdrHistogram" 
version="2.1.9"/>
           <dependency groupId="commons-cli" artifactId="commons-cli" 
version="1.1"/>
           <dependency groupId="commons-codec" artifactId="commons-codec" 
version="1.9"/>
-          <dependency groupId="commons-io" artifactId="commons-io" 
version="2.6" scope="test"/>
+          <dependency groupId="commons-io" artifactId="commons-io" 
version="2.6"/>
           <dependency groupId="org.apache.commons" artifactId="commons-lang3" 
version="3.11"/>
           <dependency groupId="org.apache.commons" artifactId="commons-math3" 
version="3.2"/>
           <dependency groupId="org.antlr" artifactId="antlr" version="3.5.2" 
scope="provided">
@@ -743,6 +742,7 @@
         <dependency groupId="org.openjdk.jmh" 
artifactId="jmh-generator-annprocess" scope="test"/>
         <dependency groupId="net.ju-n.compile-command-annotations" 
artifactId="compile-command-annotations" scope="test"/>
         <dependency groupId="org.apache.ant" artifactId="ant-junit" 
scope="test"/>
+
         <!-- adding this dependency is necessary for assertj. When updating 
assertj, need to also update the version of
              this that the new assertj's `assertj-parent-pom` depends on. -->
         <dependency groupId="org.junit" artifactId="junit-bom" type="pom"/>
@@ -1386,6 +1386,7 @@
         <pathelement location="${fqltool.build.classes}"/>
      </classpath>
      <compilerarg value="-XDignore.symbol.file"/>
+     <src path="${test.anttasks.src}"/>
      <src path="${test.unit.src}"/>
      <src path="${test.long.src}"/>
      <src path="${test.burn.src}"/>
@@ -1407,7 +1408,8 @@
   <macrodef name="testhelper">
     <attribute name="testdelegate"/>
     <sequential>
-      <testhelper_ testdelegate="@{testdelegate}"/>
+        <taskdef name="testhelper_" 
classname="org.apache.cassandra.anttasks.TestHelper" 
classpath="${test.classes}"/>
+        <testhelper_ property="@{testdelegate}"/>
       <fail message="Some test(s) failed.">
         <condition>
             <and>
@@ -1424,21 +1426,6 @@
   <!-- Run a list of junit tasks but don't track errors or generate a report 
after
        If a test fails the testfailed property will be set. All the tests are 
run using the testdelegate
        macro that is specified as an attribute and they will be run 
sequentially in this ant process -->
-  <scriptdef name="testhelper_" language="javascript">
-    <attribute name="testdelegate"/>
-    <![CDATA[
-        sep = project.getProperty("path.separator");
-        all = project.getProperty("all-test-classes").split(sep);
-        var p = project.createTask('sequential');
-        for (i = 0; i < all.length; i++) {
-            if (all[i] == undefined) continue;
-            task = project.createTask( attributes.get("testdelegate") );
-            task.setDynamicAttribute( "test.file.list", "" + all[i]);
-            p.addTask(task);
-        }
-        p.perform();
-    ]]>
-  </scriptdef>
 
   <!-- Defines how to run a set of tests. If you change the defaults for 
attributes
        you should also update them in testmacro.,
@@ -2158,37 +2145,12 @@
      </fileset>
        </path>
        <property name="eclipse-project-libs" 
refid="eclipse-project-libs-path"/>
-       <script language="javascript">
+      <taskdef name="echoeclipseprojectslibs" 
classname="org.apache.cassandra.anttasks.EchoEclipseProjectLibs" 
classpath="${test.classes}">
         <classpath>
             <path refid="cassandra.classpath"/>
             <path refid="cassandra.classpath.test"/>
         </classpath>
-        <![CDATA[
-        var File = java.io.File;
-               var FilenameUtils = 
Packages.org.apache.commons.io.FilenameUtils;
-               jars = 
project.getProperty("eclipse-project-libs").split(project.getProperty("path.separator"));
-
-               cp = "";
-           for (i=0; i< jars.length; i++) {
-              srcjar = FilenameUtils.getBaseName(jars[i]) + '-sources.jar';
-           srcdir = 
FilenameUtils.concat(project.getProperty("build.test.dir"), 'sources');
-                  srcfile = new File(FilenameUtils.concat(srcdir, srcjar));
-
-                  cp += ' <classpathentry kind="lib" path="' + jars[i] + '"';
-                  if (srcfile.exists()) {
-                     cp += ' sourcepath="' + srcfile.getAbsolutePath() + '"';
-                  }
-                  cp += '/>\n';
-               }
-
-               cp += '</classpath>';
-
-               echo = project.createTask("echo");
-           echo.setMessage(cp);
-               echo.setFile(new File(".classpath"));
-               echo.setAppend(true);
-           echo.perform();
-       ]]> </script>
+        </taskdef>
     <mkdir dir=".settings" />
   </target>
 
diff --git a/test/anttasks/EchoEclipseProjectLibs.java 
b/test/anttasks/EchoEclipseProjectLibs.java
new file mode 100644
index 0000000..c0cfb41
--- /dev/null
+++ b/test/anttasks/EchoEclipseProjectLibs.java
@@ -0,0 +1,66 @@
+/*
+ * 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 org.apache.cassandra.anttasks;
+
+import org.apache.cassandra.io.util.File;
+
+import org.apache.commons.io.FilenameUtils;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.Echo;
+
+public class EchoEclipseProjectLibs extends Task
+{
+    public void execute()
+    {
+        Project project = getProject();
+        StringBuilder msg = buildMsg();
+
+        Echo echo = (Echo) project.createTask("echo");
+        echo.setMessage(msg.toString());
+        echo.setFile(new File(".classpath").toJavaIOFile());
+        echo.setAppend(true);
+        echo.perform();
+    }
+
+    public StringBuilder buildMsg()
+    {
+        Project project = getProject();
+        String[] jars = project.getProperty("eclipse-project-libs")
+                               .split(project.getProperty("path.separator"));
+
+        StringBuilder msg = new StringBuilder();
+        for (int i=0; i< jars.length; i++)
+        {
+            String srcJar = FilenameUtils.getBaseName(jars[i]) + 
"-sources.jar";
+            String srcDir = 
FilenameUtils.concat(project.getProperty("build.test.dir"), "sources");
+            File srcFile = new File(FilenameUtils.concat(srcDir, srcJar));
+
+            msg.append("\" <classpathentry kind=\"lib\" 
path=\"").append(jars[i]).append('"');
+            if (srcFile.exists())
+                msg.append(" 
sourcepath=\"").append(srcFile.path()).append('"');
+            msg.append("/>\n");
+        }
+
+        msg.append("</classpath>");
+
+        return msg;
+    }
+}
diff --git a/test/anttasks/KeepBriefBrief.java 
b/test/anttasks/KeepBriefBrief.java
new file mode 100644
index 0000000..007900b
--- /dev/null
+++ b/test/anttasks/KeepBriefBrief.java
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.cassandra.anttasks;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+
+public class KeepBriefBrief extends Task
+{
+    private String property;
+
+    public void setProperty(String property)
+    {
+        this.property = property;
+    }
+
+    public void execute()
+    {
+        Project project = getProject();
+
+        if (project.getUserProperty(property) == null)
+            if (project.getProperty("test.name").equals("*Test"))
+                project.setProperty(property, "true");
+            else
+                project.setProperty(property, "false");
+    }
+}
diff --git a/test/anttasks/TestHelper.java b/test/anttasks/TestHelper.java
new file mode 100644
index 0000000..be2949a
--- /dev/null
+++ b/test/anttasks/TestHelper.java
@@ -0,0 +1,55 @@
+/*
+ * 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 org.apache.cassandra.anttasks;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.MacroInstance;
+import org.apache.tools.ant.taskdefs.Sequential;
+
+public class TestHelper extends Task
+{
+    private String property;
+
+    public void setProperty(String property)
+    {
+        this.property = property;
+    }
+
+    public void execute()
+    {
+        Project project = getProject();
+
+        String sep = project.getProperty("path.separator");
+        String[] allTestClasses = 
project.getProperty("all-test-classes").split(sep);
+
+        Sequential seqTask = (Sequential) project.createTask("sequential");
+        for (int i=0; i< allTestClasses.length; i++)
+        {
+            if (allTestClasses[i] == null)
+                continue;
+
+            MacroInstance task = (MacroInstance) project.createTask(property);
+            task.setDynamicAttribute("test.file.list", ' ' + 
allTestClasses[i]);
+            seqTask.addTask(task);
+        }
+
+        seqTask.perform();
+    }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to