use of org.knime.ext.sun.nodes.script.compile.CompilationFailedException in project knime-core by knime.
the class StringManipulationNodeDialog method saveSettingsTo.
/**
* {@inheritDoc}
*/
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
StringManipulationSettings s = new StringManipulationSettings();
String newColName = null;
boolean isReplace = m_replaceRadio.isSelected();
if (isReplace) {
if (m_isOnlyVariables) {
newColName = ((FlowVariable) m_replaceVariableCombo.getModel().getSelectedItem()).getName();
} else {
newColName = m_replaceColumnCombo.getSelectedColumn();
}
} else {
newColName = m_newNameField.getText();
}
s.setReplace(isReplace);
s.setColName(newColName);
String exp = m_snippetPanel.getExpression();
s.setExpression(exp);
boolean isTestCompilation = m_compileOnCloseChecker.isSelected();
s.setTestCompilationOnDialogClose(isTestCompilation);
if (isTestCompilation && m_currentSpec != null) {
try {
Expression.compile(s.createJavaScriptingSettings(), m_currentSpec);
} catch (CompilationFailedException cfe) {
throw new InvalidSettingsException(cfe.getMessage(), cfe);
}
}
s.setInsertMissingAsNull(m_insertMissingAsNullChecker.isSelected());
s.saveSettingsTo(settings);
}
use of org.knime.ext.sun.nodes.script.compile.CompilationFailedException in project knime-core by knime.
the class Expression method createClass.
/* Called from the constructor. */
@SuppressWarnings("unchecked")
private Class<? extends AbstractSnippetExpression> createClass(final String body, final JavaScriptingSettings settings) throws CompilationFailedException {
Class<?> rType = settings.getReturnType();
int version = settings.getExpressionVersion();
boolean isArrayReturn = settings.isArrayReturn();
String header = settings.getHeader();
String source;
String name = "Expression" + COUNTER.getAndIncrement();
String[] imports = null != settings.getImports() ? settings.getImports() : getDefaultImports();
// Generate the well known source of the Expression
switch(version) {
case VERSION_1X:
source = generateSourceVersion1(name, body, rType, imports);
break;
case VERSION_2X:
source = generateSourceVersion2(name, body, header, rType, imports, isArrayReturn);
break;
default:
throw new CompilationFailedException("Unknown snippet version number: " + version);
}
try {
ensureTempClassPathExists();
} catch (IOException e1) {
throw new CompilationFailedException("Unable to copy required class path files", e1);
}
File[] additionalJarFiles;
try {
additionalJarFiles = settings.getJarFilesAsFiles();
} catch (InvalidSettingsException e1) {
throw new CompilationFailedException(e1.getMessage(), e1);
}
File[] classPathFiles = new File[additionalJarFiles.length + 1];
classPathFiles[0] = tempClassPath;
System.arraycopy(additionalJarFiles, 0, classPathFiles, 1, additionalJarFiles.length);
JavaCodeCompiler compiler = new JavaCodeCompiler();
compiler.setSources(new InMemorySourceJavaFileObject(name, source));
compiler.setClasspaths(classPathFiles);
compiler.compile();
ClassLoader loader = compiler.createClassLoader(compiler.getClass().getClassLoader());
try {
return (Class<? extends AbstractSnippetExpression>) loader.loadClass(name);
} catch (ClassNotFoundException e) {
throw new CompilationFailedException("Could not load generated class", e);
}
}
use of org.knime.ext.sun.nodes.script.compile.CompilationFailedException in project knime-core by knime.
the class JavaScriptingPanel method saveSettingsTo.
/**
* Save current settings.
* @param s To save to.
* @throws InvalidSettingsException If compilation fails.
*/
public void saveSettingsTo(final JavaScriptingSettings s) throws InvalidSettingsException {
String newColName = null;
boolean isReplace = m_replaceRadio.isSelected();
if (isReplace) {
if (m_customizer.getOutputIsVariable()) {
FlowVariable item = (FlowVariable) m_replaceVariableCombo.getSelectedItem();
newColName = item.getName();
} else {
newColName = m_replaceColumnCombo.getSelectedColumn();
}
} else {
newColName = m_newNameField.getText();
}
s.setReplace(isReplace);
s.setColName(newColName);
String type = m_returnTypeButtonGroup.getSelection().getActionCommand();
s.setReturnType(type);
s.setArrayReturn(m_isArrayReturnChecker.isSelected());
String exp = m_expEdit.getText();
s.setExpression(exp);
s.setHeader(m_headerEdit.getText());
s.setExpressionVersion(m_currentVersion);
boolean isTestCompilation = m_compileOnCloseChecker.isSelected();
s.setTestCompilationOnDialogClose(isTestCompilation);
if (isTestCompilation && m_currentSpec != null) {
try {
Expression.compile(s, m_currentSpec);
} catch (CompilationFailedException cfe) {
throw new InvalidSettingsException(cfe.getMessage(), cfe);
}
}
s.setInsertMissingAsNull(m_insertMissingAsNullChecker.isSelected());
}
Aggregations