92
CQ MAVEN METHODS CQCON 2013

CQCON CQ Maven Methods

  • View
    1.319

  • Download
    0

Embed Size (px)

DESCRIPTION

This talk was presented at CQCON 2013 in Basel. Learn how to master development workflows combining the power of CQ with Apache Maven and Git. Sometimes it can be hard to get up and running with other developers' Adobe CQ projects. Where is the code? How can you build it once you have it? How do you get it into CQ? What do you do with it once it's there? Anyone should be able to quickly and easily perform a git clone of a CQ project, followed by doing a Maven build and install, and then immediately be able to try it out and work on it within CQ. This session will show developers how they can structure their projects so that they are buildable "out of the box". We will provide hints and tips on how to structure your application in git, and explain which maven plugins to use in a range of circumstances. See the CQCON website http://www.cqcon.eu/2013/en/speakers/andrew-savory.html or the online version of the presentation at http://www.andrewsavory.com/presentations/CQCon_2013_CQ_Maven_Methods/index.html The source of the presentation is in github at https://github.com/savs/CQCon_2013_CQ_Maven_Methods

Citation preview

Page 1: CQCON CQ Maven Methods

CQ MAVEN METHODSCQCON 2013

Page 2: CQCON CQ Maven Methods

HELLO WORLDI'm Andrew.

[email protected]

@savs

Page 3: CQCON CQ Maven Methods

Joined Adobe in November 2012

Page 4: CQCON CQ Maven Methods

CQ Newbie

JCR/CMS/TLA old hat

Page 5: CQCON CQ Maven Methods

Background in Open Source, Content Management, Mobile

Page 6: CQCON CQ Maven Methods

Talking today about what I learned so far...

Page 7: CQCON CQ Maven Methods

FORK ME!If you found this talk useful, or spotted mistakes:

github.com/savs/CQCon_2013_CQ_Maven_Methods

Page 8: CQCON CQ Maven Methods

IN YOUR BROWSERhttp://goo.gl/qqS1F

Page 9: CQCON CQ Maven Methods

SEE ALSOhttp://www.planetcq.org/

Page 10: CQCON CQ Maven Methods
Page 11: CQCON CQ Maven Methods
Page 12: CQCON CQ Maven Methods

LET'S BUILD A CQ SITE

... uh, where to begin?

Page 13: CQCON CQ Maven Methods

METHOD 1Enthusiastically rush in, use CRXDE Lite

Page 14: CQCON CQ Maven Methods

METHOD 2I'm a guru, I use Eclipse and CRXDE

Page 15: CQCON CQ Maven Methods

METHOD 3I'm a ninja, I use emacs and vlt

Page 16: CQCON CQ Maven Methods

METHOD 4I'm a guru ninja, I use vi and curl

Page 17: CQCON CQ Maven Methods

METHOD 5

See also: http://xkcd.com/378/ – Real Programmers

Page 18: CQCON CQ Maven Methods

BUT WHAT ABOUT ...reverting mistakes?

reproducible builds?

collaborating with others?

deploying to production?

Page 19: CQCON CQ Maven Methods

WHY ISN'T IT EASIER TO BUILD A CQ SITE?Laborious project inception

No two projects alike

Don't know project layout

Don't know project dependencies

Hard for others to reproduce

Hard to test

Lengthy RTFM or worse (no FM)

Documentation over convention

Page 20: CQCON CQ Maven Methods

CQ SUCKS

Page 21: CQCON CQ Maven Methods

$PRODUCT SUCKS

Page 22: CQCON CQ Maven Methods

YOUR METHODOLOGY SUCKS(sorry)

Page 23: CQCON CQ Maven Methods

SO HOW DO WE FIX THIS?Maven

Git(or Subversion, or CVS ... ymmv)

Best Practices

Page 24: CQCON CQ Maven Methods

MAVEN“Maven is a software project management

and comprehension tool. Based on the

concept of a project object model (POM),

Maven can manage a project's build,

reporting and documentation from a central

piece of information.”

Page 25: CQCON CQ Maven Methods

GIT“Git is a free and open source distributed

version control system designed to handleeverything from small to very large projects

with speed and efficiency. ”Version control is a system that records changes to a file or set of files over

time so that you can recall specific versions later.

Page 26: CQCON CQ Maven Methods

BEST PRACTICES“A best practice is a method or technique that

has consistently shown results superior tothose achieved with other means.”

In addition, a "best" practice can evolve to become better as improvementsare discovered.

Page 27: CQCON CQ Maven Methods

WHAT DO WE WANT?Minimal customisation

Standardised way to create a project

Standardised way to build a project

Standardised way to deploy a project

Standardised way to test a project

Standardised way to share a project

Page 28: CQCON CQ Maven Methods

OUR TARGET

Page 29: CQCON CQ Maven Methods

Success criteria:

IT'S EASY TO BUILD A CQ SITE!

Page 30: CQCON CQ Maven Methods

GETTING STARTEDInstall Maven: http://maven.apache.org/guides/getting-

started/

Install Git: http://git-scm.com/book/en/Getting-Started-Installing-Git

Page 31: CQCON CQ Maven Methods

CONFIGURING MAVENMaven has a settings file that defines things likerepositories where plugins can be downloaded (typically~/.m2/settings.xml).We need to add a profile to point to the Adobe repository.We then specify this repository when we use thearchetype plugin.

See also: Obtaining the Content Package Maven Plugin

Page 32: CQCON CQ Maven Methods

CONFIGURING MAVEN<profile> <id>adobe-public</id> <activation> <activeByDefault>false</activeByDefault> </activation> <properties> <releaseRepository-Id>adobe-public-releases</releaseRepository-Id> <releaseRepository-Name>Adobe Public Releases</releaseRepository-Name> <releaseRepository-URL>http://repo.adobe.com/nexus/content/groups/public</releaseRepository-URL> </properties> <repositories> <repository> <id>adobe-public-releases</id> <name>Adobe Basel Public Repository</name> <url>http://repo.adobe.com/nexus/content/groups/public</url> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>adobe-public-releases</id> <name>Adobe Basel Public Repository</name> <url>http://repo.adobe.com/nexus/content/groups/public</url> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories></profile>

Page 33: CQCON CQ Maven Methods

CONFIGURING MAVENEnable the repository:

Or use the -P option to activate profile(s):

<activeProfiles> <activeProfile>adobe-public</activeProfile></activeProfiles>

mvn -P adobe-public [...]

Page 34: CQCON CQ Maven Methods

USING MAVEN

Page 35: CQCON CQ Maven Methods

STARTING A NEW PROJECT ...

... can sometimes feel like reinventing the wheel.

Page 36: CQCON CQ Maven Methods

YOU ARE HERE

Page 37: CQCON CQ Maven Methods

ARCHETYPESarchetype |ˈɑːkɪtʌɪp|

noun

a very typical example of a certain person or thing: he wasthe archetype of the old-style football club chairman.an original which has been imitated; a prototype: aninstrument which was the archetype of the early flute.

Page 38: CQCON CQ Maven Methods

MAVEN ARCHETYPESA prototype upon which others are

copied, patterned, or emulated.

Page 39: CQCON CQ Maven Methods

WHAT CQ ARCHETYPES ARE THERE?simple-content-package

Generates a simple

multimodule-content-packageIncludes the folder structure for developing a CQ

application (content package and bundle).

cqblueprints multi-moduleThird-party archetype encapsulating best practices for

working with e.g. OSGi bundles, taglibs, and CQ content

See also:

content package

How to work with packages

Page 40: CQCON CQ Maven Methods

ON PACKAGESPackages enable the importing and exporting of repositorycontent. They are used to install new functionality, transfercontent between instances, or back up the repositoryA package is a zip file in file system (vault) serializationformatPackages include meta information - filter definitions,import configuration, package propertiesPackages are often managed through the CQ Package Manager

Page 41: CQCON CQ Maven Methods

ON BUNDLESBundles are modular containers of functionality for OSGi –

essentially a java module that contains application logic

Bundles consist of java classes and other resources needed

to deliver functionality or to provide services to other

bundles.

Bundles can be managed through the CQ

See also:

Web Console

Creating OSGi bundles using CRXDE

Page 42: CQCON CQ Maven Methods

HOW TO USE AN ARCHETYPE

archetypeGroupId: identifies the archetype projectuniquely across all projectsarchetypeArtifactId: the name of the archetype jarwithout a version numberarchetypeRepository: where to get the archetype from(based on pluginRepository in settings.xml)

See also: and

mvn archetype:generate -DarchetypeGroupId=foo -DarchetypeArtifactId=bar -DarchetypeVersion=1.0.0 -DarchetypeRepository=baz

Maven: Introduction to Archetypes Maven: Naming conventions

Page 43: CQCON CQ Maven Methods

SIMPLE CONTENT PACKAGE ARCHETYPEFrom the fine manual:

“Creates a maven project that is suitable for

installing resources for a simple CQ

application. The folder structure is that used

below the /apps folder of the CQ repository.

The POM defines commands for packaging

the resources that you place in the folders and

installing the packages on the CQ server.”

Page 44: CQCON CQ Maven Methods

SIMPLE CONTENT PACKAGE USAGE

archetypeGroupId: com.day.jcr.vaultidentifies the archetype project uniquely across all projectsarchetypeArtifactId: simple-content-package-archetypethe name of the archetype jar without a version numberarchetypeRepository: adobe-public-releaseswhere to get the archetype from (based onpluginRepository in settings.xml)

mvn archetype:generate -DarchetypeGroupId=com.day.jcr.vault -DarchetypeArtifactId=simple-content-package-archetype -DarchetypeVersion=1.0.1 -DarchetypeRepository=adobe-public-releases

Page 45: CQCON CQ Maven Methods

SIMPLE CONTENT PACKAGE IN ACTION

Page 46: CQCON CQ Maven Methods

SIMPLE CONTENT PACKAGE PARAMETERSgroupId: Like a package name, e.g.com.yourcompany.myprojectartifactId: name of the jar without the version, e.g.myprojectversion: accept the defaultpackage: not used in simple-content-packageappsFolderName: name of /apps/myproject, e.g. myprojectartifactName: Description in Package ManagerpackageGroup: Group in Package Manager

See also: Maven: Naming conventions

Page 47: CQCON CQ Maven Methods

SIMPLE CONTENT PACKAGE OUTPUTTemplate directoriespom.xml file

Instructions for compiling, creating bundles, deployingto CQ in packages

FileVault configuration files

Page 48: CQCON CQ Maven Methods

MULTIMODULE CONTENT PACKAGE USAGEmvn archetype:generate -DarchetypeGroupId=com.day.jcr.vault -DarchetypeArtifactId=multimodule-content-package-archetype -DarchetypeVersion=1.0.1 -DarchetypeRepository=adobe-public-releases

Page 49: CQCON CQ Maven Methods

MULTIMODULE CONTENT PACKAGE OUTPUT${artifactId} |- pom.xml |- bundle |- pom.xml |- src |- main |- java |- ${groupId} |- SimpleDSComponent.java |- test |- java |- ${groupId} |- SimpleUnitTest.java |- content |- pom.xml |- src |- main |- content |- jcr_root |- apps |- ${appsFolderName} |- config |- install |- META-INF |- vault |- config.xml

Page 50: CQCON CQ Maven Methods

|- filter.xml |- nodetypes.cnd |- properties.xml |- definition |- .content.xml

Page 51: CQCON CQ Maven Methods

CQBLUEPRINTS MULTI-MODULE USAGEFirst add the CQ Blueprints Maven Repository to Maven'ssettings.xml, then:

archetypeGroupID: com.cqblueprints.archetypesarchetypeArtifactId: multi-modulearchetypeVersion: 1.0.5archetypeRepository: cqblueprints.plugins.releases

See also: and

mvn -P cqblueprints archetype:generate -DarchetypeGroupId=com.cqblueprints.archetypes -DarchetypeArtifactId=multi-module -DarchetypeVersion=1.0.5 -DarchetypeRepository=cqblueprints.plugins.releases

Connecting to the CQ Blueprints Repository The CQ Project Maven Archetype

Page 52: CQCON CQ Maven Methods

CQBLUEPRINTS MULTI-MODULE OUTPUT${artifactId} |- README |- pom.xml |- ${artifactId}-all |- pom.xml |- ${artifactId}-config |- ${artifactId}-content |- ${artifactId}-services |- ${artifactId}-taglib |- ${artifactId}-view

Page 53: CQCON CQ Maven Methods

WHY USE CQBLUEPRINTS MULTI-MODULE?

The cqblueprint multi-module archetype is developed by

“The things we wanted to consider with ourarchetype is to address concerns of larger

teams”

headwire.com

Page 54: CQCON CQ Maven Methods

CQBLUEPRINTS MULTIMODULE DESIGNfoo-view subproject: where css/html/js developers (frontend)do their workfoo-taglib foo-services: where java developers (backend) dotheir workfoo-config: where the configuration (runmode configs stored)foo-content: how we get initial content and site structure ontothe developer's box quicklyfoo-all: how we hand off builds to the next environment

Page 55: CQCON CQ Maven Methods

USING GIT

Page 56: CQCON CQ Maven Methods

WHY GIT?Local safety net"The internet is my backup"It's good to shareEnlightened self-interest

Page 57: CQCON CQ Maven Methods

YOU ARE HERE

Page 58: CQCON CQ Maven Methods

GIT PROJECT SETUPcd projectnamegit init

Page 59: CQCON CQ Maven Methods

GIT IGNOREEdit .gitignore, for example:

.classpath

.project

.vlt/

.settings/target/

Page 60: CQCON CQ Maven Methods

GET IT IN GITgit add *git commit -m 'Initial project version'

Page 61: CQCON CQ Maven Methods

GET IT IN GITHUB (OPTIONAL)

hub-new-repo is a shortcut for creating a repository ongithub and pushing your local repo into it

See also:

See also:

cd projectgit hub-new-repo

CLI remote github repo creation

github

Page 62: CQCON CQ Maven Methods

DEMO

Page 63: CQCON CQ Maven Methods

... TIME PASSES ...

Page 64: CQCON CQ Maven Methods

COMMIT PROJECTgit add filenamesgit commit -m "meaningful message"git push origin master

Page 65: CQCON CQ Maven Methods

(BEST) PRACTICE(S)

Page 66: CQCON CQ Maven Methods

YOU ARE HERE

Page 67: CQCON CQ Maven Methods

“the three great virtues of a programmer:laziness, impatience, and hubris”

Page 68: CQCON CQ Maven Methods
Page 69: CQCON CQ Maven Methods

BUILDING

Page 70: CQCON CQ Maven Methods

HOW CAN WE BUILD SMARTER?Create local zips and jars that you can upload:

mvn packageproduces:

Content package output: target/yourapp-content-1.0-SNAPSHOT.zipBundle output: target/testapp-bundle-1.0-SNAPSHOT.jar

Page 71: CQCON CQ Maven Methods

DEPLOYING

Page 72: CQCON CQ Maven Methods

HOW CAN WE BUILD AND DEPLOY SMARTER?Content package: mvn -PautoInstallPackageinstallBundle: mvn -PautoInstallBundle install

cqblueprints: mvn -Pauto-deploy install

Page 73: CQCON CQ Maven Methods

DEMO

Page 74: CQCON CQ Maven Methods

DEVELOPING

Page 75: CQCON CQ Maven Methods

YOU ARE HERE

Page 76: CQCON CQ Maven Methods

How do we develop in a world of maven builds and deploys

and git saves?

Page 77: CQCON CQ Maven Methods

THE FILEVAULT TOOLYou can use the FileVault tool (vlt) to check in, check out,

update and sync local content with the repository.

Install: extract crx-quickstart/opt/filevault/filevault.[tgz|zip] and add to your pathUsage: vlt --credentials admin:admin co --force http://localhost:4502/crx

See also: How to use the VLT Tool

Page 78: CQCON CQ Maven Methods

SAMPLE DEVELOPMENT WORKFLOWUse maven to build and deployInitialise vltCreate components, templates with CRXDE LiteUse vlt to copy back into local filesystemChange locallyUse vlt to copy back into the repositoryAdd to git

Page 79: CQCON CQ Maven Methods

DEMO

Page 80: CQCON CQ Maven Methods

TESTING

Page 81: CQCON CQ Maven Methods

CONTINUOUS INTEGRATION? with ,

as a with and

Jenkins Git plugin GitHub plugin

Selenium server

Cucumber for java Jenkins plugin tests in java

Page 82: CQCON CQ Maven Methods

INTEGRATION TESTING FRAMEWORK... see Lydia's talk

Page 83: CQCON CQ Maven Methods

PRODUCTION

Page 84: CQCON CQ Maven Methods

How do we move to production in a world of maven builds and

deploys and git saves?

Page 85: CQCON CQ Maven Methods

YOU ARE HERE

Page 86: CQCON CQ Maven Methods

MAVEN PROFILE FOR PRODUCTIONAdd this to pom.xml:

Deploy using this profile:

Or one-time override: mvn -Dcrx.host=another.host,crx.port=4504 -PautoInstallPackage install

See also:

<profile> <id>auto-deploy-prod</id> <properties> <crx.host>production.server.hostname</crx.host> <crx.port>4502</crx.port> </properties></profile>

mvn -PautoInstallPackage,auto-deploy-prod install

Introduction to build profiles

Page 87: CQCON CQ Maven Methods

DEPLOYMENT TESTING... see Bertrand's talk

Page 88: CQCON CQ Maven Methods

PUTTING IT ALL TOGETHER

Page 89: CQCON CQ Maven Methods

0-60 IN 5 PSEUDO LINESmvn archetype:generate

git init; git add *; git commit -m "Initial project"

mvn -PautoInstallPackage install

vlt checkout ; vlt update ; vlt commit

git add; git commit; git push

Page 90: CQCON CQ Maven Methods
Page 91: CQCON CQ Maven Methods

THANK YOU. QUESTIONS?

Page 92: CQCON CQ Maven Methods

CREDITS designed by from The Noun Project

designed by from The Noun Project designed by from The Noun Project

designed by from The Noun Project designed by from The Noun Project designed by from The Noun Project

designed by from The Noun Project designed by from The Noun Project

designed by from The Noun Project designed by from The Noun Project

designed by from The Noun Project

Light Bulb Shane David KennaQuestion Anas RamadanHard Disk Drive Eddie AlshehriTime wayne25ukSync P.J. OnoriSync Rohith M SCloud Upload Adam WhitcroftPuzzle John O'SheaQuestion Henry RyderFactory Adrijan KaravdicCrash Test Dummy Luis Prado