org.gradle.language.base.internal.compile.CompileSpec Java Examples

The following examples show how to use org.gradle.language.base.internal.compile.CompileSpec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InProcessCompilerDaemonFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CompilerDaemon getDaemon(File workingDir, final DaemonForkOptions forkOptions) {
    return new CompilerDaemon() {
        public <T extends CompileSpec> CompileResult execute(Compiler<T> compiler, T spec) {
            ClassLoader groovyClassLoader = classLoaderFactory.createIsolatedClassLoader(new DefaultClassPath(forkOptions.getClasspath()));
            FilteringClassLoader filteredGroovy = classLoaderFactory.createFilteringClassLoader(groovyClassLoader);
            for (String packageName : forkOptions.getSharedPackages()) {
                filteredGroovy.allowPackage(packageName);
            }

            ClassLoader workerClassLoader = new MutableURLClassLoader(filteredGroovy, ClasspathUtil.getClasspath(compiler.getClass().getClassLoader()));

            try {
                byte[] serializedWorker = GUtil.serialize(new Worker<T>(compiler, spec));
                ClassLoaderObjectInputStream inputStream = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedWorker), workerClassLoader);
                Callable<?> worker = (Callable<?>) inputStream.readObject();
                Object result = worker.call();
                byte[] serializedResult = GUtil.serialize(result);
                inputStream = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedResult), getClass().getClassLoader());
                return (CompileResult) inputStream.readObject();
            } catch (Exception e) {
                throw UncheckedException.throwAsUncheckedException(e);
            }
        }
    };
}
 
Example #2
Source File: InProcessCompilerDaemonFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CompilerDaemon getDaemon(File workingDir, final DaemonForkOptions forkOptions) {
    return new CompilerDaemon() {
        public <T extends CompileSpec> CompileResult execute(Compiler<T> compiler, T spec) {
            ClassLoader groovyClassLoader = classLoaderFactory.createIsolatedClassLoader(new DefaultClassPath(forkOptions.getClasspath()));
            FilteringClassLoader filteredGroovy = classLoaderFactory.createFilteringClassLoader(groovyClassLoader);
            for (String packageName : forkOptions.getSharedPackages()) {
                filteredGroovy.allowPackage(packageName);
            }

            ClassLoader workerClassLoader = new MutableURLClassLoader(filteredGroovy, ClasspathUtil.getClasspath(compiler.getClass().getClassLoader()));

            try {
                byte[] serializedWorker = GUtil.serialize(new Worker<T>(compiler, spec));
                ClassLoaderObjectInputStream inputStream = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedWorker), workerClassLoader);
                Callable<?> worker = (Callable<?>) inputStream.readObject();
                Object result = worker.call();
                byte[] serializedResult = GUtil.serialize(result);
                inputStream = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedResult), getClass().getClassLoader());
                return (CompileResult) inputStream.readObject();
            } catch (Exception e) {
                throw UncheckedException.throwAsUncheckedException(e);
            }
        }
    };
}
 
Example #3
Source File: GccPlatformToolProvider.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends CompileSpec> Compiler<T> newCompiler(T spec) {
    if (spec instanceof CppCompileSpec) {
        return castCompiler(createCppCompiler());
    }
    if (spec instanceof CCompileSpec) {
        return castCompiler(createCCompiler());
    }
    if (spec instanceof ObjectiveCppCompileSpec) {
        return castCompiler(createObjectiveCppCompiler());
    }
    if (spec instanceof ObjectiveCCompileSpec) {
        return castCompiler(createObjectiveCCompiler());
    }
    if (spec instanceof WindowsResourceCompileSpec) {
        throw new RuntimeException("Windows resource compiler is not available");
    }
    if (spec instanceof AssembleSpec) {
        return castCompiler(createAssembler());
    }
    if (spec instanceof LinkerSpec) {
        return castCompiler(createLinker());
    }
    if (spec instanceof StaticLibraryArchiverSpec) {
        return castCompiler(createStaticLibraryArchiver());
    }
    throw new IllegalArgumentException(String.format("Don't know how to compile from a spec of type %s.", spec.getClass().getSimpleName()));
}
 
Example #4
Source File: ErrorProneToolChain.java    From gradle-errorprone-plugin-v0.0.x with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends CompileSpec> Compiler<T> newCompiler(Class<T> spec) {
  if (JavaCompileSpec.class.isAssignableFrom(spec)) {
    return (Compiler<T>) new NormalizingJavaCompiler(new ErrorProneCompiler(configuration));
  }
  throw new IllegalArgumentException(
      String.format("Don't know how to compile using spec of type %s.", spec.getSimpleName()));
}
 
Example #5
Source File: CompilerDaemonClient.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends CompileSpec> CompileResult execute(Compiler<T> compiler, T spec) {
    // currently we just allow a single compilation thread at a time (per compiler daemon)
    // one problem to solve when allowing multiple threads is how to deal with memory requirements specified by compile tasks
    try {
        server.execute(compiler, spec);
        return compileResults.take();
    } catch (InterruptedException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #6
Source File: CompilerDaemonServer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends CompileSpec> void execute(Compiler<T> compiler, T spec) {
    try {
        LOGGER.info("Executing {} in compiler daemon.", compiler);
        WorkResult result = compiler.execute(spec);
        LOGGER.info("Successfully executed {} in compiler daemon.", compiler);
        client.executed(new CompileResult(result.getDidWork(), null));
    } catch (Throwable t) {
        LOGGER.info("Exception executing {} in compiler daemon: {}.", compiler, t);
        client.executed(new CompileResult(true, t));
    }
}
 
Example #7
Source File: CompilerDaemonManager.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CompilerDaemon getDaemon(final File workingDir, final DaemonForkOptions forkOptions) {
    return new CompilerDaemon() {
        public <T extends CompileSpec> CompileResult execute(org.gradle.language.base.internal.compile.Compiler<T> compiler, T spec) {
            CompilerDaemonClient client = clientsManager.reserveIdleClient(forkOptions);
            if (client == null) {
                client = clientsManager.reserveNewClient(workingDir, forkOptions);
            }
            try {
                return client.execute(compiler, spec);
            } finally {
                clientsManager.release(client);
            }
        }
    };
}
 
Example #8
Source File: VisualCppToolChain.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends CompileSpec> Compiler<T> newCompiler(T spec) {
    if (spec instanceof CppCompileSpec) {
        return castCompiler(createCppCompiler());
    }
    if (spec instanceof CCompileSpec) {
        return castCompiler(createCCompiler());
    }
    if (spec instanceof ObjectiveCppCompileSpec) {
        throw new RuntimeException("Objective-C++ is not available on the Visual C++ toolchain");
    }
    if (spec instanceof ObjectiveCCompileSpec) {
        throw new RuntimeException("Objective-C is not available on the Visual C++ toolchain");
    }
    if (spec instanceof WindowsResourceCompileSpec) {
        return castCompiler(createWindowsResourceCompiler());
    }
    if (spec instanceof AssembleSpec) {
        return castCompiler(createAssembler());
    }
    if (spec instanceof LinkerSpec) {
        return castCompiler(createLinker());
    }
    if (spec instanceof StaticLibraryArchiverSpec) {
        return castCompiler(createStaticLibraryArchiver());
    }
    throw new IllegalArgumentException(String.format("Don't know how to compile from a spec of type %s.", spec.getClass().getSimpleName()));
}
 
Example #9
Source File: GccPlatformToolProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends CompileSpec> Compiler<T> newCompiler(T spec) {
    if (spec instanceof CppCompileSpec) {
        return castCompiler(createCppCompiler());
    }
    if (spec instanceof CCompileSpec) {
        return castCompiler(createCCompiler());
    }
    if (spec instanceof ObjectiveCppCompileSpec) {
        return castCompiler(createObjectiveCppCompiler());
    }
    if (spec instanceof ObjectiveCCompileSpec) {
        return castCompiler(createObjectiveCCompiler());
    }
    if (spec instanceof WindowsResourceCompileSpec) {
        throw new RuntimeException("Windows resource compiler is not available");
    }
    if (spec instanceof AssembleSpec) {
        return castCompiler(createAssembler());
    }
    if (spec instanceof LinkerSpec) {
        return castCompiler(createLinker());
    }
    if (spec instanceof StaticLibraryArchiverSpec) {
        return castCompiler(createStaticLibraryArchiver());
    }
    throw new IllegalArgumentException(String.format("Don't know how to compile from a spec of type %s.", spec.getClass().getSimpleName()));
}
 
Example #10
Source File: CompilerDaemonClient.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends CompileSpec> CompileResult execute(Compiler<T> compiler, T spec) {
    // currently we just allow a single compilation thread at a time (per compiler daemon)
    // one problem to solve when allowing multiple threads is how to deal with memory requirements specified by compile tasks
    try {
        server.execute(compiler, spec);
        return compileResults.take();
    } catch (InterruptedException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #11
Source File: CompilerDaemonServer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends CompileSpec> void execute(Compiler<T> compiler, T spec) {
    try {
        LOGGER.info("Executing {} in compiler daemon.", compiler);
        WorkResult result = compiler.execute(spec);
        LOGGER.info("Successfully executed {} in compiler daemon.", compiler);
        client.executed(new CompileResult(result.getDidWork(), null));
    } catch (Throwable t) {
        LOGGER.info("Exception executing {} in compiler daemon: {}.", compiler, t);
        client.executed(new CompileResult(true, t));
    }
}
 
Example #12
Source File: VisualCppToolChain.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends CompileSpec> Compiler<T> newCompiler(T spec) {
    if (spec instanceof CppCompileSpec) {
        return castCompiler(createCppCompiler());
    }
    if (spec instanceof CCompileSpec) {
        return castCompiler(createCCompiler());
    }
    if (spec instanceof ObjectiveCppCompileSpec) {
        throw new RuntimeException("Objective-C++ is not available on the Visual C++ toolchain");
    }
    if (spec instanceof ObjectiveCCompileSpec) {
        throw new RuntimeException("Objective-C is not available on the Visual C++ toolchain");
    }
    if (spec instanceof WindowsResourceCompileSpec) {
        return castCompiler(createWindowsResourceCompiler());
    }
    if (spec instanceof AssembleSpec) {
        return castCompiler(createAssembler());
    }
    if (spec instanceof LinkerSpec) {
        return castCompiler(createLinker());
    }
    if (spec instanceof StaticLibraryArchiverSpec) {
        return castCompiler(createStaticLibraryArchiver());
    }
    throw new IllegalArgumentException(String.format("Don't know how to compile from a spec of type %s.", spec.getClass().getSimpleName()));
}
 
Example #13
Source File: CompilerDaemonManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CompilerDaemon getDaemon(final File workingDir, final DaemonForkOptions forkOptions) {
    return new CompilerDaemon() {
        public <T extends CompileSpec> CompileResult execute(org.gradle.language.base.internal.compile.Compiler<T> compiler, T spec) {
            CompilerDaemonClient client = clientsManager.reserveIdleClient(forkOptions);
            if (client == null) {
                client = clientsManager.reserveNewClient(workingDir, forkOptions);
            }
            try {
                return client.execute(compiler, spec);
            } finally {
                clientsManager.release(client);
            }
        }
    };
}
 
Example #14
Source File: UnavailablePlatformToolProvider.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public <T extends CompileSpec> Compiler<T> newCompiler(T spec) {
    throw failure();
}
 
Example #15
Source File: ErrorProneToolChain.java    From gradle-errorprone-plugin-v0.0.x with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends CompileSpec> Compiler<T> newCompiler(Class<T> spec) {
  throw new IllegalArgumentException(getMessage());
}
 
Example #16
Source File: DefaultJavaToolChain.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public <T extends CompileSpec> Compiler<T> newCompiler(T spec) {
    throw new IllegalArgumentException(getMessage());
}
 
Example #17
Source File: GccPlatformToolProvider.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends CompileSpec> Compiler<T> castCompiler(Compiler<?> compiler) {
    return (Compiler<T>) compiler;
}
 
Example #18
Source File: VisualCppToolChain.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends CompileSpec> Compiler<T> castCompiler(Compiler<?> compiler) {
    return (Compiler<T>) compiler;
}
 
Example #19
Source File: UnavailablePlatformToolProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public <T extends CompileSpec> Compiler<T> newCompiler(T spec) {
    throw failure();
}
 
Example #20
Source File: VisualCppToolChain.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends CompileSpec> Compiler<T> castCompiler(Compiler<?> compiler) {
    return (Compiler<T>) compiler;
}
 
Example #21
Source File: GccPlatformToolProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends CompileSpec> Compiler<T> castCompiler(Compiler<?> compiler) {
    return (Compiler<T>) compiler;
}
 
Example #22
Source File: DefaultJavaToolChain.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public <T extends CompileSpec> Compiler<T> newCompiler(T spec) {
    throw new IllegalArgumentException(getMessage());
}
 
Example #23
Source File: CompilerDaemon.java    From pushfish-android with BSD 2-Clause "Simplified" License votes vote down vote up
<T extends CompileSpec> CompileResult execute(Compiler<T> compiler, T spec); 
Example #24
Source File: CompilerDaemon.java    From Pushjet-Android with BSD 2-Clause "Simplified" License votes vote down vote up
<T extends CompileSpec> CompileResult execute(Compiler<T> compiler, T spec); 
Example #25
Source File: ToolProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License votes vote down vote up
<T extends CompileSpec> Compiler<T> newCompiler(T spec); 
Example #26
Source File: CompilerDaemonServerProtocol.java    From Pushjet-Android with BSD 2-Clause "Simplified" License votes vote down vote up
<T extends CompileSpec> void execute(Compiler<T> compiler, T spec); 
Example #27
Source File: ToolProvider.java    From pushfish-android with BSD 2-Clause "Simplified" License votes vote down vote up
<T extends CompileSpec> Compiler<T> newCompiler(T spec); 
Example #28
Source File: CompilerDaemonServerProtocol.java    From pushfish-android with BSD 2-Clause "Simplified" License votes vote down vote up
<T extends CompileSpec> void execute(Compiler<T> compiler, T spec);