Fix MergedNestedJarProvider not calling the child's prepare

dev/0.11
modmuss50 2021-06-01 18:13:25 +01:00
parent 210938d749
commit 188bbe57d6
3 changed files with 66 additions and 2 deletions

View File

@ -29,12 +29,19 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;
public record MergedNestedJarProvider(NestedJarProvider... parents) implements NestedJarProvider {
import org.gradle.api.Project;
public record MergedNestedJarProvider(NestedJarProvider... children) implements NestedJarProvider {
@Override
public Collection<File> provide() {
return Arrays.stream(parents)
return Arrays.stream(children)
.map(NestedJarProvider::provide)
.flatMap(Collection::stream)
.collect(Collectors.toList());
}
@Override
public void prepare(Project project) {
Arrays.stream(children).forEach(nestedJarProvider -> nestedJarProvider.prepare(project));
}
}

View File

@ -58,6 +58,8 @@ public final class NestedJarPathProvider implements NestedJarProvider {
}
private void validateFiles() {
Preconditions.checkNotNull(files, "null files to nest, was prepare called?");
for (File file : files) {
Preconditions.checkArgument(file.getName().endsWith(".jar"), String.format("Tried to nest %s but it is not a jar", file.getAbsolutePath()));
Preconditions.checkArgument(file.exists(), String.format("Tried to nest jar %s but it does not exist", file.getAbsolutePath()));

View File

@ -0,0 +1,55 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 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.build.nesting.MergedNestedJarProvider
import net.fabricmc.loom.build.nesting.NestedJarProvider
import org.gradle.api.Project
import spock.lang.Specification
class MergedNestedJarProviderTest extends Specification {
def "empty test"() {
given:
def nestedJarProvider = new MergedNestedJarProvider(new TestNestedJarProvider())
when:
nestedJarProvider.prepare(null)
then:
nestedJarProvider.provide() != null
}
private class TestNestedJarProvider implements NestedJarProvider {
private Collection<File> files = null
@Override
Collection<File> provide() {
return files
}
@Override
void prepare(Project project) {
files = []
}
}
}