Configurable remap configs. (#674)

* First pass at configurable remap configs.

* No benefit to making it lazy: https://github.com/gradle/gradle/blob/v7.4.2/subprojects/plugins/src/main/java/org/gradle/api/plugins/BasePlugin.java#L104 ... fixes some stuff to make it work.
This commit is contained in:
modmuss50
2022-06-25 21:38:43 +01:00
committed by GitHub
parent 317c6daedd
commit da2992e7d9
27 changed files with 813 additions and 450 deletions

View File

@@ -0,0 +1,154 @@
/*
* 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.api;
import java.util.Set;
import javax.inject.Inject;
import com.google.common.base.Preconditions;
import org.gradle.api.Named;
import org.gradle.api.NamedDomainObjectProvider;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Internal;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJarConfiguration;
/**
* A {@link Named} object for configuring "proxy" configurations that remap artifacts.
*/
public abstract class RemapConfigurationSettings implements Named {
private final String name;
@Inject
public RemapConfigurationSettings(String name) {
this.name = name;
getTargetConfigurationName().finalizeValueOnRead();
getClientTargetConfigurationName().finalizeValueOnRead();
getOnCompileClasspath().finalizeValueOnRead();
getOnRuntimeClasspath().finalizeValueOnRead();
getPublishingMode().convention(PublishingMode.NONE).finalizeValueOnRead();
}
@Override
public @NotNull String getName() {
return name;
}
/**
* @return The target configuration name
*/
public abstract Property<String> getTargetConfigurationName();
/**
* Optional, only used when split sourcesets are enabled.
* When not present client only entries should go onto the target configuration.
*
* @return The client target configuration name
*/
public abstract Property<String> getClientTargetConfigurationName();
/**
* @return True if this configuration's artifacts should be exposed for compile operations.
*/
public abstract Property<Boolean> getOnCompileClasspath();
/**
* @return True if this configuration's artifacts should be exposed to runtime operations.
*/
public abstract Property<Boolean> getOnRuntimeClasspath();
/**
* @return the {@link PublishingMode} for the configuration.
*/
public abstract Property<PublishingMode> getPublishingMode();
public enum PublishingMode {
NONE,
COMPILE_ONLY(JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME),
RUNTIME_ONLY(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME),
COMPILE_AND_RUNTIME(JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME);
private final Set<String> outgoingConfigurations;
PublishingMode(String... outgoingConfigurations) {
this.outgoingConfigurations = Set.of(outgoingConfigurations);
}
public Set<String> outgoingConfigurations() {
return outgoingConfigurations;
}
}
@Inject
protected abstract Project getProject();
@ApiStatus.Internal
@Internal
public final String getRemappedConfigurationName() {
return getName() + "Mapped";
}
@ApiStatus.Internal
@Internal
public final NamedDomainObjectProvider<Configuration> getSourceConfiguration() {
return getConfigurationByName(getName());
}
@ApiStatus.Internal
@Internal
public final NamedDomainObjectProvider<Configuration> getRemappedConfiguration() {
return getConfigurationByName(getRemappedConfigurationName());
}
@ApiStatus.Internal
@Internal
public final NamedDomainObjectProvider<Configuration> getTargetConfiguration() {
return getConfigurationByName(getTargetConfigurationName().get());
}
@ApiStatus.Internal
@Internal
public final Provider<Configuration> getClientTargetConfiguration() {
return getProject().provider(() -> {
boolean split = LoomGradleExtension.get(getProject()).getMinecraftJarConfiguration().get() == MinecraftJarConfiguration.SPLIT;
Preconditions.checkArgument(split, "Cannot get client target configuration when project is not split");
return getConfigurationByName(getClientTargetConfigurationName().get()).get();
});
}
@Internal
private NamedDomainObjectProvider<Configuration> getConfigurationByName(String name) {
return getProject().getConfigurations().named(name);
}
}