Index: test/svn/model/svnExistsTest/added.txt =================================================================== --- test/svn/model/svnExistsTest/added.txt (revision 0) +++ test/svn/model/svnExistsTest/added.txt (revision 0) @@ -0,0 +1 @@ +This file will be added to the working copy, but not committed to the repository. \ No newline at end of file Index: test/svn/model/svnExistsTest/private.txt =================================================================== --- test/svn/model/svnExistsTest/private.txt (revision 0) +++ test/svn/model/svnExistsTest/private.txt (revision 0) @@ -0,0 +1 @@ +This file is not added to the working copy. \ No newline at end of file Index: test/svn/model/svnExistsTest/checkedin.txt =================================================================== --- test/svn/model/svnExistsTest/checkedin.txt (revision 0) +++ test/svn/model/svnExistsTest/checkedin.txt (revision 0) @@ -0,0 +1 @@ +This file will be committed to the repository. \ No newline at end of file Index: test/svn/build.xml =================================================================== --- test/svn/build.xml (revision 2685) +++ test/svn/build.xml (working copy) @@ -1069,6 +1069,57 @@ + + + + + + + + + + + + + + + + + + svnExists.local.checkedin: ${svnExists.local.checkedin} + + + + + svnExists.local.added: ${svnExists.local.added} + + + + + svnExists.local.private: ${svnExists.local.private} + + + + + svnExists.local.inexistant: ${svnExists.local.inexistant} + + + + + svnExists.server.checkedin: ${svnExists.server.checkedin} + + + + + svnExists.server.added: ${svnExists.server.added} + + + + + svnExists.server.private: ${svnExists.server.private} + + + Index: .classpath =================================================================== --- .classpath (revision 2685) +++ .classpath (working copy) @@ -4,11 +4,11 @@ - + - + Property changes on: doc ___________________________________________________________________ Name: svn:ignore - selectors.html fileset.html types.html + selectors.html fileset.html types.html conditions.html Index: doc/toc.html =================================================================== --- doc/toc.html (revision 2685) +++ doc/toc.html (working copy) @@ -12,5 +12,7 @@ Types
Selectors +
+ Conditions Index: doc/svn.html =================================================================== --- doc/svn.html (revision 2685) +++ doc/svn.html (working copy) @@ -81,7 +81,7 @@ SvnAnt's JAR file to perform that registration follows:

- + <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpath="svnant.jar" Index: src/main/svnantlib.xml =================================================================== --- src/main/svnantlib.xml (revision 2685) +++ src/main/svnantlib.xml (working copy) @@ -29,4 +29,9 @@ classname="org.tigris.subversion.svnant.selectors.Missing" /> + + + + Index: src/main/org/tigris/subversion/svnant/conditions/Exists.java =================================================================== --- src/main/org/tigris/subversion/svnant/conditions/Exists.java (revision 0) +++ src/main/org/tigris/subversion/svnant/conditions/Exists.java (revision 0) @@ -0,0 +1,140 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ +package org.tigris.subversion.svnant.conditions; + +import java.io.File; +import java.net.MalformedURLException; + +import org.apache.tools.ant.Project; +import org.tigris.subversion.svnant.SvnAntException; +import org.tigris.subversion.svnant.SvnTask; +import org.tigris.subversion.svnclientadapter.ISVNClientAdapter; +import org.tigris.subversion.svnclientadapter.ISVNInfo; +import org.tigris.subversion.svnclientadapter.SVNClientException; +import org.tigris.subversion.svnclientadapter.SVNRevision; +import org.tigris.subversion.svnclientadapter.SVNUrl; + +/** + * Instances of this class are used to test the existence of a repository + * element. It implements the Condition interface, as defined in ANT and + * can be used within condition tasks. + * + * This condition is based on logic from the "info" command. If info can be + * retrieved, then the condition is true. If info fails, then th condition is + * false. + * + * @author Jean-Pierre Fiset jp@fiset.ca + * + */ +public class Exists extends SvnCondition { + + /** + * The target to retrieve properties for. + */ + private String target = null; + + + @Override + public boolean internalEval() throws SvnAntException { + // Obtain a svnClient according to javahl and javasvn properties + ISVNClientAdapter svnClient = SvnTask.getClientAdapter(this); + + // Retrieve info for the requested element + ISVNInfo info = null; + try { + File targetAsFile = new File(Project.translatePath(this.target)); + if (targetAsFile.exists()) { + // Since the target exists locally, assume it's not a URL. + info = svnClient.getInfo(targetAsFile); + } else { + try { + SVNUrl url = new SVNUrl(this.target); + info = svnClient.getInfo(url); + } catch (MalformedURLException malformedURL) { + // Since we don't have a valid URL with which to + // contact the repository, assume the target is a + // local file, even though it doesn't exist locally. + info = svnClient.getInfo(targetAsFile); + } + } + } catch (SVNClientException e) { + // Assume that it is not existant + return false; + } + + // No info -> not in repository + if( null == info ) { + return false; + } + // No revision -> not in repository + if ((info.getRevision() == null) || (SVNRevision.INVALID_REVISION.equals(info.getRevision()))) { + return false; + } + + // Assume it is... + return true; + } + + + public String getTarget() { + return target; + } + + + public void setTarget(String target) { + this.target = target; + } + +} Index: src/main/org/tigris/subversion/svnant/conditions/SvnCondition.java =================================================================== --- src/main/org/tigris/subversion/svnant/conditions/SvnCondition.java (revision 0) +++ src/main/org/tigris/subversion/svnant/conditions/SvnCondition.java (revision 0) @@ -0,0 +1,93 @@ +package org.tigris.subversion.svnant.conditions; + + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.ProjectComponent; +import org.apache.tools.ant.taskdefs.condition.Condition; +import org.apache.tools.ant.taskdefs.condition.ConditionBase; +import org.tigris.subversion.svnant.ISvnAntProjectComponent; +import org.tigris.subversion.svnant.SvnAntException; + +/** + * This is an abstract class that implements functions common to all subclasses. + * It handles the generic 'javahl' and 'javasvn' properties. + * + * Conditions are from a special type in ANT where they can be used to set values + * of properties. See taks Condition in ANT documentation. + * + * @author Jean-Pierre Fiset jp@fiset.ca + * + */ +public abstract class SvnCondition extends ConditionBase implements Condition, ISvnAntProjectComponent { + + /** + * 'javahl' property for file selector. If set, + * JAVAHL bindings are used, if available. Preempts + * JavaSVN and command line. + */ + private boolean javahl = true; + + /** + * 'javasvn' property for file selector. If set, + * JavaSVN client is used, if available. Preempts + * command line, but not JAVAHL bindings. + */ + private boolean javasvn = true; + + /* (non-Javadoc) + * @see org.tigris.subversion.svnant.ISvnAntProjectComponent#getJavahl() + */ + public boolean getJavahl() { + return javahl; + } + + /* (non-Javadoc) + * @see org.tigris.subversion.svnant.ISvnAntProjectComponent#getJavaSvn() + */ + public boolean getJavaSvn() { + return javasvn; + } + + /* (non-Javadoc) + * @see org.tigris.subversion.svnant.ISvnAntProjectComponent#getProjectComponent() + */ + public ProjectComponent getProjectComponent() { + return this; + } + + /** + * Accessor method to 'javahl' property. If reset (false), + * JavaHL is not used. + * @param javahl_ New value for javahl property. + */ + public void setJavahl(boolean javahl_) { + javahl = javahl_; + } + + /** + * Accessor method to 'javasvn' property. If reset (false), + * JavaSVN is not used. + * @param javasvn_ New value for javasvn property. + */ + public void setJavasvn(boolean javasvn_) { + javasvn = javasvn_; + } + + /* (non-Javadoc) + * @see org.apache.tools.ant.taskdefs.condition.Condition#eval() + */ + public boolean eval() throws BuildException { + try { + return internalEval(); + } catch (SvnAntException e) { + throw new BuildException(e.getMessage(), e); + } + } + + /** + * Method called internally by eval(). Must be implemented by all subclasses. + * @return True if the condition is met. False, otherwsie. + * @throws BuildException exception that should be used in case of problems. + */ + public abstract boolean internalEval() throws SvnAntException; +} \ No newline at end of file Index: src/doc/selectors.xml =================================================================== --- src/doc/selectors.xml (revision 2685) +++ src/doc/selectors.xml (working copy) @@ -1,6 +1,7 @@ + + ]>

- &common_params; + &javahl_javasvn_params; &fail_on_error_params; @@ -129,7 +130,7 @@

- &common_params; + &javahl_javasvn_params; &fail_on_error_params; @@ -161,7 +162,7 @@

- &common_params; + &javahl_javasvn_params; &fail_on_error_params; @@ -195,7 +196,7 @@

- &common_params; + &javahl_javasvn_params; &fail_on_error_params; @@ -226,7 +227,7 @@

- &common_params; + &javahl_javasvn_params; &fail_on_error_params; @@ -260,7 +261,7 @@

- &common_params; + &javahl_javasvn_params; &fail_on_error_params; @@ -291,7 +292,7 @@

- &common_params; + &javahl_javasvn_params; &fail_on_error_params; @@ -323,7 +324,7 @@

- &common_params; + &javahl_javasvn_params; &fail_on_error_params; @@ -359,7 +360,7 @@

- &common_params; + &javahl_javasvn_params; &fail_on_error_params; @@ -395,7 +396,7 @@

- &common_params; + &javahl_javasvn_params; &fail_on_error_params;
\ No newline at end of file Index: src/doc/conditions.xml =================================================================== --- src/doc/conditions.xml (revision 0) +++ src/doc/conditions.xml (revision 0) @@ -0,0 +1,115 @@ + + +]> + + + Svn Conditions + + +

+ This document describes the conditions offered in svnant. To use those conditions, + you must first obtain a copy of svnant.jar, add it to the classpath of your ant project + and define the types. Fortunately, there is a resource file, within the distributed JAR file, + and all those steps can be accomplished with the following code: + + + + + + + + ]]> + +

+

+ If you are upgrading from an earlier version of svnant, and the following line was used + in your build.xml file, then replace it with the ones above. + + + ]]> + +

+

Bindings

+

+ All conditions offer two parameters: javahl and javasvn. Those parameters + are booleans, which means their values can be set to either true or false. + If not specified, those parameters are assumed to be set (true). These two parameters are used + to select which client is used to access Subversion. +

+

+ There are three clients used by svnant to access Subversion: +

    +
  • JavaHL;
  • +
  • JavaSVN; and,
  • +
  • Command Line Interface.
  • +
+ To better understand the difference between those three clients, please refer to + documentation on svnClientAdapter.jar. +

+

+ The property javahl is considered only if the javahl libraries are available. Similarly, + the property javasvn is considered only if JavaSVN is present. Finally, javahl + takes precedence over javasvn. +

+

+ To better illustrate the previous paragraph, use the following steps: +

    +
  1. If javahl is true and JavaHL bindings are available, then JavaHL is used.
  2. +
  3. If javasvn is true and JavaSVN is present, then JavaSVN is used.
  4. +
  5. If the two previous tests failed, for any reason, then the Command Line Interface is used.
  6. +
+

+
+ + + + Ant condition that returns true if an element exists in the repository + +

+ This is a custom condition, as defined in the Ant documentation. A custom + condition must be employed in conjunction with a ]]> task + to set a property. +

+

+ This custom condition is used to determine if an element exists in the repository. The condition returns + true if the element is known to te repository. It uses a process similar to "svn info" + to determine the existence of an element. If "svn info" can return information + about a file or a directory, then the svnExists condition should return true for + such file or directory. +

+

+ Example: determine if there exist a "build.xml" file for a project + + + + +fileExists: ${fileExists} +]]> + +

+
+ + + File name or URL to the element to be queried during the condition. + + + Yes + + + &javahl_javasvn_params; +
+ +
\ No newline at end of file Index: src/doc/javahl_javasvn.txt =================================================================== --- src/doc/javahl_javasvn.txt (revision 2685) +++ src/doc/javahl_javasvn.txt (working copy) @@ -18,11 +18,3 @@ No - - - Controls whether an error stops the build or is merely reported to the screen. - - - No (defaults to "true") - - Index: src/doc/fail_on_error.txt =================================================================== --- src/doc/fail_on_error.txt (revision 0) +++ src/doc/fail_on_error.txt (revision 0) @@ -0,0 +1,8 @@ + + + Controls whether an error stops the build or is merely reported to the screen. + + + No (defaults to "true") + + Index: src/testcases/org/tigris/subversion/svnant/SvnTest.java =================================================================== --- src/testcases/org/tigris/subversion/svnant/SvnTest.java (revision 2685) +++ src/testcases/org/tigris/subversion/svnant/SvnTest.java (working copy) @@ -917,6 +917,19 @@ assertTrue( (new File(dir, "file3.xml")).exists() ); } + public void testSvnExists() throws Exception { + executeTarget("testSvnExists"); + + // Test for expected results + assertEquals(project.getProperty("svnExists.local.checkedin"), "true"); + assertEquals(project.getProperty("svnExists.local.added"), "true"); + assertEquals(project.getProperty("svnExists.local.private"), null); + assertEquals(project.getProperty("svnExists.local.inexistant"), null); + assertEquals(project.getProperty("svnExists.server.checkedin"), "true"); + assertEquals(project.getProperty("svnExists.server.added"), null); + assertEquals(project.getProperty("svnExists.server.private"), null); + } + /** * Asserts whether an Ant property is set. */