use of com.squareup.wire.java.ProfileLoader in project wire by square.
the class WireCompiler method compile.
void compile() throws IOException {
SchemaLoader schemaLoader = new SchemaLoader();
for (String protoPath : protoPaths) {
schemaLoader.addSource(fs.getPath(protoPath));
}
for (String sourceFileName : sourceFileNames) {
schemaLoader.addProto(sourceFileName);
}
Schema schema = schemaLoader.load();
String profileName = emitAndroid ? "android" : "java";
Profile profile = new ProfileLoader(profileName).schema(schema).load();
if (!identifierSet.isEmpty()) {
log.info("Analyzing dependencies of root types.");
schema = schema.prune(identifierSet);
for (String rule : identifierSet.unusedIncludes()) {
log.info("Unused include: " + rule);
}
for (String rule : identifierSet.unusedExcludes()) {
log.info("Unused exclude: " + rule);
}
}
JavaGenerator javaGenerator = JavaGenerator.get(schema).withProfile(profile).withAndroid(emitAndroid).withCompact(emitCompact);
ConcurrentLinkedQueue<Type> types = new ConcurrentLinkedQueue<>();
for (ProtoFile protoFile : schema.protoFiles()) {
// Check if we're skipping files not explicitly named.
if (!sourceFileNames.isEmpty() && !sourceFileNames.contains(protoFile.location().path())) {
if (namedFilesOnly || protoFile.location().path().equals(DESCRIPTOR_PROTO))
continue;
}
types.addAll(protoFile.types());
}
ExecutorService executor = Executors.newCachedThreadPool();
List<Future<Void>> futures = new ArrayList<>(MAX_WRITE_CONCURRENCY);
for (int i = 0; i < MAX_WRITE_CONCURRENCY; ++i) {
futures.add(i, executor.submit(new JavaFileWriter(javaGenerator, types)));
}
executor.shutdown();
try {
for (Future<Void> future : futures) {
future.get();
}
} catch (ExecutionException e) {
throw new IOException(e.getMessage(), e);
} catch (InterruptedException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
Aggregations