Skip to content

Commit 2facc46

Browse files
authored
[vendordeps] Add an option to update vendordeps (#218)
Resolves wpilibsuite/GradleRIO#746 Requires #217
1 parent ed183f5 commit 2facc46

File tree

3 files changed

+58
-29
lines changed

3 files changed

+58
-29
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ java {
1313

1414
allprojects {
1515
group = "edu.wpi.first"
16-
version = "2025.4.0"
16+
version = "2025.5.0"
1717

1818
if (project.hasProperty('publishVersion')) {
1919
version = project.publishVersion

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

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.gradle.api.tasks.TaskAction;
1313
import org.gradle.api.tasks.options.Option;
1414

15+
import com.google.gson.Gson;
1516
import com.google.gson.GsonBuilder;
1617

1718
import de.undercouch.gradle.tasks.download.DownloadAction;
@@ -22,6 +23,7 @@
2223
*/
2324
public class VendorDepTask extends DefaultTask {
2425
private String url;
26+
private boolean update;
2527
private DownloadAction downloadAction = new DownloadAction(getProject());
2628
private WPIVendorDepsExtension wpiExt = getProject().getExtensions().getByType(WPIVendorDepsExtension.class);
2729

@@ -30,41 +32,68 @@ public void setURL(String url) {
3032
this.url = url;
3133
}
3234

35+
@Option(option = "update", description = "Update the existing vendordeps")
36+
public void update() {
37+
update = true;
38+
}
39+
3340
/**
3441
* Installs the JSON file
3542
* @throws java.io.IOException throws on ioexception
3643
*/
3744
@TaskAction
3845
public void install() throws IOException {
39-
String filename = findFileName(url);
40-
Path dest = computeDest(filename);
41-
if (url.startsWith("FRCLOCAL/")) {
42-
getLogger().info("Locally fetching $filename");
43-
copyLocal(filename, dest);
44-
} else {
45-
getLogger().info("Remotely fetching " + filename);
46-
downloadRemote(dest);
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;
46+
if (update) {
47+
Gson gson = new GsonBuilder().create();
48+
Object property = getProject().findProperty(WPIVendorDepsExtension.NATIVEUTILS_VENDOR_FOLDER_PROPERTY);
49+
File destfolder = new File(property != null ? (String)property : WPIVendorDepsExtension.DEFAULT_VENDORDEPS_FOLDER_NAME);
50+
File[] vendordeps = destfolder.listFiles();
51+
if (vendordeps != null) {
52+
for (File vendordep : vendordeps) {
53+
getLogger().info("Remotely fetching " + vendordep.toString());
54+
BufferedReader reader = Files.newBufferedReader(Path.of(vendordep.getPath()));
55+
var jsonUrl = gson.fromJson(reader, JsonDependency.class).jsonUrl;
56+
if (jsonUrl != null) {
57+
url = jsonUrl;
58+
downloadRemote(Path.of(vendordep.getPath()));
59+
} else {
60+
getLogger().warn("Couldn't get jsonUrl for " + vendordep);
61+
}
5662
}
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());
63+
} else {
64+
getLogger().warn("Couldn't update vendordeps, invalid directory.");
65+
}
6666
} else {
67-
getLogger().warn("Failed to rename file " + file.toString() + " to " + newFile.toString());
67+
String filename = findFileName(url);
68+
Path dest = computeDest(filename);
69+
if (url.startsWith("FRCLOCAL/")) {
70+
getLogger().info("Locally fetching $filename");
71+
copyLocal(filename, dest);
72+
} else {
73+
getLogger().info("Remotely fetching " + filename);
74+
downloadRemote(dest);
75+
}
76+
77+
var destString = dest.toString();
78+
String newFilename;
79+
try (BufferedReader reader = Files.newBufferedReader(dest)) {
80+
newFilename = new GsonBuilder().create().fromJson(reader, JsonDependency.class).fileName;
81+
if (newFilename == null) {
82+
getLogger().warn("Couldn't find fileName field in " + destString + "\n Aborting");
83+
return;
84+
}
85+
} catch (IOException e) {
86+
throw new RuntimeException(e);
87+
}
88+
File file = new File(destString);
89+
int lastPathSeparator = dest.toString().lastIndexOf('/');
90+
File newFile = new File(dest.toString().substring(0, lastPathSeparator + 1) + newFilename);
91+
boolean didRename = file.renameTo(newFile);
92+
if (didRename) {
93+
getLogger().info("Succesfully renamed " + file.toString() + " to " + newFile.toString());
94+
} else {
95+
getLogger().warn("Failed to rename file " + file.toString() + " to " + newFile.toString());
96+
}
6897
}
6998
}
7099

testing/cpp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import edu.wpi.first.nativeutils.vendordeps.WPIVendorDepsPlugin
33

44
plugins {
55
id "cpp"
6-
id "edu.wpi.first.NativeUtils" version "2025.4.0"
6+
id "edu.wpi.first.NativeUtils" version "2025.5.0"
77
}
88

99
nativeUtils.addWpiNativeUtils()

0 commit comments

Comments
 (0)