Skip to content

Commit

Permalink
java 5-8
Browse files Browse the repository at this point in the history
  • Loading branch information
mbenson committed Apr 13, 2017
1 parent af74d1f commit b7d1e9b
Show file tree
Hide file tree
Showing 609 changed files with 11,648 additions and 13,756 deletions.
15 changes: 8 additions & 7 deletions src/main/org/apache/tools/ant/AntClassLoader.java
Expand Up @@ -178,7 +178,7 @@ private void findNextResource() {
* The components of the classpath that the classloader searches
* for classes.
*/
private final Vector<File> pathComponents = new VectorSet<File>();
private final Vector<File> pathComponents = new VectorSet<>();

/**
* The project to which this class loader belongs.
Expand All @@ -196,14 +196,14 @@ private void findNextResource() {
* loader regardless of whether the parent class loader is being searched
* first or not.
*/
private final Vector<String> systemPackages = new Vector<String>();
private final Vector<String> systemPackages = new Vector<>();

/**
* These are the package roots that are to be loaded by this class loader
* regardless of whether the parent class loader is being searched first
* or not.
*/
private final Vector<String> loaderPackages = new Vector<String>();
private final Vector<String> loaderPackages = new Vector<>();

/**
* Whether or not this classloader will ignore the base
Expand All @@ -221,7 +221,7 @@ private void findNextResource() {
/**
* A hashtable of zip files opened by the classloader (File to JarFile).
*/
private Hashtable<File, JarFile> jarFiles = new Hashtable<File, JarFile>();
private Hashtable<File, JarFile> jarFiles = new Hashtable<>();

/** Static map of jar file/time to manifest class-path entries */
private static Map<String, String> pathMap =
Expand Down Expand Up @@ -293,8 +293,8 @@ public AntClassLoader(final Project project, final Path classpath) {
* classloader should be consulted before trying to
* load the a class through this loader.
*/
public AntClassLoader(
final ClassLoader parent, final Project project, final Path classpath, final boolean parentFirst) {
public AntClassLoader(final ClassLoader parent, final Project project,
final Path classpath, final boolean parentFirst) {
this(project, classpath);
if (parent != null) {
setParent(parent);
Expand All @@ -315,7 +315,8 @@ public AntClassLoader(
* classloader should be consulted before trying to
* load the a class through this loader.
*/
public AntClassLoader(final Project project, final Path classpath, final boolean parentFirst) {
public AntClassLoader(final Project project, final Path classpath,
final boolean parentFirst) {
this(null, project, classpath, parentFirst);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/org/apache/tools/ant/ArgumentProcessorRegistry.java
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
Expand Down Expand Up @@ -151,7 +152,7 @@ private ArgumentProcessor getProcessorByService(InputStream is)
try {
try {
isr = new InputStreamReader(is, "UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
} catch (UnsupportedEncodingException e) {
isr = new InputStreamReader(is);
}
BufferedReader rd = new BufferedReader(isr);
Expand Down
15 changes: 14 additions & 1 deletion src/main/org/apache/tools/ant/BuildException.java
Expand Up @@ -38,12 +38,25 @@ public BuildException() {
* Constructs an exception with the given descriptive message.
*
* @param message A description of or information about the exception.
* Should not be <code>null</code>.
* Should not be {@code null}.
*/
public BuildException(String message) {
super(message);
}

/**
* Constructs an exception with the given format pattern and arguments.
*
* @param pattern A description of or information about the exception.
* Should not be {@code null}.
* @param formatArguments
* @see String#format(String, Object...)
* @since Ant 1.11
*/
public BuildException(String pattern, Object... formatArguments) {
super(String.format(pattern, formatArguments));
}

/**
* Constructs an exception with the given message and exception as
* a root cause.
Expand Down
41 changes: 19 additions & 22 deletions src/main/org/apache/tools/ant/ComponentHelper.java
Expand Up @@ -59,31 +59,31 @@
*/
public class ComponentHelper {
/** Map of component name to lists of restricted definitions */
private Map<String, List<AntTypeDefinition>> restrictedDefinitions = new HashMap<String, List<AntTypeDefinition>>();
private Map<String, List<AntTypeDefinition>> restrictedDefinitions = new HashMap<>();

/** Map from component name to anttypedefinition */
private final Hashtable<String, AntTypeDefinition> antTypeTable = new Hashtable<String, AntTypeDefinition>();
private final Hashtable<String, AntTypeDefinition> antTypeTable = new Hashtable<>();

/** Map of tasks generated from antTypeTable */
private final Hashtable<String, Class<?>> taskClassDefinitions = new Hashtable<String, Class<?>>();
private final Hashtable<String, Class<?>> taskClassDefinitions = new Hashtable<>();

/** flag to rebuild taskClassDefinitions */
private boolean rebuildTaskClassDefinitions = true;

/** Map of types generated from antTypeTable */
private final Hashtable<String, Class<?>> typeClassDefinitions = new Hashtable<String, Class<?>>();
private final Hashtable<String, Class<?>> typeClassDefinitions = new Hashtable<>();

/** flag to rebuild typeClassDefinitions */
private boolean rebuildTypeClassDefinitions = true;

/** Set of namespaces that have been checked for antlibs */
private final HashSet<String> checkedNamespaces = new HashSet<String>();
private final HashSet<String> checkedNamespaces = new HashSet<>();

/**
* Stack of antlib contexts used to resolve definitions while
* processing antlib
*/
private Stack<String> antLibStack = new Stack<String>();
private Stack<String> antLibStack = new Stack<>();

/** current antlib uri */
private String antLibCurrentUri = null;
Expand Down Expand Up @@ -189,7 +189,6 @@ public ComponentHelper getNext() {
*/
public void setProject(Project project) {
this.project = project;
// antTypeTable = new Hashtable<String, AntTypeDefinition>(project);
}

/**
Expand All @@ -205,13 +204,13 @@ private synchronized Set<String> getCheckedNamespace() {
* @return A deep copy of the restrictredDefinition
*/
private Map<String, List<AntTypeDefinition>> getRestrictedDefinition() {
final Map<String, List<AntTypeDefinition>> result = new HashMap<String, List<AntTypeDefinition>>();
final Map<String, List<AntTypeDefinition>> result = new HashMap<>();
synchronized (restrictedDefinitions) {
for (Map.Entry<String, List<AntTypeDefinition>> entry : restrictedDefinitions.entrySet()) {
List<AntTypeDefinition> entryVal = entry.getValue();
synchronized (entryVal) {
//copy the entryVal
entryVal = new ArrayList<AntTypeDefinition> (entryVal);
entryVal = new ArrayList<>(entryVal);
}
result.put(entry.getKey(), entryVal);
}
Expand Down Expand Up @@ -750,7 +749,7 @@ public String getCurrentAntlibUri() {
*/
public void exitAntLib() {
antLibStack.pop();
antLibCurrentUri = (antLibStack.size() == 0) ? null : (String) antLibStack.peek();
antLibCurrentUri = (antLibStack.isEmpty()) ? null : (String) antLibStack.peek();
}

/**
Expand All @@ -759,9 +758,7 @@ public void exitAntLib() {
private void initTasks() {
ClassLoader classLoader = getClassLoader(null);
Properties props = getDefaultDefinitions(false);
Enumeration<?> e = props.propertyNames();
while (e.hasMoreElements()) {
String name = (String) e.nextElement();
for (String name : props.stringPropertyNames()) {
String className = props.getProperty(name);
AntTypeDefinition def = new AntTypeDefinition();
def.setName(name);
Expand Down Expand Up @@ -902,7 +899,7 @@ public String diagnoseCreationFailure(String componentName, String type) {
probablyIDE = true;
antHomeLib = "ANT_HOME" + File.separatorChar + "lib";
}
StringBuffer dirListingText = new StringBuffer();
StringBuilder dirListingText = new StringBuilder();
final String tab = " -";
dirListingText.append(tab);
dirListingText.append(antHomeLib);
Expand Down Expand Up @@ -1026,21 +1023,21 @@ private void printUnknownDefinition(PrintWriter out, String componentName, Strin
+ " declarations have taken place.");
if (uri.length() > 0) {
final List<AntTypeDefinition> matches = findTypeMatches(uri);
if (matches.size() > 0) {
out.println();
out.println("The definitions in the namespace " + uri + " are:");
for (AntTypeDefinition def : matches) {
String local = ProjectHelper.extractNameFromComponentName(def.getName());
out.println(" " + local);
}
} else {
if (matches.isEmpty()) {
out.println("No types or tasks have been defined in this namespace yet");
if (isAntlib) {
out.println();
out.println("This appears to be an antlib declaration. ");
out.println("Action: Check that the implementing library exists in one of:");
out.println(dirListing);
}
} else {
out.println();
out.println("The definitions in the namespace " + uri + " are:");
for (AntTypeDefinition def : matches) {
String local = ProjectHelper.extractNameFromComponentName(def.getName());
out.println(" " + local);
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/org/apache/tools/ant/DefaultDefinitions.java
Expand Up @@ -66,7 +66,6 @@ private void ifUnlessDef(String name, String base) {

private void componentDef(String ns, String name, String classname) {
AntTypeDefinition def = new AntTypeDefinition();
String n = ProjectHelper.genComponentName(ns, name);
def.setName(ProjectHelper.genComponentName(ns, name));
def.setClassName(classname);
def.setClassLoader(getClass().getClassLoader());
Expand Down
56 changes: 19 additions & 37 deletions src/main/org/apache/tools/ant/DefaultLogger.java
Expand Up @@ -24,9 +24,10 @@
import java.io.StringReader;
import java.text.DateFormat;
import java.util.Date;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.tools.ant.util.DateUtils;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;

/**
Expand Down Expand Up @@ -257,48 +258,30 @@ public void messageLogged(BuildEvent event) {
// Filter out messages based on priority
if (priority <= msgOutputLevel) {

StringBuffer message = new StringBuffer();
if (event.getTask() != null && !emacsMode) {
StringBuilder message = new StringBuilder();
if (event.getTask() == null || emacsMode) {
//emacs mode or there is no task
message.append(event.getMessage());
} else {
// Print out the name of the task if we're in one
String name = event.getTask().getTaskName();
String label = "[" + name + "] ";
int size = LEFT_COLUMN_SIZE - label.length();
StringBuffer tmp = new StringBuffer();
for (int i = 0; i < size; i++) {
tmp.append(" ");
}
tmp.append(label);
label = tmp.toString();

BufferedReader r = null;
try {
r = new BufferedReader(
new StringReader(event.getMessage()));
String line = r.readLine();
boolean first = true;
do {
if (first) {
if (line == null) {
message.append(label);
break;
}
} else {
message.append(StringUtils.LINE_SEP);
}
first = false;
message.append(label).append(line);
line = r.readLine();
} while (line != null);
final String prefix = size > 0 ? Stream.generate(() -> " ")
.limit(size).collect(Collectors.joining()) + label : label;

try (BufferedReader r =
new BufferedReader(new StringReader(event.getMessage()))) {

message.append(r.lines().map(line -> prefix + line)
.collect(Collectors.joining(StringUtils.LINE_SEP)));
if (message.length() == 0) {
message.append(prefix);
}
} catch (IOException e) {
// shouldn't be possible
message.append(label).append(event.getMessage());
} finally {
FileUtils.close(r);
}

} else {
//emacs mode or there is no task
message.append(event.getMessage());
}
Throwable ex = event.getException();
if (Project.MSG_DEBUG <= msgOutputLevel && ex != null) {
Expand Down Expand Up @@ -361,8 +344,7 @@ protected void log(String message) {
protected String getTimestamp() {
Date date = new Date(System.currentTimeMillis());
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
String finishTime = formatter.format(date);
return finishTime;
return formatter.format(date);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/org/apache/tools/ant/DemuxInputStream.java
Expand Up @@ -50,6 +50,7 @@ public DemuxInputStream(Project project) {
* @return the next byte
* @throws IOException on error
*/
@Override
public int read() throws IOException {
byte[] buffer = new byte[1];
if (project.demuxInput(buffer, 0, 1) == -1) {
Expand All @@ -67,6 +68,7 @@ public int read() throws IOException {
* @return the number of bytes read
* @throws IOException on error
*/
@Override
public int read(byte[] buffer, int offset, int length) throws IOException {
return project.demuxInput(buffer, offset, length);
}
Expand Down

0 comments on commit b7d1e9b

Please sign in to comment.