playbay play 2.0 plugin イロハのイ

22
PlayFramework 2.0 プラグイン イロハのイ 原 一浩 @kara_d

Upload: kazuhiro-hara

Post on 24-May-2015

2.339 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Playbay Play 2.0 plugin イロハのイ

PlayFramework 2.0プラグインイロハのイ

原 一浩 @kara_d

Page 2: Playbay Play 2.0 plugin イロハのイ

原 一浩 @kara_d http://greative.jp/

Page 3: Playbay Play 2.0 plugin イロハのイ

本日のセッション内容 ➡ Playプラグインを入れてみよう➡ Playプラグインとはなにか➡ Typesafe社製プラグインでまなぶオリジナルプラグイン作成のための構成

3

Page 4: Playbay Play 2.0 plugin イロハのイ

Playプラグインを入れてみよう

4

Page 5: Playbay Play 2.0 plugin イロハのイ

入れてみるプラグイン

➡ Groovy Template Engine for Play 2 ➡ play2-project-info

5

Page 6: Playbay Play 2.0 plugin イロハのイ

アプリケーション用プラグイン➡ Groovy Template Engine for Play 2• https://github.com/mbknor/gt-engine-play2

6

デモ

Page 7: Playbay Play 2.0 plugin イロハのイ

Build.scalaに書く

7

val  appDependencies  =  Seq(    //  Add  your  project  dependencies  here,    "kjetland"  %%  "gt-­‐engine-­‐play2"  %  "0.1.6")

val  main  =  PlayProject(appName,  appVersion,  appDependencies,  mainLang  =  JAVA).settings(    //  Add  your  own  project  settings  here            resolvers  +=  "mbknor  github  Repository"  at  "http://mbknor.github.com/m2repo/releases/"    )

Page 8: Playbay Play 2.0 plugin イロハのイ

Runした後に依存管理が行われる

8

[info]  Updating  {file:/Users/hoge/study_play20/testSample5/}testSample5...[info]  Resolving  org.hibernate.javax.persistence#hibernate-­‐jpa-­‐2.0-­‐api;1.0.1.Fin                                                                                                                                                                [info]  downloading  http://mbknor.github.com/m2repo/releases/kjetland/gt-­‐engine-­‐play2_2.9.1/0.1.6/gt-­‐engine-­‐play2_2.9.1-­‐0.1.6.jar  ...[info]    [SUCCESSFUL  ]  kjetland#gt-­‐engine-­‐play2_2.9.1;0.1.6!gt-­‐engine-­‐play2_2.9.1.jar  (2004ms)[info]  downloading  http://mbknor.github.com/m2repo/releases/kjetland/gt-­‐engine_2.9.1/0.1.7.12/gt-­‐engine_2.9.1-­‐0.1.7.12.jar  ...[info]    [SUCCESSFUL  ]  kjetland#gt-­‐engine_2.9.1;0.1.7.12!gt-­‐engine_2.9.1.jar  (1179ms)[info]  downloading  http://repo.typesafe.com/typesafe/releases/org/codehaus/groovy/groovy/1.8.6/groovy-­‐1.8.6.jar  ...

Page 9: Playbay Play 2.0 plugin イロハのイ

コンソール用プラグイン➡ Project Information module for Play2!• https://github.com/karad/play2-project-info

9

デモ

Page 10: Playbay Play 2.0 plugin イロハのイ

Plugins.sbtに書く

10

resolvers  +=  "Greative  Maven  Repository"  at  "https://github.com/karad/maven-­‐repo/raw/master/release/"

addSbtPlugin("jp.greative"  %  "play2-­‐project-­‐info-­‐sbt"  %  "0.1")

Page 11: Playbay Play 2.0 plugin イロハのイ

Playプラグインとはなにか

11

Page 12: Playbay Play 2.0 plugin イロハのイ

Playプラグインは、➡ Play上の機能追加、依存管理する仕組み• アプリケーションの機能拡張• ライブラリの追加• 対話型コンソールの機能拡張

➡ Playのプラグイン自体は、コンパイル済みのjar• これをsbtを使って依存管理する• ただし、Playコンソール系は別

12

Page 13: Playbay Play 2.0 plugin イロハのイ

Playコンソールについて➡ Playコンソールはsbtコンソールの拡張➡ sbt• sbt is a build tool for Scala and Java projects that aims to do the basics well. It requires Java 1.6 or later.

➡ .sbtと.scala• .sbt build definition uses a Scala-based "domain-specific language" (DSL)

➡ 始める sbt• http://scalajp.github.com/sbt-getting-started-guide-ja/

13

Page 14: Playbay Play 2.0 plugin イロハのイ

Playとsbtの関係➡ Play 2.0以降、sbtが全面採用• Playコマンド用• ライブラリ、プラグインの依存管理用• ビルド用

14

Page 15: Playbay Play 2.0 plugin イロハのイ

Playにおけるプラグインの種類➡ アプリケーション• Model• Controller• View- Tag

➡ クラスライブラリ• jar

➡ コンソール• sbtのコンソール- sbtプラグインとして作成

15

Page 16: Playbay Play 2.0 plugin イロハのイ

Playプラグインは何で書くの?➡ クラスライブラリとしてのプラグイン• Java/Scala両方

➡ アプリケーションのプラグイン• プロジェクトによる

➡ コンソール型のプラグイン• Scala

16

Page 17: Playbay Play 2.0 plugin イロハのイ

Typesafe社製プラグインでまなぶオリジナルプラグイン作成のための構成

17

Page 18: Playbay Play 2.0 plugin イロハのイ

参考になるもの➡ play-plugins• https://github.com/typesafehub/play-plugins- dustプラグインとか参考になる

➡ play本体• project- Build.scala

• framework- src

consolesbt-plugin

18

Page 19: Playbay Play 2.0 plugin イロハのイ

フォルダ構成➡ conf/• application.conf

➡ project/• build.properties• Build.scala• plugins.sbt

➡ sbt-plugin/• src/- main/

scala/

➡ README.md19

Page 20: Playbay Play 2.0 plugin イロハのイ

使うファイル➡ プラグイン本体のソース• HogeKeys.scala• HogePlugin.scala• HogeTasks.scala

➡ ビルド用ファイル• Build.scala

20

デモ

Page 21: Playbay Play 2.0 plugin イロハのイ

リポジトリってどうなってるの?➡ Gitをmavenリポジトリとしているプラグインが多い• ライブラリのリポジトリと、mavenリポジトリで分ける• メリット- URLが出来る- マニュアル置ける- アップロード楽- 無料

21

デモ

Page 22: Playbay Play 2.0 plugin イロハのイ

ありがとうございました

22

7/14 第3回playframework勉強会http://playframeworkja.doorkeeper.jp/events/1231-%E7%AC%AC3%E5%9B%9Eplayframework%E5%8B%89%E5%BC%B7%E4%BC%9A-play_ja

日本Play frameworkユーザー会https://groups.google.com/group/play_ja?hl=ja