Search in sources :

Example 1 with KryoBackedDecoder

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

the class ModuleMetadataStore method getModuleDescriptor.

public MutableModuleComponentResolveMetadata getModuleDescriptor(ModuleComponentAtRepositoryKey component) {
    String filePath = getFilePath(component);
    final LocallyAvailableResource resource = metaDataStore.get(filePath);
    if (resource != null) {
        try {
            KryoBackedDecoder decoder = new KryoBackedDecoder(new FileInputStream(resource.getFile()));
            try {
                return moduleMetadataSerializer.read(decoder, moduleIdentifierFactory, moduleExclusions);
            } finally {
                decoder.close();
            }
        } catch (Exception e) {
            throw new RuntimeException("Could not load module metadata from " + resource.getDisplayName(), e);
        }
    }
    return null;
}
Also used : KryoBackedDecoder(org.gradle.internal.serialize.kryo.KryoBackedDecoder) LocallyAvailableResource(org.gradle.internal.resource.local.LocallyAvailableResource) FileInputStream(java.io.FileInputStream) UncheckedException(org.gradle.internal.UncheckedException)

Example 2 with KryoBackedDecoder

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

the class DefaultScriptCompilationHandler method loadFromDir.

@Override
public <T extends Script, M> CompiledScript<T, M> loadFromDir(ScriptSource source, HashCode sourceHashCode, ClassLoader classLoader, File scriptCacheDir, File metadataCacheDir, CompileOperation<M> transformer, Class<T> scriptBaseClass, ClassLoaderId classLoaderId) {
    File metadataFile = new File(metadataCacheDir, METADATA_FILE_NAME);
    try {
        KryoBackedDecoder decoder = new KryoBackedDecoder(new FileInputStream(metadataFile));
        try {
            byte flags = decoder.readByte();
            boolean isEmpty = (flags & EMPTY_FLAG) != 0;
            boolean hasMethods = (flags & HAS_METHODS_FLAG) != 0;
            if (isEmpty) {
                classLoaderCache.remove(classLoaderId);
            }
            M data;
            if (transformer != null && transformer.getDataSerializer() != null) {
                data = transformer.getDataSerializer().read(decoder);
            } else {
                data = null;
            }
            return new ClassesDirCompiledScript<T, M>(isEmpty, hasMethods, classLoaderId, scriptBaseClass, scriptCacheDir, classLoader, source, sourceHashCode, data);
        } finally {
            decoder.close();
        }
    } catch (Exception e) {
        throw new IllegalStateException(String.format("Failed to deserialize script metadata extracted for %s", source.getDisplayName()), e);
    }
}
Also used : KryoBackedDecoder(org.gradle.internal.serialize.kryo.KryoBackedDecoder) File(java.io.File) FileInputStream(java.io.FileInputStream) UncheckedException(org.gradle.internal.UncheckedException) MultipleCompilationErrorsException(org.codehaus.groovy.control.MultipleCompilationErrorsException) MalformedURLException(java.net.MalformedURLException) GradleException(org.gradle.api.GradleException) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) ScriptCompilationException(org.gradle.groovy.scripts.ScriptCompilationException) SyntaxException(org.codehaus.groovy.syntax.SyntaxException)

Example 3 with KryoBackedDecoder

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

the class TestResultSerializer method read.

public void read(Action<? super TestClassResult> visitor) {
    if (!isHasResults()) {
        return;
    }
    try {
        InputStream inputStream = new FileInputStream(resultsFile);
        try {
            Decoder decoder = new KryoBackedDecoder(inputStream);
            int version = decoder.readSmallInt();
            if (version != RESULT_VERSION) {
                throw new IllegalArgumentException(String.format("Unexpected result file version %d found in %s.", version, resultsFile));
            }
            readResults(decoder, visitor);
        } finally {
            inputStream.close();
        }
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : KryoBackedDecoder(org.gradle.internal.serialize.kryo.KryoBackedDecoder) Decoder(org.gradle.internal.serialize.Decoder) KryoBackedDecoder(org.gradle.internal.serialize.kryo.KryoBackedDecoder) UncheckedException(org.gradle.internal.UncheckedException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 4 with KryoBackedDecoder

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

the class DaemonMain method doAction.

@Override
protected void doAction(String[] args, ExecutionListener listener) {
    //The first argument is not really used but it is very useful in diagnosing, i.e. running 'jps -m'
    if (args.length != 1) {
        invalidArgs("Following arguments are required: <gradle-version>");
    }
    // Read configuration from stdin
    List<String> startupOpts;
    File gradleHomeDir;
    File daemonBaseDir;
    int idleTimeoutMs;
    int periodicCheckIntervalMs;
    String daemonUid;
    List<File> additionalClassPath;
    KryoBackedDecoder decoder = new KryoBackedDecoder(new EncodedStream.EncodedInput(System.in));
    try {
        gradleHomeDir = new File(decoder.readString());
        daemonBaseDir = new File(decoder.readString());
        idleTimeoutMs = decoder.readSmallInt();
        periodicCheckIntervalMs = decoder.readSmallInt();
        daemonUid = decoder.readString();
        int argCount = decoder.readSmallInt();
        startupOpts = new ArrayList<String>(argCount);
        for (int i = 0; i < argCount; i++) {
            startupOpts.add(decoder.readString());
        }
        int additionalClassPathLength = decoder.readSmallInt();
        additionalClassPath = new ArrayList<File>(additionalClassPathLength);
        for (int i = 0; i < additionalClassPathLength; i++) {
            additionalClassPath.add(new File(decoder.readString()));
        }
    } catch (EOFException e) {
        throw new UncheckedIOException(e);
    }
    NativeServices.initialize(gradleHomeDir);
    DaemonServerConfiguration parameters = new DefaultDaemonServerConfiguration(daemonUid, daemonBaseDir, idleTimeoutMs, periodicCheckIntervalMs, startupOpts);
    LoggingServiceRegistry loggingRegistry = LoggingServiceRegistry.newCommandLineProcessLogging();
    LoggingManagerInternal loggingManager = loggingRegistry.newInstance(LoggingManagerInternal.class);
    DaemonServices daemonServices = new DaemonServices(parameters, loggingRegistry, loggingManager, new DefaultClassPath(additionalClassPath));
    File daemonLog = daemonServices.getDaemonLogFile();
    // Any logging prior to this point will not end up in the daemon log file.
    initialiseLogging(loggingManager, daemonLog);
    // Detach the process from the parent terminal/console
    ProcessEnvironment processEnvironment = daemonServices.get(ProcessEnvironment.class);
    processEnvironment.maybeDetachProcess();
    LOGGER.debug("Assuming the daemon was started with following jvm opts: {}", startupOpts);
    Daemon daemon = daemonServices.get(Daemon.class);
    daemon.start();
    try {
        DaemonContext daemonContext = daemonServices.get(DaemonContext.class);
        Long pid = daemonContext.getPid();
        daemonStarted(pid, daemon.getUid(), daemon.getAddress(), daemonLog);
        DaemonExpirationStrategy expirationStrategy = daemonServices.get(MasterExpirationStrategy.class);
        daemon.stopOnExpiration(expirationStrategy, parameters.getPeriodicCheckIntervalMs());
    } finally {
        daemon.stop();
    }
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) DefaultDaemonServerConfiguration(org.gradle.launcher.daemon.configuration.DefaultDaemonServerConfiguration) EncodedStream(org.gradle.process.internal.streams.EncodedStream) UncheckedIOException(org.gradle.api.UncheckedIOException) ProcessEnvironment(org.gradle.internal.nativeintegration.ProcessEnvironment) EntryPoint(org.gradle.launcher.bootstrap.EntryPoint) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) KryoBackedDecoder(org.gradle.internal.serialize.kryo.KryoBackedDecoder) DaemonServerConfiguration(org.gradle.launcher.daemon.configuration.DaemonServerConfiguration) DefaultDaemonServerConfiguration(org.gradle.launcher.daemon.configuration.DefaultDaemonServerConfiguration) DaemonContext(org.gradle.launcher.daemon.context.DaemonContext) Daemon(org.gradle.launcher.daemon.server.Daemon) DaemonServices(org.gradle.launcher.daemon.server.DaemonServices) EOFException(java.io.EOFException) File(java.io.File) DaemonExpirationStrategy(org.gradle.launcher.daemon.server.expiry.DaemonExpirationStrategy) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath)

Aggregations

KryoBackedDecoder (org.gradle.internal.serialize.kryo.KryoBackedDecoder)4 UncheckedException (org.gradle.internal.UncheckedException)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 UncheckedIOException (org.gradle.api.UncheckedIOException)2 EOFException (java.io.EOFException)1 MalformedURLException (java.net.MalformedURLException)1 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)1 MultipleCompilationErrorsException (org.codehaus.groovy.control.MultipleCompilationErrorsException)1 SyntaxException (org.codehaus.groovy.syntax.SyntaxException)1 GradleException (org.gradle.api.GradleException)1 ScriptCompilationException (org.gradle.groovy.scripts.ScriptCompilationException)1 DefaultClassPath (org.gradle.internal.classpath.DefaultClassPath)1 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)1 LoggingServiceRegistry (org.gradle.internal.logging.services.LoggingServiceRegistry)1 ProcessEnvironment (org.gradle.internal.nativeintegration.ProcessEnvironment)1 LocallyAvailableResource (org.gradle.internal.resource.local.LocallyAvailableResource)1 Decoder (org.gradle.internal.serialize.Decoder)1 EntryPoint (org.gradle.launcher.bootstrap.EntryPoint)1 DaemonServerConfiguration (org.gradle.launcher.daemon.configuration.DaemonServerConfiguration)1