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 isShareCaches();
default boolean ideSync() {
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);
}
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.artifacts.Dependency;
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 net.fabricmc.loom.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
import net.fabricmc.loom.configuration.processors.JarProcessor;
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder;
import net.fabricmc.loom.util.DeprecationHelper;
/**
* This is the public api available exposed to build scripts.
*/
public interface LoomGradleExtensionAPI {
File getAccessWidener();
@ApiStatus.Internal
DeprecationHelper getDeprecationHelper();
void setAccessWidener(File file);
RegularFileProperty getAccessWidenerPath();
void setShareCaches(boolean shareCaches);
boolean isShareCaches();
default void shareCaches() {
setShareCaches(true);
@Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "0.11")
default File getAccessWidener() {
getDeprecationHelper().replaceWithInLoom0_11("accessWidener", "accessWidenerPath");
return getAccessWidenerPath().getAsFile().getOrNull();
}
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();
@ -70,13 +119,35 @@ public interface LoomGradleExtensionAPI {
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);
@ -85,7 +156,22 @@ public interface LoomGradleExtensionAPI {
@ApiStatus.Experimental
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;
import org.gradle.api.Action;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.util.PatternSet;
import org.jetbrains.annotations.ApiStatus;
@ApiStatus.Experimental
public interface MixinApExtensionAPI {
Property<String> getDefaultRefmapName();
/**
* Apply Mixin AP to sourceSet.
* @param sourceSet the sourceSet that applies Mixin AP.
* @param refmapName the output ref-map name. By default this will
* be {@link net.fabricmc.loom.LoomGradleExtension#getRefmapName()}
* @param refmapName the output ref-map name. By default this will be {@link #getDefaultRefmapName()}
* @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
* of {@code sourceSet}.

View File

@ -44,7 +44,7 @@ public final class MixinRefmapHelper {
private MixinRefmapHelper() { }
public static boolean addRefmapName(Project project, Path outputPath) {
MixinApExtension mixin = LoomGradleExtension.get(project).getMixinApExtension();
MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
File output = outputPath.toFile();
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) {
MixinApExtension mixin = LoomGradleExtension.get(project).getMixinApExtension();
MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
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) {
MixinApExtension mixin = LoomGradleExtension.get(project).getMixinApExtension();
MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA)
.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) {
MixinApExtension mixin = LoomGradleExtension.get(project).getMixinApExtension();
MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA)
.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) {
MixinApExtension mixin = LoomGradleExtension.get(project).getMixinApExtension();
MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.SCALA)
.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"));
SetupIntelijRunConfigs.setup(project);
extension.getRemapArchives().finalizeValue();
// Enables the default mod remapper
if (extension.isRemapMod()) {
if (extension.getRemapArchives().get()) {
RemapConfiguration.setupDefaultRemap(project);
} else {
Jar jarTask = (Jar) project.getTasks().getByName("jar");
@ -144,7 +145,7 @@ public final class CompileConfiguration {
System.setProperty("log4j.skipJansi", "true");
project.getLogger().info("Configuring compiler arguments for Java");
MixinApExtension mixinApExtension = LoomGradleExtension.get(project).getMixinApExtension();
MixinApExtension mixinApExtension = LoomGradleExtension.get(project).getMixin();
mixinApExtension.init();
new JavaApInvoker(project).configureMixin();

View File

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

View File

@ -77,14 +77,15 @@ public class AccessWidenerJarProcessor implements JarProcessor {
@Override
public void setup() {
LoomGradleExtension loomGradleExtension = LoomGradleExtension.get(project);
File awPath = loomGradleExtension.getAccessWidenerPath().get().getAsFile();
if (!loomGradleExtension.getAccessWidener().exists()) {
throw new RuntimeException("Could not find access widener file @ " + loomGradleExtension.getAccessWidener().getAbsolutePath());
if (!awPath.exists()) {
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);
} catch (IOException e) {
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 {
if (getExtension().isShareCaches() && !getExtension().isRootProject() && versionManifestJson.exists() && !isRefreshDeps()) {
if (getExtension().getShareRemapCaches().get() && !getExtension().isRootProject() && versionManifestJson.exists() && !isRefreshDeps()) {
return;
}
@ -145,10 +145,10 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
Optional<ManifestVersion.Versions> optionalVersion = Optional.empty();
if (getExtension().getCustomManifest() != null) {
if (getExtension().getCustomMinecraftManifest().isPresent()) {
ManifestVersion.Versions customVersion = new ManifestVersion.Versions();
customVersion.id = minecraftVersion;
customVersion.url = getExtension().getCustomManifest();
customVersion.url = getExtension().getCustomMinecraftManifest().get();
optionalVersion = Optional.of(customVersion);
getProject().getLogger().lifecycle("Using custom minecraft manifest");
}
@ -212,7 +212,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
}
private boolean hasRecentValidManifest() throws IOException {
if (getExtension().getCustomManifest() != null) {
if (getExtension().getCustomMinecraftManifest().isPresent()) {
return false;
}
@ -233,7 +233,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
}
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;
}

View File

@ -177,11 +177,13 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
LoomGradleExtension extension = getExtension();
if (extension.getAccessWidener() != null) {
extension.addJarProcessor(new AccessWidenerJarProcessor(getProject()));
if (extension.getAccessWidenerPath().isPresent()) {
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);
processorManager.setupProcessors();

View File

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

View File

@ -24,17 +24,14 @@
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.NamedDomainObjectContainer;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
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.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.LayeredMappingSpecBuilder;
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingsDependency;
import net.fabricmc.loom.util.DeprecationHelper;
/**
* This class implements the public extension api.
*/
public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionAPI {
protected final List<LoomDecompiler> decompilers = new ArrayList<>();
protected final List<JarProcessor> jarProcessors = new ArrayList<>();
protected final DeprecationHelper deprecationHelper;
protected final ListProperty<LoomDecompiler> decompilers;
protected final ListProperty<JarProcessor> jarProcessors;
protected final ConfigurableFileCollection log4jConfigs;
protected File accessWidener = null;
protected boolean shareCaches = false;
protected String refmapName = null;
protected boolean remapMod = true;
protected String customManifest;
protected final RegularFileProperty accessWidener;
protected final Property<Boolean> shareCaches;
protected final Property<Boolean> remapArchives;
protected final Property<String> customManifest;
private NamedDomainObjectContainer<RunConfigSettings> runConfigs;
protected LoomGradleExtensionApiImpl(Project project, LoomFiles directories) {
this.runConfigs = project.container(RunConfigSettings.class,
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.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
public File getAccessWidener() {
public DeprecationHelper getDeprecationHelper() {
return deprecationHelper;
}
@Override
public RegularFileProperty getAccessWidenerPath() {
return accessWidener;
}
@Override
public void setAccessWidener(File file) {
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() {
public Property<Boolean> getShareRemapCaches() {
return shareCaches;
}
@Override
public List<LoomDecompiler> getDecompilers() {
public ListProperty<LoomDecompiler> getGameDecompilers() {
return decompilers;
}
@Override
public void addDecompiler(LoomDecompiler decompiler) {
Objects.requireNonNull(decompiler, "Decompiler cannot be null");
decompilers.add(decompiler);
}
@Override
public List<JarProcessor> getJarProcessors() {
public ListProperty<JarProcessor> getGameJarProcessors() {
return jarProcessors;
}
@Override
public void addJarProcessor(JarProcessor processor) {
Objects.requireNonNull(processor, "Jar processor cannot be null");
jarProcessors.add(processor);
}
@Override
public Dependency layered(Action<LayeredMappingSpecBuilder> action) {
LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder();
@ -120,24 +111,8 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
}
@Override
public String getRefmapName() {
if (refmapName == null || refmapName.isEmpty()) {
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;
public Property<Boolean> getRemapArchives() {
return remapArchives;
}
@Override
@ -155,24 +130,13 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
return log4jConfigs;
}
@Override
public boolean isRemapMod() {
return remapMod;
}
@Override
public void mixin(Action<MixinApExtensionAPI> action) {
action.execute(getMixinApExtension());
action.execute(getMixin());
}
@Override
public void setCustomManifest(String customManifest) {
Objects.requireNonNull(customManifest, "Custom manifest cannot be null");
this.customManifest = customManifest;
}
@Override
public String getCustomManifest() {
public Property<String> getCustomMinecraftManifest() {
return customManifest;
}
@ -180,8 +144,6 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
protected abstract LoomFiles getFiles();
protected abstract MixinApExtension getMixinApExtension();
// This is here to ensure that LoomGradleExtensionApiImpl compiles without any unimplemented methods
private final class EnsureCompile extends LoomGradleExtensionApiImpl {
private EnsureCompile() {
@ -189,6 +151,11 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
throw new RuntimeException();
}
@Override
public DeprecationHelper getDeprecationHelper() {
throw new RuntimeException("Yeah... something is really wrong");
}
@Override
protected Project getProject() {
throw new RuntimeException("Yeah... something is really wrong");
@ -200,7 +167,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
}
@Override
protected MixinApExtension getMixinApExtension() {
public MixinApExtension getMixin() {
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) {
super(project, files);
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.unmappedMods = project.files();
}
@ -164,7 +165,7 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
}
@Override
public MixinApExtension getMixinApExtension() {
public MixinApExtension getMixin() {
return this.mixinApExtension;
}
}

View File

@ -34,6 +34,7 @@ import org.gradle.api.InvalidUserDataException;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.plugins.ExtraPropertiesExtension;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.util.PatternSet;
@ -57,13 +58,13 @@ public interface MixinApExtension extends MixinApExtensionAPI {
*/
final class MixinInformationContainer {
private final SourceSet sourceSet;
private final String refmapName;
private final Provider<String> refmapName;
private Stream<String> mixinJsonNames;
final PatternSet mixinJsonPattern;
public MixinInformationContainer(@NotNull SourceSet sourceSet,
@NotNull String refmapName,
@NotNull Provider<String> refmapName,
@NotNull PatternSet mixinJsonPattern) {
this.sourceSet = sourceSet;
this.refmapName = refmapName;
@ -88,7 +89,7 @@ public interface MixinApExtension extends MixinApExtensionAPI {
@NotNull
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.Project;
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.util.PatternSet;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.MixinApExtensionAPI;
public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
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
public void add(SourceSet sourceSet, String refmapName, Action<PatternSet> action) {
@ -51,14 +57,14 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
@Override
public void add(String sourceSetName, String refmapName, Action<PatternSet> action) {
// try to find sourceSet with name sourceSetName in this project
SourceSet sourceSet = getProject().getConvention().getPlugin(JavaPluginConvention.class)
.getSourceSets().findByName(sourceSetName);
add(sourceSetName, getProject().provider(() -> refmapName), action);
}
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);
action.execute(pattern);
}
@ -70,8 +76,7 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
@Override
public void add(SourceSet sourceSet, Action<PatternSet> action) {
LoomGradleExtension extension = LoomGradleExtension.get(getProject());
add(sourceSet, extension.getRefmapName(), action);
add(sourceSet, getDefaultRefmapName(), action);
}
@Override
@ -81,8 +86,7 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
@Override
public void add(String sourceSetName, Action<PatternSet> action) {
LoomGradleExtension extension = LoomGradleExtension.get(getProject());
add(sourceSetName, extension.getRefmapName(), action);
add(sourceSetName, getDefaultRefmapName(), action);
}
@Override
@ -90,6 +94,18 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
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
private final class EnsureCompile extends MixinApExtensionApiImpl {
private EnsureCompile() {
@ -103,7 +119,12 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
}
@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");
}
}

View File

@ -33,11 +33,16 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.inject.Inject;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.UnknownTaskException;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.plugins.BasePluginConvention;
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.SourceSet;
import org.gradle.api.tasks.util.PatternSet;
@ -46,10 +51,14 @@ import org.jetbrains.annotations.NotNull;
public class MixinApExtensionImpl extends MixinApExtensionApiImpl implements MixinApExtension {
private boolean isDefault;
private final Project project;
private final Property<String> defaultRefmapName;
@Inject
public MixinApExtensionImpl(Project project) {
this.isDefault = true;
this.project = project;
this.defaultRefmapName = project.getObjects().property(String.class)
.convention(project.provider(this::getDefaultMixinRefmapName));
}
@Override
@ -58,7 +67,18 @@ public class MixinApExtensionImpl extends MixinApExtensionApiImpl implements Mix
}
@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"));
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 net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants;
public abstract class AbstractLoomTask extends DefaultTask {
public AbstractLoomTask() {
setGroup("fabric");
setGroup(Constants.TaskGroup.FABRIC);
}
@Internal

View File

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

View File

@ -56,7 +56,6 @@ public class GenerateSourcesTask extends AbstractLoomTask {
public GenerateSourcesTask(LoomDecompiler decompiler) {
this.decompiler = decompiler;
setGroup("fabric");
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.providers.mappings.MappingsProviderImpl;
import net.fabricmc.loom.decompilers.fernflower.FabricFernFlowerDecompiler;
import net.fabricmc.loom.util.Constants;
public final class LoomTasks {
private LoomTasks() {
@ -50,7 +51,7 @@ public final class LoomTasks {
tasks.register("remapJar", RemapJarTask.class, t -> {
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."));
@ -65,24 +66,24 @@ public final class LoomTasks {
tasks.register("genIdeaWorkspace", GenIdeaProjectTask.class, t -> {
t.setDescription("Generates an IntelliJ IDEA workspace from this project.");
t.dependsOn("idea", "downloadAssets");
t.setGroup("ide");
t.setGroup(Constants.TaskGroup.IDE);
});
tasks.register("genEclipseRuns", GenEclipseRunsTask.class, t -> {
t.setDescription("Generates Eclipse run configurations for this project.");
t.dependsOn("downloadAssets");
t.setGroup("ide");
t.setGroup(Constants.TaskGroup.IDE);
});
tasks.register("cleanEclipseRuns", CleanEclipseRunsTask.class, t -> {
t.setDescription("Removes Eclipse run configurations for this project.");
t.setGroup("ide");
t.setGroup(Constants.TaskGroup.IDE);
});
tasks.register("vscode", GenVsCodeProjectTask.class, t -> {
t.setDescription("Generates VSCode launch configurations.");
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 -> {
t.setDescription("Starts the '" + config.getConfigName() + "' run configuration");
t.setGroup("fabric");
if (config.getEnvironment().equals("client")) {
t.dependsOn("downloadAssets");
@ -136,7 +136,9 @@ public final class LoomTasks {
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();
// decompiler will be passed to the constructor of GenerateSourcesTask
GenerateSourcesTask generateSourcesTask = tasks.register(taskName, GenerateSourcesTask.class, decompiler).get();

View File

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

View File

@ -117,4 +117,12 @@ public class Constants {
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() {
buildGradle() << '''
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 {

View File

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

View File

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

View File

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

View File

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

View File

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