Subversion Repositories XServices

Rev

Blame | Last modification | View Log | Download | RSS feed

/*
 *   Copyright 2012 Brian Rosenberger (Brutex Network)
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package net.brutex.xservices.util;

import java.io.File;


import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.netbeans.lib.cvsclient.Client;
import org.netbeans.lib.cvsclient.admin.StandardAdminHandler;
import org.netbeans.lib.cvsclient.command.CommandAbortedException;
import org.netbeans.lib.cvsclient.command.GlobalOptions;
import org.netbeans.lib.cvsclient.connection.AuthenticationException;
import org.netbeans.lib.cvsclient.connection.PServerConnection;

public class CVSClient {
        private final File configfile;
        private final PServerConnection connection;
        private final CVSRoot root;
        private final GlobalOptions globalOptions;
        
        public final Client client;
        
        public CVSClient(File config) throws CommandAbortedException, AuthenticationException, ConfigurationException {

                if (config == null || !config.exists() || config.isDirectory())
                        throw new ConfigurationException("Config file not found");
                
                this.configfile = config;
                Configuration configuration = new PropertiesConfiguration(configfile);

                String cvsroot = configuration.getString("CVSROOT");
                String workdir = configuration.getString("WORKDIR");
                String password = configuration.getString("PASSWORD");
                
                this.root = new CVSRoot(cvsroot);
                this.globalOptions = new GlobalOptions();
                globalOptions.setCVSRoot(cvsroot);
                
                this.connection = new PServerConnection();
                connection.setUserName(root.user);
                if (password != null) {
                        connection.setEncodedPassword(CvsPassword.encode(password));
                } else {
                        connection.setEncodedPassword(password);
                }

                connection.setHostName(root.host);
                connection.setRepository(root.repository);
                connection.open();

                this.client = new Client(connection, new StandardAdminHandler());
                client.setLocalPath(workdir);
}
        /**
         * @return
         */
        public File getConfigFile() {
                return this.configfile;
        }
        
        public GlobalOptions getGlobalOptions() {
                return this.globalOptions;
        }
        /**
         * @return the connection
         */
        public PServerConnection getConnection() {
                return connection;
        }
        /**
         * @return the root
         */
        public CVSRoot getRoot() {
                return root;
        }       
        
}

Generated by GNU Enscript 1.6.5.90.