diff --git a/changelog/src/main/org/apache/maven/clearcaselib/ClearcaseChangeLogFactory.java b/changelog/src/main/org/apache/maven/clearcaselib/ClearcaseChangeLogFactory.java new file mode 100644 index 00000000..14b5bb15 --- /dev/null +++ b/changelog/src/main/org/apache/maven/clearcaselib/ClearcaseChangeLogFactory.java @@ -0,0 +1,87 @@ +package org.apache.maven.clearcaselib; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import org.apache.maven.changelog.ChangeLogFactory; +import org.apache.maven.changelog.ChangeLogGenerator; +import org.apache.maven.changelog.ChangeLogParser; + +/** + * Provides Clearcase specific instances of the ChangeLogGenerator and + * ChangeLogParser interfaces. + * + * @author Simone Zorzetti + */ +public class ClearcaseChangeLogFactory implements ChangeLogFactory { + + /* (non-Javadoc) + * @see org.apache.maven.changelog.ChangeLogFactory#createGenerator() + */ + public ChangeLogGenerator createGenerator() + { + return new ClearcaseChangeLogGenerator(); + } + + /* (non-Javadoc) + * @see org.apache.maven.changelog.ChangeLogFactory#createParser() + */ + public ChangeLogParser createParser() + { + return new ClearcaseChangeLogParser(); + } + +} diff --git a/changelog/src/main/org/apache/maven/clearcaselib/ClearcaseChangeLogGenerator.java b/changelog/src/main/org/apache/maven/clearcaselib/ClearcaseChangeLogGenerator.java new file mode 100644 index 00000000..68ac5e79 --- /dev/null +++ b/changelog/src/main/org/apache/maven/clearcaselib/ClearcaseChangeLogGenerator.java @@ -0,0 +1,140 @@ +package org.apache.maven.clearcaselib; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.text.SimpleDateFormat; +import java.util.Date; + +// commons imports +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +// ant imports +import org.apache.tools.ant.types.Commandline; + +import org.apache.maven.changelog.AbstractChangeLogGenerator; + + +/** + * A Clearcase implementation of the {@link org.apache.maven.changelog.ChangeLogGenerator} + * interface realized extending the {@link org.apache.maven.changelog.AbstractChangeLogGenerator}. + * + * The command line build by this class uses the lshistory clearcase command + * and formats the output in a way the ClearcaseChangeLogParser can understand. Due to this + * fact this implementations works only if used within a clearcase view. + * + * The command looks like this:

+ * cleartool lshistory -recurse -nco -since SAMEDATE + * -fmt "NAME:%En\\nDATE:%Nd\\nCOMM:%-12.12o - %o - %c - Activity: %[activity]p\\nUSER:%-8.8u\\n" + * + * @author Simone Zorzetti + */ +public class ClearcaseChangeLogGenerator extends AbstractChangeLogGenerator { + + /** Log */ + private static final Log LOG = LogFactory.getLog( + ClearcaseChangeLogGenerator.class); + + /** + * Constructs the appropriate command line to execute the scm's + * log command. For Clearcase it's lshistory. + * + * @see org.apache.maven.changelog.AbstractChangeLogGenerator#getScmLogCommand() + * @return The command line to be executed. + */ + protected Commandline getScmLogCommand() + { + Commandline command = new Commandline(); + command.setExecutable("cleartool"); + command.createArgument().setValue("lshistory"); + + StringBuffer format = new StringBuffer(); + format.append("NAME:%En\\n"); + format.append("DATE:%Nd\\n"); + format.append("COMM:%-12.12o - %o - %c - Activity: %[activity]p\\n"); + format.append("USER:%-8.8u\\n"); + + command.createArgument().setValue("-fmt"); + command.createArgument().setValue(format.toString()); + command.createArgument().setValue("-recurse"); + command.createArgument().setValue("-nco"); + command.createArgument().setValue("-since"); + command.createArgument().setValue(dateRange); + + return command; + } + + /** + * Construct the command-line argument that is passed to the scm + * client to specify the appropriate date range. + * + * @param before The starting point. + * @param to The ending point. + * @return A string that can be used to specify a date to a scm + * system. + * + * @see org.apache.maven.changelog.AbstractChangeLogGenerator#getScmDateArgument(java.util.Date, java.util.Date) + */ + protected String getScmDateArgument(Date before, Date to) + { + SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy"); + String argument = sdf.format(before); + + return argument; + } + +} diff --git a/changelog/src/main/org/apache/maven/clearcaselib/ClearcaseChangeLogParser.java b/changelog/src/main/org/apache/maven/clearcaselib/ClearcaseChangeLogParser.java new file mode 100644 index 00000000..433712d3 --- /dev/null +++ b/changelog/src/main/org/apache/maven/clearcaselib/ClearcaseChangeLogParser.java @@ -0,0 +1,363 @@ +package org.apache.maven.clearcaselib; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.StringTokenizer; +import java.util.TreeMap; + + +// commons imports +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +// ant imports +import org.apache.tools.ant.types.Commandline; + +import org.apache.maven.changelog.ChangeLog; +import org.apache.maven.changelog.ChangeLogParser; +import org.apache.maven.changelog.ChangeLogEntry; +import org.apache.maven.changelog.ChangeLogFile; + +/** + * Clearcase specific implementation of ChangeLogParser interface. + * + * @author Simone Zorzetti + */ +public class ClearcaseChangeLogParser implements ChangeLogParser { + + /** Log */ + private static final Log LOG = LogFactory.getLog( + ClearcaseChangeLogParser.class); + + /** + * Formatter used to parse Clearcase date/timestamp. + */ + private static final SimpleDateFormat CLEARCASE_TIMESTAMP_FORMAT = + new SimpleDateFormat("yyyyMMdd.HHmmss"); + + private static final String NAME_TAG = "NAME:"; + private static final String USER_TAG = "USER:"; + private static final String DATE_TAG = "DATE:"; + private static final String COMMENT_TAG = "COMM:"; + + /** + * Custom date/time formatter. Rounds ChangeLogEntry times to the nearest + * minute. + */ + private static final SimpleDateFormat ENTRY_KEY_TIMESTAMP_FORMAT = + new SimpleDateFormat("yyyyMMddHHmm"); + + /** + * Custom date/time formatter. Rounds ChangeLogEntry to date + */ + private static final SimpleDateFormat GROUPED_ENTRY_KEY_TIMESTAMP_FORMAT = + new SimpleDateFormat("yyyyMMdd"); + + /** + * rcs entries, in reverse (date, time, author, comment) order + */ + private Map entries = new TreeMap(Collections.reverseOrder()); + + // state machine constants for reading clearcase lshistory command output + /** expecting file information */ + private static final int GET_FILE = 1; + /** expecting date */ + private static final int GET_DATE = 2; + /** expecting comments */ + private static final int GET_COMMENT = 3; + + /** current status of the parser */ + private int status = GET_FILE; + + /** the current log entry being processed by the parser*/ + private ChangeLogEntry currentLogEntry = null; + + /** the current file being processed by the parser */ + private ChangeLogFile currentFile = null; + + /** + * Create a new ChangeLogParser. + */ + public ClearcaseChangeLogParser() + { + } + + /** + * initialize the parser from the change log + * @param changeLog the controlling task + * @see ChangeLogParser#init(ChangeLog) + */ + public void init(ChangeLog changeLog) + { + } + + /** + * Clean up any parser resources + * @see ChangeLogParser#cleanup() + */ + public void cleanup() + { + } + + /** + * Parse the input stream into a collection. + * @param anInputStream an input stream containing clearcase log output + * @return a collection of ChangeLogEntry's + * @throws IOException when there are errors reading the provided stream + */ + public Collection parse(InputStream anInputStream) throws IOException + { + BufferedReader stream = new BufferedReader( + new InputStreamReader(anInputStream)); + + // Read the tags in the order they are produced by the command setup + // by ClearcaseChangeLogGenerator + // File name + // Date + // Comment + // User Name (author) + String line = null; + + while ((line = stream.readLine()) != null) + { + switch (getStatus()) + { + case GET_FILE: + processGetFile(line); + break; + case GET_DATE: + processGetDate(line); + break; + case GET_COMMENT: + processGetCommentAndUser(line); + break; + default: + throw new IllegalStateException("Unknown state: " + status); + } + } + + return entries.values(); + } + + /** + * Add a change log entry to the list (if it's not already there) + * with the given file. + * @param entry a {@link ChangeLogEntry} to be added to the list if another + * with the same key doesn't exist already. If the entry's author + * is null, the entry wont be added + * @param file a {@link ChangeLogFile} to be added to the entry + */ + private void addEntry(ChangeLogEntry entry, ChangeLogFile file) + { + + // do not add if entry is not populated + if (entry.getAuthor() == null) + { + return; + } + // do not add if the operation is not checkin + if (entry.getComment().indexOf("- checkin") == -1) + { + return; + } + + String key = ENTRY_KEY_TIMESTAMP_FORMAT.format(entry.getDate()) + + entry.getAuthor() + entry.getComment(); + + + if (!entries.containsKey(key)) + { + entry.addFile(file); + entries.put(key, entry); + } + else + { + ChangeLogEntry existingEntry = (ChangeLogEntry) entries.get(key); + existingEntry.addFile(file); + } + } + + /** + * Process the current input line in the Get File state. + * @param line a line of text from the clearcase log output + */ + private void processGetFile(String line) + { + if (line.startsWith(NAME_TAG)) + { + setCurrentLogEntry(new ChangeLogEntry()); + setCurrentFile(new ChangeLogFile(line.substring(NAME_TAG.length(), + line.length()))); + setStatus(GET_DATE); + } + } + + + /** + * Process the current input line in the Get Date state. + * @param line a line of text from the clearcase log output + */ + private void processGetDate(String line) + { + if (line.startsWith(DATE_TAG)) + { + try + { + getCurrentLogEntry().setDate(CLEARCASE_TIMESTAMP_FORMAT.parse(line.substring(DATE_TAG.length()))); + } + catch (ParseException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + setStatus(GET_COMMENT); + } + } + + + /** + * Process the current input line in the Get Comment state. + * @param line a line of text from the clearcase log output + */ + private void processGetCommentAndUser(String line) + { + if (line.startsWith(COMMENT_TAG)) + { + String comm = line.substring(COMMENT_TAG.length()); + getCurrentLogEntry().setComment( + getCurrentLogEntry().getComment() + comm + "\n"); + + } + else if (line.startsWith(USER_TAG)) + { + getCurrentLogEntry().setAuthor(line.substring(USER_TAG.length())); + // add entry, and set state to get file + addEntry(getCurrentLogEntry(), getCurrentFile()); + setStatus(GET_FILE); + } + else + { + // keep gathering comments + getCurrentLogEntry().setComment( + getCurrentLogEntry().getComment() + line + "\n"); + } + } + + /** + * Getter for property currentFile. + * @return Value of property currentFile. + */ + private ChangeLogFile getCurrentFile() + { + return currentFile; + } + + /** + * Setter for property currentFile. + * @param currentFile New value of property currentFile. + */ + private void setCurrentFile(ChangeLogFile currentFile) + { + this.currentFile = currentFile; + } + + /** + * Getter for property currentLogEntry. + * @return Value of property currentLogEntry. + */ + private ChangeLogEntry getCurrentLogEntry() + { + return currentLogEntry; + } + + /** + * Setter for property currentLogEntry. + * @param currentLogEntry New value of property currentLogEntry. + */ + private void setCurrentLogEntry(ChangeLogEntry currentLogEntry) + { + this.currentLogEntry = currentLogEntry; + } + + /** + * Getter for property status. + * @return Value of property status. + */ + private int getStatus() + { + return status; + } + + /** + * Setter for property status. + * @param status New value of property status. + */ + private void setStatus(int status) + { + this.status = status; + } + + +} diff --git a/changelog/xdocs/changes.xml b/changelog/xdocs/changes.xml index ae4e4c00..f09cc76e 100644 --- a/changelog/xdocs/changes.xml +++ b/changelog/xdocs/changes.xml @@ -8,6 +8,9 @@ + + MAVEN-811. Add support of IBM Rational ClearCase SCM. + Upgrade to maven 1.0 beta 10 diff --git a/changelog/xdocs/index.xml b/changelog/xdocs/index.xml index 2149b1a9..49d08447 100644 --- a/changelog/xdocs/index.xml +++ b/changelog/xdocs/index.xml @@ -13,7 +13,7 @@ This plugin produces a nicely formatted changelog report so project team members can see at a glance what changes have been made recently to the project. Currently, there are three supported - source control systems: CVS, StarTeam and Subversion. + source control systems: CVS, StarTeam, IBM Rational ClearCase and Subversion.

For more information on the functionality provided by this plugin,