本文整理汇总了Java中com.github.os72.protocjar.Protoc类的典型用法代码示例。如果您正苦于以下问题:Java Protoc类的具体用法?Java Protoc怎么用?Java Protoc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Protoc类属于com.github.os72.protocjar包,在下文中一共展示了Protoc类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invokeBinary
import com.github.os72.protocjar.Protoc; //导入依赖的package包/类
private void invokeBinary(ImmutableList<String> protocArgs) throws ProtocInvocationException {
int status;
String[] protocLogLines;
// The "protoc" library unconditionally writes to stdout. So, we replace stdout right before
// calling into the library in order to gather its output.
PrintStream stdoutBackup = System.out;
try {
ByteArrayOutputStream protocStdout = new ByteArrayOutputStream();
System.setOut(new PrintStream(protocStdout));
status = Protoc.runProtoc(protocArgs.toArray(new String[0]));
protocLogLines = protocStdout.toString().split("\n");
} catch (IOException | InterruptedException e) {
throw new ProtocInvocationException("Unable to execute protoc binary", e);
} finally {
// Restore stdout.
System.setOut(stdoutBackup);
}
if (status != 0) {
// If protoc failed, we dump its output as a warning.
logger.warn("Protoc invocation failed with status: " + status);
for (String line : protocLogLines) {
logger.warn("[Protoc log] " + line);
}
throw new ProtocInvocationException(
String.format("Got exit code [%d] from protoc with args [%s]", status, protocArgs));
}
}
示例2: processTarget
import com.github.os72.protocjar.Protoc; //导入依赖的package包/类
private void processTarget(OutputTarget target) throws MojoExecutionException {
boolean shaded = false;
String targetType = target.type;
if (targetType.equals("java-shaded") || targetType.equals("java_shaded")) {
targetType = "java";
shaded = true;
}
FileFilter fileFilter = new FileFilter(extension);
for (File input : inputDirectories) {
if (input == null) continue;
if (input.exists() && input.isDirectory()) {
Collection<File> protoFiles = FileUtils.listFiles(input, fileFilter, TrueFileFilter.INSTANCE);
for (File protoFile : protoFiles) {
if (target.cleanOutputFolder || buildContext.hasDelta(protoFile.getPath())) {
processFile(protoFile, protocVersion, targetType, target.pluginPath, target.outputDirectory, target.outputOptions);
}
else {
getLog().info("Not changed " + protoFile);
}
}
}
else {
if (input.exists()) getLog().warn(input + " is not a directory");
else getLog().warn(input + " does not exist");
}
}
if (shaded) {
try {
getLog().info(" Shading (version " + protocVersion + "): " + target.outputDirectory);
Protoc.doShading(target.outputDirectory, protocVersion.replace(".", ""));
}
catch (IOException e) {
throw new MojoExecutionException("Error occurred during shading", e);
}
}
boolean mainAddSources = "main".endsWith(target.addSources);
boolean testAddSources = "test".endsWith(target.addSources);
if (mainAddSources) {
getLog().info("Adding generated classes to classpath");
project.addCompileSourceRoot(target.outputDirectory.getAbsolutePath());
}
if (testAddSources) {
getLog().info("Adding generated classes to test classpath");
project.addTestCompileSourceRoot(target.outputDirectory.getAbsolutePath());
}
if (mainAddSources || testAddSources) {
buildContext.refresh(target.outputDirectory);
}
}