Search in sources :

Example 6 with KryoBackedEncoder

use of org.gradle.internal.serialize.kryo.KryoBackedEncoder in project gradle by gradle.

the class DefaultScriptCompilationHandler method serializeMetadata.

private <M> void serializeMetadata(ScriptSource scriptSource, CompileOperation<M> extractingTransformer, File metadataDir, boolean emptyScript, boolean hasMethods) {
    File metadataFile = new File(metadataDir, METADATA_FILE_NAME);
    try {
        GFileUtils.mkdirs(metadataDir);
        try (KryoBackedEncoder encoder = new KryoBackedEncoder(new FileOutputStream(metadataFile))) {
            byte flags = (byte) ((emptyScript ? EMPTY_FLAG : 0) | (hasMethods ? HAS_METHODS_FLAG : 0));
            encoder.writeByte(flags);
            if (extractingTransformer != null && extractingTransformer.getDataSerializer() != null) {
                Serializer<M> serializer = extractingTransformer.getDataSerializer();
                serializer.write(encoder, extractingTransformer.getExtractedData());
            }
        }
    } catch (Exception e) {
        throw new GradleException(String.format("Failed to serialize script metadata extracted for %s", scriptSource.getDisplayName()), e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) GradleException(org.gradle.api.GradleException) KryoBackedEncoder(org.gradle.internal.serialize.kryo.KryoBackedEncoder) File(java.io.File) UncheckedException(org.gradle.internal.UncheckedException) MultipleCompilationErrorsException(org.codehaus.groovy.control.MultipleCompilationErrorsException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) GradleException(org.gradle.api.GradleException) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) ScriptCompilationException(org.gradle.groovy.scripts.ScriptCompilationException) SyntaxException(org.codehaus.groovy.syntax.SyntaxException)

Aggregations

KryoBackedEncoder (org.gradle.internal.serialize.kryo.KryoBackedEncoder)6 IOException (java.io.IOException)4 File (java.io.File)3 UncheckedIOException (org.gradle.api.UncheckedIOException)3 FlushableEncoder (org.gradle.internal.serialize.FlushableEncoder)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 DefaultModuleRegistry (org.gradle.api.internal.classpath.DefaultModuleRegistry)2 ModuleRegistry (org.gradle.api.internal.classpath.ModuleRegistry)2 ClassPath (org.gradle.internal.classpath.ClassPath)2 CurrentGradleInstallation (org.gradle.internal.installation.CurrentGradleInstallation)2 GradleInstallation (org.gradle.internal.installation.GradleInstallation)2 StreamByteBuffer (org.gradle.internal.io.StreamByteBuffer)2 GradleDaemon (org.gradle.launcher.daemon.bootstrap.GradleDaemon)2 FileOutputStream (java.io.FileOutputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)1 MultipleCompilationErrorsException (org.codehaus.groovy.control.MultipleCompilationErrorsException)1 SyntaxException (org.codehaus.groovy.syntax.SyntaxException)1