Using option classes

This section shows some common usage patterns you can use when coding with P4Java.

Server options

There are a variety of properties you can set for your Perforce P4Java application when acquiring an IOptionsServer object.

Setting your application's program name and version:

Setting your program name and version is recommended. You can see these values in your Perforce server log for commands submitted by this application.

IOptionsServer server = 
    ServerFactory.getOptionsServer("p4java://perforce:1666", null, 
        new UsageOptions(props).setProgramName("JavaBuilder").setProgramVersion("1.0"));

Properties

See the P4Java API Javadoc for information on the PropertyDefs and RpcPropertyDefs classes.

PropertyDefs.WRITE_IN_PLACE_KEY

Setting the PropertyDefs.WRITE_IN_PLACE_KEY to true can improve sync performance to Windows platforms due to a known Java limitation.

Properties props = System.getProperties();
props.put(PropertyDefs.WRITE_IN_PLACE_KEY, "true");

IOptionsServer server = 
    ServerFactory.getOptionsServer("p4java://perforce:1666", props, null);

IClient

Setting your P4CLIENT

IClient client = server.getClient("myclient");
server.setCurrentClient(client);

FileSpecBuilder

Using FileSpecBuilder to create IFileSpec Lists:

FileSpecBuilder.makeFileSpecList("//...@2009/05/10:00:00,2010/05/10:05:00");

FileSpecBuilder.makeFileSpecList("//depot/dev/...@release_12.1_label");

IFileSpec

Using chainable setters when using Options objects:

List<IFileSpec> syncFiles = 
    client.sync(FileSpecBuilder.makeFileSpecList("//depot/..."), 
        new SyncOptions().setNoUpdate(true));
List<IFileSpec> openedFiles = 
    server.getOpenedFiles(FileSpecBuilder.makeFileSpecList("//..."), 
        new OpenedFilesOptions().setUserName(user).setClientName(client);