mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 13:37:45 -05:00
Fix incorrect remap configuration names for none main source sets.
This commit is contained in:
@@ -34,6 +34,7 @@ import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.jetbrains.annotations.VisibleForTesting;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.api.RemapConfigurationSettings;
|
||||
@@ -161,7 +162,8 @@ public final class RemapConfigurations {
|
||||
return str.substring(0, 1).toUpperCase(Locale.ROOT) + str.substring(1);
|
||||
}
|
||||
|
||||
private record ConfigurationOption(Function<SourceSet, String> targetNameFunc, boolean compileClasspath, boolean runtimeClasspath, RemapConfigurationSettings.PublishingMode publishingMode) {
|
||||
@VisibleForTesting
|
||||
public record ConfigurationOption(Function<SourceSet, String> targetNameFunc, boolean compileClasspath, boolean runtimeClasspath, RemapConfigurationSettings.PublishingMode publishingMode) {
|
||||
String targetName(SourceSet sourceSet) {
|
||||
return targetNameFunc.apply(sourceSet);
|
||||
}
|
||||
@@ -170,27 +172,25 @@ public final class RemapConfigurations {
|
||||
return targetName(sourceSet) != null;
|
||||
}
|
||||
|
||||
String name(SourceSet sourceSet) {
|
||||
public String name(SourceSet sourceSet) {
|
||||
String targetName = targetName(sourceSet);
|
||||
|
||||
if (targetName == null) {
|
||||
throw new UnsupportedOperationException("Configuration option is not available for sourceset (%s)".formatted(sourceSet.getName()));
|
||||
}
|
||||
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (!SourceSet.MAIN_SOURCE_SET_NAME.equals(sourceSet.getName())) {
|
||||
builder.append(sourceSet.getName());
|
||||
if (targetName.startsWith(sourceSet.getName())) {
|
||||
targetName = targetName.substring(sourceSet.getName().length());
|
||||
}
|
||||
|
||||
if (builder.isEmpty()) {
|
||||
builder.append("mod");
|
||||
} else {
|
||||
builder.append("Mod");
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append("mod");
|
||||
|
||||
if (!SourceSet.MAIN_SOURCE_SET_NAME.equals(sourceSet.getName())) {
|
||||
builder.append(capitalise(sourceSet.getName()));
|
||||
}
|
||||
|
||||
builder.append(capitalise(targetName));
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.test.unit
|
||||
|
||||
import net.fabricmc.loom.api.RemapConfigurationSettings
|
||||
import net.fabricmc.loom.configuration.RemapConfigurations
|
||||
import net.fabricmc.loom.test.util.GradleTestUtil
|
||||
import org.gradle.api.tasks.SourceSet
|
||||
import spock.lang.Specification
|
||||
|
||||
class RemapConfigurationsTest extends Specification {
|
||||
private static final RemapConfigurations.ConfigurationOption IMPLEMENTATION_OPTION = new RemapConfigurations.ConfigurationOption(SourceSet::getImplementationConfigurationName, true, true, RemapConfigurationSettings.PublishingMode.RUNTIME_ONLY)
|
||||
|
||||
def "testmod impl name"() {
|
||||
given:
|
||||
def sourceSet = GradleTestUtil.mockSourceSet("testmod")
|
||||
when:
|
||||
def name = IMPLEMENTATION_OPTION.name(sourceSet)
|
||||
then:
|
||||
name == "modTestmodImplementation"
|
||||
}
|
||||
|
||||
def "main impl name"() {
|
||||
given:
|
||||
def sourceSet = GradleTestUtil.mockSourceSet("main")
|
||||
when:
|
||||
def name = IMPLEMENTATION_OPTION.name(sourceSet)
|
||||
then:
|
||||
name == "modImplementation"
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,15 @@
|
||||
|
||||
package net.fabricmc.loom.test.util
|
||||
|
||||
import org.gradle.api.file.SourceDirectorySet
|
||||
import org.gradle.api.internal.tasks.DefaultSourceSet
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.plugins.ExtensionContainer
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.SourceSet
|
||||
import org.gradle.api.tasks.util.PatternFilterable
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any
|
||||
import static org.mockito.Mockito.mock
|
||||
import static org.mockito.Mockito.when
|
||||
|
||||
@@ -35,4 +42,30 @@ class GradleTestUtil {
|
||||
when(mock.get()).thenReturn(Objects.requireNonNull(value))
|
||||
return mock
|
||||
}
|
||||
|
||||
static SourceSet mockSourceSet(String name) {
|
||||
def sourceSet = new DefaultSourceSet(name, mockObjectFactory()) {
|
||||
final ExtensionContainer extensions = null
|
||||
}
|
||||
return sourceSet
|
||||
}
|
||||
|
||||
static ObjectFactory mockObjectFactory() {
|
||||
def mock = mock(ObjectFactory.class)
|
||||
def mockSourceDirectorySet = mockSourceDirectorySet()
|
||||
when(mock.sourceDirectorySet(any(), any())).thenReturn(mockSourceDirectorySet)
|
||||
return mock
|
||||
}
|
||||
|
||||
static SourceDirectorySet mockSourceDirectorySet() {
|
||||
def mock = mock(SourceDirectorySet.class)
|
||||
def mockPatternFilterable = mockPatternFilterable()
|
||||
when(mock.getFilter()).thenReturn(mockPatternFilterable)
|
||||
return mock
|
||||
}
|
||||
|
||||
static PatternFilterable mockPatternFilterable() {
|
||||
def mock = mock(PatternFilterable.class)
|
||||
return mock
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user