package org.jenkinsci.plugins.p4.client; import com.perforce.p4java.PropertyDefs; import com.perforce.p4java.impl.mapbased.rpc.RpcPropertyDefs; import com.perforce.p4java.option.UsageOptions; import com.perforce.p4java.server.IOptionsServer; import com.perforce.p4java.server.ServerFactory; import hudson.util.FormValidation; import java.util.Properties; import java.util.logging.Logger; /** * Connection Factory * <p> * Provides concurrent connections to the Perforce Server * * @author pallen */ public class ConnectionFactory { private static Logger logger = Logger.getLogger(ConnectionFactory.class .getName()); private static IOptionsServer currentP4; /** * Returns existing connection * * @return Server connection object */ public static IOptionsServer getConnection() { return currentP4; } /** * Creates a server connection; provides a connection to the Perforce * Server, initially client is undefined. * * @param config Connection configuration * @return Server connection object * @throws Exception push up stack */ public static IOptionsServer getConnection(ConnectionConfig config) throws Exception { IOptionsServer iserver = getRawConnection(config); // Add trust for SSL connections if (config.isSsl()) { String serverTrust = iserver.getTrust(); if (!serverTrust.equalsIgnoreCase(config.getTrust())) { logger.warning("Trust mismatch! Server fingerprint: " + serverTrust); } else { iserver.addTrust(config.getTrust()); } } // Connect and update current P4 connection iserver.connect(); currentP4 = iserver; return iserver; } public static FormValidation testConnection(ConnectionConfig config) { // Test for SSL connections try { IOptionsServer iserver = getRawConnection(config); if (config.isSsl()) { String serverTrust = iserver.getTrust(); if (!serverTrust.equalsIgnoreCase(config.getTrust())) { return FormValidation .error("Trust mismatch! Server fingerprint: " + serverTrust); } else { iserver.addTrust(config.getTrust()); } } } catch (Exception e) { StringBuffer sb = new StringBuffer(); sb.append("Unable to connect to: "); sb.append(config.getServerUri()); sb.append("\n"); sb.append(e.getMessage()); return FormValidation.error(sb.toString()); } return FormValidation.ok(); } private static IOptionsServer getRawConnection(ConnectionConfig config) throws Exception { Properties props = System.getProperties(); // Identify ourselves in server log files. Identifier id = new Identifier(); props.put(PropertyDefs.PROG_NAME_KEY, id.getProduct()); props.put(PropertyDefs.PROG_VERSION_KEY, id.getVersion()); // Allow p4 admin commands. props.put(RpcPropertyDefs.RPC_RELAX_CMD_NAME_CHECKS_NICK, "true"); // disable timeout for slow servers / large db lock times String timeout = String.valueOf(config.getTimeout()); props.put(RpcPropertyDefs.RPC_SOCKET_SO_TIMEOUT_NICK, timeout); // enable graph depot and AndMaps props.put(PropertyDefs.ENABLE_GRAPH_SHORT_FORM, "true"); props.put(PropertyDefs.ENABLE_ANDMAPS_SHORT_FORM, "true"); // Set P4HOST if defined UsageOptions opts = new UsageOptions(props); String p4host = config.getP4Host(); if (p4host != null && !p4host.isEmpty()) { opts.setHostName(p4host); } // Get a server connection String serverUri = config.getServerUri(); IOptionsServer iserver; iserver = ServerFactory.getOptionsServer(serverUri, props, opts); return iserver; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 21944 | Paul Allen | Graph Populate support. | ||
#1 | 21940 | Paul Allen | Branching using p4-jenkins | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/client/ConnectionFactory.java | |||||
#9 | 21154 | Paul Allen | P4HOST support for connection. | ||
#8 | 20179 | Paul Allen | Javadoc fixes for java 8 builds. | ||
#7 | 19593 | Paul Allen | More minor fixes to satisfy FindBugs Analysis. | ||
#6 | 19296 | Paul Allen |
Typo missmatch. JENKINS-34541 |
||
#5 | 16502 | Paul Allen |
Advanced Credentials option for RPC_SOCKET_SO_TIMEOUT_NICK JENKINS-31196 |
||
#4 | 10898 | Paul Allen |
SSL not adding trust. JENKINS-25602 |
||
#3 | 10100 | elliot_wiltshire |
Fix for JENKINS-24427. All connections use the same .p4trust file, which seems to get clobbered sometimes. As addTrust writes to the file each time, I added a check for whether we already have the current fingerprint, and only add it if we don't. Another solution would be to use per-connection trust files, through setTrustFilePath(). #review-10093 |
||
#2 | 10031 | Paul Allen |
Test URI path before connection. Report Perforce Errors and Trust fingerprint if using SSL. |
||
#1 | 9690 | Paul Allen |
[Branching using p4-jenkins] Release 1.0.1 |
||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4/client/ConnectionFactory.java | |||||
#1 | 9672 | Paul Allen | Refactor name from 'p4_client' to 'p4'. | ||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4_client/client/ConnectionFactory.java | |||||
#6 | 9431 | Paul Allen | Change to P4Java connection factory (trying to prevent connection reuse) | ||
#5 | 8815 | Paul Allen | P4D test harness. | ||
#4 | 8771 | Paul Allen |
Perforce Server 12.1 min check for: Build configuration and password/ticket credentials. Includes: - Added logging for Perforce connections (fine) and set connection pool to 2. - Add 'none' to empty charset list (connection bug?) - Supress P4Java errors for syncing ubinary, xtext, unicode |
||
#3 | 8762 | Paul Allen |
Console Ouptut logging for SCM build steps. - Removed SLF4J and used old style logger (matching Jenkins) - Set Client Host filed to null, Jenkins sometimes gives an IP address. - Test p4java setps in SCM tasks for success(true/false) |
||
#2 | 8660 | Paul Allen | Added P4TRUST for SSL connections in the Credentials plugin and ConnectionFactory. | ||
#1 | 8629 | Paul Allen |
Added p4java with connection/authorisation helper classes. Included SSL support and detection of Unicode servers. |