001/*
002 * Copyright 2007-2018 The jdeb developers.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.vafer.jdeb.changes;
018
019import java.util.Date;
020
021/**
022 * A ChangeSet basically reflect a release as defined in the changes file.
023 *
024 * <pre>
025 * package (version) distribution(s); urgency=urgency
026 *        [optional blank line(s), stripped]
027 *   * change details
028 *     more change details
029 *        [blank line(s), included in output of dpkg-parsechangelog]
030 *   * even more change details
031 *        [optional blank line(s), stripped]
032 *  -- maintainer name &lt;email address&gt;[two spaces]  date
033 * </pre>
034 *
035 * @see <a href="http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog">Debian Policy Manual - Debian changelog</a>
036 */
037public final class ChangeSet {
038
039    private final String packageName;
040    private final String version;
041    private final Date date;
042    private final String distribution;
043    private final String urgency;
044    private final String changedBy;
045    private final String[] changes;
046
047    public ChangeSet(String packageName, String version, Date date, String distribution, String urgency, String changedBy, String[] changes) {
048        this.packageName = packageName;
049        this.version = version;
050        this.date = date;
051        this.distribution = distribution;
052        this.urgency = urgency;
053        this.changedBy = changedBy;
054        this.changes = changes;
055    }
056
057    public String getPackage() {
058        return packageName;
059    }
060
061    public String getVersion() {
062        return version;
063    }
064
065    public Date getDate() {
066        return date;
067    }
068
069    public String getDistribution() {
070        return distribution;
071    }
072
073    public String getUrgency() {
074        return urgency;
075    }
076
077    public String getChangedBy() {
078        return changedBy;
079    }
080
081    public String[] getChanges() {
082        return changes;
083    }
084
085    public String toString() {
086        StringBuilder sb = new StringBuilder();
087
088        sb.append(getTitle()).append('\n');
089
090        if (changes.length > 0) {
091            sb.append("\n");
092        }
093
094        for (String change : changes) {
095            sb.append("  * ").append(change).append('\n');
096        }
097
098        return sb.toString();
099    }
100
101    private String getTitle() {
102        return getPackage() + " (" + getVersion() + ") " + getDistribution() + "; urgency=" + getUrgency();
103    }
104}