Search in sources :

Example 6 with ThriftProgramParser

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);
}
Also used : ProgramParser(net.morimekta.providence.reflect.parser.ProgramParser) ThriftProgramParser(net.morimekta.providence.reflect.parser.ThriftProgramParser) TypeLoader(net.morimekta.providence.reflect.TypeLoader) File(java.io.File) ThriftProgramParser(net.morimekta.providence.reflect.parser.ThriftProgramParser) FileManager(net.morimekta.providence.generator.util.FileManager) Before(org.junit.Before)

Example 7 with ThriftProgramParser

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;
}
Also used : TypeLoader(net.morimekta.providence.reflect.TypeLoader) IOException(java.io.IOException) TreeSet(java.util.TreeSet) CProgram(net.morimekta.providence.reflect.contained.CProgram) ArgumentException(net.morimekta.console.args.ArgumentException) File(java.io.File) ThriftProgramParser(net.morimekta.providence.reflect.parser.ThriftProgramParser) PService(net.morimekta.providence.descriptor.PService)

Aggregations

File (java.io.File)7 ThriftProgramParser (net.morimekta.providence.reflect.parser.ThriftProgramParser)7 Before (org.junit.Before)5 FileInputStream (java.io.FileInputStream)4 ProgramType (net.morimekta.providence.model.ProgramType)4 TypeLoader (net.morimekta.providence.reflect.TypeLoader)3 ProgramConverter (net.morimekta.providence.reflect.util.ProgramConverter)3 ProgramRegistry (net.morimekta.providence.reflect.util.ProgramRegistry)3 IOException (java.io.IOException)2 TreeSet (java.util.TreeSet)2 FileManager (net.morimekta.providence.generator.util.FileManager)2 ProgramParser (net.morimekta.providence.reflect.parser.ProgramParser)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1