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
;
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
) {
63 myKey
= new VcsKey(myName
);
67 protected void start() throws VcsException
{
70 protected void shutdown() throws VcsException
{
73 protected void activate() {
76 protected void deactivate() {
80 public final String
getName() {
85 public abstract String
getDisplayName();
87 public abstract Configurable
getConfigurable();
90 public TransactionProvider
getTransactionProvider() {
95 public ChangeProvider
getChangeProvider() {
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.
109 public EditFileProvider
getEditFileProvider() {
113 public void directoryMappingChanged() {
116 public boolean markExternalChangesAsUpToDate() {
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.
126 public CheckinEnvironment
getCheckinEnvironment() {
131 * Returns the interface for performing revert / rollback operations.
133 * @return the rollback interface, or null if rollbacks are not supported by the VCS.
136 public RollbackEnvironment
getRollbackEnvironment() {
141 public VcsHistoryProvider
getVcsHistoryProvider() {
146 public VcsHistoryProvider
getVcsBlockHistoryProvider() {
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.
160 public UpdateEnvironment
getUpdateEnvironment() {
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
) {
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
;
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
;
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.
208 public UpdateEnvironment
getStatusEnvironment() {
213 public AnnotationProvider
getAnnotationProvider() {
218 public DiffProvider
getDiffProvider() {
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() {
248 * Returns the interface for selecting file version numbers.
250 * @return the revision selector implementation, or null if none is provided.
254 public RevisionSelector
getRevisionSelector() {
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.
265 public UpdateEnvironment
getIntegrateEnvironment() {
270 public CommittedChangesProvider
getCommittedChangesProvider() {
275 public final CachingCommittedChangesProvider
getCachingCommittedChangesProvider() {
276 CommittedChangesProvider provider
= getCommittedChangesProvider();
277 if (provider
instanceof CachingCommittedChangesProvider
) {
278 return (CachingCommittedChangesProvider
)provider
;
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
296 public VcsRevisionNumber
parseRevisionNumber(String revisionNumberString
, FilePath path
) {
297 return parseRevisionNumber(revisionNumberString
);
301 public VcsRevisionNumber
parseRevisionNumber(String revisionNumberString
) {
306 * @return null if does not support revision parsing
309 public String
getRevisionPattern() {
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
) {
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() {
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.
342 public UnnamedConfigurable
getRootConfigurable(VcsDirectoryMapping mapping
) {
347 public RootsConvertor
getCustomConvertor() {
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.
362 public MergeProvider
getMergeProvider() {
367 * List of actions that would be added to local changes browser if there are any changes for this VCS
370 public List
<AnAction
> getAdditionalActionsForLocalChange() {
375 public ChangeListEditHandler
getEditHandler() {
379 public boolean allowsNestedRoots() {
383 public List
<VirtualFile
> filterUniqueRoots(final List
<VirtualFile
> in
) {
384 FilterDescendantVirtualFiles
.filter(in
);
389 public VcsExceptionsHotFixer
getVcsExceptionsHotFixer() {
393 // for VCSes, that tracks their dirty scopes themselves - for instance, P4
394 public VcsDirtyScope
adjustDirtyScope(final VcsDirtyScope scope
) {
398 public Project
getProject() {
402 protected static VcsKey
createKey(final String name
) {
403 return new VcsKey(name
);
406 public final VcsKey
getKeyInstanceMethod() {
411 public boolean checkImmediateParentsBeforeCommit() {