Execute sub-commands through VcsAction. It's more reliable BLD200210170100
authormentlicher@netbeans.org
Wed, 16 Oct 2002 18:54:27 +0000
changeset 26878c97e88d094e
parent 2686 b1b5d43afc09
child 2688 5a9173fc9b10
Execute sub-commands through VcsAction. It's more reliable
and necessary if we do not want to setup COMMON_PARENT
and all other variables explicitly. VcsAction does a better job.
This is a fix of issue #27726.
vcs.profiles.vss/src/org/netbeans/modules/vcs/profiles/vss/list/VssListFileCommand.java
     1.1 --- a/vcs.profiles.vss/src/org/netbeans/modules/vcs/profiles/vss/list/VssListFileCommand.java	Wed Oct 16 16:43:52 2002 +0000
     1.2 +++ b/vcs.profiles.vss/src/org/netbeans/modules/vcs/profiles/vss/list/VssListFileCommand.java	Wed Oct 16 18:54:27 2002 +0000
     1.3 @@ -20,6 +20,7 @@
     1.4  import java.util.Set;
     1.5  import java.io.*;
     1.6  
     1.7 +import org.netbeans.modules.vcscore.VcsAction;
     1.8  import org.netbeans.modules.vcscore.VcsFileSystem;
     1.9  import org.netbeans.modules.vcscore.commands.*;
    1.10  import org.netbeans.modules.vcscore.cmdline.VcsAdditionalCommand;
    1.11 @@ -132,41 +133,48 @@
    1.12              missingFiles.add(file);
    1.13              return true;
    1.14          } else {
    1.15 -            Hashtable varsCmd = new Hashtable(vars);
    1.16 -            varsCmd.put("DIR", VcsUtilities.getDirNamePart(file));
    1.17 -            varsCmd.put("FILE", VcsUtilities.getFileNamePart(file));
    1.18              VcsCommand cmd = fileSystem.getCommand(diffCmd);
    1.19              if (cmd == null) {
    1.20                  stderrListener.outputLine("Unknown command: "+diffCmd);
    1.21                  return false;
    1.22              }
    1.23 -            VcsCommandExecutor vce = fileSystem.getVcsFactory().getCommandExecutor(cmd, varsCmd);
    1.24 +            Table files = new Table();
    1.25 +            files.put(file, fileSystem.findFileObject(file));
    1.26              final boolean[] differ = new boolean[1];
    1.27              final boolean[] cannotDiff = new boolean[1];
    1.28              differ[0] = false;
    1.29              cannotDiff[0] = false;
    1.30 -            vce.addDataOutputListener(new CommandDataOutputListener() {
    1.31 +            VcsCommandExecutor[] execs = VcsAction.doCommand(files, cmd, null, fileSystem, null, null, 
    1.32 +            new CommandDataOutputListener() {
    1.33                  public void outputData(String[] elements) {
    1.34                      if (elements != null) {
    1.35                          //D.deb(" ****  status match = "+VcsUtilities.arrayToString(elements));
    1.36                          if (elements[0].length() > 0) differ[0] = true;
    1.37                      }
    1.38                  }
    1.39 -            });
    1.40 -            vce.addDataErrorOutputListener(new CommandDataOutputListener() {
    1.41 +            },
    1.42 +            new CommandDataOutputListener() {
    1.43                  public void outputData(String[] elements) {
    1.44                      if (elements != null) {
    1.45                          if (elements[0].length() > 0) cannotDiff[0] = true;
    1.46                      }
    1.47                  }
    1.48              });
    1.49 -            fileSystem.getCommandsPool().preprocessCommand(vce, varsCmd, fileSystem);
    1.50 -            fileSystem.getCommandsPool().startExecutor(vce);
    1.51 -            try {
    1.52 -                fileSystem.getCommandsPool().waitToFinish(vce);
    1.53 -            } catch (InterruptedException iexc) {
    1.54 -                fileSystem.getCommandsPool().kill(vce);
    1.55 -                interrupted = true;
    1.56 +            boolean status = true;
    1.57 +            if (execs != null) {
    1.58 +                try {
    1.59 +                    for (int i = 0; i < execs.length; i++) {
    1.60 +                        fileSystem.getCommandsPool().waitToFinish(execs[i]);
    1.61 +                        status = status && execs[i].getExitStatus() == VcsCommandExecutor.SUCCEEDED;
    1.62 +                    }
    1.63 +                } catch (InterruptedException iexc) {
    1.64 +                    for (int i = 0; i < execs.length; i++) {
    1.65 +                        fileSystem.getCommandsPool().kill(execs[i]);
    1.66 +                    }
    1.67 +                    interrupted = true;
    1.68 +                    return false;
    1.69 +                }
    1.70 +            } else {
    1.71                  return false;
    1.72              }
    1.73              if (!cannotDiff[0]) {
    1.74 @@ -176,7 +184,7 @@
    1.75                      currentFiles.add(file);
    1.76                  }
    1.77              }
    1.78 -            return vce.getExitStatus() == VcsCommandExecutor.SUCCEEDED || differ[0];
    1.79 +            return status || differ[0];
    1.80          }
    1.81      }
    1.82      
    1.83 @@ -195,15 +203,13 @@
    1.84              statuses[1] = status;
    1.85              VcsCommand cmd = fileSystem.getCommand(args[1]);
    1.86              if (cmd != null) {
    1.87 -                Hashtable varsCmd = new Hashtable(vars);
    1.88 -                varsCmd.put("DIR", VcsUtilities.getDirNamePart(file));
    1.89 -                varsCmd.put("FILE", VcsUtilities.getFileNamePart(file));
    1.90 -                //cmd.setProperty(UserCommand.PROPERTY_DATA_REGEX, "^"+file.substring(0, Math.min(STATUS_POSITION, file.length()))+" (.*$)");
    1.91 +                Table filesT = new Table();
    1.92 +                filesT.put(file, fileSystem.findFileObject(file));
    1.93                  statuses[2] = null;
    1.94                  final boolean[] existing = new boolean [1];
    1.95                  existing[0] = true;
    1.96 -                VcsCommandExecutor vce = fileSystem.getVcsFactory().getCommandExecutor(cmd, varsCmd);
    1.97 -                vce.addDataOutputListener(new CommandDataOutputListener() {
    1.98 +                VcsCommandExecutor[] execs = VcsAction.doCommand(filesT, cmd, null, fileSystem, null, null, 
    1.99 +                new CommandDataOutputListener() {
   1.100                      public void outputData(String[] elements) {
   1.101                          if (elements != null) {
   1.102                              //D.deb(" ****  status match = "+VcsUtilities.arrayToString(elements));
   1.103 @@ -211,8 +217,8 @@
   1.104                              addStatuses(elements);
   1.105                          }
   1.106                      }
   1.107 -                });
   1.108 -                vce.addDataErrorOutputListener(new CommandDataOutputListener() {
   1.109 +                },
   1.110 +                new CommandDataOutputListener() {
   1.111                      public void outputData(String[] elements2) {
   1.112                          if (elements2 != null) {
   1.113                              if (elements2[0].indexOf("$/") == 0) {
   1.114 @@ -224,14 +230,22 @@
   1.115                          }
   1.116                      }
   1.117                  });
   1.118 -                fileSystem.getCommandsPool().preprocessCommand(vce, varsCmd, fileSystem);
   1.119 -                fileSystem.getCommandsPool().startExecutor(vce);
   1.120 -                try {
   1.121 -                    fileSystem.getCommandsPool().waitToFinish(vce);
   1.122 -                } catch (InterruptedException iexc) {
   1.123 -                    fileSystem.getCommandsPool().kill(vce);
   1.124 -                    interrupted = true;
   1.125 -                    return ;
   1.126 +                boolean state = true;
   1.127 +                if (execs != null) {
   1.128 +                    try {
   1.129 +                        for (int i = 0; i < execs.length; i++) {
   1.130 +                            fileSystem.getCommandsPool().waitToFinish(execs[i]);
   1.131 +                            state = state && execs[i].getExitStatus() == VcsCommandExecutor.SUCCEEDED;
   1.132 +                        }
   1.133 +                    } catch (InterruptedException iexc) {
   1.134 +                        for (int i = 0; i < execs.length; i++) {
   1.135 +                            fileSystem.getCommandsPool().kill(execs[i]);
   1.136 +                        }
   1.137 +                        interrupted = true;
   1.138 +                        return ;
   1.139 +                    }
   1.140 +                } else {
   1.141 +                    continue;
   1.142                  }
   1.143                  if (!existing[0]) statuses[1] = STATUS_UNKNOWN;
   1.144              } else statuses[2] = "";