use of org.stjs.generator.STJSRuntimeException in project st-js by st-js.
the class PackageInternalsFinder method processJar.
private List<JavaFileObject> processJar(URL packageFolderURL, boolean recursive) {
List<JavaFileObject> result = new ArrayList<JavaFileObject>();
try {
URLConnection urlConnection = packageFolderURL.openConnection();
if (!(urlConnection instanceof JarURLConnection)) {
// weird file in the classpath
return Collections.emptyList();
}
String jarUri = packageFolderURL.toExternalForm().split("!")[0];
JarURLConnection jarConn = (JarURLConnection) urlConnection;
String rootEntryName = jarConn.getEntryName();
int rootEnd = rootEntryName.length() + 1;
Enumeration<JarEntry> entryEnum = jarConn.getJarFile().entries();
while (entryEnum.hasMoreElements()) {
JarEntry jarEntry = entryEnum.nextElement();
String name = jarEntry.getName();
addFileObject(jarUri, name, rootEntryName, rootEnd, result, recursive);
}
} catch (IOException e) {
throw new STJSRuntimeException("Wasn't able to open " + packageFolderURL + " as a jar file", e);
}
return result;
}
use of org.stjs.generator.STJSRuntimeException in project st-js by st-js.
the class NodeJSExecutor method run.
/**
* <p>run.</p>
*
* @param srcFile a {@link java.io.File} object.
* @return a {@link org.stjs.generator.executor.ExecutionResult} object.
*/
@SuppressWarnings(value = "REC_CATCH_EXCEPTION")
public ExecutionResult run(File srcFile) {
try {
Process p = Runtime.getRuntime().exec(new String[] { NODE_JS, srcFile.getAbsolutePath() });
int exitValue = p.waitFor();
return new ExecutionResult(null, readStream(p.getInputStream()), readStream(p.getErrorStream()), exitValue);
} catch (IOException e) {
// TODO : this is not really going to be working on all OS!
if (e.getMessage().contains("Cannot run program")) {
String errMsg = "Please install node.js to use this feature https://github.com/joyent/node/wiki/Installation";
throw new STJSRuntimeException(errMsg, e);
}
throw new STJSRuntimeException(e);
} catch (InterruptedException e) {
throw new STJSRuntimeException(e);
}
}
Aggregations