94 |
brianR |
1 |
/*
|
|
|
2 |
* Copyright 2012 Brian Rosenberger (Brutex Network)
|
|
|
3 |
*
|
|
|
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
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
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.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
package net.brutex.xservices.util;
|
|
|
18 |
|
|
|
19 |
import java.io.File;
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
import org.apache.commons.configuration.Configuration;
|
|
|
23 |
import org.apache.commons.configuration.ConfigurationException;
|
|
|
24 |
import org.apache.commons.configuration.PropertiesConfiguration;
|
|
|
25 |
import org.netbeans.lib.cvsclient.Client;
|
|
|
26 |
import org.netbeans.lib.cvsclient.admin.StandardAdminHandler;
|
|
|
27 |
import org.netbeans.lib.cvsclient.command.CommandAbortedException;
|
|
|
28 |
import org.netbeans.lib.cvsclient.command.GlobalOptions;
|
|
|
29 |
import org.netbeans.lib.cvsclient.connection.AuthenticationException;
|
|
|
30 |
import org.netbeans.lib.cvsclient.connection.PServerConnection;
|
|
|
31 |
|
|
|
32 |
public class CVSClient {
|
|
|
33 |
private final File configfile;
|
|
|
34 |
private final PServerConnection connection;
|
|
|
35 |
private final CVSRoot root;
|
|
|
36 |
private final GlobalOptions globalOptions;
|
|
|
37 |
|
|
|
38 |
public final Client client;
|
|
|
39 |
|
|
|
40 |
public CVSClient(File config) throws CommandAbortedException, AuthenticationException, ConfigurationException {
|
|
|
41 |
|
|
|
42 |
if (config == null || !config.exists() || config.isDirectory())
|
|
|
43 |
throw new ConfigurationException("Config file not found");
|
|
|
44 |
|
|
|
45 |
this.configfile = config;
|
|
|
46 |
Configuration configuration = new PropertiesConfiguration(configfile);
|
|
|
47 |
|
|
|
48 |
String cvsroot = configuration.getString("CVSROOT");
|
|
|
49 |
String workdir = configuration.getString("WORKDIR");
|
|
|
50 |
String password = configuration.getString("PASSWORD");
|
|
|
51 |
|
|
|
52 |
this.root = new CVSRoot(cvsroot);
|
|
|
53 |
this.globalOptions = new GlobalOptions();
|
|
|
54 |
globalOptions.setCVSRoot(cvsroot);
|
|
|
55 |
|
|
|
56 |
this.connection = new PServerConnection();
|
|
|
57 |
connection.setUserName(root.user);
|
|
|
58 |
if (password != null) {
|
|
|
59 |
connection.setEncodedPassword(CvsPassword.encode(password));
|
|
|
60 |
} else {
|
|
|
61 |
connection.setEncodedPassword(password);
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
connection.setHostName(root.host);
|
|
|
65 |
connection.setRepository(root.repository);
|
|
|
66 |
connection.open();
|
|
|
67 |
|
|
|
68 |
this.client = new Client(connection, new StandardAdminHandler());
|
|
|
69 |
client.setLocalPath(workdir);
|
|
|
70 |
}
|
|
|
71 |
/**
|
|
|
72 |
* @return
|
|
|
73 |
*/
|
|
|
74 |
public File getConfigFile() {
|
|
|
75 |
return this.configfile;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
public GlobalOptions getGlobalOptions() {
|
|
|
79 |
return this.globalOptions;
|
|
|
80 |
}
|
|
|
81 |
/**
|
|
|
82 |
* @return the connection
|
|
|
83 |
*/
|
|
|
84 |
public PServerConnection getConnection() {
|
|
|
85 |
return connection;
|
|
|
86 |
}
|
|
|
87 |
/**
|
|
|
88 |
* @return the root
|
|
|
89 |
*/
|
|
|
90 |
public CVSRoot getRoot() {
|
|
|
91 |
return root;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
}
|