This is my code to get a file from perforce(STEP 1) and checkin a file in perforce (STEP 2)
I am able to get the file successfully. But when checkin the file back to the depot, I get a message : No files to submit.
Can someone please help me find what I might be missing here?
String serverUri = "p4java://my-perforce:1666";
IServer server;
try {
//getting server
server = ServerFactory.getServer(serverUri, null);
//connecting to server
server.connect();
server.setUserName("username");
server.login("password");
//Step 1 -- GETTING FILE FROM PERFORCE.
//getting client (local workspace name)
IClient client = server.getClient("myPerforce");
//setting it as current workspace
server.setCurrentClient(client);
//getting the file from perforce depot
List<IFileSpec> fileList = server.getDepotFiles(FileSpecBuilder.makeFileSpecList("//myLocalWorkspaceLocation/up.json"), false);
//sync workspace with perforce depot
client.sync(fileList, null);
//STEP 2 -- CHECKING IN FILE IN PERFORCE
//creating a changelist
Changelist changeListImpl = new Changelist(
IChangelist.UNKNOWN,
client.getName(),
"username",
ChangelistStatus.NEW,
new Date(),
"Testing checking in file from JAVA",
false,
(Server) server);
IChangelist changelist = client.createChangelist(changeListImpl);
//Edit file options
EditFilesOptions editFilesOptions = new EditFilesOptions().setChangelistId(changelist.getId());
List<IFileSpec> editList = client.editFiles(FileSpecBuilder.makeFileSpecList("//myLocalWorkspaceLocation/up.json"), editFilesOptions);
//updating the changelist and submitting the changes.
changelist.update();
List<IFileSpec> submitFiles = changelist.submit(false);
//disconnecting
server.disconnect();
} catch (Exception e) {
System.out.println("ERROR!!!>> " + e.getMessage());
}