Skip to content

Commit c22bf10

Browse files
authored
[vendordeps] Handle null keysets better (#191)
1 parent c5e7751 commit c22bf10

File tree

3 files changed

+109
-32
lines changed

3 files changed

+109
-32
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package edu.wpi.first.nativeutils.vendordeps;
2+
3+
public enum VendorParsingError {
4+
MissingName,
5+
MissingCppDeps,
6+
MissingJniDeps,
7+
MissingJavaDeps,
8+
NoMavenUrl,
9+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package edu.wpi.first.nativeutils.vendordeps;
2+
3+
import org.gradle.tooling.BuildException;
4+
5+
public class VendorParsingException extends Exception {
6+
public VendorParsingException(String file, VendorParsingError error) {
7+
switch (error) {
8+
case NoMavenUrl:
9+
System.err.println("The vendordep " + file + " is missing the required maven url.");
10+
break;
11+
12+
case MissingCppDeps:
13+
System.err.println("The vendordep " + file + " is missing the required C++ dependencies key.");
14+
System.err.println("If you would not like to declare any Cpp deps use an empty list.");
15+
break;
16+
17+
case MissingJniDeps:
18+
System.err.println("The vendordep " + file + " is missing the required Jni dependencies key.");
19+
System.err.println("If you would not like to declare any Jni deps use an empty list.");
20+
break;
21+
22+
case MissingJavaDeps:
23+
System.err.println("The vendordep " + file + " is missing the required Java dependencies key.");
24+
System.err.println("If you would not like to declare any Java deps use an empty list.");
25+
break;
26+
27+
default:
28+
throw new BuildException(
29+
"Unhandled case in VendorParsingException. This is a bug and should be reported",
30+
new Exception());
31+
}
32+
}
33+
34+
// should only be called if we don't have access to a name yet
35+
public VendorParsingException(VendorParsingError error) {
36+
switch (error) {
37+
case MissingName:
38+
System.err.println("One of the vendordep files does not have a name");
39+
break;
40+
41+
default:
42+
throw new BuildException(
43+
"Unhandled case in VendorParsingException. This is a bug and should be reported",
44+
new Exception());
45+
}
46+
}
47+
}

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

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.gradle.api.plugins.JavaPlugin;
2020
import org.gradle.api.provider.Property;
2121
import org.gradle.nativeplatform.plugins.NativeComponentPlugin;
22+
import org.gradle.tooling.BuildException;
2223

2324
import com.google.gson.Gson;
2425

@@ -165,7 +166,11 @@ public void loadFrom(File directory) {
165166
for (File f : vendorFiles(directory)) {
166167
JsonDependency dep = parse(f);
167168
if (dep != null) {
168-
load(dep);
169+
try {
170+
load(dep);
171+
} catch(Exception e) {
172+
throw new BuildException("Failed to load dependency", e);
173+
}
169174
}
170175
}
171176
}
@@ -182,7 +187,7 @@ private JsonDependency parse(File f) {
182187
}
183188
}
184189

185-
private void load(JsonDependency dep) {
190+
private void load(JsonDependency dep) throws VendorParsingException {
186191
// Don"t double-add a dependency!
187192
if (dependencySet.findByName(dep.uuid) != null) {
188193
return;
@@ -191,40 +196,56 @@ private void load(JsonDependency dep) {
191196
NamedJsonDependency namedDep = new NamedJsonDependency(dep.uuid, dep);
192197
dependencySet.add(namedDep);
193198

194-
if (dep.mavenUrls != null) {
195-
// Enumerate all group ids
196-
Set<String> groupIds = new HashSet<>();
197-
for (CppArtifact cpp : dep.cppDependencies) {
198-
groupIds.add(cpp.groupId);
199-
}
200-
for (JniArtifact jni : dep.jniDependencies) {
201-
groupIds.add(jni.groupId);
202-
}
203-
for (JavaArtifact java : dep.javaDependencies) {
204-
groupIds.add(java.groupId);
205-
}
206-
if (dep.extraGroupIds != null) {
207-
for (String groupId : dep.extraGroupIds) {
208-
groupIds.add(groupId);
209-
}
199+
if (dep.name == null) {
200+
throw new VendorParsingException(VendorParsingError.MissingName);
201+
}
202+
String filename = dep.name;
203+
204+
if (dep.mavenUrls == null) {
205+
throw new VendorParsingException(filename, VendorParsingError.NoMavenUrl);
206+
}
207+
208+
// Enumerate all group ids
209+
Set<String> groupIds = new HashSet<>();
210+
if (dep.cppDependencies == null) {
211+
throw new VendorParsingException(filename, VendorParsingError.MissingCppDeps);
212+
}
213+
for (CppArtifact cpp : dep.cppDependencies) {
214+
groupIds.add(cpp.groupId);
215+
}
216+
if (dep.jniDependencies == null) {
217+
throw new VendorParsingException(filename, VendorParsingError.MissingJniDeps);
218+
}
219+
for (JniArtifact jni : dep.jniDependencies) {
220+
groupIds.add(jni.groupId);
221+
}
222+
if (dep.javaDependencies == null) {
223+
throw new VendorParsingException(filename, VendorParsingError.MissingJavaDeps);
224+
}
225+
for (JavaArtifact java : dep.javaDependencies) {
226+
groupIds.add(java.groupId);
227+
}
228+
if (dep.extraGroupIds != null) {
229+
for (String groupId : dep.extraGroupIds) {
230+
groupIds.add(groupId);
210231
}
232+
}
211233

212-
int i = 0;
213-
for (String url : dep.mavenUrls) {
214-
boolean found = false;
234+
int i = 0;
235+
for (String url : dep.mavenUrls) {
236+
boolean found = false;
215237

216-
for (VendorMavenRepo machingRepo : vendorRepos.matching(x -> x.getUrl().equals(url))) {
217-
found = true;
218-
machingRepo.getAllowedGroupIds().addAll(groupIds);
219-
}
238+
for (VendorMavenRepo machingRepo : vendorRepos.matching(x -> x.getUrl().equals(url))) {
239+
found = true;
240+
machingRepo.getAllowedGroupIds().addAll(groupIds);
241+
}
220242

221-
// // Only add if the maven doesn"t yet exist.
222-
if (!found) {
223-
String name = dep.uuid + "_" + i++;
224-
log.info("Registering vendor dep maven: " + name + " on project " + project.getPath());
225-
VendorMavenRepo repo = project.getObjects().newInstance(VendorMavenRepo.class, name, url, groupIds);
226-
vendorRepos.add(repo);
227-
}
243+
// // Only add if the maven doesn"t yet exist.
244+
if (!found) {
245+
String name = dep.uuid + "_" + i++;
246+
log.info("Registering vendor dep maven: " + name + " on project " + project.getPath());
247+
VendorMavenRepo repo = project.getObjects().newInstance(VendorMavenRepo.class, name, url, groupIds);
248+
vendorRepos.add(repo);
228249
}
229250
}
230251
}

0 commit comments

Comments
 (0)