Broadcast on Broadcast off
The Documentation for Project Zero has moved. Please update your bookmarks to: http://www.projectzero.org/documentation/
Table of
Contents...
Hide

Project Zero Developer’s Guide

Concepts and components
Basic concepts overview
Event processing
Writing Java handlers
Writing Groovy handlers
Firing events
Global Context
Global Context reference
Application directory layout
Virtualized directories
Assemble
PHP
Features and configuration
Configuration
Debugging
Dependencies
Packaging
Application classpath
Logging and tracing
RESTful resources
RESTful documentation
File serving
Response rendering
Validators and validation
HTTP error handling
Calling a remote resource
Using the Connection API
Sending an email using EmailConnection
Configuring destinations
Configuring protocols
Configuring connection handlers
Creating a connection handler
Creating a custom protocol transport
Simple logging connection handlers
Protocol reference
Client programming with Dojo
Runtime options
Deployment modifications
HTTP configuration
SSL configuration
Proxy configuration
Extending the CLI
Security considerations
Authentication
OpenID authentication
Extending security
Security tokens
CSRF prevention support
Extending token support
Leveraging TAI
User service
File based user service
LDAP user service
Extending user service
Security Utilities
Leveraging XOREncoder
Extensions
Atom support
RSS support
JSON support
XMLEncoder
REST to SOAP extension
URIUtils
Developer Web tools
Database setup tools
Configuring data access
Common query patterns
Advanced query patterns
Update patterns
Local database transactions
Extending data access
Configuration vendor differences
PHP data access
Resource model
Configuring ZRM
Resource model declaration
Programmatic model API
HTTP REST API
A ZRM mini tutorial
Active content filtering support
Default filters
Custom filters
Runtime management
Management commands
Zero socket opener
Other extension modules
Amazon E-commerce service
Flickr service
WeatherZero forecast service
Wikipedia service
Reference
Zero command line interface
JavaDoc - Public API
JavaDoc - Public SPI
JavaDoc - All Classes

 

Adding commands to the Zero Command Line Interface

The Zero command-line interface is implemented as a collection of Apache Ant targets and tasks. This page describes how to add your own custom commands to the Zero CLI by defining Ant tasks and targets. If you are not familiar with Ant, you should start by reading the Ant manual.

Defining a command

The Zero CLI is implemented as a set of Ant targets, e.g. resolve, run. These targets call a set of custom Zero tasks, e.g. zeroresolve, zerorun. Each command directly maps to a single target. The targets which define the base Zero commands can be found in <zerohome>/ant/zero.xml. (After the CLI has been resolved, zero.xml is found in zero.tools/ant/zero.xml in the repository.)

There are two ways to define a command depending on its intent.

Defining a command for your application only

To add a command for your application you can simply define a target in the build.xml. The commands defined in the build.xml of your application will be available whenever your module is run as a application. By default, the build.xml for every application imports zero.xml. This means that all of the targets and tasks from this file are available to you in build.xml. You may want to reuse or override the commands included in zero.xml. For example, you may want to define your own run target to override the run target defined in zero.xml. Then, whenever the user types zero run it will execute your custom target. For example, you may want to start a database whenever your application is started. To do this you would define you own run target in build.xml that starts the database and then calls the imported zero run target as follows:

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="build" name="myapp">
<import file="${ant.home}/ant/zero.xml"/>
<target name="run" depends="startdb">		
<antcall target="zero.run"/>
</target>

<target name="startdb">
<echo message="starting the database"/>
<!-- DB start code goes here -->
</target>    
</project>

Defining a command to be reused by other applications

You can also define commands that can be used by any application that depends on your library. So, whenever an application adds a dependency on your library, the command will be available. To do this you also add an ant target, but you should add it to a file called zeroCommand.xml under the root of your application. The context in which your command extensions run may be slightly different than it would be for a top-level application. It is advised that your target names be unique enough not to collide with targets provided by the base CLI or other CLI extensions. One way to reduce the chance of collision is to prefix your commands with a namespace like ., e.g. mylib.startdb.

Predefined properties

You can assume the following properties will be defined before your commands are invoked:

Property Name Value
basedir root path of application
ant.home Path to root of Zero CLI. Will be zero.tools in the repository, if found; otherwise set to zerohome, which is the root of the Zero installation.

Accessing files within your package.

Files within your package can be accessed by setting a property to the value of the directory where your package is located, using the Ant dirname task. Remember, it is possible that your package could be in several locations, such as the repository, the same eclipse workspace, or even remote. Since any application could include your package as a dependency, and you want all of those applications to be able to use your extended commands, never assume the location of your package.

The following will set a property to be the top level directory containing the above extension:

<dirname file="${ant.file.myconfigchecker.commands}" property="myconfigchecker.commands.dir" />

Defining Custom Tasks

If the Core Ant tasks do not provide all of the function you need to accomplish your command extension, you can write a new task which provided the missing function. Write your task using the Ant APIs for extending the tasks, then include your task in the java directory of your project like any other class. The .zeroresolved.properties file of the application will always include a classpath, which you can then use for loading this new task.

The following example shows a zeroCommand.xml file which creates a custom Ant task which can check the configuration of a server:

<project name="myconfigchecker.commands">
<target name="${ant.project.name}.init">
<dirname file="${ant.file.myconfigchecker.commands}" property="myconfigchecker.commands.dir" />
<property file="${basedir}/.zeroresolved.properties"/>

<taskdef name="mycustomtask" classname="my.custom.Task" 
classpath="${classpath.cli}" />
</target>

<target name="checkserverconfiguration" depends="${ant.project.name}.init">
<mycustomtask/>  <!-- This is the custom written task that does the work -->
</target>
</project>

Referencing dependencies

The .zeroresolved.properties file in the root of the application provides information about the resolved application as seen in the example below:

#Resolved Info
#Mon Dec 10 13:20:29 EST 2007
zero.docs=C\:/Documents and Settings/Administrator/zero/expanded/zero.docs-1.0.6990.M3
zero.native.support=C\:/Documents and Settings/Administrator/zero/expanded/zero.native.support-1.0.8568.M3
classpath=C\:/Documents and Settings/Administrator/zero/expanded/zero.core.webtools-1.0.8725.M3/lib/zero.core.webtools-1.0.8725.M3.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.docs-1.0.6990.M3/lib/zero.docs-1.0.6990.M3.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.data.setup-1.0.8502.M3/lib/zero.data.setup-1.0.8502.M3.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.core-1.0.8730.M3/lib/zero.core-1.0.8730.M3.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.core-1.0.8730.M3/lib/antlr-2.7.6.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.core-1.0.8730.M3/lib/asm-2.2.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.core-1.0.8730.M3/lib/groovy-1.1-beta-2.jar;C\:/Documents and Settings/Administrator/zero/repository/org.apache.ant/ant/jars/ant-1.7.0.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.network-1.0.8319.M3/lib/zero.network-1.0.8319.M3.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.management.native.process-1.0.8595.M3/lib/zero.management.native.process-1.0.8595.M3.jar;C\:/Documents and Settings/Administrator/zero/repository/org.apache.ant/ant-launcher/jars/ant-launcher-1.7.0.jar;C\:/Documents and Settings/Administrator/zero/repository/xerces/xercesImpl/jars/xercesImpl-2.8.1.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.network.support-1.0.8319.M3/lib/zero.network.support-1.0.8319.M3.jar;C\:/Documents and Settings/Administrator/zero/repository/xml-apis/xml-apis/jars/xml-apis-1.3.03.jar
zero.data.setup=C\:/Documents and Settings/Administrator/zero/expanded/zero.data.setup-1.0.8502.M3
dojo=C\:/Documents and Settings/Administrator/zero/expanded/dojo-1.0.1
natives=C\:/Documents and Settings/Administrator/zero/expanded/zero.management.native.process-1.0.8595.M3/lib/x86/Windows
classpath.cli=C\:/javazero/t4/classes;C\:/Documents and Settings/Administrator/zero/expanded/zero.core.webtools-1.0.8725.M3/lib/zero.core.webtools-1.0.8725.M3.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.docs-1.0.6990.M3/lib/zero.docs-1.0.6990.M3.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.data.setup-1.0.8502.M3/lib/zero.data.setup-1.0.8502.M3.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.core-1.0.8730.M3/lib/zero.core-1.0.8730.M3.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.core-1.0.8730.M3/lib/antlr-2.7.6.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.core-1.0.8730.M3/lib/asm-2.2.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.core-1.0.8730.M3/lib/groovy-1.1-beta-2.jar;C\:/Documents and Settings/Administrator/zero/repository/org.apache.ant/ant/jars/ant-1.7.0.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.network-1.0.8319.M3/lib/zero.network-1.0.8319.M3.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.management.native.process-1.0.8595.M3/lib/zero.management.native.process-1.0.8595.M3.jar;C\:/Documents and Settings/Administrator/zero/repository/org.apache.ant/ant-launcher/jars/ant-launcher-1.7.0.jar;C\:/Documents and Settings/Administrator/zero/repository/xerces/xercesImpl/jars/xercesImpl-2.8.1.jar;C\:/Documents and Settings/Administrator/zero/expanded/zero.network.support-1.0.8319.M3/lib/zero.network.support-1.0.8319.M3.jar;C\:/Documents and Settings/Administrator/zero/repository/xml-apis/xml-apis/jars/xml-apis-1.3.03.jar
zero.network=C\:/Documents and Settings/Administrator/zero/expanded/zero.network-1.0.8319.M3
zero.network.support=C\:/Documents and Settings/Administrator/zero/expanded/zero.network.support-1.0.8319.M3
dependencies=t4,zero.webtools,zero.core.webtools,zero.docs.webtools,zero.data.setup.webtools,dojo,zero.docs,zero.data.setup,zero.core,ant,zero.network,zero.management.native.process,ant-launcher,xercesImpl,zero.network.support,zero.native.support,xml-apis
zero.core=C\:/Documents and Settings/Administrator/zero/expanded/zero.core-1.0.8730.M3
zero.data.setup.webtools=C\:/Documents and Settings/Administrator/zero/expanded/zero.data.setup.webtools-1.0.8508.M3
zero.core.webtools=C\:/Documents and Settings/Administrator/zero/expanded/zero.core.webtools-1.0.8725.M3
zero.docs.webtools=C\:/Documents and Settings/Administrator/zero/expanded/zero.docs.webtools-1.0.8182.M3
zero.management.native.process=C\:/Documents and Settings/Administrator/zero/expanded/zero.management.native.process-1.0.8595.M3
zerohome=C\:/javazero/.metadata/.plugins/zero.eclipse.core/zerohome
zero.webtools=C\:/Documents and Settings/Administrator/zero/expanded/zero.webtools-1.0.6176.M3

If you load this file using the property task with the file attribute, you will have the following properties available to you:

Property Name Property Value
dependencies a comma-separated list of dependencies (by module name) that were resolved
classpath.cli fully qualified classpath or application
natives paths to any natives that were resolved (separated by OS-specific delimiter)
<module-name> for each resolved dependency there is a key that matches the module name with a value equal to the root path to the root of that dependency

r8 - 08 Feb 2008 - 15:04:18 - danjemiolo
Syndicate this site RSS ATOM
Copyright 2007 © IBM Corporation | Privacy | Terms of Use | About this site