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.commands;


import org.openide.util.*;
import java.io.*;
import java.util.*;
import org.openide.filesystems.FileObject;
import java.beans.*;

import org.netbeans.lib.cvsclient.event.*;
import org.netbeans.lib.cvsclient.command.KeywordSubstitutionOptions;
import org.netbeans.modules.javacvs.*;

import org.netbeans.modules.javacvs.caching.*;
import org.netbeans.modules.javacvs.commands.*;
import org.netbeans.modules.javacvs.events.*;
import org.netbeans.modules.javacvs.customizers.CheckoutParamInput;


import org.netbeans.lib.cvsclient.command.DefaultFileInfoContainer;
import org.netbeans.lib.cvsclient.command.update.*;
import org.netbeans.lib.cvsclient.command.checkout.*;
import org.netbeans.lib.cvsclient.command.*;



/** This class implements the cvs checkout command.
 * @author mkleint
 */
public class CvsCheckout extends CacheUpdatingFsCommand  {
    
    CheckoutCommand command;
    boolean finishedOk;
    
    boolean isListOnly = false;
    protected String localPath;

    /**
     * Will force the checkout command to display only a list of modules.
     */
    private boolean showModules;

    /**
     * if set, will display just a list of modules with statuses.
     */
    private boolean showModulesWithStatus;

    /**
     * if set, will redirect the output of the command to standard output.
     */
    private boolean pipeToOutput;

    /**
     * Whether to prune directories, i.e. remove any directories that do not
     * contain any files. This is the -P option in command-line CVS.
     */
    private boolean pruneDirectories;

    /**
     * Resets any sticky tags/dates/options imposed on the updated file(s).
     */
    private boolean resetStickyOnes;

    /**
     * Use head revision if a revision meeting criteria set by switches -r/-D
     * (tag/date) is not found.
     */
    private boolean useHeadIfNotFound;

    /**
     * Forces a checkout of a revision that was current at specified date.
     */
    private String checkoutByDate;

    /**
     * Forces a checkout of specified revision. Can be a number/tag/branch
     */
    private String checkoutByRevision;

    /**
     * Use this keyword substitution for the command.
     * does not include the -k switch part.
     */
    
    private KeywordSubstitutionOptions keywordSubst;
    /**
     * to be recursive is default behaviour of command.
     */
    private boolean recursive = true;
    
    /**
     * A list of modules to checkout
     */
    private String[] modules;
    
    private FsCheckout checkoutImpl;
    
    /** Creates new CvsCheckout instance.
     */    
    public CvsCheckout() {
        super();
        localPath = null;
        checkoutImpl = new CheckoutImpl();
    }
    
    /** Creates new CvsCheckout instance.
     */
    public CvsCheckout(String[] modules, ClientProvider fs) {
        super(fs);
        localPath = null;
        this.modules = modules;
        checkoutImpl = new CheckoutImpl();
    }
    
    public CvsCommand getImpl() {
        return checkoutImpl;
    }    
    
    public FsCheckout getCheckoutImpl() {
        return checkoutImpl;
    }        
    
    public String getName() {
        return NbBundle.getBundle(CvsCheckout.class).getString("CvsCheckout.name"); // NOI18N
    }

    public Class getMainCvsCommand() {
        return CheckoutCommand.class;
    }
        
    
    /** this methods sets the localpath for the client needed for checkout (preferably the filesystem's working directory)
     * since we need to keep the directory structure in use and not checkout in a subtree of already checked out stuff.
     */
    public void setLocalPath(String path) {
        localPath = path;
        File[] files = new File[1];
        files[0] = new File(path);
        setFiles(files);
    }
    
    protected void initCommand(boolean commandIsRunning) {
        // here the the commands is initiated just right before running the command
        clearCommandList();
        command = new CheckoutCommand();
        if (localPath != null && commandIsRunning) {
           libClient.setLocalPath(localPath); // needed because of the nature of checkout
        }
        setCommandArguments(command);
        toDoCommands.addElement(command);
        super.initCommand(commandIsRunning);
        if (isResetStickyOnes() || getCheckoutByDate() != null || getCheckoutByRevision() != null) {
            setFullEntriesUpdate(true);
            prepareCache(getFiles(), isRecursive());
        }        
    }
    
    
    protected void beforeEachExecute() {
        super.beforeEachExecute();
    }
    
    protected void finishedCommand() {
        //fire cache update TODO
        fireUpdateCache();
        super.finishedCommand();
    }
    
    
    protected void executeFailed(Exception exc) {
        // fire cache update TODO
        fireUpdateCache();
        super.executeFailed(exc);
    }
    
    
    /**
     * Called when file status information has been received
     */
    public void fileInfoGenerated(FileInfoEvent e) {
        FileInfoContainer fInfo = e.getInfoContainer();
        if (fInfo != null) {
            if (!getGlobalOptions().isDoNoChanges()) {
                if (fInfo instanceof DefaultFileInfoContainer) {
                    DefaultFileInfoContainer info = (DefaultFileInfoContainer)fInfo;
                    updateCache(info);
                }
            }
        }
        super.fileInfoGenerated(e);
    }
    
    
    
    /**
     * Getter for property showModules.
     * @return Value of property showModules.
     */
    public boolean isShowModules()
    {
        return showModules;
    }

    /**
     * Setter for property showModules.
     * @param showModules New value of property showModules.
     */
    public void setShowModules(boolean showModules)
    {
        this.showModules = showModules;
    }

    /**
     * Getter for property showModulesWithStatus.
     * @return Value of property showModulesWithStatus.
     */
    public boolean isShowModulesWithStatus()
    {
        return showModulesWithStatus;
    }

    /**
     * Setter for property showModulesWithStatus.
     * @param showModulesWithStatus New value of property showModulesWithStatus.
     */
    public void setShowModulesWithStatus(boolean showModulesWithStatus)
    {
        this.showModulesWithStatus = showModulesWithStatus;
    }

    /**
     * Set whether to prune directories.
     * This is the -P option in the command-line CVS.
     */
    public void setPruneDirectories(boolean pruneDirectories)
    {
        this.pruneDirectories = pruneDirectories;
    }

    /**
     * Get whether to prune directories.
     * @return true if directories should be removed if they contain no files,
     * false otherwise.
     */
    public boolean getPruneDirectories()
    {
        return pruneDirectories;
    }

    /**
     * Getter for property pipeToOutput.
     * @return Value of property pipeToOutput.
     */
    public boolean isPipeToOutput()
    {
        return pipeToOutput;
    }

    /**
     * Setter for property pipeToOutput.
     * @param pipeToOutput New value of property pipeToOutput.
     */
    public void setPipeToOutput(boolean pipeToOutput)
    {
        this.pipeToOutput = pipeToOutput;
    }

    /**
     * Getter for property resetStickyOnes.
     * @return Value of property resetStickyOnes.
     */
    public boolean isResetStickyOnes()
    {
        return resetStickyOnes;
    }

    /**
     * Setter for property resetStickyOnes.
     * @param resetStickyOnes New value of property resetStickyOnes.
     */
    public void setResetStickyOnes(boolean resetStickyOnes)
    {
        this.resetStickyOnes = resetStickyOnes;
    }

    /**
     * Getter for property useHeadIfNotFound.
     * @return Value of property useHeadIfNotFound.
     */
    public boolean isUseHeadIfNotFound()
    {
        return useHeadIfNotFound;
    }

    /**
     * Setter for property useHeadIfNotFound.
     * @param useHeadIfNotFound New value of property useHeadIfNotFound.
     */
    public void setUseHeadIfNotFound(boolean useHeadIfNotFound)
    {
        this.useHeadIfNotFound = useHeadIfNotFound;
    }

    /**
     * Getter for property checkoutByDate.
     * @return Value of property checkoutByDate.
     */
    public String getCheckoutByDate()
    {
        return checkoutByDate;
    }

    /**
     * Setter for property checkoutByDate.
     * @param checkoutByDate New value of property checkoutByDate.
     */
    public void setCheckoutByDate(String checkoutByDate)
    {
        this.checkoutByDate = checkoutByDate;
    }

    /**
     * Getter for property checkoutByRevision.
     * @return Value of property checkoutByRevision.
     */
    public String getCheckoutByRevision()
    {
        return checkoutByRevision;
    }

    /**
     * Setter for property checkoutByRevision.
     * @param checkoutByRevision New value of property checkoutByRevision.
     */
    public void setCheckoutByRevision(String checkoutByRevision)
    {
        this.checkoutByRevision = checkoutByRevision;
    }

    /**
     * Getter for property keywordSubst.
     * @return Value of property keywordSubst.
     */
    public KeywordSubstitutionOptions getKeywordSubst()
    {
        return keywordSubst;
    }

    /**
     * Setter for property keywordSubst.
     * @param keywordSubst New value of property keywordSubst.
     */
    public void setKeywordSubst(KeywordSubstitutionOptions keywordSubst)
    {
        this.keywordSubst = keywordSubst;
    }    
    
    /**
     * Set the modules to checkout.
     * @param theModules the names of the modules to checkout
     */
    public void setModules(String[] modules)
    {
        this.modules = modules;
    }
    
    public String[] getModules() {
        return modules;
    }
    
    /** Sets recursive (-R switch) or local (-l switch) behaviour.
     */    
    public void setRecursive(boolean recursive) {
        this.recursive = recursive;
    }
    
    /** Returns recursive (-R switch) or local (-l switch) behaviour.
     */    
    public boolean isRecursive() {
        return recursive;
    }
    
    /** Returns the cvs command's switches as a String.
     *
     * @return String representation of the Command's cvs switches.
     */
    public String getCVSArguments() {
        String retValue;
        
        retValue = super.getCVSArguments();
        if (getModules() != null) {
            String[] mods = getModules();
            for (int i = 0; i < mods.length; i++) {
                retValue = retValue + " " + mods[i];
            }
        }
        return retValue;
    }
    
    public class CheckoutImpl extends FsCheckout implements FileSystemCommandImpl {
         public CheckoutImpl() {
        }

         public FileSystemCommand getOuterClassInstance() {
            return CvsCheckout.this;
        }        
      
        /** Returns recursive (-R switch) or local (-l switch) behaviour.
         */
        public boolean isRecursive() {
            return CvsCheckout.this.isRecursive();
        }
        
        /**
         * Set the modules to checkout.
         * @param theModules the names of the modules to checkout
         */
        public void setModules(String[] modules) {
            CvsCheckout.this.setModules(modules);
        }
        
        public void addCommandErrorListener(org.netbeans.modules.javacvs.events.CommandErrorListener commErrListener) {
            CvsCheckout.this.addCommandErrorListener(commErrListener);
        }
        
        public void removeCommandErrorListener(org.netbeans.modules.javacvs.events.CommandErrorListener commErrListener) {
            CvsCheckout.this.removeCommandErrorListener(commErrListener);
        }
        
        /**
         * Getter for property showModulesWithStatus.
         * @return Value of property showModulesWithStatus.
         */
        public boolean isShowModulesWithStatus() {
            return CvsCheckout.this.isShowModulesWithStatus();
        }
        
        /**
         * Getter for property checkoutByRevision.
         * @return Value of property checkoutByRevision.
         */
        public String getCheckoutByRevision() {
            return CvsCheckout.this.getCheckoutByRevision();
        }
        
        /**
         * Setter for property showModulesWithStatus.
         * @param showModulesWithStatus New value of property showModulesWithStatus.
         */
        public void setShowModulesWithStatus(boolean showModulesWithStatus) {
            CvsCheckout.this.setShowModulesWithStatus(showModulesWithStatus);
        }
        
        /**
         * Getter for property showModules.
         * @return Value of property showModules.
         */
        public boolean isShowModules() {
            return CvsCheckout.this.isShowModules();
        }
        
        /**
         * Setter for property showModules.
         * @param showModules New value of property showModules.
         */
        public void setShowModules(boolean showModules) {
            CvsCheckout.this.setShowModules(showModules);
        }
        
        /**
         * Setter for property keywordSubst.
         * @param keywordSubst New value of property keywordSubst.
         */
        public void setKeywordSubst(KeywordSubstitutionOptions keywordSubst) {
            CvsCheckout.this.setKeywordSubst(keywordSubst);
        }
        
        /**
         * Setter for property resetStickyOnes.
         * @param resetStickyOnes New value of property resetStickyOnes.
         */
        public void setResetStickyOnes(boolean resetStickyOnes) {
            CvsCheckout.this.setResetStickyOnes(resetStickyOnes);
        }
        
        /**
         * Setter for property checkoutByDate.
         * @param checkoutByDate New value of property checkoutByDate.
         */
        public void setCheckoutByDate(String checkoutByDate) {
            CvsCheckout.this.setCheckoutByDate(checkoutByDate);
        }
        
        /**
         * Getter for property pipeToOutput.
         * @return Value of property pipeToOutput.
         */
        public boolean isPipeToOutput() {
            return CvsCheckout.this.isPipeToOutput();
        }
        
        public String[] getModules() {
            return  CvsCheckout.this.getModules();
        }
        
        /** Sets recursive (-R switch) or local (-l switch) behaviour.
         */
        public void setRecursive(boolean recursive) {
            CvsCheckout.this.setRecursive(recursive);
        }
        
        /** Add a CommandDisplayerListener to the FilesystemCommand.
         * 
All UI communication and display of output should be handled via the CommandDisplayerListeners. * * @param listener The listener to add. * */ public void addDisplayerListener(CommandDisplayerListener listener) { CvsCheckout.this.addDisplayerListener(listener); } /** * Get whether to prune directories. * @return true if directories should be removed if they contain no files, * false otherwise. */ public boolean getPruneDirectories() { return CvsCheckout.this.getPruneDirectories(); } /** * Getter for property resetStickyOnes. * @return Value of property resetStickyOnes. */ public boolean isResetStickyOnes() { return CvsCheckout.this.isResetStickyOnes(); } /** * Set whether to prune directories. * This is the -P option in the command-line CVS. */ public void setPruneDirectories(boolean pruneDirectories) { CvsCheckout.this.setPruneDirectories(pruneDirectories); } /** * Setter for property checkoutByRevision. * @param checkoutByRevision New value of property checkoutByRevision. */ public void setCheckoutByRevision(String checkoutByRevision) { CvsCheckout.this.setCheckoutByRevision(checkoutByRevision); } /** * Setter for property useHeadIfNotFound. * @param useHeadIfNotFound New value of property useHeadIfNotFound. */ public void setUseHeadIfNotFound(boolean useHeadIfNotFound) { CvsCheckout.this.setUseHeadIfNotFound(useHeadIfNotFound); } /** * Getter for property checkoutByDate. * @return Value of property checkoutByDate. */ public String getCheckoutByDate() { return CvsCheckout.this.getCheckoutByDate(); } /** Starts the thread with the command - executes the run() method. */ public void startCommand() { CvsCheckout.this.startCommand(); } /** * Getter for property keywordSubst. * @return Value of property keywordSubst. */ public KeywordSubstitutionOptions getKeywordSubst() { return CvsCheckout.this.getKeywordSubst(); } /** Removes a CommandDisplayerListener from the FilesystemCommand. * All the listeners are removed once the command ends. * * @param listener the listener to remove */ public void removeDisplayerListener(CommandDisplayerListener listener) { CvsCheckout.this.removeDisplayerListener(listener); } public void setFileObjects(FileObject[] fileObjects) { CvsCheckout.this.setFileObjects(fileObjects); } /** * Setter for property pipeToOutput. * @param pipeToOutput New value of property pipeToOutput. */ public void setPipeToOutput(boolean pipeToOutput) { CvsCheckout.this.setPipeToOutput(pipeToOutput); } /** * Getter for property useHeadIfNotFound. * @return Value of property useHeadIfNotFound. */ public boolean isUseHeadIfNotFound() { return CvsCheckout.this.isUseHeadIfNotFound(); } public FsGlobalOptions getGlobalOptions() { FsGlobalOptions retValue; retValue = new FsGlobalOptionsImpl(CvsCheckout.this.getGlobalOptions()); return retValue; } } }
... 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.