Working with multiple XP projects

Posted by

Switching between XP projects can be tiresome with all the $XP_HOME updating and deploying to dev, prod, and QA. But using a good folder structure and some handy bash_profile aliases can make it quick and painless.

Most developers will find themselves working on multiple projects on the same local machine. You don't want to have all those apps cluttering up your XP installation and you don't want to have an entire XP installation for every app that you work on. Ideally you would have one XP installation for each XP version. You can copy the installations' "home" directories to multiple locations, one for each project. Then you set the $XP_HOME environment variable to the location of the project you want to run. A good folder structure looks like this:


It all starts with the "dev" folder, which has three important branches. The "software" folder has one copy of each version of Enonic XP. These are your $XP_INSTALL directories. 

Next is the "sourcecode" folder. This is where all the app project files are. 

Finally there is the "xp-homes" folder. Create a folder in "dev/xp-homes" for each project that you want to keep isolated from the others. Then copy the $XP_INSTALL/home folder into each of these.

You can even have multiple branches of a project for different versions of XP. For example, "xp-homes/superhero531" and "xp-homes/superhero600". Now when you want to start the XP-5.3.1 version of your superhero project, you simply set the $XP_HOME environment variable to "dev/xp-homes/superhero531/home" and then start the XP 5.3.1 installation with "dev/software/enonic/enonic-xp-5.3.1/bin/". 

This is a great way to keep projects isolated. But it's a lot of frequent typing in the command line to update $XP_HOME every time you want to deploy to a different location and/or start a different XP version. That's where the bash scripting comes in. As the Norwegians say, bash er god. Below is a portion of my .bash_profile:

# start XP 5.3.1
alias xpstart531='/Users/mla/dev/software/enonic/enonic-xp-5.3.1/bin/ clean'
# start XP 6.0.0
alias xpstart600='/Users/mla/dev/software/enonic/enonic-xp-6.0.0/bin/ clean'

# start the XP snapshot
alias xpstart='/Users/mla/dev/sourcecode/xp/modules/distro/target/install/bin/ clean'

# list the XP homes
alias xphomes='ls -l /Users/mla/dev/xp-homes'

# show the current XP_HOME
alias xpshowhome='echo $XP_HOME'

# show the current XP_HOME
alias xphome?='echo $XP_HOME'

# set the XP_HOME variable
xphome() { export XP_HOME=/Users/mla/dev/xp-homes/"$1"/home ; }

# Go to XP 5.3.1 toolbox
alias xptoolbox531='cd /Users/mla/dev/software/enonic/enonic-xp-5.3.1/toolbox'

# Go to XP 6.0.0 toolbox
alias xptoolbox600='cd /Users/mla/dev/software/enonic/enonic-xp-6.0.0/toolbox'

# Go to XP snapshot toolbox
alias xptoolbox='cd /Users/mla/dev/sourcecode/xp/modules/distro/target/install/toolbox'


The first few lines simply allow me to start a specific version of Enonic XP. I would simply type the alias for the version into the command line:

$ xpstart600

This would start XP version 6.0.0 in the terminal. Before starting the installation, make sure that $XP_HOME is set. 

To set $XP_HOME, enter "xphome <name>". For superhero, I would enter:

$ xphome superhero

Sometimes I can't remember the name of the xp-home folder that I want to use. For these situations, I created an alias that will list them for me. When I enter "xphomes" then I get the list:

$ xphomes
drwxr-xr-x  4 mla  staff  136 Sep  2 12:53
drwxr-xr-x  5 mla  staff  170 Jul  1 18:50 intranet
drwxr-xr-x  4 mla  staff  136 Aug 20 17:06 myApp
drwxr-xr-x  4 mla  staff  136 Sep  1 15:38 social
drwxr-xr-x  3 mla  staff  102 Jul 27 18:12 superhero
drwxr-xr-x  3 mla  staff  102 Aug 29 01:52 wireframe
drwxr-xr-x  3 mla  staff  102 Jul 21 11:44 xeon

To set the $XP_HOME environment variable to a particular project, I simply type "xphome <name>".

$ xphome superhero

If I ever forget which xp-homes folder is being used by a terminal window, I can check with "xphome?".

$ xphome?

Feel free to copy the scripts above and paste them into your own .bash_profile. Of course you will need to update the paths for your own machine. If you have a better setup, please leave a comment.