View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.scm.command.changelog;
20  
21  import java.util.Date;
22  
23  import org.apache.maven.scm.CommandParameter;
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.ScmRequest;
28  import org.apache.maven.scm.ScmVersion;
29  import org.apache.maven.scm.repository.ScmRepository;
30  
31  /**
32   * @author Petr Kozelka
33   * @since 1.8
34   */
35  public class ChangeLogScmRequest extends ScmRequest {
36      private static final long serialVersionUID = 20120620L;
37  
38      public ChangeLogScmRequest(ScmRepository scmRepository, ScmFileSet scmFileSet) {
39          super(scmRepository, scmFileSet);
40      }
41  
42      public ScmBranch getScmBranch() throws ScmException {
43          return (ScmBranch) parameters.getScmVersion(CommandParameter.BRANCH, null);
44      }
45  
46      public void setScmBranch(ScmBranch scmBranch) throws ScmException {
47          parameters.setScmVersion(CommandParameter.BRANCH, scmBranch);
48      }
49  
50      public Date getStartDate() throws ScmException {
51          return parameters.getDate(CommandParameter.START_DATE);
52      }
53  
54      /**
55       * @param startDate the start date of the period
56       * @throws ScmException if any
57       */
58      public void setStartDate(Date startDate) throws ScmException {
59          parameters.setDate(CommandParameter.START_DATE, startDate);
60      }
61  
62      public Date getEndDate() throws ScmException {
63          return parameters.getDate(CommandParameter.END_DATE);
64      }
65  
66      /**
67       * @param endDate the end date of the period
68       * @throws ScmException if any
69       */
70      public void setEndDate(Date endDate) throws ScmException {
71          parameters.setDate(CommandParameter.END_DATE, endDate);
72      }
73  
74      public int getNumDays() throws ScmException {
75          return parameters.getInt(CommandParameter.START_DATE);
76      }
77  
78      /**
79       * @param numDays the number days before the current time if startdate and enddate are null
80       * @throws ScmException if any
81       */
82      public void setNumDays(int numDays) throws ScmException {
83          parameters.setInt(CommandParameter.NUM_DAYS, numDays);
84      }
85  
86      public ScmVersion getStartRevision() throws ScmException {
87          return parameters.getScmVersion(CommandParameter.START_SCM_VERSION, null);
88      }
89  
90      /**
91       * @param startRevision the start branch/tag/revision
92       * @throws ScmException if any
93       */
94      public void setStartRevision(ScmVersion startRevision) throws ScmException {
95          parameters.setScmVersion(CommandParameter.START_SCM_VERSION, startRevision);
96      }
97  
98      public ScmVersion getEndRevision() throws ScmException {
99          return parameters.getScmVersion(CommandParameter.END_SCM_VERSION, null);
100     }
101 
102     /**
103      * @param endRevision the end branch/tag/revision
104      * @throws ScmException if any
105      */
106     public void setEndRevision(ScmVersion endRevision) throws ScmException {
107         parameters.setScmVersion(CommandParameter.END_SCM_VERSION, endRevision);
108     }
109 
110     public String getDatePattern() throws ScmException {
111         return parameters.getString(CommandParameter.CHANGELOG_DATE_PATTERN, null);
112     }
113 
114     /**
115      * @param datePattern the date pattern used in changelog output returned by scm tool
116      * @throws ScmException if any
117      */
118     public void setDatePattern(String datePattern) throws ScmException {
119         parameters.setString(CommandParameter.CHANGELOG_DATE_PATTERN, datePattern);
120     }
121 
122     public Integer getLimit() throws ScmException {
123         final int limit = parameters.getInt(CommandParameter.LIMIT, -1);
124         return limit > 0 ? limit : null;
125     }
126 
127     /**
128      * @param limit the maximal count of returned changesets
129      * @throws ScmException if any
130      */
131     public void setLimit(Integer limit) throws ScmException {
132         if (limit != null) {
133             parameters.setInt(CommandParameter.LIMIT, limit);
134         } else {
135             parameters.remove(CommandParameter.LIMIT);
136         }
137     }
138 
139     public void setDateRange(Date startDate, Date endDate) throws ScmException {
140         setStartDate(startDate);
141         setEndDate(endDate);
142     }
143 
144     public void setRevision(ScmVersion revision) throws ScmException {
145         parameters.setScmVersion(CommandParameter.SCM_VERSION, revision);
146     }
147 
148     public ScmVersion getRevision() throws ScmException {
149         return parameters.getScmVersion(CommandParameter.SCM_VERSION, null);
150     }
151 }