Search in sources :

Example 11 with STJSRuntimeException

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;
}
Also used : JavaFileObject(javax.tools.JavaFileObject) STJSRuntimeException(org.stjs.generator.STJSRuntimeException) JarURLConnection(java.net.JarURLConnection) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JarEntry(java.util.jar.JarEntry) URLConnection(java.net.URLConnection) JarURLConnection(java.net.JarURLConnection)

Example 12 with STJSRuntimeException

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);
    }
}
Also used : STJSRuntimeException(org.stjs.generator.STJSRuntimeException) IOException(java.io.IOException) SuppressWarnings(edu.umd.cs.findbugs.annotations.SuppressWarnings)

Aggregations

STJSRuntimeException (org.stjs.generator.STJSRuntimeException)12 IOException (java.io.IOException)9 InputStream (java.io.InputStream)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 SourceMapParseException (com.google.debugging.sourcemap.SourceMapParseException)1 SourceMapping (com.google.debugging.sourcemap.SourceMapping)1 SuppressWarnings (edu.umd.cs.findbugs.annotations.SuppressWarnings)1 File (java.io.File)1 JarURLConnection (java.net.JarURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URLClassLoader (java.net.URLClassLoader)1 URLConnection (java.net.URLConnection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JarEntry (java.util.jar.JarEntry)1 Matcher (java.util.regex.Matcher)1