use of com.squareup.wire.schema.SchemaException in project wire by square.
the class ProfileLoader method validate.
/** Confirms that {@code protoFiles} link correctly against {@code schema}. */
void validate(Schema schema, ImmutableList<ProfileFileElement> profileFiles) {
List<String> errors = new ArrayList<>();
for (ProfileFileElement profileFile : profileFiles) {
for (TypeConfigElement typeConfig : profileFile.typeConfigs()) {
ProtoType type = importedType(ProtoType.get(typeConfig.type()));
if (type == null)
continue;
Type resolvedType = schema.getType(type);
if (resolvedType == null) {
errors.add(String.format("unable to resolve %s (%s)", type, typeConfig.location()));
continue;
}
String requiredImport = resolvedType.location().path();
if (!profileFile.imports().contains(requiredImport)) {
errors.add(String.format("%s needs to import %s (%s)", typeConfig.location().path(), requiredImport, typeConfig.location()));
}
}
}
if (!errors.isEmpty()) {
throw new SchemaException(errors);
}
}
use of com.squareup.wire.schema.SchemaException in project wire by square.
the class ProfileLoaderTest method missingImport.
@Test
public void missingImport() throws Exception {
RepoBuilder repoBuilder = new RepoBuilder().add("a/b/message.proto", "" + "package a.b;\n" + "message Message {\n" + "}\n").add("a/b/android.wire", "" + "syntax = \"wire2\";\n" + "type a.b.Message {\n" + " target java.lang.Object using com.example.Message#OBJECT_ADAPTER;\n" + "}\n");
try {
repoBuilder.profile("android");
fail();
} catch (SchemaException expected) {
assertThat(expected).hasMessage("a/b/android.wire needs to import a/b/message.proto (/source/a/b/android.wire at 2:1)");
}
}
use of com.squareup.wire.schema.SchemaException in project wire by square.
the class ProfileLoaderTest method unknownType.
@Test
public void unknownType() throws Exception {
RepoBuilder repoBuilder = new RepoBuilder().add("a/b/message.proto", "" + "package a.b;\n" + "message Message {\n" + "}\n").add("a/b/android.wire", "" + "syntax = \"wire2\";\n" + "type a.b.Message2 {\n" + " target java.lang.Object using com.example.Message#OBJECT_ADAPTER;\n" + "}\n");
try {
repoBuilder.profile("android");
fail();
} catch (SchemaException expected) {
assertThat(expected).hasMessage("unable to resolve a.b.Message2 (/source/a/b/android.wire at 2:1)");
}
}
Aggregations