Formatting
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1736057 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Parser.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Parser.java
index e98acf1..862bef6 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Parser.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Parser.java
@@ -330,7 +330,8 @@
|| Token.eq(")", t)
|| Token.eq("]", t))
{
- if (needRedirArg) {
+ if (needRedirArg)
+ {
throw new EOFError(tz.line, tz.column, "Expected file name for redirection", "redir", "foo");
}
push(t);
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Pipe.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Pipe.java
index d3222f4..fc9bc67 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Pipe.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Pipe.java
@@ -25,7 +25,6 @@
import java.io.InterruptedIOException;
import java.io.PrintStream;
import java.net.URI;
-import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
import java.nio.channels.Channel;
@@ -39,7 +38,6 @@
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -49,10 +47,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.felix.gogo.runtime.CommandSessionImpl.JobImpl;
import org.apache.felix.gogo.api.Job;
import org.apache.felix.gogo.api.Job.Status;
import org.apache.felix.gogo.api.Process;
+import org.apache.felix.gogo.runtime.CommandSessionImpl.JobImpl;
import org.apache.felix.gogo.runtime.Parser.Statement;
import org.apache.felix.gogo.runtime.Pipe.Result;
import org.apache.felix.service.command.Converter;
@@ -248,17 +246,23 @@
try
{
List<Token> tokens = statement.redirections();
- for (int i = 0; i < tokens.size(); i++) {
+ for (int i = 0; i < tokens.size(); i++)
+ {
Token t = tokens.get(i);
Matcher m;
- if ((m = Pattern.compile("(?:([0-9])?|(&)?)>(>)?").matcher(t)).matches()) {
+ if ((m = Pattern.compile("(?:([0-9])?|(&)?)>(>)?").matcher(t)).matches())
+ {
int fd;
- if (m.group(1) != null) {
+ if (m.group(1) != null)
+ {
fd = Integer.parseInt(m.group(1));
}
- else if (m.group(2) != null) {
+ else if (m.group(2) != null)
+ {
fd = -1; // both 1 and 2
- } else {
+ }
+ else
+ {
fd = 1;
}
boolean append = m.group(3) != null;
@@ -283,37 +287,45 @@
}
}
}
- else if ((m = Pattern.compile("([0-9])?>&([0-9])").matcher(t)).matches()) {
+ else if ((m = Pattern.compile("([0-9])?>&([0-9])").matcher(t)).matches())
+ {
int fd0 = 1;
- if (m.group(1) != null) {
+ if (m.group(1) != null)
+ {
fd0 = Integer.parseInt(m.group(1));
}
int fd1 = Integer.parseInt(m.group(2));
- if (streams[fd0] != null && toclose[fd0]) {
+ if (streams[fd0] != null && toclose[fd0])
+ {
streams[fd0].close();
}
// If the stream has to be closed, close it when both streams are closed
- if (toclose[fd1]) {
+ if (toclose[fd1])
+ {
Channel channel = streams[fd1];
AtomicInteger references = new AtomicInteger();
streams[fd0] = new RefByteChannel(channel, references);
streams[fd1] = new RefByteChannel(channel, references);
toclose[fd0] = true;
}
- else {
+ else
+ {
streams[fd0] = streams[fd1];
toclose[fd0] = false;
}
}
- else if ((m = Pattern.compile("([0-9])?<(>)?").matcher(t)).matches()) {
+ else if ((m = Pattern.compile("([0-9])?<(>)?").matcher(t)).matches())
+ {
int fd = 0;
- if (m.group(1) != null) {
+ if (m.group(1) != null)
+ {
fd = Integer.parseInt(m.group(1));
}
boolean output = m.group(2) != null;
Set<StandardOpenOption> options = new HashSet<>();
options.add(StandardOpenOption.READ);
- if (output) {
+ if (output)
+ {
options.add(StandardOpenOption.WRITE);
options.add(StandardOpenOption.CREATE);
}
@@ -348,65 +360,83 @@
// the command is about to be executed.
errChannel = (WritableByteChannel) streams[2];
- if (threadIo != null) {
+ if (threadIo != null)
+ {
threadIo.setStreams(in, out, err);
}
Pipe previous = setCurrentPipe(this);
- try {
+ try
+ {
Object result;
// Very special case for empty statements with redirection
- if (statement.tokens().isEmpty() && toclose[0]) {
+ if (statement.tokens().isEmpty() && toclose[0])
+ {
ByteBuffer bb = ByteBuffer.allocate(1024);
- while (((ReadableByteChannel) streams[0]).read(bb) >= 0 || bb.position() != 0) {
+ while (((ReadableByteChannel) streams[0]).read(bb) >= 0 || bb.position() != 0)
+ {
bb.flip();
((WritableByteChannel) streams[1]).write(bb);
bb.compact();
}
result = null;
- } else {
+ }
+ else
+ {
result = closure.execute(statement);
}
// If an error has been set
- if (error != 0) {
+ if (error != 0)
+ {
return new Result(error);
}
// We don't print the result if we're at the end of the pipe
- if (result != null && !endOfPipe && !Boolean.FALSE.equals(closure.session().get(".FormatPipe"))) {
+ if (result != null && !endOfPipe && !Boolean.FALSE.equals(closure.session().get(".FormatPipe")))
+ {
out.println(closure.session().format(result, Converter.INSPECT));
}
return new Result(result);
- } finally {
+ }
+ finally
+ {
setCurrentPipe(previous);
}
}
catch (Exception e)
{
String msg = "gogo: " + e.getClass().getSimpleName() + ": " + e.getMessage() + "\n";
- try {
+ try
+ {
errChannel.write(ByteBuffer.wrap(msg.getBytes()));
- } catch (IOException ioe) {
+ }
+ catch (IOException ioe)
+ {
e.addSuppressed(ioe);
}
return new Result(e);
}
finally
{
- if (out != null) {
+ if (out != null)
+ {
out.flush();
}
- if (err != null) {
+ if (err != null)
+ {
err.flush();
}
- if (threadIo != null) {
+ if (threadIo != null)
+ {
threadIo.close();
}
try
{
- for (int i = 0; i < 10; i++) {
- if (toclose[i] && streams[i] != null) {
+ for (int i = 0; i < 10; i++)
+ {
+ if (toclose[i] && streams[i] != null)
+ {
streams[i].close();
}
}
@@ -472,11 +502,14 @@
return null;
}
- private Channel wrap(Channel channel) {
- if (channel == null) {
+ private Channel wrap(Channel channel)
+ {
+ if (channel == null)
+ {
return null;
}
- if (channel instanceof MultiChannel) {
+ if (channel instanceof MultiChannel)
+ {
return channel;
}
MultiChannel mch = new MultiChannel();
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Tokenizer.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Tokenizer.java
index 558b2d9..549cb5c 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Tokenizer.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Tokenizer.java
@@ -108,11 +108,13 @@
case '<':
t = text.subSequence(start, index);
tn = text.subSequence(start, index + 1);
- if (redir.matcher(tn).matches()) {
+ if (redir.matcher(tn).matches())
+ {
getch();
break;
}
- if (redir.matcher(t).matches() && start < index - 1) {
+ if (redir.matcher(t).matches() && start < index - 1)
+ {
getch();
}
word = 0;
@@ -120,7 +122,8 @@
case '&':
// beginning of token
if (start == index - 1) {
- if (peek() == '&' || peek() == '>') {
+ if (peek() == '&' || peek() == '>')
+ {
getch();
getch();
}
@@ -128,16 +131,19 @@
return token(start);
}
// in the middle of a redirection
- else if (redir.matcher(text.subSequence(start, index)).matches()) {
+ else if (redir.matcher(text.subSequence(start, index)).matches())
+ {
getch();
break;
}
- else {
+ else
+ {
word = 0;
return token(start);
}
case '|':
- if (start == index - 1 && (peek() == '|' || peek() == '&')) {
+ if (start == index - 1 && (peek() == '|' || peek() == '&'))
+ {
getch();
getch();
}
diff --git a/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser4.java b/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser4.java
index 7980014..ec69734 100644
--- a/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser4.java
+++ b/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser4.java
@@ -65,7 +65,8 @@
}
@Test
- public void testRedirInput() throws Exception {
+ public void testRedirInput() throws Exception
+ {
Context c = new Context();
c.addCommand("echo", this);
c.addCommand("tac", this);
@@ -83,7 +84,8 @@
}
@Test
- public void testMultiInput() throws Exception {
+ public void testMultiInput() throws Exception
+ {
Context c = new Context();
c.addCommand("echo", this);
c.addCommand("tac", this);