|
27 | 27 | import net.kyori.indra.git.internal.IndraGitExtensionImpl;
|
28 | 28 | import net.kyori.indra.git.internal.IndraGitService;
|
29 | 29 | import net.kyori.indra.git.task.RequireClean;
|
30 |
| -import org.gradle.api.InvalidUserDataException; |
31 |
| -import org.gradle.api.Plugin; |
| 30 | +import net.kyori.mammoth.ProjectOrSettingsPlugin; |
32 | 31 | import org.gradle.api.Project;
|
33 | 32 | import org.gradle.api.initialization.Settings;
|
34 | 33 | import org.gradle.api.invocation.Gradle;
|
35 | 34 | import org.gradle.api.plugins.ExtensionContainer;
|
| 35 | +import org.gradle.api.plugins.PluginContainer; |
36 | 36 | import org.gradle.api.provider.Provider;
|
| 37 | +import org.gradle.api.tasks.TaskContainer; |
37 | 38 | import org.jetbrains.annotations.NotNull;
|
38 | 39 |
|
39 | 40 | /**
|
40 | 41 | * A plugin that exposes any git repository that might be in a project.
|
41 | 42 | *
|
42 | 43 | * @since 2.0.0
|
43 | 44 | */
|
44 |
| -public class GitPlugin implements Plugin<Object> { |
| 45 | +public class GitPlugin implements ProjectOrSettingsPlugin { |
45 | 46 | private static final String EXTENSION_NAME = "indraGit";
|
46 | 47 | private static final String SERVICE_NAME = "indraGitService";
|
47 | 48 |
|
48 | 49 | public static final String REQUIRE_CLEAN_TASK = "requireClean";
|
49 | 50 |
|
50 | 51 | @Override
|
51 |
| - public void apply(final @NotNull Object projectOrSettings) { |
52 |
| - if (projectOrSettings instanceof Project) { |
53 |
| - this.applyToProject((Project) projectOrSettings); |
54 |
| - } else if (projectOrSettings instanceof Settings) { |
55 |
| - this.applyToSettings((Settings) projectOrSettings); |
56 |
| - } else { |
57 |
| - throw new InvalidUserDataException("The net.kyori.indra.git plugin can only be applied to a Project or Settings!"); |
58 |
| - } |
59 |
| - } |
60 |
| - |
61 |
| - private void applyToProject(final @NotNull Project project) { |
62 |
| - final Provider<IndraGitService> service = this.applyCommon( |
63 |
| - project.getGradle(), |
64 |
| - project.getExtensions(), |
65 |
| - project.getRootDir(), |
66 |
| - project.getProjectDir(), |
67 |
| - project.getDisplayName() |
68 |
| - ); |
| 52 | + public void applyToProject( |
| 53 | + final @NotNull Project target, |
| 54 | + final @NotNull PluginContainer plugins, |
| 55 | + final @NotNull ExtensionContainer extensions, |
| 56 | + final @NotNull TaskContainer tasks |
| 57 | + ) { |
| 58 | + final Provider<IndraGitService> service = this.applyCommon( |
| 59 | + target.getGradle(), |
| 60 | + extensions, |
| 61 | + target.getRootDir(), |
| 62 | + target.getProjectDir(), |
| 63 | + target.getDisplayName() |
| 64 | + ); |
69 | 65 |
|
70 | 66 | // And create a task, but don't ever make it run
|
71 |
| - project.getTasks().register(REQUIRE_CLEAN_TASK, RequireClean.class, task -> { |
| 67 | + tasks.register(REQUIRE_CLEAN_TASK, RequireClean.class, task -> { |
72 | 68 | task.getGit().set(service);
|
73 | 69 | });
|
74 | 70 | }
|
75 | 71 |
|
76 |
| - private void applyToSettings(final @NotNull Settings settings) { |
77 |
| - this.applyCommon( |
78 |
| - settings.getGradle(), |
79 |
| - settings.getExtensions(), |
80 |
| - settings.getRootDir(), |
81 |
| - settings.getRootDir(), |
82 |
| - "settings" |
83 |
| - ); |
| 72 | + @Override |
| 73 | + public void applyToSettings( |
| 74 | + final @NotNull Settings target, |
| 75 | + final @NotNull PluginContainer plugins, |
| 76 | + final @NotNull ExtensionContainer extensions |
| 77 | + ) { |
| 78 | + this.applyCommon( |
| 79 | + target.getGradle(), |
| 80 | + extensions, |
| 81 | + target.getRootDir(), |
| 82 | + target.getRootDir(), |
| 83 | + "settings" |
| 84 | + ); |
84 | 85 | }
|
85 | 86 |
|
86 | 87 | private Provider<IndraGitService> applyCommon(final @NotNull Gradle gradle, final ExtensionContainer extensions, final File rootDir, final File projectDir, final String displayName) {
|
|
0 commit comments