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; } }