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-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.javacvs.commands;


import org.openide.util.*;
import java.io.*;
import java.util.*;

import org.netbeans.modules.javacvs.*;
import org.netbeans.lib.cvsclient.event.*;
import org.netbeans.lib.cvsclient.command.diff.DiffInformation;
import org.netbeans.lib.cvsclient.command.PipedFileInformation;
import org.netbeans.lib.cvsclient.command.update.UpdateCommand;
import org.netbeans.lib.cvsclient.command.diff.DiffCommand;
import org.netbeans.lib.cvsclient.command.status.StatusCommand;
import org.netbeans.lib.cvsclient.command.Command;
import org.netbeans.lib.cvsclient.command.BasicCommand;
import org.netbeans.lib.cvsclient.command.CommandException;
import org.netbeans.modules.javacvs.commands.*;
import org.openide.filesystems.FileObject;
import java.beans.*;
import org.netbeans.modules.javacvs.customizers.DiffParamInput;
import org.netbeans.modules.javacvs.events.*;

/** This class implements the cvs diff command.
 *
 * @author mkleint
 */
public class CvsDiff extends FileSystemCommand {
    
    private File startFile;

    
    /**
     * Holds value of property beforeDate.
     */
    private String beforeDate1 = null;

    /**
     * Holds value of property firstRevision.
     */
    private String revision1 = null;

    /**
     * Holds value of property secondRevision.
     */
    private String revision2 = null;

    /**
     * Holds value of property beforeDate2.
     */
    private String beforeDate2 = null;

    /**
     * Keyword substitution. The -k switch in command line cvs.
     */
    private String keywordSubst;   
    
    /**
     * to be recursive is default behaviour of command.
     */
    private boolean recursive = true;    

    /** Holds value of property ignoreAllWhitespace. */
    private boolean ignoreAllWhitespace;
    
    /** Holds value of property ignoreBlankLines. */
    private boolean ignoreBlankLines;
    
    /** Holds value of property ignoreCase. */
    private boolean ignoreCase;
    
    /** Holds value of property ignoreSpaceChange. */
    private boolean ignoreSpaceChange;

    /** Holds value of property contextDiff. */
    private boolean contextDiff;
    
    /** Holds value of property unifiedDiff. */
    private boolean unifiedDiff;    
    
    private boolean includeStatCheckCommands = false;

    private LinkedList checkoutCommands;
    
    private FsDiff diffImpl;

    /** Creates new CvsDiff instance.
     */
    public CvsDiff(File[] filesToCheck, ClientProvider fs) {
        super(fs);
        setFiles(filesToCheck);
        diffImpl = new DiffImpl();
    }
    
    /** Creates new CvsDiff instance.
     */    
    public CvsDiff() {
        super();
        diffImpl = new DiffImpl();
    }

    public CvsCommand getImpl() {
        return diffImpl;
    }    
    
    public FsDiff getDiffImpl() {
        return diffImpl;
    }
    
    public void setIncludeStatusAndCheckout(boolean include) {
        includeStatCheckCommands = include;
    }
    
    public String getName() {
        return NbBundle.getBundle(CvsDiff.class).getString("CvsDiff.name"); // NOI18N
    }

   
    protected void initCommand(boolean commandIsRunning) {
        // here the the commands is initiated just right before running the command
        clearCommandList();
        int dirNum = 0;
        BasicCommand command;
        checkoutCommands = new LinkedList();
        File[] files = new File[getFiles().length];
        System.arraycopy(getFiles(),0,files,0, getFiles().length);
        
        for (int index = 0; index < files.length; index++) {
            if (files[index] != null && files[index].isDirectory()) {
                //that way just one UI component is run after finish of the command
                File[] fls = new File[1];
                fls[0] = files[index];
                if (includeStatCheckCommands) {
                    command = new StatusCommand();
                    command.setFiles (fls);
                    toDoCommands.addElement (command);
                }
                command = new DiffCommand();
                command.setFiles(fls);
                setCommandArguments(command);
                if (includeStatCheckCommands) {
                    checkNeedForCheckout((DiffCommand)command, checkoutCommands);
                }
                toDoCommands.addElement(command);
                files[index] = null;
                dirNum = dirNum + 1;
            }
        }
        // now proceed all single files in one batch.
        if (dirNum == files.length) {
            super.initCommand(commandIsRunning);            
            return; // no files to check status on.
        }
        File[] singleFiles = new File[files.length - dirNum];
        int singleIndex = 0;
        for (int ind = 0; ind < files.length; ind++) {
            if (files[ind] != null) {
                singleFiles[singleIndex] = files[ind];
                singleIndex = singleIndex + 1;
            }
        }
        if (includeStatCheckCommands) {
            command = new StatusCommand();
            command.setFiles (singleFiles);
            toDoCommands.addElement (command);
        }
        command = new DiffCommand();
        command.setFiles(singleFiles);
        setCommandArguments(command);     
        if (includeStatCheckCommands) {
            checkNeedForCheckout((DiffCommand)command, checkoutCommands);
        }
        toDoCommands.addElement(command);
        // just add oen command to the queue
        super.initCommand(commandIsRunning);
        
    }
    
    
    protected void beforeEachExecute() {
        super.beforeEachExecute();
    }
    
    protected void afterEachExecute() {
        super.afterEachExecute();
    }
    
    protected void executeFailed(Exception exc) {
        stopCommand();
        super.executeFailed(exc);
    }
    
     /**
     * return the library command that is considered main command.
     * that one is used for loading from
     */
    protected Class getMainCvsCommand() {
        return DiffCommand.class;
    }   
    
    /**
     * Called when file status information has been received
     */
    public void fileInfoGenerated(FileInfoEvent e) {
        super.fileInfoGenerated(e);
    }
    
    private void checkNeedForCheckout(DiffCommand comm, LinkedList checkoutList) { 
  // Do always.. just to be sure we got the base file to start from..
  // therwise for Locally removed files we would have to make complicated lookup.. for example.
//        if (comm.getRevision2() != null || comm.getBeforeDate2() != null) {
            UpdateCommand checkComm = new UpdateCommand();
            checkComm.setFiles(comm.getFiles());
            checkComm.setPipeToOutput(true);
            checkComm.setRecursive(comm.isRecursive());
            if (comm.getRevision2() != null) {
                checkComm.setUpdateByRevision(comm.getRevision2());
            } else  if (comm.getBeforeDate2() != null) {
                checkComm.setUpdateByDate(comm.getBeforeDate2());
            }
            checkoutList.add(checkComm);
//        }
    }
    
    // adds the checkouts commands before the diff commands in order to have the 
    public void addCheckoutCommands() {
        Iterator it = checkoutCommands.iterator();
        while (it.hasNext()) {
            toDoCommands.add(0, it.next());
        }
    }

        /** Getter for property beforeDate.
     * @return Value of property beforeDate.
     */
    public String getBeforeDate1()
    {
        return beforeDate1;
    }

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


    /** Getter for property firstRevision.
     * @return Value of property firstRevision.
     */
    public String getRevision1()
    {
        return revision1;
    }

    /** Setter for property firstRevision.
     * @param firstRevision New value of property firstRevision.
     */
    public void setRevision1(String firstRevision)
    {
        revision1 = firstRevision;
    }

    /** Getter for property secondRevision.
     * @return Value of property secondRevision.
     */
    public String getRevision2()
    {
        return revision2;
    }

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

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

    /** Setter for property beforeDate2.
     * @param beforeDate2 New value of property beforeDate2.
     */
    public void setBeforeDate2(String beforeDate2)
    {
        this.beforeDate2 = beforeDate2;
    }
    /**
     * Getter for property keywordSubst.
     * @return Value of property keywordSubst.
     */
    public String getKeywordSubst()
    {
        return keywordSubst;
    }

    /**
     * Setter for property keywordSubst.
     * @param keywordSubst New value of property keywordSubst.
     */
    public void setKeywordSubst(String keywordSubst)
    {
        this.keywordSubst = keywordSubst;
    }
    
    /** 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;
    }    
    
    /** true if all the whitespace differences should be ignored. (-w)
     * @return Value of property ignoreAllWhitespace.
     */
    public boolean isIgnoreAllWhitespace() {
        return this.ignoreAllWhitespace;
    }
    
    /** Setter for property ignoreAllWhitespace.
     *  true if all the whitespace differences should be ignored. (-w)
     * @param ignoreAllWhitespace New value of property ignoreAllWhitespace.
     */
    public void setIgnoreAllWhitespace(boolean ignoreAllWhitespace) {
        this.ignoreAllWhitespace = ignoreAllWhitespace;
    }
    
    /** Getter for property ignoreBlankLines.
     * @return Value of property ignoreBlankLines.
     */
    public boolean isIgnoreBlankLines() {
        return this.ignoreBlankLines;
    }
    
    /** Setter for property ignoreBlankLines.
     * @param ignoreBlankLines New value of property ignoreBlankLines.
     */
    public void setIgnoreBlankLines(boolean ignoreBlankLines) {
        this.ignoreBlankLines = ignoreBlankLines;
    }
    
    /** Getter for property ignoreCase.
     * @return Value of property ignoreCase.
     */
    public boolean isIgnoreCase() {
        return this.ignoreCase;
    }
    
    /** Setter for property ignoreCase.
     * @param ignoreCase New value of property ignoreCase.
     */
    public void setIgnoreCase(boolean ignoreCase) {
        this.ignoreCase = ignoreCase;
    }
    
    /** Getter for property ignoreSpaceChange.
     * @return Value of property ignoreSpaceChange.
     */
    public boolean isIgnoreSpaceChange() {
        return this.ignoreSpaceChange;
    }
    
    /** Setter for property ignoreSpaceChange.
     * @param ignoreSpaceChange New value of property ignoreSpaceChange.
     */
    public void setIgnoreSpaceChange(boolean ignoreSpaceChange) {
        this.ignoreSpaceChange = ignoreSpaceChange;
    }    
    
    /** 
     * equals to the -c switch of cvs
     * Getter for property contextDiff.
     * @return Value of property contextDiff.
     */
    public boolean isContextDiff() {
        return this.contextDiff;
    }
    
    /**
     * equals to the -c switch of cvs
     * Setter for property contextDiff.
     * @param contextDiff New value of property contextDiff.
     */
    public void setContextDiff(boolean contextDiff) {
        this.contextDiff = contextDiff;
    }
    
    /** 
     * equals to the -u switch of cvs
     * Getter for property unifiedDiff.
     * @return Value of property unifiedDiff.
     */
    public boolean isUnifiedDiff() {
        return this.unifiedDiff;
    }
    
    /**
     * equals to the -u switch of cvs. 
     * Setter for property unifiedDiff. 
     * @param unifiedDiff New value of property unifiedDiff.
     */
    public void setUnifiedDiff(boolean unifiedDiff) {
        this.unifiedDiff = unifiedDiff;
    }
        
    /**
     * called when server responses with "ok" or "error", (when the command finishes)
     */
    public void commandTerminated(org.netbeans.lib.cvsclient.event.TerminationEvent e) {
//        super.commandTerminated(e);
    }    
    
    public class DiffImpl extends FsDiff implements FileSystemCommandImpl {
        
        public DiffImpl() {
        }

        public FileSystemCommand getOuterClassInstance() {
            return CvsDiff.this;
        }        
        
        /** 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) { CvsDiff.this.addDisplayerListener(listener); } public void removeCommandErrorListener(CommandErrorListener commErrListener) { CvsDiff.this.removeCommandErrorListener(commErrListener); } /** * Getter for property keywordSubst. * @return Value of property keywordSubst. */ public String getKeywordSubst() { return CvsDiff.this.getKeywordSubst(); } public void addCommandErrorListener(org.netbeans.modules.javacvs.events.CommandErrorListener commErrListener) { CvsDiff.this.addCommandErrorListener(commErrListener); } /** Clones the instance of the command. * @return Returns the cloned object. * @throws CloneNotSupportedException if clone is not supported by subclasses, it throws CloneNotSupportedException */ public Object clone() throws CloneNotSupportedException { Object retValue; retValue = CvsDiff.this.clone(); return retValue; } /** Getter for property beforeDate2. * @return Value of property beforeDate2. */ public String getBeforeDate2() { return CvsDiff.this.getBeforeDate2(); } /** Getter for property beforeDate. * @return Value of property beforeDate. */ public String getBeforeDate1() { return CvsDiff.this.getBeforeDate1(); } /** Sets recursive (-R switch) or local (-l switch) behaviour. */ public void setRecursive(boolean recursive) { CvsDiff.this.setRecursive(recursive); } /** Starts the thread with the command - executes the run() method. */ public void startCommand() { CvsDiff.this.startCommand(); } /** Setter for property beforeDate. * @param beforeDate New value of property beforeDate. */ public void setBeforeDate1(String beforeDate) { CvsDiff.this.setBeforeDate1(beforeDate); } /** Setter for property beforeDate2. * @param beforeDate2 New value of property beforeDate2. */ public void setBeforeDate2(String beforeDate2) { CvsDiff.this.setBeforeDate2(beforeDate2); } /** * Setter for property keywordSubst. * @param keywordSubst New value of property keywordSubst. */ public void setKeywordSubst(String keywordSubst) { CvsDiff.this.setKeywordSubst(keywordSubst); } /** Setter for property firstRevision. * @param firstRevision New value of property firstRevision. */ public void setRevision1(String firstRevision) { CvsDiff.this.setRevision1(firstRevision); } /** Setter for property secondRevision. * @param secondRevision New value of property secondRevision. */ public void setRevision2(String secondRevision) { CvsDiff.this.setRevision2(secondRevision); } /** Returns recursive (-R switch) or local (-l switch) behaviour. */ public boolean isRecursive() { return CvsDiff.this.isRecursive(); } /** 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) { CvsDiff.this.removeDisplayerListener(listener); } /** Getter for property secondRevision. * @return Value of property secondRevision. */ public String getRevision2() { return CvsDiff.this.getRevision2(); } /** Getter for property firstRevision. * @return Value of property firstRevision. */ public String getRevision1() { return CvsDiff.this.getRevision1(); } /** true if all the whitespace differences should be ignored. (-w) * @return Value of property ignoreAllWhitespace. */ public boolean isIgnoreAllWhitespace() { return CvsDiff.this.isIgnoreAllWhitespace(); } /** Setter for property ignoreAllWhitespace. * true if all the whitespace differences should be ignored. (-w) * @param ignoreAllWhitespace New value of property ignoreAllWhitespace. */ public void setIgnoreAllWhitespace(boolean ignoreAllWhitespace) { CvsDiff.this.setIgnoreAllWhitespace(ignoreAllWhitespace); } /** Getter for property ignoreBlankLines. * @return Value of property ignoreBlankLines. */ public boolean isIgnoreBlankLines() { return CvsDiff.this.isIgnoreBlankLines(); } /** Setter for property ignoreBlankLines. * @param ignoreBlankLines New value of property ignoreBlankLines. */ public void setIgnoreBlankLines(boolean ignoreBlankLines) { CvsDiff.this.setIgnoreBlankLines(ignoreBlankLines); } /** Getter for property ignoreCase. * @return Value of property ignoreCase. */ public boolean isIgnoreCase() { return CvsDiff.this.isIgnoreCase(); } /** Setter for property ignoreCase. * @param ignoreCase New value of property ignoreCase. */ public void setIgnoreCase(boolean ignoreCase) { CvsDiff.this.setIgnoreCase(ignoreCase); } /** Getter for property ignoreSpaceChange. * @return Value of property ignoreSpaceChange. */ public boolean isIgnoreSpaceChange() { return CvsDiff.this.isIgnoreSpaceChange(); } /** Setter for property ignoreSpaceChange. * @param ignoreSpaceChange New value of property ignoreSpaceChange. */ public void setIgnoreSpaceChange(boolean ignoreSpaceChange) { CvsDiff.this.setIgnoreSpaceChange(ignoreSpaceChange); } /** * equals to the -c switch of cvs * Getter for property contextDiff. * @return Value of property contextDiff. */ public boolean isContextDiff() { return CvsDiff.this.isContextDiff(); } /** * equals to the -c switch of cvs * Setter for property contextDiff. * @param contextDiff New value of property contextDiff. */ public void setContextDiff(boolean contextDiff) { CvsDiff.this.setContextDiff(contextDiff); } /** * equals to the -u switch of cvs * Getter for property unifiedDiff. * @return Value of property unifiedDiff. */ public boolean isUnifiedDiff() { return CvsDiff.this.isUnifiedDiff(); } /** * equals to the -u switch of cvs. * Setter for property unifiedDiff. * @param unifiedDiff New value of property unifiedDiff. */ public void setUnifiedDiff(boolean unifiedDiff) { CvsDiff.this.setUnifiedDiff(unifiedDiff); } public void setFileObjects(FileObject[] fileObjects) { CvsDiff.this.setFileObjects(fileObjects); } public FsGlobalOptions getGlobalOptions() { FsGlobalOptions retValue; retValue = new FsGlobalOptionsImpl(CvsDiff.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.