No need to nest in else.
diff --git a/src/main/java/org/apache/commons/exec/CommandLine.java b/src/main/java/org/apache/commons/exec/CommandLine.java
index 7f2bab5..d2da131 100644
--- a/src/main/java/org/apache/commons/exec/CommandLine.java
+++ b/src/main/java/org/apache/commons/exec/CommandLine.java
@@ -78,19 +78,19 @@
if (line == null) {
throw new IllegalArgumentException("Command line can not be null");
- } else if (line.trim().isEmpty()) {
- throw new IllegalArgumentException("Command line can not be empty");
- } else {
- final String[] tmp = translateCommandline(line);
-
- final CommandLine cl = new CommandLine(tmp[0]);
- cl.setSubstitutionMap(substitutionMap);
- for (int i = 1; i < tmp.length; i++) {
- cl.addArgument(tmp[i]);
- }
-
- return cl;
}
+ if (line.trim().isEmpty()) {
+ throw new IllegalArgumentException("Command line can not be empty");
+ }
+ final String[] tmp = translateCommandline(line);
+
+ final CommandLine cl = new CommandLine(tmp[0]);
+ cl.setSubstitutionMap(substitutionMap);
+ for (int i = 1; i < tmp.length; i++) {
+ cl.addArgument(tmp[i]);
+ }
+
+ return cl;
}
/**
@@ -410,11 +410,11 @@
private String toCleanExecutable(final String dirtyExecutable) {
if (dirtyExecutable == null) {
throw new IllegalArgumentException("Executable can not be null");
- } else if (dirtyExecutable.trim().isEmpty()) {
- throw new IllegalArgumentException("Executable can not be empty");
- } else {
- return StringUtils.fixFileSeparatorChar(dirtyExecutable);
}
+ if (dirtyExecutable.trim().isEmpty()) {
+ throw new IllegalArgumentException("Executable can not be empty");
+ }
+ return StringUtils.fixFileSeparatorChar(dirtyExecutable);
}
/**
diff --git a/src/main/java/org/apache/commons/exec/DefaultExecutor.java b/src/main/java/org/apache/commons/exec/DefaultExecutor.java
index a598d9a..c55ea03 100644
--- a/src/main/java/org/apache/commons/exec/DefaultExecutor.java
+++ b/src/main/java/org/apache/commons/exec/DefaultExecutor.java
@@ -243,14 +243,12 @@
if (this.exitValues == null) {
return false;
}
- else if (this.exitValues.length == 0) {
+ if (this.exitValues.length == 0) {
return this.launcher.isFailure(exitValue);
}
- else {
- for (final int exitValue2 : this.exitValues) {
- if (exitValue2 == exitValue) {
- return false;
- }
+ for (final int exitValue2 : this.exitValues) {
+ if (exitValue2 == exitValue) {
+ return false;
}
}
return true;
diff --git a/src/main/java/org/apache/commons/exec/util/StringUtils.java b/src/main/java/org/apache/commons/exec/util/StringUtils.java
index 812cd70..46e78e7 100644
--- a/src/main/java/org/apache/commons/exec/util/StringUtils.java
+++ b/src/main/java/org/apache/commons/exec/util/StringUtils.java
@@ -95,11 +95,10 @@
for (++cIdx; cIdx < argStr.length(); ++cIdx) {
ch = argStr.charAt(cIdx);
- if (ch == '_' || ch == '.' || ch == '-' || ch == '+' || Character.isLetterOrDigit(ch)) {
- nameBuf.append(ch);
- } else {
+ if ((ch != '_') && (ch != '.') && (ch != '-') && (ch != '+') && !Character.isLetterOrDigit(ch)) {
break;
}
+ nameBuf.append(ch);
}
if (nameBuf.length() >= 0) {
@@ -119,13 +118,12 @@
if (value != null) {
argBuf.append(value);
} else {
- if (isLenient) {
- // just append the unresolved variable declaration
- argBuf.append("${").append(nameBuf.toString()).append("}");
- } else {
+ if (!isLenient) {
// complain that no variable was found
throw new RuntimeException("No value found for : " + nameBuf);
}
+ // just append the unresolved variable declaration
+ argBuf.append("${").append(nameBuf.toString()).append("}");
}
del = argStr.charAt(cIdx);
@@ -239,13 +237,13 @@
}
return buf.append(SINGLE_QUOTE).append(cleanedArgument).append(
SINGLE_QUOTE).toString();
- } else if (cleanedArgument.indexOf(SINGLE_QUOTE) > -1
+ }
+ if (cleanedArgument.indexOf(SINGLE_QUOTE) > -1
|| cleanedArgument.indexOf(" ") > -1) {
return buf.append(DOUBLE_QUOTE).append(cleanedArgument).append(
DOUBLE_QUOTE).toString();
- } else {
- return cleanedArgument;
}
+ return cleanedArgument;
}
/**
diff --git a/src/test/java/org/apache/commons/exec/TestUtil.java b/src/test/java/org/apache/commons/exec/TestUtil.java
index 133086e..f5b6e51 100644
--- a/src/test/java/org/apache/commons/exec/TestUtil.java
+++ b/src/test/java/org/apache/commons/exec/TestUtil.java
@@ -32,13 +32,14 @@
public static File resolveScriptForOS(final String script) {
if (OS.isFamilyWindows()) {
return new File(script + ".bat");
- } else if (OS.isFamilyUnix()) {
- return new File(script + ".sh");
- } else if (OS.isFamilyOpenVms()) {
- return new File(script + ".dcl");
- } else {
- throw new AssertionFailedError("Test not supported for this OS");
}
+ if (OS.isFamilyUnix()) {
+ return new File(script + ".sh");
+ }
+ if (OS.isFamilyOpenVms()) {
+ return new File(script + ".dcl");
+ }
+ throw new AssertionFailedError("Test not supported for this OS");
}
/**
@@ -48,13 +49,14 @@
public static int[] getTestScriptCodesForOS() {
if (OS.isFamilyWindows()) {
return new int[]{0,1};
- } else if (OS.isFamilyUnix()) {
- return new int[]{0,1};
- } else if (OS.isFamilyOpenVms()) {
- return new int[]{1,2};
- } else {
- throw new AssertionFailedError("Test not supported for this OS");
}
+ if (OS.isFamilyUnix()) {
+ return new int[]{0,1};
+ }
+ if (OS.isFamilyOpenVms()) {
+ return new int[]{1,2};
+ }
+ throw new AssertionFailedError("Test not supported for this OS");
}
}
diff --git a/src/test/java/org/apache/commons/exec/issues/Exec65Test.java b/src/test/java/org/apache/commons/exec/issues/Exec65Test.java
index bcaaa5d..a58bfd8 100644
--- a/src/test/java/org/apache/commons/exec/issues/Exec65Test.java
+++ b/src/test/java/org/apache/commons/exec/issues/Exec65Test.java
@@ -41,18 +41,17 @@
@Test(expected = ExecuteException.class, timeout = TEST_TIMEOUT)
public void testExec65WitSleepUsingSleepCommandDirectly() throws Exception {
- if (OS.isFamilyUnix()) {
- final ExecuteWatchdog watchdog = new ExecuteWatchdog(WATCHDOG_TIMEOUT);
- final DefaultExecutor executor = new DefaultExecutor();
- final CommandLine command = new CommandLine("sleep");
- command.addArgument("60");
- executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
- executor.setWatchdog(watchdog);
-
- executor.execute(command);
- } else {
+ if (!OS.isFamilyUnix()) {
throw new ExecuteException(testNotSupportedForCurrentOperatingSystem(), 0);
}
+ final ExecuteWatchdog watchdog = new ExecuteWatchdog(WATCHDOG_TIMEOUT);
+ final DefaultExecutor executor = new DefaultExecutor();
+ final CommandLine command = new CommandLine("sleep");
+ command.addArgument("60");
+ executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
+ executor.setWatchdog(watchdog);
+
+ executor.execute(command);
}
/**
@@ -67,16 +66,15 @@
@Test(expected = ExecuteException.class, timeout = TEST_TIMEOUT)
public void testExec65WithSleepUsingShellScript() throws Exception {
- if (OS.isFamilyMac()) {
- final DefaultExecutor executor = new DefaultExecutor();
- executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
- executor.setWatchdog(new ExecuteWatchdog(WATCHDOG_TIMEOUT));
- final CommandLine command = new CommandLine(resolveTestScript("sleep"));
-
- executor.execute(command);
- } else {
+ if (!OS.isFamilyMac()) {
throw new ExecuteException(testNotSupportedForCurrentOperatingSystem(), 0);
}
+ final DefaultExecutor executor = new DefaultExecutor();
+ executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
+ executor.setWatchdog(new ExecuteWatchdog(WATCHDOG_TIMEOUT));
+ final CommandLine command = new CommandLine(resolveTestScript("sleep"));
+
+ executor.execute(command);
}
/**
@@ -106,15 +104,14 @@
public void testExec65WithSudoUsingShellScript() throws Exception {
Assume.assumeFalse("Test is skipped on travis, because we have to be a sudoer "
+ "to make the other tests pass.", new File(".").getAbsolutePath().contains("travis"));
- if (OS.isFamilyUnix()) {
- final DefaultExecutor executor = new DefaultExecutor();
- executor.setStreamHandler(new PumpStreamHandler(System.out, System.err, System.in));
- executor.setWatchdog(new ExecuteWatchdog(WATCHDOG_TIMEOUT));
- final CommandLine command = new CommandLine(resolveTestScript("issues", "exec-65"));
-
- executor.execute(command);
- } else {
+ if (!OS.isFamilyUnix()) {
throw new ExecuteException(testNotSupportedForCurrentOperatingSystem(), 0);
}
+ final DefaultExecutor executor = new DefaultExecutor();
+ executor.setStreamHandler(new PumpStreamHandler(System.out, System.err, System.in));
+ executor.setWatchdog(new ExecuteWatchdog(WATCHDOG_TIMEOUT));
+ final CommandLine command = new CommandLine(resolveTestScript("issues", "exec-65"));
+
+ executor.execute(command);
}
}