2 * Copyright (c) 2004 JetBrains s.r.o. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * -Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * -Redistribution in binary form must reproduct the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the distribution.
15 * Neither the name of JetBrains or IntelliJ IDEA
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * This software is provided "AS IS," without a warranty of any kind. ALL
20 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
21 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
22 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. JETBRAINS AND ITS LICENSORS SHALL NOT
23 * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
24 * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
25 * DERIVATIVES. IN NO EVENT WILL JETBRAINS OR ITS LICENSORS BE LIABLE FOR ANY LOST
26 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
27 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
28 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
29 * IF JETBRAINS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 package com
.intellij
.cvsSupport2
.updateinfo
;
34 import com
.intellij
.cvsSupport2
.CvsVcs2
;
35 import com
.intellij
.cvsSupport2
.application
.CvsEntriesManager
;
36 import com
.intellij
.cvsSupport2
.cvshandlers
.CvsUpdatePolicy
;
37 import com
.intellij
.cvsSupport2
.cvsoperations
.cvsMessages
.CvsMessagesAdapter
;
38 import com
.intellij
.cvsSupport2
.cvsoperations
.cvsMessages
.FileMessage
;
39 import com
.intellij
.cvsSupport2
.history
.CvsRevisionNumber
;
40 import com
.intellij
.cvsSupport2
.util
.CvsVfsUtil
;
41 import com
.intellij
.openapi
.diagnostic
.Logger
;
42 import com
.intellij
.openapi
.project
.Project
;
43 import com
.intellij
.openapi
.vcs
.update
.FileGroup
;
44 import com
.intellij
.openapi
.vcs
.update
.UpdatedFiles
;
45 import com
.intellij
.openapi
.vfs
.VirtualFile
;
46 import org
.jetbrains
.annotations
.Nullable
;
47 import org
.netbeans
.lib
.cvsclient
.admin
.Entry
;
51 public class UpdatedFilesProcessor
extends CvsMessagesAdapter
{
52 private static final Logger LOG
= Logger
.getInstance("#com.intellij.cvsSupport2.updateinfo.UpdatedFilesProcessor");
54 private final Project myProject
;
55 private final UpdatedFiles myUpdatedFiles
;
57 public UpdatedFilesProcessor(Project project
, UpdatedFiles updatedFiles
) {
59 myUpdatedFiles
= updatedFiles
;
62 public void addFileMessage(FileMessage message
) {
63 String path
= message
.getFileAbsolutePath();
64 VirtualFile virtualFile
= getVirtualFileFor(path
);
65 FileGroup collection
= getCollectionFor(message
.getType(), virtualFile
);
66 LOG
.assertTrue(collection
!= null, String
.valueOf(message
.getType()));
67 final CvsRevisionNumber revision
= message
.getRevision();
68 collection
.add(path
, CvsVcs2
.getKey(), revision
);
71 private FileGroup
getCollectionFor(int messageType
, @Nullable VirtualFile vFile
) {
72 switch (messageType
) {
73 case FileMessage
.MODIFIED
:
74 return myUpdatedFiles
.getGroupById(FileGroup
.MODIFIED_ID
);
75 case FileMessage
.MERGED
:
76 return getMergedFileGroup(vFile
, FileGroup
.MERGED_ID
);
77 case FileMessage
.MERGED_WITH_CONFLICTS
:
78 return getMergedFileGroup(vFile
, FileGroup
.MERGED_WITH_CONFLICT_ID
);
79 case FileMessage
.CREATED_BY_SECOND_PARTY
:
80 return myUpdatedFiles
.getGroupById(CvsUpdatePolicy
.CREATED_BY_SECOND_PARTY_ID
);
81 case FileMessage
.NOT_IN_REPOSITORY
:
82 return myUpdatedFiles
.getGroupById(FileGroup
.UNKNOWN_ID
);
83 case FileMessage
.LOCALLY_ADDED
:
84 return myUpdatedFiles
.getGroupById(FileGroup
.LOCALLY_ADDED_ID
);
85 case FileMessage
.LOCALLY_REMOVED
:
86 return myUpdatedFiles
.getGroupById(FileGroup
.LOCALLY_REMOVED_ID
);
87 case FileMessage
.REMOVED_FROM_REPOSITORY
:
88 return myUpdatedFiles
.getGroupById(FileGroup
.REMOVED_FROM_REPOSITORY_ID
);
89 case FileMessage
.CREATED
:
91 return myUpdatedFiles
.getGroupById(FileGroup
.CREATED_ID
);
93 case FileMessage
.UPDATING
:
96 return myUpdatedFiles
.getGroupById(FileGroup
.RESTORED_ID
);
99 return myUpdatedFiles
.getGroupById(FileGroup
.UPDATED_ID
);
102 case FileMessage
.PATCHED
:
103 return myUpdatedFiles
.getGroupById(FileGroup
.UPDATED_ID
);
104 case FileMessage
.REMOVED_FROM_SERVER_CONFLICT
:
105 return myUpdatedFiles
.getGroupById(CvsUpdatePolicy
.MODIFIED_REMOVED_FROM_SERVER_ID
);
106 case FileMessage
.LOCALLY_REMOVED_CONFLICT
:
107 return myUpdatedFiles
.getGroupById(CvsUpdatePolicy
.LOCALLY_REMOVED_MODIFIED_ON_SERVER_ID
);
110 return myUpdatedFiles
.getGroupById(FileGroup
.UNKNOWN_ID
);
113 private FileGroup
getMergedFileGroup(final VirtualFile vFile
, final String textMergedId
) {
115 Entry entry
= CvsEntriesManager
.getInstance().getEntryFor(vFile
);
116 if (entry
!= null && entry
.isBinary()) {
117 return myUpdatedFiles
.getGroupById(CvsUpdatePolicy
.BINARY_MERGED_ID
);
120 return myUpdatedFiles
.getGroupById(textMergedId
);
124 public static VirtualFile
getVirtualFileFor(final String path
) {
125 if (path
== null) return null;
126 return CvsVfsUtil
.findFileByPath(path
.replace(File
.separatorChar
, '/'));