Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Remove usage of deprecated JavaPluginConvention (#75106) #75740

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskProvider;
Expand All @@ -29,7 +29,7 @@ public LicenseHeadersPrecommitPlugin(ProviderFactory providerFactory) {
public TaskProvider<? extends Task> createTask(Project project) {
return project.getTasks().register("licenseHeaders", LicenseHeadersTask.class, licenseHeadersTask -> {
project.getPlugins().withType(JavaBasePlugin.class, javaBasePlugin -> {
final SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
final SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
licenseHeadersTask.getSourceFolders()
.addAll(providerFactory.provider(() -> sourceSets.stream().map(s -> s.getAllJava()).collect(Collectors.toList())));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.TaskProvider;

/**
Expand All @@ -29,7 +29,7 @@ public final void apply(Project project) {
precommit.configure(t -> t.dependsOn(task));
project.getPluginManager().withPlugin("java", p -> {
// We want to get any compilation error before running the pre-commit checks.
project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet ->
project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().all(sourceSet ->
task.configure(t -> t.shouldRunAfter(sourceSet.getClassesTaskName()))
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.file.FileTree;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.util.PatternFilterable;

import javax.annotation.Nullable;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Optional;
import java.util.function.Supplier;

Expand Down Expand Up @@ -85,7 +83,7 @@ public static FileTree getJavaTestAndMainSourceResources(Project project, Action
* @return An Optional that contains the Java test SourceSet if it exists.
*/
public static Optional<SourceSet> getJavaTestSourceSet(Project project) {
return project.getConvention().findPlugin(JavaPluginConvention.class) == null
return project.getExtensions().findByName("java") == null
? Optional.empty()
: Optional.ofNullable(getJavaSourceSets(project).findByName(SourceSet.TEST_SOURCE_SET_NAME));
}
Expand All @@ -95,11 +93,15 @@ public static Optional<SourceSet> getJavaTestSourceSet(Project project) {
* @return An Optional that contains the Java main SourceSet if it exists.
*/
public static Optional<SourceSet> getJavaMainSourceSet(Project project) {
return project.getConvention().findPlugin(JavaPluginConvention.class) == null
return isJavaExtensionAvailable(project)
? Optional.empty()
: Optional.ofNullable(getJavaSourceSets(project).findByName(SourceSet.MAIN_SOURCE_SET_NAME));
}

private static boolean isJavaExtensionAvailable(Project project) {
return project.getExtensions().getByType(JavaPluginExtension.class) == null;
}


public static Object toStringable(Supplier<String> getter) {
return new Object() {
Expand All @@ -111,7 +113,7 @@ public String toString() {
}

public static SourceSetContainer getJavaSourceSets(Project project) {
return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
return project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.Provider;
import org.gradle.api.services.BuildService;
import org.gradle.api.services.BuildServiceRegistration;
Expand Down Expand Up @@ -46,7 +47,7 @@ public static <T> Action<T> noop() {
}

public static SourceSetContainer getJavaSourceSets(Project project) {
return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
return project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
}

public static void maybeConfigure(TaskContainer tasks, String name, Action<? super Task> config) {
Expand Down