Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a96fc12
Remove Closure taking methods from Reporting
big-guy Sep 24, 2022
06f42e5
Remove Closure taking query methods from DomainObjectCollections
big-guy Sep 24, 2022
3af09e8
Remove create(String, Closure) from domain object collections
big-guy Sep 24, 2022
213e39d
Remove most of the Closure taking methods from Task
big-guy Sep 24, 2022
9774ff1
Add Action taking equivalents for all Closure-taking methods in Script
big-guy Sep 24, 2022
76f0977
Remove Closure taking methods from Script
big-guy Sep 24, 2022
9bae576
Linkify types in Task javadoc
big-guy Sep 24, 2022
6997035
Remove Closure taking methods from ComponentSelectionRules
big-guy Sep 24, 2022
ec11839
Remove Closure from ModuleDependency
big-guy Sep 24, 2022
0479d4e
Remove Closure taking methods from Configuration
big-guy Sep 24, 2022
ff87683
Remove Closure-taking methods from ArtifactHandler
big-guy Sep 24, 2022
8dabaa9
Remove Closure from ComponentMetadataHandler
big-guy Sep 24, 2022
4fc0614
Remove Closure taking methods from RepositoryHandler
big-guy Sep 24, 2022
a9ac555
Add Configurable.configure(Action)
big-guy Sep 24, 2022
ad90633
Remove most of the Closure-taking methods in Project
big-guy Sep 24, 2022
fbac41c
Add missing Action-taking methods for Project
big-guy Sep 24, 2022
e343a51
Remove Closure methods from PluginAware
big-guy Sep 24, 2022
6ffcc30
Remove the rest of the Closure taking methods from Project
big-guy Sep 24, 2022
1b01fc0
Remove explicit reference to configure(Closure) in NamedDomainObjectC…
big-guy Sep 24, 2022
5793488
Remove Closure methods from TaskExecutionGraph
big-guy Sep 24, 2022
d7baaf7
Remove Closure taking methods from file manipulating classes
big-guy Sep 24, 2022
75d472f
Remove Closure taking methods from Gradle
big-guy Sep 24, 2022
f225fc3
Remove Closure methods from PluginCollection
big-guy Sep 24, 2022
8ea3493
Remove Closure taking methods from TaskOutputs
big-guy Sep 24, 2022
01bbac2
Remove Closure methods from ProjectConfigurationActionContainer
big-guy Sep 24, 2022
e2d5dad
Remove Closure methods from Ear
big-guy Sep 24, 2022
af9cbaf
Remove Closure methods from Javadoc
big-guy Sep 24, 2022
b1c27c4
Remove some Closure taking methods from Test tasks
big-guy Sep 24, 2022
f60ea71
Remove Closure from SourceSet
big-guy Sep 24, 2022
33b62c9
Make sanityCheck happy
big-guy Sep 25, 2022
9335513
Fix javadoc generation
big-guy Sep 25, 2022
6c91e73
Update archunit baseline input
big-guy Sep 25, 2022
6021c8b
Revert "Remove the rest of the Closure taking methods from Project"
big-guy Sep 25, 2022
75f3031
Revert "Add missing Action-taking methods for Project"
big-guy Sep 25, 2022
51b8016
Make ktlint happy
big-guy Sep 25, 2022
5bc02cc
Ignore compatibility checks so we can run some tests
big-guy Sep 25, 2022
4202461
Remove Closure methods from DeploymentDescriptor
big-guy Sep 25, 2022
6665e09
Remove Closure from IDE related types
big-guy Sep 25, 2022
bc50fbf
Remove Closure methods from Jar and War
big-guy Sep 25, 2022
8164504
Add test for Closure-taking methods with CompileStatic
big-guy Oct 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Action taking equivalents for all Closure-taking methods in Script
  • Loading branch information
big-guy committed Sep 24, 2022
commit 9774ff128de92553f84e5d2689bc01997cd16dba
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.gradle.api.file.DeleteSpec
import org.gradle.api.file.FileTree
import org.gradle.api.file.ProjectLayout
import org.gradle.api.file.SyncSpec
import org.gradle.api.initialization.dsl.ScriptHandler
import org.gradle.api.internal.DynamicObjectAware
import org.gradle.api.internal.GradleInternal
import org.gradle.api.internal.ProcessOperations
Expand Down Expand Up @@ -692,6 +693,11 @@ class ProblemReportingCrossProjectModelAccess(
delegate.buildscript(configureClosure)
}

override fun buildscript(action: Action<in ScriptHandler>) {
onAccess()
delegate.buildscript(action)
}

override fun copy(closure: Closure<*>): WorkResult {
onAccess()
return delegate.copy(closure)
Expand Down
11 changes: 11 additions & 0 deletions subprojects/core-api/src/main/java/org/gradle/api/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,17 @@ public interface Project extends Comparable<Project>, ExtensionAware, PluginAwar
*/
void buildscript(Closure configureClosure);

/**
* <p>Configures the build script classpath for this project.
*
* @param action the action to use to configure the build script classpath.
*
* @see Script#buildscript(Action)
*
* @since 8.0
*/
void buildscript(Action<? super ScriptHandler> action);

/**
* Copies the specified files. The given closure is used to configure a {@link CopySpec}, which is then used to
* copy the files. Example:
Expand Down
121 changes: 121 additions & 0 deletions subprojects/core-api/src/main/java/org/gradle/api/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import org.gradle.api.file.ConfigurableFileTree;
import org.gradle.api.file.CopySpec;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.SyncSpec;
import org.gradle.api.initialization.dsl.ScriptHandler;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.LoggingManager;
import org.gradle.api.plugins.ObjectConfigurationAction;
import org.gradle.api.provider.Provider;
import org.gradle.api.resources.ResourceHandler;
import org.gradle.api.tasks.WorkResult;
Expand Down Expand Up @@ -57,6 +59,17 @@ public interface Script {
*/
void apply(Closure closure);

/**
* <p>Configures the delegate object for this script using plugins or scripts.
*
* <p>The given action is used to configure an {@link org.gradle.api.plugins.ObjectConfigurationAction} which is
* then used to configure the delegate object.</p>
*
* @param action The action to configure the {@code ObjectConfigurationAction}.
* @since 8.0
*/
void apply(Action<? super ObjectConfigurationAction> action);

/**
* <p>Configures the delegate object for this script using plugins or scripts.
*
Expand Down Expand Up @@ -93,6 +106,16 @@ public interface Script {
*/
void buildscript(Closure configureClosure);

/**
* Configures the classpath for this script.
*
* <p>The given action is executed against this script's {@link ScriptHandler}. </p>
*
* @param action the action to use to configure the script classpath.
* @since 8.0
*/
void buildscript(Action<? super ScriptHandler> action);

/**
* <p>Resolves a file path relative to the directory containing this script. This works as described for {@link
* Project#file(Object)}</p>
Expand Down Expand Up @@ -143,6 +166,20 @@ public interface Script {
*/
ConfigurableFileCollection files(Object paths, Closure configureClosure);

/**
* <p>Creates a new {@code ConfigurableFileCollection} using the given paths. The file collection is configured
* using the given action. This method works as described for {@link Project#files(Object, Action)}.
* Relative paths are resolved relative to the directory containing this script.</p>
*
* @param paths The contents of the file collection. Evaluated as per {@link #files(Object...)}.
* @param action The action to use to configure the file collection.
* @return the configured file tree. Never returns null.
*
* @see Project#files(Object, Action)
* @since 8.0
*/
ConfigurableFileCollection files(Object paths, Action<? super ConfigurableFileCollection> action);

/**
* <p>Returns the relative path from the directory containing this script to the given path. The given path object
* is (logically) resolved as described for {@link #file(Object)}, from which a relative path is calculated.</p>
Expand Down Expand Up @@ -201,6 +238,31 @@ public interface Script {
*/
ConfigurableFileTree fileTree(Object baseDir, Closure configureClosure);

/**
* <p>Creates a new {@code ConfigurableFileTree} using the given base directory. The given baseDir path is evaluated
* as per {@link #file(Object)}. The action will be used to configure the new file tree.
* Example:</p>
*
* <pre>
* fileTree('src') {
* exclude '**&#47;.svn/**'
* }.copy { into 'dest'}
* </pre>
*
* <p>The returned file tree is lazy, so that it scans for files only when the contents of the file tree are
* queried. The file tree is also live, so that it scans for files each time the contents of the file tree are
* queried.</p>
*
* @param baseDir The base directory of the file tree. Evaluated as per {@link #file(Object)}.
* @param action Action to configure the {@code ConfigurableFileTree} object.
* @return the configured file tree. Never returns null.
*
* @see Project#fileTree(Object, Action)
*
* @since 8.0
*/
ConfigurableFileTree fileTree(Object baseDir, Action<? super ConfigurableFileTree> action);

/**
* <p>Creates a new {@code FileTree} which contains the contents of the given ZIP file. The given zipPath path is
* evaluated as per {@link #file(Object)}. You can combine this method with the {@link #copy(groovy.lang.Closure)}
Expand Down Expand Up @@ -281,6 +343,52 @@ public interface Script {
*/
WorkResult copy(Closure closure);

/**
* Copy the specified files. The given action is used to configure a {@link org.gradle.api.file.CopySpec}, which
* is then used to copy the files. Example:
* <pre>
* copy {
* from configurations.runtimeClasspath
* into 'build/deploy/lib'
* }
* </pre>
* Note that CopySpecs can be nested:
* <pre>
* copy {
* into 'build/webroot'
* exclude '**&#47;.svn/**'
* from('src/main/webapp') {
* include '**&#47;*.jsp'
* filter(ReplaceTokens, tokens:[copyright:'2009', version:'2.3.1'])
* }
* from('src/main/js') {
* include '**&#47;*.js'
* }
* }
* </pre>
*
* @param action Action to configure the CopySpec
* @return {@link org.gradle.api.tasks.WorkResult} that can be used to check if the copy did any work.
*
* @see Project#copy(Action)
*
* @since 8.0
*/
WorkResult copy(Action<? super CopySpec> action);

/**
* Synchronizes the contents of a destination directory with some source directories and files.
* The given action is used to configure a {@link SyncSpec}, which is then used to synchronize the files.
*
* @param action Action to configure the SyncSpec
* @return {@link org.gradle.api.tasks.WorkResult} that can be used to check if the sync did any work.
*
* @see Project#sync(Action)
*
* @since 8.0
*/
WorkResult sync(Action<? super SyncSpec> action);

/**
* Creates a {@link org.gradle.api.file.CopySpec} which can later be used to copy files or create an archive. The
* given closure is used to configure the {@link org.gradle.api.file.CopySpec} before it is returned by this
Expand All @@ -291,6 +399,19 @@ public interface Script {
*/
CopySpec copySpec(Closure closure);

/**
* Creates a {@link org.gradle.api.file.CopySpec} which can later be used to copy files or create an archive. The
* given action is used to configure the {@link org.gradle.api.file.CopySpec} before it is returned by this
* method.
*
* @param action Action to configure the CopySpec
* @return The CopySpec
*
* @since 8.0
* @see Project#copySpec(Action)
*/
CopySpec copySpec(Action<? super CopySpec> action);

/**
* Creates a directory and returns a file pointing to it.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.gradle.api.file.FileTree;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.SyncSpec;
import org.gradle.api.initialization.dsl.ScriptHandler;
import org.gradle.api.internal.CollectionCallbackActionDecorator;
import org.gradle.api.internal.DomainObjectContext;
import org.gradle.api.internal.DynamicObjectAware;
Expand Down Expand Up @@ -1259,7 +1260,12 @@ public void artifacts(Action<? super ArtifactHandler> configureAction) {

@Override
public void buildscript(Closure configureClosure) {
ConfigureUtil.configure(configureClosure, getBuildscript());
buildscript(ConfigureUtil.configureUsing(configureClosure));
}

@Override
public void buildscript(Action<? super ScriptHandler> action) {
Actions.with(getBuildscript(), action);
}

@Override
Expand All @@ -1278,7 +1284,7 @@ public Task task(String task, Action<? super Task> configureAction) {

@Override
public Task task(String task, Closure configureClosure) {
return taskContainer.create(task).configure(configureClosure);
return taskContainer.create(task).configure(ConfigureUtil.configureUsing(configureClosure));
}

public Task task(Object task, Closure configureClosure) {
Expand All @@ -1296,7 +1302,7 @@ public Task task(Map options, Object task) {

@Override
public Task task(Map options, String task, Closure configureClosure) {
return taskContainer.create(addMaps(Cast.uncheckedNonnullCast(options), singletonMap(Task.TASK_NAME, task))).configure(configureClosure);
return taskContainer.create(addMaps(Cast.uncheckedNonnullCast(options), singletonMap(Task.TASK_NAME, task))).configure(ConfigureUtil.configureUsing(configureClosure));
}

public Task task(Map options, Object task, Closure configureClosure) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
*/
package org.gradle.api.internal.project;

import groovy.lang.Closure;
import org.gradle.api.Action;
import org.gradle.api.initialization.dsl.ScriptHandler;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.LoggingManager;
import org.gradle.api.plugins.ObjectConfigurationAction;
import org.gradle.internal.logging.StandardOutputCapture;
import org.gradle.plugin.use.internal.PluginsAwareScript;

import java.util.Map;

public abstract class ProjectScript extends PluginsAwareScript {

@Override
public void apply(Closure closure) {
getScriptTarget().apply(closure);
public void apply(Action<? super ObjectConfigurationAction> action) {
getScriptTarget().apply(action);
}

@Override
Expand All @@ -43,8 +43,8 @@ public ScriptHandler getBuildscript() {
}

@Override
public void buildscript(Closure configureClosure) {
getScriptTarget().buildscript(configureClosure);
public void buildscript(Action<? super ScriptHandler> action) {
getScriptTarget().buildscript(action);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.gradle.api.file.CopySpec;
import org.gradle.api.file.DeleteSpec;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.SyncSpec;
import org.gradle.api.initialization.dsl.ScriptHandler;
import org.gradle.api.internal.ProcessOperations;
import org.gradle.api.internal.file.DefaultFileOperations;
Expand All @@ -40,6 +41,7 @@
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.logging.LoggingManager;
import org.gradle.api.plugins.ObjectConfigurationAction;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.resources.ResourceHandler;
Expand Down Expand Up @@ -121,9 +123,14 @@ private DefaultObjectConfigurationAction createObjectConfigurationAction() {

@Override
public void apply(Closure closure) {
DefaultObjectConfigurationAction action = createObjectConfigurationAction();
ConfigureUtil.configure(closure, action);
action.execute();
apply(ConfigureUtil.configureUsing(closure));
}

@Override
public void apply(Action<? super ObjectConfigurationAction> action) {
DefaultObjectConfigurationAction configurationAction = createObjectConfigurationAction();
action.execute(configurationAction);
configurationAction.execute();
}

@Override
Expand All @@ -143,6 +150,11 @@ public void buildscript(Closure configureClosure) {
ConfigureUtil.configure(configureClosure, getBuildscript());
}

@Override
public void buildscript(Action<? super ScriptHandler> action) {
Actions.with(getBuildscript(), action);
}

@Override
public File file(Object path) {
return fileOperations.file(path);
Expand All @@ -168,6 +180,11 @@ public ConfigurableFileCollection files(Object paths, Closure configureClosure)
return ConfigureUtil.configure(configureClosure, files(paths));
}

@Override
public ConfigurableFileCollection files(Object paths, Action<? super ConfigurableFileCollection> action) {
return Actions.with(files(paths), action);
}

@Override
public String relativePath(Object path) {
return fileOperations.relativePath(path);
Expand All @@ -188,6 +205,11 @@ public ConfigurableFileTree fileTree(Object baseDir, Closure configureClosure) {
return ConfigureUtil.configure(configureClosure, fileOperations.fileTree(baseDir));
}

@Override
public ConfigurableFileTree fileTree(Object baseDir, Action<? super ConfigurableFileTree> action) {
return Actions.with(fileTree(baseDir), action);
}

@Override
public FileTree zipTree(Object zipPath) {
return fileOperations.zipTree(zipPath);
Expand All @@ -208,11 +230,13 @@ public WorkResult copy(Closure closure) {
return copy(ConfigureUtil.configureUsing(closure));
}

@Override
public WorkResult copy(Action<? super CopySpec> action) {
return fileOperations.copy(action);
}

public WorkResult sync(Action<? super CopySpec> action) {
@Override
public WorkResult sync(Action<? super SyncSpec> action) {
return fileOperations.sync(action);
}

Expand All @@ -221,6 +245,11 @@ public CopySpec copySpec(Closure closure) {
return Actions.with(copySpec(), ConfigureUtil.configureUsing(closure));
}

@Override
public CopySpec copySpec(Action<? super CopySpec> action) {
return Actions.with(fileOperations.copySpec(), action);
}

public CopySpec copySpec() {
return fileOperations.copySpec();
}
Expand Down
Loading