From bb8bf43ccff84d5c3385c8fdbf8ac12acbc7f357 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Thu, 24 Dec 2009 19:45:04 +0000 Subject: [PATCH] These libraries are only used by the CVS support. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@24921 71c3de6d-444a-0410-be80-ed276b4c234a --- .../tools/ant/taskdefs/AbstractCvsTask.java | 862 ------------------ .../tools/ant/taskdefs/cvslib/CVSEntry.java | 87 -- .../ant/taskdefs/cvslib/ChangeLogParser.java | 380 -------- .../ant/taskdefs/cvslib/ChangeLogTask.java | 501 ---------- .../ant/taskdefs/cvslib/ChangeLogWriter.java | 104 --- .../tools/ant/taskdefs/cvslib/CvsUser.java | 93 -- .../tools/ant/taskdefs/cvslib/RCSFile.java | 77 -- .../cvslib/RedirectingOutputStream.java | 51 -- .../cvslib/RedirectingStreamHandler.java | 68 -- .../tools/ant/taskdefs/cvslib/package.html | 27 - 10 files changed, 2250 deletions(-) delete mode 100644 core/src/main/java/hudson/org/apache/tools/ant/taskdefs/AbstractCvsTask.java delete mode 100644 core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/CVSEntry.java delete mode 100644 core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java delete mode 100644 core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/ChangeLogTask.java delete mode 100644 core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java delete mode 100644 core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/CvsUser.java delete mode 100644 core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/RCSFile.java delete mode 100644 core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/RedirectingOutputStream.java delete mode 100644 core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/RedirectingStreamHandler.java delete mode 100644 core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/package.html diff --git a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/AbstractCvsTask.java b/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/AbstractCvsTask.java deleted file mode 100644 index 8cf4b9bb29..0000000000 --- a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/AbstractCvsTask.java +++ /dev/null @@ -1,862 +0,0 @@ -/* - * Copyright 2002-2004 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 hudson.org.apache.tools.ant.taskdefs; - -import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Vector; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; -import org.apache.tools.ant.taskdefs.PumpStreamHandler; -import org.apache.tools.ant.taskdefs.LogOutputStream; -import org.apache.tools.ant.taskdefs.Execute; -import org.apache.tools.ant.types.Commandline; -import org.apache.tools.ant.types.Environment; -import org.apache.tools.ant.util.StringUtils; - -/** - * original Cvs.java 1.20 - * - * NOTE: This implementation has been moved here from Cvs.java with - * the addition of some accessors for extensibility. Another task - * can extend this with some customized output processing. - * - * @since Ant 1.5 - */ -public abstract class AbstractCvsTask extends Task { - /** - * Default compression level to use, if compression is enabled via - * setCompression( true ). - */ - public static final int DEFAULT_COMPRESSION_LEVEL = 3; - private static final int MAXIMUM_COMRESSION_LEVEL = 9; - - private Commandline cmd = new Commandline(); - - /** list of Commandline children */ - private Vector vecCommandlines = new Vector(); - - /** - * the CVSROOT variable. - */ - private String cvsRoot; - - /** - * the CVS_RSH variable. - */ - private String cvsRsh; - - /** - * the package/module to check out. - */ - private String[] cvsPackage; - /** - * the tag - */ - private String tag; - /** - * the default command. - */ - private static final String DEFAULT_COMMAND = "checkout"; - /** - * the CVS command to execute. - */ - private String command = null; - - /** - * suppress information messages. - */ - private boolean quiet = false; - - /** - * suppress all messages. - */ - private boolean reallyquiet = false; - - /** - * compression level to use. - */ - private int compression = 0; - - /** - * report only, don't change any files. - */ - private boolean noexec = false; - - /** - * CVS port - */ - private int port = 0; - - /** - * CVS password file - */ - private File passFile = null; - - /** - * the directory where the checked out files should be placed. - */ - private File dest; - - /** whether or not to append stdout/stderr to existing files */ - private boolean append = false; - - /** - * the file to direct standard output from the command. - */ - private File output; - - /** - * the file to direct standard error from the command. - */ - private File error; - - /** - * If true it will stop the build if cvs exits with error. - * Default is false. (Iulian) - */ - private boolean failOnError = false; - - /** - * Create accessors for the following, to allow different handling of - * the output. - */ - private OutputStream outputStream; - private OutputStream errorStream; - private String cvsExe = "cvs"; - - /** empty no-arg constructor*/ - public AbstractCvsTask() { - super(); - } - - public void setCvsExe(String cvsExe) { - this.cvsExe = cvsExe; - } - - /** - * find the handler and instantiate it if it does not exist yet - * @return handler for output and error streams - */ - protected ExecuteStreamHandler getExecuteStreamHandler(InputStream input) { - return new PumpStreamHandler(getOutputStream(), getErrorStream(), input); - } - - /** - * sets a stream to which the output from the cvs executable should be sent - * @param outputStream stream to which the stdout from cvs should go - */ - protected void setOutputStream(OutputStream outputStream) { - - this.outputStream = outputStream; - } - - /** - * access the stream to which the stdout from cvs should go - * if this stream has already been set, it will be returned - * if the stream has not yet been set, if the attribute output - * has been set, the output stream will go to the output file - * otherwise the output will go to ant's logging system - * @return output stream to which cvs' stdout should go to - */ - protected OutputStream getOutputStream() { - - if (this.outputStream == null) { - - if (output != null) { - try { - setOutputStream(new PrintStream( - new BufferedOutputStream( - new FileOutputStream(output - .getPath(), - append)))); - } catch (IOException e) { - throw new BuildException(e, getLocation()); - } - } else { - setOutputStream(new LogOutputStream(this, Project.MSG_INFO)); - } - } - - return this.outputStream; - } - - /** - * sets a stream to which the stderr from the cvs exe should go - * @param errorStream an output stream willing to process stderr - */ - protected void setErrorStream(OutputStream errorStream) { - - this.errorStream = errorStream; - } - - /** - * access the stream to which the stderr from cvs should go - * if this stream has already been set, it will be returned - * if the stream has not yet been set, if the attribute error - * has been set, the output stream will go to the file denoted by the error attribute - * otherwise the stderr output will go to ant's logging system - * @return output stream to which cvs' stderr should go to - */ - protected OutputStream getErrorStream() { - - if (this.errorStream == null) { - - if (error != null) { - - try { - setErrorStream(new PrintStream( - new BufferedOutputStream( - new FileOutputStream(error.getPath(), - append)))); - } catch (IOException e) { - throw new BuildException(e, getLocation()); - } - } else { - setErrorStream(new LogOutputStream(this, Project.MSG_WARN)); - } - } - - return this.errorStream; - } - - /** - * Sets up the environment for toExecute and then runs it. - * @param toExecute the command line to execute - * @throws BuildException if failonError is set to true and the cvs command fails - */ - protected void runCommand(Commandline toExecute) throws BuildException { - // XXX: we should use JCVS (www.ice.com/JCVS) instead of - // command line execution so that we don't rely on having - // native CVS stuff around (SM) - - // We can't do it ourselves as jCVS is GPLed, a third party task - // outside of jakarta repositories would be possible though (SB). - - Environment env = new Environment(); - - if (port > 0) { - Environment.Variable var = new Environment.Variable(); - var.setKey("CVS_CLIENT_PORT"); - var.setValue(String.valueOf(port)); - env.addVariable(var); - } - - /** - * Need a better cross platform integration with , so - * use the same filename. - */ - if (passFile == null) { - - File defaultPassFile = new File( - System.getProperty("cygwin.user.home", - System.getProperty("user.home")) - + File.separatorChar + ".cvspass"); - - if (defaultPassFile.exists()) { - this.setPassfile(defaultPassFile); - } - } - - if (passFile != null) { - if (passFile.isFile() && passFile.canRead()) { - Environment.Variable var = new Environment.Variable(); - var.setKey("CVS_PASSFILE"); - var.setValue(String.valueOf(passFile)); - env.addVariable(var); - log("Using cvs passfile: " + String.valueOf(passFile), - Project.MSG_INFO); - } else if (!passFile.canRead()) { - log("cvs passfile: " + String.valueOf(passFile) - + " ignored as it is not readable", - Project.MSG_WARN); - } else { - log("cvs passfile: " + String.valueOf(passFile) - + " ignored as it is not a file", - Project.MSG_WARN); - } - } - - if (cvsRsh != null) { - Environment.Variable var = new Environment.Variable(); - var.setKey("CVS_RSH"); - var.setValue(String.valueOf(cvsRsh)); - env.addVariable(var); - } - - // - // Just call the getExecuteStreamHandler() and let it handle - // the semantics of instantiation or retrieval. - // - String[] argv = toExecute.getCommandline(); - InputStream input = null; - String inputText = null; - if (new File("/usr/bin/xargs").isFile()) { - // Hudson workaround #864. Check for very long command lines and use xargs whenever possible. - int sz = 0; - for (String arg : argv) { - sz += arg.length() + /*NUL*/1; - } - if (sz > 125000) { - // We are in the danger zone for Linux, which imposes a 128Kb kernel buffer max by default. - // (Need to leave some room open for ENVP.) - ByteArrayOutputStream baos = null; - List _argv = new ArrayList(); - _argv.add("/usr/bin/xargs"); - boolean prefix = true; - LOAD: for (String s : argv) { - if (s.equals("--")) { - // See ChangeLogTask.execute. xargs will try to split up long input into >1 command. - prefix = false; - baos = new ByteArrayOutputStream(); - } else if (prefix) { - _argv.add(s); - } else { - for (byte b : s.getBytes()) { - if (b < 0) { - // XXX we cannot handle non-ASCII chars here, probably. Punt. - baos = null; - break LOAD; - } - // GNU xargs accepts -0, which would be nice, but this is unfortunately not universal. - // The safest approach is to backslash every char, then use \n for separator. - baos.write('\\'); - baos.write(b); - } - baos.write('\n'); - } - } - if (baos != null) { - Logger.getLogger(AbstractCvsTask.class.getName()).log(Level.INFO, "Using xargs to run very long command line ({0} bytes)", sz); - input = new ByteArrayInputStream(baos.toByteArray()); - inputText = baos.toString(); - argv = _argv.toArray(new String[_argv.size()]); - } - } - } - Execute exe = new Execute(getExecuteStreamHandler(input), null); - - exe.setAntRun(getProject()); - if (dest == null) { - dest = getProject().getBaseDir(); - } - - if (!dest.exists()) { - dest.mkdirs(); - } - - exe.setWorkingDirectory(dest); - exe.setCommandline(argv); - exe.setEnvironment(env.getVariables()); - - try { - String actualCommandLine = executeToString(exe); - log(actualCommandLine, Project.MSG_VERBOSE); - int retCode = exe.execute(); - log("retCode=" + retCode, Project.MSG_DEBUG); - /*Throw an exception if cvs exited with error. (Iulian)*/ - if (failOnError && Execute.isFailure(retCode)) { - throw new BuildException("cvs exited with error code " - + retCode - + StringUtils.LINE_SEP - + "Command line was [" - + actualCommandLine + "] in " + dest + - "\nInput text:\nSTART==>" + inputText + "<==END", getLocation()); - } - } catch (IOException e) { - if (failOnError) { - throw new BuildException(e, getLocation()); - } else { - log("Caught exception: " + e.getMessage(), Project.MSG_WARN); - } - } catch (BuildException e) { - if (failOnError) { - throw(e); - } else { - Throwable t = e.getException(); - if (t == null) { - t = e; - } - log("Caught exception: " + t.getMessage(), Project.MSG_WARN); - } - } catch (Exception e) { - if (failOnError) { - throw new BuildException(e, getLocation()); - } else { - log("Caught exception: " + e.getMessage(), Project.MSG_WARN); - } - } finally { - if (outputStream != null) { - try { - outputStream.close(); - } catch (IOException e) { - //ignore - } - } - if (errorStream != null) { - try { - errorStream.close(); - } catch (IOException e) { - //ignore - } - } - } - } - - /** - * do the work - * @throws BuildException if failonerror is set to true and the cvs command fails. - */ - public void execute() throws BuildException { - - String savedCommand = getCommand(); - - if (this.getCommand() == null && vecCommandlines.size() == 0) { - // re-implement legacy behaviour: - this.setCommand(AbstractCvsTask.DEFAULT_COMMAND); - } - - String c = this.getCommand(); - Commandline cloned = null; - if (c != null) { - cloned = (Commandline) cmd.clone(); - cloned.createArgument(true).setLine(c); - this.addConfiguredCommandline(cloned, true); - } - - try { - for (int i = 0; i < vecCommandlines.size(); i++) { - this.runCommand((Commandline) vecCommandlines.elementAt(i)); - } - } finally { - if (cloned != null) { - removeCommandline(cloned); - } - setCommand(savedCommand); - } - } - - private String executeToString(Execute execute) { - - StringBuffer stringBuffer = - new StringBuffer(Commandline.describeCommand(execute - .getCommandline())); - - String newLine = StringUtils.LINE_SEP; - String[] variableArray = execute.getEnvironment(); - - if (variableArray != null) { - stringBuffer.append(newLine); - stringBuffer.append(newLine); - stringBuffer.append("environment:"); - stringBuffer.append(newLine); - for (int z = 0; z < variableArray.length; z++) { - stringBuffer.append(newLine); - stringBuffer.append("\t"); - stringBuffer.append(variableArray[z]); - } - } - - return stringBuffer.toString(); - } - - /** - * The CVSROOT variable. - * - * @param root the CVSROOT variable - */ - public void setCvsRoot(String root) { - - // Check if not real cvsroot => set it to null - if (root != null) { - if (root.trim().equals("")) { - root = null; - } - } - - this.cvsRoot = root; - } - - /** - * access the CVSROOT variable - * @return CVSROOT - */ - public String getCvsRoot() { - - return this.cvsRoot; - } - - /** - * The CVS_RSH variable. - * - * @param rsh the CVS_RSH variable - */ - public void setCvsRsh(String rsh) { - // Check if not real cvsrsh => set it to null - if (rsh != null) { - if (rsh.trim().equals("")) { - rsh = null; - } - } - - this.cvsRsh = rsh; - } - - /** - * access the CVS_RSH variable - * @return the CVS_RSH variable - */ - public String getCvsRsh() { - - return this.cvsRsh; - } - - /** - * Port used by CVS to communicate with the server. - * - * @param port port of CVS - */ - public void setPort(int port) { - this.port = port; - } - - /** - * access the port of CVS - * @return the port of CVS - */ - public int getPort() { - - return this.port; - } - - /** - * Password file to read passwords from. - * - * @param passFile password file to read passwords from - */ - public void setPassfile(File passFile) { - this.passFile = passFile; - } - - /** - * find the password file - * @return password file - */ - public File getPassFile() { - - return this.passFile; - } - - /** - * The directory where the checked out files should be placed. - * - *

Note that this is different from CVS's -d command line - * switch as Ant will never shorten pathnames to avoid empty - * directories.

- * - * @param dest directory where the checked out files should be placed - */ - public void setDest(File dest) { - this.dest = dest; - } - - /** - * get the file where the checked out files should be placed - * - * @return directory where the checked out files should be placed - */ - public File getDest() { - - return this.dest; - } - - /** - * The package/module to operate upon. - * - * @param p package or module to operate upon - */ - public void setPackage(String... p) { - this.cvsPackage = p; - } - - /** - * access the package or module to operate upon - * - * @return package/module - */ - public String[] getPackage() { - - return this.cvsPackage; - } - /** - * tag or branch - * @return tag or branch - * @since ant 1.6.1 - */ - public String getTag() { - return tag; - } - - /** - * The tag of the package/module to operate upon. - * @param p tag - */ - public void setTag(String p) { - // Check if not real tag => set it to null - if (p != null && p.trim().length() > 0) { - tag = p; - addCommandArgument("-r" + p); - } - } - - /** - * This needs to be public to allow configuration - * of commands externally. - * @param arg command argument - */ - public void addCommandArgument(String arg) { - this.addCommandArgument(cmd, arg); - } - - /** - * This method adds a command line argument to an external command. - * - * I do not understand what this method does in this class ??? - * particularly not why it is public ???? - * AntoineLL July 23d 2003 - * - * @param c command line to which one argument should be added - * @param arg argument to add - */ - public void addCommandArgument(Commandline c, String arg) { - c.createArgument().setValue(arg); - } - - - /** - * Use the most recent revision no later than the given date. - * @param p a date as string in a format that the CVS executable can understand - * see man cvs - */ - public void setDate(String p) { - if (p != null && p.trim().length() > 0) { - addCommandArgument("-D"); - addCommandArgument(p); - } - } - - /** - * The CVS command to execute. - * - * This should be deprecated, it is better to use the Commandline class ? - * AntoineLL July 23d 2003 - * - * @param c a command as string - */ - public void setCommand(String c) { - this.command = c; - } - /** - * accessor to a command line as string - * - * This should be deprecated - * AntoineLL July 23d 2003 - * - * @return command line as string - */ - public String getCommand() { - return this.command; - } - - /** - * If true, suppress informational messages. - * @param q if true, suppress informational messages - */ - public void setQuiet(boolean q) { - quiet = q; - } - - /** - * If true, suppress all messages. - * @param q if true, suppress all messages - * @since Ant 1.6 - */ - public void setReallyquiet(boolean q) { - reallyquiet = q; - } - - - /** - * If true, report only and don't change any files. - * - * @param ne if true, report only and do not change any files. - */ - public void setNoexec(boolean ne) { - noexec = ne; - } - - /** - * The file to direct standard output from the command. - * @param output a file to which stdout should go - */ - public void setOutput(File output) { - this.output = output; - } - - /** - * The file to direct standard error from the command. - * - * @param error a file to which stderr should go - */ - public void setError(File error) { - this.error = error; - } - - /** - * Whether to append output/error when redirecting to a file. - * @param value true indicated you want to append - */ - public void setAppend(boolean value) { - this.append = value; - } - - /** - * Stop the build process if the command exits with - * a return code other than 0. - * Defaults to false. - * @param failOnError stop the build process if the command exits with - * a return code other than 0 - */ - public void setFailOnError(boolean failOnError) { - this.failOnError = failOnError; - } - - /** - * Configure a commandline element for things like cvsRoot, quiet, etc. - * @param c the command line which will be configured - * if the commandline is initially null, the function is a noop - * otherwise the function append to the commandline arguments concerning - *
    - *
  • - * cvs package - *
  • - *
  • - * compression - *
  • - *
  • - * quiet or reallyquiet - *
  • - *
  • cvsroot
  • - *
  • noexec
  • - *
- */ - protected void configureCommandline(Commandline c) { - if (c == null) { - return; - } - c.setExecutable(cvsExe); - if (cvsPackage != null) { - for (String s : cvsPackage) - c.createArgument().setValue(s); - } - if (this.compression > 0 && this.compression <= MAXIMUM_COMRESSION_LEVEL) { - c.createArgument(true).setValue("-z" + this.compression); - } - if (quiet && !reallyquiet) { - c.createArgument(true).setValue("-q"); - } - if (reallyquiet) { - c.createArgument(true).setValue("-Q"); - } - if (noexec) { - c.createArgument(true).setValue("-n"); - } - if (cvsRoot != null) { - c.createArgument(true).setLine("-d" + cvsRoot); - } - } - - /** - * remove a particular command from a vector of command lines - * @param c command line which should be removed - */ - protected void removeCommandline(Commandline c) { - vecCommandlines.removeElement(c); - } - - /** - * Adds direct command-line to execute. - * @param c command line to execute - */ - public void addConfiguredCommandline(Commandline c) { - this.addConfiguredCommandline(c, false); - } - - /** - * Configures and adds the given Commandline. - * @param c commandline to insert - * @param insertAtStart If true, c is - * inserted at the beginning of the vector of command lines - */ - public void addConfiguredCommandline(Commandline c, - boolean insertAtStart) { - if (c == null) { - return; - } - this.configureCommandline(c); - if (insertAtStart) { - vecCommandlines.insertElementAt(c, 0); - } else { - vecCommandlines.addElement(c); - } - } - - /** - * If set to a value 1-9 it adds -zN to the cvs command line, else - * it disables compression. - * @param level compression level 1 to 9 - */ - public void setCompressionLevel(int level) { - this.compression = level; - } - - /** - * If true, this is the same as compressionlevel="3". - * - * @param usecomp If true, turns on compression using default - * level, AbstractCvsTask.DEFAULT_COMPRESSION_LEVEL. - */ - public void setCompression(boolean usecomp) { - setCompressionLevel(usecomp - ? AbstractCvsTask.DEFAULT_COMPRESSION_LEVEL : 0); - } - -} \ No newline at end of file diff --git a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/CVSEntry.java b/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/CVSEntry.java deleted file mode 100644 index 95f0957b84..0000000000 --- a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/CVSEntry.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2002,2004 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 hudson.org.apache.tools.ant.taskdefs.cvslib; - -import java.util.Date; -import java.util.Vector; - -/** - * CVS Entry. - * - * @version $Revision$ $Date$ - */ -class CVSEntry { - private Date m_date; - private String m_author; - private final String m_comment; - private final Vector m_files = new Vector(); - - public CVSEntry(Date date, String author, String comment) { - m_date = date; - m_author = author; - m_comment = comment; - } - - public void addFile(String file, String fullName, String revision, String previousRevision, String branch, boolean dead) { - m_files.addElement(new RCSFile(file, fullName, revision, previousRevision, branch, dead)); - } - - // maybe null, in case of error - Date getDate() { - return m_date; - } - - void setAuthor(final String author) { - m_author = author; - } - - String getAuthor() { - return m_author; - } - - String getComment() { - return m_comment; - } - - Vector getFiles() { - return m_files; - } - - /** - * Checks if any of the entries include a change to a branch. - * - * @param branch - * can be null to indicate the trunk. - */ - public boolean containsBranch(String branch) { - for (RCSFile file : m_files) { - String b = file.getBranch(); - if(b==null && branch==null) - return true; - if(b==null || branch==null) - continue; - if(b.equals(branch)) - return true; - } - return false; - } - - public String toString() { - return '['+getAuthor() + "," + getDate() + "," + getFiles() + "," - + getComment()+']'; - } -} diff --git a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java b/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java deleted file mode 100644 index 0d5c4f6c5e..0000000000 --- a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java +++ /dev/null @@ -1,380 +0,0 @@ -/* - * Copyright 2002-2004 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 hudson.org.apache.tools.ant.taskdefs.cvslib; -// patched to work around http://issues.apache.org/bugzilla/show_bug.cgi?id=38583 - -import org.apache.tools.ant.Project; -import org.apache.commons.io.FileUtils; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TimeZone; -import java.util.logging.Logger; -import java.util.logging.Level; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.io.File; -import java.io.IOException; - -/** - * A class used to parse the output of the CVS log command. - * - * @version $Revision$ $Date$ - */ -class ChangeLogParser { - //private static final int GET_ENTRY = 0; - private static final int GET_FILE = 1; - private static final int GET_DATE = 2; - private static final int GET_COMMENT = 3; - private static final int GET_REVISION = 4; - private static final int GET_PREVIOUS_REV = 5; - private static final int GET_SYMBOLIC_NAMES = 6; - - /** - * input format for dates read in from cvs log. - * - * Some users reported that they see different formats, - * so this is extended from original Ant version to cover different formats. - * - *

- * KK: {@link SimpleDateFormat} is not thread safe, so make it per-instance. - */ - private final SimpleDateFormat[] c_inputDate - = new SimpleDateFormat[]{ - new SimpleDateFormat("yyyy/MM/dd HH:mm:ss Z"), - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"), - new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"), - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), - }; - - { - TimeZone utc = TimeZone.getTimeZone("UTC"); - for (SimpleDateFormat df : c_inputDate) { - df.setTimeZone(utc); - } - } - - //The following is data used while processing stdout of CVS command - private String m_file; - private String m_fullName; - private String m_date; - private String m_author; - private String m_comment; - private String m_revision; - private String m_previousRevision; - /** - * All branches available on the current file. - * Keyed by branch revision prefix (like "1.2.3." if files in the branch have revision numbers like - * "1.2.3.4") and the value is the branch name. - */ - private final Map branches = new HashMap(); - /** - * True if the log record indicates deletion; - */ - private boolean m_dead; - - private int m_status = GET_FILE; - - /** rcs entries */ - private final Hashtable m_entries = new Hashtable(); - - private final ChangeLogTask owner; - - public ChangeLogParser(ChangeLogTask owner) { - this.owner = owner; - } - - /** - * Get a list of rcs entries as an array. - * - * @return a list of rcs entries as an array - */ - CVSEntry[] getEntrySetAsArray() { - final CVSEntry[] array = new CVSEntry[ m_entries.size() ]; - Enumeration e = m_entries.elements(); - int i = 0; - while (e.hasMoreElements()) { - array[i++] = (CVSEntry) e.nextElement(); - } - return array; - } - - private boolean dead = false; - private String previousLine = null; - - /** - * Receive notification about the process writing - * to standard output. - */ - public void stdout(final String line) { - if(dead) - return; - try { - switch(m_status) { - case GET_FILE: - // make sure attributes are reset when - // working on a 'new' file. - reset(); - processFile(line); - break; - case GET_SYMBOLIC_NAMES: - processSymbolicName(line); - break; - - case GET_REVISION: - processRevision(line); - break; - - case GET_DATE: - processDate(line); - break; - - case GET_COMMENT: - processComment(line); - break; - - case GET_PREVIOUS_REV: - processGetPreviousRevision(line); - break; - } - } catch (Exception e) { - // we don't know how to handle the input any more. don't accept any more input - dead = true; - } - } - - /** - * Process a line while in "GET_COMMENT" state. - * - * @param line the line - */ - private void processComment(final String line) { - final String lineSeparator = System.getProperty("line.separator"); - if (line.startsWith("======")) { - //We have ended changelog for that particular file - //so we can save it - final int end - = m_comment.length() - lineSeparator.length(); //was -1 - m_comment = m_comment.substring(0, end); - saveEntry(); - m_status = GET_FILE; - } else if (null != previousLine && previousLine.startsWith("----------------------------")) { - if (line.startsWith("revision")) { - final int end - = m_comment.length() - lineSeparator.length(); //was -1 - m_comment = m_comment.substring(0, end); - m_status = GET_PREVIOUS_REV; - - processGetPreviousRevision(line); - } else { - m_comment += previousLine + lineSeparator + line + lineSeparator; - } - - previousLine = null; - } else if (line.startsWith("----------------------------")) { - if (null != previousLine) { - m_comment += previousLine + lineSeparator; - } - previousLine = line; - } else { - m_comment += line + lineSeparator; - } - } - - /** - * Process a line while in "GET_FILE" state. - * - * @param line the line - */ - private void processFile(final String line) { - if (line.startsWith("Working file:")) { - m_file = line.substring(14, line.length()); - - File repo = new File(new File(owner.getDir(), m_file).getParentFile(), "CVS/Repository"); - try { - String module = FileUtils.readFileToString(repo, null);// not sure what encoding CVS uses. - String simpleName = m_file.substring(m_file.lastIndexOf('/')+1); - m_fullName = '/'+module.trim()+'/'+simpleName; - } catch (IOException e) { - // failed to read - LOGGER.log(Level.WARNING, "Failed to read CVS/Repository at "+repo,e); - m_fullName = null; - } - - m_status = GET_SYMBOLIC_NAMES; - } - } - - /** - * Obtains the revision name list - */ - private void processSymbolicName(String line) { - if (line.startsWith("\t")) { - line = line.trim(); - int idx = line.lastIndexOf(':'); - if(idx<0) { - // ??? - return; - } - - String symbol = line.substring(0,idx); - Matcher m = DOT_PATTERN.matcher(line.substring(idx + 2)); - if(!m.matches()) - return; // not a branch name - - branches.put(m.group(1)+m.group(3)+'.',symbol); - } else - if (line.startsWith("keyword substitution:")) { - m_status = GET_REVISION; - } - } - - private static final Pattern DOT_PATTERN = Pattern.compile("(([0-9]+\\.)+)0\\.([0-9]+)"); - - /** - * Process a line while in "REVISION" state. - * - * @param line the line - */ - private void processRevision(final String line) { - if (line.startsWith("revision")) { - m_revision = line.substring(9); - m_status = GET_DATE; - } else if (line.startsWith("======")) { - //There was no revisions in this changelog - //entry so lets move unto next file - m_status = GET_FILE; - } - } - - /** - * Process a line while in "DATE" state. - * - * @param line the line - */ - private void processDate(final String line) { - if (line.startsWith("date:")) { - int idx = line.indexOf(";"); - m_date = line.substring(6, idx); - String lineData = line.substring(idx + 1); - m_author = lineData.substring(10, lineData.indexOf(";")); - - m_status = GET_COMMENT; - - m_dead = lineData.indexOf("state: dead;")!=-1; - - //Reset comment to empty here as we can accumulate multiple lines - //in the processComment method - m_comment = ""; - } - } - - /** - * Process a line while in "GET_PREVIOUS_REVISION" state. - * - * @param line the line - */ - private void processGetPreviousRevision(final String line) { - if (!line.startsWith("revision")) { - throw new IllegalStateException("Unexpected line from CVS: " - + line); - } - m_previousRevision = line.substring(9); - - saveEntry(); - - m_revision = m_previousRevision; - m_status = GET_DATE; - } - - /** - * Utility method that saves the current entry. - */ - private void saveEntry() { - final String entryKey = m_date + m_author + m_comment; - CVSEntry entry; - if (!m_entries.containsKey(entryKey)) { - entry = new CVSEntry(parseDate(m_date), m_author, m_comment); - m_entries.put(entryKey, entry); - } else { - entry = m_entries.get(entryKey); - } - - String branch = findBranch(m_revision); - - owner.log("Recorded a change: "+m_date+','+m_author+','+m_revision+"(branch="+branch+"),"+m_comment,Project.MSG_VERBOSE); - - entry.addFile(m_file, m_fullName, m_revision, m_previousRevision, branch, m_dead); - } - - /** - * Finds the branch name that matches the revision, or null if not found. - */ - private String findBranch(String revision) { - if(revision==null) return null; // defensive check - for (Entry e : branches.entrySet()) { - if(revision.startsWith(e.getKey()) && revision.substring(e.getKey().length()).indexOf('.')==-1) - return e.getValue(); - } - return null; - } - - /** - * Parse date out from expected format. - * - * @param date the string holding dat - * @return the date object or null if unknown date format - */ - private Date parseDate(String date) { - for (SimpleDateFormat df : c_inputDate) { - try { - return df.parse(date); - } catch (ParseException e) { - // try next if one fails - } - } - - // nothing worked - owner.log("Failed to parse "+date+"\n", Project.MSG_ERR); - //final String message = REZ.getString( "changelog.bat-date.error", date ); - //getContext().error( message ); - return null; - } - - /** - * reset all internal attributes except status. - */ - private void reset() { - m_file = null; - m_fullName = null; - m_date = null; - m_author = null; - m_comment = null; - m_revision = null; - m_previousRevision = null; - m_dead = false; - branches.clear(); - } - - private static final Logger LOGGER = Logger.getLogger(ChangeLogParser.class.getName()); -} diff --git a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/ChangeLogTask.java b/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/ChangeLogTask.java deleted file mode 100644 index 55fe5efb20..0000000000 --- a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/ChangeLogTask.java +++ /dev/null @@ -1,501 +0,0 @@ -/* - * Copyright 2002-2004 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 hudson.org.apache.tools.ant.taskdefs.cvslib; - -import hudson.util.ForkOutputStream; -import hudson.org.apache.tools.ant.taskdefs.AbstractCvsTask; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.LogOutputStream; -import org.apache.tools.ant.taskdefs.cvslib.CvsVersion; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.Enumeration; -import java.util.List; -import java.util.Properties; -import java.util.Vector; -import java.util.StringTokenizer; -import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; - -/** - * Examines the output of cvs log and group related changes together. - * - * It produces an XML output representing the list of changes. - *

- * <!-- Root element -->
- * <!ELEMENT changelog (entry+)>
- * <!-- CVS Entry -->
- * <!ELEMENT entry (date,author,file+,msg)>
- * <!-- Date of cvs entry -->
- * <!ELEMENT date (#PCDATA)>
- * <!-- Author of change -->
- * <!ELEMENT author (#PCDATA)>
- * <!-- List of files affected -->
- * <!ELEMENT msg (#PCDATA)>
- * <!-- File changed -->
- * <!ELEMENT file (name,revision,prevrevision?)>
- * <!-- Name of the file -->
- * <!ELEMENT name (#PCDATA)>
- * <!-- Revision number -->
- * <!ELEMENT revision (#PCDATA)>
- * <!-- Previous revision number -->
- * <!ELEMENT prevrevision (#PCDATA)>
- * 
- * - * @version $Revision$ $Date$ - * @since Ant 1.5 - * @ant.task name="cvschangelog" category="scm" - */ -public class ChangeLogTask extends AbstractCvsTask { - /** User list */ - private File m_usersFile; - - /** User list */ - private Vector m_cvsUsers = new Vector(); - - /** Input dir */ - private File m_dir; - - /** Output */ - private OutputStream m_output; - - /** The earliest date at which to start processing entries. */ - private Date m_start; - - /** The latest date at which to stop processing entries. */ - private Date m_stop; - - /** - * To filter out change logs for a certain branch, this variable will be the branch name. - * Otherwise null. - */ - private String branch; - - /** - * Filesets containing list of files against which the cvs log will be - * performed. If empty then all files will in the working directory will - * be checked. - */ - private List m_filesets = new ArrayList(); - - - /** - * Set the base dir for cvs. - * - * @param dir The new dir value - */ - public void setDir(final File dir) { - m_dir = dir; - } - - public File getDir() { - return m_dir; - } - - - /** - * Set the output stream for the log. - * - * @param destfile The new destfile value - */ - public void setDeststream(final OutputStream destfile) { - m_output = destfile; - } - - - /** - * Set a lookup list of user names & addresses - * - * @param usersFile The file containing the users info. - */ - public void setUsersfile(final File usersFile) { - m_usersFile = usersFile; - } - - - /** - * Add a user to list changelog knows about. - * - * @param user the user - */ - public void addUser(final CvsUser user) { - m_cvsUsers.addElement(user); - } - - - /** - * Set the date at which the changelog should start. - * - * @param start The date at which the changelog should start. - */ - public void setStart(final Date start) { - m_start = start; - } - - public void setBranch(String branch) { - this.branch = branch; - } - - - /** - * Set the date at which the changelog should stop. - * - * @param stop The date at which the changelog should stop. - */ - public void setEnd(final Date stop) { - m_stop = stop; - } - - - /** - * 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; - - setStart(new Date(time)); - } - - - /** - * Adds a file about which cvs logs will be generated. - * - * @param fileName - * fileName relative to {@link #setDir(File)}. - */ - public void addFile(String fileName) { - m_filesets.add(fileName); - } - - public void setFile(List files) { - m_filesets = files; - } - - - // XXX crude but how else to track the parser & handler and still pass to super impl? - private ChangeLogParser parser; - private RedirectingStreamHandler handler; - /** - * Execute task - * - * @exception BuildException if something goes wrong executing the - * cvs command - */ - public void execute() throws BuildException { - File savedDir = m_dir; // may be altered in validate - - try { - - validate(); - final Properties userList = new Properties(); - - loadUserlist(userList); - - for (Enumeration e = m_cvsUsers.elements(); - e.hasMoreElements();) { - final CvsUser user = (CvsUser) e.nextElement(); - - user.validate(); - userList.put(user.getUserID(), user.getDisplayname()); - } - - - setCommand("log"); - - if (m_filesets.isEmpty() || m_filesets.size()>10) { - // if we are going to get logs on large number of files, - // (or if m_files is not specified at all, in which case all the files in the directory is subjec, - // then it's worth spending little time to figure out if we can use - // -S for speed up - - CvsVersion myCvsVersion = new CvsVersion(); - myCvsVersion.setProject(getProject()); - myCvsVersion.setTaskName("cvsversion"); - myCvsVersion.setCvsRoot(getCvsRoot()); - myCvsVersion.setCvsRsh(getCvsRsh()); - myCvsVersion.setPassfile(getPassFile()); - myCvsVersion.setDest(m_dir); - myCvsVersion.execute(); - if (supportsCvsLogWithSOption(myCvsVersion.getClientVersion()) - && supportsCvsLogWithSOption(myCvsVersion.getServerVersion())) { - addCommandArgument("-S"); - } - } - if (null != m_start) { - final SimpleDateFormat outputDate = - new SimpleDateFormat("yyyy-MM-dd"); - - // Kohsuke patch: - // probably due to timezone difference between server/client and - // the lack of precise specification in the protocol or something, - // sometimes the java.net CVS server (and probably others) don't - // always report all the changes that have happened in the given day. - // so let's take the date range bit wider, to make sure that - // the server sends us all the logs that we care. - // - // the only downside of this change is that it will increase the traffic - // unnecessarily, but given that in Hudson we already narrow down the scope - // by specifying files, this should be acceptable increase. - - Date safeStart = new Date(m_start.getTime()-1000L*60*60*24); - - // Kohsuke patch until here - - // We want something of the form: -d ">=YYYY-MM-dd" - final String dateRange = ">=" + outputDate.format(safeStart); - - // Supply '-d' as a separate argument - Bug# 14397 - addCommandArgument("-d"); - addCommandArgument(dateRange); - } - - // Check if list of files to check has been specified - if (!m_filesets.isEmpty()) { - addCommandArgument("--"); - for (String file : m_filesets) { - addCommandArgument(file); - } - } - - parser = new ChangeLogParser(this); - - log("Running "+getCommand()+" at "+m_dir, Project.MSG_VERBOSE); - - setDest(m_dir); - try { - super.execute(); - } finally { - final String errors = handler.getErrors(); - - if (null != errors && errors.length()!=0) { - log(errors, Project.MSG_ERR); - } - } - - final CVSEntry[] entrySet = parser.getEntrySetAsArray(); - final CVSEntry[] filteredEntrySet = filterEntrySet(entrySet); - - replaceAuthorIdWithName(userList, filteredEntrySet); - - writeChangeLog(filteredEntrySet); - - } finally { - m_dir = savedDir; - } - } - protected @Override ExecuteStreamHandler getExecuteStreamHandler(InputStream input) { - return handler = new RedirectingStreamHandler( - // stdout goes to the changelog parser, - // but we also send this to Ant logger so that we can see it at sufficient debug level - new ForkOutputStream(new RedirectingOutputStream(parser), - new LogOutputStream(this,Project.MSG_VERBOSE)), - // stderr goes to the logger, too - new LogOutputStream(this,Project.MSG_WARN), - - input); - } - - private static final long VERSION_1_11_2 = 11102; - private static final long MULTIPLY = 100; - /** - * Rip off from {@link CvsVersion#supportsCvsLogWithSOption()} - * but we need to check both client and server. - */ - private boolean supportsCvsLogWithSOption(String versionString) { - if (versionString == null) { - return false; - } - StringTokenizer mySt = new StringTokenizer(versionString, "."); - long counter = MULTIPLY * MULTIPLY; - long version = 0; - while (mySt.hasMoreTokens()) { - String s = mySt.nextToken(); - int startpos; - // find the first digit char - for (startpos = 0; startpos < s.length(); startpos++) - if (Character.isDigit(s.charAt(startpos))) - break; - // ... and up to the end of this digit set - int i; - for (i = startpos; i < s.length(); i++) { - if (!Character.isDigit(s.charAt(i))) { - break; - } - } - String s2 = s.substring(startpos, i); - version = version + counter * Long.parseLong(s2); - if (counter == 1) { - break; - } - counter = counter / MULTIPLY; - } - return (version >= VERSION_1_11_2); - } - - /** - * Validate the parameters specified for task. - * - * @throws BuildException if fails validation checks - */ - private void validate() - throws BuildException { - if (null == m_dir) { - m_dir = getProject().getBaseDir(); - } - if (null == m_output) { - final String message = "Destfile must be set."; - - throw new BuildException(message); - } - if (!m_dir.exists()) { - final String message = "Cannot find base dir " - + m_dir.getAbsolutePath(); - - throw new BuildException(message); - } - if (null != m_usersFile && !m_usersFile.exists()) { - final String message = "Cannot find user lookup list " - + m_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 != m_usersFile) { - try { - userList.load(new FileInputStream(m_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 CVSEntry[] filterEntrySet(final CVSEntry[] entrySet) { - log("Filtering entries",Project.MSG_VERBOSE); - - final Vector results = new Vector(); - - for (int i = 0; i < entrySet.length; i++) { - final CVSEntry cvsEntry = entrySet[i]; - final Date date = cvsEntry.getDate(); - - if(date==null) { - // skip dates that didn't parse. - log("Filtering out "+cvsEntry+" because it has no date",Project.MSG_VERBOSE); - continue; - } - - if (null != m_start && m_start.after(date)) { - //Skip dates that are too early - log("Filtering out "+cvsEntry+" because it's too early compare to "+m_start,Project.MSG_VERBOSE); - continue; - } - if (null != m_stop && m_stop.before(date)) { - //Skip dates that are too late - log("Filtering out "+cvsEntry+" because it's too late compare to "+m_stop,Project.MSG_VERBOSE); - continue; - } - //if tag was specified, it takes care of branches or HEAD, because it does not go out of one. Otherwise HEAD or specified Brach should be filtered - if (null == getTag() && !cvsEntry.containsBranch(branch)) { - // didn't match the branch - log("Filtering out "+cvsEntry+" because it didn't match the branch '"+branch+"'",Project.MSG_VERBOSE); - continue; - } - results.addElement(cvsEntry); - } - - final CVSEntry[] resultArray = new CVSEntry[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 CVSEntry[] entrySet) { - for (int i = 0; i < entrySet.length; i++) { - - final CVSEntry 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 CVSEntry[] entrySet) - throws BuildException { - OutputStream output = null; - - try { - output = m_output; - - final PrintWriter writer = - new PrintWriter(new OutputStreamWriter(output, "UTF-8")); - - final ChangeLogWriter serializer = new ChangeLogWriter(); - - 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 { - if (null != output) { - try { - output.close(); - } catch (final IOException ioe) { - } - } - } - } -} \ No newline at end of file diff --git a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java b/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java deleted file mode 100644 index 43adbacab9..0000000000 --- a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2002-2004 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 hudson.org.apache.tools.ant.taskdefs.cvslib; - -import org.apache.commons.lang.time.FastDateFormat; - -import java.io.PrintWriter; -import java.util.Enumeration; -import java.util.TimeZone; - -/** - * Class used to generate an XML changelog. - * - * @version $Revision$ $Date$ - */ -class ChangeLogWriter { - private static final TimeZone UTC = TimeZone.getTimeZone("UTC"); - - /** output format for dates written to xml file */ - private static final FastDateFormat c_outputDate - = FastDateFormat.getInstance("yyyy-MM-dd", UTC); - /** output format for times written to xml file */ - private static final FastDateFormat c_outputTime - = FastDateFormat.getInstance("HH:mm", UTC); - - /** - * 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 CVSEntry[] entries) { - output.println(""); - output.println(""); - for (int i = 0; i < entries.length; i++) { - final CVSEntry entry = entries[i]; - - printEntry(output, entry); - } - output.println(""); - 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 CVSEntry entry) { - output.println("\t"); - output.println("\t\t" + c_outputDate.format(entry.getDate()) - + ""); - output.println("\t\t"); - output.println("\t\t"); - - final Enumeration enumeration = entry.getFiles().elements(); - - while (enumeration.hasMoreElements()) { - final RCSFile file = (RCSFile) enumeration.nextElement(); - - output.println("\t\t"); - output.println("\t\t\t" + file.getName() + ""); - if(file.getFullName()!=null) - output.println("\t\t\t" + file.getFullName() + ""); - output.println("\t\t\t" + file.getRevision() - + ""); - - final String previousRevision = file.getPreviousRevision(); - - if (previousRevision != null) { - output.println("\t\t\t" + previousRevision - + ""); - } - - if(file.isDead()) - output.println("\t\t\t"); - - output.println("\t\t"); - } - output.println("\t\t"); - output.println("\t"); - } -} - diff --git a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/CvsUser.java b/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/CvsUser.java deleted file mode 100644 index 3502c67075..0000000000 --- a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/CvsUser.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2002-2004 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 hudson.org.apache.tools.ant.taskdefs.cvslib; - -import org.apache.tools.ant.BuildException; - -/** - * Represents a CVS user with a userID and a full name. - * - * @version $Revision$ $Date$ - */ -public class CvsUser { - /** The user's Id */ - private String m_userID; - /** The user's full name */ - private String m_displayName; - - - /** - * Set the user's fullname - * - * @param displayName the user's full name - */ - public void setDisplayname(final String displayName) { - m_displayName = displayName; - } - - - /** - * Set the user's id - * - * @param userID the user's new id value. - */ - public void setUserid(final String userID) { - m_userID = userID; - } - - - /** - * Get the user's id. - * - * @return The userID value - */ - String getUserID() { - return m_userID; - } - - - /** - * Get the user's full name - * - * @return the user's full name - */ - String getDisplayname() { - return m_displayName; - } - - - /** - * validate that this object is configured. - * - * @exception BuildException if the instance has not be correctly - * configured. - */ - void validate() throws BuildException { - if (null == m_userID) { - final String message = "Username attribute must be set."; - - throw new BuildException(message); - } - if (null == m_displayName) { - final String message = - "Displayname attribute must be set for userID " + m_userID; - - throw new BuildException(message); - } - } -} - diff --git a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/RCSFile.java b/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/RCSFile.java deleted file mode 100644 index 0e8972419b..0000000000 --- a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/RCSFile.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2002-2004 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 hudson.org.apache.tools.ant.taskdefs.cvslib; - -/** - * Represents a RCS File change. - * - * @version $Revision$ $Date$ - */ -class RCSFile { - private String m_name; - private String m_fullName; - private String m_revision; - private String m_previousRevision; - private boolean m_dead; - private String m_branch; - - - RCSFile(final String name, - final String fullName, - final String revision, - final String previousRevision, - final String branch, - final boolean dead) { - m_name = name; - m_fullName = fullName; - m_revision = revision; - if (!revision.equals(previousRevision)) { - m_previousRevision = previousRevision; - } - m_branch = branch; - m_dead = dead; - } - - - String getName() { - return m_name; - } - - public String getFullName() { - return m_fullName; - } - - String getRevision() { - return m_revision; - } - - String getPreviousRevision() { - return m_previousRevision; - } - - boolean isDead() { - return m_dead; - } - - /** - * Gets the name of this branch, if available. - */ - String getBranch() { - return m_branch; - } -} - diff --git a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/RedirectingOutputStream.java b/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/RedirectingOutputStream.java deleted file mode 100644 index b3a8adf80c..0000000000 --- a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/RedirectingOutputStream.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2002,2004 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 hudson.org.apache.tools.ant.taskdefs.cvslib; - -import org.apache.tools.ant.taskdefs.LogOutputStream; - -/** - * A dummy stream that just passes stuff to the parser. - * - * @version $Revision$ $Date$ - */ -class RedirectingOutputStream - extends LogOutputStream { - private final ChangeLogParser parser; - - - /** - * Creates a new instance of this class. - * - * @param parser the parser to which output is sent. - */ - public RedirectingOutputStream(final ChangeLogParser parser) { - super(null, 0); - this.parser = parser; - } - - - /** - * Logs a line to the log system of ant. - * - * @param line the line to log. - */ - protected void processLine(final String line) { - parser.stdout(line); - } -} - diff --git a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/RedirectingStreamHandler.java b/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/RedirectingStreamHandler.java deleted file mode 100644 index 8058a7bd48..0000000000 --- a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/RedirectingStreamHandler.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2002,2004 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 hudson.org.apache.tools.ant.taskdefs.cvslib; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.PumpStreamHandler; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * A dummy stream handler that just passes stuff to the parser. - * - * @version $Revision$ $Date$ - */ -class RedirectingStreamHandler extends PumpStreamHandler { - RedirectingStreamHandler(final ChangeLogParser parser) { - this(new RedirectingOutputStream(parser), null); - } - - RedirectingStreamHandler(OutputStream out, InputStream in) { - this(out, new ByteArrayOutputStream(), in); - } - - RedirectingStreamHandler(OutputStream out, OutputStream err, InputStream in) { - super(out, err, in); - } - - String getErrors() { - try { - final ByteArrayOutputStream error - = (ByteArrayOutputStream) getErr(); - - return error.toString("ASCII"); - } catch (final Exception e) { - return null; - } - } - - - public void stop() { - super.stop(); - try { - getErr().close(); - getOut().close(); - } catch (final IOException e) { - // plain impossible - throw new BuildException(e); - } - } -} - diff --git a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/package.html b/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/package.html deleted file mode 100644 index b051ae62d0..0000000000 --- a/core/src/main/java/hudson/org/apache/tools/ant/taskdefs/cvslib/package.html +++ /dev/null @@ -1,27 +0,0 @@ - - - -Fork of Ant CVS changelog task to work around issues. - \ No newline at end of file