Search in sources :

Example 11 with BuildOperationContext

use of org.gradle.internal.operations.BuildOperationContext in project gradle by gradle.

the class Binary2JUnitXmlReportGenerator method generate.

public void generate() {
    Timer clock = Time.startTimer();
    buildOperationExecutor.run(new RunnableBuildOperation() {

        @Override
        public void run(BuildOperationContext context) {
            File[] oldXmlFiles = testResultsDir.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    return name.startsWith("TEST") && name.endsWith(".xml");
                }
            });
            for (File oldXmlFile : oldXmlFiles) {
                GFileUtils.deleteQuietly(oldXmlFile);
            }
        }

        @Override
        public BuildOperationDescriptor.Builder description() {
            return BuildOperationDescriptor.displayName("Delete old JUnit XML results");
        }
    });
    buildOperationExecutor.runAll(new Action<BuildOperationQueue<JUnitXmlReportFileGenerator>>() {

        @Override
        public void execute(final BuildOperationQueue<JUnitXmlReportFileGenerator> queue) {
            testResultsProvider.visitClasses(new Action<TestClassResult>() {

                @Override
                public void execute(final TestClassResult result) {
                    final File reportFile = new File(testResultsDir, getReportFileName(result));
                    queue.add(new JUnitXmlReportFileGenerator(result, reportFile, xmlWriter));
                }
            });
        }
    });
    LOG.info("Finished generating test XML results ({}) into: {}", clock.getElapsed(), testResultsDir);
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) Action(org.gradle.api.Action) BuildOperationQueue(org.gradle.internal.operations.BuildOperationQueue) FilenameFilter(java.io.FilenameFilter) Timer(org.gradle.internal.time.Timer) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation) File(java.io.File)

Example 12 with BuildOperationContext

use of org.gradle.internal.operations.BuildOperationContext in project gradle by gradle.

the class ChecksumAndSignatureVerificationOverride method verifyConcurrently.

private void verifyConcurrently() {
    hasFatalFailure.set(false);
    synchronized (verificationEvents) {
        if (verificationEvents.isEmpty()) {
            return;
        }
    }
    if (closed.get()) {
        LOGGER.debug("Cannot perform verification of all dependencies because the verification service has been shutdown. Under normal circumstances this shouldn't happen unless a user buildFinished was added in an unexpected way.");
        return;
    }
    buildOperationExecutor.runAll(queue -> {
        VerificationEvent event;
        synchronized (verificationEvents) {
            while ((event = verificationEvents.poll()) != null) {
                VerificationEvent ve = event;
                queue.add(new RunnableBuildOperation() {

                    @Override
                    public void run(BuildOperationContext context) {
                        verifier.verify(checksumService, signatureVerificationService, ve.kind, ve.artifact, ve.mainFile, ve.signatureFile.create(), f -> {
                            synchronized (failures) {
                                failures.put(ve.artifact, new RepositoryAwareVerificationFailure(f, ve.repositoryName));
                            }
                            if (f.isFatal()) {
                                hasFatalFailure.set(true);
                            }
                        });
                    }

                    @Override
                    public BuildOperationDescriptor.Builder description() {
                        return BuildOperationDescriptor.displayName("Dependency verification").progressDisplayName("Verifying " + ve.artifact);
                    }
                });
            }
        }
    });
}
Also used : ConsoleRenderer(org.gradle.internal.logging.ConsoleRenderer) DependencyVerifyingModuleComponentRepository(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.DependencyVerifyingModuleComponentRepository) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Multimap(com.google.common.collect.Multimap) Deque(java.util.Deque) ChecksumService(org.gradle.internal.hash.ChecksumService) Logger(org.gradle.api.logging.Logger) DependencyVerificationReportWriter(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.report.DependencyVerificationReportWriter) VerificationReport(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.report.VerificationReport) UncheckedException(org.gradle.internal.UncheckedException) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation) ModuleComponentRepository(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ModuleComponentRepository) ResolvedVariantResult(org.gradle.api.artifacts.result.ResolvedVariantResult) DependencyVerificationException(org.gradle.api.internal.artifacts.verification.DependencyVerificationException) BuildTreeDefinedKeys(org.gradle.api.internal.artifacts.verification.signatures.BuildTreeDefinedKeys) URI(java.net.URI) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) Artifact(org.gradle.api.component.Artifact) SignatureVerificationService(org.gradle.api.internal.artifacts.verification.signatures.SignatureVerificationService) DependencyVerificationsXmlReader(org.gradle.api.internal.artifacts.verification.serializer.DependencyVerificationsXmlReader) Collection(java.util.Collection) SignatureVerificationServiceFactory(org.gradle.api.internal.artifacts.verification.signatures.SignatureVerificationServiceFactory) DependencyVerifier(org.gradle.api.internal.artifacts.verification.verifier.DependencyVerifier) Set(java.util.Set) FileInputStream(java.io.FileInputStream) ComponentArtifactIdentifier(org.gradle.api.artifacts.component.ComponentArtifactIdentifier) DocumentationRegistry(org.gradle.api.internal.DocumentationRegistry) BuildOperationDescriptor(org.gradle.internal.operations.BuildOperationDescriptor) Sets(com.google.common.collect.Sets) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) ResolutionStrategyInternal(org.gradle.api.internal.artifacts.configurations.ResolutionStrategyInternal) Queues(com.google.common.collect.Queues) List(java.util.List) Stoppable(org.gradle.internal.concurrent.Stoppable) BuildOperationExecutor(org.gradle.internal.operations.BuildOperationExecutor) Logging(org.gradle.api.logging.Logging) Factory(org.gradle.internal.Factory) ModuleComponentArtifactIdentifier(org.gradle.internal.component.external.model.ModuleComponentArtifactIdentifier) BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) GradleProperties(org.gradle.api.internal.properties.GradleProperties) ResolvedArtifactResult(org.gradle.api.artifacts.result.ResolvedArtifactResult) DependencyVerificationMode(org.gradle.api.artifacts.verification.DependencyVerificationMode) BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation)

Example 13 with BuildOperationContext

use of org.gradle.internal.operations.BuildOperationContext in project gradle by gradle.

the class CrossBuildCachingKeyService method findByLongId.

@Override
public void findByLongId(long keyId, PublicKeyResultBuilder builder) {
    longIdGuard.guardByKey(keyId, () -> {
        CacheEntry<List<Fingerprint>> fingerprints = longIdToFingerprint.getIfPresent(keyId);
        if (fingerprints == null || hasExpired(fingerprints)) {
            buildOperationExecutor.run(new RunnableBuildOperation() {

                @Override
                public void run(BuildOperationContext context) {
                    long currentTime = timeProvider.getCurrentTime();
                    AtomicBoolean missing = new AtomicBoolean(true);
                    delegate.findByLongId(keyId, new PublicKeyResultBuilder() {

                        @Override
                        public void keyRing(PGPPublicKeyRing keyring) {
                            missing.set(false);
                            builder.keyRing(keyring);
                            Iterator<PGPPublicKey> pkIt = keyring.getPublicKeys();
                            while (pkIt.hasNext()) {
                                PGPPublicKey publicKey = pkIt.next();
                                Fingerprint fingerprint = Fingerprint.of(publicKey);
                                publicKeyRings.put(fingerprint, new CacheEntry<>(currentTime, keyring));
                                updateLongKeyIndex(fingerprint, keyId);
                            }
                        }

                        @Override
                        public void publicKey(PGPPublicKey publicKey) {
                            missing.set(false);
                            if (publicKey.getKeyID() == keyId) {
                                builder.publicKey(publicKey);
                            }
                        }
                    });
                    if (missing.get()) {
                        longIdToFingerprint.put(keyId, new CacheEntry<>(currentTime, null));
                    }
                }

                @Override
                public BuildOperationDescriptor.Builder description() {
                    return BuildOperationDescriptor.displayName("Fetching public key").progressDisplayName("Downloading public key " + toLongIdHexString(keyId));
                }
            });
        } else {
            if (fingerprints.value != null) {
                for (Fingerprint fingerprint : fingerprints.value) {
                    findByFingerprint(fingerprint.getBytes(), new PublicKeyResultBuilder() {

                        @Override
                        public void keyRing(PGPPublicKeyRing keyring) {
                            builder.keyRing(keyring);
                        }

                        @Override
                        public void publicKey(PGPPublicKey publicKey) {
                            if (publicKey.getKeyID() == keyId) {
                                builder.publicKey(publicKey);
                            }
                        }
                    });
                }
            }
        }
        return null;
    });
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) Fingerprint(org.gradle.security.internal.Fingerprint) PublicKeyResultBuilder(org.gradle.security.internal.PublicKeyResultBuilder) LockOptionsBuilder(org.gradle.cache.internal.filelock.LockOptionsBuilder) CacheBuilder(org.gradle.cache.CacheBuilder) PublicKeyResultBuilder(org.gradle.security.internal.PublicKeyResultBuilder) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation)

Example 14 with BuildOperationContext

use of org.gradle.internal.operations.BuildOperationContext in project gradle by gradle.

the class RuntimeShadedJarFactory method get.

public File get(final RuntimeShadedJarType type, final Collection<? extends File> classpath) {
    final File jarFile = cache.get(type.getIdentifier(), file -> executor.run(new RunnableBuildOperation() {

        @Override
        public void run(BuildOperationContext context) {
            RuntimeShadedJarCreator creator = new RuntimeShadedJarCreator(progressLoggerFactory, new ImplementationDependencyRelocator(type), classpathWalker, classpathBuilder);
            creator.create(file, classpath);
        }

        @Override
        public BuildOperationDescriptor.Builder description() {
            return BuildOperationDescriptor.displayName("Generate " + file).progressDisplayName("Generating " + file.getName());
        }
    }));
    LOGGER.debug("Using Gradle runtime shaded JAR file: {}", jarFile);
    return jarFile;
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) BuildOperationDescriptor(org.gradle.internal.operations.BuildOperationDescriptor) File(java.io.File) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation)

Example 15 with BuildOperationContext

use of org.gradle.internal.operations.BuildOperationContext in project gradle by gradle.

the class WatchingVirtualFileSystem method afterBuildStarted.

@Override
public boolean afterBuildStarted(WatchMode watchMode, VfsLogging vfsLogging, WatchLogging watchLogging, BuildOperationRunner buildOperationRunner) {
    warningLogger = watchMode.loggerForWarnings(LOGGER);
    stateInvalidatedAtStartOfBuild = false;
    reasonForNotWatchingFiles = null;
    rootReference.update(currentRoot -> buildOperationRunner.call(new CallableBuildOperation<SnapshotHierarchy>() {

        @Override
        public SnapshotHierarchy call(BuildOperationContext context) {
            if (watchMode.isEnabled()) {
                SnapshotHierarchy newRoot;
                boolean couldDetectUnsupportedFileSystems;
                try {
                    unsupportedFileSystems.clear();
                    if (watchMode == WatchMode.DEFAULT) {
                        watchableFileSystemDetector.detectUnsupportedFileSystems().forEach(unsupportedFileSystems::add);
                    }
                    couldDetectUnsupportedFileSystems = true;
                } catch (NativeException e) {
                    couldDetectUnsupportedFileSystems = false;
                    LOGGER.info("Unable to list file systems to check whether they can be watched. Disabling watching. Reason: {}", e.getMessage());
                }
                FileSystemWatchingStatistics statisticsSinceLastBuild;
                if (watchRegistry == null) {
                    if (couldDetectUnsupportedFileSystems) {
                        context.setStatus("Starting file system watching");
                        newRoot = startWatching(currentRoot, watchMode, unsupportedFileSystems);
                    } else {
                        newRoot = currentRoot.empty();
                    }
                    statisticsSinceLastBuild = null;
                } else {
                    FileWatcherRegistry.FileWatchingStatistics statistics = watchRegistry.getAndResetStatistics();
                    if (hasDroppedStateBecauseOfErrorsReceivedWhileWatching(statistics) || !couldDetectUnsupportedFileSystems) {
                        newRoot = stopWatchingAndInvalidateHierarchyAfterError(currentRoot);
                    } else {
                        newRoot = watchRegistry.updateVfsOnBuildStarted(currentRoot, watchMode, unsupportedFileSystems);
                    }
                    stateInvalidatedAtStartOfBuild = newRoot != currentRoot;
                    statisticsSinceLastBuild = new DefaultFileSystemWatchingStatistics(statistics, newRoot);
                    if (vfsLogging == VfsLogging.VERBOSE) {
                        LOGGER.warn("Received {} file system events since last build while watching {} locations", statisticsSinceLastBuild.getNumberOfReceivedEvents(), statisticsSinceLastBuild.getNumberOfWatchedHierarchies());
                        LOGGER.warn("Virtual file system retained information about {} files, {} directories and {} missing files since last build", statisticsSinceLastBuild.getRetainedRegularFiles(), statisticsSinceLastBuild.getRetainedDirectories(), statisticsSinceLastBuild.getRetainedMissingFiles());
                        if (stateInvalidatedAtStartOfBuild) {
                            LOGGER.warn("Parts of the virtual file system have been invalidated since they didn't support watching");
                        }
                    }
                }
                if (watchRegistry != null) {
                    watchRegistry.setDebugLoggingEnabled(watchLogging == WatchLogging.DEBUG);
                }
                context.setResult(new BuildStartedFileSystemWatchingBuildOperationType.Result() {

                    @Override
                    public boolean isWatchingEnabled() {
                        return true;
                    }

                    @Override
                    public boolean isStartedWatching() {
                        return statisticsSinceLastBuild == null;
                    }

                    @Override
                    public FileSystemWatchingStatistics getStatistics() {
                        return statisticsSinceLastBuild;
                    }
                });
                return newRoot;
            } else {
                context.setResult(BuildStartedFileSystemWatchingBuildOperationType.Result.WATCHING_DISABLED);
                return stopWatchingAndInvalidateHierarchy(currentRoot);
            }
        }

        @Override
        public BuildOperationDescriptor.Builder description() {
            return BuildOperationDescriptor.displayName(BuildStartedFileSystemWatchingBuildOperationType.DISPLAY_NAME).details(BuildStartedFileSystemWatchingBuildOperationType.Details.INSTANCE);
        }
    }));
    return watchRegistry != null;
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) FileSystemWatchingStatistics(org.gradle.internal.watch.vfs.FileSystemWatchingStatistics) BuildOperationDescriptor(org.gradle.internal.operations.BuildOperationDescriptor) BuildStartedFileSystemWatchingBuildOperationType(org.gradle.internal.watch.vfs.BuildStartedFileSystemWatchingBuildOperationType) SnapshotHierarchy(org.gradle.internal.snapshot.SnapshotHierarchy) CallableBuildOperation(org.gradle.internal.operations.CallableBuildOperation) FileWatcherRegistry(org.gradle.internal.watch.registry.FileWatcherRegistry) NativeException(net.rubygrapefruit.platform.NativeException)

Aggregations

BuildOperationContext (org.gradle.internal.operations.BuildOperationContext)20 RunnableBuildOperation (org.gradle.internal.operations.RunnableBuildOperation)12 File (java.io.File)8 BuildOperationDescriptor (org.gradle.internal.operations.BuildOperationDescriptor)5 Action (org.gradle.api.Action)3 BuildOperationExecutor (org.gradle.internal.operations.BuildOperationExecutor)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 FileCollection (org.gradle.api.file.FileCollection)2 BuildOperationDetails (org.gradle.internal.progress.BuildOperationDetails)2 ImmutableList (com.google.common.collect.ImmutableList)1 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 Multimap (com.google.common.collect.Multimap)1 Queues (com.google.common.collect.Queues)1 Sets (com.google.common.collect.Sets)1 Closure (groovy.lang.Closure)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1