Search in sources :

Example 1 with FilenameUtils

use of org.apache.commons.io.FilenameUtils in project knime-core by knime.

the class JavaSnippetCompiler method getTask.

/**
 * Creates a compilation task.
 *
 * @param out a Writer for additional output from the compiler;
 * use System.err if null
 * @param digsCollector a diagnostic listener; if null use the compiler's
 * default method for reporting diagnostics
 * @return an object representing the compilation process
 * @throws IOException if temporary jar files cannot be created
 */
public CompilationTask getTask(final Writer out, final DiagnosticCollector<JavaFileObject> digsCollector) throws IOException {
    if (m_compiler == null) {
        m_compileArgs = new ArrayList<>();
        final File[] classpaths = m_snippet.getCompiletimeClassPath();
        m_compileArgs.add("-classpath");
        m_compileArgs.add(Arrays.stream(classpaths).map(f -> f.getAbsolutePath()).map(FilenameUtils::normalize).collect(Collectors.joining(File.pathSeparator)));
        m_compileArgs.add("-source");
        m_compileArgs.add("1.8");
        m_compileArgs.add("-target");
        m_compileArgs.add("1.8");
        m_compileArgs.add("-encoding");
        m_compileArgs.add("UTF-8");
        m_compiler = new EclipseCompiler();
    }
    final StandardJavaFileManager stdFileMgr = m_compiler.getStandardFileManager(digsCollector, null, Charset.forName("UTF-8"));
    final CompilationTask compileTask = m_compiler.getTask(out, stdFileMgr, digsCollector, m_compileArgs, null, m_snippet.getCompilationUnits());
    // Release all .jar files that may have been opened
    stdFileMgr.close();
    return compileTask;
}
Also used : Arrays(java.util.Arrays) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) EclipseCompiler(org.eclipse.jdt.internal.compiler.tool.EclipseCompiler) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) JavaFileObject(javax.tools.JavaFileObject) StandardJavaFileManager(javax.tools.StandardJavaFileManager) URLClassLoader(java.net.URLClassLoader) Charset(java.nio.charset.Charset) CompilationTask(javax.tools.JavaCompiler.CompilationTask) Writer(java.io.Writer) DiagnosticCollector(javax.tools.DiagnosticCollector) FilenameUtils(org.apache.commons.io.FilenameUtils) EclipseCompiler(org.eclipse.jdt.internal.compiler.tool.EclipseCompiler) StandardJavaFileManager(javax.tools.StandardJavaFileManager) File(java.io.File) FilenameUtils(org.apache.commons.io.FilenameUtils) CompilationTask(javax.tools.JavaCompiler.CompilationTask)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collectors (java.util.stream.Collectors)1 DiagnosticCollector (javax.tools.DiagnosticCollector)1 CompilationTask (javax.tools.JavaCompiler.CompilationTask)1 JavaFileObject (javax.tools.JavaFileObject)1 StandardJavaFileManager (javax.tools.StandardJavaFileManager)1 FilenameUtils (org.apache.commons.io.FilenameUtils)1 EclipseCompiler (org.eclipse.jdt.internal.compiler.tool.EclipseCompiler)1