Jump to content


p4java editfiles - empty file list problem

p4java editfiles changelist

  • Please log in to reply
8 replies to this topic

#1 karidrgn

karidrgn

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 14 April 2014 - 11:01 PM

I'm trying to create a change list filled with a file that I want to edit using p4java api. My code looks like this:

String fileSpec = "//depot/SIT/atf-main/foundation/util/src/test/resources/";
String testFileName = "perforceTestFile.txt";

List<IFileSpec> specList = FileSpecBuilder.makeFileSpecList(location + file);
//..code to connect to client - works

Changelist myChangeList = new Changelist(IChangelist.UNKNOWN, perforceClient.getName(), userName,
		 ChangelistStatus.NEW, new Date(), description.toString(), shelved, (Server) perforceServer);
IChangelist iMyChangeList = perforceClient.createChangelist(myChangeList);
EditFilesOptions editFilesOptions = new EditFilesOptions();
	 editFilesOptions.setChangelistId(iMyChangeList.getId());
iMyChangeList.update();

//the folowing returns no files in the editfiles list
List<IFileSpec> editFilesList = perforceClient.editFiles(specList, noUpdate, bypassClientUpdate,
		 iMyChangeList.getId(), null);

Why am I getting an empty editFilesList? I have another method that is using the perforceServer.getDepotFiles(specList,null) and perforceServer.getFileContents(specList) that works.

How can I debug this?
I also tried something similar using the addfiles() method and got the same result.

#2 P4Matt

P4Matt

    Advanced Member

  • Members
  • PipPipPip
  • 1383 posts

Posted 14 April 2014 - 11:26 PM

Is the changelist object getting created correctly? Try setting a break point after the update and see if it is valid.

#3 karidrgn

karidrgn

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 15 April 2014 - 12:19 AM

View PostP4Matt, on 14 April 2014 - 11:26 PM, said:

Is the changelist object getting created correctly? Try setting a break point after the update and see if it is valid.
As far as I can tell it's been created properly. there's a changelist description, id, clientId (btw what is the clientId?) It's diff from the username.
The only thing not set are the filespecs which I assume get added when I call the perforceClient.editFiles(fileSpecs, noUpdate, bypassClientUpdate, mychangelist.getId(), null)

anything that I might have missed? We also recently updated our perforce server but I've not updated anything on my local box. Could that have any impact?

#4 P4Matt

P4Matt

    Advanced Member

  • Members
  • PipPipPip
  • 1383 posts

Posted 17 April 2014 - 06:18 AM

Nope, that shouldn't have impacted anything. I have a very simple sample app I will dig up and post for you to try. It should help us figure out what is wrong.

#5 karidrgn

karidrgn

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 18 April 2014 - 03:24 PM

Thanks I appreciate it.  I thought it might be that it couldn't find the files, but I use the same path/file for a method that copies a file without checking it out (giving it a different name and then deletes it when done) and that works fine.

#6 karidrgn

karidrgn

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 21 April 2014 - 09:40 PM

View PostP4Matt, on 17 April 2014 - 06:18 AM, said:

Nope, that shouldn't have impacted anything. I have a very simple sample app I will dig up and post for you to try. It should help us figure out what is wrong.

Have you found that app that might help me in figuring out my problem? Or do you have any ideas of what I might try on my own to debug this?

#7 P4Matt

P4Matt

    Advanced Member

  • Members
  • PipPipPip
  • 1383 posts

Posted 22 April 2014 - 07:24 PM

import java.util.Date;
import java.util.List;

import com.perforce.p4java.client.IClient;
import com.perforce.p4java.core.ChangelistStatus;
import com.perforce.p4java.core.IChangelist;
import com.perforce.p4java.core.file.FileSpecBuilder;
import com.perforce.p4java.core.file.FileSpecOpStatus;
import com.perforce.p4java.core.file.IFileSpec;
import com.perforce.p4java.exception.P4JavaException;
import com.perforce.p4java.exception.RequestException;
import com.perforce.p4java.impl.generic.core.Changelist;
import com.perforce.p4java.impl.mapbased.server.Server;
import com.perforce.p4java.server.IOptionsServer;
import com.perforce.p4java.server.ServerFactory;
import com.perforce.p4java.option.client.EditFilesOptions;

public class SimpleTestApp {

public static void main(String[] args) {
try { 
IOptionsServer server = ServerFactory.getOptionsServer("p4java://localhost:1777", null);

server.setUserName("matt");
server.connect();
IClient client = server.getClient("mac-matt");

server.setCurrentClient(client);

Changelist changeListImpl = new Changelist(
IChangelist.UNKNOWN,
client.getName(),
server.getUserName(),
ChangelistStatus.NEW,
new Date(),
"Changelist demo new changelist",
false,
(Server) server
);
IChangelist changelist = client.createChangelist(changeListImpl);

EditFilesOptions editFilesOptions = new EditFilesOptions().setChangelistId(changelist.getId());

List<IFileSpec> editList = client.editFiles(FileSpecBuilder.makeFileSpecList("//depot/SampleText.txt"), null);

} catch (RequestException rexc) {
System.err.println(rexc.getDisplayString());
rexc.printStackTrace();
} catch (Exception exc) {
System.err.println(exc.getLocalizedMessage());
exc.printStackTrace();
}
} 

}

Try this and see what happens. When I run this it successfully checks out the file. One thing that bit me was I did not set the user name on the server object at first and the file was being checked out as another user. I obviously just hardcoded the port, user, and client values, but I've tested this code and it works to edit a file.

#8 karidrgn

karidrgn

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 22 April 2014 - 11:53 PM

thanks so much. I think that I've found the problem and it has to do with my confusion about the client name vs. username. I'm guessing that the client name = workspace. My local workspace is of course different from the workspace 'used' when the job is run on our Jenkins integration system. I also found all my empty changelists under the "atf" owner, along with one that had the file in it using the Pforce gui.

Another question that I have is:
How does the editFilesOptions play into your setup? It's not used when the client creates the edit list, although it does fit into where you have the null.

Hopefully, I can figure out the rest on my own.

thanks again for your time.

#9 P4Matt

P4Matt

    Advanced Member

  • Members
  • PipPipPip
  • 1383 posts

Posted 23 April 2014 - 06:53 PM

Indeed. Back in the sands of time workspaces were called clients, but the word client had too many meanings so we renamed them to workspaces. However terminology changes are tough and now we tend to have a smattering of both names.

The null value for edit options was me cutting and pasting the wrong code; swap in the editFilesOptions to have it put the opened files in the numbered changelist you just created. I had set it to null while testing to make sure the files would go into the default changelist if I didn't specify something explicitly. I should have changed it back before sharing with you.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users