2016-07-29 2 views
0

mojo-executor를 사용하여 다른 Mojo를 실행하는 maven Mojo를 만들었습니다. 이것이 실행되면 Mojo 실행 결과가 기본 출력으로 바뀝니다. 내가 Errorprone 일부 bugcheckers를 만들었 때문에Maven 플러그인 빌드 로그를 가로 채는 방법

[INFO] Compiling 1 source file to /Users/sergio/hello-world/target/classes 
[INFO] 
[INFO] --- utqg-maven-plugin:1.1.0-SNAPSHOT:errorprone (default) @ my-app --- 
/Users/sergio/hello-world/src/test/java/com/mycompany/App2Test.java:30: warning: [UTQG:HelperMethodCannotBePublic] Helper Methods of test classes cannot be public. 
    public String getName() { 
       ^
    (see https://www.mycompany.com/utqg/HelperMethodCannotBePublic) 
/Users/sergio/hello-world/src/test/java/com/mycompany/service/MyServiceTest.java:14: warning: [UTQG:HelperMethodCannotBePublic] Helper Methods of test classes cannot be public. 
    public void myHelperMethod(){ 
      ^
    (see https://www.mycompany.com/utqg/HelperMethodCannotBePublic) 
/Users/sergio/hello-world/src/test/java/com/mycompany/service/MyServiceTest.java:170: warning: [UTQG:E:UseDeprecatedStatementsNotAllowed] Usage of Deprecated Classes, Methods or Variables Not Allowed 
    final URL url = new File(".").toURL(); 
            ^
    (see https://www.mycompany.com/utqg/HelperMethodCannotBePublic) 
Note: /Users/sergio/hello-world/src/test/java/com/mycompany/service/MyServiceTest.java uses or overrides a deprecated API. 
Note: Recompile with -Xlint:deprecation for details. 
3 warnings 

좋아, 모든 경고가 예상됩니다이 실행 얻을 그래서, 그것은이 다음 인쇄합니다. 하지만 문제는이 출력을 표준 출력에서 ​​제거하고 파일에 넣어야한다는 것입니다. 하지만 그 부분 만.

PrintStream originalStream = System.out; 
    try { 
     PrintStream ps = new PrintStream(new FileOutputStream(ERRORPRONE_FILE, false)); 
     System.setOut(ps); 
    } catch (FileNotFoundException e){ 
     LOGGER.error("ErrorProneRunMojo", e); 
     throw new MojoExecutionException(e.getMessage()); 
    } 
    // do my logic of calling the plugin here 
    System.out.flush(); 
    System.setOut(originalStream); 

구내 :이 실행 얻을 때 나는 무엇을 시도했다

지금까지 파일로 내 출력을 리디렉션하는 것이었다 - 그들은 표준 출력에 이르기까지 모든 것을 제거하기 때문에 내가 mvn --logFile 또는 -l를 사용할 수 없으며, 그것을 파일 안에 두거나, 솔루션이 사용자가 --logFile 또는 그와 비슷한 것을 넣을 수 없도록해야합니다.

+1

시스템 표준 출력 및 오류 스트림을 설정하는 것이 유일한 방법이라고 생각합니다. 이 문제가 발생 했습니까? – Tunaki

+0

예, 여전히 올바른 문자열이 표시되지 않습니다. 실행 후 모든 문자열을 가져오고있었습니다. 하지만 코드를 확인하고 괜찮 았어. –

+0

MavenProject에는 로거의 다른 인스턴스를 조회하거나 다른 모조를 호출하는 방법에 따라 로거의 인스턴스를 설정하는 데 필요한 로거가 포함되어 있습니까? 그러나 구체적인 코드가 없으면 도움을 받기가 어렵습니다 ... 또한 모져에서 출력을 생성하기 위해 로거를 사용하지 않는 것처럼 보입니까? – khmarbaise

답변

0

좋아, 나는 두 가지 방법을 시도하고 둘 다 일 :

  • 만든 PrintStream.print() 모든 입력을 차단하지만 너무 열심히했고 결과를 제어하기 위해 하드이었던 ASM 에이전트 인터셉터. ASM 가이드에서 수행 방법을 확인할 수 있습니다. http://download.forge.objectweb.org/asm/asm4-guide.pdf

  • 다른 옵션은 System.out 및 System.err의 재 할당으로 유지되었습니다. 실행하기가 더 쉽고 결과를 더 잘 제어 할 수 있기 때문에 훨씬 좋았습니다. 우리가 목표를 관리 할 수 ​​있기 때문입니다.

관련 문제