A new private method matchSerial() introduced. It's called from canRun() two times BLD200303050100
authormentlicher@netbeans.org
Tue, 04 Mar 2003 20:40:15 +0000
changeset 3231a45ab76336f9
parent 3230 187da7a0d430
child 3232 4e1f90998dbc
A new private method matchSerial() introduced. It's called from canRun() two times
for every pair of commands to assure the symmetry of the decission of whether
the command can run or not.
This is a part of fix of issue #29264.
vcscore/src/org/netbeans/modules/vcscore/cmdline/UserCommandTask.java
     1.1 --- a/vcscore/src/org/netbeans/modules/vcscore/cmdline/UserCommandTask.java	Tue Mar 04 17:28:18 2003 +0000
     1.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/cmdline/UserCommandTask.java	Tue Mar 04 20:40:15 2003 +0000
     1.3 @@ -493,8 +493,7 @@
     1.4          String concurrencyWith = (String) cmd.getProperty(VcsCommand.PROPERTY_CONCURRENT_EXECUTION_WITH);
     1.5          //System.out.println("  concurrency = "+concurrency+", concurrencyWith = "+concurrencyWith);
     1.6          boolean haveToWait = false;
     1.7 -        if ((concurrency != VcsCommand.EXEC_CONCURRENT_ALL || concurrencyWith != null)
     1.8 -            && concurrency != VcsCommand.EXEC_SERIAL_INERT) {
     1.9 +        if (concurrency != VcsCommand.EXEC_SERIAL_INERT) {
    1.10              
    1.11              HashMap concurrencyMap = createConcurrencyMap(concurrencyWith);
    1.12              String name = cmd.getName();
    1.13 @@ -503,10 +502,6 @@
    1.14              boolean serialWithParent = (concurrency & VcsCommand.EXEC_SERIAL_WITH_PARENT) != 0;
    1.15              boolean serialOfCommand = (concurrency & VcsCommand.EXEC_SERIAL_OF_COMMAND) != 0;
    1.16              boolean serialOfAll = (concurrency & VcsCommand.EXEC_SERIAL_ALL) != 0;
    1.17 -            boolean matchOnFile = false;
    1.18 -            boolean matchOnPackage = false;
    1.19 -            boolean matchWithParent = false;
    1.20 -            boolean matchOfCommand = false;
    1.21              //System.out.println("  serialOnFile = "+serialOnFile);
    1.22              //System.out.println("  serialOnPackage = "+serialOnPackage);
    1.23              //System.out.println("  serialWithParent = "+serialWithParent);
    1.24 @@ -546,32 +541,21 @@
    1.25                      break;
    1.26                  }
    1.27                  String cmdName = uc.getName();
    1.28 -                if (serialOnFile) {
    1.29 -                    for(Iterator it = files.iterator(); it.hasNext(); ) {
    1.30 -                        String file = (String) it.next();
    1.31 -                        if (cmdFiles.contains(file)) {
    1.32 -                            matchOnFile = true;
    1.33 -                            break;
    1.34 -                        }
    1.35 +                haveToWait = matchSerial(name, cmdName, files, cmdFiles,
    1.36 +                                         serialOnFile, serialOnPackage,
    1.37 +                                         serialWithParent, serialOfCommand);
    1.38 +                if (!haveToWait) {
    1.39 +                    if ((cmdConcurrency & VcsCommand.EXEC_SERIAL_ALL) != 0) {
    1.40 +                        haveToWait = true;
    1.41 +                        break;
    1.42                      }
    1.43 +                    haveToWait = matchSerial(cmdName, name, cmdFiles, files,
    1.44 +                                             (cmdConcurrency & VcsCommand.EXEC_SERIAL_ON_FILE) != 0,
    1.45 +                                             (cmdConcurrency & VcsCommand.EXEC_SERIAL_ON_PACKAGE) != 0,
    1.46 +                                             (cmdConcurrency & VcsCommand.EXEC_SERIAL_WITH_PARENT) != 0,
    1.47 +                                             (cmdConcurrency & VcsCommand.EXEC_SERIAL_OF_COMMAND) != 0);
    1.48                  }
    1.49 -                if (serialOnPackage) {
    1.50 -                    if (areFilesInSamePackage(files, cmdFiles)) {
    1.51 -                        matchOnPackage = true;
    1.52 -                    }
    1.53 -                }
    1.54 -                if (serialWithParent) {
    1.55 -                    if (isParentFolder(files, cmdFiles)) {
    1.56 -                        matchWithParent = true;
    1.57 -                    }
    1.58 -                }
    1.59 -                if (serialOfCommand) {
    1.60 -                    matchOfCommand = name.equals(cmdName);
    1.61 -                }
    1.62 -                // if (serialOfCommand && !matchOfCommand) do not wait
    1.63 -                if ((!serialOfCommand || matchOfCommand) && (matchOnFile || matchOnPackage || matchWithParent || matchOfCommand)) {
    1.64 -                    //System.out.println("  matchOnFile = "+matchOnFile+", matchOnPackage = "+matchOnPackage+", matchWithParent = "+matchWithParent+", matchOfCommand = "+matchOfCommand);
    1.65 -                    haveToWait = true;
    1.66 +                if (haveToWait) {
    1.67                      break;
    1.68                  }
    1.69                  Integer concurrencyWithNum = (Integer) concurrencyMap.get(cmdName);
    1.70 @@ -595,7 +579,57 @@
    1.71          return !haveToWait;
    1.72      }
    1.73      
    1.74 -    private boolean haveToWaitFor(Collection files, Collection cmdFiles, int concurrency) {
    1.75 +    /**
    1.76 +     * Tell whether the serial execution is matched between two commands.
    1.77 +     * @param name The name of the first command
    1.78 +     * @param name2 The name of the second command
    1.79 +     * @param files The collection of files the first command acts on
    1.80 +     * @param files2 The collection of files the second command acts on
    1.81 +     * @param serialOnFile Whether the first command deserves serial execution
    1.82 +     *        on files
    1.83 +     * @param serialOnPackage Whether the first command deserves serial execution
    1.84 +     *        on files in a single package
    1.85 +     * @param serialWithParent Whether the first command deserves serial execution
    1.86 +     *        with commands running on the parent folder of it's files
    1.87 +     * @param serialOfCommand Whether there can not be two commands of the same
    1.88 +     *        name running.
    1.89 +     */
    1.90 +    private static boolean matchSerial(String name, String name2,
    1.91 +                                       Collection files, Collection files2,
    1.92 +                                       boolean serialOnFile, boolean serialOnPackage,
    1.93 +                                       boolean serialWithParent, boolean serialOfCommand) {
    1.94 +        boolean matchOnFile = false;
    1.95 +        boolean matchOnPackage = false;
    1.96 +        boolean matchWithParent = false;
    1.97 +        boolean matchOfCommand = false;
    1.98 +        if (serialOnFile) {
    1.99 +            for(Iterator it = files.iterator(); it.hasNext(); ) {
   1.100 +                String file = (String) it.next();
   1.101 +                if (files2.contains(file)) {
   1.102 +                    matchOnFile = true;
   1.103 +                    break;
   1.104 +                }
   1.105 +            }
   1.106 +        }
   1.107 +        if (serialOnPackage) {
   1.108 +            if (areFilesInSamePackage(files, files2)) {
   1.109 +                matchOnPackage = true;
   1.110 +            }
   1.111 +        }
   1.112 +        if (serialWithParent) {
   1.113 +            if (isParentFolder(files, files2)) {
   1.114 +                matchWithParent = true;
   1.115 +            }
   1.116 +        }
   1.117 +        if (serialOfCommand) {
   1.118 +            matchOfCommand = name.equals(name2);
   1.119 +        }
   1.120 +        // if (serialOfCommand && !matchOfCommand) do not wait
   1.121 +        //System.out.println("  matchOnFile = "+matchOnFile+", matchOnPackage = "+matchOnPackage+", matchWithParent = "+matchWithParent+", matchOfCommand = "+matchOfCommand);
   1.122 +        return (!serialOfCommand || matchOfCommand) && (matchOnFile || matchOnPackage || matchWithParent || matchOfCommand);
   1.123 +    }
   1.124 +    
   1.125 +    private static boolean haveToWaitFor(Collection files, Collection cmdFiles, int concurrency) {
   1.126          boolean serialOnFile = (concurrency & VcsCommand.EXEC_SERIAL_ON_FILE) != 0;
   1.127          boolean serialOnPackage = (concurrency & VcsCommand.EXEC_SERIAL_ON_PACKAGE) != 0;
   1.128          boolean serialWithParent = (concurrency & VcsCommand.EXEC_SERIAL_WITH_PARENT) != 0;