Search in sources :

Example 1 with RuntimeClassLoaderFactory

use of io.crnk.gen.runtime.RuntimeClassLoaderFactory in project crnk-framework by crnk-project.

the class GenerateTypescriptTask method generate.

@TaskAction
public void generate() throws IOException {
    Thread thread = Thread.currentThread();
    ClassLoader contextClassLoader = thread.getContextClassLoader();
    RuntimeClassLoaderFactory classLoaderFactory = new RuntimeClassLoaderFactory(getProject());
    TSGeneratorConfig config = getConfig();
    setupDefaultConfig(config);
    URLClassLoader classloader = classLoaderFactory.createClassLoader(contextClassLoader);
    try {
        thread.setContextClassLoader(classloader);
        runGeneration(classloader);
    } finally {
        // make sure to restore the classloader when leaving this task
        thread.setContextClassLoader(contextClassLoader);
        // dispose classloader
        classloader.close();
    }
}
Also used : RuntimeClassLoaderFactory(io.crnk.gen.runtime.RuntimeClassLoaderFactory) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with RuntimeClassLoaderFactory

use of io.crnk.gen.runtime.RuntimeClassLoaderFactory in project crnk-framework by crnk-project.

the class ForkedGenerateTypescriptTask method initClassPath.

private void initClassPath() {
    RuntimeClassLoaderFactory classLoaderFactory = new RuntimeClassLoaderFactory(getProject());
    Set<File> classpath = new HashSet<>();
    classpath.addAll(classLoaderFactory.getProjectLibraries());
    try {
        classpath.add(Paths.get(classLoaderFactory.getPluginUrl().toURI()).toFile());
    } catch (URISyntaxException e) {
        throw new IllegalStateException(e);
    }
    Project project = getProject();
    ConfigurableFileCollection files = project.files(classpath.toArray());
    setClasspath(files);
}
Also used : Project(org.gradle.api.Project) RuntimeClassLoaderFactory(io.crnk.gen.runtime.RuntimeClassLoaderFactory) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) URISyntaxException(java.net.URISyntaxException) File(java.io.File) HashSet(java.util.HashSet)

Example 3 with RuntimeClassLoaderFactory

use of io.crnk.gen.runtime.RuntimeClassLoaderFactory in project crnk-framework by crnk-project.

the class RuntimeClassoaderFactoryTest method setup.

@Before
public void setup() throws IOException {
    // Deltaspike sometimes really wants to have a retarded JNDI context
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, DummyInitialContextFactory.class.getName());
    testProjectDir.newFolder("src", "main", "java");
    File outputDir = testProjectDir.getRoot();
    Project project = ProjectBuilder.builder().withName("crnk-gen-typescript-test").withProjectDir(outputDir).build();
    project.setVersion("0.0.1");
    project.getPluginManager().apply("com.moowork.node");
    project.getPluginManager().apply(JavaPlugin.class);
    project.getPluginManager().apply(TSGeneratorPlugin.class);
    TSGeneratorExtension config = project.getExtensions().getByType(TSGeneratorExtension.class);
    config.getRuntime().setConfiguration("test");
    factory = new RuntimeClassLoaderFactory(project);
    ClassLoader parentClassLoader = getClass().getClassLoader();
    classLoader = factory.createClassLoader(parentClassLoader);
    sharedClassLoader = (RuntimeClassLoaderFactory.SharedClassLoader) classLoader.getParent();
}
Also used : Project(org.gradle.api.Project) RuntimeClassLoaderFactory(io.crnk.gen.runtime.RuntimeClassLoaderFactory) URLClassLoader(java.net.URLClassLoader) DummyInitialContextFactory(io.crnk.gen.typescript.runtime.DummyInitialContextFactory) File(java.io.File) Before(org.junit.Before)

Aggregations

RuntimeClassLoaderFactory (io.crnk.gen.runtime.RuntimeClassLoaderFactory)3 File (java.io.File)2 URLClassLoader (java.net.URLClassLoader)2 Project (org.gradle.api.Project)2 DummyInitialContextFactory (io.crnk.gen.typescript.runtime.DummyInitialContextFactory)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1 ConfigurableFileCollection (org.gradle.api.file.ConfigurableFileCollection)1 TaskAction (org.gradle.api.tasks.TaskAction)1 Before (org.junit.Before)1