/* * P4ListCommand.java */ package vcs.list; import org.netbeans.modules.vcscore.Variables; import org.netbeans.modules.vcscore.VcsFileSystem; import org.netbeans.modules.vcscore.commands.*; import org.netbeans.modules.vcscore.cmdline.UserCommand; import org.netbeans.modules.vcscore.util.*; import java.util.*; import java.io.*; /** * @author Axel Wienberg */ public class P4ListCommand extends AbstractListCommand { public P4ListCommand() { } public void setFileSystem(VcsFileSystem fileSystem) { super.setFileSystem(fileSystem); } File dir; protected void initDir(Hashtable vars) { String rootDirVar = (String) vars.get("ROOTDIR"); // NOI18N if (rootDirVar == null) { rootDirVar = "."; } String dirVar = (String) vars.get("DIR"); // NOI18N if (dirVar == null) { dirVar = ""; } File rootDir = new File(rootDirVar); dir = new File(rootDirVar, dirVar); } /** * List files of the VCS Repository. * @param vars Variables used by the command * @param args Command-line arguments * @param filesByName listing of files with statuses * @param stdoutNRListener listener of the standard output of the command * @param stderrNRListener listener of the error output of the command * @param stdoutListener listener of the standard output of the command which * satisfies regex <CODE>dataRegex</CODE> * @param dataRegex the regular expression for parsing the standard output * @param stderrListener listener of the error output of the command which * satisfies regex <CODE>errorRegex</CODE> * @param errorRegex the regular expression for parsing the error output */ public boolean list(Hashtable vars, String[] args, Hashtable filesByName, CommandOutputListener stdoutNRListener, CommandOutputListener stderrNRListener, CommandDataOutputListener stdoutListener, String dataRegex, CommandDataOutputListener stderrListener, String errorRegex) { this.stdoutNRListener = stdoutNRListener; this.stderrNRListener = stderrNRListener; this.stderrListener = stderrListener; this.dataRegex = dataRegex; this.errorRegex = errorRegex; this.filesByName = filesByName; //System.err.println("LIST: called with ROOTDIR "+((String)vars.get("ROOTDIR"))+" DIR "+(String)vars.get("DIR")); initVars(vars); //initDir(vars); runCommand(vars, args, true); // ### dirs missing! // ### add local files if (props != null) { outputFstat(props); props = null; } String dirCommand = (String) vars.get("DIRLIST_COMMAND"); if (dirCommand != null && !shouldFail) { runDirCommand(vars, dirCommand); } return !shouldFail; } void runDirCommand(Hashtable vars, String cmdStr) { String prepared = Variables.expand(vars,cmdStr, true); UserCommand cmd = new UserCommand(); cmd.setName("DIRLIST_CMD"); cmd.setProperty(VcsCommand.PROPERTY_EXEC, prepared); // The user should be warned by the wrapper class and not the command itself. cmd.setProperty(VcsCommand.PROPERTY_IGNORE_FAIL, new Boolean(true)); VcsCommandExecutor ec = getFileSystem().getVcsFactory().getCommandExecutor(cmd, vars); ec.addDataOutputListener(new CommandDataOutputListener() { public void outputData(String elements[]) { if (elements.length != 1) { System.err.println("dirlister: strange elements: "+array2string(elements)); } else if (elements[0].startsWith("//")) { outputDir(elements[0]); } else { System.err.println("dirlister: not a depot path: "+elements[0]); } } public void outputDir(String depotFile) { String leafName = depotFile == null ? "*directory name missing*/" : ((String) depotFile.substring(depotFile.lastIndexOf('/')+1))+"/"; String[] statusses = new String[] { leafName, "have" }; filesByName.put(leafName, statusses); } }); ec.addOutputListener(stdoutNRListener); ec.addErrorOutputListener(stderrNRListener); getFileSystem().getCommandsPool().startExecutor(ec); getFileSystem().getCommandsPool().waitToFinish(ec); if (ec.getExitStatus() != VcsCommandExecutor.SUCCEEDED) { //E.err("exec failed "+ec.getExitStatus()); shouldFail=true; } } protected Hashtable filesByName; void outputFstat(Hashtable props) { String depotFile = (String) props.get(PROP_DEPOT_FILE); String leafName = depotFile == null ? "*depotFile name missing*" : (String) depotFile.substring(depotFile.lastIndexOf('/')+1); String headRev = (String) props.get(PROP_HEAD_REV); String haveRev = (String) props.get(PROP_HAVE_REV); String action = (String) props.get(PROP_ACTION); String headType = (String) props.get(PROP_HEAD_TYPE); String headAction = (String) props.get(PROP_HEAD_ACTION); String headTime = (String) props.get(PROP_HEAD_TIME); String fileStatus; if (haveRev == null) { if (headAction != null && headAction.equals("delete")) // ignore deleted files return; fileStatus = "missing"; } else { if (action != null) { fileStatus = action; if (props.get(PROP_OUR_LOCK) != null) { fileStatus += ",*locked*"; } if (props.get(PROP_UNRESOLVED) != null) { fileStatus += ",unresolved"; } } else { fileStatus = "have"; } } String awareness = ""; if (haveRev != null && !headRev.equals(haveRev)) { awareness = "out-of-date "; } if (props.get(PROP_OTHER_OPEN) != null) { awareness += "other-open "; } if (props.get(PROP_OTHER_LOCK) != null) { awareness += "other-lock "; } String[] fileStatuses = new String[] { leafName, fileStatus, haveRev, headRev, headType, headTime, awareness }; // System.out.println("** Stati: "+array2string(fileStatuses)); filesByName.put(leafName, fileStatuses); } static final String PROP_DEPOT_FILE= "depotFile"; static final String PROP_CLIENT_FILE = "clientFile"; static final String PROP_HEAD_ACTION = "headAction"; static final String PROP_HEAD_TYPE = "headType"; static final String PROP_HEAD_TIME = "headTime"; static final String PROP_HEAD_REV = "headRev"; static final String PROP_HEAD_CHANGE = "headChange"; static final String PROP_HAVE_REV = "haveRev"; static final String PROP_ACTION = "action"; static final String PROP_CHANGE = "change"; static final String PROP_UNRESOLVED = "unresolved"; static final String PROP_OTHER_OPEN = "otherOpen"; static final String PROP_OTHER_LOCK = "otherLock"; static final String PROP_OUR_LOCK = "ourLock"; static final String NEXT_FILE_MARKER = PROP_DEPOT_FILE; protected Hashtable props = null; public void outputData(String[] elements) { if (elements == null) { System.err.println("p4listcommand: no match elements"); // ignore } else if ((elements.length == 3 || elements.length == 2) && elements[0].equals("...") ) { String field = elements[1]; String value = elements.length > 2 ? elements[2] : "true"; // System.err.println("field: "+field+" value: "+value); if (field.equals(NEXT_FILE_MARKER)) { if (props == null) { props = new Hashtable(10); } else { outputFstat(props); props.clear(); } } props.put(field, value); } else { System.err.println("P4ListCommand: strange match: elements.length="+elements.length+", "+array2string(elements)); // ignore } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 1014 | axel_wienberg |
copied perforte and sitepadp4 files from my homepage to the public depot. happy branching and improving :-) |