KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > actions > tag > RTagExecutor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.versioning.system.cvss.ui.actions.tag;
21
22 import org.netbeans.modules.versioning.system.cvss.CvsVersioningSystem;
23 import org.netbeans.modules.versioning.system.cvss.ExecutorSupport;
24 import org.netbeans.modules.versioning.system.cvss.ClientRuntime;
25 import org.netbeans.modules.versioning.system.cvss.util.CommandDuplicator;
26 import org.netbeans.modules.versioning.system.cvss.util.Utils;
27 import org.netbeans.lib.cvsclient.command.GlobalOptions;
28 import org.netbeans.lib.cvsclient.command.tag.RtagCommand;
29 import org.netbeans.lib.cvsclient.admin.AdminHandler;
30 import org.openide.ErrorManager;
31 import org.openide.util.NbBundle;
32
33 import java.util.*;
34 import java.io.File JavaDoc;
35 import java.io.IOException JavaDoc;
36 import java.text.MessageFormat JavaDoc;
37
38 /**
39  * Executes a given 'rtag' command.
40  *
41  * @author Maros Sandor
42  */

43 public class RTagExecutor extends ExecutorSupport {
44     
45     /**
46      * Splits the original command into more commands if the original
47      * command would execute on incompatible files.
48      * See {@link #prepareBasicCommand(org.netbeans.lib.cvsclient.command.BasicCommand)}
49      * for more information.
50      *
51      * @param cmd command to execute
52      * @param options global option for the command
53      * @return array of executors that will execute the command (or array of splitted commands)
54      */

55     public static RTagExecutor [] splitCommand(RtagCommand cmd, File JavaDoc [] roots, GlobalOptions options) {
56         if (cmd.getDisplayName() == null) cmd.setDisplayName(NbBundle.getMessage(RTagExecutor.class, "MSG_RTagExecutor_CmdDisplayName"));
57         
58         File JavaDoc [][] splitRoots;
59         try {
60             splitRoots = splitByCvsRoot(roots);
61         } catch (IOException JavaDoc e) {
62             ErrorManager.getDefault().notify(e);
63             return null;
64         }
65         if (options == null) options = CvsVersioningSystem.createGlobalOptions();
66         
67         CvsVersioningSystem cvs = CvsVersioningSystem.getInstance();
68         AdminHandler ah = cvs.getAdminHandler();
69
70         RTagExecutor [] executors = new RTagExecutor[splitRoots.length];
71         CommandDuplicator cloner = CommandDuplicator.getDuplicator(cmd);
72         Set remoteRepositories = new HashSet(roots.length);
73         for (int i = 0; i < splitRoots.length; i++) {
74             File JavaDoc [] files = splitRoots[i];
75             for (int j = 0; j < files.length; j++) {
76                 File JavaDoc file = files[j];
77                 File JavaDoc directory = file.isDirectory() ? file : file.getParentFile();
78                 try {
79                     String JavaDoc repository = ah.getRepositoryForDirectory(directory.getAbsolutePath(), "").substring(1); // NOI18N
80
remoteRepositories.add(repository);
81                 } catch (IOException JavaDoc e) {
82                     ErrorManager.getDefault().notify(e);
83                     return null;
84                 }
85             }
86             GlobalOptions currentOptions = (GlobalOptions) options.clone();
87             try {
88                 currentOptions.setCVSRoot(Utils.getCVSRootFor(files[0]));
89             } catch (IOException JavaDoc e) {
90                 ErrorManager.getDefault().notify(e);
91                 return null;
92             }
93
94             RtagCommand command = (RtagCommand) cloner.duplicate();
95             command.setModules((String JavaDoc[]) remoteRepositories.toArray(new String JavaDoc[remoteRepositories.size()]));
96             String JavaDoc commandContext = NbBundle.getMessage(RTagExecutor.class, "MSG_RTagExecutor_CmdContext", Integer.toString(files.length));
97             command.setDisplayName(MessageFormat.format(cmd.getDisplayName(), new Object JavaDoc [] { commandContext }));
98             executors[i] = new RTagExecutor(cvs, command, currentOptions);
99         }
100         return executors;
101     }
102
103     private RTagExecutor(CvsVersioningSystem cvs, RtagCommand cmd, GlobalOptions options) {
104         super(cvs, cmd, options);
105     }
106
107     protected void commandFinished(ClientRuntime.Result result) {
108         // repository command, nothing to do here
109
}
110 }
111
Popular Tags