Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import javax.lang.model.SourceVersion;
import javax.tools.DiagnosticListener;
import javax.tools.JavaCompiler;
import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
Expand Down Expand Up @@ -97,11 +96,13 @@ static void addTaskListener(
checkCompilePolicy(Options.instance(context).get("compilePolicy"));
setupMessageBundle(context);
RefactoringCollection[] refactoringCollection = {null};
javacTask.addTaskListener(
HubSpotErrorProneAnalyzer.wrap(
context,
errorProneOptions,
createAnalyzer(scannerSupplier, errorProneOptions, context, refactoringCollection)));
if (errorProneOptions.patchingOptions().doRefactor()) {
javacTask.addTaskListener(
createAnalyzer(scannerSupplier, errorProneOptions, context, refactoringCollection));
} else {
javacTask.addTaskListener(
HubSpotErrorProneAnalyzer.create(scannerSupplier, errorProneOptions, context));
}
if (refactoringCollection[0] != null) {
javacTask.addTaskListener(new RefactoringTask(context, refactoringCollection[0]));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2022 The Error Prone Authors.
*
* 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.hubspot;

import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskListener;

public class ErrorReportingAnalyzer implements TaskListener {

public static TaskListener wrap(TaskListener delegate) {
return new ErrorReportingAnalyzer(delegate);
}

private final TaskListener delegate;

private ErrorReportingAnalyzer(TaskListener delegate) {
this.delegate = delegate;
}

@Override
public void started(TaskEvent e) {
try {
delegate.started(e);
} catch (Throwable t) {
HubSpotUtils.recordUncaughtException(t);
throw t;
}
}

@Override
public void finished(TaskEvent e) {
try {
delegate.finished(e);
} catch (Throwable t) {
HubSpotUtils.recordUncaughtException(t);
throw t;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.errorprone.ErrorProneAnalyzer;
import com.google.errorprone.ErrorProneOptions;
import com.google.errorprone.scanner.ScannerSupplier;
import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskEvent.Kind;
import com.sun.source.util.TaskListener;
Expand All @@ -26,17 +27,26 @@
public class HubSpotErrorProneAnalyzer implements TaskListener {
private final Context context;
private final ErrorProneOptions options;
private final ErrorProneAnalyzer delegate;
private final TaskListener standardAnalyzer;


public static TaskListener wrap(Context context, ErrorProneOptions options, ErrorProneAnalyzer analyzer) {
return new HubSpotErrorProneAnalyzer(context, options, analyzer);
public static HubSpotErrorProneAnalyzer create(ScannerSupplier scannerSupplier, ErrorProneOptions options, Context context) {
// Note: This analyzer doesn't make any attempt to handle refaster refactorings. We fall back on
// standard analyzer impl if refaster is requested

TaskListener standardAnalyzer = ErrorProneAnalyzer.createByScanningForPlugins(scannerSupplier, options, context);

if (HubSpotUtils.isErrorHandlingEnabled(options)) {
standardAnalyzer = ErrorReportingAnalyzer.wrap(standardAnalyzer);
}

return new HubSpotErrorProneAnalyzer(context, options, standardAnalyzer);
}

private HubSpotErrorProneAnalyzer(Context context, ErrorProneOptions options, ErrorProneAnalyzer delegate) {
private HubSpotErrorProneAnalyzer(Context context, ErrorProneOptions options, TaskListener standardAnalyzer) {
this.context = context;
this.options = options;
this.delegate = delegate;
this.standardAnalyzer = standardAnalyzer;
}

@Override
Expand All @@ -45,31 +55,15 @@ public void started(TaskEvent taskEvent) {
HubSpotLifecycleManager.instance(context).handleStartup();
}

try {
delegate.started(taskEvent);
} catch (Throwable t) {
if (HubSpotUtils.isErrorHandlingEnabled(options)) {
HubSpotUtils.recordUncaughtException(t);
}

throw t;
}
standardAnalyzer.started(taskEvent);
}

@Override
public void finished(TaskEvent taskEvent) {
standardAnalyzer.finished(taskEvent);

if (taskEvent.getKind() == Kind.COMPILATION) {
HubSpotLifecycleManager.instance(context).handleShutdown();
}

try {
delegate.finished(taskEvent);
} catch (Throwable t) {
if (HubSpotUtils.isErrorHandlingEnabled(options)) {
HubSpotUtils.recordUncaughtException(t);
}

throw t;
}
}
}