Skip to content

Batch File Usage

Beat Strasser edited this page Aug 29, 2016 · 23 revisions

The Version Tiger batch files use an easy command language to automate large versioning tasks. It is a plain text format and the files contain one operation per line. Technically, the extension of the batch files is irrelevant, but if you want them to be recognized by the Eclipse plugin, you need to set the extension as .versiontiger.

This is a small example:

# sample.versiontiger

# Add projects to universe
project /home/me/workspace/com.inventage.project.plugin
project /home/me/workspace/com.inventage.project.depending_plugin1
project /home/me/workspace/com.inventage.project.depending_plugin2
projectRoot /home/me/workspace/depending_projects

# Release plugin, dependencies get updated automatically
release com.inventage.project.plugin

As you can observe, we use the hash ('#') as comment prefix. In the example above three projects are added to the (implicit) universe while we assume that 'depending_plugin1' and 'depending_plugin2' have dependencies on the 'plugin'. Also all projects inside 'workspace/depending_projects' are added to the universe. We then release the 'plugin' by calling the respective command, followed by the artifact id. Since we added the depending projects to the universe, all references to the 'plugin' get updated as well.

Available Commands

This is a presentation of the available commands. They can be used in batch files as well as in the interactive mode. You can also get a list of them by typing help in the interactive mode.

ensureRelease <my.artifact.id-pattern>

Makes sure that all the projects matching the given pattern (regular expressions, e.g. .*) have a release version. Stops execution else.

Example

project /home/me/workspace/com.inventage.project.plugin
ensureRelease com.inventage..*

ensureSnapshot <my.artifact.id-pattern>

Makes sure that all the projects matching the given pattern (regular expressions, e.g. .*) have a snapshot version. Stops execution else.

Example

project /home/me/workspace/com.inventage.project.plugin
ensureSnapshot com.inventage.project.plugin

ensureStrictOsgiDependencyTo <project-id>

Makes sure that all dependent projects to the given project define strict OSGi dependencies, e.g.: [1.2.0;1.2.1) . Stops execution else.

Example

projectRoot /home/me/workspace
ensureStrictOsgiDependencyTo com.inventage.project.model

ensureVersion <version>

Makes sure that the versiontiger version itself has at least the given version. If the versiontiger is too old, it will stop execution.

Example

ensureVersion 1.3.1

help

Shows the usage of all available commands.


include <path>

Includes the batch file found at the provided path and executes it in the context of the current batch file.

Example

Contents of release.versiontiger:

project /home/me/workspace/com.inventage.project.plugin

Contents of another file:

include /home/me/workspace/tools/release.versiontiger
snapshot com.inventage.project.plugin

incrementBugfix <artifact id pattern>

Updates the version in the projects matching the provided id pattern (regular expressions, e.g. .*) to the next bugfix snapshot (e.g. 1.2.1 to 1.2.2-SNAPSHOT). Also updates all dependencies in the universe.

Example

project /home/me/workspace/com.inventage.project.plugin
incrementBugfix com.inventage.project.plugin

incrementMajor <artifact id pattern>

Updates the version in the projects matching the provided id pattern (regular expressions, e.g. .*) to the next major snapshot (e.g. 1.2.0 to 2.0.0-SNAPSHOT). Also updates all dependencies in the universe.

Example

project /home/me/workspace/com.inventage.project.plugin
incrementMajor com.inventage.project.plugin

incrementMinor <artifact id pattern>

Updates the version in the projects matching the provided id pattern (regular expressions, e.g. .*) to the next minor snapshot (e.g. 1.2.1 to 1.3.0-SNAPSHOT). Also updates all dependencies in the universe.

Example

project /home/me/workspace/com.inventage.project.plugin
incrementMinor com.inventage.project.plugin

ignoreProject <artifact id>

Removes a project from the universe.

Example

ignoreProject com.inventage.project.plugin1

ignorePath <path>

Removes all projects located somewhere inside the given path.

Example

ignorePath /home/me/workspace/projects/obsoleteprojects

list

Lists all projects in the universe.


project <path>

Adds the project at the provided file system path to the ad hoc universe. Every instance of the Version Tiger forms its own universe.

Example

project /home/me/workspace/com.inventage.project.plugin

projectRoot <path>

Looks recursively for Maven projects inside the given file system path and adds each of them to the universe.

Example

projectRoot /home/me/workspace/projects

property <artifact id> <key> <value>

Updates or appends a property into the POM file of the given project.

Examples

project /home/me/workspace/com.inventage.project.plugin
property com.inventage.project.plugin myProperty myContent

The (simplified) POM file of the artifact has the following contents afterwards:

<project>
    <artifactId>com.inventage.project.plugin</artifactId>
    <version>1.2.3-SNAPSHOT</version>
    <properties>
        <myProperty>myContent</myProperty>
    </properties>
</project>

release <artifact id pattern>

Updates the version in the projects matching the provided id pattern (regular expressions, e.g. .*) to the release version (e.g. 1.2.0-SNAPSHOT to 1.2.0). Also updates all dependencies in the universe.

Example

project /home/me/workspace/com.inventage.project.plugin
release com.inventage.project.plugin

releaseWithSuffix <my.artifact.id-pattern> <suffix>

Updates the version in the projects matching the provided id pattern (regular expressions, e.g. .*) to the release version but sets the suffix to the given one. If the suffix argument is prefixed with a dash, the suffix will be separated by a dash not a dot.

If you use this command on OSGi artifacts, you might consider the setting suffixToQualifier osgi.version.mapping which will map the maven suffix to the OSGi qualifier.

Example

project /home/me/workspace/com.inventage.project.plugin
setting osgi.version.mapping suffixToQualifier
releaseWithSuffix com.inventage.project.plugin 20160825-1045

setting <key> <value>

Allows to globally set certain version tiger settings. We currently support the following configuration items:

  • dependency.range.change: Defines the strategy how a dependency version range is updated. By default, this is 'adaptive'.
    • adaptive: Detects if the range currently allows major, minor or bugfix changes and adapts the range accordingly.
    • bugfix: Sets the upper bound to the next bugfix version (exclusive) and sets the lower bound to the new version (inclusive).
    • major: Sets the upper bound to the next major version (exclusive) and sets the lower bound to the new version (inclusive).
    • minor: Sets the upper bound to the next minor version (exclusive) and sets the lower bound to the new version (inclusive).
    • nochange: Does not change the version range.
    • strict: Sets the lower and upper bound to the new version (inclusive qualifiers).
    • uppertobugfix: Sets the upper bound to the next bugfix version (exclusive) and leaves the lower bound as it is.
    • uppertomajor: Sets the upper bound to the next major version (exclusive) and leaves the lower bound as it is.
    • uppertominor: Sets the upper bound to the next minor version (exclusive) and leaves the lower bound as it is.
  • osgi.release.qualifier: Defines the qualifier which is used on OSGI release versions. By default, this is the empty string.
  • osgi.snapshot.qualifier: Defines the qualifier which is used on OSGI snapshot versions. By default, this is 'qualifier'.
  • osgi.version.mapping: Defines the strategy how maven versions are mapped to OSGI versions.
    • qualifierForSnapshotDistinction (default): Looses the maven suffix and uses the OSGi qualifier to distinguish snapshots and releases.
    • suffixToQualifier: Uses the suffix from Maven as qualifier.

Example

setting dependency.range.change minor
setting osgi.release.qualifier RELEASE
project /home/me/workspace/com.inventage.project.plugin
release com.inventage.project.plugin

snapshot <artifact id pattern>

Updates the version in the projects matching the provided id pattern (regular expressions, e.g. .*) to the snapshot version (e.g. 1.2.0 to 1.2.0-SNAPSHOT). Also updates all dependencies in the universe.

Example

project /home/me/workspace/com.inventage.project.plugin
snapshot com.inventage.project.plugin

updateReferences <artifact id pattern> <version>

Searches in the universe for occurrences of the stated project (or, projects if there are more than one matches). Their reference versions are updated to the provided version. The project itself doesn't need to be defined in the universe. This is useful to update the references to a third party artifact.

Example

project /home/me/workspace/com.inventage.project.depending_plugin1
project /home/me/workspace/com.inventage.project.depending_plugin2
updateReferences com.inventage.project.plugin 1.2.3

version <artifact id pattern> <version>

Updates the version in the projects matching the provided id pattern (regular expressions: e.g. .*) to the provided one. Also updates all dependencies in the universe. The version has to be in Maven format.

Example

project /home/me/workspace/com.inventage.project.plugin1
project /home/me/workspace/com.inventage.project.plugin2
version com.inventage.project..* 1.2.3-SNAPSHOT

Defined Variables

In any command argument, you may use variables. The following variables are supported:

  • ${version:my.project.id} - The version of a project in the Maven format.
  • ${osgiVersion:my.project.id} - The version of a project in the OSGI format.
  • ${property:my.project.id:key} - The property value for the given key in the given project.
  • ${any.environment.key} - The value for the given environment variable name.

Example

project /home/me/workspace/my.project
project /home/me/workspace/other.project
version my.project ${version:other.project}-${property:my.project:mySuffix}-${REVISION}

Overall sample

The following sample uses a project scenario which needs to release and snapshot from time to time. The respective commands are placed in two distinct .versiontiger files which can be called on demand.

Contents of the file projects.versiontiger:

# Universe definition
projectRoot ../
ignoreProject test.plugin
project ../library/my.plugin1
project ../library/my.plugin2
# ...

Contents of the file release.versiontiger:

# Including the universe
include projects.versiontiger

# Releasing all artifacts
release my.plugin.*
release my.feature
release assembly
property assembly feature-version ${version:my.feature}
# ...

Contents of the file snapshot.versiontiger:

# Including the universe
include projects.versiontiger

# Snapshotting all artifacts
incrementBugfix my.plugin.*
incrementMajor my.feature
incrementBugfix assembly
property assembly feature-version ${version:my.feature}
# ...

To switch to release versions, you now can call the following command from a project directory:

$ java -jar com.inventage.tools.versiontiger-cli.jar release.versiontiger

Analogous, call the following for preparing the project for the next snapshot build:

$ java -jar com.inventage.tools.versiontiger-cli.jar snapshot.versiontiger