Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
1
Polyglot Plugin Development
How to write plugins in a language other than Java




Stefan Saasen
Confluence Team Lead, Atla...
Audience
• Written an Atlassian plugin in Java
• Interested in other programming languages
• Eager to see what is possible...
Show of hands
• Who has actually written a Atlassian plugin?
• In any other language than Java?




                      ...
5
Rhino
        6
7
https://bitbucket.org/ssaasen/atlassian-jruby-example-plugin

https://bitbucket.org/ssaasen/atlassian-scala-example-plugin...
Polyglot Plugins
• Why?
• How?
 • Example 1: Scala
 • Example 2: JRuby

• Go and do it!


                      9
Why not?
           10
Why ?
        11
What to tell the boss?
• Leverage existing knowledge in the team
• Libraries/applications already written in language X
• ...
What to tell the boss?
• Leverage existing knowledge in the team
• Libraries/applications already written in language X
• ...
14
“No time to write in Java”

                  “Less bugs”
“Succinctness”
                                15
16
Polyglot Plugins
• Why?
• How?
 • Example 1: Scala
 • Example 2: JRuby

• Go and do it!


                      17
• Hybrid language: Object oriented & functional
• Concise, statically typed (with type inference)
• Higher order/first clas...
19
20
21
22
How?


       23
Overview

                                          Scala




                                                  scalac
   ...
25
26
Build process
• Start with Maven to get
  the AMPS goodness
• Use the maven-scala-
  plugin
• Add SBT if necessary



    ...
Build process f.
 • Compile time is a concern!
 • FSC
 • Useful Maven goals:
    mvn scala:cc
    mvn scala:console


    ...
Bundle runtime
                 29
Size might be a
  problem :(
                  30
Deployment options
     Option          Scope       Package        Size

                                mvn package
     ...
Simply install using the
   plugin manager!

                           32
Development checklist
• Dependencies: Scala libraries are jar files and often
  available from Maven repositories
• Compile...
Scala: Working
with Java APIs
                 34
Scala gotchas (the 80%)
• Collections
• Method naming conventions
• Annotations
• Null vs. Option




                    ...
Collections
 • Immutable vs Mutable, serial vs. parallel
 • Rich API: Prefer Scala collections
 • Convert between Java and...
37
38
39
Method naming conventions
• Libraries rely on bean style naming conventions
  e.g. XWork, Velocity
• Scala: uniform access...
41
42
43
(Meta)-Annotations
• How to use @JavaAnnotation on a getter method
  when defining fields?
• Scala meta annotations @beanGet...
45
46
47
Option vs. null
 • In Scala Option represents an optional value.
 • Don’t let the billion-dollar mistake leak into your
  ...
49
50
51
52
Show me the
   code!
              53
57
58
59
60
Example Scala plugin
• Servlet & XWork action
• Confluence macro
• REST via Jersey/Jackson
• Build setup
• Use as a startin...
Let’s recap
 • Replace Java entirely with Scala or mix and match
 • Runtime library: 3 deployment options
 • Fits into the...
Agenda
• Why?
• How?
 • Example 1: Scala
 • Example 2: JRuby

• Go and do it!


                      63
(J)Ruby
• Dynamic, object-oriented language
• Everything is an object (no “primitives”)
• Meta-programming and open, execu...
65
How?


       66
Overview
                    Ruby
Ruby files *.rb                                  Your Ruby
                  Standard   ...
68
69
70
Plugins can’t be
written in Ruby

                   71
But we can still use
 Ruby in a plugin!

                       72
Recipe for using JRuby
• Embed the Ruby Runtime
• Use Java to execute Ruby scripts and classes
• Make components of the ho...
Embedding Strategies
• javax.scripting - JSR 223
• Apache Bean Scripting Framework (BSF)
• JRuby Embed - lower level JRuby...
Embedding Strategies
• javax.scripting - JSR 223
  Only configurable via system properties :(
• Apache Bean scripting frame...
76
Building the plugin
• Package Ruby files
• Download and package Ruby gems
• Make Ruby gems available on the Ruby LOAD_PATH
...
Show me the
   code!
              78
79
80
1 minute


           81
82
83
84
85
86
87
88
89
Example JRuby plugin
• How to use Rubygem based
  libraries in a plugin
• How to access host
  components in Ruby
• How to...
Let’s recap
• The plugin can’t be written in Ruby!
• Use the Ruby runtime
• Development workflow bonus: dynamic reloading!
...
Conclusion
• Scala is a great alternative when
  developing an Atlassian plugin
• JRuby is powerful, makes
  developing in...
TAKE-AWAYS




“   The power of the Atlassian plugin framework allows
    you to build your plugins the way you want and

...
Thank you!




             94
• “Happy Foods” by swanksalot
  http://www.flickr.com/photos/swanksalot/5021262869/
• “Construction” by Daniel Morris
  htt...
Polyglot Plugin Programming
Polyglot Plugin Programming
Polyglot Plugin Programming
Prochain SlideShare
Chargement dans…5
×
Prochain SlideShare
Unite keynote all - mike's edit (don't edit!)
Suivant
Télécharger pour lire hors ligne et voir en mode plein écran

Partager

Polyglot Plugin Programming

Télécharger pour lire hors ligne

Polyglot Plugin Programming

  1. 1. 1
  2. 2. Polyglot Plugin Development How to write plugins in a language other than Java Stefan Saasen Confluence Team Lead, Atlassian 2
  3. 3. Audience • Written an Atlassian plugin in Java • Interested in other programming languages • Eager to see what is possible with Atlassian plugins 3
  4. 4. Show of hands • Who has actually written a Atlassian plugin? • In any other language than Java? 4
  5. 5. 5
  6. 6. Rhino 6
  7. 7. 7
  8. 8. https://bitbucket.org/ssaasen/atlassian-jruby-example-plugin https://bitbucket.org/ssaasen/atlassian-scala-example-plugin 8
  9. 9. Polyglot Plugins • Why? • How? • Example 1: Scala • Example 2: JRuby • Go and do it! 9
  10. 10. Why not? 10
  11. 11. Why ? 11
  12. 12. What to tell the boss? • Leverage existing knowledge in the team • Libraries/applications already written in language X • Time to market/devspeed • Explore technologies in a sandboxed environment • Grass looks always greener on the other side 12
  13. 13. What to tell the boss? • Leverage existing knowledge in the team • Libraries/applications already written in language X • Time to market/devspeed • Explore technologies in a sandboxed environment • Grass looks always greener on the other side 13
  14. 14. 14
  15. 15. “No time to write in Java” “Less bugs” “Succinctness” 15
  16. 16. 16
  17. 17. Polyglot Plugins • Why? • How? • Example 1: Scala • Example 2: JRuby • Go and do it! 17
  18. 18. • Hybrid language: Object oriented & functional • Concise, statically typed (with type inference) • Higher order/first class functions, pattern matching • Powerful type system • Rich standard library 18
  19. 19. 19
  20. 20. 20
  21. 21. 21
  22. 22. 22
  23. 23. How? 23
  24. 24. Overview Scala scalac Scala Runtime Library Java Bytecode *.class Java Java Standard Library javac JVM 24
  25. 25. 25
  26. 26. 26
  27. 27. Build process • Start with Maven to get the AMPS goodness • Use the maven-scala- plugin • Add SBT if necessary 27
  28. 28. Build process f. • Compile time is a concern! • FSC • Useful Maven goals: mvn scala:cc mvn scala:console 28
  29. 29. Bundle runtime 29
  30. 30. Size might be a problem :( 30
  31. 31. Deployment options Option Scope Package Size mvn package Bundle compile -Pbundle 8.5 MB Simple Bundle & Shrink mvn package Deploy compile 680 KB w/ProGuard -Pproduction externally Deploy Install separately provided mvn package 50 KB internally 31
  32. 32. Simply install using the plugin manager! 32
  33. 33. Development checklist • Dependencies: Scala libraries are jar files and often available from Maven repositories • Compile time: mvn scala:cc for continuous compilation • Workflow: scala:cc & atlas-cli pi or mvn package && atlas-install-plugin • Profit: mvn scala:console to get the Scala REPL 33
  34. 34. Scala: Working with Java APIs 34
  35. 35. Scala gotchas (the 80%) • Collections • Method naming conventions • Annotations • Null vs. Option 35
  36. 36. Collections • Immutable vs Mutable, serial vs. parallel • Rich API: Prefer Scala collections • Convert between Java and Scala collections when calling Java methods • Solution: JavaConverters (explicit, preferred) vs. JavaConversions (implicit) • Watch out for serialization: Bandana/XStream 36
  37. 37. 37
  38. 38. 38
  39. 39. 39
  40. 40. Method naming conventions • Libraries rely on bean style naming conventions e.g. XWork, Velocity • Scala: uniform access principle • Solution: Use @BeanProperty and @BooleanBeanProperty 40
  41. 41. 41
  42. 42. 42
  43. 43. 43
  44. 44. (Meta)-Annotations • How to use @JavaAnnotation on a getter method when defining fields? • Scala meta annotations @beanGetter, @beanGetter, @field, @getter, @setter 44
  45. 45. 45
  46. 46. 46
  47. 47. 47
  48. 48. Option vs. null • In Scala Option represents an optional value. • Don’t let the billion-dollar mistake leak into your Scala code! • Solution: wrap nullable method calls in an Option 48
  49. 49. 49
  50. 50. 50
  51. 51. 51
  52. 52. 52
  53. 53. Show me the code! 53
  54. 54. 57
  55. 55. 58
  56. 56. 59
  57. 57. 60
  58. 58. Example Scala plugin • Servlet & XWork action • Confluence macro • REST via Jersey/Jackson • Build setup • Use as a starting point https://bitbucket.org/ssaasen/atlassian-scala-example-plugin 61
  59. 59. Let’s recap • Replace Java entirely with Scala or mix and match • Runtime library: 3 deployment options • Fits into the AMPS development workflow • Scala Gotchas: watch out for common problems • “Scala is a great fit to write Atlassian plugins in” 62
  60. 60. Agenda • Why? • How? • Example 1: Scala • Example 2: JRuby • Go and do it! 63
  61. 61. (J)Ruby • Dynamic, object-oriented language • Everything is an object (no “primitives”) • Meta-programming and open, executable classes allow for easy creation of DSLs • JRuby: Ruby runtime written in Java 64
  62. 62. 65
  63. 63. How? 66
  64. 64. Overview Ruby Ruby files *.rb Your Ruby Standard RubyGems jrubyc Code Library Ruby Runtime Java Bytecode *.class Java Java Standard Library javac JVM 67
  65. 65. 68
  66. 66. 69
  67. 67. 70
  68. 68. Plugins can’t be written in Ruby 71
  69. 69. But we can still use Ruby in a plugin! 72
  70. 70. Recipe for using JRuby • Embed the Ruby Runtime • Use Java to execute Ruby scripts and classes • Make components of the host application available • Use the script execution result in Java 73
  71. 71. Embedding Strategies • javax.scripting - JSR 223 • Apache Bean Scripting Framework (BSF) • JRuby Embed - lower level JRuby API 74
  72. 72. Embedding Strategies • javax.scripting - JSR 223 Only configurable via system properties :( • Apache Bean scripting framework (BSF) No point in adding a separate API • JRuby Embed - lower level JRuby API 75
  73. 73. 76
  74. 74. Building the plugin • Package Ruby files • Download and package Ruby gems • Make Ruby gems available on the Ruby LOAD_PATH • Bundle everything into a plugin jar file • A lot of Maven XML :) • Caveat: JRuby runtime is even larger! 77
  75. 75. Show me the code! 78
  76. 76. 79
  77. 77. 80
  78. 78. 1 minute 81
  79. 79. 82
  80. 80. 83
  81. 81. 84
  82. 82. 85
  83. 83. 86
  84. 84. 87
  85. 85. 88
  86. 86. 89
  87. 87. Example JRuby plugin • How to use Rubygem based libraries in a plugin • How to access host components in Ruby • How to use the execution result • Sinatra in Confluence ;-) https://bitbucket.org/ssaasen/atlassian-jruby-example-plugin 90
  88. 88. Let’s recap • The plugin can’t be written in Ruby! • Use the Ruby runtime • Development workflow bonus: dynamic reloading! • The overhead of adding the runtime and providing Java glue code makes this only feasible for high value use cases :( 91
  89. 89. Conclusion • Scala is a great alternative when developing an Atlassian plugin • JRuby is powerful, makes developing in a dynamic language possible but requires more work and custom Java adapter code • Java interoperability needs to be well understood in both cases 92
  90. 90. TAKE-AWAYS “ The power of the Atlassian plugin framework allows you to build your plugins the way you want and ” Java doesn’t have to be the limit. #atlascamp 93
  91. 91. Thank you! 94
  92. 92. • “Happy Foods” by swanksalot http://www.flickr.com/photos/swanksalot/5021262869/ • “Construction” by Daniel Morris http://www.flickr.com/photos/danielmorris/275438405/ • “70 80 90” by roujo http://www.flickr.com/photos/tekmagika/437989361 95
  • blaizedsouza

    Dec. 6, 2012

Vues

Nombre de vues

1 536

Sur Slideshare

0

À partir des intégrations

0

Nombre d'intégrations

176

Actions

Téléchargements

11

Partages

0

Commentaires

0

Mentions J'aime

1

×