aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/net/fabricmc/loom/api/mappings
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2021-09-23 00:00:41 +0300
committerGitHub <noreply@github.com>2021-09-22 22:00:41 +0100
commit7d2dad6e4604c3ff0a8521ae1304ef664ebbfc27 (patch)
tree64496cd865c3954e1f77458b446512bf6cc40e88 /src/main/java/net/fabricmc/loom/api/mappings
parentbe17a02e906824ffe855155b94fdea157dfcd08b (diff)
downloadarchitectury-loom-7d2dad6e4604c3ff0a8521ae1304ef664ebbfc27.tar.gz
architectury-loom-7d2dad6e4604c3ff0a8521ae1304ef664ebbfc27.tar.bz2
architectury-loom-7d2dad6e4604c3ff0a8521ae1304ef664ebbfc27.zip
Support a wider range of parameters in FileSpec (#502)
* Support a wider range of parameters in FileSpec Now supports - all Providers (incl. Property) - groovy template string literal (GString) - Path and gradle FileSystemLocation * Use the createFromFile overloads directly * Use charsequence instead of (g)string * Update src/main/java/net/fabricmc/loom/api/mappings/layered/spec/FileSpec.java
Diffstat (limited to 'src/main/java/net/fabricmc/loom/api/mappings')
-rw-r--r--src/main/java/net/fabricmc/loom/api/mappings/layered/spec/FileSpec.java38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/FileSpec.java b/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/FileSpec.java
index 19129e5d..5af12f7d 100644
--- a/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/FileSpec.java
+++ b/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/FileSpec.java
@@ -29,7 +29,9 @@ import java.nio.file.Path;
import java.util.Objects;
import org.gradle.api.artifacts.Dependency;
+import org.gradle.api.file.FileSystemLocation;
import org.gradle.api.file.RegularFileProperty;
+import org.gradle.api.provider.Provider;
import org.jetbrains.annotations.ApiStatus;
import net.fabricmc.loom.api.mappings.layered.MappingContext;
@@ -42,17 +44,35 @@ import net.fabricmc.loom.configuration.providers.mappings.utils.MavenFileSpec;
*/
@ApiStatus.Experimental
public interface FileSpec {
+ /**
+ * Creates a file spec.
+ *
+ * <p>The parameter will be evaluated like this:
+ * <ul>
+ * <li>{@link File}, {@link Path} and {@link FileSystemLocation} will be resolved as local files</li>
+ * <li>{@link Provider} (including {@link org.gradle.api.provider.Property} will recursively be resolved as its current value</li>
+ * <li>{@link CharSequence} (including {@link String} and {@link groovy.lang.GString}) will be resolved as Maven dependencies</li>
+ * <li>{@link Dependency} will be resolved as any dependency</li>
+ * </ul>
+ *
+ * @param o the file notation
+ * @return the created file spec
+ */
static FileSpec create(Object o) {
Objects.requireNonNull(o, "Object cannot be null");
- if (o instanceof String s) {
- return createFromMavenDependency(s);
+ if (o instanceof CharSequence s) {
+ return createFromMavenDependency(s.toString());
} else if (o instanceof Dependency d) {
return createFromDependency(d);
+ } else if (o instanceof Provider<?> p) {
+ return create(p.get());
} else if (o instanceof File f) {
return createFromFile(f);
- } else if (o instanceof RegularFileProperty rfp) {
- return createFromFile(rfp);
+ } else if (o instanceof Path p) {
+ return createFromFile(p);
+ } else if (o instanceof FileSystemLocation l) {
+ return createFromFile(l);
}
throw new UnsupportedOperationException("Cannot create FileSpec from object of type:" + o.getClass().getCanonicalName());
@@ -70,9 +90,17 @@ public interface FileSpec {
return new LocalFileSpec(file);
}
+ static FileSpec createFromFile(FileSystemLocation location) {
+ return createFromFile(location.getAsFile());
+ }
+
+ static FileSpec createFromFile(Path path) {
+ return createFromFile(path.toFile());
+ }
+
// Note resolved instantly, this is not lazy
static FileSpec createFromFile(RegularFileProperty regularFileProperty) {
- return createFromFile(regularFileProperty.getAsFile().get());
+ return createFromFile(regularFileProperty.get());
}
Path get(MappingContext context);