package com.polarion.platform.repository.external.internal.p4; 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.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"); // 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 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.length() > 0) { iserver.setAuthTicket(ticket); return; } // login if password is provided String pass = config.getP4Password(); if (pass != null && pass.length() > 0) { iserver.login(pass); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 9756 | Paul Allen |
Changed Polarion name space to Perforce: com.perforce.polarion.repository.provider |
||
#2 | 9746 | Paul Allen | Empty string detection when setting passwor or ticket. | ||
#1 | 9723 | Paul Allen | Initial import of P4 Polarion plugin code |