Jump to content


p4java - Get all shelved files from a changelist

shelved p4java changelist

  • Please log in to reply
3 replies to this topic

#1 eranb

eranb

    Advanced Member

  • Members
  • PipPipPip
  • 55 posts

Posted 12 June 2014 - 11:10 AM

Hi all
I'm starting to use P4Java for some scripts i want to write.
One of the things I want is to list all files in a changelist (also the shelved ones) and create an XML with the data.

I'm using the following code to get the files in the changelist but I couldn't find a way to include the shelved files:

IChangelist cl = server.getChangelist(changelist);
List<IFileSpec> fileList = cl.getFiles(true);
for(IFileSpec file : fileList)
{
	System.out.println(file.getDepotPathString());
}

Any idea what should I do?
I really want to get the files in a list and not in text which I'll need to parse...

Thanks in advance
Eran

#2 P4Shimada

P4Shimada

    Advanced Member

  • Members
  • PipPipPip
  • 831 posts

Posted 13 June 2014 - 12:17 AM

Hi Eran,

You can get shelved changelists with the right GetChangelistsOptions.

List<IChangelistSummary> changes = server.getChangelists(files,
new GetChangelistsOptions().setType(IChangelist.Type.SHELVED));


However, for getting the files you need the "p4 describe -s -S <change>" equivalent.  It does not appear to be implemented yet.
However, there is an existing enhancement request to add shelved file convenience methods to IChangelist. If you email support@perforce.com we can add your email to the request and notify you when it is implemented.


Server.getChangelistFiles(<change>) runs "p4 describe -s", but you need the -S to get the shelved files.

Actually, I think you could send the code for getChangelistFiles() with the -S added.  You could write your own method and call it getShelvedChangelistFiles.

EXAMPLE


List<Map<String, Object>> resultMaps = execMapCmdList(CmdSpec.DESCRIBE,
new String[] { "-s", "-S", "" + id }, null);

List<IFileSpec> fileList = new ArrayList<IFileSpec>();

if (resultMaps != null) {
if ((resultMaps.size() > 0) && (resultMaps.get(0) != null)) {

Map<String, Object> map = resultMaps.get(0);

for (int i = 0; map.get("rev" + i) != null; i++) {
FileSpec fSpec = new FileSpec(map, this, i);
fSpec.setChangelistId(id);
fileList.add(fSpec);
}
}
}
return fileList;

#3 P4Shimada

P4Shimada

    Advanced Member

  • Members
  • PipPipPip
  • 831 posts

Posted 17 June 2014 - 04:27 PM

Hi Eran,

As a follow-up, here is another way (more simple) that you can list shelved files for a change in P4Java using "p4 fstat":

    List<IFileSpec> fspecs = null;
    fspecs = FileSpecBuilder.makeFileSpecList("//depot/...");  
  
    FileStatOutputOptions fso = new FileStatOutputOptions();
    fso.setShelvedFiles(true);

    GetExtendedFilesOptions efo = new GetExtendedFilesOptions();
    efo.setOutputOptions(fso);
    efo.setAffectedByChangelist(changeNumber);

    List<IExtendedFileSpec> shelvedFiles = server.getExtendedFiles(fspecs, efo);


Hope that works for you!

#4 eranb

eranb

    Advanced Member

  • Members
  • PipPipPip
  • 55 posts

Posted 19 June 2014 - 07:27 AM

Thanks a lot!
Will use it.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users