CQ Maven Methods

92
CQ MAVEN METHODS CQCON 2013

Transcript of CQ Maven Methods

Page 1: CQ Maven Methods

CQ MAVEN METHODSCQCON 2013

Page 2: CQ Maven Methods

HELLO WORLDI'm Andrew.

[email protected]

@savs

Page 3: CQ Maven Methods

Joined Adobe in November 2012

Page 4: CQ Maven Methods

CQ Newbie

JCR/CMS/TLA old hat

Page 5: CQ Maven Methods

Background in Open Source, Content Management, Mobile

Page 6: CQ Maven Methods

Talking today about what I learned so far...

Page 7: CQ Maven Methods

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

github.com/savs/CQCon_2013_CQ_Maven_Methods

Page 8: CQ Maven Methods

IN YOUR BROWSERhttp://goo.gl/qqS1F

Page 9: CQ Maven Methods

SEE ALSOhttp://www.planetcq.org/

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

LET'S BUILD A CQ SITE

... uh, where to begin?

Page 13: CQ Maven Methods

METHOD 1Enthusiastically rush in, use CRXDE Lite

Page 14: CQ Maven Methods

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

Page 15: CQ Maven Methods

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

Page 16: CQ Maven Methods

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

Page 17: CQ Maven Methods

METHOD 5

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

Page 18: CQ Maven Methods

BUT WHAT ABOUT ...reverting mistakes?

reproducible builds?

collaborating with others?

deploying to production?

Page 19: 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: CQ Maven Methods

CQ SUCKS

Page 21: CQ Maven Methods

$PRODUCT SUCKS

Page 22: CQ Maven Methods

YOUR METHODOLOGY SUCKS(sorry)

Page 23: CQ Maven Methods

SO HOW DO WE FIX THIS?Maven

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

Best Practices

Page 24: 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: 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: 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: 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: CQ Maven Methods

OUR TARGET

Page 29: CQ Maven Methods

Success criteria:

IT'S EASY TO BUILD A CQ SITE!

Page 30: 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: 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: 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: 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: CQ Maven Methods

USING MAVEN

Page 35: CQ Maven Methods

STARTING A NEW PROJECT ...

... can sometimes feel like reinventing the wheel.

Page 36: CQ Maven Methods

YOU ARE HERE

Page 37: 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: CQ Maven Methods

MAVEN ARCHETYPESA prototype upon which others are

copied, patterned, or emulated.

Page 39: 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: 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: 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: 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: 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: 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: CQ Maven Methods

SIMPLE CONTENT PACKAGE IN ACTION

Page 46: 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: CQ Maven Methods

SIMPLE CONTENT PACKAGE OUTPUTTemplate directoriespom.xml file

Instructions for compiling, creating bundles, deployingto CQ in packages

FileVault configuration files

Page 48: 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: 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: CQ Maven Methods

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

Page 51: 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: 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: 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: 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: CQ Maven Methods

USING GIT

Page 56: CQ Maven Methods

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

Page 57: CQ Maven Methods

YOU ARE HERE

Page 58: CQ Maven Methods

GIT PROJECT SETUPcd projectnamegit init

Page 59: CQ Maven Methods

GIT IGNOREEdit .gitignore, for example:

.classpath

.project

.vlt/

.settings/target/

Page 60: CQ Maven Methods

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

Page 61: 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: CQ Maven Methods

DEMO

Page 63: CQ Maven Methods

... TIME PASSES ...

Page 64: CQ Maven Methods

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

Page 65: CQ Maven Methods

(BEST) PRACTICE(S)

Page 66: CQ Maven Methods

YOU ARE HERE

Page 67: CQ Maven Methods

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

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

BUILDING

Page 70: 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: CQ Maven Methods

DEPLOYING

Page 72: CQ Maven Methods

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

cqblueprints: mvn -Pauto-deploy install

Page 73: CQ Maven Methods

DEMO

Page 74: CQ Maven Methods

DEVELOPING

Page 75: CQ Maven Methods

YOU ARE HERE

Page 76: CQ Maven Methods

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

and git saves?

Page 77: 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: 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: CQ Maven Methods

DEMO

Page 80: CQ Maven Methods

TESTING

Page 81: 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: CQ Maven Methods

INTEGRATION TESTING FRAMEWORK... see Lydia's talk

Page 83: CQ Maven Methods

PRODUCTION

Page 84: CQ Maven Methods

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

deploys and git saves?

Page 85: CQ Maven Methods

YOU ARE HERE

Page 86: 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: CQ Maven Methods

DEPLOYMENT TESTING... see Bertrand's talk

Page 88: CQ Maven Methods

PUTTING IT ALL TOGETHER

Page 89: 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: CQ Maven Methods
Page 91: CQ Maven Methods

THANK YOU. QUESTIONS?

Page 92: 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