Skip to content

Commit ed183f5

Browse files
authored
[vendordeps] Use fileName in download (#217)
Resolves #196 Also makes testing project use vendordeps plugin
1 parent 632a6cc commit ed183f5

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,5 @@ gradle-app.setting
222222
.vscode/
223223

224224
!src/resources/DefFileGenerator.exe
225+
226+
testing/cpp/vendordeps

src/main/java/edu/wpi/first/nativeutils/vendordeps/VendorDepTask.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package edu.wpi.first.nativeutils.vendordeps;
22

3+
import java.io.BufferedReader;
34
import java.io.File;
45
import java.io.IOException;
56
import java.nio.file.Files;
@@ -11,7 +12,10 @@
1112
import org.gradle.api.tasks.TaskAction;
1213
import org.gradle.api.tasks.options.Option;
1314

15+
import com.google.gson.GsonBuilder;
16+
1417
import de.undercouch.gradle.tasks.download.DownloadAction;
18+
import edu.wpi.first.nativeutils.vendordeps.WPIVendorDepsExtension.JsonDependency;
1519

1620
/**
1721
* A task type for downloading vendordep JSON files from the vendor URL.
@@ -41,6 +45,27 @@ public void install() throws IOException {
4145
getLogger().info("Remotely fetching " + filename);
4246
downloadRemote(dest);
4347
}
48+
49+
var destString = dest.toString();
50+
String newFilename;
51+
try (BufferedReader reader = Files.newBufferedReader(dest)) {
52+
newFilename = new GsonBuilder().create().fromJson(reader, JsonDependency.class).fileName;
53+
if (newFilename == null) {
54+
getLogger().warn("Couldn't find fileName field in " + destString + "\n Aborting");
55+
return;
56+
}
57+
} catch (IOException e) {
58+
throw new RuntimeException(e);
59+
}
60+
File file = new File(destString);
61+
int lastPathSeparator = dest.toString().lastIndexOf('/');
62+
File newFile = new File(dest.toString().substring(0, lastPathSeparator + 1) + newFilename);
63+
boolean didRename = file.renameTo(newFile);
64+
if (didRename) {
65+
getLogger().info("Succesfully renamed " + file.toString() + " to " + newFile.toString());
66+
} else {
67+
getLogger().warn("Failed to rename file " + file.toString() + " to " + newFile.toString());
68+
}
4469
}
4570

4671
/**

testing/cpp/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import edu.wpi.first.toolchain.NativePlatforms
2+
import edu.wpi.first.nativeutils.vendordeps.WPIVendorDepsPlugin
23

34
plugins {
45
id "cpp"
@@ -14,6 +15,8 @@ nativeUtils.crossCompilers.getByName(NativePlatforms.roborio).optional = false
1415
nativeUtils.crossCompilers.getByName(NativePlatforms.linuxarm32).optional = false
1516
nativeUtils.crossCompilers.getByName(NativePlatforms.linuxarm64).optional = false
1617

18+
project.getPlugins().apply(WPIVendorDepsPlugin.class)
19+
1720
model {
1821
components {
1922
all {

0 commit comments

Comments
 (0)