Skip to content

Commit cc388e6

Browse files
laeubieclipse-tycho-bot
authored andcommitted
Add retry to API Analysis Mojo
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)
1 parent 11fbc5b commit cc388e6

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.util.Objects;
3232
import java.util.Properties;
3333
import java.util.concurrent.Callable;
34+
import java.util.concurrent.TimeUnit;
35+
import java.util.regex.Pattern;
3436

3537
import org.eclipse.core.resources.ICommand;
3638
import org.eclipse.core.resources.IFolder;
@@ -94,6 +96,9 @@
9496
*/
9597
public class ApiAnalysis implements Serializable, Callable<ApiAnalysisResult> {
9698

99+
private static final Pattern COMPONENT_DISPOSED_ERROR = Pattern
100+
.compile("Component '(.+)' in the baseline '(.+)' is disposed");
101+
97102
private Collection<String> baselineBundles;
98103
private Collection<String> targetBundles;
99104
private String baselineName;
@@ -164,7 +169,36 @@ public void aboutToRun(IJobChangeEvent event) {
164169
deleteAllProjects();
165170
IPath projectPath = IPath.fromOSString(projectDir);
166171
IProject project = getProject(projectPath);
167-
ApiAnalysisResult result = new ApiAnalysisResult(getVersion());
172+
RuntimeException exception = new RuntimeException("Can't get API result due to API application error");
173+
String version = getVersion();
174+
for (int i = 0; i < 5; i++) {
175+
ApiAnalysisResult result = new ApiAnalysisResult(version);
176+
IStatus status = runAnalysis(projectPath, project, result);
177+
if (!status.isOK() && status.getException() instanceof Exception error) {
178+
if (isRecoverable(error)) {
179+
exception.addSuppressed(error);
180+
TimeUnit.SECONDS.sleep(10);
181+
continue;
182+
}
183+
throw error;
184+
}
185+
return result;
186+
}
187+
throw exception;
188+
}
189+
190+
private boolean isRecoverable(Exception error) {
191+
if (error instanceof CoreException) {
192+
String message = error.getMessage();
193+
if (message != null) {
194+
return COMPONENT_DISPOSED_ERROR.matcher(message).matches();
195+
}
196+
}
197+
return false;
198+
}
199+
200+
private IStatus runAnalysis(IPath projectPath, IProject project, ApiAnalysisResult result)
201+
throws InterruptedException {
168202
IStatus status;
169203
if (runAsJob) {
170204
WorkspaceJob job = new WorkspaceJob("Tycho API Analysis") {
@@ -184,10 +218,7 @@ public IStatus runInWorkspace(IProgressMonitor monitor) {
184218
}
185219
JRTUtil.reset(); // reclaim space due to loaded multiple JRTUtil should better be fixed to not
186220
// use that much space
187-
if (!status.isOK() && status.getException() instanceof Exception error) {
188-
throw error;
189-
}
190-
return result;
221+
return status;
191222
}
192223

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

0 commit comments

Comments
 (0)