Skip to content
Open
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
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ dependencies {
compileOnly(workerShared.map { it.output })
privateRuntime.name(workerClasspath.map { it.output })
privateRuntime.name(workerShared.map { it.output })
compileOnly(libs.ideaExtPlugin)

testImplementation(libs.mammoth.test) {
exclude(group = "org.jetbrains", module = "annotations")
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ spotless = "8.0.0"
stylecheck = "0.2.1"

[libraries]
ideaExtPlugin = { module = "gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext", version.ref = "ideaExt" }
mammoth = { module = "net.kyori:mammoth", version.ref = "mammoth" }
pebble = { module = "io.pebbletemplates:pebble", version.ref = "pebble" }
snakeyamlEngine = { module = "org.snakeyaml:snakeyaml-engine", version.ref = "snakeyaml" }
Expand Down
29 changes: 8 additions & 21 deletions src/main/java/net/kyori/blossom/Blossom.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
import java.io.File;
import net.kyori.blossom.internal.BlossomExtensionImpl;
import net.kyori.blossom.internal.BuildParameters;
import net.kyori.blossom.internal.IdeConfigurer;
import net.kyori.blossom.internal.TemplateSetInternal;
import net.kyori.blossom.internal.ide.EclipseIntegration;
import net.kyori.blossom.internal.ide.IdeaIntegration;
import net.kyori.mammoth.ProjectPlugin;
import org.gradle.api.NamedDomainObjectProvider;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.file.Directory;
import org.gradle.api.plugins.ExtensionAware;
import org.gradle.api.plugins.ExtensionContainer;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.PluginContainer;
Expand All @@ -41,11 +41,7 @@
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
import org.gradle.plugins.ide.idea.model.IdeaModel;
import org.gradle.util.GradleVersion;
import org.jetbrains.gradle.ext.ProjectSettings;
import org.jetbrains.gradle.ext.TaskTriggersConfig;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

Expand Down Expand Up @@ -120,23 +116,14 @@ private void registerGenerateAllTask(final Project project, final TaskContainer
task.dependsOn(tasks.withType(GenerateTemplates.class));
});

IdeConfigurer.apply(project, new IdeConfigurer.IdeImportAction() {
@Override
public void idea(final Project project, final IdeaModel idea, final ProjectSettings ideaExtension) {
((ExtensionAware) ideaExtension).getExtensions().getByType(TaskTriggersConfig.class).afterSync(generateTemplates);
project.afterEvaluate(p -> {
final IdeaModel projectIdea = p.getExtensions().getByType(IdeaModel.class);
if (projectIdea.getModule() != null) {
projectIdea.getModule().getGeneratedSourceDirs().addAll(outputDirs.get());
}
});
}
IdeaIntegration.addSynchronizationTask(project, generateTemplates);
EclipseIntegration.addSynchronizationTask(project, generateTemplates);

@Override
public void eclipse(final Project project, final EclipseModel eclipse) {
eclipse.synchronizationTasks(generateTemplates);
IdeaIntegration.apply(project, idea -> project.afterEvaluate(p -> {
if (idea.getModule() != null) {
idea.getModule().getGeneratedSourceDirs().addAll(outputDirs.get());
}
});
}));
}

@Override
Expand Down
122 changes: 0 additions & 122 deletions src/main/java/net/kyori/blossom/internal/IdeConfigurer.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* This file is part of blossom, licensed under the GNU Lesser General Public License.
*
* Copyright (c) 2023 KyoriPowered
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
package net.kyori.blossom.internal.ide;

import java.util.function.Consumer;
import org.gradle.api.Project;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.plugins.ide.eclipse.EclipsePlugin;
import org.gradle.plugins.ide.eclipse.model.EclipseModel;

public final class EclipseIntegration {

private EclipseIntegration() {
}

/**
* Applies the specified configuration action to configure Eclipse projects.
*
* <p>This does not apply the Eclipse plugin, but will perform the action when the plugin is applied.</p>
*
* @param project project to apply to
* @param action the action to perform
*/
public static void apply(final Project project, final Consumer<EclipseModel> action) {
project.getPlugins().withType(EclipsePlugin.class, plugin -> {
final EclipseModel model = project.getExtensions().findByType(EclipseModel.class);
if (model == null) {
return;
}
action.accept(model);
});
}

/**
* Executes a task when Eclipse performs a project synchronization.
*
* @param project project of the task
* @param task the task to perform on synchronization
*/
public static void addSynchronizationTask(final Project project, final TaskProvider<?> task) {
EclipseIntegration.apply(project, (eclipseModel -> eclipseModel.synchronizationTasks(task)));
}
}
100 changes: 100 additions & 0 deletions src/main/java/net/kyori/blossom/internal/ide/IdeaIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* This file is part of blossom, licensed under the GNU Lesser General Public License.
*
* Copyright (c) 2023 KyoriPowered
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
package net.kyori.blossom.internal.ide;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import org.gradle.StartParameter;
import org.gradle.TaskExecutionRequest;
import org.gradle.api.Project;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.internal.DefaultTaskExecutionRequest;
import org.gradle.plugins.ide.idea.IdeaPlugin;
import org.gradle.plugins.ide.idea.model.IdeaModel;

public final class IdeaIntegration {

private IdeaIntegration() {
}

/**
* Get whether Gradle is being invoked through IntelliJ IDEA.
*
* <p>This can be through a project import, or a task execution.</p>
*
* @return whether this is an IntelliJ-based invocation
*/
public static boolean isIdea() {
return Boolean.getBoolean("idea.active");
}

/**
* Get whether Gradle is being invoked through IntelliJ IDEA project synchronization.
*
* @return whether this is an IntelliJ-based synchronization
*/
public static boolean isIdeaSync() {
return Boolean.getBoolean("idea.sync.active");
}

/**
* Applies the specified configuration action to configure Idea projects.
*
* <p>This does not apply the Idea plugin, but will perform the action when the plugin is applied.</p>
*
* @param project project to apply to
* @param action the action to perform
*/
public static void apply(final Project project, final Consumer<IdeaModel> action) {
project.getPlugins().withType(IdeaPlugin.class, plugin -> {
if (!IdeaIntegration.isIdea()) {
return;
}
final IdeaModel model = project.getExtensions().findByType(IdeaModel.class);
if (model == null || model.getProject() == null) {
return;
}
action.accept(model);
});
}

/**
* Executes a task when Idea performs a project synchronization.
*
* @param project project of the task
* @param task the task to perform on synchronization
*/
public static void addSynchronizationTask(final Project project, final TaskProvider<?> task) {
if (!IdeaIntegration.isIdeaSync()) {
return;
}

project.afterEvaluate(p -> {
final StartParameter startParameter = project.getGradle().getStartParameter();
final List<TaskExecutionRequest> taskRequests = new ArrayList<>(startParameter.getTaskRequests());

taskRequests.add(new DefaultTaskExecutionRequest(Collections.singletonList(":" + project.getName() + ":" + task.getName())));
startParameter.setTaskRequests(taskRequests);
});
}
}