@@ -47,7 +47,7 @@ import org.apache.tools.ant.property.ResolvePropertyMap; | |||
import org.apache.tools.ant.util.ClasspathUtils; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.ProxySetup; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
/** | |||
* Command line entry point into Ant. This class is entered via the | |||
@@ -1266,7 +1266,7 @@ public class Main implements AntMain { | |||
} | |||
msg.append(eol); | |||
if (!dependencies.isEmpty() && dependencies.elementAt(i).hasMoreElements()) { | |||
msg.append(Collections.list(dependencies.elementAt(i)).stream() | |||
msg.append(StreamUtils.enumerationAsStream(dependencies.elementAt(i)) | |||
.collect(Collectors.joining(", ", " depends on: ", eol))); | |||
} | |||
} | |||
@@ -32,6 +32,7 @@ import java.util.stream.Stream; | |||
import org.apache.tools.ant.helper.ProjectHelper2; | |||
import org.apache.tools.ant.types.Resource; | |||
import org.apache.tools.ant.util.LoaderUtils; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
/** | |||
* Repository of {@link ProjectHelper} found in the classpath or via | |||
@@ -77,8 +78,7 @@ public class ProjectHelperRepository { | |||
private void collectProjectHelpers() { | |||
// First, try the system property | |||
Constructor<? extends ProjectHelper> projectHelper = getProjectHelperBySystemProperty(); | |||
registerProjectHelper(projectHelper); | |||
registerProjectHelper(getProjectHelperBySystemProperty()); | |||
// A JDK1.3 'service' (like in JAXP). That will plug a helper | |||
// automatically if in CLASSPATH, with the right META-INF/services. | |||
@@ -88,17 +88,14 @@ public class ProjectHelperRepository { | |||
for (URL resource : Collections.list(classLoader.getResources(ProjectHelper.SERVICE_ID))) { | |||
URLConnection conn = resource.openConnection(); | |||
conn.setUseCaches(false); | |||
projectHelper = | |||
getProjectHelperByService(conn.getInputStream()); | |||
registerProjectHelper(projectHelper); | |||
registerProjectHelper(getProjectHelperByService(conn.getInputStream())); | |||
} | |||
} | |||
InputStream systemResource = | |||
ClassLoader.getSystemResourceAsStream(ProjectHelper.SERVICE_ID); | |||
if (systemResource != null) { | |||
projectHelper = getProjectHelperByService(systemResource); | |||
registerProjectHelper(projectHelper); | |||
registerProjectHelper(getProjectHelperByService(systemResource)); | |||
} | |||
} catch (Exception e) { | |||
System.err.println("Unable to load ProjectHelper from service " | |||
@@ -250,20 +247,19 @@ public class ProjectHelperRepository { | |||
* @return the first ProjectHelper that fit the requirement (never <code>null</code>). | |||
*/ | |||
public ProjectHelper getProjectHelperForBuildFile(Resource buildFile) throws BuildException { | |||
for (Iterator<ProjectHelper> it = getHelpers(); it.hasNext();) { | |||
ProjectHelper helper = it.next(); | |||
if (helper.canParseBuildFile(buildFile)) { | |||
if (DEBUG) { | |||
System.out.println("ProjectHelper " | |||
+ helper.getClass().getName() | |||
+ " selected for the build file " | |||
+ buildFile); | |||
} | |||
return helper; | |||
} | |||
ProjectHelper ph = StreamUtils.iteratorAsStream(getHelpers()) | |||
.filter(helper -> helper.canParseBuildFile(buildFile)) | |||
.findFirst().orElse(null); | |||
if (ph == null) { | |||
throw new BuildException("BUG: at least the ProjectHelper2 should " | |||
+ "have supported the file " + buildFile); | |||
} | |||
if (DEBUG) { | |||
System.out.println("ProjectHelper " + ph.getClass().getName() | |||
+ " selected for the build file " + buildFile); | |||
} | |||
throw new BuildException("BUG: at least the ProjectHelper2 should " | |||
+ "have supported the file " + buildFile); | |||
return ph; | |||
} | |||
/** | |||
@@ -274,20 +270,19 @@ public class ProjectHelperRepository { | |||
* @return the first ProjectHelper that fit the requirement (never <code>null</code>). | |||
*/ | |||
public ProjectHelper getProjectHelperForAntlib(Resource antlib) throws BuildException { | |||
for (Iterator<ProjectHelper> it = getHelpers(); it.hasNext();) { | |||
ProjectHelper helper = it.next(); | |||
if (helper.canParseAntlibDescriptor(antlib)) { | |||
if (DEBUG) { | |||
System.out.println("ProjectHelper " | |||
+ helper.getClass().getName() | |||
+ " selected for the antlib " | |||
+ antlib); | |||
} | |||
return helper; | |||
} | |||
ProjectHelper ph = StreamUtils.iteratorAsStream(getHelpers()) | |||
.filter(helper -> helper.canParseAntlibDescriptor(antlib)) | |||
.findFirst().orElse(null); | |||
if (ph == null) { | |||
throw new BuildException("BUG: at least the ProjectHelper2 should " | |||
+ "have supported the file " + antlib); | |||
} | |||
if (DEBUG) { | |||
System.out.println("ProjectHelper " + ph.getClass().getName() | |||
+ " selected for the antlib " + antlib); | |||
} | |||
throw new BuildException("BUG: at least the ProjectHelper2 should " | |||
+ "have supported the file " + antlib); | |||
return ph; | |||
} | |||
/** | |||
@@ -24,7 +24,6 @@ import java.io.PrintStream; | |||
import java.io.Writer; | |||
import java.nio.file.Files; | |||
import java.nio.file.Paths; | |||
import java.util.Collections; | |||
import java.util.Hashtable; | |||
import java.util.Stack; | |||
@@ -32,6 +31,7 @@ import javax.xml.parsers.DocumentBuilder; | |||
import javax.xml.parsers.DocumentBuilderFactory; | |||
import org.apache.tools.ant.util.DOMElementWriter; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
import org.apache.tools.ant.util.StringUtils; | |||
import org.w3c.dom.Document; | |||
import org.w3c.dom.Element; | |||
@@ -345,7 +345,8 @@ public class XmlLogger implements BuildLogger { | |||
if (element != null) { | |||
return element; | |||
} | |||
return Collections.list(tasks.keys()).stream().filter(UnknownElement.class::isInstance) | |||
return StreamUtils.enumerationAsStream(tasks.keys()) | |||
.filter(UnknownElement.class::isInstance) | |||
.filter(key -> ((UnknownElement) key).getTask() == task).findFirst() | |||
.map(key -> tasks.get(key)).orElse(null); | |||
} | |||
@@ -25,7 +25,6 @@ import java.lang.reflect.Method; | |||
import java.nio.file.Files; | |||
import java.util.HashMap; | |||
import java.util.HashSet; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Objects; | |||
@@ -33,7 +32,6 @@ import java.util.Set; | |||
import java.util.Vector; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildListener; | |||
import org.apache.tools.ant.DefaultLogger; | |||
import org.apache.tools.ant.MagicNames; | |||
import org.apache.tools.ant.Main; | |||
@@ -197,10 +195,7 @@ public class Ant extends Task { | |||
private void initializeProject() { | |||
newProject.setInputHandler(getProject().getInputHandler()); | |||
Iterator<BuildListener> iter = getBuildListeners(); | |||
while (iter.hasNext()) { | |||
newProject.addBuildListener(iter.next()); | |||
} | |||
getProject().getBuildListeners().forEach(bl -> newProject.addBuildListener(bl)); | |||
if (output != null) { | |||
File outfile; | |||
@@ -748,13 +743,6 @@ public class Ant extends Task { | |||
return newProject; | |||
} | |||
/** | |||
* @since Ant 1.6.2 | |||
*/ | |||
private Iterator<BuildListener> getBuildListeners() { | |||
return getProject().getBuildListeners().iterator(); | |||
} | |||
/** | |||
* Helper class that implements the nested <reference> | |||
* element of <ant> and <antcall>. | |||
@@ -38,6 +38,7 @@ import org.apache.tools.ant.types.resources.comparators.Reverse; | |||
import org.apache.tools.ant.types.resources.selectors.Exists; | |||
import org.apache.tools.ant.types.resources.selectors.Not; | |||
import org.apache.tools.ant.types.resources.selectors.ResourceSelector; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
/** | |||
* Examines and removes out of date target files. If any of the target files | |||
@@ -263,18 +264,8 @@ public class DependSet extends MatchingTask { | |||
} | |||
private Resource getXest(ResourceCollection rc, ResourceComparator c) { | |||
Iterator<Resource> i = rc.iterator(); | |||
if (!i.hasNext()) { | |||
return null; | |||
} | |||
Resource xest = i.next(); | |||
while (i.hasNext()) { | |||
Resource next = i.next(); | |||
if (c.compare(xest, next) < 0) { | |||
xest = next; | |||
} | |||
} | |||
return xest; | |||
return StreamUtils.iteratorAsStream(rc.iterator()) | |||
.min(c::compare).orElse(null); | |||
} | |||
private Resource getOldest(ResourceCollection rc) { | |||
@@ -28,7 +28,6 @@ import java.io.UnsupportedEncodingException; | |||
import java.util.HashMap; | |||
import java.util.LinkedHashMap; | |||
import java.util.Map; | |||
import java.util.Map.Entry; | |||
import java.util.Vector; | |||
import org.apache.tools.ant.BuildException; | |||
@@ -177,9 +176,7 @@ public class Execute { | |||
@Deprecated | |||
public static synchronized Vector<String> getProcEnvironment() { | |||
Vector<String> v = new Vector<>(); | |||
for (Entry<String, String> entry : getEnvironmentVariables().entrySet()) { | |||
v.add(entry.getKey() + "=" + entry.getValue()); | |||
} | |||
getEnvironmentVariables().forEach((key, value) -> v.add(key + "=" + value)); | |||
return v; | |||
} | |||
@@ -24,8 +24,8 @@ import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.OutputStream; | |||
import java.nio.file.Files; | |||
import java.util.Collections; | |||
import java.util.Date; | |||
import java.util.Enumeration; | |||
import java.util.HashSet; | |||
import java.util.List; | |||
import java.util.Set; | |||
@@ -189,7 +189,9 @@ public class Expand extends Task { | |||
} | |||
try (ZipFile zf = new ZipFile(srcF, encoding, scanForUnicodeExtraFields)) { | |||
boolean empty = true; | |||
for (ZipEntry ze : Collections.list(zf.getEntries())) { | |||
Enumeration<ZipEntry> entries = zf.getEntries(); | |||
while (entries.hasMoreElements()) { | |||
ZipEntry ze = entries.nextElement(); | |||
empty = false; | |||
InputStream is = null; | |||
log("extracting " + ze.getName(), Project.MSG_DEBUG); | |||
@@ -55,6 +55,7 @@ import org.apache.tools.ant.types.ResourceCollection; | |||
import org.apache.tools.ant.types.ZipFileSet; | |||
import org.apache.tools.ant.types.spi.Service; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
import org.apache.tools.zip.JarMarker; | |||
import org.apache.tools.zip.ZipExtraField; | |||
import org.apache.tools.zip.ZipOutputStream; | |||
@@ -321,18 +322,17 @@ public class Jar extends Zip { | |||
*/ | |||
private Manifest getManifestFromJar(File jarFile) throws IOException { | |||
try (ZipFile zf = new ZipFile(jarFile)) { | |||
// must not use getEntry as "well behaving" applications | |||
// must accept the manifest in any capitalization | |||
for (ZipEntry ze : Collections.list(zf.entries())) { | |||
if (MANIFEST_NAME.equalsIgnoreCase(ze.getName())) { | |||
try (InputStreamReader isr = | |||
new InputStreamReader(zf.getInputStream(ze), "UTF-8")) { | |||
return getManifest(isr); | |||
} | |||
} | |||
ZipEntry ze = StreamUtils.enumerationAsStream(zf.entries()) | |||
.filter(entry -> MANIFEST_NAME.equalsIgnoreCase(entry.getName())) | |||
.findFirst().orElse(null); | |||
if (ze == null) { | |||
return null; | |||
} | |||
try (InputStreamReader isr = new InputStreamReader(zf.getInputStream(ze), "UTF-8")) { | |||
return getManifest(isr); | |||
} | |||
return null; | |||
} | |||
} | |||
@@ -351,7 +351,7 @@ public class Jar extends Zip { | |||
private boolean jarHasIndex(File jarFile) throws IOException { | |||
try (ZipFile zf = new ZipFile(jarFile)) { | |||
return Collections.list(zf.entries()).stream() | |||
return StreamUtils.enumerationAsStream(zf.entries()) | |||
.anyMatch(ze -> INDEX_NAME.equalsIgnoreCase(ze.getName())); | |||
} | |||
} | |||
@@ -524,9 +524,8 @@ public class Jar extends Zip { | |||
private void writeManifest(ZipOutputStream zOut, Manifest manifest) | |||
throws IOException { | |||
for (String warning : Collections.list(manifest.getWarnings())) { | |||
log("Manifest warning: " + warning, Project.MSG_WARN); | |||
} | |||
StreamUtils.enumerationAsStream(manifest.getWarnings()) | |||
.forEach(warning -> log("Manifest warning: " + warning, Project.MSG_WARN)); | |||
zipDir((Resource) null, zOut, "META-INF/", ZipFileSet.DEFAULT_DIR_MODE, | |||
JAR_MARKER); | |||
@@ -1064,7 +1063,7 @@ public class Jar extends Zip { | |||
throws IOException { | |||
try (org.apache.tools.zip.ZipFile zf = new org.apache.tools.zip.ZipFile(file, "utf-8")) { | |||
Set<String> dirSet = new HashSet<>(); | |||
for (org.apache.tools.zip.ZipEntry ze : Collections.list(zf.getEntries())) { | |||
StreamUtils.enumerationAsStream(zf.getEntries()).forEach(ze -> { | |||
String name = ze.getName(); | |||
if (ze.isDirectory()) { | |||
dirSet.add(name); | |||
@@ -1077,7 +1076,7 @@ public class Jar extends Zip { | |||
// well. | |||
dirSet.add(name.substring(0, name.lastIndexOf('/') + 1)); | |||
} | |||
} | |||
}); | |||
dirs.addAll(dirSet); | |||
} | |||
} | |||
@@ -26,7 +26,6 @@ import java.io.PrintWriter; | |||
import java.io.Reader; | |||
import java.io.StringWriter; | |||
import java.io.UnsupportedEncodingException; | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.Enumeration; | |||
import java.util.LinkedHashMap; | |||
@@ -39,6 +38,7 @@ import java.util.stream.Collectors; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
/** | |||
* Holds the data of a jar manifest. | |||
@@ -676,7 +676,7 @@ public class Manifest { | |||
public Object clone() { | |||
Section cloned = new Section(); | |||
cloned.setName(name); | |||
Collections.list(getAttributeKeys()).stream() | |||
StreamUtils.enumerationAsStream(getAttributeKeys()) | |||
.map(key -> new Attribute(getAttribute(key).getName(), | |||
getAttribute(key).getValue())).forEach(cloned::storeAttribute); | |||
return cloned; | |||
@@ -932,8 +932,7 @@ public class Manifest { | |||
for (String sectionName : Collections.list(other.getSectionNames())) { | |||
Section ourSection = sections.get(sectionName); | |||
Section otherSection | |||
= other.sections.get(sectionName); | |||
Section otherSection = other.sections.get(sectionName); | |||
if (ourSection == null) { | |||
if (otherSection != null) { | |||
addConfiguredSection((Section) otherSection.clone()); | |||
@@ -1020,7 +1019,7 @@ public class Manifest { | |||
*/ | |||
public Enumeration<String> getWarnings() { | |||
// create a vector and add in the warnings for the main section | |||
List<String> warnings = new ArrayList<>(Collections.list(mainSection.getWarnings())); | |||
List<String> warnings = Collections.list(mainSection.getWarnings()); | |||
// add in the warnings for all the sections | |||
sections.values().stream().map(section -> Collections.list(section.getWarnings())) | |||
@@ -25,12 +25,12 @@ import java.io.OutputStreamWriter; | |||
import java.io.PrintWriter; | |||
import java.nio.charset.Charset; | |||
import java.nio.file.Files; | |||
import java.util.Collections; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.Task; | |||
import org.apache.tools.ant.types.EnumeratedAttribute; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
/** | |||
* Creates a manifest file for inclusion in a JAR, Ant task wrapper | |||
@@ -112,7 +112,7 @@ public class ManifestTask extends Task { | |||
*/ | |||
public void addConfiguredSection(Manifest.Section section) | |||
throws ManifestException { | |||
Collections.list(section.getAttributeKeys()).stream() | |||
StreamUtils.enumerationAsStream(section.getAttributeKeys()) | |||
.map(section::getAttribute).forEach(this::checkAttribute); | |||
nestedManifest.addConfiguredSection(section); | |||
} | |||
@@ -241,7 +241,7 @@ public class ManifestTask extends Task { | |||
} | |||
// look for and print warnings | |||
Collections.list(nestedManifest.getWarnings()) | |||
StreamUtils.enumerationAsStream(nestedManifest.getWarnings()) | |||
.forEach(e -> log("Manifest warning: " + e, Project.MSG_WARN)); | |||
try { | |||
if ("update".equals(mode.getValue()) && manifestFile.exists()) { | |||
@@ -307,13 +307,9 @@ public class Recorder extends Task implements SubBuildListener { | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
private void cleanup() { | |||
Hashtable<String, RecorderEntry> entries | |||
= (Hashtable<String, RecorderEntry>) recorderEntries.clone(); | |||
for (Map.Entry<String, RecorderEntry> entry : entries.entrySet()) { | |||
if (entry.getValue().getProject() == getProject()) { | |||
recorderEntries.remove(entry.getKey()); | |||
} | |||
} | |||
((Hashtable<String, RecorderEntry>) recorderEntries.clone()).entrySet().stream() | |||
.filter(entry -> entry.getValue().getProject() == getProject()) | |||
.forEach(entry -> recorderEntries.remove(entry.getKey())); | |||
getProject().removeBuildListener(this); | |||
} | |||
} |
@@ -45,6 +45,7 @@ import org.apache.tools.ant.types.resources.FileProvider; | |||
import org.apache.tools.ant.types.resources.FileResource; | |||
import org.apache.tools.ant.types.resources.Union; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
/** | |||
* Replaces all occurrences of one or more string tokens with given | |||
@@ -511,14 +512,12 @@ public class Replace extends MatchingTask { | |||
try { | |||
if (replaceFilterResource != null) { | |||
Properties props = getProperties(replaceFilterResource); | |||
Iterator<Object> e = getOrderedIterator(props); | |||
while (e.hasNext()) { | |||
String tok = e.next().toString(); | |||
final Properties properties = getProperties(replaceFilterResource); | |||
StreamUtils.iteratorAsStream(getOrderedIterator(properties)).forEach(tok -> { | |||
Replacefilter replaceFilter = createReplacefilter(); | |||
replaceFilter.setToken(tok); | |||
replaceFilter.setValue(props.getProperty(tok)); | |||
} | |||
replaceFilter.setValue(properties.getProperty(tok)); | |||
}); | |||
} | |||
validateAttributes(); | |||
@@ -936,10 +935,9 @@ public class Replace extends MatchingTask { | |||
* | |||
* @param props Properties | |||
*/ | |||
private Iterator<Object> getOrderedIterator(Properties props) { | |||
List<Object> keys = new ArrayList<>(props.keySet()); | |||
keys.sort(Comparator.comparingInt(o -> Objects.toString(o, "").length()) | |||
.reversed()); | |||
private Iterator<String> getOrderedIterator(Properties props) { | |||
List<String> keys = new ArrayList<>(props.stringPropertyNames()); | |||
keys.sort(Comparator.<String>comparingInt(s -> s.length()).reversed()); | |||
return keys.iterator(); | |||
} | |||
} |
@@ -18,9 +18,8 @@ | |||
package org.apache.tools.ant.taskdefs.condition; | |||
import java.util.Collections; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
/** | |||
* <and> condition container. | |||
@@ -38,7 +37,7 @@ public class And extends ConditionBase implements Condition { | |||
*/ | |||
@Override | |||
public boolean eval() throws BuildException { | |||
return Collections.list(getConditions()).stream().allMatch(Condition::eval); | |||
return StreamUtils.enumerationAsStream(getConditions()).allMatch(Condition::eval); | |||
} | |||
} |
@@ -19,12 +19,12 @@ package org.apache.tools.ant.taskdefs.condition; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.util.Collections; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.taskdefs.ManifestTask; | |||
import org.apache.tools.ant.types.DataType; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
import org.apache.tools.zip.ZipFile; | |||
/** | |||
@@ -72,7 +72,7 @@ public class IsSigned extends DataType implements Condition { | |||
throws IOException { | |||
try (ZipFile jarFile = new ZipFile(zipFile)) { | |||
if (null == name) { | |||
return Collections.list(jarFile.getEntries()).stream() | |||
return StreamUtils.enumerationAsStream(jarFile.getEntries()) | |||
.anyMatch(e -> e.getName().startsWith(SIG_START) && e.getName().endsWith(SIG_END)); | |||
} | |||
name = replaceInvalidChars(name); | |||
@@ -21,6 +21,7 @@ package org.apache.tools.ant.taskdefs.condition; | |||
import java.util.Collections; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
/** | |||
* <or> condition container. | |||
@@ -38,7 +39,7 @@ public class Or extends ConditionBase implements Condition { | |||
*/ | |||
@Override | |||
public boolean eval() throws BuildException { | |||
return Collections.list(getConditions()).stream().anyMatch(Condition::eval); | |||
return StreamUtils.enumerationAsStream(getConditions()).anyMatch(Condition::eval); | |||
} | |||
} |
@@ -20,6 +20,7 @@ package org.apache.tools.ant.taskdefs.condition; | |||
import java.util.Collections; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
/** | |||
* The <tt>Xor</tt> condition type to exclusive or operations. | |||
@@ -36,13 +37,9 @@ public class Xor extends ConditionBase implements Condition { | |||
*/ | |||
@Override | |||
public boolean eval() throws BuildException { | |||
// initial state is false. | |||
boolean state = false; | |||
for (Condition c : Collections.list(getConditions())) { | |||
// every condition is xored against the previous one | |||
state ^= c.eval(); | |||
} | |||
return state; | |||
// initial state is false | |||
return StreamUtils.enumerationAsStream(getConditions()).map(Condition::eval) | |||
.reduce((a, b) -> a ^ b).orElse(Boolean.FALSE); | |||
} | |||
} |
@@ -28,7 +28,6 @@ import java.lang.reflect.Field; | |||
import java.net.URL; | |||
import java.nio.file.Files; | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.HashMap; | |||
import java.util.Hashtable; | |||
import java.util.List; | |||
@@ -64,6 +63,7 @@ import org.apache.tools.ant.types.resources.URLProvider; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.JAXPUtils; | |||
import org.apache.tools.ant.util.JavaEnvUtils; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
import org.xml.sax.EntityResolver; | |||
import org.xml.sax.InputSource; | |||
import org.xml.sax.SAXException; | |||
@@ -619,7 +619,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware | |||
if (factory != null) { | |||
setFactory(factory.getName()); | |||
// configure factory attributes | |||
Collections.list(factory.getAttributes()) | |||
StreamUtils.enumerationAsStream(factory.getAttributes()) | |||
.forEach(attr -> setAttribute(attr.getName(), attr.getValue())); | |||
factory.getFeatures() | |||
.forEach(feature -> setFeature(feature.getName(), feature.getValue())); | |||
@@ -633,7 +633,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware | |||
} | |||
// configure output properties | |||
Collections.list(xsltTask.getOutputProperties()) | |||
StreamUtils.enumerationAsStream(xsltTask.getOutputProperties()) | |||
.forEach(prop -> setOutputProperty(prop.getName(), prop.getValue())); | |||
suppressWarnings = xsltTask.getSuppressWarnings(); | |||
@@ -322,7 +322,7 @@ public class Depend extends MatchingTask { | |||
analyzer.addRootClass(info.className); | |||
analyzer.addClassPath(destPath); | |||
analyzer.setClosure(false); | |||
dependencyList = new ArrayList<>(Collections.list(analyzer.getClassDependencies())); | |||
dependencyList = Collections.list(analyzer.getClassDependencies()); | |||
dependencyList.forEach(o -> log("Class " + info.className + " depends on " + o, | |||
Project.MSG_DEBUG)); | |||
cacheDirty = true; | |||
@@ -21,7 +21,6 @@ import java.io.File; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.nio.file.Files; | |||
import java.util.Collections; | |||
import java.util.Hashtable; | |||
import java.util.jar.JarEntry; | |||
import java.util.jar.JarFile; | |||
@@ -36,6 +35,7 @@ import org.apache.tools.ant.taskdefs.Java; | |||
import org.apache.tools.ant.types.Environment; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
/** | |||
* WebSphere deployment tool that augments the ejbjar task. | |||
@@ -667,13 +667,16 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { | |||
wasJar = new JarFile(websphereJarFile); | |||
//get the list of generic jar entries | |||
Hashtable<String, JarEntry> genericEntries = Collections.list(genericJar.entries()).stream() | |||
Hashtable<String, JarEntry> genericEntries | |||
= StreamUtils.enumerationAsStream(genericJar.entries()) | |||
.collect(Collectors.toMap(je -> je.getName().replace('\\', '/'), | |||
je -> je, (a, b) -> b, Hashtable::new)); | |||
// get the list of WebSphere jar entries | |||
Hashtable<String, JarEntry> wasEntries = Collections.list(wasJar.entries()).stream() | |||
.collect(Collectors.toMap(ZipEntry::getName, je -> je, (a, b) -> b, Hashtable::new)); | |||
Hashtable<String, JarEntry> wasEntries | |||
= StreamUtils.enumerationAsStream(wasJar.entries()) | |||
.collect(Collectors.toMap(ZipEntry::getName, | |||
je -> je, (a, b) -> b, Hashtable::new)); | |||
// Cycle through generic and make sure its in WebSphere | |||
genericLoader = getClassLoaderFromJar(genericJarFile); | |||
@@ -28,7 +28,7 @@ import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.nio.file.Files; | |||
import java.nio.file.Paths; | |||
import java.util.Collections; | |||
import java.util.Enumeration; | |||
import java.util.List; | |||
import java.util.Vector; | |||
import java.util.zip.CRC32; | |||
@@ -207,7 +207,9 @@ public class jlink { | |||
return; | |||
} | |||
try (ZipFile zipf = new ZipFile(f)) { | |||
for (ZipEntry inputEntry : Collections.list(zipf.entries())) { | |||
Enumeration<? extends ZipEntry> entries = zipf.entries(); | |||
while (entries.hasMoreElements()) { | |||
ZipEntry inputEntry = entries.nextElement(); | |||
//Ignore manifest entries. They're bound to cause conflicts between | |||
//files that are being merged. User should supply their own | |||
//manifest file when doing the merge. | |||
@@ -54,8 +54,8 @@ public final class Enumerations { | |||
* @param <T> object type | |||
* @param enums the array of enumerations. | |||
* @return the enumeration over the array of enumerations. | |||
* @deprecated Stream.concat(Collections.list ( one).stream(), Collections.list(two).stream()) | |||
* .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::enumeration)) | |||
* @deprecated use Stream.concat(Collections.list(one).stream(), Collections.list(two).stream()) | |||
* .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::enumeration)) | |||
*/ | |||
@Deprecated | |||
@SafeVarargs | |||
@@ -24,7 +24,6 @@ import java.util.HashSet; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Map.Entry; | |||
import java.util.Optional; | |||
import java.util.Properties; | |||
import java.util.Set; | |||
@@ -494,17 +493,8 @@ public class PropertySet extends DataType implements ResourceCollection { | |||
return getRef().toString(); | |||
} | |||
dieOnCircularReference(); | |||
StringBuilder b = new StringBuilder(); | |||
TreeMap<String, Object> sorted = new TreeMap<>(getPropertyMap()); | |||
for (Entry<String, Object> e : sorted.entrySet()) { | |||
if (b.length() > 0) { | |||
b.append(", "); | |||
} | |||
b.append(e.getKey()); | |||
b.append("="); | |||
b.append(e.getValue()); | |||
} | |||
return b.toString(); | |||
return new TreeMap<>(getPropertyMap()).entrySet().stream() | |||
.map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(", ")); | |||
} | |||
/** | |||
@@ -20,14 +20,13 @@ package org.apache.tools.ant.types; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.util.Collections; | |||
import java.util.Map; | |||
import java.util.zip.ZipException; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.types.resources.FileProvider; | |||
import org.apache.tools.ant.types.resources.ZipResource; | |||
import org.apache.tools.zip.ZipEntry; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
import org.apache.tools.zip.ZipFile; | |||
/** | |||
@@ -62,7 +61,7 @@ public class ZipScanner extends ArchiveScanner { | |||
"Only file provider resources are supported")); | |||
try (ZipFile zf = new ZipFile(srcFile, encoding)) { | |||
for (ZipEntry entry : Collections.list(zf.getEntries())) { | |||
StreamUtils.enumerationAsStream(zf.getEntries()).forEach(entry -> { | |||
Resource r = new ZipResource(srcFile, encoding, entry); | |||
String name = entry.getName(); | |||
if (entry.isDirectory()) { | |||
@@ -77,7 +76,7 @@ public class ZipScanner extends ArchiveScanner { | |||
matchFileEntries.put(name, r); | |||
} | |||
} | |||
} | |||
}); | |||
} catch (ZipException ex) { | |||
throw new BuildException("Problem reading " + srcFile, ex); | |||
} catch (IOException ex) { | |||
@@ -18,7 +18,6 @@ | |||
package org.apache.tools.ant.types.optional.depend; | |||
import java.io.File; | |||
import java.util.Collections; | |||
import java.util.Set; | |||
import java.util.Vector; | |||
import java.util.stream.Collectors; | |||
@@ -27,9 +26,9 @@ import java.util.stream.Stream; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.DirectoryScanner; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
import org.apache.tools.ant.util.depend.DependencyAnalyzer; | |||
/** | |||
* DirectoryScanner for finding class dependencies. | |||
*/ | |||
@@ -126,14 +125,11 @@ public class DependScanner extends DirectoryScanner { | |||
Set<String> parentSet = Stream.of(parentScanner.getIncludedFiles()) | |||
.collect(Collectors.toSet()); | |||
for (String classname : Collections.list(analyzer.getClassDependencies())) { | |||
String filename = classname.replace('.', File.separatorChar) + ".class"; | |||
File depFile = new File(basedir, filename); | |||
if (depFile.exists() && parentSet.contains(filename)) { | |||
// This is included | |||
included.addElement(filename); | |||
} | |||
} | |||
// This is included | |||
StreamUtils.enumerationAsStream(analyzer.getClassDependencies()) | |||
.map(cName -> cName.replace('.', File.separatorChar) + ".class") | |||
.filter(fName -> new File(basedir, fName).exists() && parentSet.contains(fName)) | |||
.forEach(fName -> included.addElement(fName)); | |||
} | |||
/** | |||
@@ -83,7 +83,7 @@ public class CollectionUtils { | |||
// don't need the opposite check as the Dictionaries have the | |||
// same size, so we've also covered all keys of d2 already. | |||
return Collections.list(d1.keys()).stream() | |||
return StreamUtils.enumerationAsStream(d1.keys()) | |||
.allMatch(key -> d1.get(key).equals(d2.get(key))); | |||
} | |||
@@ -113,7 +113,7 @@ public class CollectionUtils { | |||
@Deprecated | |||
public static <K, V> void putAll(Dictionary<? super K, ? super V> m1, | |||
Dictionary<? extends K, ? extends V> m2) { | |||
Collections.list(m2.keys()).forEach(key -> m1.put(key, m2.get(key))); | |||
StreamUtils.enumerationAsStream(m2.keys()).forEach(key -> m1.put(key, m2.get(key))); | |||
} | |||
/** | |||
@@ -210,7 +210,7 @@ public class CollectionUtils { | |||
* @param <T> element type | |||
* @return the collection | |||
* @since Ant 1.8.0 | |||
* @deprecated instantiate a list an use forEachRemaining(list::add) | |||
* @deprecated instantiate a list and use forEachRemaining(list::add) | |||
*/ | |||
@Deprecated | |||
public static <T> Collection<T> asCollection(final Iterator<? extends T> iter) { | |||
@@ -0,0 +1,33 @@ | |||
package org.apache.tools.ant.util; | |||
import java.util.Enumeration; | |||
import java.util.Spliterator; | |||
import java.util.Spliterators; | |||
import java.util.function.Consumer; | |||
import java.util.stream.Stream; | |||
import java.util.stream.StreamSupport; | |||
public class StreamUtils { | |||
/** | |||
* Turn Enumeration into a Stream | |||
* | |||
* @param <T> Enumeration type | |||
* @param e Enumeration | |||
* @return Stream | |||
*/ | |||
public static <T> Stream<T> enumerationAsStream(Enumeration<T> e) { | |||
return StreamSupport.stream( | |||
new Spliterators.AbstractSpliterator<T>(Long.MAX_VALUE, Spliterator.ORDERED) { | |||
public boolean tryAdvance(Consumer<? super T> action) { | |||
if (e.hasMoreElements()) { | |||
action.accept(e.nextElement()); | |||
return true; | |||
} | |||
return false; | |||
} | |||
public void forEachRemaining(Consumer<? super T> action) { | |||
while(e.hasMoreElements()) action.accept(e.nextElement()); | |||
} | |||
}, false); | |||
} | |||
} |
@@ -16,6 +16,7 @@ | |||
* | |||
*/ | |||
package org.apache.tools.ant.util.depend.bcel; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.util.Collections; | |||
@@ -27,6 +28,7 @@ import org.apache.bcel.classfile.ClassParser; | |||
import org.apache.bcel.classfile.DescendingVisitor; | |||
import org.apache.bcel.classfile.JavaClass; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
import org.apache.tools.ant.util.depend.AbstractAnalyzer; | |||
/** | |||
@@ -102,7 +104,7 @@ public class FullAnalyzer extends AbstractAnalyzer { | |||
toAnalyze.clear(); | |||
// now recover all the dependencies collected and add to the list. | |||
Collections.list(dependencyVisitor.getDependencies()).stream() | |||
StreamUtils.enumerationAsStream(dependencyVisitor.getDependencies()) | |||
.filter(className -> !dependencies.contains(className)) | |||
.forEach(toAnalyze::add); | |||
} | |||
@@ -30,7 +30,6 @@ import java.io.InputStream; | |||
import java.io.OutputStream; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.Map.Entry; | |||
import org.apache.tools.zip.ZipEncoding; | |||
import org.apache.tools.zip.ZipEncodingHelper; | |||
@@ -480,31 +479,40 @@ public class TarInputStream extends FilterInputStream { | |||
* uid,uname | |||
* SCHILY.devminor, SCHILY.devmajor: don't have setters/getters for those | |||
*/ | |||
for (Entry<String, String> ent : headers.entrySet()) { | |||
String key = ent.getKey(); | |||
String val = ent.getValue(); | |||
if ("path".equals(key)) { | |||
currEntry.setName(val); | |||
} else if ("linkpath".equals(key)) { | |||
currEntry.setLinkName(val); | |||
} else if ("gid".equals(key)) { | |||
currEntry.setGroupId(Long.parseLong(val)); | |||
} else if ("gname".equals(key)) { | |||
currEntry.setGroupName(val); | |||
} else if ("uid".equals(key)) { | |||
currEntry.setUserId(Long.parseLong(val)); | |||
} else if ("uname".equals(key)) { | |||
currEntry.setUserName(val); | |||
} else if ("size".equals(key)) { | |||
currEntry.setSize(Long.parseLong(val)); | |||
} else if ("mtime".equals(key)) { | |||
currEntry.setModTime((long) (Double.parseDouble(val) * 1000)); | |||
} else if ("SCHILY.devminor".equals(key)) { | |||
currEntry.setDevMinor(Integer.parseInt(val)); | |||
} else if ("SCHILY.devmajor".equals(key)) { | |||
currEntry.setDevMajor(Integer.parseInt(val)); | |||
headers.forEach((key, val) -> { | |||
switch (key) { | |||
case "path": | |||
currEntry.setName(val); | |||
break; | |||
case "linkpath": | |||
currEntry.setLinkName(val); | |||
break; | |||
case "gid": | |||
currEntry.setGroupId(Long.parseLong(val)); | |||
break; | |||
case "gname": | |||
currEntry.setGroupName(val); | |||
break; | |||
case "uid": | |||
currEntry.setUserId(Long.parseLong(val)); | |||
break; | |||
case "uname": | |||
currEntry.setUserName(val); | |||
break; | |||
case "size": | |||
currEntry.setSize(Long.parseLong(val)); | |||
break; | |||
case "mtime": | |||
currEntry.setModTime((long) (Double.parseDouble(val) * 1000)); | |||
break; | |||
case "SCHILY.devminor": | |||
currEntry.setDevMinor(Integer.parseInt(val)); | |||
break; | |||
case "SCHILY.devmajor": | |||
currEntry.setDevMajor(Integer.parseInt(val)); | |||
break; | |||
} | |||
} | |||
}); | |||
} | |||
/** | |||
@@ -24,7 +24,7 @@ import java.net.URL; | |||
import java.util.Arrays; | |||
import java.util.Collections; | |||
import java.util.Enumeration; | |||
import java.util.List; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.Before; | |||
@@ -52,8 +52,7 @@ public class AntClassLoaderDelegationTest { | |||
} | |||
/** Sample resource present in build/testcases/ */ | |||
private static final String TEST_RESOURCE | |||
= "apache/tools/ant/IncludeTest.class"; | |||
private static final String TEST_RESOURCE = "apache/tools/ant/IncludeTest.class"; | |||
@SuppressWarnings("resource") | |||
@Test | |||
@@ -75,11 +74,11 @@ public class AntClassLoaderDelegationTest { | |||
URL urlFromParent = new URL("http://ant.apache.org/" + TEST_RESOURCE); | |||
assertEquals("correct resources (regular delegation order)", | |||
Arrays.asList(urlFromParent, urlFromPath), | |||
enum2List(acl.getResources(TEST_RESOURCE))); | |||
Collections.list(acl.getResources(TEST_RESOURCE))); | |||
acl = new AntClassLoader(parent, p, path, false); | |||
assertEquals("correct resources (reverse delegation order)", | |||
Arrays.asList(urlFromPath, urlFromParent), | |||
enum2List(acl.getResources(TEST_RESOURCE))); | |||
Collections.list(acl.getResources(TEST_RESOURCE))); | |||
} | |||
@SuppressWarnings("resource") | |||
@@ -99,11 +98,7 @@ public class AntClassLoaderDelegationTest { | |||
acl.setIsolated(true); | |||
assertEquals("correct resources (reverse delegation order)", | |||
Collections.singletonList(urlFromPath), | |||
enum2List(acl.getResources(TEST_RESOURCE))); | |||
} | |||
private static List<URL> enum2List(Enumeration<URL> e) { | |||
return Collections.list(e); | |||
Collections.list(acl.getResources(TEST_RESOURCE))); | |||
} | |||
/** Special loader that just knows how to find TEST_RESOURCE. */ | |||
@@ -24,7 +24,6 @@ import java.io.FileReader; | |||
import java.io.InputStream; | |||
import java.io.InputStreamReader; | |||
import java.io.IOException; | |||
import java.util.Collections; | |||
import java.util.zip.ZipEntry; | |||
import java.util.zip.ZipFile; | |||
@@ -32,6 +31,7 @@ import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.StreamUtils; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
@@ -239,7 +239,7 @@ public class JarTest { | |||
public void testNoDuplicateIndex() throws IOException { | |||
buildRule.executeTarget("testIndexTests"); | |||
try (ZipFile archive = new ZipFile(new File(getOutputDir(), tempJar))) { | |||
assertEquals(1, (int) Collections.list(archive.entries()).stream() | |||
assertEquals(1, StreamUtils.enumerationAsStream(archive.entries()) | |||
.filter(ze -> ze.getName().equals("META-INF/INDEX.LIST")).count()); | |||
} | |||
} | |||