maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: maven-scm/maven-scm-providers/maven-scm-provider-cvs/src/test/java/org/apache/maven/scm/provider/cvslib/command/diff CvsDiffCommand.java CvsDiffConsumer.java
Date Wed, 12 Jan 2005 12:59:14 GMT
brett       2005/01/12 04:59:14

  Added:       maven-scm-providers/maven-scm-provider-cvs/src/main/java/org/apache/maven/scm/provider/cvslib/command/diff
                        CvsDiffCommand.java CvsDiffConsumer.java
  Removed:     maven-scm-providers/maven-scm-provider-cvs/src/test/java/org/apache/maven/scm/provider/cvslib/command/diff
                        CvsDiffCommand.java CvsDiffConsumer.java
  Log:
  put in right source folder
  
  Revision  Changes    Path
  1.1                  maven-scm/maven-scm-providers/maven-scm-provider-cvs/src/main/java/org/apache/maven/scm/provider/cvslib/command/diff/CvsDiffCommand.java
  
  Index: CvsDiffCommand.java
  ===================================================================
  package org.apache.maven.scm.provider.cvslib.command.diff;
  
  /*
   * Copyright 2003-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.
   */
  
  import org.apache.maven.scm.ScmException;
  import org.apache.maven.scm.ScmFileSet;
  import org.apache.maven.scm.command.diff.AbstractDiffCommand;
  import org.apache.maven.scm.command.diff.DiffScmResult;
  import org.apache.maven.scm.provider.ScmProviderRepository;
  import org.apache.maven.scm.provider.cvslib.command.CvsCommand;
  import org.codehaus.plexus.util.cli.CommandLineException;
  import org.codehaus.plexus.util.cli.CommandLineUtils;
  import org.codehaus.plexus.util.cli.Commandline;
  
  import java.io.File;
  
  /**
   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
   * @version $Id: CvsDiffCommand.java,v 1.1 2005/01/12 12:59:14 brett Exp $
   */
  public class CvsDiffCommand
      extends AbstractDiffCommand
      implements CvsCommand
  {
      protected DiffScmResult executeDiffCommand( ScmProviderRepository repo, ScmFileSet fileSet,
String startRevision,
                                                  String endRevision )
          throws ScmException
      {
          Commandline cl = createCommandLine( fileSet.getBasedir(), startRevision, endRevision
);
  
          CvsDiffConsumer consumer = new CvsDiffConsumer( getLogger(), fileSet.getBasedir()
);
  
          CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
  
          getLogger().info( "Executing: " + cl );
          getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath()
);
  
          int exitCode;
  
          try
          {
              exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
          }
          catch ( CommandLineException ex )
          {
              throw new ScmException( "Error while executing command.", ex );
          }
  
  // TODO: a difference returns a code of "1", as does errors. How to tell the difference?
  //        if ( exitCode != 0 )
  //        {
  //            return new DiffScmResult( "The cvs command failed.", stderr.getOutput(), false
);
  //        }
  
          return new DiffScmResult( consumer.getChangedFiles(), consumer.getDifferences(),
consumer.getPatch() );
      }
  
      // ----------------------------------------------------------------------
      //
      // ----------------------------------------------------------------------
  
      public static Commandline createCommandLine( File workingDirectory, String startRevision,
String endRevision )
      {
          Commandline cl = new Commandline();
  
          cl.setExecutable( "cvs" );
  
          cl.setWorkingDirectory( workingDirectory.getAbsolutePath() );
  
          cl.createArgument().setValue( "-q" );
  
          cl.createArgument().setValue( "-f" ); // don't use ~/.cvsrc
  
          cl.createArgument().setValue( "diff" );
  
          cl.createArgument().setValue( "-u" );
  
          cl.createArgument().setValue( "-N" );
  
          if ( startRevision != null )
          {
              cl.createArgument().setValue( "-r" );
              cl.createArgument().setValue( startRevision );
          }
  
          if ( endRevision != null )
          {
              cl.createArgument().setValue( "-r" );
              cl.createArgument().setValue( endRevision );
          }
  
          return cl;
      }
  }
  
  
  
  1.1                  maven-scm/maven-scm-providers/maven-scm-provider-cvs/src/main/java/org/apache/maven/scm/provider/cvslib/command/diff/CvsDiffConsumer.java
  
  Index: CvsDiffConsumer.java
  ===================================================================
  package org.apache.maven.scm.provider.cvslib.command.diff;
  
  /*
   * Copyright 2003-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.
   */
  
  import org.apache.maven.scm.ScmFile;
  import org.apache.maven.scm.ScmFileStatus;
  import org.codehaus.plexus.logging.Logger;
  import org.codehaus.plexus.util.cli.StreamConsumer;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  /**
   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
   * @version $Id: CvsDiffConsumer.java,v 1.1 2005/01/12 12:59:14 brett Exp $
   * @todo share with SVN (3 extra lines can be ignored)
   */
  public class CvsDiffConsumer
      implements StreamConsumer
  {
  //
  // Index: plugin.jelly
  // ===================================================================
  // RCS file: /home/cvs/maven-scm/maven-scm-providers/maven-scm-provider-cvs/src/main/resources/META-INF/plexus/components.xml,v
  // retrieving revision 1.2
  // diff -u -r1.2 components.xml
  // --- plugin.jelly        (revision 124799)
  // +++ plugin.jelly        (working copy)
  //
  
      private final static String RCS_TOKEN = "RCS file: ";
  
      private final static String RETRIEVING_TOKEN = "retrieving revision ";
  
      private final static String DIFF_TOKEN = "diff ";
  
      private final static String INDEX_TOKEN = "Index: ";
  
      private final static String FILE_SEPARATOR_TOKEN = "===";
  
      private final static String START_REVISION_TOKEN = "---";
  
      private final static String END_REVISION_TOKEN = "+++";
  
      private final static String ADDED_LINE_TOKEN = "+";
  
      private final static String REMOVED_LINE_TOKEN = "-";
  
      private final static String UNCHANGED_LINE_TOKEN = " ";
  
      private final static String CHANGE_SEPARATOR_TOKEN = "@@";
  
      private final static String NO_NEWLINE_TOKEN = "\\ No newline at end of file";
  
      private Logger logger;
  
      private File workingDirectory;
  
      private String currentFile;
  
      private StringBuffer currentDifference;
  
      private List changedFiles = new ArrayList();
  
      private Map differences = new HashMap();
  
      private StringBuffer patch = new StringBuffer();
  
      // ----------------------------------------------------------------------
      //
      // ----------------------------------------------------------------------
  
      public CvsDiffConsumer( Logger logger, File workingDirectory )
      {
          this.logger = logger;
  
          this.workingDirectory = workingDirectory;
      }
  
      // ----------------------------------------------------------------------
      // StreamConsumer Implementation
      // ----------------------------------------------------------------------
  
      public void consumeLine( String line )
      {
          if ( line.startsWith( INDEX_TOKEN ) )
          {
              // start a new file
              currentFile = line.substring( INDEX_TOKEN.length() );
  
              changedFiles.add( new ScmFile( currentFile, ScmFileStatus.MODIFIED ) );
  
              currentDifference = new StringBuffer();
  
              differences.put( currentFile, currentDifference );
  
              patch.append( line ).append( "\n" );
  
              return;
          }
  
          if ( currentFile == null )
          {
              logger.warn( "Unparseable line: '" + line + "'" );
              patch.append( line ).append( "\n" );
              return;
          }
  
          if ( line.startsWith( FILE_SEPARATOR_TOKEN ) )
          {
              // skip
              patch.append( line ).append( "\n" );
          }
          else if ( line.startsWith( START_REVISION_TOKEN ) )
          {
              // skip, though could parse to verify filename, start revision
              patch.append( line ).append( "\n" );
          }
          else if ( line.startsWith( END_REVISION_TOKEN ) )
          {
              // skip, though could parse to verify filename, end revision
              patch.append( line ).append( "\n" );
          }
          else if ( line.startsWith( RCS_TOKEN ) )
          {
              // skip, though could parse to verify filename
          }
          else if ( line.startsWith( RETRIEVING_TOKEN ) )
          {
              // skip, though could parse to verify version
          }
          else if ( line.startsWith( DIFF_TOKEN ) )
          {
              // skip, though could parse to verify command
          }
          else if ( line.startsWith( ADDED_LINE_TOKEN ) || line.startsWith( REMOVED_LINE_TOKEN
) ||
              line.startsWith( UNCHANGED_LINE_TOKEN ) || line.startsWith( CHANGE_SEPARATOR_TOKEN
) ||
              line.equals( NO_NEWLINE_TOKEN ) )
          {
              // add to buffer
              currentDifference.append( line ).append( "\n" );
              patch.append( line ).append( "\n" );
          }
          else
          {
              logger.warn( "Unparseable line: '" + line + "'" );
              patch.append( line ).append( "\n" );
              // skip to next file
              currentFile = null;
              currentDifference = null;
          }
      }
  
      public List getChangedFiles()
      {
          return changedFiles;
      }
  
      public Map getDifferences()
      {
          return differences;
      }
  
      public String getPatch()
      {
          return patch.toString();
      }
  
  }
  
  
  

Mime
View raw message