package com.perforce.p4java_ext; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.server.IOptionsServer; import java.util.Map; /** * Simplified interaction to the "p4 client" command via IOptionsServer.execMapCommand */ public interface P4Client extends P4Connection, P4Errors { static P4Client create(P4Connection conn) { return new DefaultP4Client(conn); } /** * Calls "p4 client -o", returning our ClientSpec wrapper around the output. */ default ClientSpec load(String clientName) { try { String opts[] = {"-o", clientName}; IOptionsServer server = getOptionsServer(); Map<String, Object>[] results = server.execMapCmd("client", opts, null); checkError(results); ClientSpec clientSpec = new ClientSpec(results[0]); return clientSpec; } catch (P4JavaException p4) { throw new P4Exception(p4); } } /** * Calls "p4 client -i" after generating a simple spec format using the * ClientSpec object. * * @param clientSpec ClientSpec created via load */ default void save(ClientSpec clientSpec) { try { String opts[] = {"-i"}; IOptionsServer server = getOptionsServer(); Map<String, Object> clientMap = clientSpec.getClientMap(); Map<String, Object>[] results = server.execMapCmd("client", opts, clientMap); checkError(results); } catch (P4JavaException ex) { throw new P4Exception(ex); } } /** * Calls "p4 client -d" * <p/> * This executes as the current user, so there is no "force" option, which * means the user must also have privileges to delete the client. * * @param clientName Client name to use */ default void delete(String clientName) { try { String[] opts = new String[]{"-d", clientName}; IOptionsServer server = getOptionsServer(); Map<String, Object>[] results = server.execMapCmd("client", opts, null); checkError(results); } catch (P4JavaException p4) { throw new P4Exception(p4); } } /** * Calls "p4 client -d -f [clientName]" * <p/> * This should probably be run as a superuser, which is likely to happen * during server initialization. * * @param clientName */ default void forceDelete(String clientName) { try { String[] opts = new String[]{"-f", "-d", clientName}; IOptionsServer server = getOptionsServer(); Map<String, Object>[] results = server.execMapCmd("client", opts, null); checkError(results); } catch (P4JavaException p4) { throw new P4Exception(p4); } } }
# | 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. |