Skip to content

Commit

Permalink
[console] replaced tabs with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
cretzel committed Apr 5, 2011
1 parent 2fe3f5f commit 70b1065
Show file tree
Hide file tree
Showing 47 changed files with 1,197 additions and 1,196 deletions.
Expand Up @@ -42,76 +42,76 @@
*/
public class ClojureEngine implements IScriptEngine {

/**
* {@inheritDoc}
*/
public synchronized IScriptExecutionResult execute(final String script) {
return execute(script, null);
}

/**
* {@inheritDoc}
*/
public synchronized IScriptExecutionResult execute(final String script,
final Map<String, Object> bindings) {

Throwable exception = null;
String output = null;
Object returnValue = null;

final PrintStream oldOut = System.out;
final PrintStream oldErr = System.err;
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
final PrintStream newOut = new PrintStream(bout, false);
final OutputStreamWriter newRtOut = new OutputStreamWriter(newOut);

try {
System.setOut(newOut);
System.setErr(newOut);

Associative mappings = PersistentHashMap.EMPTY;
mappings = mappings.assoc(RT.CURRENT_NS, RT.CURRENT_NS.get());
mappings = mappings.assoc(RT.OUT, newRtOut);
mappings = mappings.assoc(RT.ERR, newRtOut);
mappings = applyBindings(bindings, mappings);
Var.pushThreadBindings(mappings);

returnValue = Compiler.load(new StringReader(script));
} catch (final Exception e) {
exception = e;
} finally {

try {
Var.popThreadBindings();
newRtOut.flush();
newRtOut.close();
System.setOut(oldOut);
System.setErr(oldErr);

output = bout.toString();
} catch (final Exception e1) {
throw new ScriptEngineException(e1);
}

}

return new DefaultScriptExecutionResult(script, exception, output,
returnValue);
}

private Associative applyBindings(final Map<String, Object> bindings,
Associative mappings) {
if (bindings != null) {
final Set<Entry<String, Object>> entrySet = bindings.entrySet();
for (final Entry<String, Object> entry : entrySet) {
final Symbol symbol = Symbol.intern(entry.getKey());
final Namespace userNs = Namespace.findOrCreate(Symbol
.create("user".intern()));
final Var var = Var.intern(userNs, symbol);
mappings = mappings.assoc(var, entry.getValue());
}
}
return mappings;
}
/**
* {@inheritDoc}
*/
public synchronized IScriptExecutionResult execute(final String script) {
return execute(script, null);
}

/**
* {@inheritDoc}
*/
public synchronized IScriptExecutionResult execute(final String script,
final Map<String, Object> bindings) {

Throwable exception = null;
String output = null;
Object returnValue = null;

final PrintStream oldOut = System.out;
final PrintStream oldErr = System.err;
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
final PrintStream newOut = new PrintStream(bout, false);
final OutputStreamWriter newRtOut = new OutputStreamWriter(newOut);

try {
System.setOut(newOut);
System.setErr(newOut);

Associative mappings = PersistentHashMap.EMPTY;
mappings = mappings.assoc(RT.CURRENT_NS, RT.CURRENT_NS.get());
mappings = mappings.assoc(RT.OUT, newRtOut);
mappings = mappings.assoc(RT.ERR, newRtOut);
mappings = applyBindings(bindings, mappings);
Var.pushThreadBindings(mappings);

returnValue = Compiler.load(new StringReader(script));
} catch (final Exception e) {
exception = e;
} finally {

try {
Var.popThreadBindings();
newRtOut.flush();
newRtOut.close();
System.setOut(oldOut);
System.setErr(oldErr);

output = bout.toString();
} catch (final Exception e1) {
throw new ScriptEngineException(e1);
}

}

return new DefaultScriptExecutionResult(script, exception, output,
returnValue);
}

private Associative applyBindings(final Map<String, Object> bindings,
Associative mappings) {
if (bindings != null) {
final Set<Entry<String, Object>> entrySet = bindings.entrySet();
for (final Entry<String, Object> entry : entrySet) {
final Symbol symbol = Symbol.intern(entry.getKey());
final Namespace userNs = Namespace.findOrCreate(Symbol
.create("user".intern()));
final Var var = Var.intern(userNs, symbol);
mappings = mappings.assoc(var, entry.getValue());
}
}
return mappings;
}

}
Expand Up @@ -25,37 +25,37 @@
*/
final class DefaultScriptExecutionResult implements IScriptExecutionResult {

private final String script;
private final Throwable exception;
private final String output;
private final Object returnValue;

public DefaultScriptExecutionResult(String script, Throwable exception,
String output, Object returnValue) {
this.script = script;
this.exception = exception;
this.output = output;
this.returnValue = returnValue;
}

public String getScript() {
return script;
}

public boolean isSuccess() {
return exception == null;
}

public Throwable getException() {
return exception;
}

public String getOutput() {
return output;
}

public Object getReturnValue() {
return returnValue;
}
private final String script;
private final Throwable exception;
private final String output;
private final Object returnValue;

public DefaultScriptExecutionResult(final String script, final Throwable exception,
final String output, final Object returnValue) {
this.script = script;
this.exception = exception;
this.output = output;
this.returnValue = returnValue;
}

public String getScript() {
return script;
}

public boolean isSuccess() {
return exception == null;
}

public Throwable getException() {
return exception;
}

public String getOutput() {
return output;
}

public Object getReturnValue() {
return returnValue;
}

}
Expand Up @@ -24,13 +24,13 @@
*/
public class Engines {

public static IScriptEngine create(final Lang lang) {
switch (lang) {
case GROOVY:
return new GroovyEngine();
case CLOJURE:
return new ClojureEngine();
default:
public static IScriptEngine create(final Lang lang) {
switch (lang) {
case GROOVY:
return new GroovyEngine();
case CLOJURE:
return new ClojureEngine();
default:
throw new UnsupportedOperationException("Unsupported language: "
+ lang);
}
Expand Down
Expand Up @@ -33,45 +33,45 @@
*/
public class GroovyEngine implements IScriptEngine {

/**
* {@inheritDoc}
*/
public synchronized IScriptExecutionResult execute(final String script) {
return execute(script, null);
}
/**
* {@inheritDoc}
*/
public synchronized IScriptExecutionResult execute(final String script) {
return execute(script, null);
}

/**
* {@inheritDoc}
*/
public synchronized IScriptExecutionResult execute(final String script,
final Map<String, Object> bindings) {
/**
* {@inheritDoc}
*/
public synchronized IScriptExecutionResult execute(final String script,
final Map<String, Object> bindings) {

Throwable exception = null;
String output = null;
Object returnValue = null;
Throwable exception = null;
String output = null;
Object returnValue = null;

final PrintStream oldOut = System.out;
final PrintStream oldErr = System.err;
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
final PrintStream newOut = new PrintStream(bout, false);
final PrintStream oldOut = System.out;
final PrintStream oldErr = System.err;
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
final PrintStream newOut = new PrintStream(bout, false);

try {
System.setOut(newOut);
System.setErr(newOut);
try {
System.setOut(newOut);
System.setErr(newOut);

final GroovyShell shell = new GroovyShell(new Binding(bindings));
returnValue = shell.evaluate(script);
final GroovyShell shell = new GroovyShell(new Binding(bindings));
returnValue = shell.evaluate(script);

} catch (final Exception e) {
exception = e;
} finally {
System.setOut(oldOut);
System.setErr(oldErr);
output = bout.toString();
}
} catch (final Exception e) {
exception = e;
} finally {
System.setOut(oldOut);
System.setErr(oldErr);
output = bout.toString();
}

return new DefaultScriptExecutionResult(script, exception, output,
returnValue);
}
return new DefaultScriptExecutionResult(script, exception, output,
returnValue);
}

}
Expand Up @@ -26,9 +26,9 @@
*/
public interface IScriptExecutionResult {

String getScript();
String getScript();

boolean isSuccess();
boolean isSuccess();

String getOutput();

Expand Down
Expand Up @@ -19,12 +19,12 @@
/** Supported Languages enum. */
public enum Lang {

CLOJURE, GROOVY;
CLOJURE, GROOVY;

public String getFileExtension() {
switch (this) {
case CLOJURE:
return ".clj";
public String getFileExtension() {
switch (this) {
case CLOJURE:
return ".clj";
case GROOVY:
return ".groovy";
default:
Expand Down
Expand Up @@ -29,7 +29,7 @@
*/
public class LangFileFilter implements FilenameFilter {

private final String suffix;
private final String suffix;

private LangFileFilter(final String ext) {
suffix = ext;
Expand Down
Expand Up @@ -30,14 +30,14 @@

public class ClojureEngineTest {

private ClojureEngine engine;
private ClojureEngine engine;

@Before
public void setup() {
engine = new ClojureEngine();
}
@Before
public void setup() {
engine = new ClojureEngine();
}

@Test
@Test
public void test_instanceof_engine() throws Exception {
assertTrue(engine instanceof IScriptEngine);
}
Expand Down

0 comments on commit 70b1065

Please sign in to comment.