@@ -103,10 +103,12 @@ public class ApiAnalysis implements Serializable, Callable<ApiAnalysisResult> {
103
103
private String apiPreferences ;
104
104
private String binaryArtifact ;
105
105
private String outputDir ;
106
+ private boolean runAsJob ;
106
107
107
108
ApiAnalysis (Collection <Path > baselineBundles , Collection <Path > dependencyBundles , String baselineName ,
108
109
Path apiFilterFile , Path apiPreferences , Path projectDir , boolean debug , Path binaryArtifact ,
109
- Path outputDir ) {
110
+ Path outputDir , boolean runAsJob ) {
111
+ this .runAsJob = runAsJob ;
110
112
this .targetBundles = dependencyBundles .stream ().map (ApiAnalysis ::pathAsString ).toList ();
111
113
this .baselineBundles = baselineBundles .stream ().map (ApiAnalysis ::pathAsString ).toList ();
112
114
this .baselineName = baselineName ;
@@ -163,45 +165,23 @@ public void aboutToRun(IJobChangeEvent event) {
163
165
IPath projectPath = IPath .fromOSString (projectDir );
164
166
IProject project = getProject (projectPath );
165
167
ApiAnalysisResult result = new ApiAnalysisResult (getVersion ());
166
- WorkspaceJob job = new WorkspaceJob ("Tycho API Analysis" ) {
168
+ IStatus status ;
169
+ if (runAsJob ) {
170
+ WorkspaceJob job = new WorkspaceJob ("Tycho API Analysis" ) {
167
171
168
- @ Override
169
- public IStatus runInWorkspace (IProgressMonitor monitor ) {
170
- try {
171
- BundleComponent projectComponent = getApiComponent (project , projectPath );
172
- IApiBaseline baseline = createBaseline (baselineBundles , baselineName + " - baseline" );
173
- ResolverError [] resolverErrors = projectComponent .getErrors ();
174
- if (resolverErrors != null && resolverErrors .length > 0 ) {
175
- for (ResolverError error : resolverErrors ) {
176
- result .addResolverError (error );
177
- }
178
- }
179
- IApiFilterStore filterStore = getApiFilterStore (projectComponent );
180
- Properties preferences = getPreferences ();
181
- BaseApiAnalyzer analyzer = new BaseApiAnalyzer ();
182
- try {
183
- analyzer .setContinueOnResolverError (true );
184
- analyzer .analyzeComponent (null , filterStore , preferences , baseline , projectComponent ,
185
- new BuildContext (), new NullProgressMonitor ());
186
- IApiProblem [] problems = analyzer .getProblems ();
187
- for (IApiProblem problem : problems ) {
188
- result .addProblem (problem , project );
189
- debug (String .valueOf (problem ));
190
- }
191
- } finally {
192
- analyzer .dispose ();
193
- ResourcesPlugin .getWorkspace ().save (true , new NullProgressMonitor ());
194
- }
195
- } catch (Exception e ) {
196
- return Status .error ("Api Analysis failed" , e );
172
+ @ Override
173
+ public IStatus runInWorkspace (IProgressMonitor monitor ) {
174
+ return performAPIAnalysis (project , projectPath , result );
197
175
}
198
- return Status .OK_STATUS ;
199
- }
200
- };
201
- job .setRule (ResourcesPlugin .getWorkspace ().getRoot ());
202
- job .schedule ();
203
- job .join ();
204
- IStatus status = job .getResult ();
176
+
177
+ };
178
+ job .setRule (ResourcesPlugin .getWorkspace ().getRoot ());
179
+ job .schedule ();
180
+ job .join ();
181
+ status = job .getResult ();
182
+ } else {
183
+ status = performAPIAnalysis (project , projectPath , result );
184
+ }
205
185
JRTUtil .reset (); // reclaim space due to loaded multiple JRTUtil should better be fixed to not
206
186
// use that much space
207
187
if (!status .isOK () && status .getException () instanceof Exception error ) {
@@ -210,6 +190,38 @@ public IStatus runInWorkspace(IProgressMonitor monitor) {
210
190
return result ;
211
191
}
212
192
193
+ private IStatus performAPIAnalysis (IProject project , IPath projectPath , ApiAnalysisResult result ) {
194
+ try {
195
+ BundleComponent projectComponent = getApiComponent (project , projectPath );
196
+ IApiBaseline baseline = createBaseline (baselineBundles , baselineName + " - baseline" );
197
+ ResolverError [] resolverErrors = projectComponent .getErrors ();
198
+ if (resolverErrors != null && resolverErrors .length > 0 ) {
199
+ for (ResolverError error : resolverErrors ) {
200
+ result .addResolverError (error );
201
+ }
202
+ }
203
+ IApiFilterStore filterStore = getApiFilterStore (projectComponent );
204
+ Properties preferences = getPreferences ();
205
+ BaseApiAnalyzer analyzer = new BaseApiAnalyzer ();
206
+ try {
207
+ analyzer .setContinueOnResolverError (true );
208
+ analyzer .analyzeComponent (null , filterStore , preferences , baseline , projectComponent ,
209
+ new BuildContext (), new NullProgressMonitor ());
210
+ IApiProblem [] problems = analyzer .getProblems ();
211
+ for (IApiProblem problem : problems ) {
212
+ result .addProblem (problem , project );
213
+ debug (String .valueOf (problem ));
214
+ }
215
+ } finally {
216
+ analyzer .dispose ();
217
+ ResourcesPlugin .getWorkspace ().save (true , new NullProgressMonitor ());
218
+ }
219
+ } catch (Exception e ) {
220
+ return Status .error ("Api Analysis failed" , e );
221
+ }
222
+ return Status .OK_STATUS ;
223
+ }
224
+
213
225
private String getVersion () {
214
226
Bundle apiToolsBundle = FrameworkUtil .getBundle (ApiModelFactory .class );
215
227
if (apiToolsBundle != null ) {
0 commit comments