Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vendordeps] Use fileName in download #217

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,27 @@ public void install() throws IOException {
getLogger().info("Remotely fetching " + filename);
downloadRemote(dest);
}

var destString = dest.toString();
String newFilename;
try (BufferedReader reader = Files.newBufferedReader(dest)) {
newFilename = new GsonBuilder().create().fromJson(reader, JsonDependency.class).fileName;
spacey-sooty marked this conversation as resolved.
Show resolved Hide resolved
if (newFilename == null) {
getLogger().warn("Couldn't find fileName field in " + destString + "\n Aborting");
return;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
File file = new File(destString);
int lastPathSeparator = dest.toString().lastIndexOf('/');
File newFile = new File(dest.toString().substring(0, lastPathSeparator + 1) + newFilename);
boolean didRename = file.renameTo(newFile);
if (didRename) {
getLogger().info("Succesfully renamed " + file.toString() + " to " + newFile.toString());
} else {
getLogger().warn("Failed to rename file " + file.toString() + " to " + newFile.toString());
}
}

/**
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