Use Property in LoomGradleExtension & Move task groups to constants (#445)

* Use Property in LoomGradleExtension

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Fix customMinecraftManifest

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Add deprecation messages, let's wait for the tests to run to fix the tests that are using deprecated apis

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Apply license

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Update src/main/java/net/fabricmc/loom/util/DeprecationHelper.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Fix some tests, move mixinRefmapName -> mixin.defaultRefmapName

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Move back to the api

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Fix some tests

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Apply reviews

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Update src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>
Co-authored-by: modmuss50 <modmuss50@gmail.com>
dev/0.11
shedaniel 2021-07-27 03:08:03 +08:00 committed by GitHub
parent b558ee1a46
commit 75234f4cbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 355 additions and 158 deletions

View File

@ -93,8 +93,6 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI {
boolean isRootProject(); boolean isRootProject();
boolean isShareCaches();
default boolean ideSync() { default boolean ideSync() {
return Boolean.parseBoolean(System.getProperty("idea.sync.active", "false")); return Boolean.parseBoolean(System.getProperty("idea.sync.active", "false"));
} }
@ -104,5 +102,6 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI {
return String.format("https://maven.fabricmc.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar", minecraftVersion); return String.format("https://maven.fabricmc.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar", minecraftVersion);
} }
MixinApExtension getMixinApExtension(); @Override
MixinApExtension getMixin();
} }

View File

@ -31,36 +31,85 @@ import org.gradle.api.Action;
import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.Dependency;
import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import net.fabricmc.loom.api.decompilers.LoomDecompiler; import net.fabricmc.loom.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.configuration.ide.RunConfigSettings; import net.fabricmc.loom.configuration.ide.RunConfigSettings;
import net.fabricmc.loom.configuration.processors.JarProcessor; import net.fabricmc.loom.configuration.processors.JarProcessor;
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder; import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder;
import net.fabricmc.loom.util.DeprecationHelper;
/** /**
* This is the public api available exposed to build scripts. * This is the public api available exposed to build scripts.
*/ */
public interface LoomGradleExtensionAPI { public interface LoomGradleExtensionAPI {
File getAccessWidener(); @ApiStatus.Internal
DeprecationHelper getDeprecationHelper();
void setAccessWidener(File file); RegularFileProperty getAccessWidenerPath();
void setShareCaches(boolean shareCaches); @Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "0.11")
boolean isShareCaches(); default File getAccessWidener() {
getDeprecationHelper().replaceWithInLoom0_11("accessWidener", "accessWidenerPath");
default void shareCaches() { return getAccessWidenerPath().getAsFile().getOrNull();
setShareCaches(true);
} }
List<LoomDecompiler> getDecompilers(); @Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "0.11")
default void setAccessWidener(File file) {
getDeprecationHelper().replaceWithInLoom0_11("accessWidener", "accessWidenerPath");
getAccessWidenerPath().set(file);
}
void addDecompiler(LoomDecompiler decompiler); Property<Boolean> getShareRemapCaches();
List<JarProcessor> getJarProcessors(); @Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "0.11")
default void setShareCaches(boolean shareCaches) {
getDeprecationHelper().replaceWithInLoom0_11("shareCaches", "shareRemapCaches");
getShareRemapCaches().set(shareCaches);
}
void addJarProcessor(JarProcessor processor); @Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "0.11")
default boolean isShareCaches() {
getDeprecationHelper().replaceWithInLoom0_11("shareCaches", "shareRemapCaches");
return getShareRemapCaches().get();
}
default void shareCaches() {
getShareRemapCaches().set(true);
}
ListProperty<LoomDecompiler> getGameDecompilers();
@Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "0.11")
default List<LoomDecompiler> getDecompilers() {
getDeprecationHelper().replaceWithInLoom0_11("decompilers", "gameDecompilers");
return getGameDecompilers().get();
}
default void addDecompiler(LoomDecompiler decompiler) {
getGameDecompilers().add(decompiler);
}
ListProperty<JarProcessor> getGameJarProcessors();
@Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "0.11")
default List<JarProcessor> getJarProcessors() {
getDeprecationHelper().replaceWithInLoom0_11("jarProcessors", "gameJarProcessors");
return getGameJarProcessors().get();
}
default void addJarProcessor(JarProcessor processor) {
getGameJarProcessors().add(processor);
}
ConfigurableFileCollection getLog4jConfigs(); ConfigurableFileCollection getLog4jConfigs();
@ -70,13 +119,35 @@ public interface LoomGradleExtensionAPI {
Dependency layered(Action<LayeredMappingSpecBuilder> action); Dependency layered(Action<LayeredMappingSpecBuilder> action);
String getRefmapName(); @Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "0.11")
default String getRefmapName() {
getDeprecationHelper().replaceWithInLoom0_11("refmapName", "mixin.defaultRefmapName");
return getMixin().getDefaultRefmapName().get();
}
void setRefmapName(String refmapName); @Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "0.11")
default void setRefmapName(String refmapName) {
getDeprecationHelper().replaceWithInLoom0_11("refmapName", "mixin.defaultRefmapName");
getMixin().getDefaultRefmapName().set(refmapName);
}
boolean isRemapMod(); Property<Boolean> getRemapArchives();
void setRemapMod(boolean remapMod); @Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "0.11")
default boolean isRemapMod() {
getDeprecationHelper().replaceWithInLoom0_11("remapMod", "remapArchives");
return getRemapArchives().get();
}
@Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "0.11")
default void setRemapMod(boolean remapMod) {
getDeprecationHelper().replaceWithInLoom0_11("remapMod", "remapArchives");
getRemapArchives().set(remapMod);
}
void runs(Action<NamedDomainObjectContainer<RunConfigSettings>> action); void runs(Action<NamedDomainObjectContainer<RunConfigSettings>> action);
@ -85,7 +156,22 @@ public interface LoomGradleExtensionAPI {
@ApiStatus.Experimental @ApiStatus.Experimental
void mixin(Action<MixinApExtensionAPI> action); void mixin(Action<MixinApExtensionAPI> action);
void setCustomManifest(String customManifest); @ApiStatus.Experimental
MixinApExtensionAPI getMixin();
String getCustomManifest(); Property<String> getCustomMinecraftManifest();
@Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "0.11")
default void setCustomManifest(String customManifest) {
getDeprecationHelper().replaceWithInLoom0_11("customManifest", "customMinecraftManifest");
getCustomMinecraftManifest().set(customManifest);
}
@Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "0.11")
default String getCustomManifest() {
getDeprecationHelper().replaceWithInLoom0_11("customManifest", "customMinecraftManifest");
return getCustomMinecraftManifest().getOrNull();
}
} }

View File

@ -25,17 +25,19 @@
package net.fabricmc.loom.api; package net.fabricmc.loom.api;
import org.gradle.api.Action; import org.gradle.api.Action;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.util.PatternSet; import org.gradle.api.tasks.util.PatternSet;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
@ApiStatus.Experimental @ApiStatus.Experimental
public interface MixinApExtensionAPI { public interface MixinApExtensionAPI {
Property<String> getDefaultRefmapName();
/** /**
* Apply Mixin AP to sourceSet. * Apply Mixin AP to sourceSet.
* @param sourceSet the sourceSet that applies Mixin AP. * @param sourceSet the sourceSet that applies Mixin AP.
* @param refmapName the output ref-map name. By default this will * @param refmapName the output ref-map name. By default this will be {@link #getDefaultRefmapName()}
* be {@link net.fabricmc.loom.LoomGradleExtension#getRefmapName()}
* @param action used for filter the mixin json files. By default this will be all files * @param action used for filter the mixin json files. By default this will be all files
* with name {@code *.mixins.json} that is inside the {@code resources} folder * with name {@code *.mixins.json} that is inside the {@code resources} folder
* of {@code sourceSet}. * of {@code sourceSet}.

View File

@ -44,7 +44,7 @@ public final class MixinRefmapHelper {
private MixinRefmapHelper() { } private MixinRefmapHelper() { }
public static boolean addRefmapName(Project project, Path outputPath) { public static boolean addRefmapName(Project project, Path outputPath) {
MixinApExtension mixin = LoomGradleExtension.get(project).getMixinApExtension(); MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
File output = outputPath.toFile(); File output = outputPath.toFile();
return mixin.getMixinSourceSetsStream().map(sourceSet -> { return mixin.getMixinSourceSetsStream().map(sourceSet -> {

View File

@ -65,7 +65,7 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
} }
protected static Collection<Configuration> getApConfigurations(Project project, Function<String, String> getApConfigNameFunc) { protected static Collection<Configuration> getApConfigurations(Project project, Function<String, String> getApConfigNameFunc) {
MixinApExtension mixin = LoomGradleExtension.get(project).getMixinApExtension(); MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
return mixin.getApConfigurationsStream(getApConfigNameFunc).collect(Collectors.toList()); return mixin.getApConfigurationsStream(getApConfigNameFunc).collect(Collectors.toList());
} }

View File

@ -46,7 +46,7 @@ public class JavaApInvoker extends AnnotationProcessorInvoker<JavaCompile> {
} }
private static Map<SourceSet, JavaCompile> getInvokerTasks(Project project) { private static Map<SourceSet, JavaCompile> getInvokerTasks(Project project) {
MixinApExtension mixin = LoomGradleExtension.get(project).getMixinApExtension(); MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA) return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA)
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((JavaCompile) entry.getValue()))); .collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((JavaCompile) entry.getValue())));
} }

View File

@ -66,7 +66,7 @@ public class KaptApInvoker extends AnnotationProcessorInvoker<JavaCompile> {
} }
private static Map<SourceSet, JavaCompile> getInvokerTasks(Project project) { private static Map<SourceSet, JavaCompile> getInvokerTasks(Project project) {
MixinApExtension mixin = LoomGradleExtension.get(project).getMixinApExtension(); MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA) return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA)
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((JavaCompile) entry.getValue()))); .collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((JavaCompile) entry.getValue())));
} }

View File

@ -47,7 +47,7 @@ public class ScalaApInvoker extends AnnotationProcessorInvoker<ScalaCompile> {
} }
private static Map<SourceSet, ScalaCompile> getInvokerTasks(Project project) { private static Map<SourceSet, ScalaCompile> getInvokerTasks(Project project) {
MixinApExtension mixin = LoomGradleExtension.get(project).getMixinApExtension(); MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.SCALA) return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.SCALA)
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((ScalaCompile) entry.getValue()))); .collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((ScalaCompile) entry.getValue())));
} }

View File

@ -129,9 +129,10 @@ public final class CompileConfiguration {
project.getTasks().getByName("cleanEclipse").finalizedBy(project.getTasks().getByName("cleanEclipseRuns")); project.getTasks().getByName("cleanEclipse").finalizedBy(project.getTasks().getByName("cleanEclipseRuns"));
SetupIntelijRunConfigs.setup(project); SetupIntelijRunConfigs.setup(project);
extension.getRemapArchives().finalizeValue();
// Enables the default mod remapper // Enables the default mod remapper
if (extension.isRemapMod()) { if (extension.getRemapArchives().get()) {
RemapConfiguration.setupDefaultRemap(project); RemapConfiguration.setupDefaultRemap(project);
} else { } else {
Jar jarTask = (Jar) project.getTasks().getByName("jar"); Jar jarTask = (Jar) project.getTasks().getByName("jar");
@ -144,7 +145,7 @@ public final class CompileConfiguration {
System.setProperty("log4j.skipJansi", "true"); System.setProperty("log4j.skipJansi", "true");
project.getLogger().info("Configuring compiler arguments for Java"); project.getLogger().info("Configuring compiler arguments for Java");
MixinApExtension mixinApExtension = LoomGradleExtension.get(project).getMixinApExtension(); MixinApExtension mixinApExtension = LoomGradleExtension.get(project).getMixin();
mixinApExtension.init(); mixinApExtension.init();
new JavaApInvoker(project).configureMixin(); new JavaApInvoker(project).configureMixin();

View File

@ -97,7 +97,7 @@ public class RemapConfiguration {
// TODO what is this for? // TODO what is this for?
Task parentTask = project.getTasks().getByName("build"); Task parentTask = project.getTasks().getByName("build");
if (extension.isShareCaches()) { if (extension.getShareRemapCaches().get()) {
Project rootProject = project.getRootProject(); Project rootProject = project.getRootProject();
if (extension.isRootProject()) { if (extension.isRootProject()) {
@ -154,7 +154,7 @@ public class RemapConfiguration {
}); });
} }
if (extension.isShareCaches()) { if (extension.getShareRemapCaches().get()) {
remapSourcesJarTask.setSourceRemapper(remapper); remapSourcesJarTask.setSourceRemapper(remapper);
} }

View File

@ -77,14 +77,15 @@ public class AccessWidenerJarProcessor implements JarProcessor {
@Override @Override
public void setup() { public void setup() {
LoomGradleExtension loomGradleExtension = LoomGradleExtension.get(project); LoomGradleExtension loomGradleExtension = LoomGradleExtension.get(project);
File awPath = loomGradleExtension.getAccessWidenerPath().get().getAsFile();
if (!loomGradleExtension.getAccessWidener().exists()) { if (!awPath.exists()) {
throw new RuntimeException("Could not find access widener file @ " + loomGradleExtension.getAccessWidener().getAbsolutePath()); throw new RuntimeException("Could not find access widener file @ " + awPath.getAbsolutePath());
} }
inputHash = Checksum.sha256(loomGradleExtension.getAccessWidener()); inputHash = Checksum.sha256(awPath);
try (BufferedReader reader = new BufferedReader(new FileReader(loomGradleExtension.getAccessWidener()))) { try (BufferedReader reader = new BufferedReader(new FileReader(awPath))) {
accessWidenerReader.read(reader); accessWidenerReader.read(reader);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Failed to read project access widener file"); throw new RuntimeException("Failed to read project access widener file");

View File

@ -121,7 +121,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
} }
private void downloadMcJson(boolean offline) throws IOException { private void downloadMcJson(boolean offline) throws IOException {
if (getExtension().isShareCaches() && !getExtension().isRootProject() && versionManifestJson.exists() && !isRefreshDeps()) { if (getExtension().getShareRemapCaches().get() && !getExtension().isRootProject() && versionManifestJson.exists() && !isRefreshDeps()) {
return; return;
} }
@ -145,10 +145,10 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
Optional<ManifestVersion.Versions> optionalVersion = Optional.empty(); Optional<ManifestVersion.Versions> optionalVersion = Optional.empty();
if (getExtension().getCustomManifest() != null) { if (getExtension().getCustomMinecraftManifest().isPresent()) {
ManifestVersion.Versions customVersion = new ManifestVersion.Versions(); ManifestVersion.Versions customVersion = new ManifestVersion.Versions();
customVersion.id = minecraftVersion; customVersion.id = minecraftVersion;
customVersion.url = getExtension().getCustomManifest(); customVersion.url = getExtension().getCustomMinecraftManifest().get();
optionalVersion = Optional.of(customVersion); optionalVersion = Optional.of(customVersion);
getProject().getLogger().lifecycle("Using custom minecraft manifest"); getProject().getLogger().lifecycle("Using custom minecraft manifest");
} }
@ -212,7 +212,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
} }
private boolean hasRecentValidManifest() throws IOException { private boolean hasRecentValidManifest() throws IOException {
if (getExtension().getCustomManifest() != null) { if (getExtension().getCustomMinecraftManifest().isPresent()) {
return false; return false;
} }
@ -233,7 +233,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
} }
private void downloadJars(Logger logger) throws IOException { private void downloadJars(Logger logger) throws IOException {
if (getExtension().isShareCaches() && !getExtension().isRootProject() && minecraftClientJar.exists() && minecraftServerJar.exists() && !isRefreshDeps()) { if (getExtension().getShareRemapCaches().get() && !getExtension().isRootProject() && minecraftClientJar.exists() && minecraftServerJar.exists() && !isRefreshDeps()) {
return; return;
} }

View File

@ -177,11 +177,13 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
LoomGradleExtension extension = getExtension(); LoomGradleExtension extension = getExtension();
if (extension.getAccessWidener() != null) { if (extension.getAccessWidenerPath().isPresent()) {
extension.addJarProcessor(new AccessWidenerJarProcessor(getProject())); extension.getGameJarProcessors().add(new AccessWidenerJarProcessor(getProject()));
} }
JarProcessorManager processorManager = new JarProcessorManager(extension.getJarProcessors()); extension.getAccessWidenerPath().finalizeValue();
extension.getGameJarProcessors().finalizeValue();
JarProcessorManager processorManager = new JarProcessorManager(extension.getGameJarProcessors().get());
extension.setJarProcessorManager(processorManager); extension.setJarProcessorManager(processorManager);
processorManager.setupProcessors(); processorManager.setupProcessors();

View File

@ -36,7 +36,7 @@ public final class DecompilerConfiguration {
public static void setup(Project project) { public static void setup(Project project) {
LoomGradleExtension extension = LoomGradleExtension.get(project); LoomGradleExtension extension = LoomGradleExtension.get(project);
extension.addDecompiler(new FabricFernFlowerDecompiler(project)); extension.getGameDecompilers().add(new FabricFernFlowerDecompiler(project));
extension.addDecompiler(new FabricCFRDecompiler(project)); extension.getGameDecompilers().add(new FabricCFRDecompiler(project));
} }
} }

View File

@ -24,17 +24,14 @@
package net.fabricmc.loom.extension; package net.fabricmc.loom.extension;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.gradle.api.Action; import org.gradle.api.Action;
import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.Dependency;
import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.plugins.BasePluginConvention; import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;
import net.fabricmc.loom.api.MixinApExtensionAPI; import net.fabricmc.loom.api.MixinApExtensionAPI;
import net.fabricmc.loom.api.decompilers.LoomDecompiler; import net.fabricmc.loom.api.decompilers.LoomDecompiler;
@ -45,72 +42,66 @@ import net.fabricmc.loom.configuration.providers.mappings.GradleMappingContext;
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpec; import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpec;
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder; import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder;
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingsDependency; import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingsDependency;
import net.fabricmc.loom.util.DeprecationHelper;
/** /**
* This class implements the public extension api. * This class implements the public extension api.
*/ */
public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionAPI { public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionAPI {
protected final List<LoomDecompiler> decompilers = new ArrayList<>(); protected final DeprecationHelper deprecationHelper;
protected final List<JarProcessor> jarProcessors = new ArrayList<>(); protected final ListProperty<LoomDecompiler> decompilers;
protected final ListProperty<JarProcessor> jarProcessors;
protected final ConfigurableFileCollection log4jConfigs; protected final ConfigurableFileCollection log4jConfigs;
protected final RegularFileProperty accessWidener;
protected File accessWidener = null; protected final Property<Boolean> shareCaches;
protected boolean shareCaches = false; protected final Property<Boolean> remapArchives;
protected String refmapName = null; protected final Property<String> customManifest;
protected boolean remapMod = true;
protected String customManifest;
private NamedDomainObjectContainer<RunConfigSettings> runConfigs; private NamedDomainObjectContainer<RunConfigSettings> runConfigs;
protected LoomGradleExtensionApiImpl(Project project, LoomFiles directories) { protected LoomGradleExtensionApiImpl(Project project, LoomFiles directories) {
this.runConfigs = project.container(RunConfigSettings.class, this.runConfigs = project.container(RunConfigSettings.class,
baseName -> new RunConfigSettings(project, baseName)); baseName -> new RunConfigSettings(project, baseName));
this.decompilers = project.getObjects().listProperty(LoomDecompiler.class)
.empty();
this.jarProcessors = project.getObjects().listProperty(JarProcessor.class)
.empty();
this.log4jConfigs = project.files(directories.getDefaultLog4jConfigFile()); this.log4jConfigs = project.files(directories.getDefaultLog4jConfigFile());
this.accessWidener = project.getObjects().fileProperty();
this.shareCaches = project.getObjects().property(Boolean.class)
.convention(false);
this.remapArchives = project.getObjects().property(Boolean.class)
.convention(true);
this.customManifest = project.getObjects().property(String.class);
this.deprecationHelper = new DeprecationHelper.ProjectBased(project);
} }
@Override @Override
public File getAccessWidener() { public DeprecationHelper getDeprecationHelper() {
return deprecationHelper;
}
@Override
public RegularFileProperty getAccessWidenerPath() {
return accessWidener; return accessWidener;
} }
@Override @Override
public void setAccessWidener(File file) { public Property<Boolean> getShareRemapCaches() {
Objects.requireNonNull(file, "Access widener file cannot be null");
this.accessWidener = file;
}
@Override
public void setShareCaches(boolean shareCaches) {
this.shareCaches = shareCaches;
}
@Override
public boolean isShareCaches() {
return shareCaches; return shareCaches;
} }
@Override @Override
public List<LoomDecompiler> getDecompilers() { public ListProperty<LoomDecompiler> getGameDecompilers() {
return decompilers; return decompilers;
} }
@Override @Override
public void addDecompiler(LoomDecompiler decompiler) { public ListProperty<JarProcessor> getGameJarProcessors() {
Objects.requireNonNull(decompiler, "Decompiler cannot be null");
decompilers.add(decompiler);
}
@Override
public List<JarProcessor> getJarProcessors() {
return jarProcessors; return jarProcessors;
} }
@Override
public void addJarProcessor(JarProcessor processor) {
Objects.requireNonNull(processor, "Jar processor cannot be null");
jarProcessors.add(processor);
}
@Override @Override
public Dependency layered(Action<LayeredMappingSpecBuilder> action) { public Dependency layered(Action<LayeredMappingSpecBuilder> action) {
LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder(); LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder();
@ -120,24 +111,8 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
} }
@Override @Override
public String getRefmapName() { public Property<Boolean> getRemapArchives() {
if (refmapName == null || refmapName.isEmpty()) { return remapArchives;
String defaultRefmapName = getProject().getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json";
getProject().getLogger().info("Could not find refmap definition, will be using default name: " + defaultRefmapName);
refmapName = defaultRefmapName;
}
return refmapName;
}
@Override
public void setRefmapName(String refmapName) {
this.refmapName = refmapName;
}
@Override
public void setRemapMod(boolean remapMod) {
this.remapMod = remapMod;
} }
@Override @Override
@ -155,24 +130,13 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
return log4jConfigs; return log4jConfigs;
} }
@Override
public boolean isRemapMod() {
return remapMod;
}
@Override @Override
public void mixin(Action<MixinApExtensionAPI> action) { public void mixin(Action<MixinApExtensionAPI> action) {
action.execute(getMixinApExtension()); action.execute(getMixin());
} }
@Override @Override
public void setCustomManifest(String customManifest) { public Property<String> getCustomMinecraftManifest() {
Objects.requireNonNull(customManifest, "Custom manifest cannot be null");
this.customManifest = customManifest;
}
@Override
public String getCustomManifest() {
return customManifest; return customManifest;
} }
@ -180,8 +144,6 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
protected abstract LoomFiles getFiles(); protected abstract LoomFiles getFiles();
protected abstract MixinApExtension getMixinApExtension();
// This is here to ensure that LoomGradleExtensionApiImpl compiles without any unimplemented methods // This is here to ensure that LoomGradleExtensionApiImpl compiles without any unimplemented methods
private final class EnsureCompile extends LoomGradleExtensionApiImpl { private final class EnsureCompile extends LoomGradleExtensionApiImpl {
private EnsureCompile() { private EnsureCompile() {
@ -189,6 +151,11 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
throw new RuntimeException(); throw new RuntimeException();
} }
@Override
public DeprecationHelper getDeprecationHelper() {
throw new RuntimeException("Yeah... something is really wrong");
}
@Override @Override
protected Project getProject() { protected Project getProject() {
throw new RuntimeException("Yeah... something is really wrong"); throw new RuntimeException("Yeah... something is really wrong");
@ -200,7 +167,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
} }
@Override @Override
protected MixinApExtension getMixinApExtension() { public MixinApExtension getMixin() {
throw new RuntimeException("Yeah... something is really wrong"); throw new RuntimeException("Yeah... something is really wrong");
} }
} }

View File

@ -63,7 +63,8 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
public LoomGradleExtensionImpl(Project project, LoomFiles files) { public LoomGradleExtensionImpl(Project project, LoomFiles files) {
super(project, files); super(project, files);
this.project = project; this.project = project;
this.mixinApExtension = new MixinApExtensionImpl(project); // Initiate with newInstance to allow gradle to decorate our extension
this.mixinApExtension = project.getObjects().newInstance(MixinApExtensionImpl.class, project);
this.loomFiles = files; this.loomFiles = files;
this.unmappedMods = project.files(); this.unmappedMods = project.files();
} }
@ -164,7 +165,7 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
} }
@Override @Override
public MixinApExtension getMixinApExtension() { public MixinApExtension getMixin() {
return this.mixinApExtension; return this.mixinApExtension;
} }
} }

View File

@ -34,6 +34,7 @@ import org.gradle.api.InvalidUserDataException;
import org.gradle.api.Task; import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
import org.gradle.api.plugins.ExtraPropertiesExtension; import org.gradle.api.plugins.ExtraPropertiesExtension;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.util.PatternSet; import org.gradle.api.tasks.util.PatternSet;
@ -57,13 +58,13 @@ public interface MixinApExtension extends MixinApExtensionAPI {
*/ */
final class MixinInformationContainer { final class MixinInformationContainer {
private final SourceSet sourceSet; private final SourceSet sourceSet;
private final String refmapName; private final Provider<String> refmapName;
private Stream<String> mixinJsonNames; private Stream<String> mixinJsonNames;
final PatternSet mixinJsonPattern; final PatternSet mixinJsonPattern;
public MixinInformationContainer(@NotNull SourceSet sourceSet, public MixinInformationContainer(@NotNull SourceSet sourceSet,
@NotNull String refmapName, @NotNull Provider<String> refmapName,
@NotNull PatternSet mixinJsonPattern) { @NotNull PatternSet mixinJsonPattern) {
this.sourceSet = sourceSet; this.sourceSet = sourceSet;
this.refmapName = refmapName; this.refmapName = refmapName;
@ -88,7 +89,7 @@ public interface MixinApExtension extends MixinApExtensionAPI {
@NotNull @NotNull
public String getRefmapName() { public String getRefmapName() {
return refmapName; return refmapName.get();
} }
} }

View File

@ -28,15 +28,21 @@ import org.gradle.api.Action;
import org.gradle.api.InvalidUserDataException; import org.gradle.api.InvalidUserDataException;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.util.PatternSet; import org.gradle.api.tasks.util.PatternSet;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.MixinApExtensionAPI; import net.fabricmc.loom.api.MixinApExtensionAPI;
public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI { public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
protected abstract Project getProject(); protected abstract Project getProject();
protected abstract PatternSet add0(SourceSet sourceSet, String refmapName);
protected final PatternSet add0(SourceSet sourceSet, String refmapName) {
return add0(sourceSet, getProject().provider(() -> refmapName));
}
protected abstract PatternSet add0(SourceSet sourceSet, Provider<String> refmapName);
@Override @Override
public void add(SourceSet sourceSet, String refmapName, Action<PatternSet> action) { public void add(SourceSet sourceSet, String refmapName, Action<PatternSet> action) {
@ -51,14 +57,14 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
@Override @Override
public void add(String sourceSetName, String refmapName, Action<PatternSet> action) { public void add(String sourceSetName, String refmapName, Action<PatternSet> action) {
// try to find sourceSet with name sourceSetName in this project add(sourceSetName, getProject().provider(() -> refmapName), action);
SourceSet sourceSet = getProject().getConvention().getPlugin(JavaPluginConvention.class)
.getSourceSets().findByName(sourceSetName);
if (sourceSet == null) {
throw new InvalidUserDataException("No sourceSet " + sourceSetName + " was found");
} }
public void add(String sourceSetName, Provider<String> refmapName, Action<PatternSet> action) {
add(resolveSourceSet(sourceSetName), refmapName, action);
}
public void add(SourceSet sourceSet, Provider<String> refmapName, Action<PatternSet> action) {
PatternSet pattern = add0(sourceSet, refmapName); PatternSet pattern = add0(sourceSet, refmapName);
action.execute(pattern); action.execute(pattern);
} }
@ -70,8 +76,7 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
@Override @Override
public void add(SourceSet sourceSet, Action<PatternSet> action) { public void add(SourceSet sourceSet, Action<PatternSet> action) {
LoomGradleExtension extension = LoomGradleExtension.get(getProject()); add(sourceSet, getDefaultRefmapName(), action);
add(sourceSet, extension.getRefmapName(), action);
} }
@Override @Override
@ -81,8 +86,7 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
@Override @Override
public void add(String sourceSetName, Action<PatternSet> action) { public void add(String sourceSetName, Action<PatternSet> action) {
LoomGradleExtension extension = LoomGradleExtension.get(getProject()); add(sourceSetName, getDefaultRefmapName(), action);
add(sourceSetName, extension.getRefmapName(), action);
} }
@Override @Override
@ -90,6 +94,18 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
add(sourceSetName, x -> { }); add(sourceSetName, x -> { });
} }
private SourceSet resolveSourceSet(String sourceSetName) {
// try to find sourceSet with name sourceSetName in this project
SourceSet sourceSet = getProject().getConvention().getPlugin(JavaPluginConvention.class)
.getSourceSets().findByName(sourceSetName);
if (sourceSet == null) {
throw new InvalidUserDataException("No sourceSet " + sourceSetName + " was found");
}
return sourceSet;
}
// This is here to ensure that LoomGradleExtensionApiImpl compiles without any unimplemented methods // This is here to ensure that LoomGradleExtensionApiImpl compiles without any unimplemented methods
private final class EnsureCompile extends MixinApExtensionApiImpl { private final class EnsureCompile extends MixinApExtensionApiImpl {
private EnsureCompile() { private EnsureCompile() {
@ -103,7 +119,12 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
} }
@Override @Override
protected PatternSet add0(SourceSet sourceSet, String refmapName) { public Property<String> getDefaultRefmapName() {
throw new RuntimeException("Yeah... something is really wrong");
}
@Override
protected PatternSet add0(SourceSet sourceSet, Provider<String> refmapName) {
throw new RuntimeException("Yeah... something is really wrong"); throw new RuntimeException("Yeah... something is really wrong");
} }
} }

View File

@ -33,11 +33,16 @@ import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.inject.Inject;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.Task; import org.gradle.api.Task;
import org.gradle.api.UnknownTaskException; import org.gradle.api.UnknownTaskException;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
import org.gradle.api.plugins.BasePluginConvention;
import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.util.PatternSet; import org.gradle.api.tasks.util.PatternSet;
@ -46,10 +51,14 @@ import org.jetbrains.annotations.NotNull;
public class MixinApExtensionImpl extends MixinApExtensionApiImpl implements MixinApExtension { public class MixinApExtensionImpl extends MixinApExtensionApiImpl implements MixinApExtension {
private boolean isDefault; private boolean isDefault;
private final Project project; private final Project project;
private final Property<String> defaultRefmapName;
@Inject
public MixinApExtensionImpl(Project project) { public MixinApExtensionImpl(Project project) {
this.isDefault = true; this.isDefault = true;
this.project = project; this.project = project;
this.defaultRefmapName = project.getObjects().property(String.class)
.convention(project.provider(this::getDefaultMixinRefmapName));
} }
@Override @Override
@ -58,7 +67,18 @@ public class MixinApExtensionImpl extends MixinApExtensionApiImpl implements Mix
} }
@Override @Override
protected PatternSet add0(SourceSet sourceSet, String refmapName) { public Property<String> getDefaultRefmapName() {
return defaultRefmapName;
}
private String getDefaultMixinRefmapName() {
String defaultRefmapName = getProject().getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json";
getProject().getLogger().info("Could not find refmap definition, will be using default name: " + defaultRefmapName);
return defaultRefmapName;
}
@Override
protected PatternSet add0(SourceSet sourceSet, Provider<String> refmapName) {
PatternSet pattern = new PatternSet().setIncludes(Collections.singletonList("*.mixins.json")); PatternSet pattern = new PatternSet().setIncludes(Collections.singletonList("*.mixins.json"));
MixinApExtension.setMixinInformationContainer(sourceSet, new MixinApExtension.MixinInformationContainer(sourceSet, refmapName, pattern)); MixinApExtension.setMixinInformationContainer(sourceSet, new MixinApExtension.MixinInformationContainer(sourceSet, refmapName, pattern));

View File

@ -28,10 +28,11 @@ import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.Internal;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants;
public abstract class AbstractLoomTask extends DefaultTask { public abstract class AbstractLoomTask extends DefaultTask {
public AbstractLoomTask() { public AbstractLoomTask() {
setGroup("fabric"); setGroup(Constants.TaskGroup.FABRIC);
} }
@Internal @Internal

View File

@ -35,13 +35,14 @@ import org.gradle.api.Project;
import org.gradle.api.tasks.JavaExec; import org.gradle.api.tasks.JavaExec;
import net.fabricmc.loom.configuration.ide.RunConfig; import net.fabricmc.loom.configuration.ide.RunConfig;
import net.fabricmc.loom.util.Constants;
public abstract class AbstractRunTask extends JavaExec { public abstract class AbstractRunTask extends JavaExec {
private final RunConfig config; private final RunConfig config;
public AbstractRunTask(Function<Project, RunConfig> configProvider) { public AbstractRunTask(Function<Project, RunConfig> configProvider) {
super(); super();
setGroup("fabric"); setGroup(Constants.TaskGroup.FABRIC);
this.config = configProvider.apply(getProject()); this.config = configProvider.apply(getProject());
setClasspath(config.sourceSet.getRuntimeClasspath()); setClasspath(config.sourceSet.getRuntimeClasspath());

View File

@ -56,7 +56,6 @@ public class GenerateSourcesTask extends AbstractLoomTask {
public GenerateSourcesTask(LoomDecompiler decompiler) { public GenerateSourcesTask(LoomDecompiler decompiler) {
this.decompiler = decompiler; this.decompiler = decompiler;
setGroup("fabric");
getOutputs().upToDateWhen((o) -> false); getOutputs().upToDateWhen((o) -> false);
} }

View File

@ -35,6 +35,7 @@ import net.fabricmc.loom.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.configuration.ide.RunConfigSettings; import net.fabricmc.loom.configuration.ide.RunConfigSettings;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl; import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
import net.fabricmc.loom.decompilers.fernflower.FabricFernFlowerDecompiler; import net.fabricmc.loom.decompilers.fernflower.FabricFernFlowerDecompiler;
import net.fabricmc.loom.util.Constants;
public final class LoomTasks { public final class LoomTasks {
private LoomTasks() { private LoomTasks() {
@ -50,7 +51,7 @@ public final class LoomTasks {
tasks.register("remapJar", RemapJarTask.class, t -> { tasks.register("remapJar", RemapJarTask.class, t -> {
t.setDescription("Remaps the built project jar to intermediary mappings."); t.setDescription("Remaps the built project jar to intermediary mappings.");
t.setGroup("fabric"); t.setGroup(Constants.TaskGroup.FABRIC);
}); });
tasks.register("downloadAssets", DownloadAssetsTask.class, t -> t.setDescription("Downloads required assets for Fabric.")); tasks.register("downloadAssets", DownloadAssetsTask.class, t -> t.setDescription("Downloads required assets for Fabric."));
@ -65,24 +66,24 @@ public final class LoomTasks {
tasks.register("genIdeaWorkspace", GenIdeaProjectTask.class, t -> { tasks.register("genIdeaWorkspace", GenIdeaProjectTask.class, t -> {
t.setDescription("Generates an IntelliJ IDEA workspace from this project."); t.setDescription("Generates an IntelliJ IDEA workspace from this project.");
t.dependsOn("idea", "downloadAssets"); t.dependsOn("idea", "downloadAssets");
t.setGroup("ide"); t.setGroup(Constants.TaskGroup.IDE);
}); });
tasks.register("genEclipseRuns", GenEclipseRunsTask.class, t -> { tasks.register("genEclipseRuns", GenEclipseRunsTask.class, t -> {
t.setDescription("Generates Eclipse run configurations for this project."); t.setDescription("Generates Eclipse run configurations for this project.");
t.dependsOn("downloadAssets"); t.dependsOn("downloadAssets");
t.setGroup("ide"); t.setGroup(Constants.TaskGroup.IDE);
}); });
tasks.register("cleanEclipseRuns", CleanEclipseRunsTask.class, t -> { tasks.register("cleanEclipseRuns", CleanEclipseRunsTask.class, t -> {
t.setDescription("Removes Eclipse run configurations for this project."); t.setDescription("Removes Eclipse run configurations for this project.");
t.setGroup("ide"); t.setGroup(Constants.TaskGroup.IDE);
}); });
tasks.register("vscode", GenVsCodeProjectTask.class, t -> { tasks.register("vscode", GenVsCodeProjectTask.class, t -> {
t.setDescription("Generates VSCode launch configurations."); t.setDescription("Generates VSCode launch configurations.");
t.dependsOn("downloadAssets"); t.dependsOn("downloadAssets");
t.setGroup("ide"); t.setGroup(Constants.TaskGroup.IDE);
}); });
} }
@ -97,7 +98,6 @@ public final class LoomTasks {
tasks.register(taskName, RunGameTask.class, config).configure(t -> { tasks.register(taskName, RunGameTask.class, config).configure(t -> {
t.setDescription("Starts the '" + config.getConfigName() + "' run configuration"); t.setDescription("Starts the '" + config.getConfigName() + "' run configuration");
t.setGroup("fabric");
if (config.getEnvironment().equals("client")) { if (config.getEnvironment().equals("client")) {
t.dependsOn("downloadAssets"); t.dependsOn("downloadAssets");
@ -136,7 +136,9 @@ public final class LoomTasks {
inputJar = outputJar; inputJar = outputJar;
} }
for (LoomDecompiler decompiler : extension.getDecompilers()) { extension.getGameDecompilers().finalizeValue();
for (LoomDecompiler decompiler : extension.getGameDecompilers().get()) {
String taskName = decompiler instanceof FabricFernFlowerDecompiler ? "genSources" : "genSourcesWith" + decompiler.name(); String taskName = decompiler instanceof FabricFernFlowerDecompiler ? "genSources" : "genSourcesWith" + decompiler.name();
// decompiler will be passed to the constructor of GenerateSourcesTask // decompiler will be passed to the constructor of GenerateSourcesTask
GenerateSourcesTask generateSourcesTask = tasks.register(taskName, GenerateSourcesTask.class, decompiler).get(); GenerateSourcesTask generateSourcesTask = tasks.register(taskName, GenerateSourcesTask.class, decompiler).get();

View File

@ -147,7 +147,7 @@ public class RemapJarTask extends Jar {
jarRemapper.scheduleRemap(input, output) jarRemapper.scheduleRemap(input, output)
.supplyAccessWidener((remapData, remapper) -> { .supplyAccessWidener((remapData, remapper) -> {
if (getRemapAccessWidener().getOrElse(false) && extension.getAccessWidener() != null) { if (getRemapAccessWidener().getOrElse(false) && extension.getAccessWidenerPath().isPresent()) {
AccessWidenerJarProcessor accessWidenerJarProcessor = extension.getJarProcessorManager().getByType(AccessWidenerJarProcessor.class); AccessWidenerJarProcessor accessWidenerJarProcessor = extension.getJarProcessorManager().getByType(AccessWidenerJarProcessor.class);
byte[] data; byte[] data;

View File

@ -117,4 +117,12 @@ public class Constants {
private Knot() { private Knot() {
} }
} }
public static final class TaskGroup {
public static final String FABRIC = "fabric";
public static final String IDE = "ide";
private TaskGroup() {
}
}
} }

View File

@ -0,0 +1,86 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 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;
import java.util.concurrent.atomic.AtomicBoolean;
import org.gradle.api.Project;
import org.gradle.api.logging.LogLevel;
import org.gradle.api.logging.configuration.WarningMode;
public interface DeprecationHelper {
default void replaceWithInLoom0_10(String currentName, String newName) {
toBeRemovedIn(currentName, newName, "Loom 0.10");
}
default void replaceWithInLoom0_11(String currentName, String newName) {
toBeRemovedIn(currentName, newName, "Loom 0.11");
}
default void replaceWithInLoom0_12(String currentName, String newName) {
toBeRemovedIn(currentName, newName, "Loom 0.12");
}
default void toBeRemovedIn(String currentName, String newName, String removalVersion) {
warn("The '%s' property has been deprecated, and has been replaced with '%s'. This is scheduled to be removed in %s.".formatted(currentName, newName, removalVersion));
}
Project getProject();
void warn(String warning);
class ProjectBased implements DeprecationHelper {
private final Project project;
private final AtomicBoolean usingDeprecatedApi = new AtomicBoolean(false);
public ProjectBased(Project project) {
this.project = project;
project.getGradle().buildFinished(buildResult -> {
if (usingDeprecatedApi.get()) {
project.getLogger().lifecycle("Deprecated Loom APIs were used in this build, making it incompatible with future versions of Loom. "
+ "Use Gradle warning modes to control the verbosity of the warnings.");
}
});
}
@Override
public Project getProject() {
return project;
}
@Override
public void warn(String warning) {
WarningMode warningMode = getProject().getGradle().getStartParameter().getWarningMode();
getProject().getLogger().log(warningMode == WarningMode.None ? LogLevel.INFO : LogLevel.WARN, warning);
if (warningMode == WarningMode.Fail) {
throw new UnsupportedOperationException(warning);
}
usingDeprecatedApi.set(true);
}
}
}

View File

@ -40,7 +40,7 @@ class CustomManifestTest extends Specification implements ProjectTestTrait {
def filesReady() { def filesReady() {
buildGradle() << ''' buildGradle() << '''
loom { loom {
customManifest = "https://maven.fabricmc.net/net/minecraft/1_18_experimental-snapshot-1.json" customMinecraftManifest = "https://maven.fabricmc.net/net/minecraft/1_18_experimental-snapshot-1.json"
} }
dependencies { dependencies {

View File

@ -19,7 +19,7 @@ repositories {
} }
loom { loom {
accessWidener = file("src/main/resources/modid.accesswidener") accessWidenerPath = file("src/main/resources/modid.accesswidener")
} }
dependencies { dependencies {

View File

@ -69,7 +69,7 @@ jar {
} }
minecraft { minecraft {
accessWidener = file("src/main/resources/modid.accesswidener") accessWidenerPath = file("src/main/resources/modid.accesswidener")
} }
// configure the maven publication // configure the maven publication

View File

@ -68,9 +68,8 @@ java {
} }
loom { loom {
refmapName = "refmap0000.json"
mixin { mixin {
defaultRefmapName = "refmap0000.json"
add(sourceSets["main"], "refmap0001.json") add(sourceSets["main"], "refmap0001.json")
add(sourceSets["mixin"], "refmap0002.json") add(sourceSets["mixin"], "refmap0002.json")
add(sourceSets["mixin1"], "refmap0003.json") { add(sourceSets["mixin1"], "refmap0003.json") {

View File

@ -67,8 +67,8 @@ java {
} }
loom { loom {
refmapName = "default-refmap0000.json"
mixin { mixin {
defaultRefmapName = "default-refmap0000.json"
add(sourceSets["main"], "main-refmap0000.json") add(sourceSets["main"], "main-refmap0000.json")
add(sourceSets["mixin"]) add(sourceSets["mixin"])
} }

View File

@ -40,7 +40,7 @@ allprojects {
} }
loom { loom {
shareCaches = true shareCaches()
} }
java { java {