use of com.squareup.wire.java.internal.ProfileFileElement in project wire by square.
the class ProfileLoader method load.
public Profile load() throws IOException {
Set<Location> protoLocations = new LinkedHashSet<>();
for (ProtoFile protoFile : schema.protoFiles()) {
protoLocations.add(protoFile.location());
}
Multimap<Path, String> pathsToAttempt = pathsToAttempt(protoLocations);
ImmutableList<ProfileFileElement> profileFiles = loadProfileFiles(pathsToAttempt);
Profile profile = new Profile(profileFiles);
validate(schema, profileFiles);
return profile;
}
use of com.squareup.wire.java.internal.ProfileFileElement 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.java.internal.ProfileFileElement in project wire by square.
the class ProfileLoader method loadProfileFiles.
private ImmutableList<ProfileFileElement> loadProfileFiles(Multimap<Path, String> pathsToAttempt) throws IOException {
ImmutableList.Builder<ProfileFileElement> result = ImmutableList.builder();
try (Closer closer = Closer.create()) {
for (Map.Entry<Path, Collection<String>> entry : pathsToAttempt.asMap().entrySet()) {
Path base = entry.getKey();
if (Files.isRegularFile(base)) {
FileSystem sourceFs = FileSystems.newFileSystem(base, getClass().getClassLoader());
closer.register(sourceFs);
base = getOnlyElement(sourceFs.getRootDirectories());
}
for (String path : entry.getValue()) {
ProfileFileElement element = loadProfileFile(base, path);
if (element != null)
result.add(element);
}
}
}
return result.build();
}
Aggregations