Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » workspace use-case that Eclipse fails to handle: build newly-opened project
workspace use-case that Eclipse fails to handle: build newly-opened project [message #329063] Wed, 11 June 2008 15:54
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
R3.x
WinXP

Imagine that one has N projects of type "pro" (pro != java) and that
upon startup some of those projects are closed. Now the user opens one
of those projects, and the system wants to create the in-memory model --
i.e., we need to "build" the project.

Eclipse does not apparently provide a means to do this. (See below for
my attempts to work around this. Moreover, there does not seem to be a
method within the Eclipse framework even to *determine* if a project
needs to be built -- no "IProject.isDirty()", no
"Workbench.isProjectBuilt(IProject)", etc. )

So -- what is the best-practices hack to accomplish this?

thanks,
Paul

============================================================ ========

a) if I try to use an IResourceChangeListener, I can parse the various
codes and types and deltas and resources that are sent under various
conditions, and the case at hand ("project opened") is signaled by
(IResourceChangeEvent.getType() & IResourceChangeEvent.POST_CHANGE) !=
0, when also IResourceChangeEvent.getDelta().getAffectedChildren()
contains an IResourceDelta for which (IResourceDelta.getResource()
instanceof IProject && ((IResourceDelta.getFlags() &
IResourceDelta.OPEN) != 0) &&
IResourceDelta.getResource().getProject().isOpen() -- at least, as far
as I can tell.

BUT, if at that point, I try to call:

project.build(IncrementalProjectBuilder.FULL_BUILD, monitor)
(or CLEAN_BUILD)

I get a

!MESSAGE The resource tree is locked for modifications.
!STACK 1
org.eclipse.core.internal.resources.ResourceException: The resource tree
is locked for modifications.
at
org.eclipse.core.internal.resources.WorkManager.checkIn(Work Manager.java:94)
at
org.eclipse.core.internal.resources.Workspace.prepareOperati on(Workspace.java:1684)
at org.eclipse.core.internal.resources.Project.build(Project.ja va:80)

consistent with the javadocs for IResourceChangeEvent.

============================================================ ========

b) no other relevant message from the IResourceChangeListener is
available, and only the IResourceChangeEvent.PRE_BUILD and
IResourceChangeEvent.POST_BUILD types occur when the resource-tree is
"open" -- but they are not sent when a project is *opened* because no
build occurs then!

============================================================ ========

c) the ISaveParticipant recommended at some point is not relevant to
this case (the workspace is not being *saved* when a project is newly
opened).

============================================================ ========

d) what I'm doing now is to spawn a Job to build and making it wait
until the "resource tree" is no longer locked, like this:

public IStatus run(final IProgressMonitor monitor) {
while (_project.getWorkspace().isTreeLocked()) {
try {
Thread.sleep(100);

} catch (InterruptedException exn) {
; // deliberately no-op: just wait some more
}
}
try {
_project.build(IncrementalProjectBuilder.CLEAN_BUILD,
monitor);
return Status.OK_STATUS;

} catch (Exception exn) {
Status status = new Status(
IStatus.ERROR, Activator.PLUGIN_ID, IStatus.OK,
exn.getMessage(), exn);
Activator.getDefault().getLog().log(status);
return status;

} finally {
if (null != monitor) {
monitor.done();
}
}
}

============================================================ ========
Previous Topic:open external editor on a file NOT in the workspace ...
Next Topic:Platform.getBundleGroupProviders() fails
Goto Forum:
  


Current Time: Thu Jul 18 03:32:59 GMT 2024

Powered by FUDForum. Page generated in 0.03544 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top