[Index]

properties


Creates properties that can used to configure other jobs.

There are four ways to set properties:

  1. As Property name/value Pairs in the values property of this job.
  2. By defining the environment attribute to be the prefix to which all environment variables will be appended as properties.
  3. By using the sets property to provide a number of addition property sets which are likely to be a reference to properties defined elsewhere.
  4. By defining the Input property to be a File/Resource or some other type of input.
Combinations are possible and the order of evaluation is as above. Oddjob will do it's usual property substitution using previously defined property values if required.

If the substitute property is true, property values will be evaluated for substitution.

The Properties job and properties type are very similar, the difference between them is that the job defines properties for Oddjob and the type provides properties for configuring a single job (which could be the sets property of the property job).


Property Summary

environment The prefix for environment variables.
extract Extract this prefix form property names.
fromXML If the input for the properties is in XML format.
input An input source for Properties.
name A name, can be any text.
override Properties of this job will override any previously set.
prefix Append this prefix to property names.
properties Provide all the merged properties defined by this job.
sets Extra properties to be merged into the overall property set.
stop This flag is set by the stop method and should be examined by any Stoppable jobs in their processing loops.
substitute Use substitution for the values of ${} type properties.
system Set to true to set System properties rather than Oddjob properties.
values Properties defined as key value pairs.

Example Summary

Example 1 Defining and using a property.
Example 2 Defining a property using substitution.
Example 3 Loading properties from a class path resource.
Example 4 Overriding Properties.
Example 5 Capturing Environment Variables.

Property Detail

environment

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

The prefix for environment variables.

extract

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

Extract this prefix form property names. Filters out properties that do not begin with this prefix.

fromXML

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo, default to false.

If the input for the properties is in XML format.

input

Configured ByELEMENT
AccessWRITE_ONLY
RequiredNo.

An input source for Properties.

name

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

A name, can be any text.

override

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo. Default is false.

Properties of this job will override any previously set.

prefix

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

Append this prefix to property names.

properties

AccessREAD_ONLY
RequiredRead Only.

Provide all the merged properties defined by this job.

sets

Configured ByELEMENT
AccessREAD_WRITE
RequiredNo.

Extra properties to be merged into the overall property set.

stop

AccessREAD_ONLY
RequiredRead Only.

This flag is set by the stop method and should be examined by any Stoppable jobs in their processing loops.

substitute

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

Use substitution for the values of ${} type properties.

system

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo. Defaults to false

Set to true to set System properties rather than Oddjob properties.

values

Configured ByELEMENT
AccessWRITE_ONLY
RequiredNo.

Properties defined as key value pairs.


Examples

Example 1

Defining and using a property. Note the escape syntax for property expansion.

<oddjob>
  <job>
   <sequential>
    <jobs>
     <properties>
      <values>
       <value key="fruit.favourite" value="apple"/>
       <value key="snack.favourite" value="${fruit.favourite}"/>
      </values>
     </properties>
     <echo id="echo">$${snack.favourite} is ${snack.favourite}</echo>
    </jobs>
   </sequential>
  </job>
 </oddjob>

Example 2

Defining a property using substitution. This is the same example as previously but it is the properties job doing the substitution not the Oddjob framework. The value of snack.favourite is escaped because we want ${fruit.favourite} passed into the properties job. If the property was defined in a file it would not need to be escaped like this.

<oddjob>
    <job>
        <sequential>
            <jobs>
                <properties substitute="true">
                    <values>
                        <value key="fruit.favourite" value="apple"/>
                        <value key="snack.favourite" value="$${fruit.favourite}"/>
                    </values>
                </properties>
                <echo id="echo">$${snack.favourite} is ${snack.favourite}</echo>
            </jobs>
        </sequential>
    </job>
</oddjob>

Example 3

Loading properties from a class path resource.

<oddjob>
    <job>
        <sequential>
            <jobs>
                <properties>
                    <input>
                        <resource resource="org/oddjob/values/properties/PropertiesJobTest1.properties"/>
                    </input>
                </properties>
                <echo id="echo">${someones.name}</echo>
            </jobs>
        </sequential>
    </job>
</oddjob>
The properties file contains:
# properties for test

someones.name = John Smith
someones.name.title = Mr.
someones.address = London
 
This will display
 John Smith
 

Example 4

Overriding Properties. Normally setting a property is first come first set. Using the override property on the properties job makes the properties defined in that job take priority.

<oddjob>
  <job>
   <sequential>
    <jobs>
     <properties>
      <values>
       <value key="fruit.favourite" value="apple"/>
      </values>
     </properties>
     <echo id="echo1">$${fruit.favourite} is ${fruit.favourite}</echo>
     <properties>
      <values>
       <value key="fruit.favourite" value="pear"/>
      </values>
     </properties>
     <echo id="echo2">$${fruit.favourite} is ${fruit.favourite}</echo>
     <properties override="true">
      <values>
       <value key="fruit.favourite" value="banana"/>
      </values>
     </properties>
     <echo id="echo3">$${fruit.favourite} is ${fruit.favourite}</echo>
    </jobs>
   </sequential>
  </job>
 </oddjob>
This will display
 ${fuit.favourite} is apple
 ${fuit.favourite} is apple
 ${fuit.favourite} is banana
 

Example 5

Capturing Environment Variables. Note that the case sensitivity of environment variables is Operating System dependent. On Windows ${env.Path} and ${env.path} would also yield the same result. On Unix (generally) only ${env.PATH} will work.

<oddjob>
  <job>
    <sequential>
      <jobs>
        <properties id="props" environment="env"/>
        <echo id="echo-path">Path is ${env.PATH}</echo>
      </jobs>
    </sequential>
  </job>
</oddjob>


(c) Rob Gordon 2005 - 2017