001package org.apache.maven.scm.command.changelog;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.scm.CommandParameter;
023import org.apache.maven.scm.ScmBranch;
024import org.apache.maven.scm.ScmException;
025import org.apache.maven.scm.ScmFileSet;
026import org.apache.maven.scm.ScmRequest;
027import org.apache.maven.scm.ScmVersion;
028import org.apache.maven.scm.repository.ScmRepository;
029
030import java.util.Date;
031
032/**
033 * @author Petr Kozelka
034 * @since 1.8
035 */
036public class ChangeLogScmRequest
037    extends ScmRequest
038{
039    private static final long serialVersionUID = 20120620L;
040
041    public ChangeLogScmRequest( ScmRepository scmRepository, ScmFileSet scmFileSet )
042    {
043        super( scmRepository, scmFileSet );
044    }
045
046    public ScmBranch getScmBranch()
047        throws ScmException
048    {
049        return (ScmBranch) parameters.getScmVersion( CommandParameter.BRANCH, null );
050    }
051
052    public void setScmBranch( ScmBranch scmBranch )
053        throws ScmException
054    {
055        parameters.setScmVersion( CommandParameter.BRANCH, scmBranch );
056    }
057
058    public Date getStartDate()
059        throws ScmException
060    {
061        return parameters.getDate( CommandParameter.START_DATE );
062    }
063
064    /**
065     * @param startDate the start date of the period
066         * @throws ScmException if any
067     */
068    public void setStartDate( Date startDate )
069        throws ScmException
070    {
071        parameters.setDate( CommandParameter.START_DATE, startDate );
072    }
073
074    public Date getEndDate()
075        throws ScmException
076    {
077        return parameters.getDate( CommandParameter.END_DATE );
078    }
079
080    /**
081     * @param endDate the end date of the period
082         * @throws ScmException if any
083     */
084    public void setEndDate( Date endDate )
085        throws ScmException
086    {
087        parameters.setDate( CommandParameter.END_DATE, endDate );
088    }
089
090    public int getNumDays()
091        throws ScmException
092    {
093        return parameters.getInt( CommandParameter.START_DATE );
094    }
095
096    /**
097     * @param numDays the number days before the current time if startdate and enddate are null
098         * @throws ScmException if any
099     */
100    public void setNumDays( int numDays )
101        throws ScmException
102    {
103        parameters.setInt( CommandParameter.NUM_DAYS, numDays );
104    }
105
106    public ScmVersion getStartRevision()
107        throws ScmException
108    {
109        return parameters.getScmVersion( CommandParameter.START_SCM_VERSION, null );
110    }
111
112    /**
113     * @param startRevision the start branch/tag/revision
114         * @throws ScmException if any
115     */
116    public void setStartRevision( ScmVersion startRevision )
117        throws ScmException
118    {
119        parameters.setScmVersion( CommandParameter.START_SCM_VERSION, startRevision );
120    }
121
122    public ScmVersion getEndRevision()
123        throws ScmException
124    {
125        return parameters.getScmVersion( CommandParameter.END_SCM_VERSION, null );
126    }
127
128    /**
129     * @param endRevision the end branch/tag/revision
130         * @throws ScmException if any
131     */
132    public void setEndRevision( ScmVersion endRevision )
133        throws ScmException
134    {
135        parameters.setScmVersion( CommandParameter.END_SCM_VERSION, endRevision );
136    }
137
138    public String getDatePattern()
139        throws ScmException
140    {
141        return parameters.getString( CommandParameter.CHANGELOG_DATE_PATTERN, null );
142    }
143
144    /**
145     * @param datePattern the date pattern used in changelog output returned by scm tool
146         * @throws ScmException if any
147     */
148    public void setDatePattern( String datePattern )
149        throws ScmException
150    {
151        parameters.setString( CommandParameter.CHANGELOG_DATE_PATTERN, datePattern );
152    }
153
154    public Integer getLimit()
155        throws ScmException
156    {
157        final int limit = parameters.getInt( CommandParameter.LIMIT, -1 );
158        return limit > 0 ? limit : null;
159    }
160
161    /**
162     * @param limit the maximal count of returned changesets
163         * @throws ScmException if any
164     */
165    public void setLimit( Integer limit )
166        throws ScmException
167    {
168        if ( limit != null )
169        {
170            parameters.setInt( CommandParameter.LIMIT, limit );
171        }
172        else
173        {
174            parameters.remove( CommandParameter.LIMIT );
175        }
176    }
177
178    public void setDateRange( Date startDate, Date endDate )
179        throws ScmException
180    {
181        setStartDate( startDate );
182        setEndDate( endDate );
183    }
184
185    public void setRevision( ScmVersion revision )
186        throws ScmException
187    {
188        parameters.setScmVersion( CommandParameter.SCM_VERSION, revision );
189    }
190
191    public ScmVersion getRevision()
192        throws ScmException
193    {
194        return parameters.getScmVersion( CommandParameter.SCM_VERSION, null );
195    }
196}