use of com.disney.groovity.source.GroovitySource in project groovity by disney.
the class Groovity method compile.
/**
* Compile a named set of source paths; compilation also handles static init and destroy lifecycle
* management and jar file creation
*
* @param force if true, recompile all sources, if false recompile only changed sources
* @param sourcePaths a list of source paths to compile
* @throws Exception
*/
public void compile(boolean force, boolean init, List<String> sourcePaths) throws Exception {
if (inCompile.compareAndSet(false, true)) {
try {
compileEvents.clear();
List<GroovitySource> sources = new ArrayList<GroovitySource>();
for (int i = 0; i < sourcePaths.size(); i++) {
String path = sourcePaths.get(i);
try {
GroovitySource source = null;
Exception error = null;
for (GroovitySourceLocator sourceLocator : sourceLocators) {
try {
source = sourceLocator.getGroovityScriptSource(path);
if (source != null && source.exists()) {
break;
}
} catch (Exception e) {
error = e;
}
}
if (source != null) {
sources.add(source);
} else if (error != null) {
throw error;
} else {
throw new FileNotFoundException(path);
}
} catch (Exception e) {
log.log(Level.SEVERE, "Unable to load source " + path, e);
}
}
compile(force, init, sources.toArray(new GroovitySource[0]));
} finally {
inCompile.set(false);
}
} else {
throw new RuntimeException("Groovy compiler is already busy, please retry later");
}
}
use of com.disney.groovity.source.GroovitySource in project groovity by disney.
the class GroovityServletContainer method enterConsole.
public void enterConsole() {
groovity.getArgsLookup().chainLast(new ArgsLookup.ConsoleArgsLookup());
try {
Console console = System.console();
if (console == null) {
log.warning("Unable to retrieve System.console(), GroovityServletContainer will not be interactive");
try {
Thread.currentThread().join();
} catch (InterruptedException e) {
}
return;
}
String cmdFmt = "(l)ist, (a)ll, (q)uit, or script path [%1$s] : ";
String scriptPath = "";
String command = console.readLine(cmdFmt, scriptPath);
while (!"q".equals(command)) {
if (!command.trim().isEmpty()) {
scriptPath = command.trim();
}
if (scriptPath.isEmpty()) {
console.printf("Error: enter a script path or q to quit\n");
} else {
// pick up any code changes
groovity.compileAll(false, true);
final AtomicBoolean error = new AtomicBoolean(false);
groovity.getCompilerEvents().forEach((k, v) -> {
if (v.getError() != null) {
error.set(true);
}
});
if (!error.get()) {
String[] pathParts;
if ("a".equals(scriptPath) || "l".equals(scriptPath)) {
ArrayList<String> paths = new ArrayList<>();
for (GroovitySourceLocator locator : groovity.getSourceLocators()) {
if (locator instanceof FileGroovitySourceLocator) {
String directory = ((FileGroovitySourceLocator) locator).getDirectory().toURI().toString();
if (consoleSourceLocations.contains(directory)) {
for (GroovitySource source : locator) {
paths.add(source.getPath().substring(0, source.getPath().lastIndexOf(".")));
}
}
}
}
if (paths.isEmpty()) {
paths.addAll(groovity.getGroovityScriptNames());
}
pathParts = paths.toArray(new String[0]);
} else {
pathParts = scriptPath.split("\\s*,\\s*");
}
if ("l".equals(scriptPath)) {
console.printf("All available paths:\n");
for (String pathPart : pathParts) {
console.printf("\t%1$s\n", pathPart);
}
} else {
for (String pathPart : pathParts) {
try {
run(pathPart);
} catch (Throwable e) {
console.printf("%1$s running script %2$s :\n", e.getClass().getName(), pathPart);
e.printStackTrace(console.writer());
}
}
}
}
}
command = console.readLine(cmdFmt, scriptPath);
}
} finally {
groovity.getArgsLookup().removeLast();
}
}
Aggregations