How to use PDE Source Lookup plugin? - eclipse-plugin

I installed PDE Source Lookup Plugin. However, I really have no idea how to use it? Supposedly, I think it should be similar to Java Source Attacher. But I did not find any button to trigger source code attaching.

PDE Source lookup author here.
When you open a class from an Eclipse plugin, if the sources are not attached, the Class file editor is opened, where you can manually attach missing sources. The PDE Source lookup plugin automatically detects that no sources were found so will initiate a source lookup automatically, in all available software sites (aka p2 repositories). If sources are found, they're downloaded and attached automatically, the Class file editor is then replaced by the proper source file. So this is on-demand, lazy source download.
Now, you can also fetch all sources at once from the "Plug-in Dependencies" classpath container, in the Explorer view, with a right-click and select Download Bundle Sources.

Related

How can I manually create a sources jar file to deploy to Nexus or use in Intellij?

I have here an outdated source code built with ant. But it's stil used as a library though.
For reference reason I want to able to have a look in the sources.
How can I manually create a sources jar file so that it's recognized by Intellij and Nexus as source to an already existing library?
So I can browse the referenced libraries sources for debugging reason for example.
Package the source code in a zip (in the same directory structure usually used in sources jars), and upload it in Nexus through artifact upload, giving it the classifier "sources". This should to the trick.

Java sources replaced by decompiled files in Intellij

When I'm opening a specific class using ctrl + right click I should be redirected to a window with the java sources which contains all the lines and the appropriate comments. But instead I get a window with the decompiled .class file.
I have tried to deactivate the decompiler plugin but it does not work.
If I add http://docs.oracle.com/javase/8/docs/api to Project Structure -> SDKs -> Documentation Paths I can get an overview of the class or method's I'm rolling over, but still can't open the right source file.
Any ideas?
When navigting to sources, IDEA will first go to attached sources. If not present, it will decompile the class and display it.
Try the following troubleshooting to track down the issue:
1. Make sure the sources are properly attached.
For libraries, Open the Project Structure dialog (Ctrl+Alt+Shift+S or ⌘;) and sel4ct "Libraries" on the left under "Project Settings". Find the library in question, and select it. It will show if the source is attached. You mentioned you have Maven's "Automatically download" sources/documentation both checked. So for any maven libraries that have source available, it should be listed.
If it is not listed or is in red, run "Download Sources" or "Download Sources and Documentation" from the Maven tool window. If the source is till in red, it likely means it is not available for that artifact in the maven repository. Use Maven Search to verify such.
For the JDK, select "SDKs" in the Project Structure dialog, find the JDK, and then select the "Sourcepath" tab. Make sure the {jdk-home}/src.zip file is listed.
IDEA should automatically set this when you add the JDK, but if not, add it.
2. Make sure the source JAR/ZIP file is not corrupt
Navigate to the archive in explorer/finder and make sure it can be opened and viewed.
3. Refresh IDEA's Caches
It's possible that IDEA's caches/indexes are corrupted. As such, IDEA is not "seeing" the link between the class and the source code. Go to File > Invalidate Caches / Restart...". Invalidate the caches and restart IDEA. Wait for IDEA to finish re-indexing the project and libraries (watch the progress in the bottom right of the IDEA window).
One of the above should resolve the issue.
FYI, If you do not want IDEA to decompile code(as a backup to no source being present), to the best of my knowledge (and based on the its help page), the only way to do such is to disable the "Java Bytecode Decompiler" in the Plugins list.
After ensuring my sources were attached, checking the source ZIP, invalidating the IntelliJ cache and restarting, I was still having the same problem.
To fix it, I created the project anew File > New > Project From Existing Sources..., and when I got to the library selection step I deselected the .jars for my own modules.

When deploying Xtext, how to integrate with Eclipse via plugin?

I have finished a beta of my Xtext and Xtend project. Now I want to integrate it with an Eclipse. Using this new Eclipse I want to be able to choose "New 'mydsl' project", then in this new project I want to have a .jar referenced by default. Also an empty file of mydsl. If it is possible, get rid of adding Xtext nature to project .
There are several non-trivial processes for this question:
To be able to choose "New 'yourDSL' project", you will have to implement your own project wizard. That is, in your plugin.xml file you have to contribute to the extension point "org.eclipse.ui.newWizards" and create a class that must implement the INewWizard interface, you can do so by extending the Wizard class.
That wizard, in the performFinish() task, should create a IJavaProject programatically where you can specify the Natures that you want. You also will have to specify the source and output folders, and configure the classpath (adding the classpath entries) as well. This link goes on more detail on how to create the project. http://www.pushing-pixels.org/2008/11/18/extending-eclipse-creating-a-java-project-without-displaying-a-wizard.html
In the previous step (#2), when creating your custom project, you can add packages, folders, files, so you can add your empty .mydsl files.
Now the trickiest part. To have the .jar file referenced by default there are several approaches. The easiest one is if you know the .jar path beforehand, you can add the reference by adding (in step #2) a classpath entry of type CPE_LIBRARY that point to that .jar file, but again you need to know the path somehow. In my case I didn't know the path because my .jar file was a library exported as plugin, so I ended up by implementing an IClasspathContainer that looks up for my plugin-library (.jar file) among the installed plugins. You can look up for your a plugin by doing:
Bundle bundle = Platform.getBundle("com.my.libraryPlugin");
File bundleFile = FileLocator.getBundleFile(bundle);
... and then, in step #2 what I add is a classpath entry of type CPE_CONTAINER:
JavaCore.newContainerEntry("MY_CONTAINER");
You can read more about IClasspathContainer here: http://www.ibm.com/developerworks/opensource/tutorials/os-eclipse-classpath/section2.html
5- You probably know how to do this already. The last step is to export your DSL plugins and copy them in the "plugins" folder in the Eclipse installation. To export the plugins: Select the projects -> Right-click -> Export -> Plug-in Development -> Deployable plug-ins and fragments...

Why is the "Source Code Locations" page missing on eclipse 3.6 (Helios)

I'm trying to add JFace source code on my Target Platform in Eclipse 3.6.
Many help page on the internet refers to a "Source Code Locations" tab from the Target Platform preferences page.
I do not have that tab on a fresh Eclipse 3.6 including RCP development (eclipse-rcp-helios-SR1-RC4-win32.zip). Here's a screenshot of my Target Platform preferences page :
Any idea how add source code to my target platform ?
Many help page might refer to that tab, but the Eclipse Helios page doesn't.
As far as I can see, this is no longer available with Eclipse 3.6.
You can add your source when exporting your plugin, but that is not exactly the same.
The "Generating Source Features and Plug-ins" is still there though.
It was the alternative mentioned by the old Ganymede Help page
Declared Source Locations
An alternative way to ship source code locations is to use declared (pre-defined) source locations.
This is done by using the org.eclipse.pde.core.source extension.
A plug-in defining this extension will be treated as a source location.
The extension point schemas and source archive(s) for a plug-in are located in a unique subdirectory under one of these source code locations.
The name and structure of the subdirectories must follow a specific convention.

How do I add my fragment to the list of required-plugins on an existing plugin

I currently have an existing plugin, which references a class from a required plugin. I have replaced this code with a reference to a class which is part of my fragment.
I am facing two issues.
If I import my fragment as a jar file, I am not able to see the changes I have made as the plugin running as an eclipse application results in a ClassNotFoundException
To overcome this, I link an additional source (of fragment) to the existing plugin project. However, the link uses an absolute path, and makes it unfit for deployment.
I want to be able to package the plugin with the code modification and be able to "depend" on my fragment code. Is there a way I can add my fragment as a dependency?
For example:
Plugin Project I am changing : org.eclipse.*.editor
it depends on org.eclipse.*.edit
I have a fragment mydomain.*.edit which has org.eclipse.*.edit as host plugin
I want org.eclipse.*.editor to pick up mydomain.*.edit
instead of org.eclipse.*.edit
ps: I have also tried packaging the jar file for the mydomain.*.edit in the plugins directory and try and pick it up from there, it doesnt show up on the list when I click add required plugins on the dependency tab on the plugin.xml file of the org.eclipse.*.editor
Please let me know if I am not clear enough, I will try and rephrase it.
Thanks in advance!
If I understand correctly what you want to do, I don't think that it's possible. You will have to try some other way.
Plugins have dependencies on other plugins. Fragments don't exist as separate runtime entities, but only as extensions of a plugin. So your plugin can only refer to the 'editor' plugin.
Classes provided by a fragment can't (and shouldn't) be accessed directly. They can be returned by the original plugin (A) if they are implementing an executable extension provided by plugin A.
If you refer to the fragment's code from another plugin (B), the classes will be loaded by plugin B's classloader and be different from the ones that are loaded by plugin A.
What is the purpose of your fragment? Do you want to get access to internal code in plugin A? Do you want to extend an eclipse editor?
If you want to extend functionality that the original plugin is not exposing as extensible, I think the only way is to write a plugin, extend the editor class from the original plugin, register it alongside the original one and use it instead.
[Edit] Maybe this link will explain better: Eclipse FAQ
Hope this helps,
Vlad
Thanks Vlad,
Your explanation was very helpful. Unlike the extension based architecture that is truly intended for fragments, I had to modify a certain component in the editor that was not exposed as part of the extension. This modification referred to an external project I created as an fragment but could have been a normal java project packaged a jar file that I could place in the classpath of the editor.
I was able to resolve the dependency issues by placing the jar file in class path, however when I export the plugins and related plugins as jar files and place it in the dropin directory, it does not install correctly. (Nor does placing the jar files in the plugins directory)
The eclipse editor that I am trying to modify uses the EMF project. I have kept the EMF project in the workspace inorder to resolve dependencies of the editor. However when I replace the EMF jar files bundled with eclipse with the one in the workspace, the files that I want to edit are not correctly recognized.
Is there another way of doing this?