Skip to content

Commit

Permalink
Annotate build session services (gradle#31934)
Browse files Browse the repository at this point in the history
  • Loading branch information
alllex authored Jan 7, 2025
2 parents 794be55 + 39c6c3b commit 4737d64
Show file tree
Hide file tree
Showing 48 changed files with 151 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.gradle.execution.ExecutionAccessChecker
import org.gradle.execution.ExecutionAccessListener
import org.gradle.internal.buildoption.InternalOptions
import org.gradle.internal.buildtree.BuildModelParameters
import org.gradle.internal.buildtree.BuildTreeModelControllerServices
import org.gradle.internal.cc.impl.initialization.ConfigurationCacheStartParameter
import org.gradle.internal.cc.impl.problems.BuildNameProvider
import org.gradle.internal.cc.impl.services.DefaultIsolatedProjectEvaluationListenerProvider
Expand All @@ -52,7 +53,7 @@ class ConfigurationCacheServices : AbstractGradleModuleServices() {

override fun registerBuildSessionServices(registration: ServiceRegistration) {
registration.run {
add(DefaultBuildTreeModelControllerServices::class.java)
add(BuildTreeModelControllerServices::class.java, DefaultBuildTreeModelControllerServices::class.java)
add(ConfigurationCacheRepository::class.java)
add(ConfigurationCacheEntryCollector::class.java)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package org.gradle.api.internal.file.archive;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import java.io.Closeable;
import java.io.File;

Expand All @@ -35,6 +38,7 @@
* There currently are no checks on modifications to files in the expanded directory. This can cause problems if the expanded directory is used
* by multiple tasks and each task expects different modifications to be made to the extracted files.
*/
@ServiceScope(Scope.BuildSession.class)
public interface DecompressionCoordinator extends Closeable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package org.gradle.internal.snapshot.impl;

import org.gradle.internal.serialize.SerializerRegistry;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

@ServiceScope(Scope.BuildSession.class)
public interface ValueSnapshotterSerializerRegistry extends SerializerRegistry {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package org.gradle.internal.execution;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

@ServiceScope(Scope.BuildSession.class)
public interface FileCollectionFingerprinterRegistry {
FileCollectionFingerprinter getFingerprinter(FileNormalizationSpec spec);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
package org.gradle.internal.execution;

import com.google.common.collect.ImmutableSortedMap;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.internal.snapshot.FileSystemSnapshot;

import java.io.File;

@ServiceScope(Scope.BuildSession.class)
public interface OutputSnapshotter {
/**
* Takes a snapshot of the outputs of a work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

package org.gradle.process.internal.worker.child;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import java.io.File;

@ServiceScope(Scope.BuildSession.class)
public interface WorkerDirectoryProvider {
/**
* Returns a File object representing the working directory for workers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@

import org.gradle.internal.Factory;
import org.gradle.internal.concurrent.Stoppable;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.internal.work.ConditionalExecutionQueue;
import org.gradle.internal.work.ConditionalExecutionQueueFactory;

import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;

@ThreadSafe
@ServiceScope(Scope.BuildSession.class)
public class WorkerExecutionQueueFactory implements Factory<ConditionalExecutionQueue<DefaultWorkResult>>, Stoppable {
public static final String QUEUE_DISPLAY_NAME = "WorkerExecutor Queue";
private final ConditionalExecutionQueueFactory conditionalExecutionQueueFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

package org.gradle.internal.work;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

/**
* Provides new {@link ConditionalExecutionQueue} objects
*/
@ServiceScope(Scope.BuildSession.class)
public interface ConditionalExecutionQueueFactory {
/**
* Provides a {@link ConditionalExecutionQueue} that can process {@link ConditionalExecution} objects that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,20 @@ public class BuildSessionState implements Closeable {
private final ServiceRegistry sessionScopeServices;
private final DefaultBuildSessionContext context;

public BuildSessionState(GradleUserHomeScopeServiceRegistry userHomeScopeServiceRegistry,
CrossBuildSessionState crossBuildSessionServices,
StartParameterInternal startParameter,
BuildRequestMetaData requestMetaData,
ClassPath injectedPluginClassPath,
BuildCancellationToken buildCancellationToken,
BuildClientMetaData buildClientMetaData,
BuildEventConsumer buildEventConsumer) {
public BuildSessionState(
GradleUserHomeScopeServiceRegistry userHomeScopeServiceRegistry,
CrossBuildSessionState crossBuildSessionServices,
StartParameterInternal startParameter,
BuildRequestMetaData requestMetaData,
ClassPath injectedPluginClassPath,
BuildCancellationToken buildCancellationToken,
BuildClientMetaData buildClientMetaData,
BuildEventConsumer buildEventConsumer
) {
this.userHomeScopeServiceRegistry = userHomeScopeServiceRegistry;
userHomeServices = userHomeScopeServiceRegistry.getServicesFor(startParameter.getGradleUserHomeDir());
sessionScopeServices = ServiceRegistryBuilder.builder()
.scope(Scope.BuildSession.class)
.scopeStrictly(Scope.BuildSession.class)
.displayName("build session services")
.parent(userHomeServices)
.parent(crossBuildSessionServices.getServices())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class ServiceScopeValidatorWorkarounds {
"org.gradle.cache.internal.ProducerGuard",
"org.gradle.internal.typeconversion.NotationParser",

// Problematic with GradleBuild task and CC, because marking it as a service
// makes CC skip serialization and instead use service look-up which yield a wrong value for this specially setup task
"org.gradle.api.internal.StartParameterInternal",

"org.gradle.nativeplatform.platform.internal.NativePlatforms",
"org.gradle.nativeplatform.internal.NativePlatformResolver",
"org.gradle.nativeplatform.internal.DefaultTargetMachineFactory"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dependencies {
implementation(projects.logging)
implementation(projects.loggingApi)
implementation(projects.modelCore)
implementation(projects.daemonProtocol)
implementation(projects.daemonServices)
implementation(projects.native)
implementation(projects.serviceRegistryBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
package org.gradle.testfixtures.internal;

import org.gradle.api.internal.properties.GradleProperties;
import org.gradle.configuration.DefaultBuildClientMetaData;
import org.gradle.configuration.GradleLauncherMetaData;
import org.gradle.initialization.BuildCancellationToken;
import org.gradle.initialization.BuildClientMetaData;
import org.gradle.initialization.DefaultBuildCancellationToken;
import org.gradle.initialization.DefaultProjectDescriptorRegistry;
import org.gradle.initialization.GradlePropertiesController;
Expand Down Expand Up @@ -58,11 +55,6 @@ protected BuildCancellationToken createBuildCancellationToken() {
return new DefaultBuildCancellationToken();
}

@Provides
protected BuildClientMetaData createClientMetaData() {
return new DefaultBuildClientMetaData(new GradleLauncherMetaData());
}

@Provides
protected CurrentGradleInstallation createCurrentGradleInstallation() {
return new CurrentGradleInstallation(new GradleInstallation(homeDir));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

package org.gradle.nativeplatform.toolchain.internal.gcc.metadata;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.nativeplatform.platform.internal.NativePlatformInternal;
import org.gradle.nativeplatform.toolchain.internal.xcode.MacOSSdkPathLocator;

import java.io.File;

@ServiceScope(Scope.BuildSession.class)
public class SystemLibraryDiscovery {
private final MacOSSdkPathLocator macOSSdkPathLocator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
package org.gradle.nativeplatform.toolchain.internal.msvcpp;

import net.rubygrapefruit.platform.WindowsRegistry;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.util.internal.VersionNumber;

import java.io.File;

@ServiceScope(Scope.BuildSession.class)
public class DefaultUcrtLocator extends AbstractWindowsKitComponentLocator<UcrtInstall> implements UcrtLocator {
private static final String DISPLAY_NAME = "Universal C Runtime";
private static final String COMPONENT_NAME = "ucrt";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
*/
package org.gradle.nativeplatform.toolchain.internal.msvcpp;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

@ServiceScope(Scope.BuildSession.class)
public interface VisualStudioLocator extends WindowsComponentLocator<VisualStudioInstall> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
*/
package org.gradle.nativeplatform.toolchain.internal.msvcpp;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

@ServiceScope(Scope.BuildSession.class)
public interface WindowsSdkLocator extends WindowsComponentLocator<WindowsSdkInstall> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.gradle.internal.UncheckedException;
import org.gradle.internal.io.NullOutputStream;
import org.gradle.internal.io.StreamByteBuffer;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.process.ExecResult;
import org.gradle.process.internal.ExecAction;
import org.gradle.process.internal.ExecActionFactory;
Expand All @@ -34,6 +36,7 @@
import java.util.ArrayList;
import java.util.List;

@ServiceScope(Scope.BuildSession.class)
public class CommandLineToolVersionLocator extends AbstractVisualStudioVersionLocator implements VisualStudioVersionLocator {
private static final Logger LOGGER = Logging.getLogger(CommandLineToolVersionLocator.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.internal.os.OperatingSystem;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import javax.annotation.Nonnull;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

@ServiceScope(Scope.BuildSession.class)
public class SystemPathVersionLocator implements VisualStudioVersionLocator {
private static final String LEGACY_COMPILER_FILENAME = "cl.exe";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

package org.gradle.nativeplatform.toolchain.internal.msvcpp.version;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import java.io.File;

@ServiceScope(Scope.BuildSession.class)
public interface VisualCppMetadataProvider {
VisualCppInstallCandidate getVisualCppFromMetadataFile(File installDir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

package org.gradle.nativeplatform.toolchain.internal.msvcpp.version;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import java.io.File;

@ServiceScope(Scope.BuildSession.class)
public interface VisualStudioMetaDataProvider {
VisualStudioInstallCandidate getVisualStudioMetadataFromInstallDir(File installDir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

package org.gradle.nativeplatform.toolchain.internal.msvcpp.version;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import java.io.File;

@ServiceScope(Scope.BuildSession.class)
public interface VswhereVersionLocator {
File getVswhereInstall();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
import net.rubygrapefruit.platform.MissingRegistryEntryException;
import net.rubygrapefruit.platform.WindowsRegistry;
import org.gradle.internal.FileUtils;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.util.internal.VersionNumber;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@ServiceScope(Scope.BuildSession.class)
public class WindowsRegistryVersionLocator extends AbstractVisualStudioVersionLocator implements VisualStudioVersionLocator {
static final String[] REGISTRY_BASEPATHS = {
"SOFTWARE\\",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package org.gradle.nativeplatform.toolchain.internal.xcode;

import com.google.common.collect.ImmutableList;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.process.internal.ExecActionFactory;

import javax.inject.Inject;
import java.util.List;

@ServiceScope(Scope.BuildSession.class)
public class MacOSSdkPathLocator extends AbstractLocator {
@Inject
public MacOSSdkPathLocator(ExecActionFactory execActionFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package org.gradle.nativeplatform.toolchain.internal.xcode;

import com.google.common.collect.ImmutableList;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.process.internal.ExecActionFactory;

import javax.inject.Inject;
import java.util.List;

@ServiceScope(Scope.BuildSession.class)
public class MacOSSdkPlatformPathLocator extends AbstractLocator {
@Inject
public MacOSSdkPlatformPathLocator(ExecActionFactory execActionFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package org.gradle.nativeplatform.toolchain.internal.xcode;

import com.google.common.collect.ImmutableList;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.process.internal.ExecActionFactory;

import javax.inject.Inject;
import java.util.List;

@ServiceScope(Scope.BuildSession.class)
public class SwiftStdlibToolLocator extends AbstractLocator {
@Inject
public SwiftStdlibToolLocator(ExecActionFactory execActionFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import org.gradle.api.internal.attributes.ImmutableAttributes;
import org.gradle.internal.model.InMemoryCacheFactory;
import org.gradle.internal.model.InMemoryInterner;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

/**
* Creates and interns {@link ImmutableArtifactTypeRegistry} instances
* from {@link ArtifactTypeRegistry} instances.
*/
@ServiceScope(Scope.BuildSession.class)
public class ImmutableArtifactTypeRegistryFactory {

private final AttributesFactory attributesFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
import org.gradle.internal.execution.workspace.ImmutableWorkspaceProvider;
import org.gradle.internal.execution.workspace.impl.CacheBasedImmutableWorkspaceProvider;
import org.gradle.internal.file.FileAccessTimeJournal;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import java.io.Closeable;

@ServiceScope(Scope.BuildSession.class)
public class DependenciesAccessorsWorkspaceProvider implements ImmutableWorkspaceProvider, Closeable {
private final CacheBasedImmutableWorkspaceProvider delegate;

Expand Down
Loading

0 comments on commit 4737d64

Please sign in to comment.