From 7e36979ce114f66e437a86452f7c531d52790953 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Sun, 29 Sep 2024 23:33:21 +0800 Subject: [PATCH] [vendordeps] Use fileName in download Resolves https://github.com/wpilibsuite/native-utils/issues/196 Also makes testing project use vendordeps plugin --- .gitignore | 2 ++ build.gradle | 2 +- .../nativeutils/vendordeps/VendorDepTask.java | 26 +++++++++++++++++++ testing/cpp/build.gradle | 5 +++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 10657010..ece85870 100644 --- a/.gitignore +++ b/.gitignore @@ -222,3 +222,5 @@ gradle-app.setting .vscode/ !src/resources/DefFileGenerator.exe + +testing/cpp/vendordeps diff --git a/build.gradle b/build.gradle index 98343f51..fd3a792c 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ java { allprojects { group = "edu.wpi.first" - version = "2025.3.0" + version = "2025.4.0" if (project.hasProperty('publishVersion')) { version = project.publishVersion diff --git a/src/main/java/edu/wpi/first/nativeutils/vendordeps/VendorDepTask.java b/src/main/java/edu/wpi/first/nativeutils/vendordeps/VendorDepTask.java index a1494e65..b7c8938f 100644 --- a/src/main/java/edu/wpi/first/nativeutils/vendordeps/VendorDepTask.java +++ b/src/main/java/edu/wpi/first/nativeutils/vendordeps/VendorDepTask.java @@ -1,5 +1,6 @@ package edu.wpi.first.nativeutils.vendordeps; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -11,7 +12,10 @@ import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.options.Option; +import com.google.gson.GsonBuilder; + import de.undercouch.gradle.tasks.download.DownloadAction; +import edu.wpi.first.nativeutils.vendordeps.WPIVendorDepsExtension.JsonDependency; /** * A task type for downloading vendordep JSON files from the vendor URL. @@ -41,6 +45,28 @@ public void install() throws IOException { getLogger().info("Remotely fetching " + filename); downloadRemote(dest); } + + var destString = dest.toString(); + System.out.println(destString); + var gson = new GsonBuilder().create(); + String newFilename; + try (BufferedReader reader = Files.newBufferedReader(dest)) { + newFilename = gson.fromJson(reader, JsonDependency.class).fileName; + } catch (IOException e) { + throw new RuntimeException(e); + } + File file = new File(destString); + int lastPathSeperator = dest.toString().lastIndexOf('/'); + File rename = new File(dest.toString().substring(0, lastPathSeperator + 1) + newFilename); + System.out.println(rename.toString()); + boolean didRename = file.renameTo(rename); + if (didRename == true) { + getLogger().info("File Succesfully Renamed"); + System.out.println("File Succesfully Renamed"); + } else { + getLogger().warn("Failed to rename file"); + System.out.println("Failed to rename file"); + } } /** diff --git a/testing/cpp/build.gradle b/testing/cpp/build.gradle index 50f9535a..37070002 100644 --- a/testing/cpp/build.gradle +++ b/testing/cpp/build.gradle @@ -1,8 +1,9 @@ import edu.wpi.first.toolchain.NativePlatforms +import edu.wpi.first.nativeutils.vendordeps.WPIVendorDepsPlugin plugins { id "cpp" - id "edu.wpi.first.NativeUtils" version "2025.3.0" + id "edu.wpi.first.NativeUtils" version "2025.4.0" } nativeUtils.addWpiNativeUtils() @@ -14,6 +15,8 @@ nativeUtils.crossCompilers.getByName(NativePlatforms.roborio).optional = false nativeUtils.crossCompilers.getByName(NativePlatforms.linuxarm32).optional = false nativeUtils.crossCompilers.getByName(NativePlatforms.linuxarm64).optional = false +project.getPlugins().apply(WPIVendorDepsPlugin.class) + model { components { all {