當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。