Skip to content

Commit

Permalink
Substitute ant script and scriptdef with custom ant tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ekaterinadimitrova2 committed Jan 18, 2022
1 parent 76f8333 commit 0c6eb6e
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 53 deletions.
68 changes: 15 additions & 53 deletions build.xml
Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -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}"/>
Expand All @@ -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>
Expand All @@ -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.,
Expand Down Expand Up @@ -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>

Expand Down
66 changes: 66 additions & 0 deletions 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;
}
}
43 changes: 43 additions & 0 deletions 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");
}
}
55 changes: 55 additions & 0 deletions 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();
}
}

0 comments on commit 0c6eb6e

Please sign in to comment.