001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.scm.command.changelog;
020
021import java.util.Date;
022
023import org.apache.maven.scm.CommandParameter;
024import org.apache.maven.scm.ScmBranch;
025import org.apache.maven.scm.ScmException;
026import org.apache.maven.scm.ScmFileSet;
027import org.apache.maven.scm.ScmRequest;
028import org.apache.maven.scm.ScmVersion;
029import org.apache.maven.scm.repository.ScmRepository;
030
031/**
032 * @author Petr Kozelka
033 * @since 1.8
034 */
035public class ChangeLogScmRequest extends ScmRequest {
036    private static final long serialVersionUID = 20120620L;
037
038    public ChangeLogScmRequest(ScmRepository scmRepository, ScmFileSet scmFileSet) {
039        super(scmRepository, scmFileSet);
040    }
041
042    public ScmBranch getScmBranch() throws ScmException {
043        return (ScmBranch) parameters.getScmVersion(CommandParameter.BRANCH, null);
044    }
045
046    public void setScmBranch(ScmBranch scmBranch) throws ScmException {
047        parameters.setScmVersion(CommandParameter.BRANCH, scmBranch);
048    }
049
050    public Date getStartDate() throws ScmException {
051        return parameters.getDate(CommandParameter.START_DATE);
052    }
053
054    /**
055     * @param startDate the start date of the period
056     * @throws ScmException if any
057     */
058    public void setStartDate(Date startDate) throws ScmException {
059        parameters.setDate(CommandParameter.START_DATE, startDate);
060    }
061
062    public Date getEndDate() throws ScmException {
063        return parameters.getDate(CommandParameter.END_DATE);
064    }
065
066    /**
067     * @param endDate the end date of the period
068     * @throws ScmException if any
069     */
070    public void setEndDate(Date endDate) throws ScmException {
071        parameters.setDate(CommandParameter.END_DATE, endDate);
072    }
073
074    public int getNumDays() throws ScmException {
075        return parameters.getInt(CommandParameter.START_DATE);
076    }
077
078    /**
079     * @param numDays the number days before the current time if startdate and enddate are null
080     * @throws ScmException if any
081     */
082    public void setNumDays(int numDays) throws ScmException {
083        parameters.setInt(CommandParameter.NUM_DAYS, numDays);
084    }
085
086    public ScmVersion getStartRevision() throws ScmException {
087        return parameters.getScmVersion(CommandParameter.START_SCM_VERSION, null);
088    }
089
090    /**
091     * @param startRevision the start branch/tag/revision
092     * @throws ScmException if any
093     */
094    public void setStartRevision(ScmVersion startRevision) throws ScmException {
095        parameters.setScmVersion(CommandParameter.START_SCM_VERSION, startRevision);
096    }
097
098    public ScmVersion getEndRevision() throws ScmException {
099        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}