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.NbBundle;
import java.io.*;
import java.util.*;
import java.beans.*;
import org.openide.filesystems.FileObject;
import org.netbeans.modules.javacvs.customizers.ImportParamInput;

import org.netbeans.modules.javacvs.*;
import org.netbeans.modules.javacvs.events.*;
import org.netbeans.modules.javacvs.commands.*;
import org.netbeans.lib.cvsclient.event.*;
import org.netbeans.lib.cvsclient.commandLine.GetOpt;
import org.netbeans.lib.cvsclient.command.importcmd.*;
import org.netbeans.lib.cvsclient.command.DefaultFileInfoContainer;
import org.netbeans.lib.cvsclient.command.checkout.*;
import org.netbeans.lib.cvsclient.command.*;
import org.netbeans.modules.javacvs.caching.*;


/** this class implements the cvs import command.
 * @author mkleint
 */
public class CvsImport extends FileSystemCommand {
    
    ImportCommand command;
    private Map wrapperMap = new HashMap();
    private String logMessage;
    private String module;
    private String releaseTag;
    private String vendorBranch;
    private String vendorTag;
    private KeywordSubstitutionOptions keywordSubstitutionOptions;    
    
    private ImportImpl importImpl;
    
    /** Creates new CvsImport instance.
     */    
    public CvsImport() {
        super();
        importImpl = new ImportImpl();
    }
    
    /** Creates new CvsImport instance.
     */
    public CvsImport(ClientProvider fs) {
        super(fs);
        importImpl = new ImportImpl();
    }
    
    public CvsCommand getImpl() {
        return importImpl;
    }    
    
    public FsImport getImportImpl() {
        return importImpl;
    }
    
    public String getName() {
        return NbBundle.getBundle(CvsImport.class).getString("CvsImport.name"); // NOI18N
    }
    
    protected Class getMainCvsCommand() {
        return ImportCommand.class;
    }

/** if no param input was set before staring the command, 
 * the default defined in this method is used
 */
    
    protected void initCommand(boolean commandIsRunning) {
        // here the the commands is initiated just right before running the command
        clearCommandList();
        command = new ImportCommand();
        setCommandArguments(command);
        toDoCommands.addElement(command);
        super.initCommand(commandIsRunning);
    }
    
    
    protected void finishedCommand() {
        // called when the communication with server ends and the command thread is about to end..
        // used for calling visualizer stuff..
        super.finishedCommand();
    }
    
    protected void executeFailed(Exception exc) {
        // do refresh.. refresh or recursive refresh, depending on getRecursive()
        // TODO needs some optimizing..
        super.executeFailed(exc);
    }
    
    
    /**
     * Called when file status information has been received
     */
    public void fileInfoGenerated(FileInfoEvent e) {
        super.fileInfoGenerated(e);
    }
    
    /**
     * Compliant method to addWrapper. It replaces the whole list of cvswrappers.
     * The Map's structure should be following:
     *   Key: instance of StringPattern(fileName wildpattern)
     *   Value: instance of KeywordSubstitutionOptions
     */
    public void setWrappers(Map wrappeMap) {
        wrapperMap = wrappeMap;
    }
    
    /**
     * Returns a map with all wrappers.
     * For map descriptions see setWrapper()
     */
    public Map getWrappers() {
        return wrapperMap;
    }

    /**
     * Returns the keyword substitution option.
     */
    public KeywordSubstitutionOptions getKeywordSubstitutionOptions() {
        return keywordSubstitutionOptions;
    }

    /**
     * Sets the keywords substitution option.
     */
    public void setKeywordSubstitutionOptions(KeywordSubstitutionOptions keywordSubstitutionOptions) {
        this.keywordSubstitutionOptions = keywordSubstitutionOptions;
    }

    /**
     * Returns the release tag.
     */
    public String getReleaseTag() {
        return releaseTag;
    }

    /**
     * Sets the necessary release tag.
     */
    public void setReleaseTag(String releaseTag) {
        this.releaseTag = releaseTag;
    }

    /**
     * Returns the log message.
     */
    public String getLogMessage() {
        return logMessage;
    }

    /**
     * Sets the log message.
     */
    public void setLogMessage(String logMessage) {
        this.logMessage = logMessage;
    }

    /**
     * Returns the module (the in-repository path, where the files should be
     * stored.
     */
    public String getModule() {
        return module;
    }

    /**
     * Sets the module (the in-repository path, where the files should be
     * stored).
     */
    public void setModule(String module) {
        this.module = module;
    }

    /**
     * Returns the vendor branch.
     */
    public String getVendorBranch() {
        return vendorBranch;
    }


    /**
     * Sets the vendor branch.
     * If null is set, the default branch 1.1.1 is used automatically.
     */
    public void setVendorBranch(String vendorBranch) {
        this.vendorBranch = vendorBranch;
    }

    /**
     * Returns the vendor tag.
     */
    public String getVendorTag() {
        return vendorTag;
    }

    /**
     * Sets the necessary vendor tag.
     */
    public void setVendorTag(String vendorTag) {
        this.vendorTag = vendorTag;
    }
    
    /** Attempts to set it's properties by parsing the string parameter.
     * 
* If the switch is not identified, it's silently ignored. * To learn if all switches were set corrently, check the getCVSArguments() method. *
* For correct functionality of this method, the command needs to have * the getMainCvsCommand() method setup correctly. * * @param arguments Command's arguments as command-line switches. * */ public void parseCvsArguments(String arguments) { ImportCommand comm = (ImportCommand)loadCommand(getMainCvsCommand()); StringTokenizer tokens = new StringTokenizer(arguments, " \"", true); // NOI18N boolean withinString = false; LinkedList stringList = new LinkedList(); while (tokens.hasMoreTokens()) { String tok = tokens.nextToken(); if (tok.equals("\"")) { // NOI18N String param = ""; // NOI18N while (tokens.hasMoreTokens()) { String toke2 = tokens.nextToken(); if (toke2.equals("\"")) break; // NOI18N param = param + toke2; } stringList.add(param); } else { if (!tok.equals(" ")) { // NOI18N stringList.add(tok); } } } String[] args = new String[stringList.size()]; args = (String[])stringList.toArray(args); // 2. set the parameters to the command. comm.resetCVSCommand(); final String getOptString = comm.getOptString(); GetOpt go = new GetOpt(args, getOptString); int ch = -1; go.optIndexSet(0); // maybe should be set to another number go.optIndexSet(0); boolean usagePrint = false; String arg; while ((ch = go.getopt()) != go.optEOF) { // System.out.println("option=" + (char)ch + "arg=" + go.optArgGet()); boolean ok = comm.setCVSCommand((char)ch, go.optArgGet()); } int restArgsIndex = go.optIndexGet(); int gap = args.length - restArgsIndex; // test if we have been passed any file arguments if (gap > 0) { comm.setModule(args[restArgsIndex]); if (gap > 1) { comm.setVendorTag(args[restArgsIndex + 1]); if (gap > 2) { comm.setReleaseTag(args[restArgsIndex + 2]); } } } getCommandArguments(comm); } /** Returns the command's cvs switches in the follwoing format: [command's name] [switches]. *
Can be used for writing the Command to .cvsrc file where the default switches are stored. * Subclasses can override this to handle special cases like comit -m "multi-line-message" * * @return String consisting of command's name and arguments. */ public String getCvsrcEntry() { Command comm = loadCommand(getMainCvsCommand()); boolean ok = setCommandArguments(comm); if (ok) { return "import " + comm.getCVSArguments(); // NOI18N } return ""; } public class ImportImpl extends FsImport implements FileSystemCommandImpl { public ImportImpl() { } public FileSystemCommand getOuterClassInstance() { return CvsImport.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) { CvsImport.this.addDisplayerListener(listener); } /** 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 = CvsImport.super.clone(); return retValue; } /** Starts the thread with the command - executes the run() method. */ public void startCommand() { CvsImport.this.startCommand(); } /** 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) { CvsImport.this.removeDisplayerListener(listener); } public void setFileObjects(FileObject[] fileObjects) { CvsImport.this.setFileObjects(fileObjects); } /** Add a CommandErrorListener to the CvsCommand. * * @param commErrListener The listener to add. * */ public void addCommandErrorListener(org.netbeans.modules.javacvs.events.CommandErrorListener commErrListener) { CvsImport.this.addCommandErrorListener(commErrListener); } /** Remove a CommandErrorListener to the CvsCommand. * * @param commErrListener The listener to remove. * */ public void removeCommandErrorListener(org.netbeans.modules.javacvs.events.CommandErrorListener commErrListener) { CvsImport.this.removeCommandErrorListener(commErrListener); } /** * Compliant method to addWrapper. It replaces the whole list of cvswrappers. * The Map's structure should be following: * Key: instance of StringPattern(fileName wildpattern) * Value: instance of KeywordSubstitutionOptions */ public void setWrappers(Map wrapperMap) { CvsImport.this.setWrappers(wrapperMap); } /** * Sets the log message. */ public void setLogMessage(String logMessage) { CvsImport.this.setLogMessage(logMessage); } /** * Returns the module (the in-repository path, where the files should be * stored. */ public String getModule() { return CvsImport.this.getModule(); } /** * Sets the keywords substitution option. */ public void setKeywordSubstitutionOptions(KeywordSubstitutionOptions keywordSubstitutionOptions) { CvsImport.this.setKeywordSubstitutionOptions(keywordSubstitutionOptions); } /** * Sets the vendor branch. * If null is set, the default branch 1.1.1 is used automatically. */ public void setVendorBranch(String vendorBranch) { CvsImport.this.setVendorBranch(vendorBranch); } /** * Returns a map with all wrappers. * For map descriptions see setWrapper() */ public Map getWrappers() { return CvsImport.this.getWrappers(); } /** * Returns the vendor tag. */ public String getVendorTag() { return CvsImport.this.getVendorTag(); } /** * Returns the keyword substitution option. */ public KeywordSubstitutionOptions getKeywordSubstitutionOptions() { return CvsImport.this.getKeywordSubstitutionOptions(); } /** * Sets the necessary vendor tag. */ public void setVendorTag(String vendorTag) { CvsImport.this.setVendorTag(vendorTag); } /** * Returns the release tag. */ public String getReleaseTag() { return CvsImport.this.getReleaseTag(); } /** * Returns the vendor branch. */ public String getVendorBranch() { return CvsImport.this.getVendorBranch(); } /** * Sets the module (the in-repository path, where the files should be * stored). */ public void setModule(String module) { CvsImport.this.setModule(module); } /** * Returns the log message. */ public String getLogMessage() { return CvsImport.this.getLogMessage(); } /** * Sets the necessary release tag. */ public void setReleaseTag(String releaseTag) { CvsImport.this.setReleaseTag(releaseTag); } public FsGlobalOptions getGlobalOptions() { FsGlobalOptions retValue; retValue = new FsGlobalOptionsImpl(CvsImport.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.