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 * TODO move to a real enum 025 * <p> 026 * Typesafe enum for file status 027 * </p> 028 * <p> 029 * There are two types of status defined in this class: <br> 030 * 1) Status: Changes in the working tree, not yet committed to the repository eg. MODIFIED <br> 031 * 2) Transaction: The file is part of some transaction with the repository eg. CHECKED_IN 032 * </p> 033 * 034 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a> 035 * 036 */ 037public final class ScmFileStatus implements Serializable { 038 private static final long serialVersionUID = -7840223279162817915L; 039 040 /** 041 * File is added to the working tree and does not yet exist in the repository 042 */ 043 public static final ScmFileStatus ADDED = new ScmFileStatus("added"); 044 045 /** 046 * File is removed from the working tree thus not revisioned anymore.<br> 047 * The file is still present in the repository.<br> 048 * The file could be deleted from the filesystem depending on the provider. 049 */ 050 public static final ScmFileStatus DELETED = new ScmFileStatus("deleted"); 051 052 /** 053 * The file has been modified in the working tree. 054 */ 055 public static final ScmFileStatus MODIFIED = new ScmFileStatus("modified"); 056 057 /** 058 * The file has been renamed or moved in the working tree. 059 * @since 1.7 060 */ 061 public static final ScmFileStatus RENAMED = new ScmFileStatus("renamed"); 062 063 /** 064 * The file has been copied in the working tree. 065 * @since 1.7 066 */ 067 public static final ScmFileStatus COPIED = new ScmFileStatus("copied"); 068 069 /** 070 * The file is missing in the working tree. 071 */ 072 public static final ScmFileStatus MISSING = new ScmFileStatus("missing"); 073 074 /** 075 * File from working tree is checked into the repository 076 */ 077 public static final ScmFileStatus CHECKED_IN = new ScmFileStatus("checked-in"); 078 079 /** 080 * File is checked out from the repository and into the working tree 081 */ 082 public static final ScmFileStatus CHECKED_OUT = new ScmFileStatus("checked-out"); 083 084 /** 085 * The file in the working tree has differences to the one in repository that 086 * conflicts ie. it cannot automatically be merged. 087 */ 088 public static final ScmFileStatus CONFLICT = new ScmFileStatus("conflict"); 089 090 /** 091 * The file in the working tree has been updated with changes from the repository. 092 */ 093 public static final ScmFileStatus PATCHED = new ScmFileStatus("patched"); 094 095 /** 096 * The file is added, removed or updated from the repository, thus its 097 * up-to-date with the version in the repository. See also isUpdate() 098 */ 099 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}