diff --git a/src/main/java/net/fabricmc/loom/build/nesting/MergedNestedJarProvider.java b/src/main/java/net/fabricmc/loom/build/nesting/MergedNestedJarProvider.java index 1b93b44..61b05eb 100644 --- a/src/main/java/net/fabricmc/loom/build/nesting/MergedNestedJarProvider.java +++ b/src/main/java/net/fabricmc/loom/build/nesting/MergedNestedJarProvider.java @@ -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 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)); + } } diff --git a/src/main/java/net/fabricmc/loom/build/nesting/NestedJarPathProvider.java b/src/main/java/net/fabricmc/loom/build/nesting/NestedJarPathProvider.java index badb265..184617f 100644 --- a/src/main/java/net/fabricmc/loom/build/nesting/NestedJarPathProvider.java +++ b/src/main/java/net/fabricmc/loom/build/nesting/NestedJarPathProvider.java @@ -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())); diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/MergedNestedJarProviderTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/MergedNestedJarProviderTest.groovy new file mode 100644 index 0000000..a31d9cc --- /dev/null +++ b/src/test/groovy/net/fabricmc/loom/test/unit/MergedNestedJarProviderTest.groovy @@ -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 files = null + + @Override + Collection provide() { + return files + } + + @Override + void prepare(Project project) { + files = [] + } + } +}