1 package org.apache.maven.scm;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.Serializable;
23
24 /**
25 * @TODO move to a real enum
26 * <p/>
27 * Typesafe enum for file status
28 * </p>
29 * <p/>
30 * There are two types of status defined in this class: <br/>
31 * 1) Status: Changes in the working tree, not yet committed to the repository eg. MODIFIED <br/>
32 * 2) Transaction: The file is part of some transaction with the repository eg. CHECKED_IN
33 * </p>
34 *
35 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
36 *
37 */
38 public final class ScmFileStatus
39 implements Serializable
40 {
41 private static final long serialVersionUID = -7840223279162817915L;
42
43 /**
44 * File is added to the working tree and does not yet exist in the repository
45 */
46 public static final ScmFileStatus ADDED = new ScmFileStatus( "added" );
47
48 /**
49 * File is removed from the working tree thus not revisioned anymore.<br>
50 * The file is still present in the repository.<br>
51 * The file could be deleted from the filesystem depending on the provider.
52 */
53 public static final ScmFileStatus DELETED = new ScmFileStatus( "deleted" );
54
55 /**
56 * The file has been modified in the working tree.
57 */
58 public static final ScmFileStatus MODIFIED = new ScmFileStatus( "modified" );
59
60 /**
61 * The file has been renamed or moved in the working tree.
62 * @since 1.7
63 */
64 public static final ScmFileStatus RENAMED = new ScmFileStatus( "renamed" );
65
66 /**
67 * The file has been copied in the working tree.
68 * @since 1.7
69 */
70 public static final ScmFileStatus COPIED = new ScmFileStatus( "copied" );
71
72 /**
73 * The file is missing in the working tree.
74 */
75 public static final ScmFileStatus MISSING = new ScmFileStatus( "missing" );
76
77 /**
78 * File from working tree is checked into the repository
79 */
80 public static final ScmFileStatus CHECKED_IN = new ScmFileStatus( "checked-in" );
81
82 /**
83 * File is checked out from the repository and into the working tree
84 */
85 public static final ScmFileStatus CHECKED_OUT = new ScmFileStatus( "checked-out" );
86
87 /**
88 * The file in the working tree has differences to the one in repository that
89 * conflicts ie. it cannot automatically be merged.
90 */
91 public static final ScmFileStatus CONFLICT = new ScmFileStatus( "conflict" );
92
93 /**
94 * The file in the working tree has been updated with changes from the repository.
95 */
96 public static final ScmFileStatus PATCHED = new ScmFileStatus( "patched" );
97
98 /**
99 * The file is added, removed or updated from the repository, thus its
100 * up-to-date with the version in the repository. See also isUpdate()
101 */
102 public static final ScmFileStatus UPDATED = new ScmFileStatus( "updated" );
103
104 /**
105 * The file is part of a tag.
106 */
107 public static final ScmFileStatus TAGGED = new ScmFileStatus( "tagged" );
108
109 /**
110 * The file is locked.
111 */
112 public static final ScmFileStatus LOCKED = new ScmFileStatus( "locked" );
113
114 /**
115 * The file is in the working tree but is not versioned and not ignored either.
116 */
117 public static final ScmFileStatus UNKNOWN = new ScmFileStatus( "unknown" );
118
119 /**
120 * @since 1.5
121 * The file is being edited
122 */
123 public static final ScmFileStatus EDITED = new ScmFileStatus( "edit" );
124
125 /**
126 * The status name
127 */
128 private final String name;
129
130 private ScmFileStatus( String name )
131 {
132 this.name = name;
133 }
134
135 /** {@inheritDoc} */
136 public String toString()
137 {
138 return name;
139 }
140
141 /**
142 * There are changes in the working tree that are not committed to the repository, or <br>
143 * the file is unknown for the working tree.
144 *
145 * @return true on changes in the working tree or if the file is unknown.
146 */
147 public boolean isStatus()
148 {
149 return this == UNKNOWN || isDiff();
150 }
151
152 /**
153 * There are changes in the working tree that are not committed to the repository. <br>
154 *
155 * @return true on changes in the working tree
156 */
157 public boolean isDiff()
158 {
159 return this == ADDED || this == DELETED || this == MODIFIED;
160 }
161
162 /**
163 * @return true if the file was part of a transaction with the repository.
164 */
165 public boolean isTransaction()
166 {
167 return this == CHECKED_IN || this == CHECKED_OUT || this == LOCKED || this == TAGGED || isUpdate();
168 }
169
170 /**
171 * File is part of an update transaction with the repository.<br>
172 * Note: ADDED and REMOVED are not an update status since they indicates
173 * that the working tree has changed.<br>
174 * An update indicates the opposite, that the repository was changed compared to
175 * the working tree and that it is now synchronized unless there are conflicts.
176 *
177 * @return true if the status is conflict, updated or patched.
178 */
179 public boolean isUpdate()
180 {
181 return this == CONFLICT || this == UPDATED || this == PATCHED;
182 }
183 }