You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2013/12/28 15:20:35 UTC
svn commit: r1553832 [1/2] - in /commons/proper/exec/trunk/src:
main/java/org/apache/commons/exec/
main/java/org/apache/commons/exec/environment/
main/java/org/apache/commons/exec/launcher/
main/java/org/apache/commons/exec/util/ test/java/org/apache/c...
Author: ggregory
Date: Sat Dec 28 14:20:34 2013
New Revision: 1553832
URL: http://svn.apache.org/r1553832
Log:
Add final modifier where possible.
Modified:
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/CommandLine.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecuteResultHandler.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecutor.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteException.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/InputStreamPumper.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/LogOutputStream.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/StreamPumper.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/Watchdog.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentUtils.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/DebugUtils.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/MapUtils.java
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/StringUtils.java
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/CommandLineTest.java
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/LogOutputStreamTest.java
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/StandAloneTest.java
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/TestRunner.java
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/TestUtilTest.java
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/TutorialTest.java
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/environment/EnvironmentUtilTest.java
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/util/MapUtilTest.java
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/util/StringUtilTest.java
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/CommandLine.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/CommandLine.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/CommandLine.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/CommandLine.java Sat Dec 28 14:20:34 2013
@@ -72,16 +72,16 @@ public class CommandLine {
* @return the parsed command line
* @throws IllegalArgumentException If line is null or all whitespace
*/
- public static CommandLine parse(final String line, Map substitutionMap) {
+ public static CommandLine parse(final String line, final Map substitutionMap) {
if (line == null) {
throw new IllegalArgumentException("Command line can not be null");
} else if (line.trim().length() == 0) {
throw new IllegalArgumentException("Command line can not be empty");
} else {
- String[] tmp = translateCommandline(line);
+ final String[] tmp = translateCommandline(line);
- CommandLine cl = new CommandLine(tmp[0]);
+ final CommandLine cl = new CommandLine(tmp[0]);
cl.setSubstitutionMap(substitutionMap);
for (int i = 1; i < tmp.length; i++) {
cl.addArgument(tmp[i]);
@@ -96,7 +96,7 @@ public class CommandLine {
*
* @param executable the executable
*/
- public CommandLine(String executable) {
+ public CommandLine(final String executable) {
this.isFile=false;
this.executable=getExecutable(executable);
}
@@ -106,7 +106,7 @@ public class CommandLine {
*
* @param executable the executable file
*/
- public CommandLine(File executable) {
+ public CommandLine(final File executable) {
this.isFile=true;
this.executable=getExecutable(executable.getAbsolutePath());
}
@@ -116,7 +116,7 @@ public class CommandLine {
*
* @param other the instance to copy
*/
- public CommandLine(CommandLine other)
+ public CommandLine(final CommandLine other)
{
this.executable = other.getExecutable();
this.isFile = other.isFile();
@@ -125,10 +125,10 @@ public class CommandLine {
if(other.getSubstitutionMap() != null)
{
this.substitutionMap = new HashMap();
- Iterator iterator = other.substitutionMap.keySet().iterator();
+ final Iterator iterator = other.substitutionMap.keySet().iterator();
while(iterator.hasNext())
{
- Object key = iterator.next();
+ final Object key = iterator.next();
this.substitutionMap.put(key, other.getSubstitutionMap().get(key));
}
}
@@ -172,7 +172,7 @@ public class CommandLine {
* @param handleQuoting Add the argument with/without handling quoting
* @return The command line itself
*/
- public CommandLine addArguments(final String[] arguments, boolean handleQuoting) {
+ public CommandLine addArguments(final String[] arguments, final boolean handleQuoting) {
if (arguments != null) {
for (int i = 0; i < arguments.length; i++) {
addArgument(arguments[i], handleQuoting);
@@ -203,9 +203,9 @@ public class CommandLine {
* @param handleQuoting Add the argument with/without handling quoting
* @return The command line itself
*/
- public CommandLine addArguments(final String arguments, boolean handleQuoting) {
+ public CommandLine addArguments(final String arguments, final boolean handleQuoting) {
if (arguments != null) {
- String[] argumentsArray = translateCommandline(arguments);
+ final String[] argumentsArray = translateCommandline(arguments);
addArguments(argumentsArray, handleQuoting);
}
@@ -230,7 +230,7 @@ public class CommandLine {
* @param handleQuoting Add the argument with/without handling quoting
* @return The command line itself
*/
- public CommandLine addArgument(final String argument, boolean handleQuoting) {
+ public CommandLine addArgument(final String argument, final boolean handleQuoting) {
if (argument == null)
{
@@ -257,7 +257,7 @@ public class CommandLine {
Argument currArgument;
String expandedArgument;
- String[] result = new String[arguments.size()];
+ final String[] result = new String[arguments.size()];
for(int i=0; i<result.length; i++) {
currArgument = (Argument) arguments.get(i);
@@ -281,7 +281,7 @@ public class CommandLine {
*
* @param substitutionMap the map
*/
- public void setSubstitutionMap(Map substitutionMap) {
+ public void setSubstitutionMap(final Map substitutionMap) {
this.substitutionMap = substitutionMap;
}
@@ -317,7 +317,7 @@ public class CommandLine {
* @return the expanded string
*/
private String expandArgument(final String argument) {
- StringBuffer stringBuffer = StringUtils.stringSubstitution(argument, this.getSubstitutionMap(), true);
+ final StringBuffer stringBuffer = StringUtils.stringSubstitution(argument, this.getSubstitutionMap(), true);
return stringBuffer.toString();
}
@@ -341,13 +341,13 @@ public class CommandLine {
final int inQuote = 1;
final int inDoubleQuote = 2;
int state = normal;
- StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
- Vector v = new Vector();
+ final StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
+ final Vector v = new Vector();
StringBuffer current = new StringBuffer();
boolean lastTokenHasBeenQuoted = false;
while (tok.hasMoreTokens()) {
- String nextTok = tok.nextToken();
+ final String nextTok = tok.nextToken();
switch (state) {
case inQuote:
if ("\'".equals(nextTok)) {
@@ -392,7 +392,7 @@ public class CommandLine {
+ toProcess);
}
- String[] args = new String[v.size()];
+ final String[] args = new String[v.size()];
v.copyInto(args);
return args;
}
@@ -422,7 +422,7 @@ public class CommandLine {
private final String value;
private final boolean handleQuoting;
- private Argument(String value, boolean handleQuoting)
+ private Argument(final String value, final boolean handleQuoting)
{
this.value = value.trim();
this.handleQuoting = handleQuoting;
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecuteResultHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecuteResultHandler.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecuteResultHandler.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecuteResultHandler.java Sat Dec 28 14:20:34 2013
@@ -47,7 +47,7 @@ public class DefaultExecuteResultHandler
/**
* @see org.apache.commons.exec.ExecuteResultHandler#onProcessComplete(int)
*/
- public void onProcessComplete(int exitValue) {
+ public void onProcessComplete(final int exitValue) {
this.exitValue = exitValue;
this.exception = null;
this.hasResult = true;
@@ -56,7 +56,7 @@ public class DefaultExecuteResultHandler
/**
* @see org.apache.commons.exec.ExecuteResultHandler#onProcessFailed(org.apache.commons.exec.ExecuteException)
*/
- public void onProcessFailed(ExecuteException e) {
+ public void onProcessFailed(final ExecuteException e) {
this.exitValue = e.getExitValue();
this.exception = e;
this.hasResult = true;
@@ -133,9 +133,9 @@ public class DefaultExecuteResultHandler
* thread while it is waiting, then the wait is ended and
* an {@link InterruptedException} is thrown.
*/
- public void waitFor(long timeout) throws InterruptedException {
+ public void waitFor(final long timeout) throws InterruptedException {
- long until = System.currentTimeMillis() + timeout;
+ final long until = System.currentTimeMillis() + timeout;
while (!hasResult() && (System.currentTimeMillis() < until)) {
Thread.sleep(SLEEP_TIME_MS);
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecutor.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecutor.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecutor.java Sat Dec 28 14:20:34 2013
@@ -97,7 +97,7 @@ public class DefaultExecutor implements
/**
* @see org.apache.commons.exec.Executor#setStreamHandler(org.apache.commons.exec.ExecuteStreamHandler)
*/
- public void setStreamHandler(ExecuteStreamHandler streamHandler) {
+ public void setStreamHandler(final ExecuteStreamHandler streamHandler) {
this.streamHandler = streamHandler;
}
@@ -111,7 +111,7 @@ public class DefaultExecutor implements
/**
* @see org.apache.commons.exec.Executor#setWatchdog(org.apache.commons.exec.ExecuteWatchdog)
*/
- public void setWatchdog(ExecuteWatchdog watchDog) {
+ public void setWatchdog(final ExecuteWatchdog watchDog) {
this.watchdog = watchDog;
}
@@ -125,7 +125,7 @@ public class DefaultExecutor implements
/**
* @see org.apache.commons.exec.Executor#setProcessDestroyer(ProcessDestroyer)
*/
- public void setProcessDestroyer(ProcessDestroyer processDestroyer) {
+ public void setProcessDestroyer(final ProcessDestroyer processDestroyer) {
this.processDestroyer = processDestroyer;
}
@@ -139,7 +139,7 @@ public class DefaultExecutor implements
/**
* @see org.apache.commons.exec.Executor#setWorkingDirectory(java.io.File)
*/
- public void setWorkingDirectory(File dir) {
+ public void setWorkingDirectory(final File dir) {
this.workingDirectory = dir;
}
@@ -154,7 +154,7 @@ public class DefaultExecutor implements
/**
* @see org.apache.commons.exec.Executor#execute(CommandLine, java.util.Map)
*/
- public int execute(final CommandLine command, Map environment)
+ public int execute(final CommandLine command, final Map environment)
throws ExecuteException, IOException {
if (workingDirectory != null && !workingDirectory.exists()) {
@@ -169,7 +169,7 @@ public class DefaultExecutor implements
* @see org.apache.commons.exec.Executor#execute(CommandLine,
* org.apache.commons.exec.ExecuteResultHandler)
*/
- public void execute(final CommandLine command, ExecuteResultHandler handler)
+ public void execute(final CommandLine command, final ExecuteResultHandler handler)
throws ExecuteException, IOException {
execute(command, null, handler);
}
@@ -189,7 +189,7 @@ public class DefaultExecutor implements
watchdog.setProcessNotStarted();
}
- Runnable runnable = new Runnable()
+ final Runnable runnable = new Runnable()
{
public void run()
{
@@ -197,9 +197,9 @@ public class DefaultExecutor implements
try {
exitValue = executeInternal(command, environment, workingDirectory, streamHandler);
handler.onProcessComplete(exitValue);
- } catch (ExecuteException e) {
+ } catch (final ExecuteException e) {
handler.onProcessFailed(e);
- } catch(Exception e) {
+ } catch(final Exception e) {
handler.onProcessFailed(new ExecuteException("Execution failed", exitValue, e));
}
}
@@ -247,7 +247,7 @@ public class DefaultExecutor implements
* @param name the name of the thread
* @return the thread
*/
- protected Thread createThread(Runnable runnable, String name) {
+ protected Thread createThread(final Runnable runnable, final String name) {
return new Thread(runnable, name);
}
@@ -296,21 +296,21 @@ public class DefaultExecutor implements
try {
process.getInputStream().close();
}
- catch(IOException e) {
+ catch(final IOException e) {
setExceptionCaught(e);
}
try {
process.getOutputStream().close();
}
- catch(IOException e) {
+ catch(final IOException e) {
setExceptionCaught(e);
}
try {
process.getErrorStream().close();
}
- catch(IOException e) {
+ catch(final IOException e) {
setExceptionCaught(e);
}
}
@@ -337,7 +337,7 @@ public class DefaultExecutor implements
streams.setProcessInputStream(process.getOutputStream());
streams.setProcessOutputStream(process.getInputStream());
streams.setProcessErrorStream(process.getErrorStream());
- } catch (IOException e) {
+ } catch (final IOException e) {
process.destroy();
throw e;
}
@@ -360,7 +360,7 @@ public class DefaultExecutor implements
try {
exitValue = process.waitFor();
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
process.destroy();
}
finally {
@@ -378,7 +378,7 @@ public class DefaultExecutor implements
try {
streams.stop();
}
- catch(IOException e) {
+ catch(final IOException e) {
setExceptionCaught(e);
}
@@ -391,9 +391,9 @@ public class DefaultExecutor implements
if (watchdog != null) {
try {
watchdog.checkException();
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new IOException(e.getMessage());
}
}
@@ -416,7 +416,7 @@ public class DefaultExecutor implements
*
* @param e the IOException
*/
- private void setExceptionCaught(IOException e) {
+ private void setExceptionCaught(final IOException e) {
if(this.exceptionCaught == null) {
this.exceptionCaught = e;
}
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteException.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteException.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteException.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteException.java Sat Dec 28 14:20:34 2013
@@ -47,7 +47,7 @@ public class ExecuteException extends IO
* The detail message
* @param exitValue The exit value
*/
- public ExecuteException(final String message, int exitValue) {
+ public ExecuteException(final String message, final int exitValue) {
super(message + " (Exit value: " + exitValue + ")");
this.cause = null;
this.exitValue = exitValue;
@@ -62,7 +62,7 @@ public class ExecuteException extends IO
* @param cause
* The underlying cause
*/
- public ExecuteException(final String message, int exitValue, final Throwable cause) {
+ public ExecuteException(final String message, final int exitValue, final Throwable cause) {
super(message + " (Exit value: " + exitValue + ". Caused by " + cause + ")");
this.cause = cause; // Two-argument version requires JDK 1.4 or later
this.exitValue = exitValue;
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java Sat Dec 28 14:20:34 2013
@@ -151,7 +151,7 @@ public class ExecuteWatchdog implements
if(process != null) {
process.exitValue();
}
- } catch (IllegalThreadStateException itse) {
+ } catch (final IllegalThreadStateException itse) {
// the process is not terminated, if this is really
// a timeout and not a manual stop then destroy it.
if (watch) {
@@ -159,7 +159,7 @@ public class ExecuteWatchdog implements
process.destroy();
}
}
- } catch (Exception e) {
+ } catch (final Exception e) {
caught = e;
DebugUtils.handleException("Getting the exit value of the process failed", e);
} finally {
@@ -225,7 +225,7 @@ public class ExecuteWatchdog implements
while (!processStarted){
try {
this.wait();
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
throw new RuntimeException(e.getMessage());
}
}
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/InputStreamPumper.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/InputStreamPumper.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/InputStreamPumper.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/InputStreamPumper.java Sat Dec 28 14:20:34 2013
@@ -68,8 +68,8 @@ public class InputStreamPumper implement
os.flush();
Thread.sleep(SLEEPING_TIME);
}
- } catch (Exception e) {
- String msg = "Got exception while reading/writing the stream";
+ } catch (final Exception e) {
+ final String msg = "Got exception while reading/writing the stream";
DebugUtils.handleException(msg ,e);
} finally {
}
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/LogOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/LogOutputStream.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/LogOutputStream.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/LogOutputStream.java Sat Dec 28 14:20:34 2013
@@ -135,7 +135,7 @@ public abstract class LogOutputStream
remaining--;
}
// either end of buffer or a line separator char
- int blockLength = offset - blockStartOffset;
+ final int blockLength = offset - blockStartOffset;
if (blockLength > 0) {
buffer.write(b, blockStartOffset, blockLength);
}
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java Sat Dec 28 14:20:34 2013
@@ -99,7 +99,7 @@ public class PumpStreamHandler implement
*
* @param timeout timeout in milliseconds or zero to wait forever (default)
*/
- public void setStopTimeout(long timeout) {
+ public void setStopTimeout(final long timeout) {
this.stopTimeout = timeout;
}
@@ -143,8 +143,8 @@ public class PumpStreamHandler implement
} else {
try {
os.close();
- } catch (IOException e) {
- String msg = "Got exception while closing output stream";
+ } catch (final IOException e) {
+ final String msg = "Got exception while closing output stream";
DebugUtils.handleException(msg, e);
}
}
@@ -182,8 +182,8 @@ public class PumpStreamHandler implement
if (err != null && err != out) {
try {
err.flush();
- } catch (IOException e) {
- String msg = "Got exception while flushing the error stream : " + e.getMessage();
+ } catch (final IOException e) {
+ final String msg = "Got exception while flushing the error stream : " + e.getMessage();
DebugUtils.handleException(msg, e);
}
}
@@ -191,8 +191,8 @@ public class PumpStreamHandler implement
if (out != null) {
try {
out.flush();
- } catch (IOException e) {
- String msg = "Got exception while flushing the output stream";
+ } catch (final IOException e) {
+ final String msg = "Got exception while flushing the output stream";
DebugUtils.handleException(msg, e);
}
}
@@ -250,7 +250,7 @@ public class PumpStreamHandler implement
* @return the stream pumper thread
*/
protected Thread createPump(final InputStream is, final OutputStream os) {
- boolean closeWhenExhausted = os instanceof PipedOutputStream ? true : false;
+ final boolean closeWhenExhausted = os instanceof PipedOutputStream ? true : false;
return createPump(is, os, closeWhenExhausted);
}
@@ -278,22 +278,22 @@ public class PumpStreamHandler implement
* @param thread the thread to be stopped
* @param timeout the time in ms to wait to join
*/
- protected void stopThread(Thread thread, long timeout) {
+ protected void stopThread(final Thread thread, final long timeout) {
if (thread != null) {
try {
if (timeout == 0) {
thread.join();
} else {
- long timeToWait = timeout + STOP_TIMEOUT_ADDITION;
- long startTime = System.currentTimeMillis();
+ final long timeToWait = timeout + STOP_TIMEOUT_ADDITION;
+ final long startTime = System.currentTimeMillis();
thread.join(timeToWait);
if (!(System.currentTimeMillis() < startTime + timeToWait)) {
- String msg = "The stop timeout of " + timeout + " ms was exceeded";
+ final String msg = "The stop timeout of " + timeout + " ms was exceeded";
caught = new ExecuteException(msg, Executor.INVALID_EXITVALUE);
}
}
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
thread.interrupt();
}
}
@@ -307,7 +307,7 @@ public class PumpStreamHandler implement
* @param os the output stream to copy into
* @return the stream pumper thread
*/
- private Thread createSystemInPump(InputStream is, OutputStream os) {
+ private Thread createSystemInPump(final InputStream is, final OutputStream os) {
inputStreamPumper = new InputStreamPumper(is, os);
final Thread result = new Thread(inputStreamPumper, "Exec Input Stream Pumper");
result.setDaemon(true);
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java Sat Dec 28 14:20:34 2013
@@ -90,7 +90,7 @@ public class ShutdownHookProcessDestroye
*/
private void removeShutdownHook() {
if (added && !running) {
- boolean removed = Runtime.getRuntime().removeShutdownHook(
+ final boolean removed = Runtime.getRuntime().removeShutdownHook(
destroyProcessThread);
if (!removed) {
System.err.println("Could not remove shutdown hook");
@@ -106,7 +106,7 @@ public class ShutdownHookProcessDestroye
// this should return quickly, since it basically is a NO-OP.
try {
destroyProcessThread.join(20000);
- } catch (InterruptedException ie) {
+ } catch (final InterruptedException ie) {
// the thread didn't die in time
// it should not kill any processes unexpectedly
}
@@ -156,7 +156,7 @@ public class ShutdownHookProcessDestroye
*/
public boolean remove(final Process process) {
synchronized (processes) {
- boolean processRemoved = processes.removeElement(process);
+ final boolean processRemoved = processes.removeElement(process);
if (processRemoved && processes.size() == 0) {
removeShutdownHook();
}
@@ -179,13 +179,13 @@ public class ShutdownHookProcessDestroye
public void run() {
synchronized (processes) {
running = true;
- Enumeration e = processes.elements();
+ final Enumeration e = processes.elements();
while (e.hasMoreElements()) {
- Process process = (Process) e.nextElement();
+ final Process process = (Process) e.nextElement();
try {
process.destroy();
}
- catch (Throwable t) {
+ catch (final Throwable t) {
System.err.println("Unable to terminate process during process shutdown");
}
}
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/StreamPumper.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/StreamPumper.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/StreamPumper.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/StreamPumper.java Sat Dec 28 14:20:34 2013
@@ -105,14 +105,14 @@ public class StreamPumper implements Run
while ((length = is.read(buf)) > 0) {
os.write(buf, 0, length);
}
- } catch (Exception e) {
+ } catch (final Exception e) {
// nothing to do - happens quite often with watchdog
} finally {
if (closeWhenExhausted) {
try {
os.close();
- } catch (IOException e) {
- String msg = "Got exception while closing exhausted output stream";
+ } catch (final IOException e) {
+ final String msg = "Got exception while closing exhausted output stream";
DebugUtils.handleException(msg ,e);
}
}
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/Watchdog.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/Watchdog.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/Watchdog.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/Watchdog.java Sat Dec 28 14:20:34 2013
@@ -28,7 +28,7 @@ import java.util.Vector;
*/
public class Watchdog implements Runnable {
- private Vector observers = new Vector(1);
+ private final Vector observers = new Vector(1);
private final long timeout;
@@ -50,7 +50,7 @@ public class Watchdog implements Runnabl
}
protected final void fireTimeoutOccured() {
- Enumeration e = observers.elements();
+ final Enumeration e = observers.elements();
while (e.hasMoreElements()) {
((TimeoutObserver) e.nextElement()).timeoutOccured(this);
}
@@ -58,7 +58,7 @@ public class Watchdog implements Runnabl
public synchronized void start() {
stopped = false;
- Thread t = new Thread(this, "WATCHDOG");
+ final Thread t = new Thread(this, "WATCHDOG");
t.setDaemon(true);
t.start();
}
@@ -77,7 +77,7 @@ public class Watchdog implements Runnabl
while (!stopped && isWaiting) {
try {
wait(timeLeft);
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
}
timeLeft = timeout - (System.currentTimeMillis() - startTime);
isWaiting = timeLeft > 0;
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java Sat Dec 28 14:20:34 2013
@@ -65,7 +65,7 @@ public class DefaultProcessingEnvironmen
// create a copy of the map just in case that
// anyone is going to modifiy it, e.g. removing
// or setting an evironment variable
- Map copy = createEnvironmentMap();
+ final Map copy = createEnvironmentMap();
copy.putAll(procEnvironment);
return copy;
}
@@ -79,22 +79,22 @@ public class DefaultProcessingEnvironmen
protected Map createProcEnvironment() throws IOException {
if (procEnvironment == null) {
try {
- Method getenvs = System.class.getMethod( "getenv", (java.lang.Class[]) null );
- Map env = (Map) getenvs.invoke( null, (java.lang.Object[]) null );
+ final Method getenvs = System.class.getMethod( "getenv", (java.lang.Class[]) null );
+ final Map env = (Map) getenvs.invoke( null, (java.lang.Object[]) null );
procEnvironment = createEnvironmentMap();
procEnvironment.putAll(env);
- } catch ( NoSuchMethodException e ) {
+ } catch ( final NoSuchMethodException e ) {
// ok, just not on JDK 1.5
- } catch ( IllegalAccessException e ) {
+ } catch ( final IllegalAccessException e ) {
// Unexpected error obtaining environment - using JDK 1.4 method
- } catch ( InvocationTargetException e ) {
+ } catch ( final InvocationTargetException e ) {
// Unexpected error obtaining environment - using JDK 1.4 method
}
}
if(procEnvironment == null) {
procEnvironment = createEnvironmentMap();
- BufferedReader in = runProcEnvCommand();
+ final BufferedReader in = runProcEnvCommand();
String var = null;
String line;
@@ -130,8 +130,8 @@ public class DefaultProcessingEnvironmen
* @throws IOException starting the process failed
*/
protected BufferedReader runProcEnvCommand() throws IOException {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- Executor exe = new DefaultExecutor();
+ final ByteArrayOutputStream out = new ByteArrayOutputStream();
+ final Executor exe = new DefaultExecutor();
exe.setStreamHandler(new PumpStreamHandler(out));
// ignore the exit value - Just try to use what we got
exe.execute(getProcEnvCommand());
@@ -203,13 +203,13 @@ public class DefaultProcessingEnvironmen
if (OS.isFamilyZOS()) {
try {
return bos.toString("Cp1047");
- } catch (java.io.UnsupportedEncodingException e) {
+ } catch (final java.io.UnsupportedEncodingException e) {
// noop default encoding used
}
} else if (OS.isFamilyOS400()) {
try {
return bos.toString("Cp500");
- } catch (java.io.UnsupportedEncodingException e) {
+ } catch (final java.io.UnsupportedEncodingException e) {
// noop default encoding used
}
}
@@ -227,9 +227,9 @@ public class DefaultProcessingEnvironmen
private Map createEnvironmentMap() {
if (OS.isFamilyWindows()) {
return new TreeMap(new Comparator() {
- public int compare(Object arg0, Object arg1) {
- String key0 = (String) arg0;
- String key1 = (String) arg1;
+ public int compare(final Object arg0, final Object arg1) {
+ final String key0 = (String) arg0;
+ final String key1 = (String) arg1;
return key0.compareToIgnoreCase(key1);
}
});
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentUtils.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentUtils.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentUtils.java Sat Dec 28 14:20:34 2013
@@ -54,14 +54,14 @@ public class EnvironmentUtils
* @return array of key=value assignment strings or <code>null</code> if and only if
* the input map was <code>null</code>
*/
- public static String[] toStrings(Map environment) {
+ public static String[] toStrings(final Map environment) {
if (environment == null) {
return null;
}
- String[] result = new String[environment.size()];
+ final String[] result = new String[environment.size()];
int i = 0;
- for (Iterator iter = environment.entrySet().iterator(); iter.hasNext();) {
- Map.Entry entry = (Map.Entry) iter.next();
+ for (final Iterator iter = environment.entrySet().iterator(); iter.hasNext();) {
+ final Map.Entry entry = (Map.Entry) iter.next();
result[i] = entry.getKey().toString() + "=" + entry.getValue().toString();
i++;
@@ -89,8 +89,8 @@ public class EnvironmentUtils
* @param environment the current environment
* @param keyAndValue the key/value pair
*/
- public static void addVariableToEnvironment(Map environment, String keyAndValue) {
- String[] parsedVariable = parseEnvironmentVariable(keyAndValue);
+ public static void addVariableToEnvironment(final Map environment, final String keyAndValue) {
+ final String[] parsedVariable = parseEnvironmentVariable(keyAndValue);
environment.put(parsedVariable[0], parsedVariable[1]);
}
@@ -102,14 +102,14 @@ public class EnvironmentUtils
* @return a String[] containing the key and value
*/
private static String[] parseEnvironmentVariable(final String keyAndValue) {
- int index = keyAndValue.indexOf('=');
+ final int index = keyAndValue.indexOf('=');
if (index == -1) {
throw new IllegalArgumentException(
"Environment variable for this platform "
+ "must contain an equals sign ('=')");
}
- String[] result = new String[2];
+ final String[] result = new String[2];
result[0] = keyAndValue.substring(0, index);
result[1] = keyAndValue.substring(index + 1);
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java Sat Dec 28 14:20:34 2013
@@ -38,7 +38,7 @@ public class OpenVmsProcessingEnvironmen
*/
protected Map createProcEnvironment() throws IOException {
if (procEnvironment == null) {
- BufferedReader in = runProcEnvCommand();
+ final BufferedReader in = runProcEnvCommand();
procEnvironment = addVMSenvironmentVariables(new HashMap(), in);
}
@@ -52,7 +52,7 @@ public class OpenVmsProcessingEnvironmen
* @return the command line
*/
protected CommandLine getProcEnvCommand() {
- CommandLine commandLine = new CommandLine("show");
+ final CommandLine commandLine = new CommandLine("show");
commandLine.addArgument("symbol/global"); // the parser assumes symbols are global
commandLine.addArgument("*");
return commandLine;
@@ -73,9 +73,9 @@ public class OpenVmsProcessingEnvironmen
String line;
while ((line = in.readLine()) != null) {
final String SEP = "=="; // global symbol separator
- int sepidx = line.indexOf(SEP);
+ final int sepidx = line.indexOf(SEP);
if (sepidx > 0){
- String name = line.substring(0, sepidx).trim();
+ final String name = line.substring(0, sepidx).trim();
String value = line.substring(sepidx+SEP.length()).trim();
value = value.substring(1,value.length()-1); // drop enclosing quotes
environment.put(name,value);
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java Sat Dec 28 14:20:34 2013
@@ -34,7 +34,7 @@ public abstract class CommandLauncherImp
public Process exec(final CommandLine cmd, final Map env)
throws IOException {
- String[] envVar = EnvironmentUtils.toStrings(env);
+ final String[] envVar = EnvironmentUtils.toStrings(env);
return Runtime.getRuntime().exec(cmd.toStrings(), envVar);
}
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java Sat Dec 28 14:20:34 2013
@@ -53,7 +53,7 @@ public class Java13CommandLauncher exten
public Process exec(final CommandLine cmd, final Map env,
final File workingDir) throws IOException {
- String[] envVars = EnvironmentUtils.toStrings(env);
+ final String[] envVars = EnvironmentUtils.toStrings(env);
return Runtime.getRuntime().exec(cmd.toStrings(),
envVars, workingDir);
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java Sat Dec 28 14:20:34 2013
@@ -59,7 +59,7 @@ public class OS2CommandLauncher extends
return exec(cmd, env);
}
- CommandLine newCmd = new CommandLine("cmd");
+ final CommandLine newCmd = new CommandLine("cmd");
newCmd.addArgument("/c");
newCmd.addArguments(cmd.toStrings());
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java Sat Dec 28 14:20:34 2013
@@ -42,7 +42,7 @@ public class VmsCommandLauncher extends
*/
public Process exec(final CommandLine cmd, final Map env)
throws IOException {
- CommandLine vmsCmd = new CommandLine(
+ final CommandLine vmsCmd = new CommandLine(
createCommandFile(cmd, env).getPath()
);
@@ -57,7 +57,7 @@ public class VmsCommandLauncher extends
*/
public Process exec(final CommandLine cmd, final Map env,
final File workingDir) throws IOException {
- CommandLine vmsCmd = new CommandLine(
+ final CommandLine vmsCmd = new CommandLine(
createCommandFile(cmd, env).getPath()
);
@@ -77,7 +77,7 @@ public class VmsCommandLauncher extends
*/
private File createCommandFile(final CommandLine cmd, final Map env)
throws IOException {
- File script = File.createTempFile("EXEC", ".TMP");
+ final File script = File.createTempFile("EXEC", ".TMP");
script.deleteOnExit();
PrintWriter out = null;
try {
@@ -85,10 +85,10 @@ public class VmsCommandLauncher extends
// add the environment as global symbols for the DCL script
if (env != null) {
- Set entries = env.entrySet();
+ final Set entries = env.entrySet();
- for (Iterator iter = entries.iterator(); iter.hasNext();) {
- Entry entry = (Entry) iter.next();
+ for (final Iterator iter = entries.iterator(); iter.hasNext();) {
+ final Entry entry = (Entry) iter.next();
out.print("$ ");
out.print(entry.getKey());
out.print(" == "); // define as global symbol
@@ -96,9 +96,9 @@ public class VmsCommandLauncher extends
String value = (String) entry.getValue();
// Any embedded " values need to be doubled
if (value.indexOf('\"') > 0){
- StringBuffer sb = new StringBuffer();
+ final StringBuffer sb = new StringBuffer();
for (int i = 0; i < value.length(); i++) {
- char c = value.charAt(i);
+ final char c = value.charAt(i);
if (c == '\"') {
sb.append('\"');
}
@@ -115,7 +115,7 @@ public class VmsCommandLauncher extends
if (cmd.isFile()){// We assume it is it a script file
out.print("$ @");
// This is a bit crude, but seems to work
- String parts[] = StringUtils.split(command,"/");
+ final String parts[] = StringUtils.split(command,"/");
out.print(parts[0]); // device
out.print(":[");
out.print(parts[1]); // top level directory
@@ -130,7 +130,7 @@ public class VmsCommandLauncher extends
out.print("$ ");
out.print(command);
}
- String[] args = cmd.getArguments();
+ final String[] args = cmd.getArguments();
for (int i = 0; i < args.length; i++) {
out.println(" -");
out.print(args[i]);
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java Sat Dec 28 14:20:34 2013
@@ -54,7 +54,7 @@ public class WinNTCommandLauncher extend
// Use cmd.exe to change to the specified directory before running
// the command
- CommandLine newCmd = new CommandLine("cmd");
+ final CommandLine newCmd = new CommandLine("cmd");
newCmd.addArgument("/c");
newCmd.addArguments(cmd.toStrings());
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/DebugUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/DebugUtils.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/DebugUtils.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/DebugUtils.java Sat Dec 28 14:20:34 2013
@@ -46,7 +46,7 @@ public class DebugUtils
* @param msg message describing the problem
* @param e an exception being handled
*/
- public static void handleException(String msg, Exception e) {
+ public static void handleException(final String msg, final Exception e) {
if(isDebugEnabled()) {
System.err.println(msg);
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/MapUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/MapUtils.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/MapUtils.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/MapUtils.java Sat Dec 28 14:20:34 2013
@@ -37,13 +37,13 @@ public class MapUtils
* @param source the source map
* @return the clone of the source map
*/
- public static Map copy(Map source) {
+ public static Map copy(final Map source) {
if(source == null) {
return null;
}
- Map result = new HashMap();
+ final Map result = new HashMap();
result.putAll(source);
return result;
}
@@ -57,20 +57,20 @@ public class MapUtils
* @param prefix the prefix used for all names
* @return the clone of the source map
*/
- public static Map prefix(Map source, String prefix) {
+ public static Map prefix(final Map source, final String prefix) {
if(source == null) {
return null;
}
- Map result = new HashMap();
+ final Map result = new HashMap();
- Iterator iter = source.entrySet().iterator();
+ final Iterator iter = source.entrySet().iterator();
while(iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- Object key = entry.getKey();
- Object value = entry.getValue();
+ final Map.Entry entry = (Map.Entry) iter.next();
+ final Object key = entry.getKey();
+ final Object value = entry.getValue();
result.put(prefix + '.' + key.toString(), value);
}
@@ -85,7 +85,7 @@ public class MapUtils
* @param rhs the second map
* @return the merged map
*/
- public static Map merge(Map lhs, Map rhs) {
+ public static Map merge(final Map lhs, final Map rhs) {
Map result = null;
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/StringUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/StringUtils.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/StringUtils.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/util/StringUtils.java Sat Dec 28 14:20:34 2013
@@ -62,9 +62,9 @@ public class StringUtils {
* @param isLenient ignore a key not found in vars or throw a RuntimeException?
* @return String target string with replacements.
*/
- public static StringBuffer stringSubstitution(String argStr, Map vars, boolean isLenient) {
+ public static StringBuffer stringSubstitution(final String argStr, final Map vars, final boolean isLenient) {
- StringBuffer argBuf = new StringBuffer();
+ final StringBuffer argBuf = new StringBuffer();
if (argStr == null || argStr.length() == 0) {
return argBuf;
@@ -74,7 +74,7 @@ public class StringUtils {
return argBuf.append(argStr);
}
- int argStrLength = argStr.length();
+ final int argStrLength = argStr.length();
for (int cIdx = 0; cIdx < argStrLength;) {
@@ -84,7 +84,7 @@ public class StringUtils {
switch (ch) {
case '$':
- StringBuffer nameBuf = new StringBuffer();
+ final StringBuffer nameBuf = new StringBuffer();
del = argStr.charAt(cIdx + 1);
if (del == '{') {
cIdx++;
@@ -101,7 +101,7 @@ public class StringUtils {
if (nameBuf.length() >= 0) {
String value;
- Object temp = vars.get(nameBuf.toString());
+ final Object temp = vars.get(nameBuf.toString());
if(temp instanceof File) {
// for a file we have to fix the separator chars to allow
@@ -158,9 +158,9 @@ public class StringUtils {
* @param splitChar what to split on
* @return the array of strings
*/
- public static String[] split(String input, String splitChar) {
- StringTokenizer tokens = new StringTokenizer(input, splitChar);
- List strList = new ArrayList();
+ public static String[] split(final String input, final String splitChar) {
+ final StringTokenizer tokens = new StringTokenizer(input, splitChar);
+ final List strList = new ArrayList();
while (tokens.hasMoreTokens()) {
strList.add(tokens.nextToken());
}
@@ -179,7 +179,7 @@ public class StringUtils {
* @param arg the argument to fix
* @return the transformed argument
*/
- public static String fixFileSeparatorChar(String arg) {
+ public static String fixFileSeparatorChar(final String arg) {
return arg.replace(SLASH_CHAR, File.separatorChar).replace(
BACKSLASH_CHAR, File.separatorChar);
}
@@ -191,8 +191,8 @@ public class StringUtils {
* @param separator the separator between two strings
* @return the concatenated strings
*/
- public static String toString(String[] strings, String separator) {
- StringBuffer sb = new StringBuffer();
+ public static String toString(final String[] strings, final String separator) {
+ final StringBuffer sb = new StringBuffer();
for (int i = 0; i < strings.length; i++) {
if (i > 0) {
sb.append(separator);
Modified: commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/CommandLineTest.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/CommandLineTest.java?rev=1553832&r1=1553831&r2=1553832&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/CommandLineTest.java (original)
+++ commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/CommandLineTest.java Sat Dec 28 14:20:34 2013
@@ -29,14 +29,14 @@ import org.apache.commons.exec.util.Stri
public class CommandLineTest extends TestCase {
- private void assertEquals(String[] expected, String[] actual) {
+ private void assertEquals(final String[] expected, final String[] actual) {
if (!Arrays.equals(expected, actual)) {
throw new AssertionFailedError("Arrays not equal");
}
}
public void testExecutable() {
- CommandLine cmdl = new CommandLine("test");
+ final CommandLine cmdl = new CommandLine("test");
assertEquals("[test]", cmdl.toString());
assertEquals(new String[] {"test"}, cmdl.toStrings());
assertEquals("test", cmdl.getExecutable());
@@ -47,7 +47,7 @@ public class CommandLineTest extends Tes
try {
new CommandLine("");
fail("Must throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
+ } catch (final IllegalArgumentException e) {
// Expected
}
}
@@ -56,7 +56,7 @@ public class CommandLineTest extends Tes
try {
new CommandLine(" ");
fail("Must throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
+ } catch (final IllegalArgumentException e) {
// Expected
}
}
@@ -65,13 +65,13 @@ public class CommandLineTest extends Tes
try {
new CommandLine((String)null);
fail("Must throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
+ } catch (final IllegalArgumentException e) {
// Expected
}
}
public void testAddArgument() {
- CommandLine cmdl = new CommandLine("test");
+ final CommandLine cmdl = new CommandLine("test");
cmdl.addArgument("foo");
cmdl.addArgument("bar");
@@ -80,7 +80,7 @@ public class CommandLineTest extends Tes
}
public void testAddNullArgument() {
- CommandLine cmdl = new CommandLine("test");
+ final CommandLine cmdl = new CommandLine("test");
cmdl.addArgument(null);
assertEquals("[test]", cmdl.toString());
@@ -88,7 +88,7 @@ public class CommandLineTest extends Tes
}
public void testAddArgumentWithSpace() {
- CommandLine cmdl = new CommandLine("test");
+ final CommandLine cmdl = new CommandLine("test");
cmdl.addArgument("foo");
cmdl.addArgument("ba r");
assertEquals("[test, foo, \"ba r\"]", cmdl.toString());
@@ -96,7 +96,7 @@ public class CommandLineTest extends Tes
}
public void testAddArgumentWithQuote() {
- CommandLine cmdl = new CommandLine("test");
+ final CommandLine cmdl = new CommandLine("test");
cmdl.addArgument("foo");
cmdl.addArgument("ba\"r");
assertEquals("[test, foo, 'ba\"r']", cmdl.toString());
@@ -104,7 +104,7 @@ public class CommandLineTest extends Tes
}
public void testAddArgumentWithQuotesAround() {
- CommandLine cmdl = new CommandLine("test");
+ final CommandLine cmdl = new CommandLine("test");
cmdl.addArgument("\'foo\'");
cmdl.addArgument("\"bar\"");
cmdl.addArgument("\"fe z\"");
@@ -113,7 +113,7 @@ public class CommandLineTest extends Tes
}
public void testAddArgumentWithSingleQuote() {
- CommandLine cmdl = new CommandLine("test");
+ final CommandLine cmdl = new CommandLine("test");
cmdl.addArgument("foo");
cmdl.addArgument("ba'r");
@@ -123,32 +123,32 @@ public class CommandLineTest extends Tes
}
public void testAddArgumentWithBothQuotes() {
- CommandLine cmdl = new CommandLine("test");
+ final CommandLine cmdl = new CommandLine("test");
try {
cmdl.addArgument("b\"a'r");
fail("IllegalArgumentException should be thrown");
- } catch (IllegalArgumentException e) {
+ } catch (final IllegalArgumentException e) {
// OK, expected
}
}
public void testAddArguments() {
- CommandLine cmdl = new CommandLine("test");
+ final CommandLine cmdl = new CommandLine("test");
cmdl.addArguments("foo bar");
assertEquals("[test, foo, bar]", cmdl.toString());
assertEquals(new String[] {"test", "foo", "bar"}, cmdl.toStrings());
}
public void testAddArgumentsWithQuotes() {
- CommandLine cmdl = new CommandLine("test");
+ final CommandLine cmdl = new CommandLine("test");
cmdl.addArguments("'foo' \"bar\"");
assertEquals("[test, foo, bar]", cmdl.toString());
assertEquals(new String[] {"test", "foo", "bar"}, cmdl.toStrings());
}
public void testAddArgumentsWithQuotesAndSpaces() {
- CommandLine cmdl = new CommandLine("test");
+ final CommandLine cmdl = new CommandLine("test");
cmdl.addArguments("'fo o' \"ba r\"");
assertEquals("[test, \"fo o\", \"ba r\"]", cmdl.toString());
assertEquals(new String[] {"test", "\"fo o\"", "\"ba r\""}, cmdl
@@ -156,14 +156,14 @@ public class CommandLineTest extends Tes
}
public void testAddArgumentsArray() {
- CommandLine cmdl = new CommandLine("test");
+ final CommandLine cmdl = new CommandLine("test");
cmdl.addArguments(new String[] {"foo", "bar"});
assertEquals("[test, foo, bar]", cmdl.toString());
assertEquals(new String[] {"test", "foo", "bar"}, cmdl.toStrings());
}
public void testAddArgumentsArrayNull() {
- CommandLine cmdl = new CommandLine("test");
+ final CommandLine cmdl = new CommandLine("test");
cmdl.addArguments((String[]) null);
assertEquals("[test]", cmdl.toString());
assertEquals(new String[] {"test"}, cmdl.toStrings());
@@ -176,12 +176,12 @@ public class CommandLineTest extends Tes
*/
public void testAddTwoArguments() {
- CommandLine userAddCL1 = new CommandLine("useradd");
+ final CommandLine userAddCL1 = new CommandLine("useradd");
userAddCL1.addArgument("-g");
userAddCL1.addArgument("tomcat");
userAddCL1.addArgument("foo");
- CommandLine userAddCL2 = new CommandLine("useradd");
+ final CommandLine userAddCL2 = new CommandLine("useradd");
userAddCL2.addArgument("-g").addArgument("tomcat");
userAddCL2.addArgument("foo");
@@ -189,13 +189,13 @@ public class CommandLineTest extends Tes
}
public void testParseCommandLine() {
- CommandLine cmdl = CommandLine.parse("test foo bar");
+ final CommandLine cmdl = CommandLine.parse("test foo bar");
assertEquals("[test, foo, bar]", cmdl.toString());
assertEquals(new String[] {"test", "foo", "bar"}, cmdl.toStrings());
}
public void testParseCommandLineWithQuotes() {
- CommandLine cmdl = CommandLine.parse("test \"foo\" \'ba r\'");
+ final CommandLine cmdl = CommandLine.parse("test \"foo\" \'ba r\'");
assertEquals("[test, foo, \"ba r\"]", cmdl.toString());
assertEquals(new String[] {"test", "foo", "\"ba r\""}, cmdl.toStrings());
}
@@ -204,7 +204,7 @@ public class CommandLineTest extends Tes
try {
CommandLine.parse("test \"foo bar");
fail("IllegalArgumentException must be thrown due to uneven quotes");
- } catch (IllegalArgumentException e) {
+ } catch (final IllegalArgumentException e) {
// Expected
}
}
@@ -213,7 +213,7 @@ public class CommandLineTest extends Tes
try {
CommandLine.parse(null);
fail("IllegalArgumentException must be thrown due to incorrect command line");
- } catch (IllegalArgumentException e) {
+ } catch (final IllegalArgumentException e) {
// Expected
}
}
@@ -222,7 +222,7 @@ public class CommandLineTest extends Tes
try {
CommandLine.parse(" ");
fail("IllegalArgumentException must be thrown due to incorrect command line");
- } catch (IllegalArgumentException e) {
+ } catch (final IllegalArgumentException e) {
// Expected
}
}
@@ -234,10 +234,10 @@ public class CommandLineTest extends Tes
* do that without adding a space, e.g. "500x> ".
*/
public void testParseComplexCommandLine1() {
- HashMap substitutionMap = new HashMap();
+ final HashMap substitutionMap = new HashMap();
substitutionMap.put("in", "source.jpg");
substitutionMap.put("out", "target.jpg");
- CommandLine cmdl = CommandLine.parse("cmd /C convert ${in} -resize \"\'500x> \'\" ${out}", substitutionMap);
+ final CommandLine cmdl = CommandLine.parse("cmd /C convert ${in} -resize \"\'500x> \'\" ${out}", substitutionMap);
assertEquals("[cmd, /C, convert, source.jpg, -resize, \"500x> \", target.jpg]", cmdl.toString());
}
@@ -248,14 +248,14 @@ public class CommandLineTest extends Tes
*/
public void testParseComplexCommandLine2() {
- String commandline = "./script/jrake cruise:publish_installers "
+ final String commandline = "./script/jrake cruise:publish_installers "
+ "INSTALLER_VERSION=unstable_2_1 "
+ "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
+ "INSTALLER_DOWNLOAD_SERVER=\'something\' "
+ "WITHOUT_HELP_DOC=true";
- CommandLine cmdl = CommandLine.parse(commandline);
- String[] args = cmdl.getArguments();
+ final CommandLine cmdl = CommandLine.parse(commandline);
+ final String[] args = cmdl.getArguments();
assertEquals(args[0], "cruise:publish_installers");
assertEquals(args[1], "INSTALLER_VERSION=unstable_2_1");
// assertEquals(args[2], "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\"");
@@ -270,10 +270,10 @@ public class CommandLineTest extends Tes
*/
public void testParseRealLifeCommandLine_1() {
- String commandline = "cmd.exe /C \"c:\\was51\\Web Sphere\\AppServer\\bin\\versionInfo.bat\"";
+ final String commandline = "cmd.exe /C \"c:\\was51\\Web Sphere\\AppServer\\bin\\versionInfo.bat\"";
- CommandLine cmdl = CommandLine.parse(commandline);
- String[] args = cmdl.getArguments();
+ final CommandLine cmdl = CommandLine.parse(commandline);
+ final String[] args = cmdl.getArguments();
assertEquals("/C", args[0]);
assertEquals("\"c:\\was51\\Web Sphere\\AppServer\\bin\\versionInfo.bat\"", args[1]);
}
@@ -283,7 +283,7 @@ public class CommandLineTest extends Tes
* e.g. "runMemorySud.cmd", "10", "30", "-XX:+UseParallelGC", "\"-XX:ParallelGCThreads=2\""
*/
public void testComplexAddArgument() {
- CommandLine cmdl = new CommandLine("runMemorySud.cmd");
+ final CommandLine cmdl = new CommandLine("runMemorySud.cmd");
cmdl.addArgument("10", false);
cmdl.addArgument("30", false);
cmdl.addArgument("-XX:+UseParallelGC", false);
@@ -296,7 +296,7 @@ public class CommandLineTest extends Tes
* e.g. "runMemorySud.cmd", "10", "30", "-XX:+UseParallelGC", "\"-XX:ParallelGCThreads=2\""
*/
public void testComplexAddArguments1() {
- CommandLine cmdl = new CommandLine("runMemorySud.cmd");
+ final CommandLine cmdl = new CommandLine("runMemorySud.cmd");
cmdl.addArguments(new String[] {"10", "30", "-XX:+UseParallelGC", "\"-XX:ParallelGCThreads=2\""}, false);
assertEquals(new String[] {"runMemorySud.cmd", "10", "30", "-XX:+UseParallelGC", "\"-XX:ParallelGCThreads=2\""}, cmdl.toStrings());
}
@@ -308,7 +308,7 @@ public class CommandLineTest extends Tes
* don't know if this is a bug or a feature.
*/
public void testComplexAddArguments2() {
- CommandLine cmdl = new CommandLine("runMemorySud.cmd");
+ final CommandLine cmdl = new CommandLine("runMemorySud.cmd");
cmdl.addArguments("10 30 -XX:+UseParallelGC '\"-XX:ParallelGCThreads=2\"'", false);
assertEquals(new String[] {"runMemorySud.cmd", "10", "30", "-XX:+UseParallelGC", "\"-XX:ParallelGCThreads=2\""}, cmdl.toStrings());
}
@@ -320,13 +320,13 @@ public class CommandLineTest extends Tes
CommandLine cmdl;
- HashMap substitutionMap = new HashMap();
+ final HashMap substitutionMap = new HashMap();
substitutionMap.put("JAVA_HOME", "/usr/local/java");
substitutionMap.put("appMainClass", "foo.bar.Main");
substitutionMap.put("file1", new File("./pom.xml"));
substitutionMap.put("file2", new File(".\\temp\\READ ME.txt"));
- HashMap incompleteMap = new HashMap();
+ final HashMap incompleteMap = new HashMap();
incompleteMap.put("JAVA_HOME", "/usr/local/java");
// do not pass substitution map
@@ -367,7 +367,7 @@ public class CommandLineTest extends Tes
String[] result;
// build the user supplied parameters
- HashMap substitutionMap = new HashMap();
+ final HashMap substitutionMap = new HashMap();
substitutionMap.put("JAVA_HOME", "C:\\Programme\\jdk1.5.0_12");
substitutionMap.put("appMainClass", "foo.bar.Main");
@@ -392,8 +392,8 @@ public class CommandLineTest extends Tes
// verify the first command line again but by
// accessing the executable and arguments directly
- String executable = cmdl.getExecutable();
- String[] arguments = cmdl.getArguments();
+ final String executable = cmdl.getExecutable();
+ final String[] arguments = cmdl.getArguments();
assertEquals(StringUtils.fixFileSeparatorChar("C:\\Programme\\jdk1.5.0_12\\bin\\java"), executable);
assertEquals("-class", arguments[0]);
assertEquals("foo.bar.Main", arguments[1]);
@@ -409,14 +409,14 @@ public class CommandLineTest extends Tes
}
public void testCommandLineParsingWithExpansion3(){
- CommandLine cmdl = CommandLine.parse("AcroRd32.exe");
+ final CommandLine cmdl = CommandLine.parse("AcroRd32.exe");
cmdl.addArgument("/p");
cmdl.addArgument("/h");
cmdl.addArgument("${file}", false);
- HashMap params = new HashMap();
+ final HashMap params = new HashMap();
params.put("file", "C:\\Document And Settings\\documents\\432432.pdf");
cmdl.setSubstitutionMap(params);
- String[] result = cmdl.toStrings();
+ final String[] result = cmdl.toStrings();
assertEquals("AcroRd32.exe", result[0]);
assertEquals("/p", result[1]);
assertEquals("/h", result[2]);
@@ -430,7 +430,7 @@ public class CommandLineTest extends Tes
*/
public void testToString() throws Exception {
CommandLine cmdl;
- HashMap params = new HashMap();
+ final HashMap params = new HashMap();
// use no arguments
cmdl = CommandLine.parse("AcroRd32.exe", params);
@@ -457,9 +457,9 @@ public class CommandLineTest extends Tes
// On HP-UX quotes handling leads to errors,
// also usage of quotes isn't mandatory on other platforms too
// so it probably should work correctly either way.
- CommandLine cmd1 = new CommandLine("sh").addArgument("-c")
+ final CommandLine cmd1 = new CommandLine("sh").addArgument("-c")
.addArgument("echo 1", false);
- CommandLine cmd2 = new CommandLine("sh").addArgument("-c")
+ final CommandLine cmd2 = new CommandLine("sh").addArgument("-c")
.addArgument("echo").addArgument("1");
System.out.println("cmd1: " + cmd1.toString());
System.out.println("cmd2: " + cmd2.toString());
@@ -475,7 +475,7 @@ public class CommandLineTest extends Tes
CommandLine cmdl;
- String line = "./script/jrake "
+ final String line = "./script/jrake "
+ "cruise:publish_installers "
+ "INSTALLER_VERSION=unstable_2_1 "
+ "INSTALLER_PATH=\"/var/lib/cruise-agent/installers\" "
@@ -483,7 +483,7 @@ public class CommandLineTest extends Tes
+ "WITHOUT_HELP_DOC=true";
cmdl = CommandLine.parse(line);
- String[] args = cmdl.toStrings();
+ final String[] args = cmdl.toStrings();
assertEquals("./script/jrake", args[0]);
assertEquals("cruise:publish_installers", args[1]);
assertEquals("INSTALLER_VERSION=unstable_2_1", args[2]);
@@ -500,12 +500,12 @@ public class CommandLineTest extends Tes
CommandLine cmdl;
- String line = "dotnetfx.exe"
+ final String line = "dotnetfx.exe"
+ " /q:a "
+ "/c:\"install.exe /l \"\"c:\\Documents and Settings\\myusername\\Local Settings\\Temp\\netfx.log\"\" /q\"";
cmdl = CommandLine.parse(line);
- String[] args = cmdl.toStrings();
+ final String[] args = cmdl.toStrings();
assertEquals("dotnetfx.exe", args[0]);
assertEquals("/q:a", args[1]);
assertEquals("/c:\"install.exe /l \"\"c:\\Documents and Settings\\myusername\\Local Settings\\Temp\\netfx.log\"\" /q\"", args[2] );
@@ -518,10 +518,10 @@ public class CommandLineTest extends Tes
*/
public void _testExec36_3() {
- String commandline = "C:\\CVS_DB\\WeightsEngine /f WeightsEngine.mak CFG=\"WeightsEngine - Win32Release\"";
+ final String commandline = "C:\\CVS_DB\\WeightsEngine /f WeightsEngine.mak CFG=\"WeightsEngine - Win32Release\"";
- CommandLine cmdl = CommandLine.parse(commandline);
- String[] args = cmdl.getArguments();
+ final CommandLine cmdl = CommandLine.parse(commandline);
+ final String[] args = cmdl.getArguments();
assertEquals("/f", args[0]);
assertEquals("WeightsEngine.mak", args[1]);
assertEquals("CFG=\"WeightsEngine - Win32Release\"", args[2]);
@@ -529,13 +529,13 @@ public class CommandLineTest extends Tes
public void testCopyConstructor()
{
- Map map = new HashMap();
+ final Map map = new HashMap();
map.put("bar", "bar");
- CommandLine other = new CommandLine("test");
+ final CommandLine other = new CommandLine("test");
other.addArgument("foo");
other.setSubstitutionMap(map);
- CommandLine cmdl = new CommandLine(other);
+ final CommandLine cmdl = new CommandLine(other);
assertEquals(other.getExecutable(), cmdl.getExecutable());
assertEquals(other.getArguments(), cmdl.getArguments());
assertEquals(other.isFile(), cmdl.isFile());