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);
}
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);
}
});
}
}
});
}
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;
});
}
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;
}
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;
}
Aggregations