Jump to content


P4Java API - check if files are locked or resolved

p4java

  • Please log in to reply
1 reply to this topic

#1 eranb

eranb

    Advanced Member

  • Members
  • PipPipPip
  • 55 posts

Posted 03 November 2014 - 01:46 PM

Hi
I'm working on an "automatic changelist submission" script.
The call to IChangelist.submit() do not return any error in case of conflicts so I need to check it by myself before submit.

There are actually 2 things I want to check:
1) if the files need resolving.
2) if the files are lock.

I use IChangelist.getFiles to retrieve the checked out files and then I check each files in a loop.
For some reason, getResolveType always return null and IFileSpec.isLocked() always return false.

I tried to sync (get latest version of the files to the workspace by calling IClient.sync() ) but this call did nothing (checked via GUI to make sure).

Please advise...


code:
	  server = ServerFactory.getOptionsServer("p4java://" + serverAdd, null);
	  server.connect();
	  server.setUserName(userName);
	  server.login(pass);
	 
	 
	  originalChangelist = server.getChangelist(changelistInt);
	  originalClient = server.getClient(originalChangelist.getClientId());
	  fileList = originalChangelist.getFiles(false);
	  String[] unshelveArgs = new String[]{"-s", "-S", "" + changelistInt};
	  List<Map<String, Object>> resultMaps = server.execMapCmdList("DESCRIBE", unshelveArgs, null, null);
	  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, server, i);
		 fSpec.setChangelistId(changelistInt);
		 fileList.add(fSpec);
		}
	   }
	  }
	 
	 
	  depotsMap = getDepotsMappingStringArr(newClientName);
	  newClient = Client.newClient(server, newClientName, "Temp client for submitting changelist " + changelist, newClientPath + changelist, depotsMap);
	  server.createClient(newClient);
	  newClientCreated = true;
	  newClient = server.getClient(newClient.getName());
	  server.setCurrentClient(newClient);
	 
	  Changelist cl = new Changelist(IChangelist.UNKNOWN, newClient.getName(), userName, ChangelistStatus.NEW, originalChangelist.getDate(), originalChangelist.getDescription(), false, (Server)server);
	  newChangelist = newClient.createChangelist(cl);
	  newChangelist.update();
	  newChangelistCreated = true;
	 
	 
	  fileList = newClient.unshelveChangelist(originalChangelist.getId(), null, newChangelist.getId(), false, false);
	  newChangelist = server.getChangelist(newChangelist.getId());
	 
	 
	  //==================================THIS IS THE PART I NEED HELP WITH!!!============================================
	  //Sync workspace with server
	  newClient.sync(newClFilesList, false, false, false, false);
	  newClFilesList = newChangelist.getFiles(false);
	  for (IFileSpec f : newClFilesList)
	  {
	   if (f != null && f.getDepotPathString() != null)
	   {
		if (f.getResolveType() != null  &&  f.getResolveType().equals("unresolved"))
		 throw new Exception("There are un-resolved files in the changelist!");
		if (f.isLocked())
		 throw new Exception("There are locked files in the changelist!");
	   }
	  }
	  //===================================================================================================================
	 

Thanks in advance

#2 eranb

eranb

    Advanced Member

  • Members
  • PipPipPip
  • 55 posts

Posted 03 November 2014 - 01:50 PM

Some comments:
- This is not all of the code (I removed some un-important stuff).
- Except of the marked code, all works fine.
- The flow is:
  - Create new Client and new changelist
  - Un-shelve files from original changelist to the new one
  - Make the necessary checks
  - Submit the new changelist





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users