2 * Copyright 2000-2009 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
.cvsSupport2
.checkinProject
;
18 import com
.intellij
.CvsBundle
;
19 import com
.intellij
.cvsSupport2
.CvsUtil
;
20 import com
.intellij
.cvsSupport2
.actions
.AddFileOrDirectoryAction
;
21 import com
.intellij
.cvsSupport2
.actions
.RemoveLocallyFileOrDirectoryAction
;
22 import com
.intellij
.cvsSupport2
.config
.CvsConfiguration
;
23 import com
.intellij
.cvsSupport2
.cvsExecution
.CvsOperationExecutor
;
24 import com
.intellij
.cvsSupport2
.cvsExecution
.CvsOperationExecutorCallback
;
25 import com
.intellij
.cvsSupport2
.cvshandlers
.CommandCvsHandler
;
26 import com
.intellij
.cvsSupport2
.cvshandlers
.CvsHandler
;
27 import com
.intellij
.openapi
.project
.Project
;
28 import com
.intellij
.openapi
.vcs
.CheckinProjectPanel
;
29 import com
.intellij
.openapi
.vcs
.FilePath
;
30 import com
.intellij
.openapi
.vcs
.VcsException
;
31 import com
.intellij
.openapi
.vcs
.changes
.Change
;
32 import com
.intellij
.openapi
.vcs
.changes
.ChangesUtil
;
33 import com
.intellij
.openapi
.vcs
.changes
.ContentRevision
;
34 import com
.intellij
.openapi
.vcs
.changes
.ChangeList
;
35 import com
.intellij
.openapi
.vcs
.checkin
.CheckinEnvironment
;
36 import com
.intellij
.openapi
.vcs
.ui
.RefreshableOnComponent
;
37 import com
.intellij
.openapi
.vfs
.VirtualFile
;
40 import java
.util
.Collection
;
41 import java
.util
.Collections
;
42 import java
.util
.List
;
43 import java
.util
.ArrayList
;
48 public class CvsCheckinEnvironment
implements CheckinEnvironment
{
50 private final Project myProject
;
52 public CvsCheckinEnvironment(Project project
) {
56 public RefreshableOnComponent
createAdditionalOptionsPanel(final CheckinProjectPanel panel
) {
58 // TODO: shall these options be available elsewhere?
59 /*return new CvsProjectAdditionalPanel(panel, myProject);*/
62 public String
getDefaultMessageFor(FilePath
[] filesToCheckin
) {
63 if (filesToCheckin
== null) {
66 if (filesToCheckin
.length
!= 1) {
69 return CvsUtil
.getTemplateFor(filesToCheckin
[0]);
72 public String
getHelpId() {
73 return "cvs.commitProject";
76 public String
getCheckinOperationName() {
77 return CvsBundle
.message("operation.name.checkin.project");
80 public List
<VcsException
> commit(List
<Change
> changes
, String preparedComment
) {
81 final Collection
<FilePath
> filesList
= ChangesUtil
.getPaths(changes
);
82 FilePath
[] files
= filesList
.toArray(new FilePath
[filesList
.size()]);
83 final CvsOperationExecutor executor
= new CvsOperationExecutor(myProject
);
84 executor
.setShowErrors(false);
86 final List
<File
> dirsToPrune
= new ArrayList
<File
>();
87 for(Change c
: changes
) {
88 if (c
.getType() == Change
.Type
.DELETED
) {
89 final ContentRevision contentRevision
= c
.getBeforeRevision();
90 assert contentRevision
!= null;
91 final FilePath path
= contentRevision
.getFile();
92 final FilePath parentPath
= path
.getParentPath();
93 if (parentPath
!= null) {
94 dirsToPrune
.add(parentPath
.getIOFile());
99 final CvsConfiguration cvsConfiguration
= CvsConfiguration
.getInstance(myProject
);
101 CvsHandler handler
= CommandCvsHandler
.createCommitHandler(
104 CvsBundle
.message("operation.name.commit.file", files
.length
),
105 cvsConfiguration
.MAKE_NEW_FILES_READONLY
, myProject
,
106 cvsConfiguration
.TAG_AFTER_PROJECT_COMMIT
,
107 cvsConfiguration
.TAG_AFTER_PROJECT_COMMIT_NAME
,
110 executor
.performActionSync(handler
, CvsOperationExecutorCallback
.EMPTY
);
111 return executor
.getResult().getErrorsAndWarnings();
114 public List
<VcsException
> commit(List
<Change
> changes
, String preparedComment
, Object parameters
) {
115 return commit(changes
, preparedComment
);
118 public List
<VcsException
> scheduleMissingFileForDeletion(List
<FilePath
> files
) {
119 final CvsHandler handler
= RemoveLocallyFileOrDirectoryAction
.getDefaultHandler(myProject
, ChangesUtil
.filePathsToFiles(files
));
120 final CvsOperationExecutor executor
= new CvsOperationExecutor(myProject
);
121 executor
.performActionSync(handler
, CvsOperationExecutorCallback
.EMPTY
);
122 return Collections
.emptyList();
125 public List
<VcsException
> scheduleUnversionedFilesForAddition(List
<VirtualFile
> files
) {
126 final CvsHandler handler
= AddFileOrDirectoryAction
.getDefaultHandler(myProject
, files
.toArray(new VirtualFile
[files
.size()]));
127 final CvsOperationExecutor executor
= new CvsOperationExecutor(myProject
);
128 executor
.performActionSync(handler
, CvsOperationExecutorCallback
.EMPTY
);
129 return Collections
.emptyList();
132 public boolean keepChangeListAfterCommit(ChangeList changeList
) {