KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > executor > CheckoutExecutor


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.executor;
21
22 import org.netbeans.modules.versioning.system.cvss.*;
23 import org.netbeans.lib.cvsclient.command.GlobalOptions;
24 import org.netbeans.lib.cvsclient.command.DefaultFileInfoContainer;
25 import org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand;
26 import org.netbeans.lib.cvsclient.command.commit.CommitInformation;
27 import org.netbeans.lib.cvsclient.event.ModuleExpansionEvent;
28 import org.netbeans.api.progress.aggregate.ProgressContributor;
29 import org.openide.filesystems.FileObject;
30 import org.openide.filesystems.FileUtil;
31
32 import java.util.*;
33 import java.io.File JavaDoc;
34
35 /**
36  * Executes a given 'checkout' command and refreshes file statuses.
37  *
38  * @author Maros Sandor
39  */

40 public class CheckoutExecutor extends ExecutorSupport {
41     
42     private Set refreshedFiles;
43     private Set expandedModules = new HashSet();
44
45     public CheckoutExecutor(CvsVersioningSystem cvs, CheckoutCommand cmd) {
46         this(cvs, cmd, null);
47     }
48     
49     public CheckoutExecutor(CvsVersioningSystem cvs, CheckoutCommand cmd, GlobalOptions options) {
50         super(cvs, cmd, options);
51     }
52
53     /**
54      * Return expanded module names (String)s, If it contains "."
55      * it means "unknown but all".
56      */

57     public Set getExpandedModules() {
58         return expandedModules;
59     }
60
61     public final void moduleExpanded(ModuleExpansionEvent e) {
62         String JavaDoc module = e.getModule();
63         expandedModules.add(module);
64     }
65
66     /**
67      * Refreshes statuses of relevant files after this command terminates.
68      */

69     protected void commandFinished(ClientRuntime.Result result) {
70         
71         CheckoutCommand xcmd = (CheckoutCommand) cmd;
72         
73         // files that we have information that changed
74
refreshedFiles = new HashSet(toRefresh.size());
75         
76         for (Iterator i = toRefresh.iterator(); i.hasNext();) {
77             // XXX getting DefaultFileInfoContainer still filled by types from CommitInformation
78
DefaultFileInfoContainer info = (DefaultFileInfoContainer) i.next();
79             int repositoryStatus = FileStatusCache.REPOSITORY_STATUS_UNKNOWN;
80             if (CommitInformation.CHANGED.equals(info.getType()) || CommitInformation.ADDED.equals(info.getType())) {
81                 repositoryStatus = FileStatusCache.REPOSITORY_STATUS_UPTODATE;
82             } else if (CommitInformation.REMOVED.equals(info.getType()) || CommitInformation.TO_ADD.equals(info.getType())) {
83                 repositoryStatus = FileStatusCache.REPOSITORY_STATUS_UNKNOWN;
84             }
85             File JavaDoc file = FileUtil.normalizeFile(info.getFile());
86             cache.refreshCached(file, repositoryStatus);
87             refreshedFiles.add(file);
88         }
89         
90         // refresh all command roots
91
File JavaDoc [] files = xcmd.getFiles();
92         for (int i = 0; i < files.length; i++) {
93             File JavaDoc file = FileUtil.normalizeFile(files[i]);
94             refreshRecursively(file);
95             if (file.isFile()) {
96                 cache.refreshCached(file.getParentFile(), FileStatusCache.REPOSITORY_STATUS_UNKNOWN);
97             }
98             FileObject fo = FileUtil.toFileObject(file);
99             if (fo != null) {
100                 fo.refresh(true);
101             }
102         }
103     }
104
105     private void refreshRecursively(File JavaDoc file) {
106         if (cvs.isIgnoredFilename(file)) return;
107         if (refreshedFiles.contains(file)) return;
108         if (file.isDirectory()) {
109             File JavaDoc [] files = file.listFiles();
110             for (int i = 0; i < files.length; i++) {
111                 refreshRecursively(files[i]);
112             }
113             cache.refreshCached(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN);
114         } else {
115             if (cache.getStatus(file.getParentFile()).getStatus() == FileInformation.STATUS_VERSIONED_UPTODATE) {
116                 // do nothing
117
} else {
118                 cache.refreshCached(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN);
119             }
120         }
121     }
122
123 }
124
Popular Tags