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 30, 2024
1 parent d08557a commit 09efab9
Show file tree
Hide file tree
Showing 4 changed files with 32 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,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;
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

0 comments on commit 09efab9

Please sign in to comment.