How can I get a notification when build workspace is finished? - eclipse

How can I write a plugin or program routine that gets notified when "build workspace" finishes in Eclipse?
Is IProgressMonitor useful for this? If so, how do I get ahold of it?

You can wait for the automatic build to finish using:
Platform.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
This will block until the builds have finished (and do nothing if the build is not running).
You would probably also want to wait on the manual builds are well:
Platform.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_BUILD, null);

If you really want to receive a notification (rather than blocking), try this:
IWorkspace.addResourceChangeListener(myListener, IResourceChangeEvent.POST_BUILD);
The Javadoc of IResourceChangeEvent gives more details on usage and on information found in the event instance.

Related

Eclipse: how to avoid blocking user input of frequent saves with build on save enabled?

I have activated an option "Build on resource save". My typing habits is to save the code every few seconds and whenever previous build is not complete before I save again, I get a window like this:
Basically Eclipse is forcing me to wait before it will finish the previous build and start a new one. Can I somehow configure it, so that it will start new build automatically once the previous is completed and will not block my input? It is okay if it will incorporate multiple consequent saves of the code.
Essentially, my solution was not to build on save. As scottb mentioned in comments it is too complicated to actually decide when it is save to build and when it is not.

Passing an object as a parameter to a command

I Have two commands in my eclipse plugin. (Upload and Run). They can be invoked by the user one after another. So it only makes sense to invoke Run after the upload command is done.
Since the upload command possibly takes some time it will schedule a WorkspaceJob for actual execution. And returns right after it scheduled the job.
What i like to do know is to add another command called "Upload and Run" which (suprisingly) is supposed to first upload and then run the selection. Therefore it must be notified when the WorkspaceJob started in the Upload command has finished.
So i'd like to parameterize the command with an additional IJobChangeListener which it will add when the WorkspaceJob is scheduled.
Unfortunately it seems to me like it's only possible to pass Strings as parameters to a command or Objects that can be converted to Strings easily. However a Listener like this cannot be passed as a String.
How can i provide the command with such an Listener Object?
Is there maybe an other way of providing the Listener Object to the Command (other than passing it as a prameter) that i didn't think of?
Since your "Upload and Run" action is going to start the upload, you could then just schedule another job for the Run-action which simply calls join() on the workspace job-reference you have before doing anything else.
Update:
I think you're running into a limitation of the framework there. The commands are intended as an abstraction on the user-interface, not as an abstraction of getting things done. I'd simply go with reusing the Java code that you have, and directly invoke the code for both actions from the button for the joint functionality.

How to auto terminate instances of Java application in eclipse?

I was doing a small project and everytime I run the program, I can feel more lag and delay, until it is completely not working anymore.
I checked with the task managers and found many "Javaw.exe" Instances. Then I opened the debug field and realize that it runs a new instance everytime I run the same project.
here is the link to image of the instances in debug area.
http://i50.tinypic.com/2hz4spu.png
The temporary solution for me is to terminate them from the debug area. Is there any way to prevent the same project from creating a new instance everytime it is run ? I only need one instance that can be reused everytime I run again and again.
Thanks for any response in advance.
No, I'm sure that's not what you want. If you restart an application, it's probably that you want to test some changes you've just made in the code. So Eclipse needs to start a new instance of your application. You could also want to start two instances of an app because they need to talk to each other.
If you want previously launched applications to stop, then stop them. Your app seems to be a GUI app. Use the close button on the main frame of the app to close it. As simple as that.
It's often not desired to kill an application, because it might need to properly close resources, or tell the server it's leaving before exiting, or whatever. Having Eclipse kill apps without a conscious request from the user would not be wise.

Can eclipse notify me when a task has finished running?

I am often stuck twiddling my thumbs for a couple minutes while eclipse cleans, builds, or loads my projects. It would be nice if eclipse could notify me with a beep when the last task in the Progress view has finished running, so I can stop reading the internet and get back to work. Is there a setting or plugin that does this?
Edit: I tried adapting the plugin template that nonty provided below, which adds a listener to the JobManager. I tried implementing done() to beep only when the job change event's name contains "Building workspace," as that is the task that usually takes the longest in my setup. Exasperatingly, the task that builds the workspace never sends a done() call, just scheduled() and aboutToRun() calls. Any other ideas?
There are no preference for this - yet.
The JobManager have the needed API to support this functionality...
EDIT: I have constructed and attached a very simple plug-in that will beep for every job that terminates. That turns out to be rather often :-) . You can modify it to filter out all the false positives, e.g. by getPriority() and getName(). Also you can make the listener play a tune, popup a message (don't!) or whatever...
See jobnotifier.zip.
UPDATED the link above again

Eclipse plugin - handling events when stepping or breaking

Is there a generic way of receiving event notifications from the Eclipse debugger. Specifically I would just like to know when the user steps over/into and when a breakpoint is hit.
I have already got this working in JDT (see my other question: Eclipse Debugger Events) but the same technique doesn't work in CDT (I am using DebugPlugin.addDebugEventListener).
If there is no generic way of doing this, then is there a way to avoid the CDT dependencies from breaking the plugin when it is run in JDT?
Thanks,
Alan
OK, I've found an alternative that may be of use for others. You can use the method outlined above to listen for debug events when the session is created and terminated.
For any stepping events, one way I found was to register an IExecutionListener to be notified of all commands that take place in the Eclipse workspace. You can register an execution listener by getting hold of an ICommandService as follows:
ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class)
Then add an execution listener:
commandService.addExecutionListener(this);
This will give you various event handlers (notHandled, postExecuteFailure, postExecuteSuccess, preExecute) from which you can filter by the commandId value.
I hope this helps someone else.
Alan