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