Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Not able to check-in the files to CVS using JCVS api

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Not able to check-in the files to CVS using JCVS api

    Hi,

    I am creating the component for check-in the files to CVS using JCVS api for one of my project.
    I was not able to check-in the files to CVS using the newly created component .
    Would be appreciated if anyone post the working code for the check-in and check-out operations using JCVS api.

    Here is the code which i have tried to do the things
    package com;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.PrintWriter;
     
    import com.ice.cvsc.CVSArgumentVector;
    import com.ice.cvsc.CVSClient;
    import com.ice.cvsc.CVSEntry;
    import com.ice.cvsc.CVSEntryVector;
    import com.ice.cvsc.CVSProject;
    import com.ice.cvsc.CVSProjectDef;
    import com.ice.cvsc.CVSRequest;
    import com.ice.cvsc.CVSResponse;
    import com.ice.cvsc.CVSScramble;
    import com.ice.cvsc.CVSTracer;
     
    public class CVSMetGen {
     
        public CVSMetGen() {
     
        }
     
          public static void main(String[] args) throws FileNotFoundException {
        	  //CVSMetGen.checkout();
        	  CVSMetGen.checkin();
        	  //CVSMetGen.test();
          }
     
          public static void test() throws FileNotFoundException {
                String userName = "xxxxx";
                String passWord = "xxxxxx";
                String hostname = "localhost";
     
                int cvsPort = 2401;
                boolean isPServer = true;
                int connMethod = CVSRequest.METHOD_INETD;
     
                CVSTracer.turnOn();
        		CVSTracer.setWriter(new PrintWriter(new File("D:\\cvslog.txt")));
     
                CVSClient client = new CVSClient(hostname, cvsPort);
     
                CVSRequest request = new CVSRequest();
                request.setPServer(isPServer);
                request.setUserName(userName);
                request.setHostName(client.getHostName());
     
                String scrambled = CVSScramble.scramblePassword(new String(passWord), 'A');
                request.setPassword(scrambled);
     
                request.setConnectionMethod(connMethod);
                request.setServerCommand("cvs server");
     
                request.setPort(client.getPort());
     
        		request.setRootDirectory("/mys/cvsd/cvsroot");
        		request.setRootRepository("/mys/cvsd/cvsroot" + "/docmgr");
        		request.setLocalDirectory("D:\\cvstest");
        		request.setRepository("docmgr");
     
                request.setCommand("noop");
     
                request.includeNotifies = true;
     
                // This will avoid the 'Directory' reset before the noop command
                request.execInCurDir = true;
                // This will avoid the 'Directory' to the 'execInCurDir directory'
                request.setDirEntry(null);
     
                request.traceRequest = true;
                request.traceResponse = true;
                request.traceProcessing = true;
                request.traceTCPData = true;
     
                request.allowGzipFileMode = false;
     
                request.setEntries(new CVSEntryVector());
                request.setArguments(new CVSArgumentVector());
     
                CVSResponse response = new CVSResponse();
                response = client.processCVSRequest(request, response);
     
                if (response.getStatus() != CVSResponse.OK) {
    	            System.out.println(("CVS command '" + request.getCommand() + "' failed : " + response.getStderr()));
    	        }else {
                      System.out.println("test succeeded!" + request.getCommand());
                }
          }
     
          public static void checkout() {
     
                String userName = "xxxxx";
                String passWord = "xxxxx";
                String hostname = "localhost";
                String repository = "docmgr";
                String rootDirectory = "/mys3/cvsd/cvsroot";
                String localDirectory = "D:\\cvstest";
                String tempdir = "D:\\cvstemp"; 
     
                boolean isPServer = true;
     
                int connMethod = CVSRequest.METHOD_INETD;
     
                int cvsPort = 2401;
     
                CVSArgumentVector arguments = new CVSArgumentVector();
     
                CVSRequest request = new CVSRequest();
     
                request.setArguments( new CVSArgumentVector() );
     
                String checkOutCommand = ":co:N:ANP:deou:";
     
                if ( ! request.parseControlString( checkOutCommand ) ) {
                      System.err.println("not good ctrl string!");
                      System.exit(-1);
                }
     
                arguments.appendArgument( repository );
     
                CVSClient client = new CVSClient( hostname, cvsPort );
                CVSProject project = new CVSProject( client );
     
                CVSProjectDef projectDef = new CVSProjectDef(1, true, false, hostname, userName, rootDirectory, repository);
                project.setProjectDef(projectDef);
     
                project.setUserName( userName );
     
                project.setTempDirectory( tempdir );
                project.setRepository( repository );
                project.setRootDirectory( rootDirectory );
                project.setLocalRootDirectory( localDirectory );
     
                project.setPServer( isPServer );
                project.setConnectionPort( cvsPort );
                project.setConnectionMethod( connMethod );
                project.establishRootEntry( rootDirectory );
                project.setServerCommand("cvs server" );
     
                project.setAllowsGzipFileMode(true);
                project.setGzipStreamLevel(6);
     
                String scrambled = CVSScramble.scramblePassword( passWord, 'A' );
                project.setPassword( scrambled );
     
                request.setPServer( true );
                request.setUserName( userName );
                request.setPassword( project.getPassword() );
     
                request.setConnectionMethod( connMethod );
                request.setServerCommand( project.getServerCommand() );
     
                request.setPort( cvsPort );
                request.setHostName( client.getHostName() );
     
        		request.setRootDirectory(project.getRootDirectory());
        		request.setRootRepository(project.getRootDirectory());
        		request.setLocalDirectory(project.getLocalRootDirectory());
        		request.setRepository(repository);
        		request.setCommand("co");
                request.setSetVariables( project.getSetVariables() );
     
                request.responseHandler = project;
     
                request.allowGzipFileMode = project.allowsGzipFileMode();
                request.setGzipStreamLevel( project.getGzipStreamLevel() );
     
                request.setEntries( new CVSEntryVector() );
                request.appendArguments( arguments );
                request.setUserInterface(new CVSUI());
     
                CVSResponse response = new CVSResponse();
                response = client.processCVSRequest( request, response );
     
                if (response.getStatus() == CVSResponse.OK) {
                      System.out.println("test is OK");
                } else {
                      System.out.println("test failed!");
                }
     
          }  
     
    	public static void checkin() {
     
    		File filePath = createFileInLocalRepository();
     
    		String userName = "xxxx";
    		String passWord = "xxxx";
    		String hostname = "localhost";
    		String repository = "docmgr";
    		String rootDirectory = "/mys3/cvsd/cvsroot";
    		String localDirectory = "D:\\cvstest";
    		String tempdir = "D:\\cvstemp"; 
     
    		boolean isPServer = true;
    		int cvsPort = 2401;
    		int connMethod = CVSRequest.METHOD_INETD;
     
    		CVSTracer.turnOn();
    		CVSArgumentVector arguments = new CVSArgumentVector();
    		arguments.appendArgument(repository);
     
    		CVSClient client = new CVSClient(hostname, cvsPort);
    		CVSProject project = new CVSProject(client);
     
    		CVSProjectDef projectDef = new CVSProjectDef(1, true, false, hostname, userName, rootDirectory, repository);
    		project.setProjectDef(projectDef);
     
    		project.setUserName(userName);
     
    		project.setTempDirectory(tempdir);
    		project.setRepository(repository);
    		project.setRootDirectory(rootDirectory);
    		project.setLocalRootDirectory(localDirectory);
     
    		project.setPServer(isPServer);
    		project.setConnectionPort(cvsPort);
    		project.setConnectionMethod(connMethod);
    		project.establishRootEntry(rootDirectory);
    		project.setServerCommand("cvs server");
     
    		project.setAllowsGzipFileMode(true);
    		project.setGzipStreamLevel(6);
     
    		project.setPassword(CVSScramble.scramblePassword(passWord, 'A'));
     
    		CVSEntry parentEntry = project.getRootEntry();
     
    		CVSEntry newFileEntry = new CVSEntry();
    		String fileToAdd = filePath.getName();
    		System.out.println("File to be added: " + fileToAdd);
     
    		newFileEntry.setName(fileToAdd);
    		newFileEntry.setLocalDirectory(parentEntry.getLocalDirectory());
    		newFileEntry.setRepository(parentEntry.getRepository());
    		newFileEntry.setNewUserFile(true);
    		newFileEntry.setVersion("0");
     
    		File newFile = project.getEntryFile(newFileEntry);
    		newFileEntry.setTimestamp(newFile);
    		newFileEntry.setOptions("-kb");
     
    		CVSEntryVector entries = new CVSEntryVector();
    		entries.appendEntry(parentEntry);
    		entries.appendEntry(newFileEntry);
     
    		CVSRequest request = new CVSRequest();
    		request.handleEntries = true;
    		request.execInCurDir = true;
    		request.setDirEntry(parentEntry);
    		request.setEntries(entries);
     
    		request.sendEntries = true;
    		request.sendArguments = true;
    		request.sendEntryFiles = false;
     
    		request.allowGzipFileMode = true;
    		request.gzipStreamLevel = project.getGzipStreamLevel();
     
    		request.setUserName(userName);
    		request.setPServer(true);
     
    		request.setPassword(CVSScramble.scramblePassword(passWord, 'A'));
     
    		request.setPort(cvsPort);
    		request.setHostName(project.getClient().getHostName());
    		request.setRshProcess(project.getRshProcess());
    		request.setConnectionMethod(connMethod);
     
    		request.setRepository(project.getRepository());
    		request.setRootRepository(project.getRepository());
    		request.setRootDirectory(project.getRootDirectory());
    		request.setLocalDirectory(newFileEntry.getLocalDirectory());
     
    		request.setServerCommand(project.getServerCommand());
    		request.setSetVariables(project.getSetVariables());
    		request.setGzipStreamLevel(project.getGzipStreamLevel());
     
    		request.setCommand("ci");
     
    		request.setUserInterface(new CVSUI());
    		request.includeNotifies = false;
    		request.gzipFileMode = true;
    		request.queueResponse = true;
    		request.traceRequest=true;
     
    		arguments = new CVSArgumentVector();
    		arguments.appendArgument("-f");
    		//arguments.appendArgument("-m");
    		//arguments.appendArgument("Commiting the changes");
    		arguments.appendArgument(fileToAdd);
    		request.setArguments(arguments);	
     
    		CVSResponse response = new CVSResponse();
    		response = client.processCVSRequest(request, response);
     
    		if (response.getStatus() == CVSResponse.OK) {
    			System.out.println("test is OK");
    		} else {
    			System.out.println("test failed!");
    			System.out.println(response.getStderr());
    			System.exit(1);
    		}
     
    		boolean cvsResponse = project.performCVSRequest(request, response);
     
    		if(cvsResponse) {
    			System.out.println("File added to the CVS Repository");
    		}else {
    			System.out.println("File NOT added to the CVS Repository");
    		}
    	}
     
    	private static File createFileInLocalRepository() {
    		File filePath = new File("D:\\cvstest\\docmgr\\xxx.txt");
     
    		if (filePath.exists()) {
    			System.out.println("Error: A file already exists with the same name as the file being uploaded.");
    		}
     
    		FileOutputStream fos = null;
    		try {
    			fos = new FileOutputStream(filePath);
    			fos.write(97);
    			fos.close();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		System.out.println("File written to local cvs repository");
    		return filePath;
    	}    
     
    }


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Not able to check-in the files to CVS using JCVS api

    Is an exception generated? Please post your entire error message.

    For people who are not familiar with "check-in the files to CVS" using the JCVS api, please explain what this means.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Not able to check-in the files to CVS using JCVS api

    Thanks for your reply. The following errors are generated while check in the file to the CVS using jcvs api.

    Response error : cvs server: Up-to-date check failed for `a1.txt'
    cvs [server aborted]: correct above errors first!

    Request failed - cvs server: Up-to-date check failed for `a1.txt'
    cvs [server aborted]: correct above errors first!

    File NOT added to cvs repository.
    .

    Please provide me the working code if you have already tried the same in any of your project.

Similar Threads

  1. How to create or edit .ser files in Jar files
    By xbill in forum Java IDEs
    Replies: 1
    Last Post: May 18th, 2011, 05:15 AM
  2. Seraching through files in a folder for a pattern match inside the files.
    By dazzabiggs in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 2nd, 2011, 08:35 AM
  3. Replies: 1
    Last Post: March 22nd, 2011, 06:59 PM
  4. how to check the value
    By javaking in forum Java Servlet
    Replies: 2
    Last Post: July 22nd, 2010, 06:56 AM
  5. Problem in AWT and IFrame implementaion
    By AZBOY2000 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: April 24th, 2009, 03:41 AM