Skip to content

Commit

Permalink
[vendordeps] Use fileName in download
Browse files Browse the repository at this point in the history
Resolves #196

Also makes testing project use vendordeps plugin
  • Loading branch information
spacey-sooty committed Sep 29, 2024
1 parent d08557a commit 54bdaa7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,5 @@ gradle-app.setting
.vscode/

!src/resources/DefFileGenerator.exe

testing/cpp/vendordeps
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -41,6 +45,25 @@ public void install() throws IOException {
getLogger().info("Remotely fetching " + filename);
downloadRemote(dest);
}

var destString = dest.toString();
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");
} else {
getLogger().warn("Failed to rename file");
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion testing/cpp/build.gradle
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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 {
Expand Down

0 comments on commit 54bdaa7

Please sign in to comment.