286N/A/*
286N/A * CDDL HEADER START
286N/A *
286N/A * The contents of this file are subject to the terms of the
286N/A * Common Development and Distribution License, Version 1.0 only
286N/A * (the "License"). You may not use this file except in compliance
286N/A * with the License.
286N/A *
286N/A * You can obtain a copy of the license at
286N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
286N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
286N/A * See the License for the specific language governing permissions
286N/A * and limitations under the License.
286N/A *
286N/A * When distributing Covered Code, include this CDDL HEADER in each
286N/A * file and include the License file at
286N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
286N/A * add the following below this CDDL HEADER, with the fields enclosed
286N/A * by brackets "[]" replaced with your own identifying information:
286N/A * Portions Copyright [yyyy] [name of copyright owner]
286N/A *
286N/A * CDDL HEADER END
286N/A *
286N/A *
286N/A * Copyright 2008 Sun Microsystems, Inc.
286N/A * Portions Copyright 2013 ForgeRock AS
286N/A */
286N/Apackage org.opends.build.tools;
286N/A
286N/Aimport java.text.DecimalFormat;
286N/A
286N/Aimport org.apache.tools.ant.Task;
286N/A
286N/A/**
286N/A * This class provides an implementation of an Ant task that may be used to
286N/A * construct the full version number string that the Directory Server should
286N/A * use. The value of the version number string will be stored in an Ant
286N/A * property.
286N/A */
286N/Apublic class CreateVersionString extends Task
286N/A{
286N/A // The name of the property in which the revision number should be set.
286N/A private String propertyName = null;
286N/A
286N/A /**
286N/A * Specifies the name of the Ant property into which the Subversion revision
286N/A * number will be stored.
286N/A *
286N/A * @param propertyName
286N/A * The name of the Ant property into which the Subversion revision
286N/A * number will be stored.
286N/A */
286N/A public void setProperty(String propertyName)
286N/A {
286N/A this.propertyName = propertyName;
286N/A }
286N/A
286N/A /**
286N/A * Performs the appropriate processing needed for this task. In this case, it
286N/A * uses SVNKit to identify the current revision number for the local workspace
286N/A * and store it in a specified property.
286N/A */
286N/A @Override()
286N/A public void execute()
286N/A {
286N/A StringBuilder versionString = new StringBuilder();
286N/A
286N/A versionString.append(getProject().getProperty("MAJOR_VERSION"));
286N/A versionString.append(".");
286N/A versionString.append(getProject().getProperty("MINOR_VERSION"));
286N/A versionString.append(".");
286N/A versionString.append(getProject().getProperty("POINT_VERSION"));
286N/A
286N/A // Sets the version string to the property used by packages.
286N/A getProject().setNewProperty("pkg_version_string", versionString.toString());
286N/A
286N/A String versionQualifier = getProject().getProperty("VERSION_QUALIFIER");
286N/A versionString.append(versionQualifier);
286N/A
286N/A // Removes all special chars contained in the version qualifier
286N/A // Sets the version qualifier to the property used by packages.
286N/A getProject().setNewProperty("pkg_version_qualifier",
286N/A versionQualifier.replaceAll("[^A-Za-z0-9]", ""));
286N/A
286N/A try
286N/A {
286N/A int buildNumber =
286N/A Integer.parseInt(getProject().getProperty("BUILD_NUMBER"));
286N/A if (buildNumber > 0)
286N/A {
286N/A versionString.append("-build");
286N/A versionString.append(new DecimalFormat("000").format(buildNumber));
286N/A }
286N/A }
286N/A catch (NumberFormatException nfe)
286N/A {
286N/A }
286N/A
286N/A getProject().setNewProperty(propertyName, versionString.toString());
286N/A }
286N/A}
286N/A