|
1 | 1 | package edu.wpi.first.nativeutils.vendordeps;
|
2 | 2 |
|
| 3 | +import java.io.BufferedReader; |
3 | 4 | import java.io.File;
|
4 | 5 | import java.io.IOException;
|
5 | 6 | import java.nio.file.Files;
|
|
11 | 12 | import org.gradle.api.tasks.TaskAction;
|
12 | 13 | import org.gradle.api.tasks.options.Option;
|
13 | 14 |
|
| 15 | +import com.google.gson.GsonBuilder; |
| 16 | + |
14 | 17 | import de.undercouch.gradle.tasks.download.DownloadAction;
|
| 18 | +import edu.wpi.first.nativeutils.vendordeps.WPIVendorDepsExtension.JsonDependency; |
15 | 19 |
|
16 | 20 | /**
|
17 | 21 | * A task type for downloading vendordep JSON files from the vendor URL.
|
@@ -41,6 +45,27 @@ public void install() throws IOException {
|
41 | 45 | getLogger().info("Remotely fetching " + filename);
|
42 | 46 | downloadRemote(dest);
|
43 | 47 | }
|
| 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 | + } |
44 | 69 | }
|
45 | 70 |
|
46 | 71 | /**
|
|
0 commit comments