Skip to content

Commit

Permalink
Configuration cache support for IDE tasks (#1163)
Browse files Browse the repository at this point in the history
* Configuration cache support for IDE tasks

* Fix some tests
  • Loading branch information
modmuss50 authored Aug 31, 2024
1 parent f3a9a49 commit 543e49d
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 286 deletions.
3 changes: 0 additions & 3 deletions src/main/java/net/fabricmc/loom/LoomGradlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import net.fabricmc.loom.configuration.FabricApiExtension;
import net.fabricmc.loom.configuration.LoomConfigurations;
import net.fabricmc.loom.configuration.MavenPublication;
import net.fabricmc.loom.configuration.ide.IdeConfiguration;
import net.fabricmc.loom.configuration.ide.idea.IdeaConfiguration;
import net.fabricmc.loom.configuration.sandbox.SandboxConfiguration;
import net.fabricmc.loom.decompilers.DecompilerConfiguration;
Expand All @@ -64,7 +63,6 @@ public class LoomGradlePlugin implements BootstrappedPlugin {
LoomTasks.class,
DecompilerConfiguration.class,
IdeaConfiguration.class,
IdeConfiguration.class,
SandboxConfiguration.class
);

Expand All @@ -84,7 +82,6 @@ public void apply(Project project) {
// Apply default plugins
project.apply(ImmutableMap.of("plugin", "java-library"));
project.apply(ImmutableMap.of("plugin", "eclipse"));
project.apply(ImmutableMap.of("plugin", "idea"));

// Setup extensions
project.getExtensions().create(LoomGradleExtensionAPI.class, "loom", LoomGradleExtensionImpl.class, project, LoomFiles.create(project));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ public void run() {
configureDecompileTasks(configContext);
});

finalizedBy("idea", "genIdeaWorkspace");
finalizedBy("eclipse", "genEclipseRuns");
finalizedBy("cleanEclipse", "cleanEclipseRuns");

// Add the "dev" jar to the "namedElements" configuration
getProject().artifacts(artifactHandler -> artifactHandler.add(Configurations.NAMED_ELEMENTS, getTasks().named("jar")));
Expand Down

This file was deleted.

48 changes: 0 additions & 48 deletions src/main/java/net/fabricmc/loom/task/CleanEclipseRunsTask.java

This file was deleted.

77 changes: 65 additions & 12 deletions src/main/java/net/fabricmc/loom/task/GenEclipseRunsTask.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016-2021 FabricMC
* Copyright (c) 2016-2024 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,38 +26,91 @@

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import javax.inject.Inject;

import org.gradle.api.Project;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.gradle.plugins.ide.eclipse.model.EclipseModel;

import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.configuration.ide.RunConfig;
import net.fabricmc.loom.configuration.ide.RunConfigSettings;

public class GenEclipseRunsTask extends AbstractLoomTask {
public abstract class GenEclipseRunsTask extends AbstractLoomTask {
@Nested
protected abstract ListProperty<EclipseRunConfig> getEclipseRunConfigs();

@Inject
public GenEclipseRunsTask() {
getEclipseRunConfigs().set(getProject().provider(() -> getRunConfigs(getProject())));
}

@TaskAction
public void genRuns() throws IOException {
EclipseModel eclipseModel = getProject().getExtensions().getByType(EclipseModel.class);
LoomGradleExtension extension = getExtension();
for (EclipseRunConfig runConfig : getEclipseRunConfigs().get()) {
runConfig.writeLaunchFile();
}
}

private static List<EclipseRunConfig> getRunConfigs(Project project) {
EclipseModel eclipseModel = project.getExtensions().getByType(EclipseModel.class);
LoomGradleExtension extension = LoomGradleExtension.get(project);

List<EclipseRunConfig> runConfigs = new ArrayList<>();

for (RunConfigSettings settings : extension.getRunConfigs()) {
if (!settings.isIdeConfigGenerated()) {
continue;
}

String name = settings.getName();

File configs = new File(getProject().getProjectDir(), eclipseModel.getProject().getName() + "_" + name + ".launch");
RunConfig configInst = RunConfig.runConfig(getProject(), settings);
String config = configInst.fromDummy("eclipse_run_config_template.xml", false, getProject());
final String name = settings.getName();
final File configs = new File(project.getProjectDir(), eclipseModel.getProject().getName() + "_" + name + ".launch");
final RunConfig configInst = RunConfig.runConfig(project, settings);
final String config;

if (!configs.exists()) {
FileUtils.writeStringToFile(configs, config, StandardCharsets.UTF_8);
try {
config = configInst.fromDummy("eclipse_run_config_template.xml", false, project);
} catch (IOException e) {
throw new UncheckedIOException("Failed to generate Eclipse run configuration", e);
}

EclipseRunConfig eclipseRunConfig = project.getObjects().newInstance(EclipseRunConfig.class);
eclipseRunConfig.getLaunchContent().set(config);
eclipseRunConfig.getLaunchFile().set(project.file(configs));
runConfigs.add(eclipseRunConfig);

settings.makeRunDir();
}

return runConfigs;
}

public interface EclipseRunConfig {
@Input
Property<String> getLaunchContent();

@OutputFile
RegularFileProperty getLaunchFile();

default void writeLaunchFile() throws IOException {
Path launchFile = getLaunchFile().get().getAsFile().toPath();

if (Files.notExists(launchFile)) {
Files.writeString(launchFile, getLaunchContent().get(), StandardCharsets.UTF_8);
}
}
}
}
103 changes: 0 additions & 103 deletions src/main/java/net/fabricmc/loom/task/GenIdeaProjectTask.java

This file was deleted.

Loading

0 comments on commit 543e49d

Please sign in to comment.