/** * Copyright (c) 2010 Perforce Software. All rights reserved. */ package com.perforce.maven.scm.provider.p4.command; import java.net.URISyntaxException; import org.apache.maven.scm.ScmException; import org.apache.maven.scm.ScmFileSet; import org.apache.maven.scm.log.ScmLogger; import com.perforce.maven.scm.provider.p4.repository.P4ScmProviderRepository; import com.perforce.p4java.exception.MessageSeverityCode; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.impl.mapbased.rpc.sys.helper.RpcSystemFileCommandsHelper; import com.perforce.p4java.option.server.TrustOptions; import com.perforce.p4java.server.ServerFactory; import com.perforce.p4java.server.callback.ICommandCallback; /** * Base class for Perforce server specific command. It initializes an instance * of the Perforce server. </p> */ public class P4ServerExecutor extends P4Executor { /** * Instantiates a new p4 server executor. * * @param repository * the repository * @param fileSet * the file set * @param logger * the logger * @throws ScmException * the scm exception */ public P4ServerExecutor(P4ScmProviderRepository repository, ScmFileSet fileSet, ScmLogger logger) throws ScmException { super(repository, fileSet, logger); } /** * Initialize an instance of the Perforce server from the factory using the * specified protocol, server port, protocol specific properties and usage * options. Register callback on the server. Connect to server; set the user * (if present) to server and login to the server with the user's password * (if present). * * @throws ScmException * the scm exception */ protected void initServer() throws ScmException { try { // Set default system file helper ServerFactory .setRpcFileSystemHelper(new RpcSystemFileCommandsHelper()); // Get an instance of the P4J server. server = ServerFactory.getOptionsServer( getUrl( p4Port), p4ServerProperties, p4ServerOptions); if (isSsl(p4Port)) { // assume a new first time connection server.addTrust(new TrustOptions().setAutoAccept(true)); } // Register server callback. server.registerCallback(new ICommandCallback() { public void receivedServerMessage(int key, int genericCode, int severityCode, String message) { // Log warning messages from server, since it's not included // in the other callback methods. if (severityCode == MessageSeverityCode.E_WARN) { if (logger.isWarnEnabled()) { logger.warn(message); } } } public void receivedServerInfoLine(int key, String infoLine) { if (logger.isInfoEnabled()) { logger.info(infoLine); } } public void receivedServerErrorLine(int key, String errorLine) { if (logger.isErrorEnabled()) { logger.error(errorLine); } } public void issuingServerCommand(int key, String command) { if (logger.isInfoEnabled()) { logger.info(command); } } public void completedServerCommand(int key, long millisecsTaken) { if (logger.isInfoEnabled()) { logger.info("Command completed in " + millisecsTaken + "ms"); } } }); // Connect to the server. server.connect(); // Set the Perforce charset. if (!isEmpty(p4Charset)) { if (server.isConnected()) { if (server.supportsUnicode()) { server.setCharsetName(p4Charset); } } } // Set server user. if (!isEmpty(p4User)) { server.setUserName(p4User); // Login to the server with a password. // Password can be null if it is not needed (i.e. SSO logins). server.login(p4Passwd, p4LoginOptions); } } catch (URISyntaxException e) { if (getLogger().isErrorEnabled()) { getLogger().error(e); } throw new ScmException(e.getLocalizedMessage(), e); } catch (P4JavaException e) { if (getLogger().isErrorEnabled()) { getLogger().error(e); } throw new ScmException(e.getLocalizedMessage(), e); } } /** * Cleanup the Perforce server instance. Disconnect from the Perforce * server. Also, set the server to null. * * Note: It does not logout, because that will delete the user's ticket. * * @throws ScmException * the scm exception */ protected void cleanServer() throws ScmException { try { server.disconnect(); server = null; } catch (P4JavaException e) { if (getLogger().isErrorEnabled()) { getLogger().error(e); } throw new ScmException(e.getLocalizedMessage(), e); } } /** * @see com.perforce.maven.scm.provider.p4.command.P4Executor#initP4() */ @Override protected void initP4() throws ScmException { // Initialize the Perforce server. initServer(); } /** * @see com.perforce.maven.scm.provider.p4.command.P4Executor#cleanP4() */ @Override protected void cleanP4() throws ScmException { // Cleanup the Perforce server. cleanServer(); } private static String getUrl( String p4Port ) { String protocol = "p4java"; String hostPort=p4Port; if ( isSsl(p4Port)) { protocol += "ssl"; hostPort = p4Port.substring( 4 ); } return protocol + "://" + hostPort; } private static boolean isSsl(String p4Port) { return p4Port.startsWith("ssl:"); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 9519 | dantran | folder rename to match with its artifactId | ||
#2 | 9422 | dantran | add update, changelog TCK | ||
#1 | 9167 | dantran |
Populate //guest/dantran/p4maven/... from //guest/perforce_software/p4maven/main/.... |
||
//guest/perforce_software/p4maven/main/com.perforce.maven/src/main/java/com/perforce/maven/scm/provider/p4/command/P4ServerExecutor.java | |||||
#2 | 9014 | Matt Attaway |
Add SSL support to P4Maven (committed on behalf of Dan Tran) USer visible change |
||
#1 | 8496 | Matt Attaway | Move P4Ant and P4Maven into their proper homes | ||
//public/perforce/p4maven/main/com.perforce.maven/src/main/java/com/perforce/maven/scm/provider/p4/command/P4ServerExecutor.java | |||||
#1 | 8270 | Matt Attaway | Initial add of P4Maven source code |