Skip to content

Commit

Permalink
chore: Mark template output as generated in IntelliJ
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Sep 4, 2023
1 parent aa127b5 commit b00ad28
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import com.diffplug.gradle.spotless.FormatExtension
import org.gradle.plugins.ide.eclipse.model.Classpath
import org.gradle.plugins.ide.eclipse.model.SourceFolder
import org.jetbrains.gradle.ext.settings
import org.jetbrains.gradle.ext.taskTriggers

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/net/kyori/blossom/Blossom.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
package net.kyori.blossom;

import java.io.File;
import net.kyori.blossom.internal.BlossomExtensionImpl;
import net.kyori.blossom.internal.BuildParameters;
import net.kyori.blossom.internal.IdeConfigurer;
Expand All @@ -36,6 +37,7 @@
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.PluginContainer;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.TaskProvider;
Expand Down Expand Up @@ -69,7 +71,8 @@ public void apply(
final @NotNull TaskContainer tasks
) {
plugins.withType(JavaBasePlugin.class, $ -> {
this.registerGenerateAllTask(project, tasks);
final SetProperty<File> outputDirs = project.getObjects().setProperty(File.class);
this.registerGenerateAllTask(project, tasks, outputDirs);

final SourceSetContainer sourceSets = extensions.getByType(SourceSetContainer.class);
final NamedDomainObjectProvider<Configuration> blossomRuntimeConfig = this.registerBlossomRuntimeConfig(project.getDependencies(), project.getConfigurations());
Expand All @@ -89,6 +92,7 @@ public void apply(
task.getBaseSet().set(templateSet);
task.getPebbleClasspath().from(blossomRuntimeConfig.map(it -> it.getIncoming().getFiles()));
});
outputDirs.add(internal.getTemplates().getDestinationDirectory().map(Directory::getAsFile));
internal.getTemplates().compiledBy(generateTask, GenerateTemplates::getOutputDir);

// And add the output as a source directory
Expand All @@ -110,7 +114,7 @@ private NamedDomainObjectProvider<Configuration> registerBlossomRuntimeConfig(fi
});
}

private void registerGenerateAllTask(final Project project, final TaskContainer tasks) {
private void registerGenerateAllTask(final Project project, final TaskContainer tasks, final SetProperty<File> outputDirs) {
final TaskProvider<?> generateTemplates = tasks.register("generateTemplates", task -> {
task.dependsOn(tasks.withType(GenerateTemplates.class));
});
Expand All @@ -119,6 +123,12 @@ private void registerGenerateAllTask(final Project project, final TaskContainer
@Override
public void idea(final @NotNull Project project, final @NotNull IdeaModel idea, final @NotNull ProjectSettings ideaExtension) {
((ExtensionAware) ideaExtension).getExtensions().getByType(TaskTriggersConfig.class).afterSync(generateTemplates);
project.afterEvaluate(p -> {
final @Nullable IdeaModel projectIdea = p.getExtensions().getByType(IdeaModel.class);
if (projectIdea.getModule() != null) {
projectIdea.getModule().getGeneratedSourceDirs().addAll(outputDirs.get());
}
});
}

@Override
Expand Down

0 comments on commit b00ad28

Please sign in to comment.