All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.qwazr.compiler.CompilerManager Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
/**
 * Copyright 2015-2016 Emmanuel Keller / QWAZR
 * 

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.qwazr.compiler; import com.qwazr.classloader.ClassLoaderManager; import com.qwazr.server.ApplicationBuilder; import com.qwazr.server.GenericServer; import com.qwazr.utils.ClassLoaderUtils; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; public class CompilerManager { private final JavaCompiler javaCompiler; private final JniCompiler jniCompiler; private final CompilerServiceInterface service; public CompilerManager(final ClassLoaderManager classLoaderManager, final File dataDirectory) throws IOException, URISyntaxException { final File javaSourceDirectory = new File(dataDirectory, "src/main/java"); final File cppSourceDirectory = new File(dataDirectory, "src/main/cpp"); if (!classLoaderManager.javaClassesDirectory.exists()) classLoaderManager.javaClassesDirectory.mkdirs(); javaCompiler = JavaCompiler.newInstance(classLoaderManager, javaSourceDirectory, classLoaderManager.javaClassesDirectory, classLoaderManager.javaLibrariesDirectory); jniCompiler = new JniCompiler(classLoaderManager.javaClassesDirectory, cppSourceDirectory); service = new CompilerServiceImpl(this); } public CompilerManager registerContextAttribute(final GenericServer.Builder builder) { builder.contextAttribute(this); return this; } public CompilerManager registerWebService(final ApplicationBuilder webServices) { webServices.singletons(service); return this; } public void compileNative(String className) throws ClassNotFoundException, IOException, InterruptedException { final Class clazz = ClassLoaderUtils.findClass(className); jniCompiler.generateHeader(clazz); jniCompiler.compile(clazz); } public CompilerServiceInterface getService() { return service; } CompilerStatus getStatus() { return javaCompiler.getStatus(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy