当前位置: 首页>>代码示例>>Java>>正文


Java Protoc类代码示例

本文整理汇总了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));
  }
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:31,代码来源:ProtocInvoker.java

示例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);
	}
}
 
开发者ID:os72,项目名称:protoc-jar-maven-plugin,代码行数:55,代码来源:ProtocJarMojo.java


注:本文中的com.github.os72.protocjar.Protoc类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。