Extending and scripting PDT
-
Upload
william-candillon -
Category
Technology
-
view
6.385 -
download
1
Transcript of Extending and scripting PDT
![Page 2: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/2.jpg)
Who am I ?
• Engineering student at Telecom Lille 1
• ETH Zurich: XQuery runtime in C++
• Aspect PHP Development Toolkit:http://apdt.googlecode.com
![Page 3: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/3.jpg)
Who are you ?
• What is your favorite IDE?
• VIM?
• Netbeans?
• Komodo?
• PHPEd?
• PDT / Zend Studio?
![Page 4: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/4.jpg)
The Long TailSupport
Specific
PHP
XDebug
Zend framework
PHP Unit
frameworks
Business libraries
PEAR
test/build systemsDevelopment rules
General
How to scale?
![Page 5: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/5.jpg)
Eclipse galaxy
WTP
MTJ RCP
PDTRDT
CDT
EPF SVN
TPTPANT
EMF
UML
OCL
ECF GEFALF DTK
Eclipse
JDT
Frameworks Languages and modeling
Development tasks
Applications
Programming languages
GMF
AJDT
Plug-ins ecosystem (+ 1000)
PDE
J2EEMAVEN
MYLYN
DTP
APDT
![Page 6: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/6.jpg)
Architecture
Equinox (OSGI)
Workspace
Help
Team
Workbench
JFace
SWT
JavaDevelopment
Tools(JDT)
NotreOutil
Votre Outil
Un autreOutil
Plug-inDevelopmentEnvironment
(PDE)
Eclipse Platform
Debug
Update
JVM
![Page 7: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/7.jpg)
PHP Development Toolkit
• Developped by Zend and IBM since 2006
• December 2008: version 2.0
• Second most popular project on eclipse.org
• 100% under the EPL (Eclipse Public License)
• Build on top of DLTK (Dynamic Language Toolkit)
![Page 8: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/8.jpg)
Objectives
• De-facto standard for PHP developments
• Providing extension points and APIs to support PHP tools...
• ...from the last hot PHP framework to the best practices of your company!
![Page 9: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/9.jpg)
Architecture
![Page 10: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/10.jpg)
Why extending ?
• Integrate your own extension or framework
• DLTK/PDT define more than 30 extension points!
![Page 11: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/11.jpg)
What is extensible ? (1/3)
Launcher
BuilderOutline
Syntax highlightingExplorer tree
![Page 12: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/12.jpg)
What is extensible ? (2/3)
Wizard pages
![Page 13: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/13.jpg)
What is extensible ? (3/3)
Search semantic
![Page 14: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/14.jpg)
Code refactoring
• Abstract model of a PHP program
• AST representation of source code
• Tree walking and manipulation
• Extensible type inference engine
![Page 15: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/15.jpg)
What’s wrong ?
![Page 16: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/16.jpg)
Use case
• Objective: ensuring a simple development rule
• Never trust your inputs!
• Finding and fixing the bug...
• ...in the coolest manner
![Page 17: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/17.jpg)
Step 1
• Strategy: extending PDT building process with our own build participant
• Registering the contribution
![Page 18: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/18.jpg)
Step 2
• Build participant factory
public class BuildParticipantFactory implements IBuildParticipantFactory { public IBuildParticipant createBuildParticipant(IScriptProject project){ return new XSSProtectionParticipant(); }}
• Build participantpublic void build(IBuildContext context) throws CoreException{ ISourceModule sourceModule = context.getSourceModule(); ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule); try { moduleDeclaration.traverse(new XSSValidationVisitor(context)); } catch (Exception e) { throw new CoreException(new Status(IStatus.ERROR, ExamplePlugin.PLUGIN_ID, "An error has occurred while invoking XSS validator", e)); }}
Traverse the PHP AST
![Page 19: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/19.jpg)
Step 3
• Trasverse the AST
• If the node is safe, don’t visit child nodes
public boolean visit(PHPCallExpression node) throws Exception { if (node.getReceiver() == null) { // if this is a function call, not method String funcName = node.getName(); if ("isset".equalsIgnoreCase(funcName)) { return false; } return false; }
• Check variable references of globalsprotected boolean isURLParemeterVariable(VariableReference s) { String name = s.getName(); return ("$_GET".equals(name) || "$_POST".equals(name));}
public boolean visit(ArrayVariableReference s) throws Exception { if(isURLParemeterVariable(s)) { context.getProblemReporter().reportProblem(new DefaultProblem(context.getFile().getName(), "Unsafe use of " + s.getName() + ": possible XSS attack", XSSProblem.UNSAFE_GLOBAL_REFERENCE.ordinal(), new String[0], ProblemSeverities.Error, s.sourceStart(), s.sourceEnd(), context.getLineTracker().getLineNumberOfOffset(s.sourceStart())) );
VariableReference
CallExpression
ModuleDeclaration
........
........
![Page 20: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/20.jpg)
Result
• Invalid PHP project
• Mission accomplished!
![Page 21: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/21.jpg)
Let’s digg it
• PHP Quick Fix
• Quick Fix proposal interfacepublic interface IQuickFixProcessor{ boolean hasCorrections(ISourceModule, int problemId); IScriptCompletionProposal[] getCorrections(IInvocationContext, IProblemLocation[]);}
![Page 22: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/22.jpg)
Result
• hasCorrection() checks if correction are availables
• getCorrection() returns a collection of corrections
• apply(document), performs the AST rewriting
![Page 23: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/23.jpg)
Programming is hard...• ...Go scripting!
• PHP Developpers need to extend Eclipse
• Without getting close to Java
• In a dynamic manner
• Eclipse e4, the next generation of Eclipse
• Provides support for JavaScript bundles
• Dynamic execution and deployment model
• Usage: Task automation, glue between plugins, scripting workflows, etc.
![Page 24: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/24.jpg)
The recipie
• Extension Registry
• JavaScript source and Java bridgefunction helloworld() { var object = { run: function (action){ Packages.org.eclipse.jface.dialogs.MessageDialog.openInformation( this.window.getShell(), 'TestJavascriptPlugin', 'Hello, Eclipse world'); }, dispose: function(){}, init: function(window) { this.window = window }, selectionChanged: function(action, selection){} }; return new JavaAdapter(Packages.org.eclipse.ui.IWorkbenchWindowActionDelegate, o);}
![Page 25: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/25.jpg)
Dynamic deployment
• JavaScript Plug-in Development Environment (http://jspde.googlecode.com)
• Support JavaScript Plugins
• Dynamic deployment
![Page 26: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/26.jpg)
Conclusion• Extension mechanisms to integrate:
• PHP frameworks and tools
• Development workflows
• PHP 5.3 support
• Towards customized PDT distribution
• Writing PHP plugins with PHP ?
![Page 27: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/27.jpg)
Resources
• PDT website
• Extending and Scripting PDT tutorial
• Eclipse e4, JavaScript support
• PDT adopter’s
• Aspect PHP Development Toolkit
• Smarty
![Page 28: Extending and scripting PDT](https://reader033.fdocuments.us/reader033/viewer/2022052411/55797b45d8b42a5f438b4a10/html5/thumbnails/28.jpg)
Thank you