Eclipse Plugin Development - Getting information from Team Provider - eclipse

I am very new to developing eclipse plugins. The biggest hurdle I am facing right now is where/how to get at the data from various other plugins. I am having a real hard time finding documentation for this. For instance the Team Provider plugin....
How do I read the svn revision of a file? Lets say I have an IResourceChangeListener and I want to keep track of the svn revision number of a file (if the user did an update for example).
If I want to ask svn if there are pending updates for a project, how do I talk to the eclipse team provider?
I am not sure where to start...
Thanks!

I eventually discovered what I was looking for after many hours of searching. Unfortunately since I have less than 100 rep. I have been unable to post until now....
I am making a little progress on this. I randomly stumbled upon this while pouring through eclipse source code.
The following code snippet monitors everything that goes on with regard to an svn enabled project. If you save a file, to an update, revert etc. Anything that touches the files or meta data of the files. I just print out the file/direcory name and its revision number.
Subversive version:
final Subscriber subscriber = UpdateSubscriber.instance();
subscriber.addListener(new ISubscriberChangeListener() {
#Override
public void subscriberResourceChanged(ISubscriberChangeEvent[] events) {
for(ISubscriberChangeEvent event : events) {
UpdateSyncInfo info = (UpdateSyncInfo) subscriber.getSyncInfo(event.getResource());
System.out.println(event.getResource().getName()+" revision: "+uInfo.getLocalResource().getRevision());
}
}
});
The real trick was figuring out the entry point to get at this information: UpdateSubscriber. It would be nice if there was a good resource for finding out this sort of information.
Subclipse version:
private static final Subscriber subscriber = SVNWorkspaceSubscriber.getInstance();
private static final ISubscriberChangeListener subsciberListener = new ISubscriberChangeListener() {
#Override
public void subscriberResourceChanged(ISubscriberChangeEvent[] events) {
try {
for (ISubscriberChangeEvent event : events) {
SVNStatusSyncInfo info = (SVNStatusSyncInfo) subscriber.getSyncInfo(event.getResource());
System.out.println(event.getResource().getName() + " revision: " + info.getRepositoryRevision());
}
} catch (TeamException e) {
}
}
};
#Override
public void start(BundleContext context) throws Exception {
super.start(context);
subscriber.addListener(subsciberListener);
}
#Override
public void stop(BundleContext context) throws Exception {
subscriber.removeListener(subsciberListener);
super.stop(context);
}

For general information on the Team API in the Eclipse platform, review the documentation in the help system.
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/team.htm
(If you're working with the Subscriber stuff, it appears that's mentioned under the "Synchronization Support" -> "Beyond the Basics" topic.)
The Java doc for the team packages also helps:
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/team/core/package-summary.html
If you're trying to integrate with or otherwise extend the Subclipse or Subversive team providers, you may have better luck asking your question in their forums:
http://subclipse.tigris.org/ds/viewForums.do
http://www.eclipse.org/subversive/newsgroup.php

One starting point would be to explore the sources of subversive to see how they did their implementation of the features you are describing.
The sources for eclipse.team (the common module for all VCS plugins) are available in a Git repo.
The sources for EGit, another VCS plugin (for Git) can also be instructive.

Related

How does merge work within eclipse?

Perhaps I am looking in the wrong places, but can anyone explain how "Team >> Merge" works within Eclipse? I ended up with instances of git comments interjecting into my code throughout the project, and would like to not have to delete my branch and rebuild.
Example:
<<<<<<< HEAD
static final void method(String input) {
=======
static final void method(String input, int i) {
>>>>>>> master
Your git found a conflict there. You have now both version in your code HEAD and master. You should check which version you want to keep, and remove manually the the rest.
Just literally delete the <<<<<< HEAD stuff, till you only see static final void method(String input) {.
Since I'm working with Android, I didn't use Eclipse in years, but there should be a way to use a GUI for git, so you don't have to delete those lines manually.

Does JGit support .gitattributes?

I'm trying to understand how to use the .gitattributes from JGit. But I'm unable to find any tutorial which best demonstrates it.
Is it that JGit hasn't support for it. But git client has this support. Why not JGit?
JGit has basic support for .gitattributes. See bug 342372 and related bugs for the current state of development.
The JGit test suite may help you understanding how .gitattributes are implemented in JGit. See this article for how to work with the JGit sources.
If you would like to try libgi2, there is a jni bindings that allows you to access most recent libgit2 attributes apis
Following are some examples:
Repository testRepo = Repository.open("path-to-your-repo");
// load macros from .gitattributes file
Attr.addMacro(testRepo, "binary", "-diff -crlf");
// Loop through all attributes
Map<String, String> attributes = new HashMap<>();
Attr.foreach(
testRepo,
EnumSet.of(CHECK_INDEX_THEN_FILE),
".",
new Attr.ForeachCb() {
#Override
public int accept(String name, String value) {
attributes.put(name, value);
return 0;
}
});
You can find the test case about these apis here

How do I easily query a running Eclipse for its installed Features?

I'm building an Eclipse Feature that has a requirement that amounts to this... The Feature must be able to be uninstalled automatically if the user has his license revoked.
If you want more background information about that, Here is another question that I've asked on this topic.
Thanks to the answers on that question, I've been trying to learn the Eclipse p2 director api. I've found some classes that look useful here
I've been trying to instantiate one of these classes in my code, but with no luck yet.
I've been reading the help documentation, and I'm getting kind of lost in it all.
I'm stuck because I have a need to supply the OperationFactory with a collection of IInstallableUnit objects.
private void scheduleUninstallOperationJob(
Collection<? extends IVersionedId> toUninstall)
{
OperationFactory oFactory = new OperationFactory();
Collection<URI> repos = null;
UninstallOperation op = null;
try {
op = oFactory.createUninstallOperation(toUninstall, repos, null);
} catch (ProvisionException e) {
e.printStackTrace();
}
IStatus result = op.resolveModal(null);
if (result.isOK()) {
op.getProvisioningJob(null).schedule();
}
}
I don't see any way to easily ask the running instance of Eclipse to give me the collection of currently installed InstallableUnits so that I can easily pass the one I want to uninstall to the OperationFactory.createUninstallOperation() method.
I've tried using Eclipse source code as an example, but the code that I have found is the org.eclipse.equinox.p2.ui.ProvisioningUI, and it's tightly coupled to the UI that is used when manually uninstalling InstallableUnits. This code also uses code that is in the dreaded Eclipse internal packages which I would like to avoid using if possible.
Thank you for your consideration, Trace
This code gets the collection of IUs which are managed by the profile of the currently running system:
/**
* This Activator informs user about the IUs which are currently installed in
* the running environment.
*
* This code is intended for demo only and should be much more defensive for
* production use.
*
* #author Ilya Shinkarenko
*
*/
public class SelfInformerActivator extends Plugin {
#Override
public void start(final BundleContext ctx) throws Exception {
super.start(ctx);
ServiceReference<IProvisioningAgentProvider> sr = ctx.getServiceReference(IProvisioningAgentProvider.class);
IProvisioningAgentProvider agentProvider = ctx.getService(sr);
URI p2InstanceURI = null; // myself
final IProvisioningAgent agent = agentProvider.createAgent(p2InstanceURI);
IProfileRegistry regProfile = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
IProfile profileSelf = regProfile.getProfile(IProfileRegistry.SELF);
IQuery<IInstallableUnit> query = QueryUtil.createIUAnyQuery();
//This is what you need:
IQueryResult<IInstallableUnit> allIUs = profileSelf.query(query, new NullProgressMonitor());
//Let's output it:
Iterator<IInstallableUnit> iterator = allIUs.iterator();
while (iterator.hasNext()) {
IInstallableUnit iu = iterator.next();
System.out.println(iu);
}
}
}
There was very little traffic on this question. I attribute that to the odd nature of the requirement that is driving this development.
Well, it seems that those requirements have changed, and I will no longer be needing to programmatically uninstall Eclipse Features based on a revoked license. Therefore I will stop researching how to do this for now.
If you're looking to solve this issue to, feel free to contact me by leaving a comment here, or answering this question with another question. :)

How two people, concurrently editing the same file is handled?

I believe the title says it. I'm new to source control thingy.
So, let's say I have two developers working on the same project and they started editing the same file(s) at the same time then everyone of them send the new version at a slightly different time. From what I understand the one who sends the changes last will have his changes kept, the other one's code will be in the archive only!!!
Is that correct?
Please clarify. Thanks.
No, that's not quite correct. It depends somewhat on which version control software you're using, but I like Git so I'll talk about that.
Suppose we have a file Foo.java:
class Foo {
public void printAWittyMessage() {
// TODO: Be witty
}
}
Alice and Bob both modify the file. Alice does this:
class Foo {
public void printAWittyMessage() {
System.out.println("Alice is the coolest");
}
}
and Bob does this:
class Foo {
public void printAWittyMessage() {
System.out.println("Alice is teh suk");
}
}
Alice checks her version in first. When Bob attempts to check his in, Git will warn him that there is a conflict and won't allow the commit to be pushed into the main repository. Bob has to update his local repository and fix the conflict. He'll get something like this:
class Foo {
public void printAWittyMessage() {
<<<<< HEAD:<some git nonsense>
System.out.println("Alice is the coolest");
=====
System.out.println("Alice is teh suk");
>>>>> blahdeblahdeblah:<some more git nonsense>
}
}
The <<<<<, ===== and >>>>> markers show which lines were changed simultaneously. Bob must resolve the conflict in some sensible way, remove the markers, and commit the result.
So what eventually lives in the repository is:
Original version -> Alice's version -> Bob's conflict-fixed version.
To summarise: the first to commit gets in without any problems, the second to commit must resolve the conflict before getting into the repository. You should never end up with someone's changes being clobbered automatically. Obviously Bob can resolve the conflict incorrectly but the beauty of version control is that you can roll back the incorrect fix and repair it.
Much depends on the system you're using.
However in the common case is: who commits his changes second would have to perform a "merge" operation. Meaning s/he would need to compare the two files and come up with a merged version. However (!) many popular system (including IDE) comes with smart tools to assist you doing that.
Here are some tools like that compared:
http://en.wikipedia.org/wiki/Comparison_of_file_comparison_tools

Eclipse RCP: How to access internal classes of plugins?

I want to use the default XML editor (org.eclipse.wst.xml.ui) of Eclipse in an RCP application. I need to read the DOM of the xml file currently open. The plugin doesn't offer any extension point, so I'm trying to access the internal classes. I am aware that the I should not access the internal classes, but I don't have another option.
My approach is to create a fragment and an extension point to be able to read data from the plugin. I'm trying not to recompile the plugin, that's why I thought that a fragment was necessary. I just want to load it and extract the data at runtime.
So, my question is: is there another way to access the classes of a plugin? if yes, how?
Any tutorial, doc page or useful link for any of the methods is welcome.
Since nobody answered my question and I found the answer after long searches, I will post the answer for others to use if they bump into this problem.
To access a plugin at runtime you must create and extension point and an extension attached to it into the plugin that you are trying to access.
Adding classes to a plugin using a fragment is not recommended if you want to access those classes from outside of the plugin.
So, the best solution for this is to get the plugin source from the CVS Repository and make the modifications directly into the source of the plugin. Add extension points, extensions and the code for functionality.
Tutorials:
Getting the plugin from the CVS Repository:
http://www.eclipse.org/webtools/community/tutorials/DevelopingWTP/DevelopingWTP.html
Creating extensions and extension points and accessing them:
http://www.vogella.de/articles/EclipseExtensionPoint/article.html
http://www.eclipsezone.com/eclipse/forums/t97608.rhtml
I ended up extending XMLMultiPageEditorPart like this:
public class MultiPageEditor extends XMLMultiPageEditorPart implements
IResourceChangeListener {
#Override
public void resourceChanged(IResourceChangeEvent event) {
// TODO Auto-generated method stub
setActivePage(3);
}
public Document getDOM() {
int activePageIndex = getActivePage();
setActivePage(1);
StructuredTextEditor fTextEditor = (StructuredTextEditor) getSelectedPage();
IDocument document = fTextEditor.getDocumentProvider().getDocument(
fTextEditor.getEditorInput());
IStructuredModel model = StructuredModelManager.getModelManager()
.getExistingModelForRead(document);
Document modelDocument = null;
try {
if (model instanceof IDOMModel) {
// cast the structured model to a DOM Model
modelDocument = (Document) (((IDOMModel) model).getDocument());
}
} finally {
if (model != null) {
model.releaseFromRead();
}
}
setActivePage(activePageIndex);
return modelDocument;
}
}
This is not a clean implementation, but it gets the job done.