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