Thursday, April 9, 2015

Eclipse Jobs framework best practice: Handling the long running background jobs while Eclipse shutdown

How to handle background jobs which are running silently for a long time during the Eclipse shutdown ?

Solution would be to cancel all the jobs before before plugin stops,so that jobs won't complain about the other resources availablity. If we don't do this, some times we can get some null pointer issues in the log.

In Plugin Activator class, just invoke Job.getJobManager().cancel(jobName);


import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.osgi.framework.BundleContext;

public abstract class AbstractJob extends Job
{

private String jobFamilyName;

public AbstractJob(String name, String jobFamilyName)
{
super(name);
this.jobFamilyName = jobFamilyName;
}

@Override
public boolean belongsTo(Object family)
{
return this.jobFamilyName.equals(family);
}
}

Your Actual Job Implementation:

Job coreJob = new AbstractJob("Collecting assets", "ASSETS_FAMILY")
{

@Override
protected IStatus run(IProgressMonitor monitor)
{
//TODO: some long work job

return Status.OK_STATUS;
}
};

coreJob.schedule();


In Activate Class:

public void stop(BundleContext context) throws Exception {
plugin = null;
Job.getJobManager().cancel("ASSETS_FAMILY");
super.stop(context);
}

This will cancel all the jobs who's family name is ASSETS_FAMILY.


Wednesday, April 8, 2015

Adding resource filter for project in eclipse

try
{
project.createFilter(IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FOLDERS,
new FileInfoMatcherDescription("org.eclipse.core.resources.regexFilterMatcher", //$NON-NLS-N$
"node_modules"), IResource.BACKGROUND_REFRESH, new NullProgressMonitor());
}
catch (CoreException e)
{

}


This piece code will hide the "node_modules" folder from project.

Tuesday, March 24, 2015

Registering a listener for changes in network connections and proxy from eclipse preferences

import org.eclipse.core.net.proxy.IProxyChangeEvent;
import org.eclipse.core.net.proxy.IProxyChangeListener;
import org.eclipse.core.net.proxy.IProxyService;
import org.osgi.util.tracker.ServiceTracker;

public class ProxyHelper
{

public void registerListener()
{
ServiceTracker tracker = new ServiceTracker(MyPlugin.getDefault().getBundle().getBundleContext(),
IProxyService.class.getName(), null);
tracker.open();
IProxyService proxyService = (IProxyService) tracker.getService();
proxyService.addProxyChangeListener(new IProxyChangeListener()
{

@Override
public void proxyInfoChanged(IProxyChangeEvent event)
{
// TODO: your action for proxy changed
}
});
}

}

Sunday, March 22, 2015

Tool for checking MD5 and SHA1 values for any file

Git: Updating a forked repository from the original repository

Let's take a scenario:

This is the remote repository: https://github.com/apache/mystudio.git
Your forked repository from the above:  https://github.com/kolipakakondal/mystudio.git

'development' is the branch name both in remote and forked repository.

1. Add remote repository to forked repository
>git remote add upstream https://github.com/apache/mystudio.git

2.  Fetch from remote repository .i.e upstream
> git fetch upstream

3. Rest your branch(ex: development) to the remote branch(ex: development)
> git reset --hard upstream/development

4. Pushed changes which we got it form remote repo to remote forked repo.
> git push origin  development --force






Friday, March 20, 2015

Debugging an Installer Plugin


Step 1 : Configure your Xcode project

1Open your plugin project in Xcode.
2Choose Project > New Executable…
3Click Choose.
4Select Installer.app.
You can find Installer.app in /System/Library/CoreServices on Mac OS X 10.5 (or later) and in /Applications/Utilities on earlier versions.
5Click Finish.
6Choose Project > Set Active Build configuration > Debug.
7Choose Build > Build.

Step 2 : Debug

1Add breakpoints in Xcode
2Copy your plugin into the Plugins folder.
3Choose Debug > Debug Executable in Xcode.
4Open your package with Installer.app.


Product->Scheme->Edit scheme -> 
This will launch below screen