Link to home
Start Free TrialLog in
Avatar of shilpa_rajith
shilpa_rajith

asked on

Using Javacvs to interact with CVS from Java programming. Problem in remove file.


Hi All,

I am using JavaCvs (cvs client library - NetBeans ) in my java application to communicate with CVS repository. My Add, update, checkout, checkin operations seems to be working fine. But when I remove a file using RemoveCommand, the file seems to be removed. But If i upload another file with the same name into the same directory path , for some reason instead of uploading the new file its  getting back (recovering) the previous file. I don't know why its doing that. Below is the example to illustrate the problem better.

1) Added a file A.txt using AddCommand to CVS.  (Say file A.txt's content A#).

2) Viewed the file A.txt. It showed the content A#

3) Removed the file using RemoveCommand followed by CommitCommnad from CVS.

4) Modified the file A.txt (Say file A.txt's content B#) in my local dir.

5) Added the file A.txt to CVS using AddCommand.

6) Viewed the file A.txt. It showed the content A# instead of B#. Its not adding the new file instead its considering (recovering) the old file it seems.

I did the above operations from Java program using netbean's javacvs api. I don't gave any local working folder, as i am using cvs to store some documents.

I don't know why its behaving that way. Please help me resolve this issue.

Thanks in advance.

Here is my code for removeing the file from cvs.

                  c = new PServerConnection();

                  c.setUserName(username);
                  c.setEncodedPassword(passwd);
                  c.setHostName(host);
                  c.setRepository(reppath);  
                  c.verify();
                  c.open();

                  RPCvsClient client = new RPCvsClient(c, new RPAdminHandler());
                  client.getEventManager().addCVSListener(new BasicListener());
                  client.setRepositoryFullPath(directoryPath);
                  Entry ent = new Entry();
                  ent.setDirectory(false);
                  ent.setName(fileName);
                  ent.setRevision("1");
                  ByteArrayOutputStream streamForCVS = null;
                  client.setEntry(null, ent);

                  ent.setFileStream(streamForCVS);
                  client.setLocalPath(repPath()+"/"+directoryPath);
                  
                  StatusCommand command = new StatusCommand();
                  
                  GlobalOptions globalOptions = new GlobalOptions();
                  client.executeCommand(command, globalOptions);
                  StatusBuilder sb = (StatusBuilder) command.getBuilder();
                  StatusInformation si = sb.getStatusInformation();
                  if ( si != null )
                  {
                        
                        
                        
                  }
                  String repositoryVersionOfFileToBeDeleted = si.getRepositoryRevision();
                  
                  c.close();
                  
                  
                  c.open();
                  

                  client.setRepositoryFullPath(directoryPath);
                  ent = new Entry();
                  ByteArrayOutputStream stream = null;
                  ent.setDirectory(false);
                  ent.setName(fileName);      
                  ent.setRelativePath(directoryPath);      
                  ent.setFileStream(stream);
                  client.setLocalPath(reppath+"/"+directoryPath);      
                  ent.setOptions("-kb");
                  
                  client.setEntry(null, ent);      
                  
                  ent.setFileStream(stream);
                  
                  RemoveCommand removeCommand = new RemoveCommand();
                  removeCommand.setIgnoreLocallyExistingFiles(true);
                  
                  
                  globalOptions = new GlobalOptions();
                  client.executeCommand(removeCommand, globalOptions);
                  c.close();

                  
                  //      Now commit the delete
                  
                  c.open();
                  client = new RPCvsClient(c, new RPAdminHandler());
                  client.getEventManager().addCVSListener(new BasicListener());
                  client.setRepositoryFullPath(directoryPath);
                  ent = new Entry();
                  stream = new ByteArrayOutputStream();      //      faking out the file
                  ent.setDirectory(false);
                  ent.setName(fileName);
                  ent.setRelativePath(directoryPath);      
                  ent.setRevision("-"+repositoryVersionOfFileToBeDeleted);
                  ent.setFileStream(stream);
                  client.setLocalPath(reppath+"/"+directoryPath);      
                  client.setEntry(null, ent);      //      no need to set the file. hence set to null.
                  
                  CommitCommand commitCommand = new CommitCommand();
                  commitCommand.setDeleteCommit(true);
                  commitCommand.setForceCommit(true);
                  
                  commitCommand.setMessage(logMessage);
                  
                  globalOptions = new GlobalOptions();
                  client.setCommand(commitCommand);
                  client.executeCommand(commitCommand, globalOptions);
                  
                  c.close();






SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shilpa_rajith
shilpa_rajith

ASKER


Thanks for the response.

Hi Objects,

In my application the users will upload their documents. Behind the scene I am storing the documents in CVS. So when the users upload their documents,  the application will add them to CVS. When the user wants to view them, then the app will get it from CVS and show them. Basically its kind of document management. So i don't have a local copy as such here. OR i don't know if i am missing something here.

How do i remove the file from History ??


Hi aozarov,

I am calling client.executeCommand() with CommitCommand after RemoveCommand. You can find that at the botton of my code.


Thanks in advance.

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial