PK ٵu=f# # manifestversion=head
frameworkVersions=1.1
PK o=9e README.textileh1. Maven support
The Maven module enables maven support for your application. It adds a pom.xml in your project and deploys a play-parent pom in your local Maven repository.
Thus, libraries are copied to /lib folder.
Moreover, this module has the ability to create a war package of a Play! application using the 'mvn package' command'.
The Play! applciations can now be used in you Continuous Integration (CI) system.
h1. What is supported?
* A standard pom.xml can be installed in your Play! application.
* Libraries dependencies are handled by your pom and are downloaded to your */lib* folder in a single command.
* Cleaning libraries in the /lib folder is supported in a single command.
* Packaging your Play! application to a war using Maven is now possible (using only **mvn package**).
h1. Getting started
First, you need to download and install "Apache Maven":http://maven.apache.org/download.html.
Finally, you need to install the play-maven module:
bc. # play install maven
h1. How to use your own Maven repository to store Play! artefacts
Play!'s' parent pom contains the reference to a repository containing Play! libs and the Play! runtime packaged as a resource.
But you can use your own repository (your company's one for example).
* Here is the list of the artefacts you have to upload as third-parties (you can find the jars inside framework/lib directory of your Play! installation):
bc. // At the time of writing this README, Play's version is 1.1
hsqldbhsqldb1.8.1.2com.jamonapijamon2.7org.play.jjimaging1.1org.play.jjsimple-captcha1.1org.play.jjtextile1.1org.play.jjwikitext1.1jregexjregex1.2_01net.spymemcached2.4.2org.playorg.eclipse.jdt.core3.6.0
* You also have to upload the Play! runtime:
Upload the zip package of the Play! framework using these informations :
bc. // At the time of writing this README, Play's version is 1.1
org.playplay-runtime1.1zip
* Finally, upload Play!'s jar :
bc. // At the time of writing this README, Play's version is 1.1
org.playplay1.1
h1. Setting up the Maven module
Start by creating a new application in the classical way.
bc. # play new test-maven
Then edit the *conf/application.conf* file to enable the Maven module:
bc. # Additional modules
# ~~~~~
# A module is another play! application. Add a line for each module you want
# to add to your application. Module paths are either absolutes or relative to
# the application root.
#
module.maven=${play.path}/modules/maven
At this moment, if you are working with Eclipse, do not forget to update your .classpath :
bc. # play ec
You now have to install play-parent in your repository and get a pom.xml in your Play! application :
bc. # play mvn:init
This command installs play-parent pom in your local repository (ex : ~/.m2/repository) and copies the 'skeleton' pom from the play-module to your application.
Edit your pom.xml to change your groupId, artifactId, version, name and description.
Launch an update to retrieve Play! libraries and check there is no error :
bc. # play mvn:up
That's it ! Your application is Maven-compliant.
The following maven commands are now working :
bc. # mvn clean // be careful, it deletes your /lib folder
# mvn compile
# mvn package // will create a war file
h1. play-maven specific commands
bc. # play mvn:init
Installs play-parent project (a Maven pom project) into local Maven repository. Then creates the appropriate *pom.xml*. After this step, you can add your dependencies to pom.xml.
bc. # play mvn:update // or play mvn:up
Retrieves all defined dependencies and then it copies them into your /lib folder.
bc. # play mvn:refresh // or play mvn:re
Clears your app/lib folder first, then it executes play mvn:up.
h1. Known issues
As long as Play! framework "Issue #359":http://play.lighthouseapp.com/projects/57987/tickets/359-war-packaging-add-an-exclude-option is not resolved, 'target' directory is embedded inside the generated war.
You have to remove it manually after packaging your war (because target directory contains Play! runtime).
h1. How is packaging working
This module contains ant targets designed to launch a *play war* command.
This command is replacing the war done by *mvn package* with a war build by Play! itself.
* Play! runtime is package as a Maven resource and is a dependency of your application.
* As a consequence, it is downloaded as a dependency.
* An Ant target unzip the runtime and launches a *play war* command.
* The Play! war as the same name as the Maven one, thus it is replacing it.
%{color:red}*It is important to remove target directory from the war to decrease the size by 70Mb.*%
PK еu=e+ + clean-repos.sh#!/bin/sh
rm -Rf ~/.m2/repository/org/play
PK o=AHGX X commands.py# Here you can create play commands that are specific to the module, and extend existing commands
import os, inspect, shutil
import getopt
import sys
import subprocess
MODULE = 'maven'
# Commands that are specific to your module
COMMANDS = ['new','mvn:init','mvn:install','mvn:update','mvn:up','mvn:refresh','mvn:re','mvn:sources','mvn:src','mvn:play-dependency-sources','mvn:play-src']
HELP = {
'update': "Updates libraries in the /lib folder",
'refresh': "Deletes all *.jar and *.zip in /lib folder and updates libraries in the /lib folder",
}
##################################################
### execute
##################################################
def execute(**kargs):
command = kargs.get("command")
app = kargs.get("app")
args = kargs.get("args")
env = kargs.get("env")
# Definition of Module path
module_dir = inspect.getfile(inspect.currentframe()).replace("commands.py","")
kargs["module_dir"]=module_dir
# Definition of Application path
kargs["app_path"]=app.path
if command == "mvn:install":
callInstall(kargs)
if command == 'new' or command == "mvn:init":
callInit(kargs)
if command == 'mvn:update' or command == 'mvn:up':
checkPomXML(app.path)
callUpdate(kargs)
if command == 'mvn:refresh' or command == 'mvn:re':
checkPomXML(app.path)
callRefresh(kargs)
if command == 'mvn:sources' or command == 'mvn:src':
checkPomXML(app.path)
callSources(kargs)
if command == 'mvn:play-dependency-sources' or command == 'mvn:play-src':
checkPomXML(app.path)
callPlaySources(kargs)
##################################################
### mvn:install
##################################################
def callInstall(args):
module_dir = args.get("module_dir")
save_cwd = os.getcwd()
print "~ Installing parent pom ..."
print "~ "
os.chdir(os.path.join(module_dir, 'resources/play-parent'))
os.system('mvn clean install')
os.chdir(save_cwd)
##################################################
### mvn:init OR new
##################################################
def callInit(args):
module_dir = args.get("module_dir")
app_path=args.get("app_path")
print "~ Executing mvn:init"
print "~ "
callInstall(args)
if os.path.exists('pom.xml'):
print "~ "
print "~ Existing pom.xml will be backed up to pom.xml.bak"
print "~ "
shutil.copyfile('pom.xml', 'pom.xml.bak')
print "~ "
print "~ Copying pom.xml from module to project ..."
print "~ "
shutil.copyfile(os.path.join(module_dir,'resources/pom.xml'), os.path.join(app_path, 'pom.xml'))
##################################################
### mvn:update OR mvn:up
##################################################
def callUpdate(args):
print "~"
print "~ Retrieving dependencies..."
print "~"
os.system('mvn dependency:copy-dependencies')
# callSources(args)
##################################################
### mvn:refresh OR mvn:re
##################################################
def callRefresh(args):
print "~"
print "~ Refresh dependencies..."
print "~"
os.system('mvn clean')
callUpdate(args)
##################################################
### mvn:sources OR mvn:src
##################################################
def callSources(args):
print "~"
print "~ Retrieving dependencies sources..."
print "~"
os.system('mvn dependency:copy-dependencies -Dclassifier=sources')
##################################################
### mvn:play-dependency-sources OR mvn:play-src
##################################################
def callPlaySources(args):
print "~"
print "~ Retrieving Play's dependencies sources ..."
print "~"
os.system('mvn dependency:copy-dependencies -Pplay-src')
def checkPomXML(path):
if not os.path.exists('pom.xml'):
print "~ ERROR : pom.xml does not exist in your project."
print "~ You can initialize a pom.xml with the command play mvn:init."
sys.exit(-1)
PK еu=v - samples-and-tests/validate-with-maven/pom.xml4.0.0org.playplay-parent1.1my.group.Idmyartifactid0.0.1-SNAPSHOTMy Artifact NameMy Artifact Descriptionorg.hibernatehibernate-validator4.1.0.Finalmaven-clean-pluginmaven-dependency-pluginmaven-antrun-plugin
PK еu=p
T ? samples-and-tests/validate-with-maven/test/ApplicationTest.javaimport org.junit.*;
import play.test.*;
import play.mvc.*;
import play.mvc.Http.*;
import models.*;
public class ApplicationTest extends FunctionalTest {
@Test
public void testThatIndexPageWorks() {
Response response = GET("/");
assertIsOk(response);
assertContentType("text/html", response);
assertCharset("utf-8", response);
}
}PK еu=ˋ3 @ samples-and-tests/validate-with-maven/test/Application.test.html*{ You can use plain selenium command using the selenium tag }*
#{selenium}
// Open the home page, and check that no error occured
open('/')
assertNotTitle('Application error')
#{/selenium}PK еu=) 9 samples-and-tests/validate-with-maven/test/BasicTest.javaimport org.junit.*;
import java.util.*;
import play.test.*;
import models.*;
public class BasicTest extends UnitTest {
@Test
public void aVeryImportantThingToTest() {
assertEquals(2, 1 + 1);
}
}
PK еu=c 3 samples-and-tests/validate-with-maven/test/data.yml# you describe your data using the YAML notation here
# and then load them using Fixtures.load("data.yml")
# User(bob):
# email: bob@gmail.com
# password: secret
# fullname: BobPK еu=tkd F samples-and-tests/validate-with-maven/app/controllers/Application.javapackage controllers;
import play.*;
import play.mvc.*;
import java.util.*;
import models.*;
public class Application extends Controller {
public static void index() {
render();
}
}PK еu=xL L 9 samples-and-tests/validate-with-maven/app/views/main.html
#{get 'title' /}
#{get 'moreStyles' /}
#{get 'moreScripts' /}
#{doLayout /}
PK еu=,] ] ? samples-and-tests/validate-with-maven/app/views/errors/404.html
Not found
#{if play.mode.name() == 'DEV'}
#{404 result /}
#{/if}
#{else}