Document 1168939
Download
Report
Transcript Document 1168939
Maven project automation for dummies
Aino Andriessen
AMIS
dec 20, 2007
1
Continuous Integration
Continuous integration is the practice where
the work of all the developers are integrated,
analyzed and verified on a regular basis,
preferably multiple times a day.
It takes the latest situation from the source
control system, performs unit tests, makes a
build, deploys the application, performs
integration tests and creates reports about
these steps and communicates them with the
team, all automatically without human
interaction.
dec 20, 2007
2
Conditions
Infrastructure
Scripting
No IDE
dec 20, 2007
3
Scripting
Maven
ant
make
shell scripts
sql scripts
...
dec 20, 2007
4
Demo
dec 20, 2007
5
Maven execution info
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO]
HR1
[INFO]
HR1 model
[INFO]
HR1 viewController
[INFO]
HR1 ear
[INFO]
HR1 integration
[INFO] ------------------------Downloading: http://repo1.maven.org/maven2/junit/junit/3.8.1/junit-3.8.1.jar
118K downloaded
[INFO]
[INFO]
[INFO]
[INFO]
[INFO]
[INFO]
[INFO]
[INFO]
[INFO]
[INFO]
[INFO]
[INFO]
[INFO]
[INFO]
[INFO]
[INFO]
[INFO]
-----------------------------------------------------------------------Reactor Summary:
-----------------------------------------------------------------------HR1 ................................................... SUCCESS [3.003s]
HR1 model ............................................. SUCCESS [7.866s]
HR1 viewController .................................... SUCCESS [54.451s]
HR1 ear ............................................... SUCCESS [14.591s]
HR1 integration ....................................... SUCCESS [0.312s]
----------------------------------------------------------------------------------------------------------------------------------------------BUILD SUCCESSFUL
-----------------------------------------------------------------------Total time: 1 minute 20 seconds
Finished at: Fri Jun 01 17:32:01 CEST 2007
Final Memory: 10M/18M
-----------------------------------------------------------------------
dec 20, 2007
6
mvn test
[INFO] [surefire:test]
[INFO] Surefire report directory: D:\projects\myprojects\odtugDemo\hr1\model\tar
get\surefire-reports
------------------------------------------------------TESTS
------------------------------------------------------Running nl.amis.demo.odtug.model.queries.OdtugTstViewTest
Jun 1, 2007 7:04:22 PM oracle.adf.share.config.ADFConfigFactory findOrCreateADFC
onfig
INFO: oracle.adf.share.config.ADFConfigFactory No META-INF/adf-config.xml found
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.606 sec
Running nl.amis.demo.odtug.model.queries.RegionsViewTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.031 sec
Running nl.amis.adf.fwk.test.Java5Test
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
Running nl.amis.demo.odtug.model.queries.JobsViewTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.046 sec
Running nl.amis.demo.odtug.model.queries.EmployeesViewTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.032 sec
Running nl.amis.demo.odtug.model.queries.DepartmentsViewTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.015 sec
Running nl.amis.demo.odtug.model.queries.LocationsViewTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
Running nl.amis.demo.odtug.model.queries.CountriesViewTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.015 sec
Results :
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0
dec 20, 2007
7
mvn package
[INFO] Building HR1
[INFO] task-segment: [package]
[INFO] --------------------------[INFO] [jar:jar]
[INFO] Building jar: D:\projects\myprojects\odtugDemo\hr1\model\target\hr1-model-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------[INFO] [war:war]
[INFO] Building war: D:\projects\myprojects\odtugDemo\hr1\viewController\target\hr1-viewController-1.0SNAPSHOT.war
[INFO] [ear:ear]
[INFO] Copying artifact[war:nl.amis.demo.odtug.hr1:hr1-viewController:1.0-SNAPSHOT] to[hr1-viewController-1.0SNAPSHOT.war]
[INFO] Copying artifact[jar:log4j:log4j:1.2.12] to[log4j-1.2.12.jar]
[INFO] Copying artifact[jar:commons-logging:commons-logging:1.0.4] to[commons-logging-1.0.4.jar]
[INFO] Could not find manifest file: D:\projects\myprojects\odtugDemo\hr1\ear\src\main\application\METAINF\MANIFEST.MF - Generating one
[INFO] Building jar: D:\projects\myprojects\odtugDemo\hr1\ear\target\hr1-ear-1.0-SNAPSHOT.ear
[INFO] -------------------------------------------------------------------------
dec 20, 2007
8
mvn exec:exec -PlocalOC4J
[INFO] [exec:exec]
[[INFO] 07/06/01 17:21:22 Notification ==>Uploading file hr1.ear ...
[INFO]
[INFO] 07/06/01 17:21:22 Notification ==>Application Deployer for hr1 STARTS.
[INFO]
[INFO] 07/06/01 17:21:22 Notification ==>Copy the archive to :\server\oc4j_101310\j2ee\home\applications\hr1.ear
[INFO]
[INFO] 07/06/01 17:21:22 Notification ==>Initialize C:\server\oc4j_101310\j2ee\home\applications\hr1.ear begins...
[INFO]
[INFO] 07/06/01 17:21:24 Notification ==>Initialize hr1-viewController-1.0-SNAPSHOT begins...
[INFO]
[INFO] 07/06/01 17:21:24 Notification ==>Initialize hr1-viewController-1.0-SNAPSHOT ends...
[INFO]
[INFO] 07/06/01 17:21:24 Notification ==>Started application : hr1
[INFO]
[INFO] 07/06/01 17:21:24 Notification ==>Binding web application(s) to site default-web-site begins...
[INFO]
[INFO] 07/06/01 17:21:24 Notification ==>Binding hr1-viewController-1.0-SNAPSHOT web-module for application
hr1 to site default-web-site under context root /hr1
[INFO]
[INFO] 07/06/01 17:21:31 Notification ==>Initializing Servlet: javax.faces.webapp.FacesServlet for web application
hr1-viewController-1.0-SNAPSHOT
[INFO]
[INFO] 07/06/01 17:21:31 Notification ==>Binding web application(s) to site default-web-site ends...
[INFO]
[INFO] 07/06/01 17:21:31 Notification ==>Application Deployer for hr1 COMPLETES.
Operation time: 8273 msecs
dec 20, 2007
9
mvn verify -PlocalOC4J
dec 20, 2007
10
mvn deploy
[INFO] [deploy:deploy]
[INFO] Retrieving previous build number from ATAMaven2SnapshotsRepo
Uploading: file:\\amis-test-aa\maven2snapshots/nl/amis/demo/odtug/hr1/hr1-model/1.0-SNAPSHOT/hr1-model-1.020070601.171522-4.jar
50K uploaded
[INFO] Retrieving previous metadata from ATAMaven2SnapshotsRepo
[INFO] Uploading repository metadata for: 'snapshot nl.amis.demo.odtug.hr1:hr1-model:1.0-SNAPSHOT'
[INFO] -------------------------------------------------------------------------
dec 20, 2007
11
mvn site
dec 20, 2007
12
Build automation server
dec 20, 2007
13
Demo Summary
ADF Faces application
Tasks
Unittesting
Make a build
Deploy ear file to OC4J
Perform integrationtests
Share artifacts
Share information
Without manual intervention and JDeveloper !
dec 20, 2007
14
Infrastructure
dec 20, 2007
15
Software Studio
dec 20, 2007
16
Software development
The development environment
Source control
Delivery environments
Issue management
Library management
Build automation / continuous integration
Reporting and documentation
Communication
dec 20, 2007
17
Nightly build
Continuum
Scheduler
http://ci.amis.nl:8080/continuum/servlet/continuum
dec 20, 2007
18
'Scripting' with Maven
dec 20, 2007
19
Maven
Project Object Model
Project objects
xml file
Build Lifecycle
actions / goals (tasks)
Dependency (library, artifact) Management
Reporting and Documentation
...
dec 20, 2007
20
Convention
over
configuration
dec 20, 2007
21
POM example
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>nl.amis.demo.odtug.hr1</groupId>
<artifactId>hr1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>model</module>
<module>viewController</module>
<module>ear</module>
</modules>
<name>HR1</name>
<description>This application manages employees and general company
information.</description>
<url>http://localhost:8800/hr1/faces/index.jspx</url>
<organization>
<name>AMIS Services</name>
<url>http://www.amis.nl</url>
</organization>
<issueManagement>
<system>Jira</system>
<url>http://dev.amis.nl/jira/browse/PAG</url>
</issueManagement>
dec 20, 2007
22
POM example
<scm>
<connection>scm:svn:http://subversion.amis.nl/users/aino_a/hr1/trunk/
</connection>
<developerConnection>
scm:svn:http://subversion.amis.nl/users/aino_a/hr1/trunk/
</developerConnection>
<url>http://subversion.amis.nl/users/aino_a/hr1/trunk/</url>
</scm>
<developers>
<developer>
<id>aino.andriessen</id>
<name>Aino Andriessen</name>
<email>[email protected]</email>
<organization>AMIS</organization>
<roles><role>developer</role></roles>
<timezone>+1</timezone>
</developer>
</developers>
<distributionManagement>
<repository>
<id>AMISMaven2Repo</id>
<url>file:\\ci.amis.nl\maven2</url>
</repository>
</distributionManagement>
dec 20, 2007
23
Pom Example
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>
src/main/resources/amis_checkstyle.xml
</configLocation>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
dec 20, 2007
24
Build Lifecycle
Organized sequence of phases
like compile, test, package, build
etc. The actual work is done by
goals which are bound to a
certain phase.
Configuration (if necessary) in
pom
Other lifecycles
clean
site
validate
generate-sources
process-sources
generate-resources
process-resources
compile
process-classes
generate-test-sources
process-test-sources
generate-test-resources
process-test-resources
test-compile
test
prepare-package
package
pre-integration-test
integration-test
post-integration-test
verify
install
deploy
dec 20, 2007
25
Execution
mvn compile
mvn compile:compile
mvn compile:test-compile
mvn package
mvn jar
• mvn jar:jar
• mvn jar:sign
• mvn test-jar:jar
dec 20, 2007
26
Plugins
All 'tasks' are plugins
Written in java, ant
dec 20, 2007
27
Dependency Management
Defined in the POM
Downloaded from repository when needed
Stored in local repository
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle.adf</groupId>
<artifactId>adfbinding</artifactId>
<version>10.1.3.39.84</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>nl.amis.demo.odtug.hr1</groupId>
<artifactId>hr1-model</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
dec 20, 2007
28
Maven repositories
dec 20, 2007
29
Maven repositories 2
Local
Internal
Central
http://repo1.maven.org/maven2/
External
Codehaus
java.net
...
dec 20, 2007
30
Internal repository
commercial libraries
non-public libraries
company products
dec 20, 2007
31
AMIS internal repositories
http://ci.amis.nl/maven2/
http://ci.amis.nl/maven2snapshots/
dec 20, 2007
32
Deploy
Upload the (created) artifact to the internal
repository
mvn deploy:deploy-file
deploy a library tot the repository
call mvn deploy:deploy-file
-DgroupId=com.oracle.jdbc
-DartifactId=ojdbc14
-Dversion=10.2.0.1
-Dfile=ojdbc14.jar
-Dpackaging=jar
-DrepositoryId=AMISMaven2Repository
-Durl=file:\\ci.amis.nl\maven2
dec 20, 2007
33
Snapshots
Dependency management for development
'releases'.
dec 20, 2007
34
Testing
Unittests
JUnit
TestNG
Integration tests
Database tests
...
dec 20, 2007
35
Integration tests
Start application server
Prepare the database
Deploy application
Run tests
Undeploy application
Stop application server
dec 20, 2007
36
Integration tests
Front-end
Selenium
JMeter
Back-end / Database
QCTO
utPLSQL
Tools
dbunit
Maven sql plugin
Maven exec plugin
(JDeveloper) ant tasks
dec 20, 2007
37
Release
mvn release:prepare
update version
tag in scm
mvn release:perform
deploy tagged version
•
•
•
artifact
sources
doc
create and deploy file
dec 20, 2007
38
Maven projectsites
Documentation
Project info
Reports
http://ci.amis.nl/projectsites/
dec 20, 2007
39
Maven 'bits and pieces'
Reports
Profiles
Archetype
Cargo plugin
Multi module projects
...
dec 20, 2007
40
ADF & JDeveloper & Maven
dec 20, 2007
41
Mavenize an ADF application
Dependency management
Crete or generate POM files
Tools
dec 20, 2007
42
Tools
admin_client.jar utility
deployment to OC4J
ojspc.jar utility
pre compilation of jsf files
[JDeveloper]
[oc4j]
dec 20, 2007
43
JDeveloper library management
JDeveloper has a great library management
system...
as long as you stay in JDeveloper
as long as you use the provided libraries
dec 20, 2007
44
Dependencies
Put (deploy) libraries in the internal repository
Keep pom file(s) in sync
call mvn deploy:deploy-file
-DgroupId=com.oracle.adf
-DartifactId=adfshare
-Dversion=%ADF_VERSION%
-Dfile=%JDEV_HOME%/BC4J/lib/adfshare.jar
-Dpackaging=jar
-DrepositoryId=%REPO_ID%
-Durl=%REPO_URL%
<dependencies>
<dependency>
<groupId>com.oracle.adf</groupId>
<artifactId>adfshare</artifactId>
<version>10.1.3.41.57</version>
<scope>provided</scope>
</dependency>
</dependencies>
dec 20, 2007
45
Required libraries
ADF
•
•
adfshare, adfui, adf-controller, adfbinding, adfm, bc4jdomorcl,
bc4jmt, bc4jct, bc4jdatum, bc4jhtml, datatags, graphtags,
bc4jimdomains, ordim
jhsadfrt, sqlj runtime
JDeveloper
•
oc4j-internal, oc4j, adf-faces-impl, adf-faces-api, jdev-cm, ojmisc,
xmlparserv2, ojsp, ojsputil
Other
•
sun collections 1.1, apache commons
Note : do NOT include log4j
ADF
10.1.3.0
10.1.3.36.73
10.1.3.1
10.1.3.39.84
10.1.3.2
10.1.3.40.66
10.1.3.3
10.1.3.41.57
dec 20, 2007
JDev
46
Application / Project organisation
Directory layout
Default Maven layout
JDev project settings
Application with multiple projects
dec 20, 2007
47
ADF Archetype
AMIS maven-archetype-adf :
mvn archetype:create
-DarchetypeGroupId=nl.amis.maven.archetypes
-DarchetypeArtifactId=maven-archetype-adf
-DarchetypeVersion=10.1.3.3[-SNAPSHOT]
-DremoteRepositories=http://ci.amis.nl/maven2(snapshots)
-DgroupId=nl.amis.demo
-DartifactId=hr1
dec 20, 2007
48
Projectfile generation
Create jws and jpr files
myFaces - Trinidad JDev plugin
org.apache.myfaces.trinidadbuild.maven-jdevplugin
version 1.2.5
Execute : mvn jdev:jdev
http://technology.amis.nl/blog/?p=1279
dec 20, 2007
49
Deploy to OC4J
Command-line
oc4j admin_client.jar utility
in ear project or associated with a certain
phase
mvn exec:exec -PlocalOC4J
Unfortunately no Cargo plugin
cargo:start, cargo:stop, cargo:deploy
Define local dependencies (location of
admin_client.jar) in local settings.xml
dec 20, 2007
50
Example
<profile>
<id>devOC4J</id>
<plugin>
<activation>
<groupId>org.codehaus.mojo</groupId>
<activeByDefault>false</activeByDefault>
<artifactId>exec-maven-plugin</artifactId>
</activation>
<properties>
<executions>
<ias.server.url>ci.amis.nl</ias.server.url>
<execution>
<ias.server.port>8888</ias.server.port>
<id>deployApp</id>
<ias.deploy.url>deployer:oc4j:${ias.server.url}</ias.deploy.url>
<phase>pre-integration-test</phase> <ias.username>oc4jadmin</ias.username>
<goals>
<ias.password>oc4jadmin</ias.password>
</properties>
<goal>exec</goal>
</profile>
</goals>
<configuration>
<executable>${java.home}/bin/java</executable>
<arguments>
<argument>-jar</argument>
<argument>${oc4j.adminclient.home}\j2ee\home\admin_client.jar</argument>
<argument>${ias.deploy.url}</argument>
<argument>${ias.username}</argument>
<argument>${ias.password}</argument>
<argument>-deploy</argument>
<argument>-file</argument>
<argument>../ear/target/hr1-ear-${version}.ear</argument>
<argument>-deploymentName</argument>
<argument>hr1</argument>
<argument>-bindAllWebApps</argument>
</arguments>
</configuration>
java -jar C:\server\oc4j_101310\j2ee\home\admin_client.jar
</execution>
deployer:oc4j:localhost
</executions>
oc4jadmin oc4jadmin
</plugin>
-deploy -file hr1-ear-1.0-SNAPSHOT.ear
-deploymentName hr1 -bindAllWebApps
dec 20, 2007
51
Running Maven from JDeveloper
Waiting for a JDeveloper extension ;-)
Ant tasks as wrapper
dec 20, 2007
52
Installation of Maven
http://maven.apache.org/download.html
Unzip
Environment settings : M2_HOME , PATH
mvn -verify
settings.xml
<M2_HOME>/conf/ or <user.dir>/.m2/
[local repository]
servers
•
credentials
internal repositories
local configurations
•
dec 20, 2007
oc4j installation
53
Conclusion
Continuous integration is essential for the
development process!
Using Maven, ADF Faces applications can be
continuously integrated!
Maven succesfully applied at Connexys,
Pagoni, Locatus, Nieuw Caledonië
dec 20, 2007
54
[email protected]
http://technology.amis.nl/blog
dec 20, 2007
55