Example 1 - Build Environment
Overview
This example shows how a developer can use BundleWorks to manage a build environment containing multiple versions of Java™ and a set of Java tools. In this example, there are BundleWorks bundles for two different versions of Java (1.5.0_13 and 1.6.0_03) and bundles for the latest vesions of the Ant and JUnit tools.
In this example, these bundles will be deployed into two environments: build and experimental. The 'build' environment will contain Java 1.5_0_13, Ant, and JUnit. The 'experimental' environment will contain Java 1.6.0_03, Ant, and JUnit.
The BundleWorks 'use' command targets the appropriate environment. For example, use build will load the tools inside the 'build' environment, while use experimental will load the versions inside the 'experimental' environment, replacing any previously loaded versions.
Bundles
- Java 1.5.0_13 - Java5 development kit
- Java 1.6.0_03 - Java6 development kit
- Ant 1.7.0 - Build tool for Java
- JUnit 4.4 - Unit testing tool for Java
Environments
- build - contains Java 1.5.0_13, Ant 1.7.0, and JUnit 4.4
- experimental - contains Java 1.6.0_03, Ant 1.7.0, and JUnit 4.4
Details
/opt/bundles [1]
jdk/
1.5.0_13/ [2]
bundle/ [3]
actions/
load.sh [4]
unload.sh [5]
info
1.6.0_03/
bundle/
actions/
load.sh
unload.sh
info
ant/
1.7.0/
bundle/
actions/ [6]
load.sh
unload.sh
info
shared/ [7]
bin/, docs/, ...
junit/
4.4/ [8]
bundle/
actions/
load.sh
unload.sh
info
shared/
doc/, javadoc/, junit-4.4.jar, ...
/var/env/ [9]
build/ [10]
env/ [11]
info
uses/ [12]
ant
jdk [13]
junit
experimental/ [14]
env/
info
uses/
ant
jdk [15]
junit
- The recommended location for storing bundles (on UNIX/Linux based systems) is /opt/bundles. Each bundle is stored inside directories containing the bundle name and bundle version. This allows multiple versions of a bundle to co-exist.
- This is an example of a bundle that references files outside the bundle. In this case, the jdk/1.5.0_13 points to the JDK installation inside /usr/java/jdk1.5.0_13. BundleWorks provides a jdk bundler for creating bundles from an existing JDK installation.
- All bundles contain a bundle directory. This directory contains an actions directory with one or more bundle scripts and an info file providing information about the bundle. This directory can also contain other bundle files like documentation and configuration templates.
- The load.sh script (load.bat under Windows) is called in response to the BundleWorks use command. This script typically sets environment variables using built-in BundleWorks functions like env_set and env_prepend_path. In the case of the jdk bundle, two environment variables are changed by the load script: JAVA_HOME and PATH.
- The unload.sh script (unload.bat under Windows) is called in response to the BundleWorks use command when a different version of the bundle needs to be loaded. BundleWorks first unloads the previous version, then loads the new version. In the case of the jdk bundle, the unoad script reverses the changes made to JAVA_HOME and PATH. This allows for switching between multiple versions of the jdk.
- The load and unload scripts for the ant bundle are similar to the ones for the jdk bundle. These scripts change the ANT_HOME and PATH environment variables. Unlike the scripts in the jdk bundle, the ant load and unload scripts refer to directories inside the bundle.
- The ant bundle has a shared directory which contains the entire ant distribution as supplied by Apache. The shared directory is the BundleWorks standard location for storing items that are not platform-specific.
- The junit bundle is similar to the ant bundle in a number of respects. It has a shared directory with the entire junit distribution. It has load and unload scripts which change several environment variables. In this case, the scripts impact the ANT_ARGS and CLASSPATH environment variables allowing junit to be used by ant or by java itself.
- In this example, the /var/env directory is used to contain all environments. Environments will typically contain runtime files from the bundles deployed to that environment (though not in this example, where none of the bundles have runtime files). On UNIX/Linux based systems, the /var directory is generally used for runtime files.
- This is the 'build' environment, which is simply a set of directories and files in a standard layout. Environments are created using the BundleWorks envcreate command. Bundles are deployed into an environment using the BundleWorks deploy command.
- All environments have an env directory, which contains an info file that holds information about the environment.
- All environments have a uses directory. This directory is used to store references to bundles that do not have runtime files. Bundles that do not have runtime files are called loadable bundles. In this example, all bundles (jdk, ant, and junit) are loadable. If a bundle has runtime files (e.g. logs, configuration) is called a runnable. The other examples includes runnable bundles.
- In the 'build' environment, the 'jdk' reference points to /opt/bundle/jdk/1.5.0_13. When the 'build' environment is loaded with the 'use' command, BundleWorks will call the load script within the bundle at /opt/bundle/jdk/1.5.0_13.
- This is the 'experimental' environment, created with the envcreate. This environment is identical to the 'build' environment, except for the version of java deployed into it.
- In the 'experimental' environment, the 'jdk' reference points to /opt/bundle/jdk/1.6.0_03. When the 'experimental' environment is loaded with the 'use' command, BundleWorks will call the load script within the bundle at /opt/bundle/jdk/1.6.0_03. If the 'build' environment was previously loaded, the unload script within /opt/bundle/jdk/1.5.0_13 will be called first.