package com.perforce.p4java_ext; import com.fasterxml.jackson.databind.ObjectMapper; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.server.IOptionsServer; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * Methods to execute "p4 change" commands */ public interface P4Change extends P4ClientConnection, P4Errors { static P4Change create(P4ClientConnection conn) { return new DefaultP4Change(conn); } /** * Issues the "p4 change -d" command. You must ensure there are no open files before running. * * @param changelist Changelist ID, should be on the active client */ default void delete(String changelist) { try { String[] opts = new String[]{"-d", changelist}; IOptionsServer server = getOptionsServer(); Map<String, Object>[] results = server.execMapCmd("change", opts, null); checkError(results); } catch (P4JavaException e) { throw new P4Exception(e); } } /** * Returns the spec for the "p4 change" command. * <p/> * You should ensure the client has been set on the current connection before calling. * * @param changelist Changelist ID, can be null to get a new changelist specification * * @return ChangeSpec */ default ChangeSpec load(String changelist) { try { List<String> optList = new ArrayList<String>(); optList.add("-o"); if (changelist != null) { optList.add(changelist); } String[] opts = optList.toArray(new String[0]); IOptionsServer server = getOptionsServer(); Map<String, Object>[] results = server.execMapCmd("change", opts, null); checkError(results); return new ChangeSpec(results[0]); } catch (P4JavaException e) { throw new P4Exception(e); } } /** * Save the change spec using "p4 change -i". * * @param changeSpec The ChangeSpec to save. Once saved, we will update the "Change" property. */ default void update(ChangeSpec changeSpec) { try { String[] opts = new String[]{"-i"}; String spec = changeSpec.toString(); IOptionsServer server = getOptionsServer(); Map<String, Object>[] results = server.execInputStringMapCmd("change", opts, spec); checkError(results); if (results.length > 0) { String changeStr = (String) results[0].get("change"); changeStr = changeStr.replaceAll("[^\\d]", ""); changeSpec.put("Change", changeStr); } else { String mapStr = ""; try { ObjectMapper mapper = new ObjectMapper(); mapStr = mapper.writeValueAsString(results); } catch (Exception ex) { ex.printStackTrace(); } throw new P4Exception("Unexpected output from 'p4 change " + "-i': " + mapStr); } } catch (P4JavaException e) { throw new P4Exception(e); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 9086 | tjuricek |
0.1.0 Initial release of p4java_ext Mostly just contains enough of the P4 API to build the test data initializer. About 4 commands have minimal testing, so it works. Kind of. |
||
#1 | 9085 | tjuricek | First import of the project, before package refactoring. |