Added:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnChangeLogTask.java
URL:
http://svn.apache.org/viewcvs/ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnChangeLogTask.java?view=auto&rev=161469
==============================================================================
---
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnChangeLogTask.java
(added)
+++
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnChangeLogTask.java
Fri Apr 15 07:32:50 2005
@@ -0,0 +1,399 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.svn;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.Vector;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.LogOutputStream;
+import org.apache.tools.ant.taskdefs.PumpStreamHandler;
+import org.apache.tools.ant.taskdefs.cvslib.CvsUser;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.util.FileUtils;
+
+/**
+ * Examines the output of svn log and group related changes together.
+ *
+ * It produces an XML output representing the list of changes.
+ * <pre>
+ * <font color=#0000ff><!-- Root element --></font>
+ * <font color=#6a5acd><!ELEMENT</font> changelog <font
color=#ff00ff>(entry</font><font color=#ff00ff>+</font><font
color=#ff00ff>)</font><font color=#6a5acd>></font>
+ * <font color=#0000ff><!-- SVN Entry --></font>
+ * <font color=#6a5acd><!ELEMENT</font> entry <font
color=#ff00ff>(date,time,revision,author,path</font><font
color=#ff00ff>+,msg</font><font color=#ff00ff>,msg)</font><font
color=#6a5acd>></font>
+ * <font color=#0000ff><!-- Date of svn entry --></font>
+ * <font color=#6a5acd><!ELEMENT</font> date <font
color=#ff00ff>(#PCDATA)</font><font color=#6a5acd>></font>
+ * <font color=#0000ff><!-- Time of svn entry --></font>
+ * <font color=#6a5acd><!ELEMENT</font> time <font
color=#ff00ff>(#PCDATA)</font><font color=#6a5acd>></font>
+ * <font color=#0000ff><!-- Author of change --></font>
+ * <font color=#6a5acd><!ELEMENT</font> author <font
color=#ff00ff>(#PCDATA)</font><font color=#6a5acd>></font>
+ * <font color=#0000ff><!-- commit message --></font>
+ * <font color=#6a5acd><!ELEMENT</font> msg <font
color=#ff00ff>(#PCDATA)</font><font color=#6a5acd>></font>
+ * <font color=#0000ff><!-- List of paths affected --></font>
+ * <font color=#6a5acd><!ELEMENT</font> path <font
color=#ff00ff>(name,action)</font><font color=#ff00ff></font><font
color=#ff00ff>)</font><font color=#6a5acd>></font>
+ * <font color=#0000ff><!-- Name of the path --></font>
+ * <font color=#6a5acd><!ELEMENT</font> name <font
color=#ff00ff>(#PCDATA)</font><font color=#6a5acd>></font>
+ * <font color=#6a5acd><!ELEMENT</font> action <font
color=#ff00ff>(added|modified|deleted)</font><font color=#6a5acd>></font>
+ * <font color=#0000ff><!-- Revision number --></font>
+ * <font color=#6a5acd><!ELEMENT</font> revision <font
color=#ff00ff>(#PCDATA)</font><font color=#6a5acd>></font>
+ * </pre>
+ *
+ * @ant.task name="svnchangelog" category="scm"
+ */
+public class SvnChangeLogTask extends AbstractSvnTask {
+ /** User list */
+ private File usersFile;
+
+ /** User list */
+ private Vector svnUsers = new Vector();
+
+ /** Input dir */
+ private File inputDir;
+
+ /** Output file */
+ private File destFile;
+
+ /** The earliest revision at which to start processing entries. */
+ private String startRevision;
+
+ /** The latest revision at which to stop processing entries. */
+ private String endRevision;
+
+ /**
+ * Filesets containing list of files against which the svn log will be
+ * performed. If empty then all files in the working directory will
+ * be checked.
+ */
+ private final Vector filesets = new Vector();
+
+
+ /**
+ * Set the base dir for svn.
+ *
+ * @param inputDir The new dir value
+ */
+ public void setDir(final File inputDir) {
+ this.inputDir = inputDir;
+ }
+
+
+ /**
+ * Set the output file for the log.
+ *
+ * @param destFile The new destfile value
+ */
+ public void setDestfile(final File destFile) {
+ this.destFile = destFile;
+ }
+
+
+ /**
+ * Set a lookup list of user names & addresses
+ *
+ * @param usersFile The file containing the users info.
+ */
+ public void setUsersfile(final File usersFile) {
+ this.usersFile = usersFile;
+ }
+
+
+ /**
+ * Add a user to list changelog knows about.
+ *
+ * @param user the user
+ */
+ public void addUser(final CvsUser user) {
+ svnUsers.addElement(user);
+ }
+
+
+ /**
+ * Set the revision at which the changelog should start.
+ *
+ * @param start The revision at which the changelog should start.
+ */
+ public void setStart(final String start) {
+ this.startRevision = start;
+ }
+
+
+ /**
+ * Set the revision at which the changelog should stop.
+ *
+ * @param endRevision The revision at which the changelog should stop.
+ */
+ public void setEnd(final String endRevision) {
+ this.endRevision = endRevision;
+ }
+
+
+ /**
+ * Set the number of days worth of log entries to process.
+ *
+ * @param days the number of days of log to process.
+ */
+ public void setDaysinpast(final int days) {
+ final long time = System.currentTimeMillis()
+ - (long) days * 24 * 60 * 60 * 1000;
+
+ final SimpleDateFormat outputDate =
+ new SimpleDateFormat("{yyyy-MM-dd}");
+ setStart(outputDate.format(new Date(time)));
+ }
+
+
+ /**
+ * Adds a set of files about which svn logs will be generated.
+ *
+ * @param fileSet a set of files about which svn logs will be generated.
+ */
+ public void addFileset(final FileSet fileSet) {
+ filesets.addElement(fileSet);
+ }
+
+
+ /**
+ * Execute task
+ *
+ * @exception BuildException if something goes wrong executing the
+ * svn command
+ */
+ public void execute() throws BuildException {
+ File savedDir = inputDir; // may be altered in validate
+
+ try {
+
+ validate();
+ final Properties userList = new Properties();
+
+ loadUserlist(userList);
+
+ for (int i = 0, size = svnUsers.size(); i < size; i++) {
+ final CvsUser user = (CvsUser) svnUsers.get(i);
+ user.validate();
+ userList.put(user.getUserID(), user.getDisplayname());
+ }
+
+ setSubCommand("log");
+ setVerbose(true);
+
+ if (null != startRevision) {
+ if (null != endRevision) {
+ setRevision(startRevision + ":" + endRevision);
+ } else {
+ setRevision(startRevision + ":HEAD");
+ }
+ }
+
+ // Check if list of files to check has been specified
+ if (!filesets.isEmpty()) {
+ final Enumeration e = filesets.elements();
+
+ while (e.hasMoreElements()) {
+ final FileSet fileSet = (FileSet) e.nextElement();
+ final DirectoryScanner scanner =
+ fileSet.getDirectoryScanner(getProject());
+ final String[] files = scanner.getIncludedFiles();
+
+ for (int i = 0; i < files.length; i++) {
+ addSubCommandArgument(files[i]);
+ }
+ }
+ }
+
+ final SvnChangeLogParser parser = new SvnChangeLogParser();
+ final PumpStreamHandler handler =
+ new PumpStreamHandler(parser,
+ new LogOutputStream(this,
+ Project.MSG_ERR));
+
+ log(getSubCommand(), Project.MSG_VERBOSE);
+
+ setDest(inputDir);
+ setExecuteStreamHandler(handler);
+ super.execute();
+
+ final SvnEntry[] entrySet = parser.getEntrySetAsArray();
+ final SvnEntry[] filteredEntrySet = filterEntrySet(entrySet);
+
+ replaceAuthorIdWithName(userList, filteredEntrySet);
+
+ writeChangeLog(filteredEntrySet);
+
+ } finally {
+ inputDir = savedDir;
+ }
+ }
+
+ /**
+ * Validate the parameters specified for task.
+ *
+ * @throws BuildException if fails validation checks
+ */
+ private void validate()
+ throws BuildException {
+ if (null == inputDir) {
+ inputDir = getDest();
+ }
+ if (null == destFile) {
+ final String message = "Destfile must be set.";
+
+ throw new BuildException(message);
+ }
+ if (!inputDir.exists()) {
+ final String message = "Cannot find base dir "
+ + inputDir.getAbsolutePath();
+
+ throw new BuildException(message);
+ }
+ if (null != usersFile && !usersFile.exists()) {
+ final String message = "Cannot find user lookup list "
+ + usersFile.getAbsolutePath();
+
+ throw new BuildException(message);
+ }
+ }
+
+ /**
+ * Load the userlist from the userList file (if specified) and add to
+ * list of users.
+ *
+ * @param userList the file of users
+ * @throws BuildException if file can not be loaded for some reason
+ */
+ private void loadUserlist(final Properties userList)
+ throws BuildException {
+ if (null != usersFile) {
+ try {
+ userList.load(new FileInputStream(usersFile));
+ } catch (final IOException ioe) {
+ throw new BuildException(ioe.toString(), ioe);
+ }
+ }
+ }
+
+ /**
+ * Filter the specified entries according to an appropriate rule.
+ *
+ * @param entrySet the entry set to filter
+ * @return the filtered entry set
+ */
+ private SvnEntry[] filterEntrySet(final SvnEntry[] entrySet) {
+ final Vector results = new Vector();
+
+ for (int i = 0; i < entrySet.length; i++) {
+ final SvnEntry svnEntry = entrySet[i];
+
+ if (null != endRevision && !isBeforeEndRevision(svnEntry)) {
+ //Skip revisions that are too late
+ continue;
+ }
+ results.addElement(svnEntry);
+ }
+
+ final SvnEntry[] resultArray = new SvnEntry[results.size()];
+
+ results.copyInto(resultArray);
+ return resultArray;
+ }
+
+ /**
+ * replace all known author's id's with their maven specified names
+ */
+ private void replaceAuthorIdWithName(final Properties userList,
+ final SvnEntry[] entrySet) {
+ for (int i = 0; i < entrySet.length; i++) {
+
+ final SvnEntry entry = entrySet[ i ];
+ if (userList.containsKey(entry.getAuthor())) {
+ entry.setAuthor(userList.getProperty(entry.getAuthor()));
+ }
+ }
+ }
+
+ /**
+ * Print changelog to file specified in task.
+ *
+ * @param entrySet the entry set to write.
+ * @throws BuildException if there is an error writing changelog.
+ */
+ private void writeChangeLog(final SvnEntry[] entrySet)
+ throws BuildException {
+ FileOutputStream output = null;
+
+ try {
+ output = new FileOutputStream(destFile);
+
+ final PrintWriter writer =
+ new PrintWriter(new OutputStreamWriter(output, "UTF-8"));
+
+ final SvnChangeLogWriter serializer = new SvnChangeLogWriter();
+
+ serializer.printChangeLog(writer, entrySet);
+ } catch (final UnsupportedEncodingException uee) {
+ getProject().log(uee.toString(), Project.MSG_ERR);
+ } catch (final IOException ioe) {
+ throw new BuildException(ioe.toString(), ioe);
+ } finally {
+ FileUtils.close(output);
+ }
+ }
+
+ private static final String PATTERN = "yyyy-MM-dd";
+ private static final SimpleDateFormat INPUT_DATE
+ = new SimpleDateFormat(PATTERN);
+
+ /**
+ * Checks whether a given entry is before the given end revision,
+ * using revision numbers or date information as appropriate.
+ */
+ private boolean isBeforeEndRevision(SvnEntry entry) {
+ if (endRevision.startsWith("{")
+ && endRevision.length() >= 2 + PATTERN.length() ) {
+ try {
+ Date endDate =
+ INPUT_DATE.parse(endRevision.substring(1,
+ PATTERN.length()
+ + 1));
+ return entry.getDate().before(endDate);
+ } catch (ParseException e) {
+ }
+ } else {
+ try {
+ int endRev = Integer.parseInt(endRevision);
+ int entryRev = Integer.parseInt(entry.getRevision());
+ return endRev >= entryRev;
+ } catch (NumberFormatException e) {
+ } // end of try-catch
+ }
+ // failed to parse revision, use a save fallback
+ return true;
+ }
+}
+
Propchange:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnChangeLogTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnChangeLogWriter.java
URL:
http://svn.apache.org/viewcvs/ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnChangeLogWriter.java?view=auto&rev=161469
==============================================================================
---
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnChangeLogWriter.java
(added)
+++
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnChangeLogWriter.java
Fri Apr 15 07:32:50 2005
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.svn;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.text.SimpleDateFormat;
+import javax.xml.parsers.DocumentBuilder;
+
+import org.apache.tools.ant.util.DOMElementWriter;
+import org.apache.tools.ant.util.DOMUtils;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Class used to generate an XML changelog.
+ */
+public class SvnChangeLogWriter {
+ /** output format for dates written to xml file */
+ private static final SimpleDateFormat OUTPUT_DATE
+ = new SimpleDateFormat("yyyy-MM-dd");
+ /** output format for times written to xml file */
+ private static final SimpleDateFormat OUTPUT_TIME
+ = new SimpleDateFormat("HH:mm");
+ /** stateless helper for writing the XML document */
+ private static final DOMElementWriter DOM_WRITER = new DOMElementWriter();
+
+ /**
+ * Print out the specified entries.
+ *
+ * @param output writer to which to send output.
+ * @param entries the entries to be written.
+ */
+ public void printChangeLog(final PrintWriter output,
+ final SvnEntry[] entries) throws IOException {
+ output.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ Document doc = DOMUtils.newDocument();
+ Element root = doc.createElement("changelog");
+ DOM_WRITER.openElement(root, output, 0, "\t");
+ output.println();
+ for (int i = 0; i < entries.length; i++) {
+ final SvnEntry entry = entries[i];
+
+ printEntry(output, entry, root);
+ }
+ DOM_WRITER.closeElement(root, output, 0, "\t", entries.length > 0);
+ output.flush();
+ output.close();
+ }
+
+
+ /**
+ * Print out an individual entry in changelog.
+ *
+ * @param entry the entry to print
+ * @param output writer to which to send output.
+ */
+ private void printEntry(final PrintWriter output, final SvnEntry entry,
+ final Element element) throws IOException {
+ Document doc = element.getOwnerDocument();
+
+ Element ent = doc.createElement("entry");
+ DOMUtils.appendTextElement(ent, "date",
+ OUTPUT_DATE.format(entry.getDate()));
+ DOMUtils.appendTextElement(ent, "time",
+ OUTPUT_TIME.format(entry.getDate()));
+ DOMUtils.appendCDATAElement(ent, "author", entry.getAuthor());
+ DOMUtils.appendTextElement(ent, "revision", entry.getRevision());
+
+ SvnEntry.Path[] paths = entry.getPaths();
+ for (int i = 0; i < paths.length; i++) {
+ Element path = DOMUtils.createChildElement(ent, "path");
+ DOMUtils.appendCDATAElement(path, "name", paths[i].getName());
+ DOMUtils.appendTextElement(path, "action",
+ paths[i].getActionDescription());
+ }
+ DOMUtils.appendCDATAElement(ent, "message", entry.getMessage());
+ DOM_WRITER.write(ent, output, 1, "\t");
+ }
+}
+
Propchange:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnChangeLogWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnDiffHandler.java
URL:
http://svn.apache.org/viewcvs/ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnDiffHandler.java?view=auto&rev=161469
==============================================================================
---
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnDiffHandler.java
(added)
+++
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnDiffHandler.java
Fri Apr 15 07:32:50 2005
@@ -0,0 +1,207 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.svn;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.util.DOMElementWriter;
+import org.apache.tools.ant.util.DOMUtils;
+import org.apache.tools.ant.util.FileUtils;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Parses the output of a svn diff command and/or writes an XML report
+ * based on such a diff output.
+ *
+ * It produces an XML output representing the list of changes.
+ */
+final class SvnDiffHandler {
+
+ /**
+ * Token to identify the word file in the rdiff log
+ */
+ private static final String INDEX = "Index: ";
+ /**
+ * Token to identify a deleted file based on the Index line.
+ */
+ private static final String DELETED = " (deleted)";
+
+ /**
+ * Token to identify added files based on the diff line.
+ */
+ private static final String IS_NEW = "\t(revision 0)";
+
+ /**
+ * Token that starts diff line of old revision.
+ */
+ private static final String DASHES = "--- ";
+
+ /** stateless helper for writing the XML document */
+ private static final DOMElementWriter DOM_WRITER = new DOMElementWriter();
+
+ /**
+ * Parse the tmpFile and return and array of entries to be written
+ * in the output.
+ *
+ * @param tmpFile the File containing the output of the svn rdiff command
+ * @return the entries in the output
+ * @exception BuildException if an error occurs
+ */
+ static SvnEntry.Path[] parseDiff(File tmpFile) throws BuildException {
+ // parse the output of the command
+ BufferedReader reader = null;
+
+ try {
+ reader = new BufferedReader(new FileReader(tmpFile));
+ ArrayList entries = new ArrayList();
+
+ String line = reader.readLine();
+ String name = null;
+ String currDiffLine = null;
+ boolean deleted = false;
+ boolean added = false;
+
+ while (null != line) {
+ if (line.length() > INDEX.length()) {
+ if (line.startsWith(INDEX)) {
+ if (name != null) {
+ SvnEntry.Path p =
+ new SvnEntry.Path(name,
+ deleted
+ ? SvnEntry.Path.DELETED
+ : (added
+ ? SvnEntry.Path.ADDED
+ : SvnEntry.Path.MODIFIED)
+ );
+ entries.add(p);
+ deleted = added = false;
+ }
+
+ name = line.substring(INDEX.length());
+ if (line.endsWith(DELETED)) {
+ name = name.substring(0, name.length()
+ - DELETED.length());
+ deleted = true;
+ }
+
+ currDiffLine = DASHES + name;
+ } else if (currDiffLine != null
+ && line.startsWith(currDiffLine)
+ && line.endsWith(IS_NEW)) {
+ added = true;
+ }
+ }
+ line = reader.readLine();
+ }
+ if (name != null) {
+ SvnEntry.Path p = new SvnEntry.Path(name,
+ deleted
+ ? SvnEntry.Path.DELETED
+ : (added
+ ? SvnEntry.Path.ADDED
+ :
SvnEntry.Path.MODIFIED)
+ );
+ entries.add(p);
+ }
+
+ SvnEntry.Path[] array = (SvnEntry.Path[])
+ entries.toArray(new SvnEntry.Path[entries.size()]);
+ return array;
+ } catch (IOException e) {
+ throw new BuildException("Error in parsing", e);
+ } finally {
+ FileUtils.close(reader);
+ }
+ }
+
+ /**
+ * Write the diff log.
+ *
+ * @param entries a <code>SvnRevisionEntry[]</code> value
+ * @exception BuildException if an error occurs
+ */
+ static void writeDiff(File destFile, SvnEntry.Path[] entries,
+ String rootElementName,
+ String tag1Name, String tag1Value,
+ String tag2Name, String tag2Value,
+ String svnURL) throws BuildException {
+ FileOutputStream output = null;
+ try {
+ output = new FileOutputStream(destFile);
+ PrintWriter writer = new PrintWriter(
+ new OutputStreamWriter(output, "UTF-8"));
+ writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ Document doc = DOMUtils.newDocument();
+ Element root = doc.createElement(rootElementName);
+ if (tag1Name != null && tag1Value != null) {
+ root.setAttribute(tag1Name, tag1Value);
+ }
+ if (tag2Name != null && tag2Value != null) {
+ root.setAttribute(tag2Name, tag2Value);
+ }
+
+ if (svnURL != null) {
+ root.setAttribute("svnurl", svnURL);
+ }
+ DOM_WRITER.openElement(root, writer, 0, "\t");
+ writer.println();
+ for (int i = 0, c = entries.length; i < c; i++) {
+ writeRevisionEntry(doc, writer, entries[i]);
+ }
+ DOM_WRITER.closeElement(root, writer, 0, "\t", true);
+ writer.flush();
+ writer.close();
+ } catch (UnsupportedEncodingException uee) {
+ throw new BuildException(uee);
+ } catch (IOException ioe) {
+ throw new BuildException(ioe.toString(), ioe);
+ } finally {
+ FileUtils.close(output);
+ }
+ }
+
+ /**
+ * Write a single entry to the given writer.
+ *
+ * @param doc Document used to create elements.
+ * @param writer a <code>PrintWriter</code> value
+ * @param entry a <code>SvnRevisionEntry</code> value
+ */
+ private static void writeRevisionEntry(Document doc,
+ PrintWriter writer,
+ SvnEntry.Path entry)
+ throws IOException {
+ Element e = doc.createElement("path");
+ DOMUtils.appendCDATAElement(e, "name", entry.getName());
+ DOMUtils.appendTextElement(e, "action", entry.getActionDescription());
+ DOM_WRITER.write(e, writer, 1, "\t");
+ }
+
+}
Propchange:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnDiffHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnEntry.java
URL:
http://svn.apache.org/viewcvs/ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnEntry.java?view=auto&rev=161469
==============================================================================
---
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnEntry.java
(added)
+++
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnEntry.java
Fri Apr 15 07:32:50 2005
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.svn;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+
+public class SvnEntry {
+ private final Date date;
+ private final String revision;
+ private String author;
+ private final String message;
+ private final ArrayList paths = new ArrayList();
+
+ /**
+ * Creates a new instance of a SvnEntry
+ * @param date the date
+ * @param author the author
+ * @param message a message to be added to the revision
+ */
+ public SvnEntry(final Date date, final String revision,
+ final String author, final String message) {
+ this(date, revision, author, message, Collections.EMPTY_LIST);
+ }
+
+ /**
+ * Creates a new instance of a SvnEntry
+ * @param date the date
+ * @param author the author
+ * @param message a message to be added to the revision
+ */
+ public SvnEntry(final Date date, final String revision,
+ final String author, final String message,
+ final Collection paths) {
+ this.date = date;
+ this.revision = revision;
+ this.author = author;
+ this.message = message;
+ this.paths.addAll(paths);
+ }
+
+ /**
+ * Adds a path to the SvnEntry
+ * @param path the path to add
+ * @param revision the revision
+ */
+ public void addPath(final String name, final char action) {
+ paths.add(new Path(name, action));
+ }
+
+ /**
+ * Gets the date of the SvnEntry
+ * @return the date
+ */
+ public Date getDate() {
+ return date;
+ }
+
+ /**
+ * Gets the revision of the SvnEntry
+ * @return the date
+ */
+ public String getRevision() {
+ return revision;
+ }
+
+ /**
+ * Sets the author of the SvnEntry
+ * @param author the author
+ */
+ public void setAuthor(final String author) {
+ this.author = author;
+ }
+
+ /**
+ * Gets the author of the SvnEntry
+ * @return the author
+ */
+ public String getAuthor() {
+ return author;
+ }
+
+ /**
+ * Gets the message for the SvnEntry
+ * @return the message
+ */
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * Gets the paths in this SvnEntry
+ * @return the files
+ */
+ public Path[] getPaths() {
+ return (Path[]) paths.toArray(new Path[paths.size()]);
+ }
+
+ public static class Path {
+
+ private static final char ADDED_MARKER = 'A';
+ private static final char MODIFIED_MARKER = 'M';
+ private static final char DELETED_MARKER = 'D';
+
+ public static final int ADDED = 0;
+ public static final int MODIFIED = 1;
+ public static final int DELETED = 2;
+
+ private static final String[] ACTIONS = {
+ "added", "modified", "deleted",
+ };
+
+ private final String name;
+ private final int action;
+
+ public Path(final String name, final char actionChar) {
+ this.name = name;
+ switch (actionChar) {
+ case ADDED_MARKER:
+ action = ADDED;
+ break;
+ case MODIFIED_MARKER:
+ action = MODIFIED;
+ break;
+ case DELETED_MARKER:
+ action = DELETED;
+ break;
+ default:
+ throw new IllegalArgumentException("Unkown action; "
+ + actionChar);
+ }
+ }
+
+ public Path(final String name, final int action) {
+ this.name = name;
+ if (action != ADDED && action != DELETED && action != MODIFIED) {
+ throw new IllegalArgumentException("Unkown action; " + action);
+ }
+ this.action = action;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getAction() {
+ return action;
+ }
+
+ public String getActionDescription() {
+ return ACTIONS[action];
+ }
+ }
+
+}
Propchange:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnEntry.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiff.java
URL:
http://svn.apache.org/viewcvs/ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiff.java?view=auto&rev=161469
==============================================================================
---
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiff.java
(added)
+++
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiff.java
Fri Apr 15 07:32:50 2005
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.svn;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.util.FileUtils;
+
+/**
+ * Examines the output of svn diff between two revisions.
+ *
+ * It produces an XML output representing the list of changes.
+ * <PRE>
+ * <!-- Root element -->
+ * <!ELEMENT revisiondiff ( paths? ) >
+ * <!-- Start revision of the report -->
+ * <!ATTLIST revisiondiff start NMTOKEN #IMPLIED >
+ * <!-- End revision of the report -->
+ * <!ATTLIST revisiondiff end NMTOKEN #IMPLIED >
+ * <!-- Subversion URL if known -->
+ * <!ATTLIST revisiondiff svnurl NMTOKEN #IMPLIED >
+ *
+ * <!-- Path added, changed or removed -->
+ * <!ELEMENT path ( name,action ) >
+ * <!-- Name of the file -->
+ * <!ELEMENT name ( #PCDATA ) >
+ * <!ELEMENT action (added|modified|deleted)>
+ * </PRE>
+ *
+ * @ant.task name="svnrevisiondiff"
+ */
+public class SvnRevisionDiff extends AbstractSvnTask {
+
+ /**
+ * Used to create the temp file for svn log
+ */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
+ /**
+ * The earliest revision from which diffs are to be included in the report.
+ */
+ private String mystartRevision;
+
+ /**
+ * The latest revision from which diffs are to be included in the report.
+ */
+ private String myendRevision;
+
+ /**
+ * The file in which to write the diff report.
+ */
+ private File mydestfile;
+
+ /**
+ * Set the start revision.
+ *
+ * @param s the start revision.
+ */
+ public void setStart(String s) {
+ mystartRevision = s;
+ }
+
+ /**
+ * Set the end revision.
+ *
+ * @param s the end revision.
+ */
+ public void setEnd(String s) {
+ myendRevision = s;
+ }
+
+ /**
+ * Set the output file for the diff.
+ *
+ * @param f the output file for the diff.
+ */
+ public void setDestFile(File f) {
+ mydestfile = f;
+ }
+
+ /**
+ * Execute task.
+ *
+ * @exception BuildException if an error occurs
+ */
+ public void execute() throws BuildException {
+ // validate the input parameters
+ validate();
+
+ // build the rdiff command
+ setSubCommand("diff");
+ setRevision(mystartRevision + ":" + myendRevision);
+ addSubCommandArgument("--no-diff-deleted");
+
+ File tmpFile = null;
+ try {
+ tmpFile =
+ FILE_UTILS.createTempFile("svnrevisiondiff", ".log", null);
+ tmpFile.deleteOnExit();
+ setOutput(tmpFile);
+
+ // run the svn command
+ super.execute();
+
+ // parse the diff
+ SvnEntry.Path[] entries = SvnDiffHandler.parseDiff(tmpFile);
+
+ // write the revision diff
+ SvnDiffHandler.writeDiff(mydestfile, entries, "revisiondiff",
+ "start", mystartRevision,
+ "end", myendRevision, getSvnURL());
+ } finally {
+ if (tmpFile != null) {
+ tmpFile.delete();
+ }
+ }
+ }
+
+ /**
+ * Validate the parameters specified for task.
+ *
+ * @exception BuildException if a parameter is not correctly set
+ */
+ private void validate() throws BuildException {
+ if (null == mydestfile) {
+ throw new BuildException("Destfile must be set.");
+ }
+
+ if (null == mystartRevision) {
+ throw new BuildException("Start revision or start date must be
set.");
+ }
+
+ if (null == myendRevision) {
+ throw new BuildException("End revision or end date must be set.");
+ }
+ }
+}
Propchange:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiff.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnTagDiff.java
URL:
http://svn.apache.org/viewcvs/ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnTagDiff.java?view=auto&rev=161469
==============================================================================
---
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnTagDiff.java
(added)
+++
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnTagDiff.java
Fri Apr 15 07:32:50 2005
@@ -0,0 +1,210 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.svn;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.util.FileUtils;
+
+/**
+ * Examines the output of svn diff between two tags or a tag and trunk.
+ *
+ * <p>This task only works if you follow the best-practice structure of
+ * <pre>
+ * BASEURL
+ * |
+ * |
+ * -----> trunk
+ * -----> tags
+ * |
+ * |
+ * ----------> tag1
+ * ----------> tag2
+ * </pre>
+ *
+ * It produces an XML output representing the list of changes.
+ * <PRE>
+ * <!-- Root element -->
+ * <!ELEMENT tagdiff ( paths? ) >
+ * <!-- First tag -->
+ * <!ATTLIST tagdiff tag1 NMTOKEN #IMPLIED >
+ * <!-- Second tag -->
+ * <!ATTLIST tagdiff tag2 NMTOKEN #IMPLIED >
+ * <!-- Subversion BaseURL -->
+ * <!ATTLIST tagdiff svnurl NMTOKEN #IMPLIED >
+ *
+ * <!-- Path added, changed or removed -->
+ * <!ELEMENT path ( name,action ) >
+ * <!-- Name of the file -->
+ * <!ELEMENT name ( #PCDATA ) >
+ * <!ELEMENT action (added|modified|deleted)>
+ * </PRE>
+ *
+ * @ant.task name="svntagdiff"
+ */
+public class SvnTagDiff extends AbstractSvnTask {
+
+ /**
+ * Used to create the temp file for svn log
+ */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
+ /**
+ * The earliest revision from which diffs are to be included in the report.
+ */
+ private String tag1;
+
+ /**
+ * The latest revision from which diffs are to be included in the report.
+ */
+ private String tag2;
+
+ /**
+ * The file in which to write the diff report.
+ */
+ private File mydestfile;
+
+ /**
+ * Base URL.
+ */
+ private String baseURL;
+
+ /**
+ * Set the first tag.
+ *
+ * @param s the first tag.
+ */
+ public void setTag1(String s) {
+ tag1 = s;
+ }
+
+ /**
+ * Set the second tag.
+ *
+ * @param s the second tag.
+ */
+ public void setTag2(String s) {
+ tag2 = s;
+ }
+
+ /**
+ * Set the output file for the diff.
+ *
+ * @param f the output file for the diff.
+ */
+ public void setDestFile(File f) {
+ mydestfile = f;
+ }
+
+ /**
+ * Set the base URL from which to calculate tag URLs.
+ *
+ * @param u the base URL from which to calculate tag URLs.
+ */
+ public void setBaseURL(String u) {
+ baseURL = u;
+ if (!u.endsWith("/")) {
+ baseURL += "/";
+ }
+ }
+
+ /**
+ * Execute task.
+ *
+ * @exception BuildException if an error occurs
+ */
+ public void execute() throws BuildException {
+ // validate the input parameters
+ validate();
+
+ // build the rdiff command
+ setSubCommand("diff");
+ addSubCommandArgument("--no-diff-deleted");
+ if (tag1.equals("trunk") || tag1.equals("trunk/")) {
+ addSubCommandArgument(baseURL + "trunk/");
+ } else {
+ if (tag1.endsWith("/")) {
+ addSubCommandArgument(baseURL + "tags/" + tag1);
+ } else {
+ addSubCommandArgument(baseURL + "tags/" + tag1 + "/");
+ }
+ }
+ if (tag2 == null || tag2.equals("trunk") || tag2.equals("trunk/")) {
+ addSubCommandArgument(baseURL + "trunk/");
+ } else {
+ if (tag2.endsWith("/")) {
+ addSubCommandArgument(baseURL + "tags/" + tag2);
+ } else {
+ addSubCommandArgument(baseURL + "tags/" + tag2 + "/");
+ }
+ }
+
+ File tmpFile = null;
+ try {
+ tmpFile =
+ FILE_UTILS.createTempFile("svntagdiff", ".log", null);
+ tmpFile.deleteOnExit();
+ setOutput(tmpFile);
+
+ // run the svn command
+ super.execute();
+
+ // parse the diff
+ SvnEntry.Path[] entries = SvnDiffHandler.parseDiff(tmpFile);
+
+ // write the revision diff
+ SvnDiffHandler.writeDiff(mydestfile, entries, "tagdiff",
+ "tag1", tag1, "tag2",
+ tag2 == null ? "trunk" : tag2,
+ baseURL);
+ } finally {
+ if (tmpFile != null) {
+ tmpFile.delete();
+ }
+ }
+ }
+
+ /**
+ * Validate the parameters specified for task.
+ *
+ * @exception BuildException if a parameter is not correctly set
+ */
+ private void validate() throws BuildException {
+ if (null == mydestfile) {
+ throw new BuildException("Destfile must be set.");
+ }
+
+ if (null == tag1) {
+ throw new BuildException("tag1 must be set.");
+ }
+
+ if (null == baseURL) {
+ throw new BuildException("baseURL must be set.");
+ }
+ }
+}
Propchange:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/SvnTagDiff.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/antlib.xml
URL:
http://svn.apache.org/viewcvs/ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/antlib.xml?view=auto&rev=161469
==============================================================================
---
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/antlib.xml
(added)
+++
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/antlib.xml
Fri Apr 15 07:32:50 2005
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 2005 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<antlib>
+ <taskdef
+ name="svn"
+ classname="org.apache.tools.ant.taskdefs.svn.Svn"
+ />
+ <taskdef
+ name="changelog"
+ classname="org.apache.tools.ant.taskdefs.svn.SvnChangeLogTask"
+ />
+ <taskdef
+ name="revisiondiff"
+ classname="org.apache.tools.ant.taskdefs.svn.SvnRevisionDiff"
+ />
+ <taskdef
+ name="tagdiff"
+ classname="org.apache.tools.ant.taskdefs.svn.SvnTagDiff"
+ />
+</antlib>
Propchange:
ant/sandbox/antlibs/svn/trunk/src/main/org/apache/tools/ant/taskdefs/svn/antlib.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/AbstractSvnTaskTest.java
URL:
http://svn.apache.org/viewcvs/ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/AbstractSvnTaskTest.java?view=auto&rev=161469
==============================================================================
---
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/AbstractSvnTaskTest.java
(added)
+++
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/AbstractSvnTaskTest.java
Fri Apr 15 07:32:50 2005
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.svn;
+
+import java.io.File;
+
+import org.apache.tools.ant.BuildFileTest;
+
+/**
+ */
+public class AbstractSvnTaskTest extends BuildFileTest {
+
+ public AbstractSvnTaskTest() {
+ this( "AbstractSvnTaskTest" );
+ }
+
+ public AbstractSvnTaskTest(String name) {
+ super(name);
+ }
+
+ public void setUp() {
+ configureProject("src/etc/testcases/abstractsvntask.xml");
+ }
+
+ public void tearDown() {
+ executeTarget("cleanup");
+ }
+
+ public void testAbstractSvnTask() {
+ executeTarget("all");
+ }
+
+ public void testRevisionAttribute() {
+ File f = getProject().resolveFile("tmpdir/tpf/ebcdic.h");
+ assertTrue("starting empty", !f.exists());
+ expectLogContaining("revision-attribute", "A tpf/ebcdic.h");
+ assertTrue("now it is there", f.exists());
+ }
+}
Propchange:
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/AbstractSvnTaskTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnChangeLogTaskTest.java
URL:
http://svn.apache.org/viewcvs/ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnChangeLogTaskTest.java?view=auto&rev=161469
==============================================================================
---
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnChangeLogTaskTest.java
(added)
+++
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnChangeLogTaskTest.java
Fri Apr 15 07:32:50 2005
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.svn;
+
+import java.io.IOException;
+import java.io.FileReader;
+
+import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.util.FileUtils;
+
+import junit.framework.Assert;
+
+/**
+ */
+public class SvnChangeLogTaskTest extends BuildFileTest {
+
+ public SvnChangeLogTaskTest(String name) {
+ super(name);
+ }
+
+ public void setUp() {
+ configureProject("src/etc/testcases/changelog.xml");
+ }
+
+ public void tearDown() {
+ executeTarget("cleanup");
+ }
+
+ public void testLog() throws IOException {
+ String log = executeTargetAndReadLogFully("log");
+ assertRev153687(log);
+ assertRev152685(log);
+ }
+
+ public void testStart() throws IOException {
+ String log = executeTargetAndReadLogFully("start");
+ assertRev153687(log);
+ assertNoRev152685(log);
+ }
+
+ public void testStartDate() throws IOException {
+ String log = executeTargetAndReadLogFully("startDate");
+ assertRev153687(log);
+ assertNoRev152685(log);
+ }
+
+ public void testEnd() throws IOException {
+ String log = executeTargetAndReadLogFully("end");
+ assertNoRev153687(log);
+ assertRev152685(log);
+ }
+
+ public void testEndDate() throws IOException {
+ String log = executeTargetAndReadLogFully("endDate");
+ assertNoRev153687(log);
+ assertRev152685(log);
+ }
+
+ private String executeTargetAndReadLogFully(String target)
+ throws IOException {
+ executeTarget(target);
+ FileReader r = new FileReader(getProject()
+ .resolveFile("tmpdir/log.xml"));
+ try {
+ return FileUtils.readFully(r);
+ } finally {
+ r.close();
+ }
+ }
+
+ private static final void assertRev153687(String log) {
+ int rev = log.indexOf("<revision>153687</revision>");
+ Assert.assertTrue(rev > -1);
+ int entryBeforeRev = log.lastIndexOf("<entry>", rev);
+ int entryAfterRev = log.indexOf("</entry>", rev);
+
+ Assert.assertTrue(entryBeforeRev > -1);
+ Assert.assertTrue(entryAfterRev > -1);
+
+ Assert
+
.assertTrue(log.lastIndexOf("<author><![CDATA[dbrosius]]></author>",
+ rev) > entryBeforeRev);
+ Assert
+ .assertTrue(log.indexOf("<name><![CDATA[/jakarta/bcel/trunk/src"
+ + "/java/org/apache/bcel/util/BCELifier."
+ + "java]]></name>", rev) < entryAfterRev);
+ Assert
+ .assertTrue(log.indexOf("<action>modified</action>", rev)
+ < entryAfterRev);
+ Assert
+ .assertTrue(log.indexOf("<message><![CDATA[Update BCELifier to "
+ + "handle the new method access flags "
+ + "(ACC_BRIDGE, ACC_VARARGS)]]></message>",
+ rev)
+ < entryAfterRev);
+ }
+
+ private static final void assertRev152685(String log) {
+ int rev = log.indexOf("<revision>152685</revision>");
+ Assert.assertTrue(rev > -1);
+ int entryBeforeRev = log.lastIndexOf("<entry>", rev);
+ int entryAfterRev = log.indexOf("</entry>", rev);
+
+ Assert.assertTrue(entryBeforeRev > -1);
+ Assert.assertTrue(entryAfterRev > -1);
+
+ Assert
+ .assertTrue(log.lastIndexOf("<![CDATA[(no author)]]>", rev)
+ > entryBeforeRev);
+ Assert
+ .assertTrue(log.indexOf("<name><![CDATA[/jakarta/bcel/branches]]>"
+ + "</name>", rev) < entryAfterRev);
+ Assert
+ .assertTrue(log.indexOf("<action>added</action>", rev)
+ < entryAfterRev);
+ Assert
+ .assertTrue(log.indexOf("<message><![CDATA[New repository "
+ + "initialized by cvs2svn.]]></message>",
+ rev)
+ < entryAfterRev);
+ }
+
+ private static final void assertNoRev153687(String log) {
+ int rev = log.indexOf("<revision>153687</revision>");
+ Assert.assertEquals(-1, rev);
+ }
+
+ private static final void assertNoRev152685(String log) {
+ int rev = log.indexOf("<revision>152685</revision>");
+ Assert.assertEquals(-1, rev);
+ }
+}
Propchange:
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnChangeLogTaskTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiffTest.java
URL:
http://svn.apache.org/viewcvs/ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiffTest.java?view=auto&rev=161469
==============================================================================
---
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiffTest.java
(added)
+++
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiffTest.java
Fri Apr 15 07:32:50 2005
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.svn;
+
+import java.io.IOException;
+import java.io.FileReader;
+
+import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.util.FileUtils;
+
+import junit.framework.Assert;
+
+/**
+ */
+public class SvnRevisionDiffTest extends BuildFileTest {
+
+ public SvnRevisionDiffTest(String name) {
+ super(name);
+ }
+
+ public void setUp() {
+ configureProject("src/etc/testcases/revisiondiff.xml");
+ }
+
+ public void tearDown() {
+ executeTarget("cleanup");
+ }
+
+ public void testDiff() throws IOException {
+ String log = executeTargetAndReadLogFully("diff");
+ assertAttributesNoURL(log);
+ assertAdded(log);
+ assertModified(log);
+ assertDeleted(log);
+ }
+
+ public void testDiffUrl() throws IOException {
+ String log = executeTargetAndReadLogFully("diff-using-url");
+ assertAttributesWithURL(log);
+ assertAdded(log);
+ assertModified(log);
+ assertDeleted(log);
+ }
+
+ private String executeTargetAndReadLogFully(String target)
+ throws IOException {
+ executeTarget(target);
+ FileReader r = new FileReader(getProject()
+ .resolveFile("tmpdir/diff.xml"));
+ try {
+ return FileUtils.readFully(r);
+ } finally {
+ r.close();
+ }
+ }
+
+ private static final void assertAttributes(String log) {
+ int start = log.indexOf("<revisiondiff");
+ Assert.assertTrue(start > -1);
+ int end = log.indexOf(">", start);
+ Assert.assertTrue(end > -1);
+ Assert.assertTrue(log.indexOf("start=\"152904\"", start) > -1);
+ Assert.assertTrue(log.indexOf("start=\"152904\"", start) < end);
+ Assert.assertTrue(log.indexOf("end=\"153682\"", start) > -1);
+ Assert.assertTrue(log.indexOf("end=\"153682\"", start) < end);
+ }
+
+ private static final void assertAttributesNoURL(String log) {
+ assertAttributes(log);
+ Assert.assertEquals(-1, log.indexOf("svnurl="));
+ }
+
+ private static final void assertAttributesWithURL(String log) {
+ assertAttributes(log);
+ int start = log.indexOf("<revisiondiff");
+ int end = log.indexOf(">", start);
+ Assert.assertTrue(log.indexOf("svnurl=\"http://svn.apache.org/repos/"
+ + "asf/jakarta/bcel/trunk\"", start)
+ > -1);
+ Assert.assertTrue(log.indexOf("svnurl=\"http://svn.apache.org/repos/"
+ + "asf/jakarta/bcel/trunk\"", start)
+ < end);
+ }
+
+ private static final void assertAdded(String log) {
+ int name = log.indexOf("<![CDATA[src/java/org/apache/bcel/classfile/"
+ + "ElementValuePair.java]]>");
+ Assert.assertTrue(name > -1);
+
+ int pathAfterName = log.indexOf("</path>", name);
+ Assert.assertTrue(pathAfterName > -1);
+
+ Assert.assertTrue(log.indexOf("<action>added</action>", name) > -1);
+ Assert.assertTrue(log.indexOf("<action>added</action>", name)
+ < pathAfterName);
+ }
+
+ private static final void assertModified(String log) {
+ int name = log.indexOf("<name><![CDATA[xdocs/stylesheets/project."
+ + "xml]]></name>");
+ Assert.assertTrue(name > -1);
+
+ int pathAfterName = log.indexOf("</path>", name);
+ Assert.assertTrue(pathAfterName > -1);
+
+ Assert.assertTrue(log.indexOf("<action>modified</action>", name) > -1);
+ Assert.assertTrue(log.indexOf("<action>modified</action>", name)
+ < pathAfterName);
+ }
+
+ private static final void assertDeleted(String log) {
+ int name = log.indexOf("<name><![CDATA[lib/CCK.jar]]></name>");
+ Assert.assertTrue(name > -1);
+
+ int pathAfterName = log.indexOf("</path>", name);
+ Assert.assertTrue(pathAfterName > -1);
+
+ Assert.assertTrue(log.indexOf("<action>deleted</action>", name) > -1);
+ Assert.assertTrue(log.indexOf("<action>deleted</action>", name)
+ < pathAfterName);
+ }
+}
Propchange:
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiffTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnTagDiffTest.java
URL:
http://svn.apache.org/viewcvs/ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnTagDiffTest.java?view=auto&rev=161469
==============================================================================
---
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnTagDiffTest.java
(added)
+++
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnTagDiffTest.java
Fri Apr 15 07:32:50 2005
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.svn;
+
+import java.io.IOException;
+import java.io.FileReader;
+
+import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.util.FileUtils;
+
+import junit.framework.Assert;
+
+/**
+ */
+public class SvnTagDiffTest extends BuildFileTest {
+
+ public SvnTagDiffTest(String name) {
+ super(name);
+ }
+
+ public void setUp() {
+ configureProject("src/etc/testcases/tagdiff.xml");
+ }
+
+ public void tearDown() {
+ executeTarget("cleanup");
+ }
+
+ public void testDiffWithTwoTags() throws IOException {
+ String log = executeTargetAndReadLogFully("diff-with-two-tags");
+ assertAttributes(log, "initial", "BCEL_5_0");
+ assertAdded1(log);
+ }
+
+ public void testDiffWithExplicitTrunk() throws IOException {
+ String log = executeTargetAndReadLogFully("diff-with-explicit-trunk");
+ assertDiffWithTrunk(log);
+ }
+
+ public void testDiffWithImplicitTrunk() throws IOException {
+ String log = executeTargetAndReadLogFully("diff-with-implicit-trunk");
+ assertDiffWithTrunk(log);
+ }
+
+ private static void assertDiffWithTrunk(String log) {
+ assertAttributes(log, "BCEL_5_0", "trunk");
+ assertAdded(log);
+ assertModified(log);
+ assertDeleted(log);
+ }
+
+ private String executeTargetAndReadLogFully(String target)
+ throws IOException {
+ executeTarget(target);
+ FileReader r = new FileReader(getProject()
+ .resolveFile("tmpdir/diff.xml"));
+ try {
+ return FileUtils.readFully(r);
+ } finally {
+ r.close();
+ }
+ }
+
+ private static final void assertAttributes(String log, String tag1,
+ String tag2) {
+ int start = log.indexOf("<tagdiff");
+ Assert.assertTrue(start > -1);
+ int end = log.indexOf(">", start);
+ Assert.assertTrue(end > -1);
+ Assert.assertTrue(log.indexOf("tag1=\"" + tag1 + "\"", start) > -1);
+ Assert.assertTrue(log.indexOf("tag1=\"" + tag1 + "\"", start) < end);
+ Assert.assertTrue(log.indexOf("tag2=\"" + tag2 + "\"", start) > -1);
+ Assert.assertTrue(log.indexOf("tag2=\"" + tag2 + "\"", start) < end);
+ Assert.assertTrue(log.indexOf("svnurl=\"http://svn.apache.org/repos/"
+ + "asf/jakarta/bcel/\"", start) > -1);
+ Assert.assertTrue(log.indexOf("svnurl=\"http://svn.apache.org/repos/"
+ + "asf/jakarta/bcel/\"", start) < end);
+ }
+
+ private static final void assertAdded(String log) {
+ int name = log.indexOf("<![CDATA[LICENSE.txt]]>");
+ Assert.assertTrue(name > -1);
+
+ int pathAfterName = log.indexOf("</path>", name);
+ Assert.assertTrue(pathAfterName > -1);
+
+ Assert.assertTrue(log.indexOf("<action>added</action>", name) > -1);
+ Assert.assertTrue(log.indexOf("<action>added</action>", name)
+ < pathAfterName);
+ }
+
+ private static final void assertModified(String log) {
+ int name = log.indexOf("<name><![CDATA[src/java/org/apache/bcel/"
+ + "Repository.java]]></name>");
+ Assert.assertTrue(name > -1);
+
+ int pathAfterName = log.indexOf("</path>", name);
+ Assert.assertTrue(pathAfterName > -1);
+
+ Assert.assertTrue(log.indexOf("<action>modified</action>", name) > -1);
+ Assert.assertTrue(log.indexOf("<action>modified</action>", name)
+ < pathAfterName);
+ }
+
+ private static final void assertDeleted(String log) {
+ int name = log.indexOf("<name><![CDATA[LICENSE]]></name>");
+ Assert.assertTrue(name > -1);
+
+ int pathAfterName = log.indexOf("</path>", name);
+ Assert.assertTrue(pathAfterName > -1);
+
+ Assert.assertTrue(log.indexOf("<action>deleted</action>", name) > -1);
+ Assert.assertTrue(log.indexOf("<action>deleted</action>", name)
+ < pathAfterName);
+ }
+
+ private static final void assertAdded1(String log) {
+ int name = log.indexOf("<name><![CDATA[src/java/org/apache/bcel/"
+ + "Repository.java]]></name>");
+ Assert.assertTrue(name > -1);
+
+ int pathAfterName = log.indexOf("</path>", name);
+ Assert.assertTrue(pathAfterName > -1);
+
+ Assert.assertTrue(log.indexOf("<action>added</action>", name) > -1);
+ Assert.assertTrue(log.indexOf("<action>added</action>", name)
+ < pathAfterName);
+ }
+
+}
Propchange:
ant/sandbox/antlibs/svn/trunk/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnTagDiffTest.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]