update copyright
[fedora-idea.git] / plugins / cvs / cvs-core / src / com / intellij / cvsSupport2 / connections / local / LocalConnection.java
blob48d243fce9fb6bd8ef218badc1f4bb3bf976a5be
1 /*
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.local;
18 import com.intellij.cvsSupport2.config.LocalSettings;
19 import com.intellij.cvsSupport2.connections.ConnectionOnProcess;
20 import com.intellij.cvsSupport2.errorHandling.ErrorRegistry;
21 import com.intellij.execution.configurations.GeneralCommandLine;
22 import org.netbeans.lib.cvsclient.connection.AuthenticationException;
24 import java.io.IOException;
25 import java.util.StringTokenizer;
27 /**
28 * author: lesya
30 public class LocalConnection extends ConnectionOnProcess{
31 private final LocalSettings myLocalSettings;
33 public LocalConnection(String repository, LocalSettings localSettings, ErrorRegistry errorRegistry) {
34 super(repository, errorRegistry);
35 myLocalSettings = localSettings;
38 public void open() throws AuthenticationException {
39 if (!myLocalSettings.isCvsClientVerified()) {
40 verifyServerCapability();
41 myLocalSettings.setCvsClientVerified(true);
44 final GeneralCommandLine commandLine = new GeneralCommandLine();
45 commandLine.setExePath(myLocalSettings.PATH_TO_CVS_CLIENT);
46 StringTokenizer st = new StringTokenizer(myLocalSettings.SERVER_COMMAND.trim());
47 while (st.hasMoreTokens()) {
48 commandLine.addParameter(st.nextToken());
51 execute(commandLine);
54 private void verifyServerCapability() throws AuthenticationException {
55 final GeneralCommandLine commandLine = new GeneralCommandLine();
56 commandLine.setExePath(myLocalSettings.PATH_TO_CVS_CLIENT);
57 commandLine.addParameter("-v");
58 execute(commandLine);
59 try {
60 StringBuilder responseBuilder = new StringBuilder();
61 while(true) {
62 int c = myInputStream.read();
63 if (c == -1) {
64 break;
66 responseBuilder.append((char) c);
68 String[] lines = responseBuilder.toString().split("\n");
69 for (String line : lines) {
70 // check that the first non-empty line does not end with (client)
71 if (line.trim().endsWith("(client)")) {
72 throw new AuthenticationException("CVS client does not support server mode operation", null);
74 if (line.trim().length() > 0) {
75 break;
79 catch (IOException e) {
80 throw new AuthenticationException("Can't read CVS version", e);
82 closeInternal();