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;
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations