How can I modify the .buildpath file in my Eclipse plugin? - eclipse

I have written a plugin that uses PDT (and thus DLTK) to create a customized project. I now to need to add libraries to the buildpath of my custom project.
I do have a plugin that contains these libraries and I've been struggling trying to figure out how to create / modify the .buildpath file. I was not successful trying to use BuildpathEntry, as it seemed to fail because the path I provided to .buildpath did not contain a device id.
I'm not sure where to go from here.
EDIT: I'm trying to add PHP libraries to the .buildpath file of my PDT project in my custom plugin, just to be clear ;)

You could do this with the addEntriesToBuildPath method of org.eclipse.php.internal.core.buildpath.BuildPathUtils.
Add org.eclipse.php.core and org.eclipse.dltk.core to the dependencies of your plugin.xml. (you have need installed PDT SDK)
Add the build path entry when create the project:
IScriptProject scriptProject = DLTKCore.create(project);
List<IBuildpathEntry> bentries = new ArrayList<IBuildpathEntry>();
IBuildpathEntry juliaServerEntry = DLTKCore.newProjectEntry(new Path("/otherproject"));
bentries.add(juliaServerEntry);
BuildPathUtils.addEntriesToBuildPath(scriptProject, bentries);

Related

Exporting an Eclipse plugin with a dependency on an external jar

Just recently started using Eclipse and ran into an issue with exporting the plugin I'm working on. I tried to search but so far no luck - but if the answer is already here I'd be grateful if someone can point me to it.
I'm writing a n OSGi/Equinox plugin with Eclipse. The plugin is for a 3rd party system, which allows extensions: basically all jars placed in the application's plugin folder are automatically loaded into the application at startup. I have managed to put together my plugin, it's loading fine and it works.
The issue is that I rely on another plugin which is placed beside mine in the plugins folder. For obvious reasons I do not want to package that plugin into my plugin jar file. I have tried to add the dependency as an external archive, but this breaks the export: when I try to export my plugin project ant complains about missing dependencies and types. (If I actually include the other jar file in my plugin everything works, but obviously this is less then ideal.)
So: how do I set up my plugin project dependency, that it's a) an external dependency and b) doesn't need to be specified with a path or a variable - i.e. how do I tell my exporter to "don't worry, it will be there right beside you"?
Edit: Apparently there's an important detail I didn't mention. The external jar file I depend on is not an OSGi plugin, just a regular jar file with some classes in it. To the 3rd party system it seems all the same (all are under the plugins folder, all are loaded into the application), but for Eclipse the distinction seems important.
If you reference the other plug-in as a dependency in your plug-in's MANIFEST.MF the export should work without errors. The plug-in should be listed in the Require-Bundle list in the MANIFEST.MF.
You can do this in the MANIFEST.MF editor by adding to the 'Required Plug-ins' list on the 'Dependencies' tab of the editor.
Note: When referencing other plug-ins you must always use this method. Do not try adding the plug-in jar to the Java build path or anything like that.
If the jar you want to use is not an Eclipse plug-in you must should include it as part of the plug-in and list the jar in the Bundle-Classpath in the MANIFEST.MF. If you cannot do this you can reference an external jar in the Bundle-Classpath using something like:
Bundle-Classpath: .,external:$LIB_LOCATION$/lib.jar
. is the normal entry in for the plug-in code. external:$LIB_LOCATION$/lib.jar looks for lib.jar in a location defined by the environment variable LIB_LOCATION. This method can be difficult to get right.
In the end the solution to my specific problem was to add the external jar file as an Extra Classpath Entry on the build properties tab (this translated to a "jars.extra.classpath = .jar" entry in the build.properties file). I have also added the jar file to the project itself - after adding the extra class path entry that got changed into an external dependency automatically.
With these two changes I was able to successfully export my plugin, which didn't contain the external jar file, but was able to reference it when loaded into the 3rd party system.

Checkstyle: Custom Rules - Eclipse Plugin

I have written few custom checkstyle rules using checkstyle API. They run fine using Maven (after I add the new project as a dependency to the checkstyle plugin).
Now I want these rules to be used by the Eclipse Checkstyle plugin. And this is where I am stuggling.
I've downloaded the sample plugin project (as suggested here and here).
I do not understand what to do next after reading these links.
Do I need to export my project as a JAR?
How do I plug it into my existing Checkstyle plugin?
Thanks
You can do it like following :
Create plugin project and add your custom checks there.
Make appropriate changes to plugin.xml, checkstyle_packages.xml.
Export the project as Deployable Plug-ins and fragments (Export > Plug-in Developement)
Copy the jar file to Eclipse Plugin folde, so no need to install your custom check .
You can refer this tutorial
You already have the correct links that will eventually get you there. As for your questions:
All your custom checks can go into one JAR file. That JAR file must be an Eclipse plugin JAR. I simply install it by copying it to the Eclipse dropins folder, but there may be more elegant ways to do that.
So you end up with two plugins: The original, unmodified Eclipse-CS, and your own plugin which contains the custom checks. When both are independently installed in Eclipse, the Eclipse-CS configuration dialog will offer your custom checks for use in Checkstyle configurations.

Programmatically remove linked files from the project in eclipse

I'm developing plugin for Eclipse. This plugin nothing else but the wizard to allows user to create its own file format with inbuilt jar files inside. All the JARs inside are linked resources for the project.
To clean the project I need to remove all the linked JARs from the project programmatically.
Are there any suggestions how to do that?
how to search files by mask?
how to know that this is linked file?
and how to remove linked resource?

Custom project structure in eclipse

I often use a eclipse plugins to quckliy generate project directory structure, for example Spring plugin helps to create WebContent folder to hold WEB-INF contents. But sometimes I create a projects with specific directory structure, always the same. Something like this:
[project_name]
-folder1
-folderA
-folderX
-folderB
-folder2
-dirC
-folder3
I know, that I can write my own ant/maven script to generate specific folders, but I don't want to manualy invoke scripts each time after project creating. I want to create a project template which I would use in the future.
What is the best way to create a this feature?
Should I create something like plugin? If yes, how would I do it?
If you don't want to use a plugin or a script to generate the project structure, you're pretty limited.
Since you can create a project from existing source, you could create the folder structure on your filesystem, and whenever you are creating another project, tell Eclipse to "Create Project from existing source" and point it to your template folder.
If you want to write a plugin, you'll want to contribute a org.eclipse.jdt.ui.actions.OpenProjectWizard that creates the folder structure as part of the project generation. A good tutorial can be found at: http://cvalcarcel.wordpress.com/2009/07/08/writing-an-eclipse-plug-in-part-1-what-im-going-to-do/%20
Maven has a concept of project templates called archetypes which is very similar to what you need. It defines the project structure, files, etc and can be customized upon creation.
If you install the Eclipse m2e maven plugin then you can create a new project from template with a few click
File / new Project / Maven project / Select archetype
You can use this feature even if you dont want to use maven later. You can auto generate ant scripts or anything like that. You can convert an exisint project into an archetype or create a new one from scratch, desciption is here
http://maven.apache.org/archetype/maven-archetype-plugin/
http://maven.apache.org/guides/mini/guide-creating-archetypes.html

How to simply add jar files, as libraries in a Netbeans module suite?

I'm a bit confused with NetBeans (versions 6.5 and 6.7). I have a NetBeans Module Suite application, which consists of several NetBeans Modules. I need to add some code in one of the modules. The new code is using a library, distributed as several jar files.
The problem is, that NetBeans does not allow me to add this library jars directly to the classpath. It wants to wrap all the jars in a new Library Wrapper Module, which is then added to the project and used from there. The effect is that all the original jars are combined into a single new jar automatically by NetBeans. This is a problem, because I can't just replace the jars later, without rebuilding this "Library Wrapper Module" and the original library is updated nightly.
I read some NetBeans forums, but I found nothing... I tried with simple java application, where it is possible to simply add jar(s) to the classpath using Project Properties -> Libraries -> Add JAR/Folder. If you use a NetBeans module instead of a simple application, the Libraries dialog looks different and does not have the "Add JAR/Folder" button.
Is it possible to add a plain normal jar in a NetBeans module and how?
It looks like the way a user can wrap a jar has changed in NetBeans 6.8.
Since this has been integrated into a property dialog of a project, the build process might be smarter, too. And it seems like that was your primary concern....