From 5cde431ef1dea58acd59e03e8d3753cde45bc531 Mon Sep 17 00:00:00 2001 From: Thad House Date: Fri, 7 Apr 2023 21:51:23 -0700 Subject: [PATCH] Add ability to inject gradle scripts from vendor deps We need to think if the security connotations with this are too great, and if this opens too big of a hole --- .../vendordeps/WPIVendorDepsExtension.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/java/edu/wpi/first/nativeutils/vendordeps/WPIVendorDepsExtension.java b/src/main/java/edu/wpi/first/nativeutils/vendordeps/WPIVendorDepsExtension.java index da4badea..7e14615d 100644 --- a/src/main/java/edu/wpi/first/nativeutils/vendordeps/WPIVendorDepsExtension.java +++ b/src/main/java/edu/wpi/first/nativeutils/vendordeps/WPIVendorDepsExtension.java @@ -7,6 +7,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import javax.inject.Inject; @@ -17,6 +18,7 @@ import org.gradle.api.model.ObjectFactory; import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.provider.Property; +import org.gradle.api.resources.TextResourceFactory; import org.gradle.internal.os.OperatingSystem; import org.gradle.nativeplatform.plugins.NativeComponentPlugin; @@ -54,10 +56,13 @@ public WPIJavaVendorDepsExtension getJavaVendor() { return javaVendor; } + private final TextResourceFactory resources; + @Inject public WPIVendorDepsExtension(Project project) { this.log = ETLoggerFactory.INSTANCE.create("WPIVendorDeps"); this.project = project; + this.resources = project.getResources().getText(); hwSimulation = project.hasProperty(HW_SIM_SWITCH_PROPERTY); dependencySet = project.getObjects().namedDomainObjectSet(NamedJsonDependency.class); vendorRepos = project.getObjects().namedDomainObjectSet(VendorMavenRepo.class); @@ -112,6 +117,32 @@ public static List vendorFiles(File directory) { } } + private void applyIncludedGradleScriptInternal(NamedJsonDependency dep) { + String includedGradle = dep.getDependency().includedGradle; + if (includedGradle == null) { + return; + } + + if (includedGradle.isBlank()) { + return; + } + + project.apply(Map.of("from", resources.fromString(includedGradle))); + } + + public void applyIncludedGradleScripts() { + for (NamedJsonDependency dep : dependencySet) { + applyIncludedGradleScriptInternal(dep); + } + } + + public void applyIncludedGradleScript(String uuid) { + NamedJsonDependency dep = dependencySet.findByName(uuid); + if (dep != null) { + applyIncludedGradleScriptInternal(dep); + } + } + public void loadAll() { loadFrom(vendorFolder(project)); } @@ -266,6 +297,7 @@ public static class JsonDependency { public JavaArtifact[] javaDependencies; public JniArtifact[] jniDependencies; public CppArtifact[] cppDependencies; + public String includedGradle; } public static class NamedJsonDependency implements Named {