August 27, 2007 at 9:51 pm
· Filed under SoC2007, eclipse, google
Finally I’ve found a PHP and JS library which work and are useful to show off how to use them through the Scripting Bridge (my GSoC project). This post is about the core part of my work.
A week before the deadline we separated all Eclipse stuff from the Scripting Bridge to provide something more general which we call core now. The core lets you incorporate scripts into your Java code and treat them as regular Java objects.
The libraries I found are:
The samples use these libraries to package a small JavaScript and show the output. Basically I have a Java-PHP mapping interface:
@ScriptableClass (fileName="etc/phpPacker.php,
etc/myWrapper.php",
extension="php")
public interface PhpPacker {
@ScriptableMethod(functionName="packJs",output="true")
public String packJs(String jsContents);
}
This defines which PHP files to use and which function to invoke. Then I use this interface as:
PhpPacker phpPacker = (PhpPacker)
ScriptableFactory.newInstance(PhpPacker.class);
result = phpPacker.packJs(toPack);
This actually invokes the bundled PHP function packJs($str). The same example is also for JavaScript using the other library.
I made a separate page for the core & samples which include
Next post will be about the UI or Eclipse part of the deliverables. I hope I’ll find some sexy PHP & JS scripts.
Permalink
August 20, 2007 at 9:13 pm
· Filed under SoC2007, eclipse, google
Its pencils down for the Google Summer Of Code. I’ve tagged my source in the repo and made another release. The update URL is the same. More info during the following days.
Permalink
August 7, 2007 at 9:44 pm
· Filed under SoC2007, eclipse
One of the features that my GSoC project will have is generating Java-To-Php interfaces from PHP files. To accomplish that task I have two options:
Both have their pros and cons. Today I’ll talk about the second option because I was contacted by one of the PDT guys to offer help and now I had time to go into their code.
You can see a list of PDT module names in the viewcvs of the Tools Project. The CVS root is dev.eclipse.org/cvsroot/tools.
How to hook into the PDT to find the function names? There is a handler ParserClient. It has all the necessary callbacks when parsing PHP source files. I’m interested in handleFunctionDeclarationStarts. So I have to implement the interface and I will be called when the parser finds a function. Easy
It was not that easy to get it running in a simple main(String args[]) as PDT’s PHPLanguageModel does a lookup of the file using PHPCorePlugin.getDefault().getBundle() which results in a NPE as Eclipse is not running. After overriding couple of classes (+methods) and changing 2 modifiers to public I was able to get it working. Generally to get a list of functions in a PHP file the code looks like this:
ParserClient parserClient = new MyPhpHandler();
PHPLanguageManager langManager = new MyLanguageManager();
PHPParserManager manager = langManager.createPHPParserManager();
final Reader reader = new FileReader(new File("pathToPhpFile"));
manager.parse(reader, "path", 0l, parserClient, new Pattern[]{}, false);
The prefix “My” constitutes to overridden version. So its easy. I’ll contact PDT and see if I can get a cleaner interface from them or maybe provide it myself.
Once I get reflection working I’ll let you know which is easier. Then again who would ever want to parse PHP files from Java and care about the source code more than the output
PS. I’m slowly getting back to developing Aranea Web Framework. The final deadline of SoC is 31. August.
Permalink
August 5, 2007 at 9:45 pm
· Filed under SoC2007, eclipse, meme
After three weeks we have the next release of Eclipse Plugins in Php ready. The update site is the same. The main changes include:
Reworked API
Class level annotation to define the PHP file. Method level annotation to define the PHP function. To map Java to PHP only an interface is needed. Sample:
@ScriptableClass(fileName="helloWorld.php")
public interface HelloWorld {
@ScriptableMethod(functionName="helloWorld")
String getHelloWorld(String name);
}
And to instantiate a simple call to a factory is needed:
PhpScriptableFactory.newInstance(HelloWorld.class);
Quercus GPL issue
We depended on Quercus to provide out-of-the-box PHP support. Quercus in under GPL, my plugin EPL. Although we had no code level access to the quercus.jar (discovering ScriptEngine is the J2SE’s work) we separated the two by packaging the GPL part of the libraries in a separate fragment. The fragments host plugin is this our plugin and we offer it on the same update site. This means when you install both of them you can run PHP code just after the install
I battled with different problems during this time and I’ll try to give an overview in the following blog posts. Some issues I had trouble with include:
- Generating proxies with ASM
- Generating interceptors with CGLIB
- Unit-testing Eclipse plugins
- Making an Eclipse Fragment
During this time I also managed to finish last in a Go tournament and get accepted to Tartu University to study CS at the masters level.
Permalink