alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.javacvs.caching;

/**
 *
 * @author  Milos Kleint
 */
import org.netbeans.modules.javacvs.commands.CvsStatus;
import org.netbeans.modules.vcscore.cache.CacheHandler;
import org.netbeans.modules.javacvs.commands.ClientProvider;
import java.io.File;
import java.io.FileFilter;
import java.util.*;

public class RefreshCommand extends CvsStatus {

    public RefreshCommand(File[] filesToCheck, ClientProvider fs) {
        super(filesToCheck, fs);
        setRefreshing(true);
    }
    
    /** Creates cvs status command.
     */    
    public RefreshCommand() {
        super();
        setRefreshing(true);
    }
    
   
            // for dirs to be recursively refreshed, perform check wheather they are CVS dirs. If not..
    // search for all it's subdirs that are..
    private File[] findRelevantDirs(File[] files) {
        LinkedList localOnes = new LinkedList();
        LinkedList okFiles = new LinkedList();
        if (files == null) {
            return null;
        }
        for (int index = 0; index < files.length; index++) {
            File file = files[index];
            if (file.isDirectory()) {
                File[] cvsDir = file.listFiles(new FileFilter() {
                    public boolean accept(File f) {
                        if (f.isDirectory() && f.getName().equalsIgnoreCase("CVS")) return true; // NOI18N
                        return false;
                    }
                });
                if (cvsDir.length == 0)  {
                    localOnes.add(file);
//                    cacheObject.fireCacheHandlerEvent(FileSystemCache.EVENT_CHANGED, file);
                }
                else okFiles.add(file);
            } else {
                // okFiles.add(file);
                // files are not included.. recursive refresh makes no sense for them
            }
        }
        if (localOnes.size() == 0) {
            // everything is ok.. return the initial file[] array.
            return files;
        } 
        Iterator it = localOnes.iterator();
        while (it.hasNext()) {
            File main = (File)it.next();
            File[] toFind = main.listFiles();
            if (toFind.length > 0) {
                toFind = findRelevantDirs(toFind);
                if (toFind.length > 0) {
                    for (int ind = 0; ind < toFind.length; ind++) {
                        okFiles.add(toFind[ind]);
                    }
                }
            }
        }
        File[] toReturn = new File[okFiles.size()];
        toReturn = (File[])okFiles.toArray(toReturn);
        return toReturn;
    }    

    /** set the files/dirs that the command operates on. Not directly used here,
     * but subclasses use it in 99% of cases. They should set it before starting a
     * command, according to the nodes selected or otherwise.. and feed it to
     * undelying library commands.
     * @deprecated Use the setFileObjects() methods intead where possible. The setFiles() method might disappear soon.
     * @param fls array of files that the comamnds is executed upon.
     */
    public void setFiles(File[] fls) {
        super.setFiles(findRelevantDirs(fls));
    }
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.