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
.connections
;
18 import com
.intellij
.cvsSupport2
.connections
.login
.CvsLoginWorker
;
19 import com
.intellij
.cvsSupport2
.cvsExecution
.ModalityContext
;
20 import com
.intellij
.cvsSupport2
.errorHandling
.CannotFindCvsRootException
;
21 import com
.intellij
.cvsSupport2
.javacvsImpl
.io
.ReadWriteStatistics
;
22 import com
.intellij
.openapi
.project
.Project
;
23 import com
.intellij
.util
.ThreeState
;
24 import org
.jetbrains
.annotations
.NotNull
;
25 import org
.netbeans
.lib
.cvsclient
.CvsRoot
;
26 import org
.netbeans
.lib
.cvsclient
.command
.CommandException
;
27 import org
.netbeans
.lib
.cvsclient
.connection
.IConnection
;
34 public abstract class CvsRootProvider
implements CvsEnvironment
{
35 private File myLocalRoot
;
36 private File myAdminRoot
;
37 protected final CvsEnvironment myCvsEnvironment
;
39 public static CvsRootProvider
createOn(File file
) throws CannotFindCvsRootException
{
40 return CvsRootOnFileSystem
.createMeOn(file
);
43 public static CvsRootProvider
createOn(File file
, CvsEnvironment env
){
44 return new CvsRootOnEnvironment(file
, env
);
47 public CvsRootProvider(File rootFile
, CvsEnvironment cvsRoot
) {
48 myLocalRoot
= rootFile
;
49 myAdminRoot
= rootFile
;
50 myCvsEnvironment
= cvsRoot
;
53 public void changeLocalRootTo(@NotNull File localRoot
){
54 myLocalRoot
= localRoot
;
57 public IConnection
createConnection(ReadWriteStatistics statistics
) {
58 return myCvsEnvironment
.createConnection(statistics
);
61 public CvsLoginWorker
getLoginWorker(ModalityContext executor
, Project project
) {
62 return myCvsEnvironment
.getLoginWorker(executor
, project
);
65 public CvsRoot
getCvsRoot() {
66 return myCvsEnvironment
.getCvsRoot();
69 public String
getCvsRootAsString() {
70 return myCvsEnvironment
.getCvsRootAsString();
73 public File
getLocalRoot() {
77 public File
getAdminRoot() {
81 public void changeAdminRootTo(File directory
) {
82 myAdminRoot
= directory
;
85 public boolean isValid() {
86 return myCvsEnvironment
.isValid();
89 public CommandException
processException(CommandException t
) {
90 return myCvsEnvironment
.processException(t
);
93 public boolean isOffline() {
94 return myCvsEnvironment
.isOffline();
98 public boolean equals(Object o
) {
99 if (this == o
) return true;
100 if (!(o
instanceof CvsRootProvider
)) return false;
102 CvsRootProvider that
= (CvsRootProvider
)o
;
104 if (myAdminRoot
!= null ?
!myAdminRoot
.equals(that
.myAdminRoot
) : that
.myAdminRoot
!= null) return false;
105 if (myLocalRoot
!= null ?
!myLocalRoot
.equals(that
.myLocalRoot
) : that
.myLocalRoot
!= null) return false;
107 final ThreeState checkEnv
= checkNulls(myCvsEnvironment
, that
.myCvsEnvironment
);
108 if (! ThreeState
.UNSURE
.equals(checkEnv
)) return ThreeState
.YES
.equals(checkEnv
);
110 final ThreeState checkRoot
= checkNulls(myCvsEnvironment
.getCvsRoot(), that
.myCvsEnvironment
.getCvsRoot());
111 if (! ThreeState
.UNSURE
.equals(checkRoot
)) return ThreeState
.YES
.equals(checkRoot
);
113 if (myCvsEnvironment
.getCvsRoot().getRepositoryPath() != null ?
114 ! myCvsEnvironment
.getCvsRoot().getRepositoryPath().equals(that
.myCvsEnvironment
.getCvsRoot().getRepositoryPath()) :
115 that
.myCvsEnvironment
.getCvsRoot().getRepositoryPath() != null) return false;
117 if (myCvsEnvironment
.getCvsRoot().getCvsRoot() != null ?
118 ! myCvsEnvironment
.getCvsRoot().getCvsRoot().equals(that
.myCvsEnvironment
.getCvsRoot().getCvsRoot()) :
119 that
.myCvsEnvironment
.getCvsRoot().getCvsRoot() != null) return false;
124 private ThreeState
checkNulls(final Object one
, final Object two
) {
125 if ((one
== null) ^
(two
== null)) return ThreeState
.NO
;
126 if (one
== null) return ThreeState
.YES
;
127 return ThreeState
.UNSURE
;
131 public int hashCode() {
132 int result
= myLocalRoot
!= null ? myLocalRoot
.hashCode() : 0;
133 result
= 31 * result
+ (myAdminRoot
!= null ? myAdminRoot
.hashCode() : 0);
134 if (myCvsEnvironment
!= null && myCvsEnvironment
.getCvsRoot() != null) {
135 final CvsRoot root
= myCvsEnvironment
.getCvsRoot();
136 result
= 31 * result
+ (root
.getRepositoryPath() != null ? root
.getRepositoryPath().hashCode() : 0);
137 result
= 31 * result
+ (root
.getCvsRoot() != null ? root
.getCvsRoot().hashCode() : 0);