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

[tycho-4.0.x] Add retry to API Analysis Mojo #4561

Merged
merged 1 commit into from
Dec 27, 2024
Merged
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 @@ -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
Loading