tags:

views:

315

answers:

3

In a web-app I'm writing, the user is supposed to enter the path in the Perforce repository for the node they're entering. The application is supposed to validate that the entered directory exists in the repo.

I've got the P4Package (p4.jar) lib, and I'm configuring it correctly enough that it works for almost everything, EXCEPT this directory validation. I'm creating a DirEntry (from the p4.jar) using a configured Env and a path, but when I call DirEntry.sync(), it issues an incorrect command. Where I want it to issue the command:

p4 [config info] dirs directory_argument <-- using the dirs command to validate a dir

Instead, it issues:

p4 [config info] dirs directory_argument%1 <-- note extraneous %1

Which always fails, since none of the directories have a %1 at the end of them.

Any help? Is there a different way to check that a directory exists using this package?

+1  A: 

Sounds like the sync command has a bug in relation to dir entries and the command. My suggestion would be to just roll the command yourself, using the perforce command line as that has to be set up anyway in order to use the java library.

Process p = Runtime.getRuntime().exec("p4 dirs " + directory_argument);
BufferedReader stdOut = new BufferedReader(new InputReader(p.InputStream()));
//Read the output of the command and process appropriately after this
workmad3
Ya, I get what you're saying, but this has been around for a long while, and I find it difficult to believe this bug exists. I have the source for the P4Package, and could just modify it to not put in the %1 and repackage the jar, but I have to assume it's there for a reason.
Bill James
A: 

To answer the question myself, it seems to be a bug in the API. Replacing the %1 with /* caused all the commands to behave correctly.

Unfortunately, this means I now have my own version of the code in our repository, sigh.

Bill James
+1  A: 

I would try another library, P4Java, instead:

http://tek42.com/p4java

P4Java is much newer and I've found works much better than the P4Package. It is used in the Hudson project and I've seen it in the Fisheye source, though, I'm not sure if they are using it or not.

Mike