package com.perforce.api; import java.io.*; import java.util.*; /* * Copyright (c) 2001, Perforce Software, All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /** * Representation of a source control environment. This information is * typically passed to a <code>P4Process</code> instance by the * <code>SourceControlObject</code> instances. It can also be set in the * {@link P4Process#getBase() base} P4Process instance. This will cause it * to be used as the default environment for all command execution. * * @author <a href="mailto:david@markley.cc">David Markley</a> * @version $Date: 2001/11/05 $ $Revision: #1 $ */ public class Env { private String[] envp = { "P4USER=robot", "P4CLIENT=robot-client", "P4PORT=localhost:1666", "P4PASSWD=", "PATH=C:\\Program Files\\Perforce", "SystemDrive=C:", "SystemRoot=C:\\WINNT", "PATHEXT=.COM;.EXE;.BAT;.CMD" }; private String p4_exe; // Full path to the P4 executable. private String sep_path = null; private String sep_file = null; /** Default, no-argument constructor. */ public Env() { super(); setFromProperties(System.getProperties()); } /** * Constructor that uses another environment as its basis. This is useful * for cloning environments and then changing a few attributes. * * @param base Environment to be copied into the new environment. */ public Env(Env base) { this(); this.envp = (String[])((base.getEnvp()).clone()); this.p4_exe = base.getExecutable(); } /** * Constructor that uses a set of <code>Properties</code> to set up the * environment. * * @see #setFromProperties(Properties) * @param props Used to construct the environment. */ public Env(Properties props) { super(); setFromProperties(props); } protected String[] getEnvp() { return envp; } /** * Uses a set of <code>Properties</code> to set up the environment. The * properties that are used used by this method are: * * <table border="1"> * <thead><tr><th>Property</th><th>Value Set</th></tr></thead><tbody> * <tr><td>p4.user</td><td>P4USER</td></tr> * <tr><td>p4.client</td><td>P4CLIENT</td></tr> * <tr><td>p4.port</td><td>P4PORT</td></tr> * <tr><td>p4.password</td><td>P4PASSWORD</td></tr> * <tr><td>p4.executable</td><td>Executable</td></tr> * <tr><td>p4.sysdrive</td><td>SystemDrive</td></tr> * <tr><td>p4.sysroot</td><td>SystemRoot</td></tr> * </tbody></table> * * @see #setFromProperties(Properties) * @param props Used to construct the environment. */ public void setFromProperties(Properties props) { sep_path = props.getProperty("path.separator",";"); sep_file = props.getProperty("file.separator","/"); setUser(props.getProperty("p4.user","robot")); setClient(props.getProperty("p4.client","robot-client")); setPort(props.getProperty("p4.port","localhost:1666")); setPassword(props.getProperty("p4.password","")); setExecutable(props.getProperty("p4.executable", "P4")); setSystemDrive(props.getProperty("p4.sysdrive", "C:")); setSystemRoot(props.getProperty("p4.sysroot", "C:\\WINNT")); String os = props.getProperty("os.name"); if (null == os) { return; } if (os.startsWith("Windows")) { String windir = props.getProperty("com.ms.windir"); if (null != windir) { setPath(windir.substring(0,1)+"\\Program Files\\Perforce"); setSystemDrive(windir.substring(0,1)); setSystemRoot(windir); } } } /** * Sets the P4USER in the class information. * * @param user P4USER value. */ public void setUser(String user) { if (null != user) { envp[0] = "P4USER="+user; } } /** Returns the P4USER. */ public String getUser() { return envp[0].substring(7); } /** * Sets the P4CLIENT in the class information. * * @param user P4CLIENT value. */ public void setClient(String client) { if (null != client) { envp[1] = "P4CLIENT="+client; } } /** Returns the P4CLIENT. */ public String getClient() { return envp[1].substring(9); } /** * Sets the P4PORT in the class information. * * @param user P4PORT value. */ public void setPort(String port) { if (null != port) { envp[2] = "P4PORT="+port; } } /** Returns the P4PORT. */ public String getPort() { return envp[2].substring(7); } /** * Sets the P4PASSWD in the class information. * * @param user P4PASSWD value. */ public void setPassword(String password) { if (null != password) { envp[3] = "P4PASSWD="+password; } } /** Returns the P4PASSWORD. */ public String getPassword() { return envp[3].substring(9); } /** * Sets the PATH in the class information. * * @param user PATH value. */ public void setPath(String path) { if (null != path) { envp[4] = "PATH="+path; } } /** Returns the PATH. */ public String getPath() { return envp[4].substring(5); } /** * Sets the SystemDrive in the class information. This is only * meaningful under Windows. * * @param user SystemDrive value. */ public void setSystemDrive(String drive) { if (null != drive) { envp[5] = "SystemDrive="+drive; } } /** * Sets the SystemRoot in the class information. This is only * meaningful under Windows. * * @param user SystemRoot value. */ public void setSystemRoot(String root) { if (null != root) { envp[6] = "SystemRoot="+root; } } /** * Sets up the path to reach the p4 executable. The full path passed in must * contain the executable or at least end in the system's file separator * character. This gotten from the file.separator property. For example: * <pre> * p4.executable=/usr/bin/p4 # This will work * p4.executable=/usr/bin/ # This will work * <font color=Red>p4.executable=/usr/bin # This won't work</font> * </pre> * * @param exe Full path to the p4 executable. */ public void setExecutable(String exe) { int pos; if (null == exe) return; p4_exe = exe; if (null == sep_file) { sep_file = System.getProperties().getProperty("file.separator","\\"); } if (-1 == (pos = exe.lastIndexOf(sep_file))) return; if (null == sep_path) { sep_path = System.getProperties().getProperty("path.separator",";"); } envp[4] += sep_path + exe.substring(0,pos); } /** Returns the path to the executable. */ public String getExecutable() { return p4_exe; } public String toString() { return envp[0]+"\n"+envp[1]+"\n"+envp[2]+"\n"+envp[4]+"\n"+ envp[5]+"\n"+envp[6]+"\n"+envp[7]; } /** * Returns an XML representation of the environment. */ public String toXML() { StringBuffer sb = new StringBuffer("<env"); sb.append(" user=\""); sb.append(getUser()); sb.append("\" client=\""); sb.append(getClient()); sb.append("\" port=\""); sb.append(getPort()); sb.append("\" password=\""); sb.append(getPassword()); sb.append("\" sysdrive=\""); sb.append(envp[5].substring(12)); sb.append("\" sysroot=\""); sb.append(envp[6].substring(10)); sb.append("\"><executable>"); sb.append(getExecutable()); sb.append("</executable><path>"); sb.append(getPath()); sb.append("</path></env>"); return sb.toString(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#9 | 8157 | michael | Archiving legacy java api projects which predate the supported P4Java api. | ||
#8 | 7580 | Sivananda Poreddy | Adding support for tickets, new jar file, small fix for DirEntry file | ||
#7 | 6433 | Sivananda Poreddy | Changing the communication preferences, and some documentation updates | ||
#6 | 6141 | Sivananda Poreddy | Updating the p4package with fixes, some new features, jar update, and doc updates | ||
#5 | 1826 | David Markley | Incorporating minor changes in support of upcoming p4jsp package. | ||
#4 | 1382 | David Markley | Publicly changed Env and FileEntry | ||
#3 | 1361 | David Markley | Added convenience methods to the Env class. | ||
#2 | 1149 | David Markley | Added more documentation, a few examples, a cleanUp method, and a server timeout threshold. | ||
#1 | 1043 | David Markley | Initial branch to public area. | ||
//guest/david_markley/p4package/com/perforce/api/Env.java | |||||
#2 | 1035 | David Markley | Changed the file type to provide for keyword expansion. | ||
#1 | 1034 | David Markley |
Added P4Package sources as subset of the P4WebPublisher project. Copyright (c) 2001, Perforce Software, All rights reserved. |