use of net.morimekta.providence.reflect.parser.ThriftProgramParser in project providence by morimekta.
the class JsonGeneratorTest method setUp.
@Before
public void setUp() throws IOException {
out = tmp.newFolder("out");
File inc = tmp.newFolder("includes");
FileManager fileManager = new FileManager(out);
ProgramParser parser = new ThriftProgramParser();
typeLoader = new TypeLoader(ImmutableList.of(inc), parser);
generator = new JsonGenerator(fileManager);
}
use of net.morimekta.providence.reflect.parser.ThriftProgramParser in project providence by morimekta.
the class RPCOptions method getDefinition.
public PService getDefinition() throws ParseException, IOException {
Map<String, File> includeMap = FormatUtils.getIncludeMap(getRc(), includes);
if (service.isEmpty()) {
throw new ArgumentException("Missing service type name");
}
Set<File> rootSet = new TreeSet<File>();
for (File file : includeMap.values()) {
rootSet.add(file.getParentFile());
}
String programName = service.substring(0, service.lastIndexOf("."));
TypeLoader loader = new TypeLoader(rootSet, new ThriftProgramParser());
try {
if (!includeMap.containsKey(programName)) {
throw new ArgumentException("No program " + programName + " found in include path.\n" + "Found: " + Strings.join(", ", new TreeSet<Object>(includeMap.keySet())));
}
loader.load(includeMap.get(programName));
} catch (IOException e) {
throw new ArgumentException(e.getLocalizedMessage());
}
String filePath = includeMap.get(programName).getCanonicalFile().getAbsolutePath();
PService srv = loader.getProgramRegistry().getService(service, null);
if (srv == null) {
CProgram document = loader.getProgramRegistry().registryForPath(filePath).getProgram();
Set<String> services = new TreeSet<>(document.getServices().stream().map(s -> s.getQualifiedName()).collect(Collectors.toSet()));
throw new ArgumentException("Unknown service %s in %s.\n" + "Found %s", service, programName, services.size() == 0 ? "none" : Strings.join(", ", services));
}
return srv;
}
Aggregations