Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErrorPronePlugins support search annation info within CLASS_PATH #3393

Open
pli2014 opened this issue Aug 16, 2022 · 0 comments
Open

ErrorPronePlugins support search annation info within CLASS_PATH #3393

pli2014 opened this issue Aug 16, 2022 · 0 comments

Comments

@pli2014
Copy link

pli2014 commented Aug 16, 2022

public class ErrorPronePlugins {

  public static ScannerSupplier loadPlugins(ScannerSupplier scannerSupplier, Context context) {
    JavaFileManager fileManager = context.get(JavaFileManager.class);
    // Unlike in annotation processor discovery, we never search CLASS_PATH if
    // ANNOTATION_PROCESSOR_PATH is unavailable.
    if (!fileManager.hasLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH)) {
      return scannerSupplier;
    }
    // Use the same classloader that Error Prone was loaded from to avoid classloader skew
    // when using Error Prone plugins together with the Error Prone javac plugin.
    JavacProcessingEnvironment processingEnvironment = JavacProcessingEnvironment.instance(context);
    ClassLoader loader = processingEnvironment.getProcessorClassLoader();
    Iterable<BugChecker> extraBugCheckers = ServiceLoader.load(BugChecker.class, loader);
    if (Iterables.isEmpty(extraBugCheckers)) {
      return scannerSupplier;
    }
    return scannerSupplier.plus(
        ScannerSupplier.fromBugCheckerClasses(
            Iterables.transform(extraBugCheckers, BugChecker::getClass)));
  }
}

https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html
maven note: Classpath elements to supply as annotation processor path. If specified, the compiler will detect annotation processors only in those classpath elements. If omitted, the default classpath is used to detect annotation processors. The detection itself depends on the configuration of annotationProcessors.

ErrorPronePlugins broke this specification of maven-compiler-plugin, please resolve this conflict issue about this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant