View Javadoc
1   package org.apache.maven.scm.provider.cvslib.cvsjava.command.changelog;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.scm.ScmException;
23  import org.apache.maven.scm.ScmVersion;
24  import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
25  import org.apache.maven.scm.command.changelog.ChangeLogSet;
26  import org.apache.maven.scm.provider.cvslib.command.changelog.AbstractCvsChangeLogCommand;
27  import org.apache.maven.scm.provider.cvslib.command.changelog.CvsChangeLogConsumer;
28  import org.apache.maven.scm.provider.cvslib.cvsjava.util.CvsConnection;
29  import org.apache.maven.scm.provider.cvslib.cvsjava.util.CvsLogListener;
30  import org.codehaus.plexus.util.cli.Commandline;
31  
32  import java.io.BufferedReader;
33  import java.io.ByteArrayInputStream;
34  import java.io.InputStreamReader;
35  import java.util.Date;
36  
37  /**
38   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
39   *
40   */
41  public class CvsJavaChangeLogCommand
42      extends AbstractCvsChangeLogCommand
43  {
44      /** {@inheritDoc} */
45      protected ChangeLogScmResult executeCvsCommand( Commandline cl, Date startDate, Date endDate,
46                                                      ScmVersion startVersion, ScmVersion endVersion, String datePattern )
47          throws ScmException
48      {
49          CvsLogListener logListener = new CvsLogListener();
50  
51          CvsChangeLogConsumer consumer = new CvsChangeLogConsumer( getLogger(), datePattern );
52  
53          try
54          {
55              boolean isSuccess = CvsConnection.processCommand( cl.getArguments(),
56                                                                cl.getWorkingDirectory().getAbsolutePath(), logListener,
57                                                                getLogger() );
58  
59              if ( !isSuccess )
60              {
61                  return new ChangeLogScmResult( cl.toString(), "The cvs command failed.",
62                                                 logListener.getStderr().toString(), false );
63              }
64              BufferedReader stream = new BufferedReader(
65                  new InputStreamReader( new ByteArrayInputStream( logListener.getStdout().toString().getBytes() ) ) );
66  
67              String line;
68  
69              while ( ( line = stream.readLine() ) != null )
70              {
71                  consumer.consumeLine( line );
72              }
73          }
74          catch ( Exception e )
75          {
76              e.printStackTrace();
77              return new ChangeLogScmResult( cl.toString(), "The cvs command failed.", logListener.getStdout().toString(),
78                                             false );
79          }
80  
81          ChangeLogSet changeLogSet = new ChangeLogSet( consumer.getModifications(), startDate, endDate );
82          changeLogSet.setStartVersion( startVersion );
83          changeLogSet.setEndVersion( endVersion );
84  
85          return new ChangeLogScmResult( cl.toString(), changeLogSet );
86      }
87  
88      protected void addDateRangeParameter( Commandline cl, String dateRange )
89      {
90          cl.createArg().setValue( dateRange );
91      }
92  }