package com.perforce.p4java_ext; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.server.IOptionsServer; import java.util.Map; /** * API for the "p4 user" command. */ public interface P4User extends P4Connection, P4Errors { static P4User fromConnection(P4Connection connection) { return new DefaultP4User(connection); } /** * Issues a "p4 user -o", with our UserSpec wrapper around the output map. * * @param login Perforce login */ default UserSpec load(String login) { try { String[] opts = {"-o", login}; IOptionsServer server = getOptionsServer(); Map<String, Object>[] results = server.execMapCmd("user", opts, null); checkError(results); if (results.length != 1) { throw new IllegalStateException("results.length != 1"); } return new UserSpec(results[0]); } catch (P4JavaException e) { throw new P4Exception(e); } } /** * Will update the user spec using "p4 user -i". * * @param userSpec The UserSpec definition, you should obtain one by * calling load() first. */ default void save(UserSpec userSpec) { String[] opts = {"-i"}; _doSave(userSpec, opts); } default void _doSave(UserSpec userSpec, String[] opts){ try { IOptionsServer server = getOptionsServer(); Map<String, Object> userMap = userSpec.getUserMap(); Map<String, Object>[] results = server.execMapCmd("user", opts, userMap); checkError(results); } catch (P4JavaException e) { throw new P4Exception(e); } } /** * Updates the user spec using "p4 user -i -f". * * * @param userSpec */ default void forceSave(UserSpec userSpec) { String[] opts = {"-i", "-f"}; _doSave(userSpec, opts); } /** * Issues a "p4 user -d [login]". * * @param login The Perforce login */ default void delete(String login) { try { String[] opts = {"-d", login}; IOptionsServer server = getOptionsServer(); Map<String, Object>[] results = server.execMapCmd("user", opts, null); checkError(results); } 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. |