mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 21:05:58 -05:00
Merge remote-tracking branch 'upstream/dev/0.12' into dev/0.12.0
This commit is contained in:
@@ -27,21 +27,20 @@ package net.fabricmc.loom.api;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gradle.api.Named;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.file.ConfigurableFileCollection;
|
||||
import org.gradle.api.provider.ListProperty;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.fabricmc.loom.util.gradle.SourceSetHelper;
|
||||
import net.fabricmc.loom.util.gradle.SourceSetReference;
|
||||
|
||||
/**
|
||||
* A {@link Named} object for setting mod-related values. The {@linkplain Named#getName() name} should match the mod id.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public abstract class ModSettings implements Named {
|
||||
/**
|
||||
* List of classpath directories, used to populate the `fabric.classPathGroups` Fabric Loader system property.
|
||||
*/
|
||||
public abstract ListProperty<SourceSet> getModSourceSets();
|
||||
|
||||
/**
|
||||
* List of classpath directories, or jar files used to populate the `fabric.classPathGroups` Fabric Loader system property.
|
||||
*/
|
||||
@@ -54,9 +53,37 @@ public abstract class ModSettings implements Named {
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a {@link SourceSet} output directories part of the named mod.
|
||||
* Add {@link SourceSet}'s output directories from the current project to be grouped with the named mod.
|
||||
*/
|
||||
public void sourceSet(SourceSet sourceSet) {
|
||||
getModSourceSets().add(sourceSet);
|
||||
Project project = getProject();
|
||||
|
||||
if (!SourceSetHelper.isSourceSetOfProject(sourceSet, project)) {
|
||||
getProject().getLogger().info("Computing owner project for SourceSet {} as it is not a sourceset of {}", sourceSet.getName(), project.getPath());
|
||||
project = SourceSetHelper.getSourceSetProject(sourceSet);
|
||||
|
||||
if (project == getProject()) {
|
||||
throw new IllegalStateException("isSourceSetOfProject lied, report to loom devs.");
|
||||
}
|
||||
}
|
||||
|
||||
sourceSet(sourceSet, project);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add {@link SourceSet}'s output directories from supplied project to be grouped with the named mod.
|
||||
*/
|
||||
public void sourceSet(SourceSet sourceSet, Project project) {
|
||||
getModSourceSets().add(new SourceSetReference(sourceSet, project));
|
||||
}
|
||||
|
||||
/**
|
||||
* List of classpath directories, used to populate the `fabric.classPathGroups` Fabric Loader system property.
|
||||
* Use the {@link ModSettings#sourceSet} methods to add to this.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public abstract ListProperty<SourceSetReference> getModSourceSets();
|
||||
|
||||
@Inject
|
||||
public abstract Project getProject();
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public final class MavenPublication {
|
||||
continue;
|
||||
} else if (!reportedDeprecation.get() && !LoomGradleExtension.get(project).isForge()) {
|
||||
DeprecationHelper deprecationHelper = LoomGradleExtension.get(project).getDeprecationHelper();
|
||||
deprecationHelper.warn("Loom is applying dependency data manually to publications instead of using a software component (from(components[\"java\"])). This is deprecated and will be removed in Loom 0.12.");
|
||||
deprecationHelper.warn("Loom is applying dependency data manually to publications instead of using a software component (from(components[\"java\"])). This is deprecated and will be removed in Loom 0.13.");
|
||||
reportedDeprecation.set(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ import net.fabricmc.loom.configuration.ide.idea.IdeaSyncTask;
|
||||
import net.fabricmc.loom.configuration.ide.idea.IdeaUtils;
|
||||
import net.fabricmc.loom.configuration.providers.BundleMetadata;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.gradle.SourceSetReference;
|
||||
|
||||
public class RunConfig {
|
||||
public String configName;
|
||||
@@ -174,7 +175,7 @@ public class RunConfig {
|
||||
runConfig.envVariables.putAll(settings.envVariables);
|
||||
runConfig.configName = configName;
|
||||
populate(project, extension, runConfig, environment);
|
||||
runConfig.ideaModuleName = IdeaUtils.getIdeaModuleName(project, sourceSet);
|
||||
runConfig.ideaModuleName = IdeaUtils.getIdeaModuleName(new SourceSetReference(sourceSet, project));
|
||||
runConfig.runDirIdeaUrl = "file://$PROJECT_DIR$/" + runDir;
|
||||
runConfig.runDir = runDir;
|
||||
runConfig.sourceSet = sourceSet;
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.gradle.api.tasks.SourceSet;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftSourceSets;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.OperatingSystem;
|
||||
|
||||
@@ -107,7 +108,11 @@ public final class RunConfigSettings implements Named {
|
||||
this.extension = LoomGradleExtension.get(project);
|
||||
this.ideConfigGenerated = extension.isRootProject();
|
||||
|
||||
source("main");
|
||||
setSource(p -> {
|
||||
final String sourceSetName = MinecraftSourceSets.get(p).getSourceSetForEnv(getEnvironment());
|
||||
return p.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName(sourceSetName);
|
||||
});
|
||||
|
||||
runDir("run");
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ package net.fabricmc.loom.configuration.ide.idea;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
import net.fabricmc.loom.util.gradle.SourceSetReference;
|
||||
|
||||
public class IdeaUtils {
|
||||
public static boolean isIdeaSync() {
|
||||
@@ -46,8 +47,9 @@ public class IdeaUtils {
|
||||
return major > 2021 || (major == 2021 && minor >= 3);
|
||||
}
|
||||
|
||||
public static String getIdeaModuleName(Project project, SourceSet srcs) {
|
||||
String module = project.getName() + "." + srcs.getName();
|
||||
public static String getIdeaModuleName(SourceSetReference reference) {
|
||||
Project project = reference.project();
|
||||
String module = project.getName() + "." + reference.sourceSet().getName();
|
||||
|
||||
while ((project = project.getParent()) != null) {
|
||||
module = project.getName() + "." + module;
|
||||
|
||||
@@ -195,11 +195,6 @@ public abstract sealed class MinecraftSourceSets permits MinecraftSourceSets.Sin
|
||||
.plus(mainSourceSet.getOutput())
|
||||
);
|
||||
|
||||
loomExtension.mixin(mixinExtension -> {
|
||||
// Generate a refmap for mixins in the new source set.
|
||||
mixinExtension.add(clientOnlySourceSet, "client-" + mixinExtension.getDefaultRefmapName().get(), (p) -> { });
|
||||
});
|
||||
|
||||
// Include the client only output in the jars
|
||||
project.getTasks().named(mainSourceSet.getJarTaskName(), Jar.class).configure(jar -> {
|
||||
jar.from(clientOnlySourceSet.getOutput().getClassesDirs());
|
||||
|
||||
@@ -128,9 +128,19 @@ public class MixinExtensionImpl extends MixinExtensionApiImpl implements MixinEx
|
||||
@Override
|
||||
public void init() {
|
||||
if (isDefault) {
|
||||
project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().forEach(this::add);
|
||||
initDefault();
|
||||
}
|
||||
|
||||
isDefault = false;
|
||||
}
|
||||
|
||||
private void initDefault() {
|
||||
project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().forEach(sourceSet -> {
|
||||
if (sourceSet.getName().equals("main")) {
|
||||
add(sourceSet);
|
||||
} else {
|
||||
add(sourceSet, sourceSet.getName() + "-" + getDefaultRefmapName().get());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.gradle.api.tasks.TaskProvider;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJarConfiguration;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftSourceSets;
|
||||
import net.fabricmc.loom.task.launch.GenerateDLIConfigTask;
|
||||
import net.fabricmc.loom.task.launch.GenerateLog4jConfigTask;
|
||||
import net.fabricmc.loom.task.launch.GenerateRemapClasspathTask;
|
||||
@@ -59,6 +58,10 @@ public final class LoomTasks {
|
||||
});
|
||||
tasks.register("generateDLIConfig", GenerateDLIConfigTask.class, t -> {
|
||||
t.setDescription("Generate the DevLaunchInjector config file");
|
||||
|
||||
// Must allow these IDE files to be generated first
|
||||
t.mustRunAfter(tasks.named("eclipse"));
|
||||
t.mustRunAfter(tasks.named("idea"));
|
||||
});
|
||||
tasks.register("generateLog4jConfig", GenerateLog4jConfigTask.class, t -> {
|
||||
t.setDescription("Generate the log4j config file");
|
||||
@@ -153,17 +156,6 @@ public final class LoomTasks {
|
||||
|
||||
extension.getRunConfigs().removeIf(settings -> settings.getName().equals(taskName));
|
||||
});
|
||||
|
||||
// Configure the run config source sets.
|
||||
project.afterEvaluate(p -> {
|
||||
if (!extension.areEnvironmentSourceSetsSplit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
extension.getRunConfigs().configureEach(settings ->
|
||||
settings.source(MinecraftSourceSets.get(project).getSourceSetForEnv(settings.getEnvironment()))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private static void registerLaunchSettings(Project project) {
|
||||
|
||||
@@ -137,7 +137,7 @@ public class Constants {
|
||||
* Constants for versions of dependencies.
|
||||
*/
|
||||
public static final class Versions {
|
||||
public static final String MIXIN_COMPILE_EXTENSIONS = "0.4.7";
|
||||
public static final String MIXIN_COMPILE_EXTENSIONS = "0.5.0";
|
||||
public static final String DEV_LAUNCH_INJECTOR = "0.2.1+build.8";
|
||||
public static final String TERMINAL_CONSOLE_APPENDER = "1.2.0";
|
||||
public static final String JETBRAINS_ANNOTATIONS = "23.0.0";
|
||||
|
||||
@@ -37,8 +37,13 @@ import javax.xml.xpath.XPathExpressionException;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.internal.tasks.DefaultSourceSetOutput;
|
||||
import org.gradle.api.internal.tasks.DefaultTaskDependency;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.SourceSetOutput;
|
||||
import org.gradle.api.tasks.TaskProvider;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.VisibleForTesting;
|
||||
@@ -55,6 +60,42 @@ public final class SourceSetHelper {
|
||||
private SourceSetHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the provided project contains the {@link SourceSet}.
|
||||
*/
|
||||
public static boolean isSourceSetOfProject(SourceSet sourceSet, Project project) {
|
||||
if (System.getProperty("fabric-loom.unit.testing") != null) return true;
|
||||
|
||||
final JavaPluginExtension javaExtension = project.getExtensions().getByType(JavaPluginExtension.class);
|
||||
return javaExtension.getSourceSets().stream()
|
||||
.anyMatch(test -> test == sourceSet); // Ensure we have an identical reference
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to compute the owning project for the {@link SourceSet}
|
||||
*
|
||||
* <p>A bit of a hack, would be nice for this to be added to the Gradle API.
|
||||
*/
|
||||
public static Project getSourceSetProject(SourceSet sourceSet) {
|
||||
final DefaultSourceSetOutput sourceSetOutput = (DefaultSourceSetOutput) sourceSet.getOutput();
|
||||
final DefaultTaskDependency taskDependency = (DefaultTaskDependency) sourceSetOutput.getClassesContributors();
|
||||
Project project = null;
|
||||
|
||||
for (Object object : taskDependency.getMutableValues()) {
|
||||
if (object instanceof Task task) {
|
||||
project = task.getProject();
|
||||
} else if (object instanceof TaskProvider<?> provider) {
|
||||
project = provider.get().getProject();
|
||||
}
|
||||
}
|
||||
|
||||
if (project == null) {
|
||||
throw new NullPointerException("Unable to determine owning project for SourceSet: " + sourceSet.getName());
|
||||
}
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
public static List<File> getClasspath(ModSettings modSettings, Project project) {
|
||||
final List<File> files = new ArrayList<>();
|
||||
|
||||
@@ -66,18 +107,18 @@ public final class SourceSetHelper {
|
||||
return Collections.unmodifiableList(files);
|
||||
}
|
||||
|
||||
public static List<File> getClasspath(SourceSet sourceSet, Project project) {
|
||||
final List<File> classpath = getGradleClasspath(sourceSet);
|
||||
public static List<File> getClasspath(SourceSetReference reference, Project project) {
|
||||
final List<File> classpath = getGradleClasspath(reference);
|
||||
|
||||
classpath.addAll(getIdeaClasspath(sourceSet, project));
|
||||
classpath.addAll(getEclipseClasspath(sourceSet, project));
|
||||
classpath.addAll(getVscodeClasspath(sourceSet, project));
|
||||
classpath.addAll(getIdeaClasspath(reference, project));
|
||||
classpath.addAll(getEclipseClasspath(reference, project));
|
||||
classpath.addAll(getVscodeClasspath(reference, project));
|
||||
|
||||
return classpath;
|
||||
}
|
||||
|
||||
private static List<File> getGradleClasspath(SourceSet sourceSet) {
|
||||
final SourceSetOutput output = sourceSet.getOutput();
|
||||
private static List<File> getGradleClasspath(SourceSetReference reference) {
|
||||
final SourceSetOutput output = reference.sourceSet().getOutput();
|
||||
final File resources = output.getResourcesDir();
|
||||
|
||||
final List<File> classpath = new ArrayList<>();
|
||||
@@ -92,7 +133,7 @@ public final class SourceSetHelper {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public static List<File> getIdeaClasspath(SourceSet sourceSet, Project project) {
|
||||
public static List<File> getIdeaClasspath(SourceSetReference reference, Project project) {
|
||||
final File projectDir = project.getRootDir();
|
||||
final File dotIdea = new File(projectDir, ".idea");
|
||||
|
||||
@@ -116,7 +157,7 @@ public final class SourceSetHelper {
|
||||
outputDirUrl = outputDirUrl.replaceAll("^file:", "");
|
||||
|
||||
final File productionDir = new File(outputDirUrl, "production");
|
||||
final File outputDir = new File(productionDir, IdeaUtils.getIdeaModuleName(project, sourceSet));
|
||||
final File outputDir = new File(productionDir, IdeaUtils.getIdeaModuleName(reference));
|
||||
|
||||
return Collections.singletonList(outputDir);
|
||||
}
|
||||
@@ -126,7 +167,13 @@ public final class SourceSetHelper {
|
||||
final XPath xpath = XPathFactory.newInstance().newXPath();
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
return xpath.evaluate(expression, new InputSource(fis));
|
||||
String result = xpath.evaluate(expression, new InputSource(fis));
|
||||
|
||||
if (result.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (XPathExpressionException e) {
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
@@ -135,7 +182,7 @@ public final class SourceSetHelper {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public static List<File> getEclipseClasspath(SourceSet sourceSet, Project project) {
|
||||
public static List<File> getEclipseClasspath(SourceSetReference reference, Project project) {
|
||||
// Somewhat of a guess, I'm unsure if this is correct for multi-project builds
|
||||
final File projectDir = project.getProjectDir();
|
||||
final File classpath = new File(projectDir, ".classpath");
|
||||
@@ -144,11 +191,11 @@ public final class SourceSetHelper {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return getBinDirClasspath(projectDir, sourceSet);
|
||||
return getBinDirClasspath(projectDir, reference);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public static List<File> getVscodeClasspath(SourceSet sourceSet, Project project) {
|
||||
public static List<File> getVscodeClasspath(SourceSetReference reference, Project project) {
|
||||
// Somewhat of a guess, I'm unsure if this is correct for multi-project builds
|
||||
final File projectDir = project.getProjectDir();
|
||||
final File dotVscode = new File(projectDir, ".vscode");
|
||||
@@ -157,16 +204,16 @@ public final class SourceSetHelper {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return getBinDirClasspath(projectDir, sourceSet);
|
||||
return getBinDirClasspath(projectDir, reference);
|
||||
}
|
||||
|
||||
private static List<File> getBinDirClasspath(File projectDir, SourceSet sourceSet) {
|
||||
private static List<File> getBinDirClasspath(File projectDir, SourceSetReference reference) {
|
||||
final File binDir = new File(projectDir, "bin");
|
||||
|
||||
if (!binDir.exists()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Collections.singletonList(new File(binDir, sourceSet.getName()));
|
||||
return Collections.singletonList(new File(binDir, reference.sourceSet().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2022 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.util.gradle;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
/**
|
||||
* A reference to a {@link SourceSet} from a {@link Project}.
|
||||
*/
|
||||
public record SourceSetReference(SourceSet sourceSet, Project project) {
|
||||
public SourceSetReference {
|
||||
Preconditions.checkArgument(
|
||||
SourceSetHelper.isSourceSetOfProject(sourceSet, project),
|
||||
"SourceSet (%s) does not own to (%s) project".formatted(sourceSet.getName(), project.getName())
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user