Search in sources :

Example 1 with STJSRuntimeException

use of org.stjs.generator.STJSRuntimeException in project st-js by st-js.

the class RhinoJavaScriptWriter method print.

/**
 * <p>print.</p>
 *
 * @param arg a {@link java.lang.String} object.
 * @return a {@link org.stjs.generator.javascript.rhino.RhinoJavaScriptWriter} object.
 */
protected RhinoJavaScriptWriter print(String arg) {
    if (!indented) {
        makeIndent();
        indented = true;
    }
    try {
        writer.append(arg);
    } catch (IOException e) {
        throw new STJSRuntimeException("Writing problem:" + e, e);
    }
    // TODO check for newlines in the string
    currentColumn += arg.length();
    return this;
}
Also used : STJSRuntimeException(org.stjs.generator.STJSRuntimeException) IOException(java.io.IOException)

Example 2 with STJSRuntimeException

use of org.stjs.generator.STJSRuntimeException in project st-js by st-js.

the class GenerationPlugins method forClass.

/**
 * <p>forClass.</p>
 *
 * @param clazz a {@link java.lang.Class} object.
 * @return a {@link org.stjs.generator.plugin.GenerationPlugins} object.
 */
@SuppressWarnings("unchecked")
public GenerationPlugins<JS> forClass(Class<?> clazz) {
    UsePlugin usePlugins = clazz.getAnnotation(UsePlugin.class);
    if (usePlugins == null || usePlugins.value() == null || usePlugins.value().length == 0) {
        // this class uses the default plugins - no need to create a new one
        return this;
    }
    // TODO - here I can add a cache using the list of plugin names as key
    GenerationPlugins<JS> newPlugins = new GenerationPlugins<JS>();
    newPlugins.checkVisitor = new CheckVisitor(checkVisitor);
    newPlugins.writerVisitor = new WriterVisitor<JS>(writerVisitor);
    for (String pluginName : usePlugins.value()) {
        STJSGenerationPlugin<JS> plugin = optionalPlugins.get(pluginName);
        if (plugin == null) {
            throw new STJSRuntimeException("The class:" + clazz.getName() + " need an unknown Generation Plugin :" + pluginName);
        }
        plugin.contributeCheckVisitor(newPlugins.checkVisitor);
        plugin.contributeWriteVisitor(newPlugins.writerVisitor);
    }
    return newPlugins;
}
Also used : STJSRuntimeException(org.stjs.generator.STJSRuntimeException) CheckVisitor(org.stjs.generator.check.CheckVisitor) UsePlugin(org.stjs.javascript.annotation.UsePlugin)

Example 3 with STJSRuntimeException

use of org.stjs.generator.STJSRuntimeException in project st-js by st-js.

the class GenerationPlugins method loadConfigFile.

private void loadConfigFile(URL configFile) {
    InputStream input = null;
    try {
        input = configFile.openStream();
        Properties props = new Properties();
        props.load(input);
        String javaVersion = props.getProperty(JAVA_VERSION_ENTRY);
        String runningVersion = System.getProperty(JAVA_VERSION_ENTRY);
        if (compareVersion(javaVersion, runningVersion) > 0) {
            // this plugin is for a next version of java
            return;
        }
        for (Map.Entry<Object, Object> entry : props.entrySet()) {
            loadPlugin(entry.getKey().toString(), entry.getValue().toString());
        }
    } catch (IOException e) {
        throw new STJSRuntimeException(e);
    } finally {
        Closeables.closeQuietly(input);
    }
}
Also used : STJSRuntimeException(org.stjs.generator.STJSRuntimeException) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with STJSRuntimeException

use of org.stjs.generator.STJSRuntimeException in project st-js by st-js.

the class CommandLine method compile.

static void compile(final String path, final List<File> sourceFiles, List<File> dependencies) {
    try {
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        if (compiler == null) {
            throw new STJSRuntimeException("A Java compiler is not available for this project. " + "You may have configured your environment to run with a JRE instead of a JDK");
        }
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
        fileManager.setLocation(StandardLocation.CLASS_PATH, dependencies);
        Iterable<? extends JavaFileObject> compilationUnits1 = fileManager.getJavaFileObjectsFromFiles(sourceFiles);
        compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call();
        fileManager.close();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : STJSRuntimeException(org.stjs.generator.STJSRuntimeException) JavaCompiler(javax.tools.JavaCompiler) StandardJavaFileManager(javax.tools.StandardJavaFileManager) STJSRuntimeException(org.stjs.generator.STJSRuntimeException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 5 with STJSRuntimeException

use of org.stjs.generator.STJSRuntimeException in project st-js by st-js.

the class GenerationPlugins method loadPlugin.

@SuppressWarnings("unchecked")
private void loadPlugin(String key, String value) {
    if (key.equals(JAVA_VERSION_ENTRY)) {
        return;
    }
    STJSGenerationPlugin<JS> plugin;
    try {
        plugin = (STJSGenerationPlugin<JS>) Class.forName(value).newInstance();
    } catch (InstantiationException e) {
        throw new STJSRuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new STJSRuntimeException(e);
    } catch (ClassNotFoundException e) {
        throw new STJSRuntimeException(e);
    }
    if (plugin.loadByDefault()) {
        plugin.contributeCheckVisitor(checkVisitor);
        plugin.contributeWriteVisitor(writerVisitor);
        mandatoryPlugins.put(key, plugin);
    } else {
        optionalPlugins.put(key, plugin);
    }
}
Also used : STJSRuntimeException(org.stjs.generator.STJSRuntimeException)

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