View Javadoc

1   package org.apache.maven.scm.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.CommandParameter;
23  import org.apache.maven.scm.CommandParameters;
24  import org.apache.maven.scm.ScmBranch;
25  import org.apache.maven.scm.ScmException;
26  import org.apache.maven.scm.ScmFileSet;
27  import org.apache.maven.scm.ScmResult;
28  import org.apache.maven.scm.ScmVersion;
29  import org.apache.maven.scm.command.AbstractCommand;
30  import org.apache.maven.scm.provider.ScmProviderRepository;
31  
32  import java.util.Date;
33  
34  /**
35   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
36   * @author Olivier Lamy
37   *
38   */
39  public abstract class AbstractChangeLogCommand
40      extends AbstractCommand
41      implements ChangeLogCommand
42  {
43      @Deprecated
44      protected abstract ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
45                                                                     Date startDate, Date endDate, ScmBranch branch,
46                                                                     String datePattern )
47          throws ScmException;
48  
49      @Deprecated
50      protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
51                                                            ScmVersion startVersion, ScmVersion endVersion,
52                                                            String datePattern )
53          throws ScmException
54      {
55          throw new ScmException( "Unsupported method for this provider." );
56      }
57  
58      /**
59       * {@inheritDoc}
60       */
61      public ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
62                                       CommandParameters parameters )
63          throws ScmException
64      {
65          Date startDate = parameters.getDate( CommandParameter.START_DATE, null );
66  
67          Date endDate = parameters.getDate( CommandParameter.END_DATE, null );
68  
69          int numDays = parameters.getInt( CommandParameter.NUM_DAYS, 0 );
70  
71          Integer limit = parameters.getInt( CommandParameter.LIMIT, -1 );
72          if ( limit < 1 )
73          {
74              limit = null;
75          }
76  
77          ScmBranch branch = (ScmBranch) parameters.getScmVersion( CommandParameter.BRANCH, null );
78  
79          ScmVersion startVersion = parameters.getScmVersion( CommandParameter.START_SCM_VERSION, null );
80  
81          ScmVersion endVersion = parameters.getScmVersion( CommandParameter.END_SCM_VERSION, null );
82  
83          String datePattern = parameters.getString( CommandParameter.CHANGELOG_DATE_PATTERN, null );
84  
85          if ( startVersion != null || endVersion != null )
86          {
87              return executeChangeLogCommand( repository, fileSet, startVersion, endVersion, datePattern );
88          }
89          else
90          {
91              if ( numDays != 0 && ( startDate != null || endDate != null ) )
92              {
93                  throw new ScmException( "Start or end date cannot be set if num days is set." );
94              }
95  
96              if ( endDate != null && startDate == null )
97              {
98                  throw new ScmException( "The end date is set but the start date isn't." );
99              }
100 
101             if ( numDays > 0 )
102             {
103                 int day = 24 * 60 * 60 * 1000;
104                 startDate = new Date( System.currentTimeMillis() - (long) numDays * day );
105 
106                 endDate = new Date( System.currentTimeMillis() + (long) day );
107             }
108             else if ( endDate == null )
109             {
110                 endDate = new Date();
111             }
112 
113             return executeChangeLogCommand( repository, fileSet, startDate, endDate, branch, datePattern );
114         }
115     }
116 
117     protected ChangeLogScmResult executeChangeLogCommand( ChangeLogScmRequest request )
118         throws ScmException
119     {
120         throw new ScmException( "Unsupported method for this provider." );
121     }
122 }