Archive for July, 2007

SoC – First Release – Eclipse Plugins in PHP

After six weeks I have a release to show, this is something I can really call alpha quality :( . Keep on reading to get the details. Firstly how to get the plugin :)

  • You must have Java 6 installed for the scripting support (I need to verify it works with < Eclipse 3.3)
  • Update site url http://tom.jabber.ee/phpengine/update-site/
  • SVN url http://eclipse-incub.svn.sourceforge.net/viewvc/eclipse-incub/plugins_in_php/
  • Module org.eclipse.soc2007.phpscriptengine
  • Module update-site
  • The info is more up-to-date on my wikipage.

What can you do with the plugin?
Firstly map PHP functions to Java methods. The approach is to create an interface.

public interface HelloWorld extends Scriptable {
@ScriptableAnnotation(
 fileName="helloWorld.php",
 output="true")
String getHelloWorld(String rtrn);
}

Implement the interface with method stubs that return the argument (I’m invoking the methods with return values as arguments). Get a proxy for the object implementing the interface

HelloWorld helloWorld = (HelloWorld)ScriptUtil.registerProxy(
     objectImplementingTheInterface,
     HelloWorld.class,
     classLoaderThatFindsThePath);

And using the interface as you would. Right now you have to read the source code for more comments. I’ve actually documented it to some extent. To get a quick and dirty example see the “Mapping PHP Functions to Java Methods” (step-by-step tutorial) wiki page.

Secondly using some simple PHP developing aids. See the “Facilities Provided by the Plugin” again on the wiki.

The plugin comes with the Quercus ScriptEngine jar inside the plugin. It is compiled from trunk and has the support for MySql (you still have to download the MySql JDBC connector yourself). I’ve proposed a solution/patch to the issue I was ranting about in the last post. No GD support yet but I’ll get around to that soon.

Hopefully next releases will come quicker. I’ve automated the building of the update-site. So it is easy to even produce pseudo releases :) .

Where to now? Oh boy, there is so much more work to do:). Here is a list of ideas/problems that I will be dealing with to produce an actual integration plugin:

  • Provide a cleaner API for users.
  • Implement invoking PHP functions/methods/multiple arguments etc.
  • As PHP is somewhat different (also thanks to Quercus) than other scripting languages also provide support for JavaScript
  • Development aids (when writing interfaces autocomplete for PHP functions/methods/objects etc.)
  • Work on Quercus source code to solve issues that are bugging me (GD, logging exception when certain J2EE classes missing, etc.)
  • Sample plugin mostly in PHP
  • See if and how much I duplicate with PDT Project
  • Bugfixes, bugfixes & bugfixes

Any feedback is appreciated. Go download the plugin, update your J2SE instance and go wild :)

Comments off

GSoC Project Update

There has not been any news for more than a week now. I have not been idleing the whole time :) . Mostly I’ve been battling with Quercus, trying once more the PHP/Java Bridge and waiting for my mentor to get back from a week of vacation which he deserved and is back from :) . One of the main tasks for last week (that i failed) was making an initial release but I was able to run into showstopper bugs. I wanted the release to have at least one feature/example that I find sexy. No luck :( . I’ll give you an idea what I have been trying.

First up is using MySQL or PostgreSQL through the JSR223 PHP ScriptEngine.

mysql_connect("host", "username", "password");
mysql_select_db("databasename");
$result = mysql_query("select * from test");
while($arr=mysql_fetch_assoc($result)) {
 print_r($arr);
}

Currently this produces an error (com.caucho.quercus.QuercusModuleException: Can’t find database for driver). I’ve documented the issue in the bug report. I tried different Quercus versions (currently running trunk). I even tried PostgreSQL. No luck. Although Quercus is a JSR223 ScriptEngine it is developed to run in a web container. The Servlet initializing the QuercusScriptEngine takes care of some configurations that don’t come out-of-the-box when using it as a ScriptEngine.

Secondly I thought it would be nice to do some image manipulation.

$im = @imagecreate(110, 20)
    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);

This should produce the following image: . Sample is taken from PHP Manual. But I get a java.io.CharConversionException: illegal utf8 encoding. The underlying OutputStream, in this case com.caucho.vfs.ReaderWriterStream insists on checking the bytes of the image for being UTF8. I’ve filed a bug report.

Thirdly I thought of incorporating some PHP into my plugin. I’ve been working on using PHP through annotations and reflection. So that the user would have something along the lines:

@ScriptableAnnotation(
 fileName="org/eclipse/soc2007/php/ScriptablePlugin.php",
 functionName="getVersion()")
public String getVersion(String rtrn) {
 return rtrn;
}

Currently I’m registering a dynamic proxy for the interface of this class. The proxy will invoke the method and the give for the argument the return value of calling getVersion() from ScriptablePlugin.php. Cumbersome :/. I was not able to get this sample to work either. During the initialization I started getting org.osgi.framework.BundleException. Supposedly it is avoiding deadlock and has set time limits on the loading process. ScriptEngine creation takes some time. I’ve been initing the ScriptEngine in a popup menu and this has not happened before so I don’t have a clear answer why this is happening. But still as all plugins are lazily loaded then it is imporant where I put it.

I’m sure I won’t be able to find solutions to all of these problems this week, I’ll still make a release in couple of days. I’ve imported my project to eclipse-incub@sourceforge.net and working on getting the first version out. Stay tuned :)

Comments off

Developing the Mylyn/Eclipse way

About a week ago as I was hacking on my SoC project I was pointed out that I was getting the current selection in the workspace not the right way. I referred that this is how this was done in Mylyn (I guess I was grepping for ISelection in Mylyn sources). I was asked to file a bug and so I did, Bugzilla Bug 195052.

Today I got an answer that the reason was legacy and if I would be interested in contributing a patch. Then there was a another comment with a zip attachment mylyn/context/zip. I already was disappointed that somebody else had made a patch but I only found an XML file. I thought, well I’ve accidently uploaded gibberish too, happens. I did use Mylar about a year ago but I had no idea what a Mylyn context is.

Hours later I took the patch up. Thought I’ll activate the Mylyn task management (I tried it once before but did not understand squeak about it). And woah was I surprised. I was able to retrieve the whole issue to my IDE (screenshot 1st down below). I was amazed. I noticed a menu item Attach contex, it accepted a zip file. Bingo!, I used the weird “accidental” XML file. Boom, only the affected file was visible in my IDE (screenshot 2nd down below).

Taskinfo page in Mylyn Eclipse looks like this when context applied

What this means for developers?

  • Tasks have resource context (subset of the whole project).
  • Tasks & contexts are shareable.
  • Your tasks are where your code is.
  • Don’t have to bookmark the issue to make changes to it.
  • Don’t have to use emails/feedreaders to keep an eye on tasks you’re interested in (Mylyn reqularly updates the task items).

No wonder Eclipse was again on-time with a major release :)

On a side note, I wish Changelogic (used for Aranea Web App Platform development) would have integration with Mylyn. I’ll see, maybe there’s something I can do about it.

Comments (3)

jsPgnViewer 0.5.3 (maintenance release)

Just a bug-fix release. Entities of the sort $[1-6] which represent “!”, “?”, “!!”, “!?”, “?!”, and “??” respectively get handled correctly instead of an exception :) . The other features that we planned according to the last release’s post’s comments will take some time.

Head off to the downloads section and grab 0.5.3 and to the issues list to add feature requests. Chesspastebin.com has also been updated with the latest version.

Comments (4)

Building my SoC app

How to search for files in the workspace using the API? See the dev.eclipse.org viewcvs for package org.eclipse.search.tests. Quick link to the file. You can search for files defining text patterns for file content matching and name patterns for file name matching

How to add a pop-up menu entry to a context-menu? IBM developerWorks has an article “Build extensions for Eclipse one snippet at a time“. I liked that I just supply the interface and then the entry is only added to that context menu (IFile for files and IProject for projects etc.).

How to do something when the menu entry is clicked? Like getting the reference to the IProject it was under. See Mylyn source code.

How to add a project nature to a project? General info at Eclipse Resources article “Project Builders and Natures” and then an example with code.

My googling daily average is 117 searches for the past week.

When I have a problem to solve (search for files in the Workspace) then I first try to get as far I can with what I know. At one point there will be some kind of an API question. What class to use to do that? Thanks to the self-descriptive naming scheme one can find an interface or two and check the implementations. If that does not do it then head off to dev.eclipse.org and see the tests for the usage. You can always try to remember if you have seen this functionality before and download the source of that plugin!

This week’s plan is:

  • First Release
  • Configure update site
  • CVS import
  • Usable PHP sample

My mentor is on a vacation so I guess I’ll be bugging the others :)

Comments off