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