View Javadoc

1   package org.apache.maven.scm.provider.hg.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.ChangeSet;
23  import org.apache.maven.scm.ScmBranch;
24  import org.apache.maven.scm.ScmException;
25  import org.apache.maven.scm.ScmFileSet;
26  import org.apache.maven.scm.ScmResult;
27  import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
28  import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
29  import org.apache.maven.scm.command.changelog.ChangeLogSet;
30  import org.apache.maven.scm.provider.ScmProviderRepository;
31  import org.apache.maven.scm.provider.hg.HgUtils;
32  import org.apache.maven.scm.provider.hg.command.HgCommand;
33  
34  import java.util.ArrayList;
35  import java.util.Date;
36  import java.util.Iterator;
37  import java.util.List;
38  
39  /**
40   * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
41   */
42  public class HgChangeLogCommand
43      extends AbstractChangeLogCommand
44      implements HgCommand
45  {
46  
47      protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository scmProviderRepository,
48                                                            ScmFileSet fileSet, Date startDate, Date endDate,
49                                                            ScmBranch branch, String datePattern )
50          throws ScmException
51      {
52          String[] cmd = new String[]{LOG_CMD, VERBOSE_OPTION};
53          HgChangeLogConsumer consumer = new HgChangeLogConsumer( getLogger(), datePattern );
54          ScmResult result = HgUtils.execute( consumer, getLogger(), fileSet.getBasedir(), cmd );
55  
56          List logEntries = consumer.getModifications();
57          List inRangeAndValid = new ArrayList();
58          startDate = startDate == null ? new Date( 0 ) : startDate;//From 1. Jan 1970
59          endDate = endDate == null ? new Date() : endDate;//Upto now
60  
61          for ( Iterator it = logEntries.iterator(); it.hasNext(); )
62          {
63              ChangeSet change = (ChangeSet) it.next();
64              if ( change.getFiles().size() > 0 )
65              {
66                  if ( !change.getDate().before( startDate ) && !change.getDate().after( endDate ) )
67                  {
68                      inRangeAndValid.add( change );
69                  }
70              }
71          }
72  
73          ChangeLogSet changeLogSet = new ChangeLogSet( inRangeAndValid, startDate, endDate );
74          return new ChangeLogScmResult( changeLogSet, result );
75      }
76  }