Skip to content

Commit

Permalink
Merge pull request #23112 Do not expose named domain object list, take 2
Browse files Browse the repository at this point in the history
Fixes #23016

Co-authored-by: József Bartók <jbartok@gradle.com>
  • Loading branch information
bot-gradle and jbartok committed Dec 14, 2022
2 parents 7d72bae + 2291e91 commit 33f1620
Show file tree
Hide file tree
Showing 16 changed files with 338 additions and 72 deletions.
Expand Up @@ -1549,7 +1549,15 @@
},
{
"type": "org.gradle.jvm.toolchain.JavaToolchainRepositoryHandler",
"member": "Method org.gradle.jvm.toolchain.JavaToolchainRepositoryHandler.repositories()",
"member": "Method org.gradle.jvm.toolchain.JavaToolchainRepositoryHandler.getAsList()",
"acceptation": "method addition backport to 7.6.1",
"changes": [
"Method added to interface"
]
},
{
"type": "org.gradle.jvm.toolchain.JavaToolchainRepositoryHandler",
"member": "Method org.gradle.jvm.toolchain.JavaToolchainRepositoryHandler.remove(java.lang.String)",
"acceptation": "method addition backport to 7.6.1",
"changes": [
"Method added to interface"
Expand Down
Expand Up @@ -26,12 +26,13 @@
import org.gradle.groovy.scripts.ScriptSource;
import org.gradle.initialization.DefaultProjectDescriptor;
import org.gradle.initialization.IncludedBuildSpec;
import org.gradle.internal.FinalizableValue;
import org.gradle.internal.management.DependencyResolutionManagementInternal;
import org.gradle.internal.service.ServiceRegistry;

import java.util.List;

public interface SettingsInternal extends Settings, PluginAwareInternal {
public interface SettingsInternal extends Settings, PluginAwareInternal, FinalizableValue {

String BUILD_SRC = "buildSrc";

Expand Down Expand Up @@ -70,8 +71,6 @@ public interface SettingsInternal extends Settings, PluginAwareInternal {
@Override
BuildCacheConfigurationInternal getBuildCache();

void preventFromFurtherMutation();

DependencyResolutionManagementInternal getDependencyResolutionManagement();

@Override
Expand Down
Expand Up @@ -45,6 +45,7 @@
import org.gradle.internal.buildoption.FeatureFlags;
import org.gradle.internal.deprecation.DeprecationLogger;
import org.gradle.internal.management.DependencyResolutionManagementInternal;
import org.gradle.internal.management.ToolchainManagementInternal;
import org.gradle.internal.resource.TextUriResourceLoader;
import org.gradle.internal.service.ServiceRegistry;
import org.gradle.internal.service.scopes.ServiceRegistryFactory;
Expand Down Expand Up @@ -79,6 +80,8 @@ public abstract class DefaultSettings extends AbstractPluginAware implements Set
private final List<IncludedBuildSpec> includedBuildSpecs = new ArrayList<>();
private final DependencyResolutionManagementInternal dependencyResolutionManagement;

private final ToolchainManagementInternal toolchainManagement;

public DefaultSettings(
ServiceRegistryFactory serviceRegistryFactory,
GradleInternal gradle,
Expand All @@ -99,6 +102,7 @@ public DefaultSettings(
this.services = serviceRegistryFactory.createFor(this);
this.rootProjectDescriptor = createProjectDescriptor(null, settingsDir.getName(), settingsDir);
this.dependencyResolutionManagement = services.get(DependencyResolutionManagementInternal.class);
this.toolchainManagement = services.get(ToolchainManagementInternal.class);
}

@Override
Expand Down Expand Up @@ -244,20 +248,13 @@ public void setSettingsScript(ScriptSource settingsScript) {

@Override
@Inject
public ProviderFactory getProviders() {
// Decoration takes care of the implementation
throw new UnsupportedOperationException();
}
public abstract ProviderFactory getProviders();

@Inject
public ProjectDescriptorRegistry getProjectDescriptorRegistry() {
throw new UnsupportedOperationException();
}
public abstract ProjectDescriptorRegistry getProjectDescriptorRegistry();

@Inject
public TextUriResourceLoader.Factory getTextUriResourceLoaderFactory() {
throw new UnsupportedOperationException();
}
public abstract TextUriResourceLoader.Factory getTextUriResourceLoaderFactory();

@Override
public ProjectRegistry<DefaultProjectDescriptor> getProjectRegistry() {
Expand Down Expand Up @@ -291,25 +288,17 @@ public ServiceRegistry getServices() {
}

@Inject
protected ScriptHandlerFactory getScriptHandlerFactory() {
throw new UnsupportedOperationException();
}
protected abstract ScriptHandlerFactory getScriptHandlerFactory();

@Inject
protected ScriptPluginFactory getScriptPluginFactory() {
throw new UnsupportedOperationException();
}
protected abstract ScriptPluginFactory getScriptPluginFactory();

@Inject
protected FileResolver getFileResolver() {
throw new UnsupportedOperationException();
}
protected abstract FileResolver getFileResolver();

@Override
@Inject
public PluginManagerInternal getPluginManager() {
throw new UnsupportedOperationException();
}
public abstract PluginManagerInternal getPluginManager();

@Override
public void includeBuild(Object rootProject) {
Expand All @@ -329,9 +318,7 @@ public void buildCache(Action<? super BuildCacheConfiguration> action) {

@Override
@Inject
public BuildCacheConfigurationInternal getBuildCache() {
throw new UnsupportedOperationException();
}
public abstract BuildCacheConfigurationInternal getBuildCache();

@Override
public void pluginManagement(Action<? super PluginManagementSpec> rule) {
Expand All @@ -341,9 +328,7 @@ public void pluginManagement(Action<? super PluginManagementSpec> rule) {

@Override
@Inject
public PluginManagementSpec getPluginManagement() {
throw new UnsupportedOperationException();
}
public abstract PluginManagementSpec getPluginManagement();

@Override
public void sourceControl(Action<? super SourceControl> configuration) {
Expand All @@ -352,9 +337,7 @@ public void sourceControl(Action<? super SourceControl> configuration) {

@Override
@Inject
public SourceControl getSourceControl() {
throw new UnsupportedOperationException();
}
public abstract SourceControl getSourceControl();

@Override
public void enableFeaturePreview(String name) {
Expand All @@ -372,13 +355,14 @@ public void enableFeaturePreview(String name) {
}

@Override
public void dependencyResolutionManagement(Action<? super DependencyResolutionManagement> dependencyResolutionConfiguration) {
dependencyResolutionConfiguration.execute(dependencyResolutionManagement);
public void preventFromFurtherMutation() {
dependencyResolutionManagement.preventFromFurtherMutation();
toolchainManagement.preventFromFurtherMutation();
}

@Override
public void preventFromFurtherMutation() {
dependencyResolutionManagement.preventFromFurtherMutation();
public void dependencyResolutionManagement(Action<? super DependencyResolutionManagement> dependencyResolutionConfiguration) {
dependencyResolutionConfiguration.execute(dependencyResolutionManagement);
}

@Override
Expand All @@ -387,21 +371,18 @@ public DependencyResolutionManagementInternal getDependencyResolutionManagement(
}

@Override
@Inject
public ToolchainManagement getToolchainManagement() {
throw new UnsupportedOperationException();
return toolchainManagement;
}

@Override
@Inject
public CacheConfigurationsInternal getCaches() {
throw new UnsupportedOperationException();
public void toolchainManagement(Action<? super ToolchainManagement> toolchainManagementConfiguration) {
toolchainManagementConfiguration.execute(toolchainManagement);
}

@Override
public void toolchainManagement(Action<? super ToolchainManagement> toolchainManagementConfiguration) {
toolchainManagementConfiguration.execute(getToolchainManagement());
}
@Inject
public abstract CacheConfigurationsInternal getCaches();

@Override
public void caches(Action<? super CacheConfigurations> cachesConfiguration) {
Expand Down
Expand Up @@ -16,7 +16,19 @@

package org.gradle.initialization;

import org.gradle.api.toolchain.management.ToolchainManagement;
import org.gradle.api.internal.plugins.ExtensionContainerInternal;
import org.gradle.internal.FinalizableValue;
import org.gradle.internal.management.ToolchainManagementInternal;

public abstract class DefaultToolchainManagement implements ToolchainManagementInternal {

@Override
public void preventFromFurtherMutation() {
ExtensionContainerInternal extensions = (ExtensionContainerInternal) getExtensions();
extensions.getAsMap().values().stream()
.filter(ext -> ext instanceof FinalizableValue)
.map(ext -> (FinalizableValue) ext)
.forEach(FinalizableValue::preventFromFurtherMutation);
}

public abstract class DefaultToolchainManagement implements ToolchainManagement {
}
@@ -0,0 +1,35 @@
/*
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.internal;

/**
* Mutable value type for which mutation can be disabled at a certain point in time,
* by calling the {@code disableFurtherMutations()} method.
* <p>
* After {@code disableFurtherMutations()} has been called, any subsequent calls to methods that mutate
* the value in any way will fail by throwing an {@code IllegalStateException}.
*/
public interface FinalizableValue {

/**
* Disallows further changes to the value represented by this type.
* <p>
* Subsequent calls to methods that mutate the value in any way will fail by throwing an {@code IllegalStateException}.
*/
void preventFromFurtherMutation();

}
Expand Up @@ -22,18 +22,17 @@
import org.gradle.api.initialization.resolve.RulesMode;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.api.provider.Property;
import org.gradle.internal.FinalizableValue;
import org.gradle.internal.service.scopes.Scopes;
import org.gradle.internal.service.scopes.ServiceScope;

import java.util.List;

@ServiceScope(Scopes.Build.class)
public interface DependencyResolutionManagementInternal extends DependencyResolutionManagement {
public interface DependencyResolutionManagementInternal extends DependencyResolutionManagement, FinalizableValue {

void configureProject(ProjectInternal project);

void preventFromFurtherMutation();

void applyRules(ComponentMetadataHandler target);

RepositoriesModeInternal getConfiguredRepositoriesMode();
Expand Down
@@ -0,0 +1,26 @@
/*
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.internal.management;

import org.gradle.api.toolchain.management.ToolchainManagement;
import org.gradle.internal.FinalizableValue;
import org.gradle.internal.service.scopes.Scopes;
import org.gradle.internal.service.scopes.ServiceScope;

@ServiceScope(Scopes.Build.class)
public interface ToolchainManagementInternal extends ToolchainManagement, FinalizableValue {
}
Expand Up @@ -28,6 +28,7 @@
import org.gradle.api.internal.attributes.AttributeContainerInternal;
import org.gradle.api.internal.attributes.ImmutableAttributes;
import org.gradle.internal.DisplayName;
import org.gradle.internal.FinalizableValue;
import org.gradle.internal.deprecation.DeprecatableConfiguration;
import org.gradle.util.Path;

Expand All @@ -37,7 +38,7 @@
import java.util.Set;
import java.util.function.Supplier;

public interface ConfigurationInternal extends ResolveContext, Configuration, DeprecatableConfiguration, DependencyMetaDataProvider {
public interface ConfigurationInternal extends ResolveContext, Configuration, DeprecatableConfiguration, DependencyMetaDataProvider, FinalizableValue {
enum InternalState {
UNRESOLVED,
BUILD_DEPENDENCIES_RESOLVED,
Expand Down Expand Up @@ -89,13 +90,6 @@ enum InternalState {

boolean isCanBeMutated();

/**
* Locks the configuration for mutation
* <p>
* Any invalid state at this point will end up throwing an exception.
*/
void preventFromFurtherMutation();

/**
* Locks the configuration for mutation
* <p>
Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.gradle.api.internal.tasks.TaskDependencyFactory;
import org.gradle.api.provider.Provider;
import org.gradle.internal.DisplayName;
import org.gradle.internal.FinalizableValue;
import org.gradle.internal.reflect.Instantiator;
import org.gradle.internal.typeconversion.NotationParser;

Expand All @@ -47,7 +48,7 @@
import java.util.List;
import java.util.Set;

public class DefaultConfigurationPublications implements ConfigurationPublications {
public class DefaultConfigurationPublications implements ConfigurationPublications, FinalizableValue {
private final DisplayName displayName;
private final PublishArtifactSet artifacts;
private final PublishArtifactSetProvider allArtifacts;
Expand Down Expand Up @@ -225,7 +226,7 @@ public Collection<? extends Capability> getCapabilities() {
return capabilities == null ? Collections.emptyList() : ImmutableList.copyOf(capabilities);
}

void preventFromFurtherMutation() {
public void preventFromFurtherMutation() {
canCreate = false;
if (variants != null) {
for (ConfigurationVariant variant : variants) {
Expand Down

0 comments on commit 33f1620

Please sign in to comment.