Skip to content

Commit

Permalink
Add retry to API Analysis Mojo
Browse files Browse the repository at this point in the history
Currently it can happen that due to concurrent run jobs the workspace
the API analysis fails with a component disposed error. Rerun the whole
build often fix the problem.

This now adds a maximum of five retries to allow the analysis to
complete.

(cherry picked from commit 3172e56)
  • Loading branch information
laeubi authored and eclipse-tycho-bot committed Dec 27, 2024
1 parent 11fbc5b commit cc388e6
Showing 1 changed file with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFolder;
Expand Down Expand Up @@ -94,6 +96,9 @@
*/
public class ApiAnalysis implements Serializable, Callable<ApiAnalysisResult> {

private static final Pattern COMPONENT_DISPOSED_ERROR = Pattern
.compile("Component '(.+)' in the baseline '(.+)' is disposed");

private Collection<String> baselineBundles;
private Collection<String> targetBundles;
private String baselineName;
Expand Down Expand Up @@ -164,7 +169,36 @@ public void aboutToRun(IJobChangeEvent event) {
deleteAllProjects();
IPath projectPath = IPath.fromOSString(projectDir);
IProject project = getProject(projectPath);
ApiAnalysisResult result = new ApiAnalysisResult(getVersion());
RuntimeException exception = new RuntimeException("Can't get API result due to API application error");
String version = getVersion();
for (int i = 0; i < 5; i++) {
ApiAnalysisResult result = new ApiAnalysisResult(version);
IStatus status = runAnalysis(projectPath, project, result);
if (!status.isOK() && status.getException() instanceof Exception error) {
if (isRecoverable(error)) {
exception.addSuppressed(error);
TimeUnit.SECONDS.sleep(10);
continue;
}
throw error;
}
return result;
}
throw exception;
}

private boolean isRecoverable(Exception error) {
if (error instanceof CoreException) {
String message = error.getMessage();
if (message != null) {
return COMPONENT_DISPOSED_ERROR.matcher(message).matches();
}
}
return false;
}

private IStatus runAnalysis(IPath projectPath, IProject project, ApiAnalysisResult result)
throws InterruptedException {
IStatus status;
if (runAsJob) {
WorkspaceJob job = new WorkspaceJob("Tycho API Analysis") {
Expand All @@ -184,10 +218,7 @@ public IStatus runInWorkspace(IProgressMonitor monitor) {
}
JRTUtil.reset(); // reclaim space due to loaded multiple JRTUtil should better be fixed to not
// use that much space
if (!status.isOK() && status.getException() instanceof Exception error) {
throw error;
}
return result;
return status;
}

private IStatus performAPIAnalysis(IProject project, IPath projectPath, ApiAnalysisResult result) {
Expand Down

0 comments on commit cc388e6

Please sign in to comment.