1

I've seen examples online of using Perforce's p4java api to sync a client workspace with the latest files. Eg:

public List<IFileSpec> sync(List<IFileSpec> fileSpecs,
                        boolean forceUpdate,
                        boolean noUpdate,
                        boolean clientBypass,
                        boolean serverBypass)

But how do I specify it to sync to a specific label? Eg, the equivalent of this at the command-line:

p4 sync @labelname

Is it perhaps via the alternate method that uses SyncOptions?

public List<IFileSpec> sync(List<IFileSpec> fileSpecs,
                        SyncOptions syncOpts)

I had a look at SyncOptions, but didn't see any way to specify a label in there.

Xavier T.
  • 40,509
  • 10
  • 68
  • 97
Gurce
  • 592
  • 7
  • 18

2 Answers2

1

FileSpec which is an implementation of IFileSpec has a label field :

protected  String   label

and the following method :

 void   setLabel(String label)
      Set the label associated with this file spec.

taken from the following link :

https://www.perforce.com/perforce/r15.1/manuals/p4java-javadoc/com/perforce/p4java/impl/generic/core/file/FileSpec.html

Xavier T.
  • 40,509
  • 10
  • 68
  • 97
  • Ah ok, mentioning the FileSpec put me in the right direction. It turned out I could specify a label via a call to FileSpecBuilder.makeFileSpecList("//path/to/project/...@labelname") and then I could feed this in as the first parameter to the sync(filespeclist, ...) method. – Gurce Dec 04 '15 at 10:04
1

After advice above to look into the fileSpecs parameter, I discovered that this method worked for me:

List<IFileSpec> fileSpecsSet = 
    FileSpecBuilder.makeFileSpecList("//path/to/project/...@labelname");
client.sync(fileSpecsSet, true, false, false, false);
Gurce
  • 592
  • 7
  • 18