VCS: file changed remotely hint
[fedora-idea.git] / vcs-api / src / com / intellij / openapi / vcs / AbstractVcs.java
blob3b1272497818c9a8838276f58fbdcc4a261457b5
1 /*
2 * Copyright 2000-2007 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.vcs;
18 import com.intellij.openapi.actionSystem.AnAction;
19 import com.intellij.openapi.diagnostic.Logger;
20 import com.intellij.openapi.options.Configurable;
21 import com.intellij.openapi.options.UnnamedConfigurable;
22 import com.intellij.openapi.project.Project;
23 import com.intellij.openapi.vcs.annotate.AnnotationProvider;
24 import com.intellij.openapi.vcs.changes.ChangeListEditHandler;
25 import com.intellij.openapi.vcs.changes.ChangeProvider;
26 import com.intellij.openapi.vcs.changes.VcsDirtyScope;
27 import com.intellij.openapi.vcs.checkin.CheckinEnvironment;
28 import com.intellij.openapi.vcs.diff.DiffProvider;
29 import com.intellij.openapi.vcs.diff.RevisionSelector;
30 import com.intellij.openapi.vcs.history.VcsHistoryProvider;
31 import com.intellij.openapi.vcs.history.VcsRevisionNumber;
32 import com.intellij.openapi.vcs.merge.MergeProvider;
33 import com.intellij.openapi.vcs.rollback.RollbackEnvironment;
34 import com.intellij.openapi.vcs.update.UpdateEnvironment;
35 import com.intellij.openapi.vfs.VirtualFile;
36 import org.jetbrains.annotations.NonNls;
37 import org.jetbrains.annotations.Nullable;
39 import java.util.List;
41 /**
42 * The base class for a version control system integrated with IDEA.
44 * @see ProjectLevelVcsManager
46 public abstract class AbstractVcs extends StartedActivated {
48 private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.AbstractVcs");
50 @NonNls protected static final String ourIntegerPattern = "\\d+";
52 protected final Project myProject;
53 private final String myName;
54 private final VcsKey myKey;
55 private VcsShowSettingOption myUpdateOption;
56 private VcsShowSettingOption myStatusOption;
58 public AbstractVcs(final Project project, final String name) {
59 super(project);
61 myProject = project;
62 myName = name;
63 myKey = new VcsKey(myName);
66 // acts as adapter
67 protected void start() throws VcsException {
70 protected void shutdown() throws VcsException {
73 protected void activate() {
76 protected void deactivate() {
79 @NonNls
80 public final String getName() {
81 return myName;
84 @NonNls
85 public abstract String getDisplayName();
87 public abstract Configurable getConfigurable();
89 @Nullable
90 public TransactionProvider getTransactionProvider() {
91 return null;
94 @Nullable
95 public ChangeProvider getChangeProvider() {
96 return null;
99 public final VcsConfiguration getConfiguration() {
100 return VcsConfiguration.getInstance(myProject);
104 * Returns the interface for performing check out / edit file operations.
106 * @return the interface implementation, or null if none is provided.
108 @Nullable
109 public EditFileProvider getEditFileProvider() {
110 return null;
113 public void directoryMappingChanged() {
116 public boolean markExternalChangesAsUpToDate() {
117 return false;
121 * Returns the interface for performing checkin / commit / submit operations.
123 * @return the checkin interface, or null if checkins are not supported by the VCS.
125 @Nullable
126 public CheckinEnvironment getCheckinEnvironment() {
127 return null;
131 * Returns the interface for performing revert / rollback operations.
133 * @return the rollback interface, or null if rollbacks are not supported by the VCS.
135 @Nullable
136 public RollbackEnvironment getRollbackEnvironment() {
137 return null;
140 @Nullable
141 public VcsHistoryProvider getVcsHistoryProvider() {
142 return null;
145 @Nullable
146 public VcsHistoryProvider getVcsBlockHistoryProvider() {
147 return null;
150 public String getMenuItemText() {
151 return getDisplayName();
155 * Returns the interface for performing update/sync operations.
157 * @return the update interface, or null if the updates are not supported by the VCS.
159 @Nullable
160 public UpdateEnvironment getUpdateEnvironment() {
161 return null;
165 * Returns true if the specified file path is located under a directory which is managed by this VCS.
166 * This method is called only for directories which are mapped to this VCS in the project configuration.
168 * @param filePath the path to check.
169 * @return true if the path is managed by this VCS, false otherwise.
171 public boolean fileIsUnderVcs(FilePath filePath) {
172 return true;
176 * Returns true if the specified file path represents a file which exists in the VCS repository (is neither
177 * unversioned nor scheduled for addition).
178 * This method is called only for directories which are mapped to this VCS in the project configuration.
180 * @param path the path to check.
181 * @return true if the corresponding file exists in the repository, false otherwise.
183 public boolean fileExistsInVcs(FilePath path) {
184 final VirtualFile virtualFile = path.getVirtualFile();
185 if (virtualFile != null) {
186 final FileStatus fileStatus = FileStatusManager.getInstance(myProject).getStatus(virtualFile);
187 return fileStatus != FileStatus.UNKNOWN && fileStatus != FileStatus.ADDED;
189 return true;
192 public static boolean fileInVcsByFileStatus(final Project project, final FilePath path) {
193 final VirtualFile virtualFile = path.getVirtualFile();
194 if (virtualFile != null) {
195 final FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(virtualFile);
196 return fileStatus != FileStatus.UNKNOWN && fileStatus != FileStatus.ADDED && fileStatus != FileStatus.IGNORED;
198 return true;
202 * Returns the interface for performing "check status" operations (operations which show the differences between
203 * the local working copy state and the latest server state).
205 * @return the status interface, or null if the check status operation is not supported or required by the VCS.
207 @Nullable
208 public UpdateEnvironment getStatusEnvironment() {
209 return null;
212 @Nullable
213 public AnnotationProvider getAnnotationProvider() {
214 return null;
217 @Nullable
218 public DiffProvider getDiffProvider() {
219 return null;
222 public VcsShowSettingOption getUpdateOptions() {
223 return myUpdateOption;
227 public VcsShowSettingOption getStatusOptions() {
228 return myStatusOption;
231 public void loadSettings() {
232 final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
234 if (getUpdateEnvironment() != null) {
235 myUpdateOption = vcsManager.getStandardOption(VcsConfiguration.StandardOption.UPDATE, this);
238 if (getStatusEnvironment() != null) {
239 myStatusOption = vcsManager.getStandardOption(VcsConfiguration.StandardOption.STATUS, this);
243 public FileStatus[] getProvidedStatuses() {
244 return null;
248 * Returns the interface for selecting file version numbers.
250 * @return the revision selector implementation, or null if none is provided.
251 * @since 5.0.2
253 @Nullable
254 public RevisionSelector getRevisionSelector() {
255 return null;
259 * Returns the interface for performing integrate operations (merging changes made in another branch of
260 * the project into the current working copy).
262 * @return the update interface, or null if the integrate operations are not supported by the VCS.
264 @Nullable
265 public UpdateEnvironment getIntegrateEnvironment() {
266 return null;
269 @Nullable
270 public CommittedChangesProvider getCommittedChangesProvider() {
271 return null;
274 @Nullable
275 public final CachingCommittedChangesProvider getCachingCommittedChangesProvider() {
276 CommittedChangesProvider provider = getCommittedChangesProvider();
277 if (provider instanceof CachingCommittedChangesProvider) {
278 return (CachingCommittedChangesProvider)provider;
280 return null;
284 * For some version controls (like Git) the revision parsing is dependent
285 * on the the specific repository instance since the the revision number
286 * returned from this method is later used for comparison information.
287 * By default, this method invokes {@link #parseRevisionNumber(String)}.
288 * The client code should invoke this method, if it expect ordering information
289 * from revision numbers.
291 * @param revisionNumberString the string to be parsed
292 * @param path the path for which revsion number is queried
293 * @return the parsed revision number
295 @Nullable
296 public VcsRevisionNumber parseRevisionNumber(String revisionNumberString, FilePath path) {
297 return parseRevisionNumber(revisionNumberString);
300 @Nullable
301 public VcsRevisionNumber parseRevisionNumber(String revisionNumberString) {
302 return null;
306 * @return null if does not support revision parsing
308 @Nullable
309 public String getRevisionPattern() {
310 return null;
314 * Checks if the specified directory is managed by this version control system (regardless of the
315 * project VCS configuration). For example, for CVS this checks the presense of "CVS" admin directories.
316 * This method is used for VCS autodetection during initial project creation and VCS configuration.
318 * @param dir the directory to check.
319 * @return <code>true</code> if directory is managed by this VCS
321 public boolean isVersionedDirectory(VirtualFile dir) {
322 return false;
326 * If VCS does not implement detection whether directory is versioned ({@link #isVersionedDirectory(com.intellij.openapi.vfs.VirtualFile)}),
327 * it should return <code>false</code>. Otherwise return <code>true</code>
329 public boolean supportsVersionedStateDetection() {
330 return true;
334 * Returns the configurable to be shown in the VCS directory mapping dialog which should be displayed
335 * for configuring VCS-specific settings for the specified root, or null if no such configuration is required.
336 * The VCS-specific settings are stored in {@link com.intellij.openapi.vcs.VcsDirectoryMapping#getRootSettings()}.
338 * @param mapping the mapping being configured
339 * @return the configurable instance, or null if no configuration is required.
341 @Nullable
342 public UnnamedConfigurable getRootConfigurable(VcsDirectoryMapping mapping) {
343 return null;
346 @Nullable
347 public RootsConvertor getCustomConvertor() {
348 return null;
351 public interface RootsConvertor {
352 List<VirtualFile> convertRoots(List<VirtualFile> result);
356 * Returns the implementation of the merge provider which is used to load the revisions to be merged
357 * for a particular file.
359 * @return the merge provider implementation, or null if the VCS doesn't support merge operations.
361 @Nullable
362 public MergeProvider getMergeProvider() {
363 return null;
367 * List of actions that would be added to local changes browser if there are any changes for this VCS
369 @Nullable
370 public List<AnAction> getAdditionalActionsForLocalChange() {
371 return null;
374 @Nullable
375 public ChangeListEditHandler getEditHandler() {
376 return null;
379 public boolean allowsNestedRoots() {
380 return false;
383 public List<VirtualFile> filterUniqueRoots(final List<VirtualFile> in) {
384 FilterDescendantVirtualFiles.filter(in);
385 return in;
388 @Nullable
389 public VcsExceptionsHotFixer getVcsExceptionsHotFixer() {
390 return null;
393 // for VCSes, that tracks their dirty scopes themselves - for instance, P4
394 public VcsDirtyScope adjustDirtyScope(final VcsDirtyScope scope) {
395 return scope;
398 public Project getProject() {
399 return myProject;
402 protected static VcsKey createKey(final String name) {
403 return new VcsKey(name);
406 public final VcsKey getKeyInstanceMethod() {
407 return myKey;
410 // todo ?
411 public boolean checkImmediateParentsBeforeCommit() {
412 return false;