Lines 10-23
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.pde.api.tools.internal.builder; |
11 |
package org.eclipse.pde.api.tools.internal.builder; |
12 |
|
12 |
|
13 |
import java.io.BufferedInputStream; |
|
|
14 |
import java.io.BufferedOutputStream; |
15 |
import java.io.DataInputStream; |
16 |
import java.io.DataOutputStream; |
17 |
import java.io.File; |
18 |
import java.io.FileInputStream; |
19 |
import java.io.FileOutputStream; |
20 |
import java.io.IOException; |
21 |
import java.util.ArrayList; |
13 |
import java.util.ArrayList; |
22 |
import java.util.Date; |
14 |
import java.util.Date; |
23 |
import java.util.HashMap; |
15 |
import java.util.HashMap; |
Lines 39-52
Link Here
|
39 |
import org.eclipse.core.runtime.IStatus; |
31 |
import org.eclipse.core.runtime.IStatus; |
40 |
import org.eclipse.core.runtime.OperationCanceledException; |
32 |
import org.eclipse.core.runtime.OperationCanceledException; |
41 |
import org.eclipse.core.runtime.Path; |
33 |
import org.eclipse.core.runtime.Path; |
42 |
import org.eclipse.core.runtime.Platform; |
|
|
43 |
import org.eclipse.core.runtime.Status; |
44 |
import org.eclipse.core.runtime.SubMonitor; |
34 |
import org.eclipse.core.runtime.SubMonitor; |
45 |
import org.eclipse.jdt.core.IClasspathAttribute; |
35 |
import org.eclipse.jdt.core.IClasspathAttribute; |
46 |
import org.eclipse.jdt.core.IClasspathEntry; |
36 |
import org.eclipse.jdt.core.IClasspathEntry; |
47 |
import org.eclipse.jdt.core.IJavaProject; |
37 |
import org.eclipse.jdt.core.IJavaProject; |
48 |
import org.eclipse.jdt.core.JavaCore; |
38 |
import org.eclipse.jdt.core.JavaCore; |
49 |
import org.eclipse.jdt.core.JavaModelException; |
39 |
import org.eclipse.jdt.core.JavaModelException; |
|
|
40 |
import org.eclipse.jdt.internal.core.JavaModelManager; |
41 |
import org.eclipse.jdt.internal.core.builder.State; |
50 |
import org.eclipse.osgi.service.resolver.BundleDescription; |
42 |
import org.eclipse.osgi.service.resolver.BundleDescription; |
51 |
import org.eclipse.osgi.util.NLS; |
43 |
import org.eclipse.osgi.util.NLS; |
52 |
import org.eclipse.pde.api.tools.internal.ApiDescriptionManager; |
44 |
import org.eclipse.pde.api.tools.internal.ApiDescriptionManager; |
Lines 214-264
Link Here
|
214 |
SubMonitor localMonitor = SubMonitor.convert(monitor, BuilderMessages.api_analysis_builder, 2); |
206 |
SubMonitor localMonitor = SubMonitor.convert(monitor, BuilderMessages.api_analysis_builder, 2); |
215 |
final IProject[] projects = getRequiredProjects(true); |
207 |
final IProject[] projects = getRequiredProjects(true); |
216 |
IApiBaseline baseline = ApiPlugin.getDefault().getApiBaselineManager().getDefaultApiBaseline(); |
208 |
IApiBaseline baseline = ApiPlugin.getDefault().getApiBaselineManager().getDefaultApiBaseline(); |
|
|
209 |
IApiBaseline wbaseline = ApiPlugin.getDefault().getApiBaselineManager().getWorkspaceBaseline(); |
210 |
if (wbaseline == null) { |
211 |
if (DEBUG) { |
212 |
System.err.println("Could not retrieve a workspace profile"); //$NON-NLS-1$ |
213 |
} |
214 |
return NO_PROJECTS; |
215 |
} |
217 |
try { |
216 |
try { |
218 |
switch(kind) { |
217 |
switch(kind) { |
219 |
case FULL_BUILD : { |
218 |
case FULL_BUILD : { |
220 |
if (DEBUG) { |
219 |
if (DEBUG) { |
221 |
System.out.println("Performing full build as requested by user"); //$NON-NLS-1$ |
220 |
System.out.println("Performing full build as requested by user"); //$NON-NLS-1$ |
222 |
} |
221 |
} |
223 |
buildAll(baseline, localMonitor.newChild(1)); |
222 |
buildAll(baseline, wbaseline, localMonitor.newChild(1)); |
224 |
break; |
223 |
break; |
225 |
} |
224 |
} |
226 |
case AUTO_BUILD : |
225 |
case AUTO_BUILD : |
227 |
case INCREMENTAL_BUILD : { |
226 |
case INCREMENTAL_BUILD : { |
228 |
this.buildstate = getLastBuiltState(currentproject); |
227 |
this.buildstate = BuildState.getLastBuiltState(currentproject); |
229 |
if (this.buildstate == null) { |
228 |
if (this.buildstate == null) { |
230 |
buildAll(baseline, localMonitor.newChild(1)); |
229 |
buildAll(baseline, wbaseline, localMonitor.newChild(1)); |
231 |
break; |
230 |
break; |
232 |
} |
231 |
} |
233 |
else if(worthDoingFullBuild(projects)) { |
232 |
else if(worthDoingFullBuild(projects)) { |
234 |
buildAll(baseline, localMonitor.newChild(1)); |
233 |
buildAll(baseline, wbaseline, localMonitor.newChild(1)); |
235 |
} |
234 |
break; |
236 |
IResourceDelta[] deltas = getDeltas(projects); |
|
|
237 |
if(deltas.length < 1) { |
238 |
buildAll(baseline, localMonitor.newChild(1)); |
239 |
} |
235 |
} |
240 |
else { |
236 |
else { |
241 |
IResourceDelta manifest = null; |
237 |
IResourceDelta[] deltas = getDeltas(projects); |
242 |
IResourceDelta filters = null; |
238 |
if(deltas.length < 1) { |
243 |
for (int i = 0; i < deltas.length; i++) { |
239 |
buildAll(baseline, wbaseline, localMonitor.newChild(1)); |
244 |
manifest = deltas[i].findMember(MANIFEST_PATH); |
240 |
} |
245 |
if(manifest != null) { |
241 |
else { |
246 |
break; |
242 |
IResourceDelta manifest = null; |
|
|
243 |
IResourceDelta filters = null; |
244 |
for (int i = 0; i < deltas.length; i++) { |
245 |
manifest = deltas[i].findMember(MANIFEST_PATH); |
246 |
if(manifest != null) { |
247 |
break; |
248 |
} |
249 |
filters = deltas[i].findMember(FILTER_PATH); |
250 |
if(filters != null){ |
251 |
break; |
252 |
} |
247 |
} |
253 |
} |
248 |
filters = deltas[i].findMember(FILTER_PATH); |
254 |
if (manifest != null || filters != null) { |
249 |
if(filters != null){ |
255 |
if (DEBUG) { |
250 |
break; |
256 |
System.out.println("Performing full build since MANIFEST.MF or .api_filters was modified"); //$NON-NLS-1$ |
|
|
257 |
} |
258 |
buildAll(baseline, wbaseline, localMonitor.newChild(1)); |
259 |
} |
260 |
else { |
261 |
State state = (State)JavaModelManager.getJavaModelManager().getLastBuiltState(this.currentproject, localMonitor.newChild(1)); |
262 |
if(state == null) { |
263 |
buildAll(baseline, wbaseline, localMonitor.newChild(1)); |
264 |
break; |
265 |
} |
266 |
BuildState.setLastBuiltState(this.currentproject, null); |
267 |
IncrementalApiBuilder builder = new IncrementalApiBuilder(this); |
268 |
builder.build(baseline, wbaseline, deltas, state, this.buildstate, localMonitor.newChild(1)); |
251 |
} |
269 |
} |
252 |
} |
|
|
253 |
if (manifest != null || filters != null) { |
254 |
if (DEBUG) { |
255 |
System.out.println("Performing full build since MANIFEST.MF or .api_filters was modified"); //$NON-NLS-1$ |
256 |
} |
257 |
buildAll(baseline, localMonitor.newChild(1)); |
258 |
} |
259 |
else { |
260 |
IncrementalApiBuilder builder = new IncrementalApiBuilder(this); |
261 |
builder.build(baseline, deltas, this.buildstate, localMonitor.newChild(1)); |
262 |
} |
270 |
} |
263 |
} |
271 |
} |
264 |
} |
272 |
} |
Lines 279-284
Link Here
|
279 |
if(baseline != null) { |
287 |
if(baseline != null) { |
280 |
baseline.close(); |
288 |
baseline.close(); |
281 |
} |
289 |
} |
|
|
290 |
wbaseline.close(); |
282 |
if(monitor != null) { |
291 |
if(monitor != null) { |
283 |
monitor.done(); |
292 |
monitor.done(); |
284 |
} |
293 |
} |
Lines 289-295
Link Here
|
289 |
this.buildstate.addApiToolingDependentProject(project.getName()); |
298 |
this.buildstate.addApiToolingDependentProject(project.getName()); |
290 |
} |
299 |
} |
291 |
} |
300 |
} |
292 |
saveBuiltState(this.currentproject, this.buildstate); |
301 |
BuildState.saveBuiltState(this.currentproject, this.buildstate); |
293 |
this.buildstate = null; |
302 |
this.buildstate = null; |
294 |
} |
303 |
} |
295 |
} |
304 |
} |
Lines 299-305
Link Here
|
299 |
return projects; |
308 |
return projects; |
300 |
} |
309 |
} |
301 |
|
310 |
|
302 |
private boolean worthDoingFullBuild(IProject[] projects) { |
311 |
/** |
|
|
312 |
* if its worth doing a full build considering the given set if projects |
313 |
* @param projects projects to check the build state for |
314 |
* @return true if a full build should take place, false otherwise |
315 |
*/ |
316 |
boolean worthDoingFullBuild(IProject[] projects) { |
303 |
Set apiToolingDependentProjects = this.buildstate.getApiToolingDependentProjects(); |
317 |
Set apiToolingDependentProjects = this.buildstate.getApiToolingDependentProjects(); |
304 |
for (int i = 0, max = projects.length; i < max; i++) { |
318 |
for (int i = 0, max = projects.length; i < max; i++) { |
305 |
IProject currentProject = projects[i]; |
319 |
IProject currentProject = projects[i]; |
Lines 317-328
Link Here
|
317 |
|
331 |
|
318 |
/** |
332 |
/** |
319 |
* Performs a full build for the project |
333 |
* Performs a full build for the project |
|
|
334 |
* @param baseline the default baseline |
335 |
* @param wbaseline the workspace baseline |
320 |
* @param monitor |
336 |
* @param monitor |
321 |
*/ |
337 |
*/ |
322 |
void buildAll(IApiBaseline baseline, IProgressMonitor monitor) throws CoreException { |
338 |
void buildAll(IApiBaseline baseline, IApiBaseline wbaseline, IProgressMonitor monitor) throws CoreException { |
323 |
IApiBaseline wsprofile = null; |
|
|
324 |
try { |
339 |
try { |
325 |
clearLastState(); |
340 |
BuildState.setLastBuiltState(this.currentproject, null); |
326 |
this.buildstate = new BuildState(); |
341 |
this.buildstate = new BuildState(); |
327 |
SubMonitor localMonitor = SubMonitor.convert(monitor, BuilderMessages.api_analysis_on_0, 4); |
342 |
SubMonitor localMonitor = SubMonitor.convert(monitor, BuilderMessages.api_analysis_on_0, 4); |
328 |
localMonitor.subTask(NLS.bind(BuilderMessages.ApiAnalysisBuilder_initializing_analyzer, currentproject.getName())); |
343 |
localMonitor.subTask(NLS.bind(BuilderMessages.ApiAnalysisBuilder_initializing_analyzer, currentproject.getName())); |
Lines 330-346
Link Here
|
330 |
IPluginModelBase currentModel = getCurrentModel(); |
345 |
IPluginModelBase currentModel = getCurrentModel(); |
331 |
if (currentModel != null) { |
346 |
if (currentModel != null) { |
332 |
localMonitor.subTask(BuilderMessages.building_workspace_profile); |
347 |
localMonitor.subTask(BuilderMessages.building_workspace_profile); |
333 |
wsprofile = getWorkspaceProfile(); |
|
|
334 |
updateMonitor(localMonitor, 1); |
348 |
updateMonitor(localMonitor, 1); |
335 |
if (wsprofile == null) { |
|
|
336 |
if (DEBUG) { |
337 |
System.err.println("Could not retrieve a workspace profile"); //$NON-NLS-1$ |
338 |
} |
339 |
return; |
340 |
} |
341 |
String id = currentModel.getBundleDescription().getSymbolicName(); |
349 |
String id = currentModel.getBundleDescription().getSymbolicName(); |
342 |
// Compatibility checks |
350 |
// Compatibility checks |
343 |
IApiComponent apiComponent = wsprofile.getApiComponent(id); |
351 |
IApiComponent apiComponent = wbaseline.getApiComponent(id); |
344 |
if(apiComponent != null) { |
352 |
if(apiComponent != null) { |
345 |
getAnalyzer().analyzeComponent(this.buildstate, null, null, baseline, apiComponent, null, null, localMonitor.newChild(1)); |
353 |
getAnalyzer().analyzeComponent(this.buildstate, null, null, baseline, apiComponent, null, null, localMonitor.newChild(1)); |
346 |
updateMonitor(localMonitor, 1); |
354 |
updateMonitor(localMonitor, 1); |
Lines 350-358
Link Here
|
350 |
} |
358 |
} |
351 |
} |
359 |
} |
352 |
finally { |
360 |
finally { |
353 |
if(wsprofile != null) { |
|
|
354 |
wsprofile.close(); |
355 |
} |
356 |
if(monitor != null) { |
361 |
if(monitor != null) { |
357 |
monitor.done(); |
362 |
monitor.done(); |
358 |
} |
363 |
} |
Lines 393-402
Link Here
|
393 |
/** |
398 |
/** |
394 |
* Returns the {@link IApiMarkerConstants} problem type given the |
399 |
* Returns the {@link IApiMarkerConstants} problem type given the |
395 |
* problem category |
400 |
* problem category |
396 |
* @param category |
401 |
* @param category the problem category - see {@link IApiProblem} for problem categories |
|
|
402 |
* @param kind the kind of the problem - see {@link IApiProblem} for problem kinds |
397 |
* @return the problem type or <code>null</code> |
403 |
* @return the problem type or <code>null</code> |
398 |
*/ |
404 |
*/ |
399 |
private String getProblemTypeFromCategory(int category, int kind) { |
405 |
String getProblemTypeFromCategory(int category, int kind) { |
400 |
switch(category) { |
406 |
switch(category) { |
401 |
case IApiProblem.CATEGORY_API_COMPONENT_RESOLUTION : { |
407 |
case IApiProblem.CATEGORY_API_COMPONENT_RESOLUTION : { |
402 |
return IApiMarkerConstants.API_COMPONENT_RESOLUTION_PROBLEM_MARKER; |
408 |
return IApiMarkerConstants.API_COMPONENT_RESOLUTION_PROBLEM_MARKER; |
Lines 430-438
Link Here
|
430 |
* Creates an {@link IMarker} on the resource specified |
436 |
* Creates an {@link IMarker} on the resource specified |
431 |
* in the problem (via its path) with the given problem |
437 |
* in the problem (via its path) with the given problem |
432 |
* attributes |
438 |
* attributes |
|
|
439 |
* @param category the category of the problem - see {@link IApiProblem} for categories |
440 |
* @param type the marker type to create - see {@link IApiMarkerConstants} for types |
433 |
* @param problem the problem to create a marker from |
441 |
* @param problem the problem to create a marker from |
434 |
*/ |
442 |
*/ |
435 |
private void createMarkerForProblem(int category, String type, IApiProblem problem) { |
443 |
void createMarkerForProblem(int category, String type, IApiProblem problem) { |
436 |
IResource resource = resolveResource(problem); |
444 |
IResource resource = resolveResource(problem); |
437 |
if(resource == null) { |
445 |
if(resource == null) { |
438 |
return; |
446 |
return; |
Lines 498-504
Link Here
|
498 |
* @param problem the problem to get the resource for |
506 |
* @param problem the problem to get the resource for |
499 |
* @return the resource or <code>null</code> |
507 |
* @return the resource or <code>null</code> |
500 |
*/ |
508 |
*/ |
501 |
private IResource resolveResource(IApiProblem problem) { |
509 |
IResource resolveResource(IApiProblem problem) { |
502 |
String resourcePath = problem.getResourcePath(); |
510 |
String resourcePath = problem.getResourcePath(); |
503 |
if (resourcePath == null) { |
511 |
if (resourcePath == null) { |
504 |
return null; |
512 |
return null; |
Lines 519-525
Link Here
|
519 |
* @param args |
527 |
* @param args |
520 |
* @return a single string attribute from an array or arguments |
528 |
* @return a single string attribute from an array or arguments |
521 |
*/ |
529 |
*/ |
522 |
private String createArgAttribute(String[] args) { |
530 |
String createArgAttribute(String[] args) { |
523 |
StringBuffer buff = new StringBuffer(); |
531 |
StringBuffer buff = new StringBuffer(); |
524 |
for(int i = 0; i < args.length; i++) { |
532 |
for(int i = 0; i < args.length; i++) { |
525 |
buff.append(args[i]); |
533 |
buff.append(args[i]); |
Lines 564-570
Link Here
|
564 |
updateMonitor(localmonitor, 1); |
572 |
updateMonitor(localmonitor, 1); |
565 |
} |
573 |
} |
566 |
finally { |
574 |
finally { |
567 |
clearLastState(); |
575 |
BuildState.setLastBuiltState(this.currentproject, null); |
568 |
localmonitor.done(); |
576 |
localmonitor.done(); |
569 |
} |
577 |
} |
570 |
} |
578 |
} |
Lines 573-579
Link Here
|
573 |
* Cleans the .api_settings file for the given project |
581 |
* Cleans the .api_settings file for the given project |
574 |
* @param project |
582 |
* @param project |
575 |
*/ |
583 |
*/ |
576 |
private void cleanupApiDescription(IProject project) { |
584 |
void cleanupApiDescription(IProject project) { |
577 |
if(project != null && project.exists()) { |
585 |
if(project != null && project.exists()) { |
578 |
ApiDescriptionManager.getDefault().clean(JavaCore.create(project), true, true); |
586 |
ApiDescriptionManager.getDefault().clean(JavaCore.create(project), true, true); |
579 |
} |
587 |
} |
Lines 608-614
Link Here
|
608 |
* @param projects |
616 |
* @param projects |
609 |
* @return |
617 |
* @return |
610 |
*/ |
618 |
*/ |
611 |
private IResourceDelta[] getDeltas(IProject[] projects) { |
619 |
IResourceDelta[] getDeltas(IProject[] projects) { |
612 |
if(DEBUG) { |
620 |
if(DEBUG) { |
613 |
System.out.println("Searching for deltas for build of project: "+this.currentproject.getName()); //$NON-NLS-1$ |
621 |
System.out.println("Searching for deltas for build of project: "+this.currentproject.getName()); //$NON-NLS-1$ |
614 |
} |
622 |
} |
Lines 646-655
Link Here
|
646 |
/** |
654 |
/** |
647 |
* Returns the complete listing of required projects from the classpath of the backing project |
655 |
* Returns the complete listing of required projects from the classpath of the backing project |
648 |
* @param includeBinaryPrerequisites |
656 |
* @param includeBinaryPrerequisites |
649 |
* @return |
657 |
* @return the list of projects required |
650 |
* @throws CoreException |
658 |
* @throws CoreException |
651 |
*/ |
659 |
*/ |
652 |
private IProject[] getRequiredProjects(boolean includebinaries) throws CoreException { |
660 |
IProject[] getRequiredProjects(boolean includebinaries) throws CoreException { |
653 |
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); |
661 |
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); |
654 |
if (this.currentproject == null || workspaceRoot == null) { |
662 |
if (this.currentproject == null || workspaceRoot == null) { |
655 |
return new IProject[0]; |
663 |
return new IProject[0]; |
Lines 719-731
Link Here
|
719 |
projects.toArray(result); |
727 |
projects.toArray(result); |
720 |
return result; |
728 |
return result; |
721 |
} |
729 |
} |
722 |
|
|
|
723 |
/** |
724 |
* @return the workspace {@link IApiProfile} |
725 |
*/ |
726 |
IApiBaseline getWorkspaceProfile() throws CoreException { |
727 |
return ApiPlugin.getDefault().getApiBaselineManager().getWorkspaceBaseline(); |
728 |
} |
729 |
|
730 |
|
730 |
/** |
731 |
/** |
731 |
* Returns the output paths of the given project or <code>null</code> if none have been computed |
732 |
* Returns the output paths of the given project or <code>null</code> if none have been computed |
Lines 741-747
Link Here
|
741 |
* @param entry |
742 |
* @param entry |
742 |
* @return true if the specified {@link IClasspathEntry} is optional, false otherwise |
743 |
* @return true if the specified {@link IClasspathEntry} is optional, false otherwise |
743 |
*/ |
744 |
*/ |
744 |
private boolean isOptional(IClasspathEntry entry) { |
745 |
boolean isOptional(IClasspathEntry entry) { |
745 |
IClasspathAttribute[] attribs = entry.getExtraAttributes(); |
746 |
IClasspathAttribute[] attribs = entry.getExtraAttributes(); |
746 |
for (int i = 0, length = attribs.length; i < length; i++) { |
747 |
for (int i = 0, length = attribs.length; i < length; i++) { |
747 |
IClasspathAttribute attribute = attribs[i]; |
748 |
IClasspathAttribute attribute = attribs[i]; |
Lines 757-889
Link Here
|
757 |
public String toString() { |
758 |
public String toString() { |
758 |
return NLS.bind(BuilderMessages.ApiAnalysisBuilder_builder_for_project, this.currentproject.getName()); |
759 |
return NLS.bind(BuilderMessages.ApiAnalysisBuilder_builder_for_project, this.currentproject.getName()); |
759 |
} |
760 |
} |
760 |
|
|
|
761 |
/** |
762 |
* Return the last built state for the given project, or null if none |
763 |
*/ |
764 |
public static BuildState getLastBuiltState(IProject project) throws CoreException { |
765 |
if (!Util.isApiProject(project)) { |
766 |
// should never be requested on non-Java projects |
767 |
return null; |
768 |
} |
769 |
return readState(project); |
770 |
} |
771 |
|
772 |
/** |
773 |
* Reads the build state for the relevant project. |
774 |
*/ |
775 |
static BuildState readState(IProject project) throws CoreException { |
776 |
File file = getSerializationFile(project); |
777 |
if (file != null && file.exists()) { |
778 |
try { |
779 |
DataInputStream in= new DataInputStream(new BufferedInputStream(new FileInputStream(file))); |
780 |
try { |
781 |
return BuildState.read(in); |
782 |
} finally { |
783 |
if (DEBUG) { |
784 |
System.out.println("Saved state thinks last build failed for " + project.getName()); //$NON-NLS-1$ |
785 |
} |
786 |
in.close(); |
787 |
} |
788 |
} catch (Exception e) { |
789 |
e.printStackTrace(); |
790 |
throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, Platform.PLUGIN_ERROR, "Error reading last build state for project "+ project.getName(), e)); //$NON-NLS-1$ |
791 |
} |
792 |
} else if (DEBUG) { |
793 |
if (file == null) { |
794 |
System.out.println("Project does not exist: " + project); //$NON-NLS-1$ |
795 |
} else { |
796 |
System.out.println("Build state file " + file.getPath() + " does not exist"); //$NON-NLS-1$ //$NON-NLS-2$ |
797 |
} |
798 |
} |
799 |
return null; |
800 |
} |
801 |
|
802 |
/** |
803 |
* Sets the last built state for the given project, or null to reset it. |
804 |
*/ |
805 |
public static void setLastBuiltState(IProject project, BuildState state) throws CoreException { |
806 |
if (Util.isApiProject(project)) { |
807 |
// should never be requested on non-Java projects |
808 |
if (state != null) { |
809 |
saveBuiltState(project, state); |
810 |
} else { |
811 |
try { |
812 |
File file = getSerializationFile(project); |
813 |
if (file != null && file.exists()) { |
814 |
file.delete(); |
815 |
} |
816 |
} catch(SecurityException se) { |
817 |
// could not delete file: cannot do much more |
818 |
} |
819 |
} |
820 |
} |
821 |
} |
822 |
|
823 |
/** |
824 |
* Returns the File to use for saving and restoring the last built state for the given project. |
825 |
*/ |
826 |
static File getSerializationFile(IProject project) { |
827 |
if (!project.exists()) { |
828 |
return null; |
829 |
} |
830 |
IPath workingLocation = project.getWorkingLocation(ApiPlugin.PLUGIN_ID); |
831 |
return workingLocation.append("state.dat").toFile(); //$NON-NLS-1$ |
832 |
} |
833 |
|
834 |
/** |
835 |
* Saves the current build state |
836 |
* @param project |
837 |
* @param state |
838 |
* @throws CoreException |
839 |
*/ |
840 |
static void saveBuiltState(IProject project, BuildState state) throws CoreException { |
841 |
if (DEBUG) { |
842 |
System.out.println("Saving build state for project: "+project.getName()); //$NON-NLS-1$ |
843 |
} |
844 |
File file = getSerializationFile(project); |
845 |
if (file == null) return; |
846 |
long t = 0; |
847 |
if (DEBUG) { |
848 |
t = System.currentTimeMillis(); |
849 |
} |
850 |
try { |
851 |
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); |
852 |
try { |
853 |
BuildState.write(state, out); |
854 |
} finally { |
855 |
out.close(); |
856 |
} |
857 |
} catch (RuntimeException e) { |
858 |
try { |
859 |
file.delete(); |
860 |
} catch(SecurityException se) { |
861 |
// could not delete file: cannot do much more |
862 |
} |
863 |
throw new CoreException( |
864 |
new Status(IStatus.ERROR, ApiPlugin.PLUGIN_ID, Platform.PLUGIN_ERROR, |
865 |
NLS.bind(BuilderMessages.build_cannotSaveState, project.getName()), e)); |
866 |
} catch (IOException e) { |
867 |
try { |
868 |
file.delete(); |
869 |
} catch(SecurityException se) { |
870 |
// could not delete file: cannot do much more |
871 |
} |
872 |
throw new CoreException( |
873 |
new Status(IStatus.ERROR, ApiPlugin.PLUGIN_ID, Platform.PLUGIN_ERROR, |
874 |
NLS.bind(BuilderMessages.build_cannotSaveState, project.getName()), e)); |
875 |
} |
876 |
if (DEBUG) { |
877 |
t = System.currentTimeMillis() - t; |
878 |
System.out.println(NLS.bind(BuilderMessages.build_saveStateComplete, String.valueOf(t))); |
879 |
} |
880 |
} |
881 |
|
882 |
/** |
883 |
* Clears the last build state by setting it to <code>null</code> |
884 |
* @throws CoreException |
885 |
*/ |
886 |
void clearLastState() throws CoreException { |
887 |
setLastBuiltState(this.currentproject, null); |
888 |
} |
889 |
} |
761 |
} |