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;
20
21 import java.io.Serializable;
22
23 /**
24 * TODO move to a real enum
25 * <p>
26 * Typesafe enum for file status
27 * </p>
28 * <p>
29 * There are two types of status defined in this class: <br>
30 * 1) Status: Changes in the working tree, not yet committed to the repository e.g. MODIFIED <br>
31 * 2) Transaction: The file is part of some transaction with the repository e.g. CHECKED_IN
32 * </p>
33 *
34 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
35 */
36 public final class ScmFileStatus implements Serializable {
37 private static final long serialVersionUID = -7840223279162817915L;
38
39 /**
40 * File is added to the working tree and does not yet exist in the repository.
41 */
42 public static final ScmFileStatus ADDED = new ScmFileStatus("added");
43
44 /**
45 * File is removed from the working tree thus not revisioned anymore.<br>
46 * The file is still present in the repository.<br>
47 * The file could be deleted from the filesystem depending on the provider.
48 */
49 public static final ScmFileStatus DELETED = new ScmFileStatus("deleted");
50
51 /**
52 * The file has been modified in the working tree.
53 */
54 public static final ScmFileStatus MODIFIED = new ScmFileStatus("modified");
55
56 /**
57 * The file has been renamed or moved in the working tree.
58 *
59 * @since 1.7
60 */
61 public static final ScmFileStatus RENAMED = new ScmFileStatus("renamed");
62
63 /**
64 * The file has been copied in the working tree.
65 *
66 * @since 1.7
67 */
68 public static final ScmFileStatus COPIED = new ScmFileStatus("copied");
69
70 /**
71 * The file is missing in the working tree.
72 */
73 public static final ScmFileStatus MISSING = new ScmFileStatus("missing");
74
75 /**
76 * File from working tree is checked into the repository.
77 */
78 public static final ScmFileStatus CHECKED_IN = new ScmFileStatus("checked-in");
79
80 /**
81 * File is checked out from the repository and into the working tree.
82 */
83 public static final ScmFileStatus CHECKED_OUT = new ScmFileStatus("checked-out");
84
85 /**
86 * The file in the working tree has differences to the one in repository that
87 * conflicts ie. it cannot automatically be merged.
88 */
89 public static final ScmFileStatus CONFLICT = new ScmFileStatus("conflict");
90
91 /**
92 * The file in the working tree has been updated with changes from the repository.
93 */
94 public static final ScmFileStatus PATCHED = new ScmFileStatus("patched");
95
96 /**
97 * The file is added, removed or updated from the repository, thus its
98 * up-to-date with the version in the repository. See also isUpdate()
99 */
100 public static final ScmFileStatus UPDATED = new ScmFileStatus("updated");
101
102 /**
103 * The file is part of a tag.
104 */
105 public static final ScmFileStatus TAGGED = new ScmFileStatus("tagged");
106
107 /**
108 * The file is locked.
109 */
110 public static final ScmFileStatus LOCKED = new ScmFileStatus("locked");
111
112 /**
113 * The file is in the working tree but is not versioned and not ignored either.
114 */
115 public static final ScmFileStatus UNKNOWN = new ScmFileStatus("unknown");
116
117 /**
118 * @since 1.5
119 * The file is being edited
120 */
121 public static final ScmFileStatus EDITED = new ScmFileStatus("edit");
122
123 /**
124 * The status name.
125 */
126 private final String name;
127
128 private ScmFileStatus(String name) {
129 this.name = name;
130 }
131
132 /**
133 * {@inheritDoc}
134 */
135 public String toString() {
136 return name;
137 }
138
139 /**
140 * There are changes in the working tree that are not committed to the repository, or <br>
141 * the file is unknown for the working tree.
142 *
143 * @return true on changes in the working tree or if the file is unknown
144 */
145 public boolean isStatus() {
146 return this == UNKNOWN || isDiff();
147 }
148
149 /**
150 * There are changes in the working tree that are not committed to the repository. <br>
151 *
152 * @return true on changes in the working tree
153 */
154 public boolean isDiff() {
155 return this == ADDED || this == DELETED || this == MODIFIED;
156 }
157
158 /**
159 * @return true if the file was part of a transaction with the repository
160 */
161 public boolean isTransaction() {
162 return this == CHECKED_IN || this == CHECKED_OUT || this == LOCKED || this == TAGGED || isUpdate();
163 }
164
165 /**
166 * File is part of an update transaction with the repository.<br>
167 * Note: ADDED and REMOVED are not an update status since they indicates
168 * that the working tree has changed.<br>
169 * An update indicates the opposite, that the repository was changed compared to
170 * the working tree and that it is now synchronized unless there are conflicts.
171 *
172 * @return true if the status is conflict, updated or patched
173 */
174 public boolean isUpdate() {
175 return this == CONFLICT || this == UPDATED || this == PATCHED;
176 }
177 }