Skip to content

Commit

Permalink
[vendordeps] handle null keysets better
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty committed Sep 15, 2024
1 parent c5e7751 commit 7425883
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package edu.wpi.first.nativeutils.vendordeps;

public enum VendorParsingError {
MissingName,
MissingCppDeps,
MissingJniDeps,
MissingJavaDeps,
NoMavenUrl,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package edu.wpi.first.nativeutils.vendordeps;

import org.gradle.tooling.BuildException;

public class VendorParsingException extends Exception {
public VendorParsingException(String file, VendorParsingError error) {
switch (error) {
case NoMavenUrl:
System.err.println("The vendordep " + file + " is missing the required maven url.");
break;

case MissingCppDeps:
System.err.println("The vendordep " + file + " is missing the required C++ dependencies key.");
System.err.println("If you would not like to declare any Cpp deps use an empty list.");
break;

case MissingJniDeps:
System.err.println("The vendordep " + file + " is missing the required Jni dependencies key.");
System.err.println("If you would not like to declare any Jni deps use an empty list.");
break;

case MissingJavaDeps:
System.err.println("The vendordep " + file + " is missing the required Java dependencies key.");
System.err.println("If you would not like to declare any Java deps use an empty list.");
break;

default:
throw new BuildException(
"Unhandled case in VendorParsingException. This is a bug and should be reported",
new Exception());
}
}

// should only be called if we don't have access to a name yet
public VendorParsingException(VendorParsingError error) {
switch (error) {
case MissingName:
System.err.println("One of the vendordep files does not have a name");
break;

default:
throw new BuildException(
"Unhandled case in VendorParsingException. This is a bug and should be reported",
new Exception());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.provider.Property;
import org.gradle.nativeplatform.plugins.NativeComponentPlugin;
import org.gradle.tooling.BuildException;

import com.google.gson.Gson;

Expand Down Expand Up @@ -165,7 +166,11 @@ public void loadFrom(File directory) {
for (File f : vendorFiles(directory)) {
JsonDependency dep = parse(f);
if (dep != null) {
load(dep);
try {
load(dep);
} catch(Exception e) {
throw new BuildException("Failed to load dependency", e);
}
}
}
}
Expand All @@ -182,7 +187,7 @@ private JsonDependency parse(File f) {
}
}

private void load(JsonDependency dep) {
private void load(JsonDependency dep) throws VendorParsingException {
// Don"t double-add a dependency!
if (dependencySet.findByName(dep.uuid) != null) {
return;
Expand All @@ -191,40 +196,56 @@ private void load(JsonDependency dep) {
NamedJsonDependency namedDep = new NamedJsonDependency(dep.uuid, dep);
dependencySet.add(namedDep);

if (dep.mavenUrls != null) {
// Enumerate all group ids
Set<String> groupIds = new HashSet<>();
for (CppArtifact cpp : dep.cppDependencies) {
groupIds.add(cpp.groupId);
}
for (JniArtifact jni : dep.jniDependencies) {
groupIds.add(jni.groupId);
}
for (JavaArtifact java : dep.javaDependencies) {
groupIds.add(java.groupId);
}
if (dep.extraGroupIds != null) {
for (String groupId : dep.extraGroupIds) {
groupIds.add(groupId);
}
if (dep.name == null) {
throw new VendorParsingException(VendorParsingError.MissingName);
}
String filename = dep.name;

if (dep.mavenUrls == null) {
throw new VendorParsingException(filename, VendorParsingError.NoMavenUrl);
}

// Enumerate all group ids
Set<String> groupIds = new HashSet<>();
if (dep.cppDependencies == null) {
throw new VendorParsingException(filename, VendorParsingError.MissingCppDeps);
}
for (CppArtifact cpp : dep.cppDependencies) {
groupIds.add(cpp.groupId);
}
if (dep.jniDependencies == null) {
throw new VendorParsingException(filename, VendorParsingError.MissingJniDeps);
}
for (JniArtifact jni : dep.jniDependencies) {
groupIds.add(jni.groupId);
}
if (dep.javaDependencies == null) {
throw new VendorParsingException(filename, VendorParsingError.MissingJavaDeps);
}
for (JavaArtifact java : dep.javaDependencies) {
groupIds.add(java.groupId);
}
if (dep.extraGroupIds != null) {
for (String groupId : dep.extraGroupIds) {
groupIds.add(groupId);
}
}

int i = 0;
for (String url : dep.mavenUrls) {
boolean found = false;
int i = 0;
for (String url : dep.mavenUrls) {
boolean found = false;

for (VendorMavenRepo machingRepo : vendorRepos.matching(x -> x.getUrl().equals(url))) {
found = true;
machingRepo.getAllowedGroupIds().addAll(groupIds);
}
for (VendorMavenRepo machingRepo : vendorRepos.matching(x -> x.getUrl().equals(url))) {
found = true;
machingRepo.getAllowedGroupIds().addAll(groupIds);
}

// // Only add if the maven doesn"t yet exist.
if (!found) {
String name = dep.uuid + "_" + i++;
log.info("Registering vendor dep maven: " + name + " on project " + project.getPath());
VendorMavenRepo repo = project.getObjects().newInstance(VendorMavenRepo.class, name, url, groupIds);
vendorRepos.add(repo);
}
// // Only add if the maven doesn"t yet exist.
if (!found) {
String name = dep.uuid + "_" + i++;
log.info("Registering vendor dep maven: " + name + " on project " + project.getPath());
VendorMavenRepo repo = project.getObjects().newInstance(VendorMavenRepo.class, name, url, groupIds);
vendorRepos.add(repo);
}
}
}
Expand Down

0 comments on commit 7425883

Please sign in to comment.