Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/sg/50/placeholders'
Browse files Browse the repository at this point in the history
* origin/sg/50/placeholders:
  remove TaskConfiguration by inlining all methods
  Remove unnecessary method
  Add since 5.0 tag
  Hold a project lock when reporting on tasks in other projects
  Add release notes for removed placeholder tasks
  Relax ordering of plugin application operation asserts
  Fix integration tests that relied on placeholder behavior
  Remove placeholder tasks
  • Loading branch information
big-guy committed Sep 17, 2018
2 parents c15a8a0 + 8acb67b commit 37e3654
Show file tree
Hide file tree
Showing 25 changed files with 195 additions and 759 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,4 @@ class WrapperPluginAutoApplyActionIntegTest extends AbstractIntegrationSpec {
then:
wrapper.generated()
}

def "manually declared wrapper task is preferred, but deprecated"() {
when:
buildFile << """
task wrapper {
doLast {
println "running custom wrapper task"
}
}
"""
executer.expectDeprecationWarning()
run 'wrapper'
then:

outputContains("running custom wrapper task")
outputContains("Creating a custom task named 'wrapper' has been deprecated.")
wrapper.notGenerated()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,78 @@

package org.gradle.buildinit.plugins;

import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.buildinit.tasks.internal.TaskConfiguration;
import org.gradle.api.Task;
import org.gradle.api.specs.Spec;
import org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl;
import org.gradle.buildinit.tasks.InitBuild;

import java.io.File;
import java.util.concurrent.Callable;

/**
* The build init plugin.
*/
public class BuildInitPlugin implements Plugin<Project> {
public void apply(final Project project) {
TaskConfiguration.addInitPlaceholder((ProjectInternal) project);
if (project.getParent() == null) {
project.getTasks().register("init", InitBuild.class, new Action<InitBuild>() {
@Override
public void execute(InitBuild initBuild) {
initBuild.setGroup("Build Setup");
initBuild.setDescription("Initializes a new Gradle build.");

initBuild.onlyIf(new Spec<Task>() {
@Override
public boolean isSatisfiedBy(Task element) {
Object skippedMsg = reasonToSkip(project);
if (skippedMsg != null) {
project.getLogger().warn((String) skippedMsg);
return false;
}

return true;
}
});

initBuild.dependsOn(new Callable<String>() {
@Override
public String call() throws Exception {
if (reasonToSkip(project) == null) {
return "wrapper";
} else {
return null;
}
}
});
}
});
}
}

private String reasonToSkip(Project project) {
for (BuildInitDsl dsl : BuildInitDsl.values()) {
String buildFileName = dsl.fileNameFor("build");
if (project.file(buildFileName).exists()) {
return "The build file '" + buildFileName + "' already exists. Skipping build initialization.";
}
String settingsFileName = dsl.fileNameFor("settings");
if (project.file(settingsFileName).exists()) {
return "The settings file '" + settingsFileName + "' already exists. Skipping build initialization.";
}
}

File buildFile = project.getBuildFile();
if (buildFile != null && buildFile.exists()) {
return "The build file \'" + buildFile.getName() + "\' already exists. Skipping build initialization.";
}

if (project.getSubprojects().size() > 0) {
return "This Gradle project appears to be part of an existing multi-project Gradle build. Skipping build initialization.";
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@

package org.gradle.buildinit.plugins;

import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.buildinit.tasks.internal.TaskConfiguration;
import org.gradle.api.tasks.wrapper.Wrapper;

/**
* The wrapper plugin.
*/
public class WrapperPlugin implements Plugin<Project> {
public void apply(Project project) {
TaskConfiguration.addWrapperPlaceholder((ProjectInternal) project);
if (project.getParent() == null) {
project.getTasks().register("wrapper", Wrapper.class, new Action<Wrapper>() {
@Override
public void execute(Wrapper wrapper) {
wrapper.setGroup("Build Setup");
wrapper.setDescription("Generates Gradle wrapper files.");
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
package org.gradle.buildinit.plugins.internal.action;

import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.buildinit.tasks.internal.TaskConfiguration;
import org.gradle.configuration.project.ProjectConfigureAction;

public class BuildInitAutoApplyAction implements ProjectConfigureAction {

public void execute(final ProjectInternal projectInternal) {
TaskConfiguration.addInitPlaceholder(projectInternal);
public void execute(final ProjectInternal project) {
project.getPluginManager().apply("org.gradle.build-init");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
package org.gradle.buildinit.plugins.internal.action;

import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.buildinit.tasks.internal.TaskConfiguration;
import org.gradle.configuration.project.ProjectConfigureAction;

public class WrapperPluginAutoApplyAction implements ProjectConfigureAction {
@Override
public void execute(ProjectInternal project) {
TaskConfiguration.addWrapperPlaceholder(project);
project.getPluginManager().apply("org.gradle.wrapper");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.gradle.buildinit.plugins

import org.gradle.api.tasks.wrapper.Wrapper
import org.gradle.buildinit.tasks.internal.TaskConfiguration
import org.gradle.test.fixtures.file.TestNameTestDirectoryProvider
import org.gradle.util.TestUtil
import org.gradle.util.UsesNativeServices
Expand All @@ -37,6 +36,6 @@ class WrapperPluginSpec extends Specification {

then:
project.tasks.wrapper instanceof Wrapper
project.tasks.wrapper.group == TaskConfiguration.GROUP
project.tasks.wrapper.group == "Build Setup"
}
}

This file was deleted.

0 comments on commit 37e3654

Please sign in to comment.