Merge pull request #141 from TheConstructor/input-file-tokenizer
#64855 Add filterbeforeconcat option to Concat
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 0a9026a..5b9639b 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -285,6 +285,7 @@
Matthew Yanos
Matthias Bhend
Matthias Gutheil
+Matthias Johann Vill
Michael Bayne
Michael Clarke
Michael Davey
diff --git a/WHATSNEW b/WHATSNEW
index f17bf4b..b9bbf3d 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -1,6 +1,32 @@
Changes from Ant 1.10.9 TO Ant 1.10.10
======================================
+Fixed bugs:
+-----------
+
+ * SCP (with sftp=true) task would fail if fetching file located in root directory
+ Bugzilla Report 64742
+
+Other changes:
+--------------
+
+ * javaversion condition now has a new "atmost" attribute. See the javaversion
+ manual for more details
+
+ * The "listener" nested element of the "junitlauncher" task now has a new
+ "useLegacyReportingName" attribute which can be used to control the test
+ identifiers names that get reported by the listener. See the junitlauncher
+ manual for more details.
+ Note that this change also introduces a new "setUseLegacyReportingName" method
+ on the org.apache.tools.ant.taskdefs.optional.junitlauncher.TestResultFormatter
+ interface. This will break backward compatibility with any of your custom
+ result formatters which implemented this interface and such implementations
+ are now expected to implement this new method.
+
+ * a new attribute preserveduplicates allows <resourcelist> to return
+ the same resource multiple times when set to true.
+ Bugzilla Report 64854
+
Changes from Ant 1.10.8 TO Ant 1.10.9
=====================================
diff --git a/contributors.xml b/contributors.xml
index 18cb423..bbdb03c 100644
--- a/contributors.xml
+++ b/contributors.xml
@@ -1184,6 +1184,11 @@
<last>Gutheil</last>
</name>
<name>
+ <first>Matthias</first>
+ <middle>Johann</middle>
+ <last>Vill</last>
+ </name>
+ <name>
<first>Michael</first>
<last>Bayne</last>
</name>
diff --git a/manual/Tasks/conditions.html b/manual/Tasks/conditions.html
index 846733f..247f2dd 100644
--- a/manual/Tasks/conditions.html
+++ b/manual/Tasks/conditions.html
@@ -945,11 +945,19 @@
<th scope="col">Required</th>
</tr>
<tr>
- <td>atleast</td>
+ <td class="left">atleast</td>
<td>The version that this JVM is of at least. The format
is <code>major.minor.point</code>. Starting with Java 9 really only the major number is
determined.</td>
- <td rowspan="2">Exactly one of the two</td>
+ <td rowspan="3">Exactly one of the three</td>
+ </tr>
+ <tr>
+ <td>atmost</td>
+ <td class="left">The version that this JVM is of at most. The format
+ is <code>major.minor.point</code>. Starting with Java 9 really only the major number is
+ determined.<br/>
+ <em>Since Ant 1.10.10</em>
+ </td>
</tr>
<tr>
<td>exactly</td>
diff --git a/manual/Tasks/junitlauncher.html b/manual/Tasks/junitlauncher.html
index ec14e03..4a96e71 100644
--- a/manual/Tasks/junitlauncher.html
+++ b/manual/Tasks/junitlauncher.html
@@ -402,6 +402,14 @@
is <strong>not</strong> set</a>.</td>
<td>No</td>
</tr>
+ <tr>
+ <td>useLegacyReportingName</td>
+ <td>Set to true, if the test identifiers reported by this listener should use legacy (JUnit4
+ style) names. Else set to false. Defaults to true.
+ <p><em>Since Ant 1.10.10</em></p>
+ </td>
+ <td>No</td>
+ </tr>
</table>
<h4>test</h4>
diff --git a/manual/Types/resources.html b/manual/Types/resources.html
index 184ec02..5783fd1 100644
--- a/manual/Types/resources.html
+++ b/manual/Types/resources.html
@@ -1420,6 +1420,14 @@
<td>No</td>
</tr>
<tr>
+ <td>preserveduplicates</td>
+ <td>Makes this <code>resourcelist</code> return all resources as
+ many times as they are specified. Otherwise
+ <code>resourcelist</code> will only return each resource, in the
+ order they first appear. <em>Since Ant 1.10.10</em></td>
+ <td>No</td>
+ </tr>
+ <tr>
<td>refid</td>
<td>Makes this <code>resourcelist</code>
a <a href="../using.html#references">reference</a> to
diff --git a/src/etc/testcases/taskdefs/optional/junitlauncher.xml b/src/etc/testcases/taskdefs/optional/junitlauncher.xml
index f86ddc8..87b00ad 100644
--- a/src/etc/testcases/taskdefs/optional/junitlauncher.xml
+++ b/src/etc/testcases/taskdefs/optional/junitlauncher.xml
@@ -161,7 +161,7 @@
<sysproperty key="junitlauncher.test.sysprop.one" value="forked"/>
</fork>
- <listener type="legacy-xml" sendSysErr="true" sendSysOut="true"/>
+ <listener type="legacy-xml" sendSysErr="true" sendSysOut="true" useLegacyReportingName="false"/>
</test>
</junitlauncher>
</target>
@@ -368,6 +368,7 @@
</fork>
</testclasses>
<listener type="legacy-plain" sendSysOut="true" />
+ <listener type="legacy-brief" sendSysOut="true" useLegacyReportingName="true"/>
</junitlauncher>
</target>
</project>
diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/JavaVersion.java b/src/main/org/apache/tools/ant/taskdefs/condition/JavaVersion.java
index e121c30..a221495 100644
--- a/src/main/org/apache/tools/ant/taskdefs/condition/JavaVersion.java
+++ b/src/main/org/apache/tools/ant/taskdefs/condition/JavaVersion.java
@@ -23,10 +23,11 @@
/**
* An Java version condition.
- * @since Java 1.10.2
+ * @since Ant 1.10.2
*/
public class JavaVersion implements Condition {
+ private String atMost = null;
private String atLeast = null;
private String exactly = null;
@@ -44,16 +45,19 @@
if (null != exactly) {
return actual.isEqual(new DeweyDecimal(exactly));
}
+ if (atMost != null) {
+ return actual.isLessThanOrEqual(new DeweyDecimal(atMost));
+ }
//default
return false;
}
private void validate() throws BuildException {
- if (atLeast != null && exactly != null) {
- throw new BuildException("Only one of atleast or exactly may be set.");
+ if (atLeast != null && exactly != null && atMost != null) {
+ throw new BuildException("Only one of atleast or atmost or exactly may be set.");
}
- if (null == atLeast && null == exactly) {
- throw new BuildException("One of atleast or exactly must be set.");
+ if (null == atLeast && null == exactly && atMost == null) {
+ throw new BuildException("One of atleast or atmost or exactly must be set.");
}
if (atLeast != null) {
try {
@@ -64,6 +68,14 @@
"The 'atleast' attribute is not a Dewey Decimal eg 1.1.0 : "
+ atLeast);
}
+ } else if (atMost != null) {
+ try {
+ new DeweyDecimal(atMost); //NOSONAR
+ } catch (NumberFormatException e) {
+ throw new BuildException(
+ "The 'atmost' attribute is not a Dewey Decimal eg 1.1.0 : "
+ + atMost);
+ }
} else {
try {
// only created for side effect
@@ -88,13 +100,33 @@
* Set the atleast attribute.
* This is of the form major.minor.point.
* For example 1.7.0.
- * @param atLeast the version to check against.
+ * @param atLeast the version to set
*/
public void setAtLeast(String atLeast) {
this.atLeast = atLeast;
}
/**
+ * Get the atmost attribute.
+ * @return the atmost attribute.
+ * @since Ant 1.10.10
+ */
+ public String getAtMost() {
+ return atMost;
+ }
+
+ /**
+ * Set the atmost attribute.
+ * This is of the form major.minor.point.
+ * For example 11.0.2
+ * @param atMost the version to set
+ * @since Ant 1.10.10
+ */
+ public void setAtMost(String atMost) {
+ this.atMost = atMost;
+ }
+
+ /**
* Get the exactly attribute.
* @return the exactly attribute.
*/
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
index a5ce996..3b56016 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
@@ -226,6 +226,7 @@
testRequest.closeUponCompletion(resultFormatter);
// set the execution context
resultFormatter.setContext(this.testExecutionContext);
+ resultFormatter.setUseLegacyReportingName(formatterDefinition.isUseLegacyReportingName());
// set the destination output stream for writing out the formatted result
final java.nio.file.Path resultOutputFile = getListenerOutputFile(testRequest, formatterDefinition);
try {
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyPlainResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyPlainResultFormatter.java
index 997e86e..7583d78 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyPlainResultFormatter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyPlainResultFormatter.java
@@ -47,6 +47,7 @@
private final Map<TestIdentifier, Stats> testIds = new ConcurrentHashMap<>();
private TestPlan testPlan;
private BufferedWriter writer;
+ private boolean useLegacyReportingName = true;
@Override
public void testPlanExecutionStarted(final TestPlan testPlan) {
@@ -111,7 +112,7 @@
if (testIdentifier.isTest()) {
final StringBuilder sb = new StringBuilder();
sb.append("Test: ");
- sb.append(testIdentifier.getLegacyReportingName());
+ sb.append(this.useLegacyReportingName ? testIdentifier.getLegacyReportingName() : testIdentifier.getDisplayName());
sb.append(" took ");
stats.appendElapsed(sb);
sb.append(" SKIPPED");
@@ -175,7 +176,7 @@
if (testIdentifier.isTest() && shouldReportExecutionFinished(testIdentifier, testExecutionResult)) {
final StringBuilder sb = new StringBuilder();
sb.append("Test: ");
- sb.append(testIdentifier.getLegacyReportingName());
+ sb.append(this.useLegacyReportingName ? testIdentifier.getLegacyReportingName() : testIdentifier.getDisplayName());
if (stats != null) {
sb.append(" took ");
stats.appendElapsed(sb);
@@ -230,6 +231,11 @@
this.writer = new BufferedWriter(new OutputStreamWriter(this.outputStream, StandardCharsets.UTF_8));
}
+ @Override
+ public void setUseLegacyReportingName(final boolean useLegacyReportingName) {
+ this.useLegacyReportingName = useLegacyReportingName;
+ }
+
protected boolean shouldReportExecutionFinished(final TestIdentifier testIdentifier, final TestExecutionResult testExecutionResult) {
return true;
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
index dad1cc8..c0d4bee 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
@@ -63,6 +63,7 @@
private final AtomicLong numTestsFailed = new AtomicLong(0);
private final AtomicLong numTestsSkipped = new AtomicLong(0);
private final AtomicLong numTestsAborted = new AtomicLong(0);
+ private boolean useLegacyReportingName = true;
@Override
@@ -141,6 +142,11 @@
this.outputStream = os;
}
+ @Override
+ public void setUseLegacyReportingName(final boolean useLegacyReportingName) {
+ this.useLegacyReportingName = useLegacyReportingName;
+ }
+
private final class Stats {
@SuppressWarnings("unused")
private final TestIdentifier testIdentifier;
@@ -252,7 +258,8 @@
final String classname = (parentClassSource.get()).getClassName();
writer.writeStartElement(ELEM_TESTCASE);
writer.writeAttribute(ATTR_CLASSNAME, classname);
- writer.writeAttribute(ATTR_NAME, testId.getLegacyReportingName());
+ writer.writeAttribute(ATTR_NAME, useLegacyReportingName ? testId.getLegacyReportingName()
+ : testId.getDisplayName());
final Stats stats = entry.getValue();
writer.writeAttribute(ATTR_TIME, String.valueOf((stats.endedAt - stats.startedAt) / ONE_SECOND));
// skipped element if the test was skipped
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/TestResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/TestResultFormatter.java
index f59641b..4de168a 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/TestResultFormatter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/TestResultFormatter.java
@@ -51,6 +51,17 @@
void setContext(TestExecutionContext context);
/**
+ * This method will be invoked by the {@code junitlauncher} to let the result formatter implementation
+ * know whether or not to use JUnit 4 style, legacy reporting names for test identifiers that get
+ * displayed in the test reports. Result formatter implementations are allowed to default to a specific
+ * reporting style for test identifiers, if this method isn't invoked.
+ * @param useLegacyReportingName {@code true} if legacy reporting name is to be used, {@code false}
+ * otherwise.
+ * @since Ant 1.10.10
+ */
+ void setUseLegacyReportingName(boolean useLegacyReportingName);
+
+ /**
* This method will be invoked by the <code>junitlauncher</code>, <strong>regularly/multiple times</strong>,
* as and when any content is generated on the standard output stream during the test execution.
* This method will be only be called if the <code>sendSysOut</code> attribute of the <code>listener</code>,
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/Constants.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/Constants.java
index ddd5902..7117907 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/Constants.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/Constants.java
@@ -48,6 +48,7 @@
public static final String LD_XML_ATTR_SEND_SYS_ERR = "sendSysErr";
public static final String LD_XML_ATTR_SEND_SYS_OUT = "sendSysOut";
public static final String LD_XML_ATTR_LISTENER_RESULT_FILE = "resultFile";
+ public static final String LD_XML_ATTR_LISTENER_USE_LEGACY_REPORTING_NAME = "useLegacyReportingName";
private Constants() {
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java
index c600e60..ce9fdee 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java
@@ -28,6 +28,7 @@
import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_CLASS_NAME;
import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_LISTENER_RESULT_FILE;
+import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_LISTENER_USE_LEGACY_REPORTING_NAME;
import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_OUTPUT_DIRECTORY;
import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_SEND_SYS_ERR;
import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_SEND_SYS_OUT;
@@ -51,6 +52,7 @@
private boolean sendSysOut;
private boolean sendSysErr;
private String outputDir;
+ private boolean useLegacyReportingName = true;
public ListenerDefinition() {
@@ -135,6 +137,26 @@
return this.outputDir;
}
+ /**
+ *
+ * @return Returns {@code true} if legacy reporting name (JUnit 4 style) is to be used.
+ * Else returns {@code false}.
+ * @since Ant 1.10.10
+ */
+ public boolean isUseLegacyReportingName() {
+ return useLegacyReportingName;
+ }
+
+ /**
+ * Set the test identifier reporting style
+ * @param useLegacyReportingName {@code true} if legacy reporting name (JUnit 4 style) is to
+ * be used. Else {@code false}.
+ * @since Ant 1.10.10
+ */
+ public void setUseLegacyReportingName(final boolean useLegacyReportingName) {
+ this.useLegacyReportingName = useLegacyReportingName;
+ }
+
public boolean shouldUse(final Project project) {
final PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(project);
return propertyHelper.testIfCondition(this.ifProperty) && propertyHelper.testUnlessCondition(this.unlessProperty);
@@ -157,6 +179,7 @@
writer.writeAttribute(LD_XML_ATTR_CLASS_NAME, this.className);
writer.writeAttribute(LD_XML_ATTR_SEND_SYS_ERR, Boolean.toString(this.sendSysErr));
writer.writeAttribute(LD_XML_ATTR_SEND_SYS_OUT, Boolean.toString(this.sendSysOut));
+ writer.writeAttribute(LD_XML_ATTR_LISTENER_USE_LEGACY_REPORTING_NAME, Boolean.toString(this.useLegacyReportingName));
if (this.outputDir != null) {
writer.writeAttribute(LD_XML_ATTR_OUTPUT_DIRECTORY, this.outputDir);
}
@@ -187,6 +210,11 @@
if (resultFile != null) {
listenerDef.setResultFile(resultFile);
}
+ final String useLegacyReportingName = reader.getAttributeValue(null,
+ LD_XML_ATTR_LISTENER_USE_LEGACY_REPORTING_NAME);
+ if (useLegacyReportingName != null) {
+ listenerDef.setUseLegacyReportingName(Boolean.parseBoolean(useLegacyReportingName));
+ }
reader.nextTag();
reader.require(XMLStreamConstants.END_ELEMENT, null, LD_XML_ELM_LISTENER);
return listenerDef;
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java
index 0ad0899..7e5edab 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java
@@ -134,9 +134,16 @@
final String remoteFile,
final File localFile) throws SftpException {
String pwd = remoteFile;
- if (remoteFile.lastIndexOf('/') != -1) {
+ final int lastIndexOfFileSeparator = remoteFile.lastIndexOf('/');
+ if (lastIndexOfFileSeparator != -1) {
if (remoteFile.length() > 1) {
- pwd = remoteFile.substring(0, remoteFile.lastIndexOf('/'));
+ if (lastIndexOfFileSeparator == 0) {
+ // the file path is of the form "/foo....." i.e. the file separator
+ // occurs at the start (and only there).
+ pwd = "/";
+ } else {
+ pwd = remoteFile.substring(0, lastIndexOfFileSeparator);
+ }
}
}
channel.cd(pwd);
diff --git a/src/main/org/apache/tools/ant/types/resources/AppendableResourceCollection.java b/src/main/org/apache/tools/ant/types/resources/AppendableResourceCollection.java
new file mode 100644
index 0000000..cc7bd53
--- /dev/null
+++ b/src/main/org/apache/tools/ant/types/resources/AppendableResourceCollection.java
@@ -0,0 +1,38 @@
+/*
+ * 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
+ *
+ * https://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.tools.ant.types.resources;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.ResourceCollection;
+
+/**
+ * Interface describing a collection of Resources, to which elements can be
+ * appended.
+ *
+ * @since Ant 1.10.10
+ */
+public interface AppendableResourceCollection extends ResourceCollection {
+ /**
+ Add a ResourceCollection to the container.
+
+ @param c the ResourceCollection to add.
+ @throws BuildException on error.
+ @since Ant 1.10.10
+ */
+ void add(ResourceCollection c) throws BuildException;
+}
diff --git a/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java b/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
index 66dbda7..b066a5f 100644
--- a/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
+++ b/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
@@ -37,7 +37,7 @@
* @since Ant 1.7
*/
public abstract class BaseResourceCollectionContainer
- extends DataType implements ResourceCollection, Cloneable {
+ extends DataType implements AppendableResourceCollection, Cloneable {
private List<ResourceCollection> rc = new ArrayList<>();
private Collection<Resource> coll = null;
private boolean cache = true;
@@ -92,6 +92,7 @@
* @param c the ResourceCollection to add.
* @throws BuildException on error.
*/
+ @Override
public synchronized void add(ResourceCollection c) throws BuildException {
if (isReference()) {
throw noChildrenAllowed();
diff --git a/src/main/org/apache/tools/ant/types/resources/ResourceList.java b/src/main/org/apache/tools/ant/types/resources/ResourceList.java
index 2925cb4..9000af3 100644
--- a/src/main/org/apache/tools/ant/types/resources/ResourceList.java
+++ b/src/main/org/apache/tools/ant/types/resources/ResourceList.java
@@ -47,14 +47,10 @@
public class ResourceList extends DataType implements ResourceCollection {
private final Vector<FilterChain> filterChains = new Vector<>();
private final ArrayList<ResourceCollection> textDocuments = new ArrayList<>();
- private final Union cachedResources = new Union();
- private volatile boolean cached = false;
+ private AppendableResourceCollection cachedResources = null;
private String encoding = null;
private File baseDir;
-
- public ResourceList() {
- cachedResources.setCache(true);
- }
+ private boolean preserveDuplicates = false;
/**
* Adds a source.
@@ -117,6 +113,22 @@
}
/**
+ * Makes this <code>resourcelist</code> return all resources as
+ * many times as they are specified. Otherwise
+ * <code>resourcelist</code> will only return each resource, in the
+ * order they first appear.
+ *
+ * @param preserveDuplicates boolean
+ * @since Ant 1.10.10
+ */
+ public final void setPreserveDuplicates(boolean preserveDuplicates) {
+ if (isReference()) {
+ throw tooManyAttributes();
+ }
+ this.preserveDuplicates = preserveDuplicates;
+ }
+
+ /**
* Makes this instance in effect a reference to another ResourceList
* instance.
*
@@ -207,20 +219,31 @@
return getCheckedRef(ResourceList.class);
}
+ private AppendableResourceCollection newResourceCollection() {
+ if (preserveDuplicates) {
+ final Resources resources = new Resources();
+ resources.setCache(true);
+ return resources;
+ } else {
+ final Union union = new Union();
+ union.setCache(true);
+ return union;
+ }
+ }
+
private synchronized ResourceCollection cache() {
- if (!cached) {
+ if (cachedResources == null) {
dieOnCircularReference();
+ this.cachedResources = newResourceCollection();
textDocuments.stream().flatMap(ResourceCollection::stream)
.map(this::read).forEach(cachedResources::add);
- cached = true;
}
return cachedResources;
}
private ResourceCollection read(Resource r) {
try (BufferedReader reader = new BufferedReader(open(r))) {
- Union streamResources = new Union();
- streamResources.setCache(true);
+ final AppendableResourceCollection streamResources = newResourceCollection();
reader.lines().map(this::parse).forEach(streamResources::add);
return streamResources;
} catch (final IOException ioe) {
diff --git a/src/main/org/apache/tools/ant/types/resources/Resources.java b/src/main/org/apache/tools/ant/types/resources/Resources.java
index a74557a..a832f63 100644
--- a/src/main/org/apache/tools/ant/types/resources/Resources.java
+++ b/src/main/org/apache/tools/ant/types/resources/Resources.java
@@ -40,7 +40,7 @@
* making no attempt to remove duplicates, or references another ResourceCollection.
* @since Ant 1.7
*/
-public class Resources extends DataType implements ResourceCollection {
+public class Resources extends DataType implements AppendableResourceCollection {
/** static empty ResourceCollection */
public static final ResourceCollection NONE = new ResourceCollection() {
@Override
@@ -156,6 +156,7 @@
* Add a ResourceCollection.
* @param c the ResourceCollection to add.
*/
+ @Override
public synchronized void add(ResourceCollection c) {
if (isReference()) {
throw noChildrenAllowed();
diff --git a/src/tests/antunit/taskdefs/condition/javaversion-test.xml b/src/tests/antunit/taskdefs/condition/javaversion-test.xml
index a5d9a21..586cad0 100644
--- a/src/tests/antunit/taskdefs/condition/javaversion-test.xml
+++ b/src/tests/antunit/taskdefs/condition/javaversion-test.xml
@@ -25,6 +25,20 @@
</au:assertTrue>
</target>
+ <target name="test-atmost">
+ <au:assertTrue message="Expected javaversion ${java.version} to be at most 1000.111.211">
+ <!-- a high version value so that the check passes -->
+ <javaversion atmost="1000.111.211" />
+ </au:assertTrue>
+ </target>
+
+ <target name="test-atmost-negative">
+ <au:assertFalse message="Expected javaversion ${java.version} to be at most 1.4.0">
+ <!-- Ant 1.10.x requires Java 8 at runtime - so this check is expected to return false -->
+ <javaversion atmost="1.4.0" />
+ </au:assertFalse>
+ </target>
+
<target name="test-exactly">
<au:assertTrue message="Expected javaversion of ${ant.java.version}">
<javaversion exactly="${ant.java.version}" />
diff --git a/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml b/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml
index b604aa2..e2a7718 100644
--- a/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml
+++ b/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml
@@ -26,13 +26,17 @@
</description>
<condition property="prereqs-ok">
- <or>
- <and>
- <available classname="org.apache.bsf.BSFManager" />
- <available classname="org.apache.bsf.engines.javascript.JavaScriptEngine" />
- </and>
- <available classname="javax.script.ScriptEngineManager" />
- </or>
+ <and>
+ <!-- Starting Java 15, there's no "javascript" script engine (not even nashorn) bundled in JRE -->
+ <javaversion atmost="14"/>
+ <or>
+ <and>
+ <available classname="org.apache.bsf.BSFManager" />
+ <available classname="org.apache.bsf.engines.javascript.JavaScriptEngine" />
+ </and>
+ <available classname="javax.script.ScriptEngineManager" />
+ </or>
+ </and>
</condition>
<!-- auto doesn't verify the language is supported and selects BSF
diff --git a/src/tests/antunit/types/resources/resourcelist-test.xml b/src/tests/antunit/types/resources/resourcelist-test.xml
index 2575b65..602ee54 100644
--- a/src/tests/antunit/types/resources/resourcelist-test.xml
+++ b/src/tests/antunit/types/resources/resourcelist-test.xml
@@ -101,4 +101,41 @@
</copy>
<au:assertFileExists file="${output}/antlib.xml"/>
</target>
+
+ <target name="testDuplicatesRemoved" depends="setUp">
+ <echo file="${input}/a.txt">${input}/b.txt
+${input}/b.txt</echo>
+ <echo file="${input}/b.txt">Demo content</echo>
+ <echo file="${input}/c.txt">${input}/b.txt
+${input}/b.txt</echo>
+ <pathconvert property="1b" pathsep="|" preserveduplicates="true">
+ <flattenmapper/>
+ <resourcelist>
+ <resources>
+ <file file="${input}/a.txt"/>
+ <file file="${input}/c.txt"/>
+ </resources>
+ </resourcelist>
+ </pathconvert>
+ <au:assertPropertyEquals name="1b" value="b.txt"/>
+ </target>
+
+ <target name="testDuplicatesPreserved" depends="setUp">
+ <echo file="${input}/a.txt">${input}/b.txt
+${input}/b.txt</echo>
+ <echo file="${input}/b.txt">Demo content</echo>
+ <echo file="${input}/c.txt">${input}/b.txt
+${input}/b.txt</echo>
+ <pathconvert property="4bs" pathsep="|" preserveduplicates="true">
+ <flattenmapper/>
+ <resourcelist preserveduplicates="true">
+ <resources>
+ <file file="${input}/a.txt"/>
+ <file file="${input}/a.txt"/>
+ <file file="${input}/c.txt"/>
+ </resources>
+ </resourcelist>
+ </pathconvert>
+ <au:assertPropertyEquals name="4bs" value="b.txt|b.txt|b.txt|b.txt|b.txt|b.txt"/>
+ </target>
</project>
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
index 667db43..4ebf3d6 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
@@ -20,7 +20,9 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.condition.JavaVersion;
import org.apache.tools.ant.types.FileSet;
+import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -155,7 +157,11 @@
@Test
public void testUseCompiled() {
-
+ final JavaVersion atMostJava14 = new JavaVersion();
+ atMostJava14.setAtMost("14");
+ // skip execution since this compilation timing based test consistently fails starting Java 15 (where we use
+ // Graal libraries for Javascript engine)
+ Assume.assumeTrue("Skipping test execution since Java version is greater than Java 14", atMostJava14.eval());
final long duration;
{
long start = System.nanoTime();
diff --git a/src/tests/junit/org/example/junitlauncher/Tracker.java b/src/tests/junit/org/example/junitlauncher/Tracker.java
index ba31ec8..ec5f30a 100644
--- a/src/tests/junit/org/example/junitlauncher/Tracker.java
+++ b/src/tests/junit/org/example/junitlauncher/Tracker.java
@@ -74,6 +74,11 @@
}
@Override
+ public void setUseLegacyReportingName(final boolean useLegacyReportingName) {
+ // do nothing
+ }
+
+ @Override
public void close() throws IOException {
this.writer.flush();
if (this.appendModeFile != null) {