public SpecificCompiler(Protocol protocol, DateTimeLogicalTypeImplementation dateTimeLogicalTypeImplementation) { this(dateTimeLogicalTypeImplementation); // enqueue all types for (Schema s : protocol.getTypes()) { enqueue(s); } this.protocol = protocol; }
@Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { if (args.isEmpty() || args.size() > 2 || isRequestingHelp(args)) { err.println("Usage: idl2schemata [idl] [outdir]"); err.println(""); err.println("If an output directory is not specified, " + "outputs to current directory."); return -1; } boolean pretty = true; Idl parser = new Idl(new File(args.get(0))); File outputDirectory = getOutputDirectory(args); for (Schema schema : parser.CompilationUnit().getTypes()) { print(schema, outputDirectory, pretty); } parser.close(); return 0; }
@Test public void testForwardReference() { ReflectData data = ReflectData.get(); Protocol reflected = data.getProtocol(C.class); Protocol reparsed = Protocol.parse(reflected.toString()); assertEquals(reflected, reparsed); assert(reparsed.getTypes().contains(data.getSchema(A.class))); assert(reparsed.getTypes().contains(data.getSchema(B1.class))); assert(reparsed.getTypes().contains(data.getSchema(B2.class))); assert(reparsed.getTypes().contains(data.getSchema(X.class))); }
private Protocol addStringType(Protocol p) { if (stringType != StringType.String) return p; Protocol newP = new Protocol(p.getName(), p.getDoc(), p.getNamespace()); Map<Schema,Schema> types = new LinkedHashMap<>(); for (Map.Entry<String, Object> a : p.getObjectProps().entrySet()) { newP.addProp(a.getKey(), a.getValue()); } // annotate types Collection<Schema> namedTypes = new LinkedHashSet<>(); for (Schema s : p.getTypes()) namedTypes.add(addStringType(s, types)); newP.setTypes(namedTypes); // annotate messages Map<String,Message> newM = newP.getMessages(); for (Message m : p.getMessages().values()) newM.put(m.getName(), m.isOneWay() ? newP.createMessage(m, addStringType(m.getRequest(), types)) : newP.createMessage(m, addStringType(m.getRequest(), types), addStringType(m.getResponse(), types), addStringType(m.getErrors(), types))); return newP; }
final Collection<Schema> types = protocol.getTypes();
throw new ParseException(); for (Schema s : importProtocol.getTypes()) names.put(s.getFullName(), s); p.getMessages().putAll(importProtocol.getMessages());
public SpecificCompiler(Protocol protocol) { // enqueue all types for (Schema s : protocol.getTypes()) { enqueue(s); } this.protocol = protocol; }
public SpecificCompiler(Protocol protocol) { // enqueue all types for (Schema s : protocol.getTypes()) { enqueue(s); } this.protocol = protocol; }
private void publishSchemasAndAttachMvnIdToProtocol(final Protocol protocol, final boolean addMvnId) throws IOException { Collection<Schema> types = protocol.getTypes(); Set<String> typeNames = Sets.newHashSetWithExpectedSize(types.size()); for (Schema schema : types) { String fullName = schema.getFullName(); if (!typeNames.add(fullName)) { continue; } if (addMvnId) { attachMavenId(schema); } String targetName = fullName.replace('.', File.separatorChar) + ".avsc"; Path destinationFile = generatedAvscTarget.toPath().resolve(targetName); Path parent = destinationFile.getParent(); if (parent != null) { Files.createDirectories(parent); } Files.write(destinationFile, schema.toString().getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } }
Idl parser = new Idl(idl, cl); Protocol protocol = parser.CompilationUnit(); for (Schema s : protocol.getTypes()) { if (s.getProp("mvnId") != null) { continue;
@Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { if (args.isEmpty() || args.size() > 2 || isRequestingHelp(args)) { err.println("Usage: idl2schemata [idl] [outdir]"); err.println(""); err.println("If an output directory is not specified, " + "outputs to current directory."); return -1; } boolean pretty = true; Idl parser = new Idl(new File(args.get(0))); File outputDirectory = getOutputDirectory(args); for (Schema schema : parser.CompilationUnit().getTypes()) { print(schema, outputDirectory, pretty); } parser.close(); return 0; }
private void processProtoFile(File sourceFile) { getLogger().info("Processing {}", sourceFile); try { Protocol protocol = Protocol.parse(sourceFile); for (Schema schema : protocol.getTypes()) { String path = schema.getNamespace().replaceAll(Pattern.quote("."), "/"); File schemaFile = new File(getOutputDir(), path + "/" + schema.getName() + "." + SCHEMA_EXTENSION); String schemaJson = schema.toString(true); FileUtils.writeJsonFile(schemaFile, schemaJson); getLogger().debug("Wrote {}", schemaFile.getPath()); } } catch (IOException ex) { throw new GradleException(String.format("Failed to process protocol definition file %s", sourceFile), ex); } } }