-
Notifications
You must be signed in to change notification settings - Fork 2
The com.perforce.api is the old API provided by Perforce (the company). It is there only if you need a feature that P4Java does not yet provide. As an example, consider the following:
import com.tek42.perforce.*;
import com.perforce.api.*;
// Normal intialization of P4Java
Depot depot = new Depot();
depot.setPort("hostname:1666");
depot.setUser("username");
depot.setPassword("password");
// P4Java call to return a list of changes...
List<Changelist> changes = depot.getChanges().getChangelists("//depot/KillerApp/..." , \-1, 1);
for(Changelist change : changes) {
System.out.println("Have change: " + change);
}
// While the above was part of P4Java, there is no support for submitting changes or making branches
// or integrating branches. You can do that with the old API as follows... Notice that you do not
// need to provide configuration to the API call. The old config is wrapped via the new getPerforceEnv()
// method.
Branch.integrate(depot.getPerforceEnv(), "//depot/KillerApp/...","BranchName", new StringBuffer(), new Change());
Following the comments, you can see that certain things are not supported in P4Java. These are usually things like submitting changelists.
2. I walked through code and I see it internally uses OS process. Is there a plan to support JNI interface?
No plans to use to use JNI by P4Java. The code you see is part of the original API. P4Java simply wraps the command line tool p4. I have not encountered any disadvantages to this method.
3. If I am logged in to P4 do I still need to pass p4 credentials? If it’s using p4 commands internally shouldn’t it be available to the process?
If you are using tickets via security level 3 in Perforce, you can pass the ticket to the Depot configuration using:
depot.setP4Ticket("TICKET");
This would normally be done with a ticket that doesn’t expire for a sufficiently long period of time.
If you are concerned about embedding your username/password in your program, you could use a properties file that has the encrypted password. You could decrypt it on the fly and pass it to P4Java. This is what many people have done for more robust security.
Please note, that P4Java fully supports the ticket system, if you are using security level 3, P4Java will use p4 login instead of setting P4PASSWD.
Adding support for Perforce entities is very easy with this API. You need to add 3 files to support the entity. For example, counters:
- Add a Counter model class under the com.tek42.perforce.model package. This would represent a counter returned from “p4 counter name”. It would consist of simply a string name and an int value for the class fields.
- A Builder that extends AbstractFormBuilder to handle creating and saving the Counter model. Builders are responsible for taking a Map of key value pairs and calling the appropriate setter/getters on a model bean.
- A Counters class that extends AbstractPerforceTemplate to provide the user callable API for accessing counter objects. APT follows a Template pattern for performing interactions with the P4 client program. You implement a few methods and the logic for calling those methods is handled for you. (Maybe not the best description of this pattern, but that is what Wikipedia is for.
The simplest example in the source to see how this works is the Labels class. You can look at Label.java, LabelBuilder.java, and Labels.java to see how everything works.