4274N/A/*
4274N/A * CDDL HEADER START
4274N/A *
4274N/A * The contents of this file are subject to the terms of the
4274N/A * Common Development and Distribution License, Version 1.0 only
4274N/A * (the "License"). You may not use this file except in compliance
4274N/A * with the License.
4274N/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.
4274N/A * See the License for the specific language governing permissions
4274N/A * and limitations under the License.
4274N/A *
4274N/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:
4274N/A * Portions Copyright [yyyy] [name of copyright owner]
4274N/A *
4274N/A * CDDL HEADER END
4274N/A *
4274N/A *
4274N/A * Copyright 2009 Sun Microsystems, Inc.
4274N/A */
4274N/Apackage org.opends.build.tools;
4274N/A
4274N/A
4274N/A
4274N/Aimport java.io.File;
4274N/A
4274N/Aimport org.apache.tools.ant.BuildException;
4274N/Aimport org.apache.tools.ant.Task;
4274N/A
4274N/Aimport org.tmatesoft.svn.core.SVNException;
4274N/Aimport org.tmatesoft.svn.core.wc.SVNClientManager;
4274N/Aimport org.tmatesoft.svn.core.wc.SVNInfo;
4274N/Aimport org.tmatesoft.svn.core.wc.SVNRevision;
4274N/Aimport org.tmatesoft.svn.core.SVNURL;
4274N/A
4274N/A
4274N/A
4274N/A/**
4274N/A * This class provides an implementation of an Ant task that may be used to
4274N/A * determine the current Subversion revision number of the current working
4274N/A * copy. The value of the revision number will be stored in an Ant property.
4274N/A */
4274N/Apublic class GetSubversionUrlRepo
4274N/A extends Task
4274N/A{
4274N/A // The name of the property in which the revision number should be set.
4274N/A private String propertyName = null;
4274N/A
4274N/A // The path to the root of the Subversion workspace for which to retrieve the
4274N/A // revision number.
4274N/A private String workspace = null;
4274N/A
4274N/A // The svn client manager. Required by svnkit 1.2.x
4274N/A private static SVNClientManager ourClientManager =
4274N/A SVNClientManager.newInstance();
4274N/A
4274N/A /**
4274N/A * Specifies the name of the Ant property into which the Subversion revision
4274N/A * number will be stored.
4274N/A *
4274N/A * @param propertyName The name of the Ant property into which the
4274N/A * Subversion revision number will be stored.
4274N/A */
4274N/A public void setProperty(String propertyName)
4274N/A {
4274N/A this.propertyName = propertyName;
4274N/A }
4274N/A
4274N/A
4274N/A
4274N/A /**
4274N/A * Specifies the path to the root of the Subversion workspace for which to
4274N/A * retrieve the revision number.
4274N/A *
4274N/A * @param workspace The path to the root of the Subversion workspace for
4274N/A * which to retrieve the revision number.
4274N/A */
4274N/A public void setWorkspace(String workspace)
4274N/A {
4274N/A this.workspace = workspace;
4274N/A }
4274N/A
4274N/A
4274N/A
4274N/A /**
4274N/A * Performs the appropriate processing needed for this task. In this case,
4274N/A * it uses SVNKit to identify the current revision number for the local
4274N/A * workspace and store it in a specified property.
4274N/A */
4274N/A @Override()
4274N/A public void execute()
4274N/A {
4274N/A if ((propertyName == null) || (propertyName.length() == 0))
4274N/A {
4274N/A throw new BuildException("ERROR: No property was specified for " +
4274N/A "storing the revision number value.");
4274N/A }
4274N/A
4274N/A File workspacePath;
4274N/A if ((workspace == null) || (workspace.length() == 0))
4274N/A {
4274N/A workspacePath = getProject().getBaseDir();
4274N/A }
4274N/A else
4274N/A {
4274N/A workspacePath = new File(workspace);
4274N/A }
4274N/A
4274N/A
4274N/A try
4274N/A {
4274N/A SVNInfo svnInfo = ourClientManager.getWCClient().doInfo(workspacePath, SVNRevision.WORKING);
4274N/A SVNURL url_repo = svnInfo.getURL();
4274N/A
4274N/A
4274N/A if (url_repo == null)
4274N/A {
4274N/A System.err.println("WARNING: Could not determine Subversion URL Repository " +
4274N/A "for current workspace.");
4274N/A getProject().setNewProperty(propertyName, "-1");
4274N/A }
4274N/A else
4274N/A {
4274N/A getProject().setNewProperty(propertyName,
4274N/A String.valueOf(url_repo));
4274N/A
4274N/A }
4274N/A
4274N/A }
4274N/A catch (SVNException svnException)
4274N/A {
4274N/A System.err.println("WARNING: Could not determine Subversion " +
4274N/A "URL repository for current workspace: " +
4274N/A svnException);
4274N/A getProject().setNewProperty(propertyName, "-1");
4274N/A }
4274N/A }
4274N/A}
4274N/A