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;
020
021import java.io.Serializable;
022
023/**
024 * A set of information about revisions of a file as returned by SCM's log
025 * command.
026 *
027 * @author <a href="mailto:dion@multitask.com.au">dIon Gillard </a>
028 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
029 */
030public class ChangeFile implements Serializable {
031    private static final long serialVersionUID = 6294855290542668753L;
032
033    /**
034     * The name of the file relative to the project directory.
035     */
036    private String name;
037
038    /**
039     * The latest revision of the file.
040     */
041    private String revision;
042
043    /**
044     * Edit type on the file
045     * note: perhaps we should use a different type, ideally enum? this one seems to target quite different usecases ...
046     *
047     * @since 1.7
048     */
049    private ScmFileStatus action;
050
051    /**
052     * The name before copying or moving.
053     *
054     * @since 1.7
055     */
056    private String originalName;
057
058    /**
059     * The revision from which we {@link ScmFileStatus copied} or {@link ScmFileStatus moved} this file or directory.
060     *
061     * @since 1.7
062     */
063    private String originalRevision;
064
065    /**
066     * Constructor for the ChangeFile object without all details available.
067     *
068     * @param name file name
069     */
070    public ChangeFile(String name) {
071        setName(name);
072    }
073
074    /**
075     * Constructor for the ChangeFile object.
076     *
077     * @param name file name
078     * @param rev  latest revision of the file
079     */
080    public ChangeFile(String name, String rev) {
081        setName(name);
082
083        setRevision(rev);
084    }
085
086    /**
087     * Gets the name attribute of the ChangeLogFile object.
088     *
089     * @return the file name
090     */
091    public String getName() {
092        return name;
093    }
094
095    /**
096     * Setter for property name.
097     *
098     * @param name new value of property name
099     */
100    public void setName(String name) {
101        this.name = name;
102    }
103
104    public String getOriginalName() {
105        return originalName;
106    }
107
108    public void setOriginalName(String originalName) {
109
110        this.originalName = originalName;
111    }
112
113    public String getOriginalRevision() {
114        return originalRevision;
115    }
116
117    public void setOriginalRevision(String originalRevision) {
118        this.originalRevision = originalRevision;
119    }
120
121    /**
122     * Gets the revision attribute of the ChangeLogFile object.
123     *
124     * @return the latest revision of the file
125     */
126    public String getRevision() {
127        return revision;
128    }
129
130    /**
131     * Setter for property revision.
132     *
133     * @param revision new value of property revision
134     */
135    public void setRevision(String revision) {
136        this.revision = revision;
137    }
138
139    public ScmFileStatus getAction() {
140        return action;
141    }
142
143    public void setAction(ScmFileStatus action) {
144        this.action = action;
145    }
146
147    /**
148     * Provide a version of the object as a string for debugging purposes.
149     *
150     * @return a {@link String}made up of the properties of the object
151     */
152    public String toString() {
153        StringBuilder buffer = new StringBuilder();
154
155        if (getAction() != null) {
156            buffer.append("[").append(getAction()).append("]:");
157        }
158
159        buffer.append(getName());
160        if (getRevision() != null) {
161            buffer.append(", ").append(getRevision());
162        }
163
164        if (getOriginalName() != null) {
165            buffer.append(", originalName=").append(getOriginalName());
166        }
167
168        if (getOriginalRevision() != null) {
169            buffer.append(", originalRevision=").append(getOriginalRevision());
170        }
171
172        return buffer.toString();
173    }
174}