2 * Copyright 2000-2013 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.execution.ui.ConsoleViewContentType;
19 import com.intellij.lifecycle.PeriodicalTasksCloser;
20 import com.intellij.openapi.application.ApplicationManager;
21 import com.intellij.openapi.editor.markup.TextAttributes;
22 import com.intellij.openapi.progress.ProcessCanceledException;
23 import com.intellij.openapi.project.Project;
24 import com.intellij.openapi.util.Computable;
25 import com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener;
26 import com.intellij.openapi.vcs.history.VcsHistoryCache;
27 import com.intellij.openapi.vcs.impl.ContentRevisionCache;
28 import com.intellij.openapi.vcs.impl.VcsDescriptor;
29 import com.intellij.openapi.vcs.update.UpdatedFiles;
30 import com.intellij.openapi.vfs.VirtualFile;
31 import com.intellij.util.Processor;
32 import com.intellij.util.messages.Topic;
33 import org.jetbrains.annotations.NonNls;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
37 import java.util.List;
40 * Manages the version control systems used by a specific project.
42 public abstract class ProjectLevelVcsManager {
44 public static final Topic<VcsListener> VCS_CONFIGURATION_CHANGED = Topic.create("VCS configuration changed", VcsListener.class);
45 public static final Topic<VcsListener> VCS_CONFIGURATION_CHANGED_IN_PLUGIN = Topic.create("VCS configuration changed in VCS plugin", VcsListener.class);
47 public abstract void iterateVfUnderVcsRoot(VirtualFile file, Processor<VirtualFile> processor);
50 * Returns the <code>ProjectLevelVcsManager<code> instance for the specified project.
52 * @param project the project for which the instance is requested.
53 * @return the manager instance.
55 public static ProjectLevelVcsManager getInstance(Project project) {
56 return PeriodicalTasksCloser.getInstance().safeGetComponent(project, ProjectLevelVcsManager.class);
60 * Gets the instance of the component if the project wasn't disposed. If the project was
61 * disposed, throws ProcessCanceledException. Should only be used for calling from background
62 * threads (for example, committed changes refresh thread).
64 * @param project the project for which the component instance should be retrieved.
65 * @return component instance
67 public static ProjectLevelVcsManager getInstanceChecked(final Project project) {
68 return ApplicationManager.getApplication().runReadAction(new Computable<ProjectLevelVcsManager>() {
69 public ProjectLevelVcsManager compute() {
70 if (project.isDisposed()) throw new ProcessCanceledException();
71 return getInstance(project);
77 * Returns the list of all registered version control systems.
79 * @return the list of registered version control systems.
81 public abstract VcsDescriptor[] getAllVcss();
84 * Returns the version control system with the specified name.
86 * @param name the name of the VCS to find.
87 * @return the VCS instance, or null if none is found.
90 public abstract AbstractVcs findVcsByName(@NonNls String name);
93 public abstract VcsDescriptor getDescriptor(final String name);
95 * Checks if all files in the specified array are managed by the specified VCS.
97 * @param abstractVcs the VCS to check.
98 * @param files the files to check.
99 * @return true if all files are managed by the VCS, false otherwise.
101 public abstract boolean checkAllFilesAreUnder(AbstractVcs abstractVcs, VirtualFile[] files);
104 * Returns the VCS managing the specified file.
106 * @param file the file to check.
107 * @return the VCS instance, or null if the file does not belong to any module or the module
108 * it belongs to is not under version control.
111 public abstract AbstractVcs getVcsFor(@NotNull VirtualFile file);
114 * Returns the VCS managing the specified file path.
116 * @param file the file to check.
117 * @return the VCS instance, or null if the file does not belong to any module or the module
118 * it belongs to is not under version control.
121 public abstract AbstractVcs getVcsFor(FilePath file);
124 * Return the parent directory of the specified file which is mapped to a VCS.
126 * @param file the file for which the root is requested.
127 * @return the root, or null if the specified file is not in a VCS-managed directory.
130 public abstract VirtualFile getVcsRootFor(@Nullable VirtualFile file);
133 * Return the parent directory of the specified file path which is mapped to a VCS.
135 * @param file the file for which the root is requested.
136 * @return the root, or null if the specified file is not in a VCS-managed directory.
139 public abstract VirtualFile getVcsRootFor(FilePath file);
142 public abstract VcsRoot getVcsRootObjectFor(final VirtualFile file);
145 public abstract VcsRoot getVcsRootObjectFor(FilePath file);
148 * Checks if the specified VCS is used by any of the modules in the project.
150 * @param vcs the VCS to check.
151 * @return true if the VCS is used by any of the modules, false otherwise
153 public abstract boolean checkVcsIsActive(AbstractVcs vcs);
156 * Checks if the VCS with the specified name is used by any of the modules in the project.
158 * @param vcsName the name of the VCS to check.
159 * @return true if the VCS is used by any of the modules, false otherwise
161 public abstract boolean checkVcsIsActive(@NonNls String vcsName);
164 * Returns the list of VCSes used by at least one module in the project.
166 * @return the list of VCSes used in the project.
168 public abstract AbstractVcs[] getAllActiveVcss();
170 public abstract boolean hasActiveVcss();
172 public abstract boolean hasAnyMappings();
175 public abstract void addMessageToConsoleWindow(String message, TextAttributes attributes);
177 public abstract void addMessageToConsoleWindow(@Nullable String message, @NotNull ConsoleViewContentType contentType);
180 public abstract VcsShowSettingOption getStandardOption(@NotNull VcsConfiguration.StandardOption option,
181 @NotNull AbstractVcs vcs);
184 public abstract VcsShowConfirmationOption getStandardConfirmation(@NotNull VcsConfiguration.StandardConfirmation option,
188 public abstract VcsShowSettingOption getOrCreateCustomOption(@NotNull String vcsActionName,
189 @NotNull AbstractVcs vcs);
192 public abstract void showProjectOperationInfo(final UpdatedFiles updatedFiles, String displayActionName);
195 * Adds a listener for receiving notifications about changes in VCS configuration for the project.
197 * @param listener the listener instance.
198 * @deprecated use {@link #VCS_CONFIGURATION_CHANGED} instead
202 public abstract void addVcsListener(VcsListener listener);
205 * Removes a listener for receiving notifications about changes in VCS configuration for the project.
207 * @param listener the listener instance.
208 * @deprecated use {@link #VCS_CONFIGURATION_CHANGED} instead
212 public abstract void removeVcsListener(VcsListener listener);
215 * Marks the beginning of a background VCS operation (commit or update).
219 public abstract void startBackgroundVcsOperation();
222 * Marks the end of a background VCS operation (commit or update).
226 public abstract void stopBackgroundVcsOperation();
229 * Checks if a background VCS operation (commit or update) is currently in progress.
231 * @return true if a background operation is in progress, false otherwise.
234 public abstract boolean isBackgroundVcsOperationRunning();
236 public abstract List<VirtualFile> getRootsUnderVcsWithoutFiltering(final AbstractVcs vcs);
238 public abstract VirtualFile[] getRootsUnderVcs(@NotNull AbstractVcs vcs);
241 * Also includes into list all modules under roots
243 public abstract List<VirtualFile> getDetailedVcsMappings(final AbstractVcs vcs);
245 public abstract VirtualFile[] getAllVersionedRoots();
248 public abstract VcsRoot[] getAllVcsRoots();
250 public abstract void updateActiveVcss();
252 public abstract List<VcsDirectoryMapping> getDirectoryMappings();
253 public abstract List<VcsDirectoryMapping> getDirectoryMappings(AbstractVcs vcs);
256 public abstract VcsDirectoryMapping getDirectoryMappingFor(FilePath path);
259 * This method can be used only when initially loading the project configuration!
261 public abstract void setDirectoryMapping(final String path, final String activeVcsName);
263 public abstract void setDirectoryMappings(final List<VcsDirectoryMapping> items);
265 public abstract void iterateVcsRoot(final VirtualFile root, final Processor<FilePath> iterator);
267 public abstract void iterateVcsRoot(final VirtualFile root, final Processor<FilePath> iterator,
268 @Nullable VirtualFileFilter directoryFilter);
271 public abstract AbstractVcs findVersioningVcs(VirtualFile file);
273 public abstract CheckoutProvider.Listener getCompositeCheckoutListener();
275 public abstract VcsHistoryCache getVcsHistoryCache();
276 public abstract ContentRevisionCache getContentRevisionCache();
277 public abstract boolean isFileInContent(final VirtualFile vf);
278 public abstract boolean isIgnored(VirtualFile vf);
281 public abstract VcsAnnotationLocalChangesListener getAnnotationLocalChangesListener();