Java Code Examples for org.gradle.util.GUtil#serialize()

The following examples show how to use org.gradle.util.GUtil#serialize() . 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 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 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: 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 4
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 5
Source File: DefaultWorkerProcessFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void attachStdInContent(WorkerFactory workerFactory, JavaExecHandleBuilder javaCommand) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    OutputStream encoded = new EncodedStream.EncodedOutput(bytes);
    GUtil.serialize(workerFactory.create(), encoded);
    ByteArrayInputStream stdinContent = new ByteArrayInputStream(bytes.toByteArray());
    javaCommand.setStandardInput(stdinContent);
}
 
Example 6
Source File: ApplicationClassesInSystemClassLoaderWorkerFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Callable<?> create() {
    // Serialize the bootstrap worker, so it can be transported through the system ClassLoader
    ActionExecutionWorker injectedWorker = new ActionExecutionWorker(processBuilder.getWorker(), workerId, displayName, serverAddress);
    ImplementationClassLoaderWorker worker = new ImplementationClassLoaderWorker(processBuilder.getLogLevel(), processBuilder.getSharedPackages(),
            implementationClassPath, injectedWorker);
    byte[] serializedWorker = GUtil.serialize(worker);

    return new BootstrapClassLoaderWorker(classPathRegistry.getClassPath("WORKER_PROCESS").getAsURLs(), serializedWorker);
}
 
Example 7
Source File: DefaultWorkerProcessFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void attachStdInContent(WorkerFactory workerFactory, JavaExecHandleBuilder javaCommand) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    OutputStream encoded = new EncodedStream.EncodedOutput(bytes);
    GUtil.serialize(workerFactory.create(), encoded);
    ByteArrayInputStream stdinContent = new ByteArrayInputStream(bytes.toByteArray());
    javaCommand.setStandardInput(stdinContent);
}
 
Example 8
Source File: ApplicationClassesInSystemClassLoaderWorkerFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Callable<?> create() {
    // Serialize the bootstrap worker, so it can be transported through the system ClassLoader
    ActionExecutionWorker injectedWorker = new ActionExecutionWorker(processBuilder.getWorker(), workerId, displayName, serverAddress);
    ImplementationClassLoaderWorker worker = new ImplementationClassLoaderWorker(processBuilder.getLogLevel(), processBuilder.getSharedPackages(),
            implementationClassPath, injectedWorker);
    byte[] serializedWorker = GUtil.serialize(worker);

    return new BootstrapClassLoaderWorker(classPathRegistry.getClassPath("WORKER_PROCESS").getAsURLs(), serializedWorker);
}
 
Example 9
Source File: DefaultWorkerProcessFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void attachStdInContent(WorkerFactory workerFactory, JavaExecHandleBuilder javaCommand) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    OutputStream encoded = new EncodedStream.EncodedOutput(bytes);
    GUtil.serialize(workerFactory.create(), encoded);
    ByteArrayInputStream stdinContent = new ByteArrayInputStream(bytes.toByteArray());
    javaCommand.setStandardInput(stdinContent);
}
 
Example 10
Source File: ApplicationClassesInSystemClassLoaderWorkerFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Callable<?> create() {
    // Serialize the bootstrap worker, so it can be transported through the system ClassLoader
    ActionExecutionWorker injectedWorker = new ActionExecutionWorker(processBuilder.getWorker(), workerId, displayName, serverAddress);
    ImplementationClassLoaderWorker worker = new ImplementationClassLoaderWorker(processBuilder.getLogLevel(), processBuilder.getSharedPackages(),
            implementationClassPath, injectedWorker);
    byte[] serializedWorker = GUtil.serialize(worker);

    return new BootstrapClassLoaderWorker(classPathRegistry.getClassPath("WORKER_PROCESS").getAsURLs(), serializedWorker);
}
 
Example 11
Source File: DefaultWorkerProcessFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void attachStdInContent(WorkerFactory workerFactory, JavaExecHandleBuilder javaCommand) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    OutputStream encoded = new EncodedStream.EncodedOutput(bytes);
    GUtil.serialize(workerFactory.create(), encoded);
    ByteArrayInputStream stdinContent = new ByteArrayInputStream(bytes.toByteArray());
    javaCommand.setStandardInput(stdinContent);
}
 
Example 12
Source File: ApplicationClassesInSystemClassLoaderWorkerFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Callable<?> create() {
    // Serialize the bootstrap worker, so it can be transported through the system ClassLoader
    ActionExecutionWorker injectedWorker = new ActionExecutionWorker(processBuilder.getWorker(), workerId, displayName, serverAddress);
    ImplementationClassLoaderWorker worker = new ImplementationClassLoaderWorker(processBuilder.getLogLevel(), processBuilder.getSharedPackages(),
            implementationClassPath, injectedWorker);
    byte[] serializedWorker = GUtil.serialize(worker);

    return new BootstrapClassLoaderWorker(classPathRegistry.getClassPath("WORKER_PROCESS").getAsURLs(), serializedWorker);
}