Index: C:/dev/java/svnant/test/svn/build.xml =================================================================== --- C:/dev/java/svnant/test/svn/build.xml (revision 2094) +++ C:/dev/java/svnant/test/svn/build.xml (working copy) @@ -1008,6 +1008,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: C:/dev/java/svnant/doc/svn.html =================================================================== --- C:/dev/java/svnant/doc/svn.html (revision 2094) +++ C:/dev/java/svnant/doc/svn.html (working copy) @@ -123,36 +123,36 @@ createRepository import move - status + revert cat delete + info + mkdir + status + + + checkout + diff keywordsset propdel switch - checkout - diff + commit + export keywordsadd propget update - commit - export + copy + ignore keywordsremove propset - - copy - ignore - mkdir - revert - -

@@ -620,6 +620,33 @@ +

info

+

+Gets the information from the repo for a file or directory and sets the values to Ant properties.
+

+ + + + + + + + + + + + + + + + + + + + + +
AttributeDescriptionRequired
fileDirectory or file to gather the information about.Yes
propPrefixPrefix to use for the Ant properties. Default is "svn.info.".False
verboseTurns on verbosity for this Ant task. Default is "false".False
+

keywordsset

Keywordsset controls which keywords will be substituted on the given files. Valid keywords are: Index: C:/dev/java/svnant/src/main/org/tigris/subversion/svnant/SvnTask.java =================================================================== --- C:/dev/java/svnant/src/main/org/tigris/subversion/svnant/SvnTask.java (revision 2094) +++ C:/dev/java/svnant/src/main/org/tigris/subversion/svnant/SvnTask.java (working copy) @@ -208,6 +208,10 @@ commands.add(a); } + public void addInfo(Info a) { + commands.add(a); + } + public void addNotifyListener(ISVNNotifyListener notifyListener) { notifyListeners.add(notifyListener); } Index: C:/dev/java/svnant/src/main/org/tigris/subversion/svnant/Info.java =================================================================== --- C:/dev/java/svnant/src/main/org/tigris/subversion/svnant/Info.java (revision 0) +++ C:/dev/java/svnant/src/main/org/tigris/subversion/svnant/Info.java (revision 0) @@ -0,0 +1,181 @@ +package org.tigris.subversion.svnant; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.tigris.subversion.svnclientadapter.ISVNClientAdapter; +import org.tigris.subversion.svnclientadapter.ISVNInfo; + +/** + * svn info + * @author Jeremy Whitlock + * jwhitlock@collab.net + */ +public class Info extends SvnCommand { + + /** Path to the file to get properties from **/ + private String file = null; + + /** Whether or not to print the properties **/ + private boolean verbose = false; + + /** String prepended to new property names **/ + private String propPrefix = "svn.info."; + + /** Project reference **/ + private Project project = null; + + /** Subversion info **/ + private ISVNInfo info = null; + + /** Available directory properties **/ + private String[] dirProps = new String[] { + "path", + "url", + "repouuid", + "rev", + "nodekind", + "schedule", + "author", + "lastRev", + "lastDate" + }; + + /** Available file properties **/ + private String[] fileProps = new String[] { + "path", + "name", + "url", + "repouuid", + "rev", + "nodekind", + "schedule", + "author", + "lastRev", + "lastDate", + "lastTextUpdate", + "lastPropUpdate", + "checksum" + }; + + /** + * @see org.tigris.subversion.svnant.SvnCommand#execute(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) + */ + public void execute(ISVNClientAdapter svnClient) throws BuildException { + validateAttributes(); + + if (verbose) { + log("Svn: Info"); + } + + project = getProject(); + + File wc = new File(file); + + if (wc.exists()) { + try { + info = svnClient.getInfo(wc); + String[] props = null; + + if (wc.isDirectory()) { + props = dirProps; + } else { + props = fileProps; + } + + for (int i = 0; i < props.length; i++) { + String value = getValue(props[i]); + + project.setProperty(propPrefix + props[i], value); + + if (verbose) { + log(" " + propPrefix + props[i] + ": " + value, Project.MSG_INFO); + } + } + } catch (Exception e) { + throw new BuildException(e); + } + } else { + throw new BuildException("Dir must be set to an existing file/directory in your working copy."); + } + } + + /** + * Gets the proper info property + * @param prop String representation of the property + * @return String value of the property + */ + public String getValue(String prop) { + String value = null; + + if (prop.equals(fileProps[0])) { + value = info.getFile().getAbsolutePath(); + } else if (prop.equals(fileProps[1])) { + value = info.getFile().getName(); + } else if (prop.equals(fileProps[2])) { + value = info.getUrl().toString(); + } else if (prop.equals(fileProps[3])) { + value = info.getUuid(); + } else if (prop.equals(fileProps[4])) { + value = info.getRevision().toString(); + } else if (prop.equals(fileProps[5])) { + value = info.getNodeKind().toString(); + } else if (prop.equals(fileProps[6])) { + value = info.getSchedule().toString(); + } else if (prop.equals(fileProps[7])) { + value = info.getLastCommitAuthor(); + } else if (prop.equals(fileProps[8])) { + value = info.getLastChangedRevision().toString(); + } else if (prop.equals(fileProps[9])) { + value = info.getLastChangedDate().toString(); + } else if (prop.equals(fileProps[10])) { + value = info.getLastDateTextUpdate().toString(); + } else if (prop.equals(fileProps[11])) { + value = info.getLastDatePropsUpdate().toString(); + } else if (prop.equals(fileProps[12])) { + value = "Checksum is not implemented!"; + } else { + value = prop + " is an invalid property!"; + } + + return value; + } + + /** + * Validates the call to svn info + */ + public void validateAttributes() { + if (file == null) { + throw new BuildException("File must be set to a file/directory of your local working copy."); + } + } + + /** + * Set the path to the file/dir + * @param file + */ + public void setFile(String file) { + this.file = Project.translatePath(file); + } + + /** + * Sets whether or not we output the properties we set + * @param verbose + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + /** + * Sets the Ant property prefix + * @param propPrefix + */ + public void setPropPrefix(String propPrefix) { + if (propPrefix.endsWith(".")) { + this.propPrefix = propPrefix; + } else { + this.propPrefix = propPrefix + "."; + } + } +} Index: C:/dev/java/svnant/src/testcases/org/tigris/subversion/svnant/SvnTest.java =================================================================== --- C:/dev/java/svnant/src/testcases/org/tigris/subversion/svnant/SvnTest.java (revision 2094) +++ C:/dev/java/svnant/src/testcases/org/tigris/subversion/svnant/SvnTest.java (working copy) @@ -815,8 +815,53 @@ assertEquals(1, dir.listFiles().length); assertTrue( (new File(dir, "file3.xml")).exists() ); } - + public void testSvnInfo() throws Exception { + // Here only for debugging the test + try { + expectBuildException("testInfoNoAttributes", "Dir or file must be set."); + expectBuildException("testInfoBadFile", "fakefile.txt: (Not a versioned resource)"); + + executeTarget("testInfoFile"); + + assertNotNull("Property should be set!", project.getProperty("svn.info.path")); + assertNotNull("Property should be set!", project.getProperty("svn.info.name")); + assertNotNull("Property should be set!", project.getProperty("svn.info.url")); + assertNotNull("Property should be set!", project.getProperty("svn.info.repouuid")); + assertNotNull("Property should be set!", project.getProperty("svn.info.rev")); + assertNotNull("Property should be set!", project.getProperty("svn.info.nodekind")); + assertNotNull("Property should be set!", project.getProperty("svn.info.schedule")); + assertNotNull("Property should be set!", project.getProperty("svn.info.author")); + assertNotNull("Property should be set!", project.getProperty("svn.info.lastRev")); + assertNotNull("Property should be set!", project.getProperty("svn.info.lastDate")); + assertNotNull("Property should be set!", project.getProperty("svn.info.lastTextUpdate")); + assertNotNull("Property should be set!", project.getProperty("svn.info.lastPropUpdate")); + assertNotNull("Property should be set!", project.getProperty("svn.info.checksum")); + + executeTarget("testInfoDir"); + + assertNotNull("Property should be set!", project.getProperty("svn.info.path")); + assertNull("Property should be null!", project.getProperty("svn.info.name")); + assertNotNull("Property should be set!", project.getProperty("svn.info.url")); + assertNotNull("Property should be set!", project.getProperty("svn.info.repouuid")); + assertNotNull("Property should be set!", project.getProperty("svn.info.rev")); + assertNotNull("Property should be set!", project.getProperty("svn.info.nodekind")); + assertNotNull("Property should be set!", project.getProperty("svn.info.schedule")); + assertNotNull("Property should be set!", project.getProperty("svn.info.author")); + assertNotNull("Property should be set!", project.getProperty("svn.info.lastRev")); + assertNotNull("Property should be set!", project.getProperty("svn.info.lastDate")); + assertNull("Property should be null!", project.getProperty("svn.info.lastTextUpdate")); + assertNull("Property should be null!", project.getProperty("svn.info.lastPropUpdate")); + assertNull("Property should be null!", project.getProperty("svn.info.checksum")); + + executeTarget("testInfoCustomPrefix"); + + assertNotNull("Property should not be null!", project.getProperty("wc.info.path")); + } catch (Exception e) { + e.printStackTrace(); + } + } + /** * This is not actually a test case, but a hook to assure that * cleanup is handled after all test cases have run (rather than