/*
 * Copyright 2012 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.errorprone;

import org.codehaus.plexus.compiler.CompilerConfiguration;
import org.codehaus.plexus.compiler.CompilerException;
import org.codehaus.plexus.compiler.javac.JavacCompiler;

import java.util.List;

/**
 * @author alexeagle@google.com (Alex Eagle)
 */
public class PlexusErrorProneCompiler extends JavacCompiler {
  @Override
  public List compile(CompilerConfiguration config) throws CompilerException {
    throw new UnsupportedOperationException("Uh oh!");
  }
}

@@ -814,16 +814,67 @@
 piler;%0A%0A
+import java.io.File;%0Aimport java.util.Collections;%0A
 import j
@@ -888,16 +888,16 @@
 l.List;%0A
-
 %0A/**%0A * 
@@ -1038,16 +1038,17 @@
 compile(
+ 
 Compiler
@@ -1067,17 +1067,24 @@
 n config
-)
+ )%0A     
  throws 
@@ -1111,58 +1111,894 @@
     
-throw new UnsupportedOperationException(%22Uh oh!%22);
+File destinationDir = new File(config.getOutputLocation() );%0A%0A    if (!destinationDir.exists()) %7B%0A      destinationDir.mkdirs();%0A    %7D%0A%0A    String%5B%5D sourceFiles = getSourceFiles(config);%0A%0A    if ((sourceFiles == null) %7C%7C ( sourceFiles.length == 0 )) %7B%0A      return Collections.EMPTY_LIST;%0A    %7D%0A%0A    if ( ( getLogger() != null ) && getLogger().isInfoEnabled() )%0A    %7B%0A      getLogger().info( %22Compiling %22 + sourceFiles.length + %22 %22 +%0A          %22source file%22 + ( sourceFiles.length == 1 ? %22%22 : %22s%22 ) +%0A          %22 to %22 + destinationDir.getAbsolutePath() );%0A    %7D%0A%0A    String%5B%5D args = buildCompilerArguments( config, sourceFiles );%0A%0A    if (config.isFork()) %7B%0A      throw new UnsupportedOperationException(%0A          %22error-prone compiler can only be run in-process%22);%0A    %7D else %7B%0A      new ErrorProneCompiler.Builder().build().compile(args);%0A%0A      return Collections.emptyList();%0A    %7D
 %0A  %7D

Implement the compiler hook. Now the maven build runs with error-prone and reports our errors, but it doesn't detect the outcome of the failed build correctly, so it needs us to emit errors.