package com.perforce.polarion.repository.provider; import java.util.Properties; import com.perforce.p4java.PropertyDefs; import com.perforce.p4java.client.IClient; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.impl.mapbased.rpc.RpcPropertyDefs; import com.perforce.p4java.server.IOptionsServer; import com.perforce.p4java.server.ServerFactory; import com.polarion.platform.service.repository.RepositoryException; public class ConnectionFactory { public static IOptionsServer getConnection(P4RepositoryConfiguration config) { IOptionsServer iserver = null; Properties props = System.getProperties(); props.put(PropertyDefs.PROG_NAME_KEY, "P4-Polarion"); props.put(PropertyDefs.PROG_VERSION_KEY, "Undefined"); props.put(RpcPropertyDefs.RPC_SOCKET_SO_TIMEOUT_NICK, "0"); // build the p4java URI String serverUri; String p4port = config.getP4Port(); if (p4port.startsWith("ssl:")) { p4port = p4port.substring("ssl:".length()); serverUri = "p4javassl://" + p4port; } else { serverUri = "p4java://" + p4port; } try { // open a Perforce connection iserver = ServerFactory.getOptionsServer(serverUri, props); iserver.connect(); // set unicode if required String charset = config.getP4Charset(); if(charset != null && !charset.isEmpty()) { iserver.setCharsetName(charset); } // set user name iserver.setUserName(config.getP4User()); // authenticate with Perforce login(iserver, config); // Set active client workspace IClient iclient = iserver.getClient(config.getP4Client()); iserver.setCurrentClient(iclient); } catch (Exception e) { throw new RepositoryException(e); } return iserver; } private static void login(IOptionsServer iserver, P4RepositoryConfiguration config) throws P4JavaException { String status = iserver.getLoginStatus(); if (status.contains("not necessary")) { return; } // login if ticket is provided String ticket = config.getP4Ticket(); if (ticket != null && !ticket.isEmpty()) { iserver.setAuthTicket(ticket); return; } // login if password is provided String pass = config.getP4Password(); if (pass != null && !pass.isEmpty()) { iserver.login(pass); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 10073 | Paul Allen | Use boolean flag to indicate password or ticket in Perforce Connection dialog. | ||
#3 | 9999 | Paul Allen | Modified String isEmpty() check to use "length() > 0" to support Java 1.5 for build. | ||
#2 | 9998 | Paul Allen | Added Unicode server support and ExternalRepositoryCredentials annotation. | ||
#1 | 9756 | Paul Allen |
Changed Polarion name space to Perforce: com.perforce.polarion.repository.provider |
||
//guest/paul_allen/dev/p4-polarion/main/src/com/polarion/platform/repository/external/internal/p4/ConnectionFactory.java | |||||
#2 | 9746 | Paul Allen | Empty string detection when setting passwor or ticket. | ||
#1 | 9723 | Paul Allen | Initial import of P4 Polarion plugin code |