You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm-commits@maven.apache.org by ev...@apache.org on 2003/12/05 19:00:40 UTC

cvs commit: maven-scm/generic-scm-providers/clearcase/src/java/org/apache/maven/genericscm/provider/clearcase/command/update ClearcaseUpdateCommand.java

evenisse    2003/12/05 10:00:39

  Modified:    generic-scm-providers/clearcase/src/java/org/apache/maven/genericscm/provider/clearcase/command/checkout
                        ClearcaseCheckOutCommand.java
  Added:       generic-scm-providers/clearcase/src/java/org/apache/maven/genericscm/provider/clearcase/command/changelog
                        ClearcaseChangeLogCommand.java
                        ClearcaseChangeLogConsumer.java
               generic-scm-providers/clearcase/src/java/org/apache/maven/genericscm/provider/clearcase/command/update
                        ClearcaseUpdateCommand.java
  Log:
  Add changelog and update clearcase commands
  
  Revision  Changes    Path
  1.2       +2 -2      maven-scm/generic-scm-providers/clearcase/src/java/org/apache/maven/genericscm/provider/clearcase/command/checkout/ClearcaseCheckOutCommand.java
  
  Index: ClearcaseCheckOutCommand.java
  ===================================================================
  RCS file: /home/cvs/maven-scm/generic-scm-providers/clearcase/src/java/org/apache/maven/genericscm/provider/clearcase/command/checkout/ClearcaseCheckOutCommand.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClearcaseCheckOutCommand.java	4 Dec 2003 20:59:11 -0000	1.1
  +++ ClearcaseCheckOutCommand.java	5 Dec 2003 18:00:39 -0000	1.2
  @@ -1,4 +1,4 @@
  -package org.apache.maven.genericscm.provider.svn.command.checkout;
  +package org.apache.maven.genericscm.provider.clearcase.command.checkout;
   
   /* ====================================================================
    * The Apache Software License, Version 1.1
  
  
  
  1.1                  maven-scm/generic-scm-providers/clearcase/src/java/org/apache/maven/genericscm/provider/clearcase/command/changelog/ClearcaseChangeLogCommand.java
  
  Index: ClearcaseChangeLogCommand.java
  ===================================================================
  package org.apache.maven.genericscm.provider.clearcase.command.changelog;
  
  /* ====================================================================
   * 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-userName 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
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  import java.text.SimpleDateFormat;
  import java.util.Date;
  
  import org.apache.maven.genericscm.ScmException;
  import org.apache.maven.genericscm.command.changelog.ChangeLogCommand;
  import org.apache.maven.genericscm.command.changelog.ChangeLogConsumer;
  import org.apache.maven.genericscm.provider.clearcase.command.AbstractClearcaseCommand;
  import org.apache.maven.genericscm.provider.clearcase.repository.ClearcaseRepository;
  import org.apache.maven.genericscm.util.Commandline;
  import org.apache.maven.genericscm.util.StreamConsumer;
  
  /**
   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
   * @version $Id: ClearcaseChangeLogCommand.java,v 1.1 2003/12/05 18:00:39 evenisse Exp $
   */
  public class ClearcaseChangeLogCommand
      extends AbstractClearcaseCommand
      implements ChangeLogCommand
  {
  	private ChangeLogConsumer consumer;
      private Date startDate;
      private Date endDate;
      
      public ClearcaseChangeLogCommand() throws ScmException
      {
          super();
          endDate = new Date(
              System.currentTimeMillis() + (long)1 * 24 * 60 * 60 * 1000);
          
          setConsumer(new ClearcaseChangeLogConsumer());
      }
  
      /* (non-Javadoc)
       * @see org.apache.maven.genericscm.command.changelog.ChangeLogCommand#setStartDate(java.util.Date)
       */
      public void setStartDate(Date startDate)
      {
          this.startDate = startDate;
      }
  
      /* (non-Javadoc)
       * @see org.apache.maven.genericscm.command.changelog.ChangeLogCommand#getStartDate()
       */
      public Date getStartDate()
      {
          return startDate;
      }
  
      /* (non-Javadoc)
       * @see org.apache.maven.genericscm.command.changelog.ChangeLogCommand#setEndDate(java.util.Date)
       */
      public void setEndDate(Date endDate)
      {
          //Do nothing
      }
  
      /* (non-Javadoc)
       * @see org.apache.maven.genericscm.command.changelog.ChangeLogCommand#getEndDate()
       */
      public Date getEndDate()
      {
          return endDate;
      }
  
      /* (non-Javadoc)
       * @see org.apache.maven.genericscm.command.changelog.ChangeLogCommand#setRange(int)
       */
      public void setRange(int numDays)
      {
          setStartDate(
              new Date(
                  System.currentTimeMillis()
                      - (long)numDays * 24 * 60 * 60 * 1000));
      }
  
      /* (non-Javadoc)
       * @see org.apache.maven.genericscm.command.Command#getName()
       */
      public String getName()
      {
          return NAME;
      }
  
      /* (non-Javadoc)
       * @see org.apache.maven.genericscm.command.Command#getDisplayName()
       */
      public String getDisplayName() throws Exception
      {
          return "ChangeLog";
      }
  
      public Commandline getCommandLine() throws ScmException
      {
          Commandline command = new Commandline();
          command.setExecutable("cleartool");
          command.createArgument().setValue("lshistory");
          
  		if (getWorkingDirectory() != null)
  		{
  			command.setWorkingDirectory(getWorkingDirectory());
  		}
          
          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");
  
          SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
          String start = sdf.format(startDate);
          
          command.createArgument().setValue("-since");
          command.createArgument().setValue(start);
  
          if (getBranch() != null)
          {
              command.createArgument().setValue("-branch");
              command.createArgument().setValue(getBranch());
          }
          
          return command;
      }
      
      /* (non-Javadoc)
       * @see org.apache.maven.genericscm.command.Command#setConsumer(org.apache.maven.genericscm.util.StreamConsumer)
       */
      public void setConsumer(StreamConsumer consumer) throws ScmException
      {
  		if (consumer instanceof ChangeLogConsumer)
  		{
  			this.consumer = (ChangeLogConsumer)consumer;
  		}
  		else
  		{
  			throw new ScmException("Unsupported consumer for this command");
  		}
      }
  
      /* (non-Javadoc)
       * @see org.apache.maven.genericscm.command.Command#getConsumer()
       */
      public StreamConsumer getConsumer()
      {
          return consumer;
      }
  }
  
  
  1.1                  maven-scm/generic-scm-providers/clearcase/src/java/org/apache/maven/genericscm/provider/clearcase/command/changelog/ClearcaseChangeLogConsumer.java
  
  Index: ClearcaseChangeLogConsumer.java
  ===================================================================
  package org.apache.maven.genericscm.provider.clearcase.command.changelog;
  
  /* ====================================================================
   * 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-userName 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
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.Map;
  import java.util.TreeMap;
  
  import org.apache.maven.genericscm.command.changelog.ChangeLogConsumer;
  import org.apache.maven.genericscm.command.changelog.ChangeLogEntry;
  import org.apache.maven.genericscm.command.changelog.ChangeLogFile;
  
  /**
   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
   * @version $Id: ClearcaseChangeLogConsumer.java,v 1.1 2003/12/05 18:00:39 evenisse Exp $
   */
  public class ClearcaseChangeLogConsumer implements ChangeLogConsumer
  {
      /**
       * 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;
  
      /* (non-Javadoc)
       * @see org.apache.maven.genericscm.command.changelog.ChangeLogConsumer#getModifications()
       */
      public Collection getModifications()
      {
          return entries.values();
      }
  
      /* (non-Javadoc)
       * @see org.apache.maven.genericscm.util.StreamConsumer#consumeLine(java.lang.String)
       */
      public void consumeLine(String line)
      {
          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);
          }
      }
  
      /**
       * 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;
      }
  }
  
  
  
  1.1                  maven-scm/generic-scm-providers/clearcase/src/java/org/apache/maven/genericscm/provider/clearcase/command/update/ClearcaseUpdateCommand.java
  
  Index: ClearcaseUpdateCommand.java
  ===================================================================
  package org.apache.maven.genericscm.provider.clearcase.command.update;
  
  /* ====================================================================
   * 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-userName 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
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  import org.apache.maven.genericscm.ScmException;
  import org.apache.maven.genericscm.command.update.UpdateCommand;
  import org.apache.maven.genericscm.provider.clearcase.command.checkout.ClearcaseCheckOutCommand;
  
  /**
   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
   * @version $Id: ClearcaseUpdateCommand.java,v 1.1 2003/12/05 18:00:39 evenisse Exp $
   */
  public class ClearcaseUpdateCommand
      extends ClearcaseCheckOutCommand
      implements UpdateCommand
  {
      /* (non-Javadoc)
       * @see org.apache.maven.genericscm.command.Command#getName()
       */
      public String getName() throws Exception
      {
          return UpdateCommand.NAME;
      }
      
      /* (non-Javadoc)
       * @see org.apache.maven.genericscm.command.Command#getDisplayName()
       */
      public String getDisplayName() throws Exception
      {
          return "Update";
      }
  }