use of com.squareup.wire.schema.IdentifierSet in project wire by square.
the class WireGenerateSourcesMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
// Add the directory into which generated sources are placed as a compiled source root.
project.addCompileSourceRoot(generatedSourceDirectory);
try {
List<String> directories = protoPaths != null && protoPaths.length > 0 ? Arrays.asList(protoPaths) : Collections.singletonList(protoSourceDirectory);
List<String> protoFilesList = Arrays.asList(protoFiles);
Schema schema = loadSchema(directories, protoFilesList);
Profile profile = loadProfile(schema);
IdentifierSet identifierSet = identifierSet();
if (!identifierSet.isEmpty()) {
schema = retainRoots(identifierSet, schema);
}
JavaGenerator javaGenerator = JavaGenerator.get(schema).withAndroid(emitAndroid).withCompact(emitCompact).withProfile(profile);
for (ProtoFile protoFile : schema.protoFiles()) {
if (!protoFilesList.isEmpty() && !protoFilesList.contains(protoFile.location().path())) {
// Don't emit anything for files not explicitly compiled.
continue;
}
for (Type type : protoFile.types()) {
Stopwatch stopwatch = Stopwatch.createStarted();
TypeSpec typeSpec = javaGenerator.generateType(type);
ClassName javaTypeName = javaGenerator.generatedTypeName(type);
writeJavaFile(javaTypeName, typeSpec, type.location().withPathOnly());
getLog().info(String.format("Generated %s in %s", javaTypeName, stopwatch));
}
}
} catch (Exception e) {
throw new MojoExecutionException("Wire Plugin: Failure compiling proto sources.", e);
}
}
use of com.squareup.wire.schema.IdentifierSet in project wire by square.
the class CodegenSampleMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
project.addCompileSourceRoot(generatedSourceDirectory);
ImmutableSet<String> protoPathsSet = ImmutableSet.copyOf(protoPaths);
ImmutableSet<String> protoFilesSet = ImmutableSet.copyOf(protoFiles);
IdentifierSet identifierSet = identifierSet();
try {
CodegenSample codeGenerator = new CodegenSample(this, protoPathsSet, protoFilesSet, generatedSourceDirectory, identifierSet);
codeGenerator.execute();
} catch (IOException e) {
throw new MojoExecutionException("failed to generate sources", e);
}
}
Aggregations