Search in sources :

Example 1 with CustomClassLoader

use of com.dexels.navajo.compiler.tsl.custom.CustomClassLoader in project navajo by Dexels.

the class OSGiJavaCompilerImplementation method modified.

public void modified(Map<String, Object> settings, BundleContext context) {
    logger.info("Update settings");
    if (fileManagerRegistration != null) {
        fileManagerRegistration.unregister();
    }
    if (customClassLoaderRegistration != null) {
        customClassLoaderRegistration.unregister();
    }
    if (customJavaFileManager != null) {
        try {
            customJavaFileManager.close();
        } catch (IOException e) {
            logger.error("Error: ", e);
        }
    }
    compiler = getEclipseCompiler();
    DiagnosticListener<JavaFileObject> compilerOutputListener = diagnostic -> {
    // 
    };
    fileManager = compiler.getStandardFileManager(compilerOutputListener, null, null);
    customJavaFileManager = new CustomClassloaderJavaFileManager(Optional.ofNullable(context), getClass().getClassLoader(), fileManager);
    this.customClassLoader = new CustomClassLoader(customJavaFileManager);
    if (context != null) {
        // support unit tests:
        this.fileManagerRegistration = this.context.registerService(JavaFileManager.class, customJavaFileManager, null);
        // (type=navajoScriptClassLoader)
        Dictionary<String, String> nsc = new Hashtable<>();
        nsc.put("type", "navajoScriptClassLoader");
        this.customClassLoaderRegistration = this.context.registerService(ClassLoader.class, customClassLoader, nsc);
    }
}
Also used : Kind(javax.tools.JavaFileObject.Kind) Arrays(java.util.Arrays) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JavaFileManager(javax.tools.JavaFileManager) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) CustomClassLoader(com.dexels.navajo.compiler.tsl.custom.CustomClassLoader) CompilationTask(javax.tools.JavaCompiler.CompilationTask) Locale(java.util.Locale) Map(java.util.Map) URI(java.net.URI) Hashtable(java.util.Hashtable) CustomClassloaderJavaFileManager(com.dexels.navajo.compiler.tsl.custom.CustomClassloaderJavaFileManager) ServiceRegistration(org.osgi.framework.ServiceRegistration) StandardLocation(javax.tools.StandardLocation) Logger(org.slf4j.Logger) JavaCompiler(javax.tools.JavaCompiler) EclipseCompiler(org.eclipse.jdt.internal.compiler.tool.EclipseCompiler) StringWriter(java.io.StringWriter) CustomJavaFileObject(com.dexels.navajo.compiler.tsl.custom.CustomJavaFileObject) OSGiJavaCompiler(com.dexels.osgicompiler.OSGiJavaCompiler) IOException(java.io.IOException) BundleContext(org.osgi.framework.BundleContext) JavaFileObject(javax.tools.JavaFileObject) StandardJavaFileManager(javax.tools.StandardJavaFileManager) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Writer(java.io.Writer) Optional(java.util.Optional) DiagnosticListener(javax.tools.DiagnosticListener) Dictionary(java.util.Dictionary) CompilationException(com.dexels.navajo.script.api.CompilationException) InputStream(java.io.InputStream) CustomJavaFileObject(com.dexels.navajo.compiler.tsl.custom.CustomJavaFileObject) JavaFileObject(javax.tools.JavaFileObject) CustomClassloaderJavaFileManager(com.dexels.navajo.compiler.tsl.custom.CustomClassloaderJavaFileManager) JavaFileManager(javax.tools.JavaFileManager) CustomClassloaderJavaFileManager(com.dexels.navajo.compiler.tsl.custom.CustomClassloaderJavaFileManager) StandardJavaFileManager(javax.tools.StandardJavaFileManager) Hashtable(java.util.Hashtable) CustomClassLoader(com.dexels.navajo.compiler.tsl.custom.CustomClassLoader) IOException(java.io.IOException) CustomClassLoader(com.dexels.navajo.compiler.tsl.custom.CustomClassLoader)

Aggregations

CustomClassLoader (com.dexels.navajo.compiler.tsl.custom.CustomClassLoader)1 CustomClassloaderJavaFileManager (com.dexels.navajo.compiler.tsl.custom.CustomClassloaderJavaFileManager)1 CustomJavaFileObject (com.dexels.navajo.compiler.tsl.custom.CustomJavaFileObject)1 CompilationException (com.dexels.navajo.script.api.CompilationException)1 OSGiJavaCompiler (com.dexels.osgicompiler.OSGiJavaCompiler)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 DiagnosticListener (javax.tools.DiagnosticListener)1