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 java.io.File;
import org.netbeans.lib.cvsclient.command.Command;
import org.netbeans.lib.cvsclient.connection.Connection;
import org.netbeans.modules.javacvs.commands.*;
import java.lang.reflect.Method;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileSystem;
import org.netbeans.modules.javacvs.*;
import org.openide.util.NbBundle;
import org.netbeans.modules.javacvs.events.CommandDisplayerListener;
import java.beans.*;
import org.netbeans.lib.cvsclient.commandLine.GetOpt;
import org.netbeans.modules.javacvs.events.ServerErrorException;
import java.util.*;
import org.openide.ErrorManager;
import org.openide.cookies.SaveCookie;
import org.openide.loaders.DataObject;


/**
 * A general class that acts as wrapper around the library Commands.
 * Each fileSystemCommand is capable of executing 1 or more library commands in sequential order.
 * 
The correct working scheme with the FileSystem comamnd is following. *
1. create an instance. *
2.a setClientProvider and files(fileObjects) that the command will use. *
2.b set cvs switches for the command. *
2.c add CommandDisplayerListeners that will display the command's results and handle UI of error handling. *
3. start the command vi the startCommand() method. * * * @author mkleint */ public abstract class FileSystemCommand extends org.netbeans.lib.cvsclient.event.CVSAdapter implements Runnable, Cloneable { private java.util.LinkedList stdErrList; private java.util.LinkedList stdOutList; private Thread thread; /** instance of a Client object that is needed for execution of library commands. * */ protected org.netbeans.lib.cvsclient.Client libClient; /** Global options for the library commands. * */ protected org.netbeans.lib.cvsclient.command.GlobalOptions globalOptions; private org.netbeans.lib.cvsclient.event.EventManager eventManager; private boolean dispWasSet; private String root; private Command currCommand; private ArrayList errListeners; private boolean stopCommand; private File[] files; private Object[] paramOptions; private Object[] paramClosingOptions; private boolean defaultSettings; private boolean serverError = false; // vector of commands to run. From first to last. Needs to be set up in InitCommand /** queue of commands to be executed. During the run, this list is iterated and the commands are sequentially executed. * */ protected java.util.Vector toDoCommands; private boolean running; private ClientProvider provider; /** * Registered listeners for events. This is an array for performance when * firing events. We take the hit when adding or removing listeners - that * should be a relatively rare occurrence. */ private CommandDisplayerListener[] displayListeners; /** Creates new FileSystemCommand */ public FileSystemCommand() { initInternals(); initializeCommandList(); } /** Creates a new FileSystemCommand. * @param provider Object implementing the ClientProvider interface. * Each Filesystem object requires to have a ClientProvider in order to run. * */ public FileSystemCommand(ClientProvider provider) { this(); setClientProvider(provider); } /** prepares the internal properties for another run. To be used in CommandFactory */ private void initInternals() { setRunning(false); stopCommand = false; thread = null; serverError = false; setFiles(null); } /** 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 { FileSystemCommand com = (FileSystemCommand)super.clone(); com.initInternals(); // it's here to make the command ready for execution return com; } public CvsCommand getImpl() { return new CvsCommand(); } /** set the client provider for the to-be-executed FileSystemCommand. * In case the command is created with the constructor without parameters, it needs to be set before starting the command. * This is needed to provide the required enviroment for the execution of the commands. * * @param prov the ClientProvider to use. * */ public void setClientProvider(ClientProvider prov) { provider = prov; setGlobalOptions(provider.getGlobalOptions()); } /** 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) { files = fls; } /** set the files/dirs that the command operates on. * * @return array of files that are used by the commands. */ public File[] getFiles() { return files; } public void setFileObjects(FileObject[] fileObjects) { saveFiles(fileObjects); setFiles(convertFileObjects(fileObjects)); } /** Signals to the FileSystemCommand that it should stop.
* The command will no try to abort the undelying server communication and will wait for the next best moment. *
* this method is to be called from within the executeFailed() method (or others) * if you want to stop the command. (do not perform any other activity after the one where it's called) * */ public synchronized void stopCommand() { stopCommand = true; } /** Just like stopCommand(), however ties to abort the server/client communication. * The library takes care not to break in umconsistent state (like writing only 1/2 of a file to disk) * So it may take some time untill the command really stops. * */ public synchronized void hardCommandStop() { libClient.abort(); stopCommand = true; // needs to ne here?? } /** Indicates that the command was stopped. * * @return true is stopped. */ public synchronized boolean isStopped() { return stopCommand; } /** returns the client provider that was set for this FileSystemCommand. * @return ClientProvider that is used by the command. * */ public ClientProvider getClientProvider() { return provider; } /** Sets the Global options to the command. *
The global options object stores the data that equals the global switches of the cvs command. *
When setting a new Clientprovider,the Global options are automagically set from the ClientProvider. * @param glOpt New value of global options. */ public void setGlobalOptions(org.netbeans.lib.cvsclient.command.GlobalOptions glOpt) { globalOptions = glOpt; } /** Returns the current value of cvs global option for this command. * * @return Current instance of GlobalOptions */ public org.netbeans.lib.cvsclient.command.GlobalOptions getGlobalOptions() { return globalOptions; } private org.netbeans.lib.cvsclient.event.EventManager getEventManager() throws ClientCreationException { if (libClient == null) { libClient = createClient(); } return libClient.getEventManager(); } public synchronized boolean isRunning() { return running; } /** this method is to be called right BEFORE leaving the run() method */ private synchronized void setRunning(boolean run) { if (run == false) { if (errListeners != null) errListeners.clear(); if (displayListeners != null) { displayListeners = null; } if (libClient != null) { try { Connection conn = libClient.getConnection(); if (conn != null) { conn.close(); } } catch (java.io.IOException ex) {} libClient = null; } if (eventManager != null) { eventManager.removeCVSListener(this); eventManager = null; } if (toDoCommands != null) { toDoCommands.clear(); toDoCommands = null; } } running = run; } /** * Adds an item (generally a FileInfoContainer) the the command's resultList. */ // protected void addToResultList(Object item) { // resultList.add(item); // } /** * Returns a list with all the returned results. */ // protected java.util.List getResultList() { // return resultList; // } /** * Clears the result list of FileInfoContainers returned and parsed by the cvs client. */ // protected void clearResultList() { // resultList = new java.util.LinkedList(); // } protected Command getCurrentCommand() { return currCommand; } private void setCurrentCommand(Command comm) { currCommand = comm; } /** default way of getting instances of cvs commands for use in the FileSystemObjects */ protected Command loadCommand(Class type) { Command comm = null; try { comm = (Command)type.newInstance(); return comm; } catch (Exception exc2) { // System.out.println("error while creating library command"); } return comm; } /** Starts the thread with the command - executes the run() method. */ public void startCommand() { setRunning(true); //create thread thread = new Thread(this, "JavaCvsFileSystem.CVSCommand"); //NOI18N // register with the filesystems command stack // ?? thread.start(); } public abstract String getName(); protected void initializeCommandList() { toDoCommands = new java.util.Vector(2); } protected void clearCommandList() { toDoCommands.clear(); } /** This method is used for setting up the filesystem command. Here the queue of commands should be created, depending on the value of the properties. * Fires the StartDisplayerEvent * @param commandIsRunning True is called from within the run() method. Otherwise needs to be set to false. * */ protected void initCommand(boolean commandIsRunning) { fireDisplayerEvent(new org.netbeans.modules.javacvs.events.StartDisplayerEvent(this)); } /** This method is called when all commands in the queue were already successfully finished. *
* Fires the FinishDisplayerEvent */ protected void finishedCommand() { fireDisplayerEvent(new org.netbeans.modules.javacvs.events.FinishDisplayerEvent(this)); } /** Gets executed before the current command in queue gets executed. * To access that command use the getCurrentCommand() method * Fires the BeforeEachCommandDisplayerEvent */ protected void beforeEachExecute() { fireDisplayerEvent(new org.netbeans.modules.javacvs.events.BeforeEachCommandDisplayerEvent(this, getCurrentCommand())); } /** Gets executed after the current command in queue successfully finished. *
* Fires the AfterEachCommandDisplayerEvent * */ protected void afterEachExecute() { fireDisplayerEvent(new org.netbeans.modules.javacvs.events.AfterEachCommandDisplayerEvent(this)); } /** Will run only if any of the commands in the queue failed - for whatever reason. *
* Fires the FailedDisplayerEvent * * @param exc The exception that was thrown by the library. * */ protected void executeFailed(Exception exc) { fireDisplayerEvent(new org.netbeans.modules.javacvs.events.FailedDisplayerEvent(this, exc)); } /** when the library command's builder generates a FileInfoContainer object, * this method is run. *
* Fires a InfoGeneratedDisplayerEvent * @param e The FileInfoEvent generated by the builder. Includes the object holding the parsed data (FileInfoContainer) * */ public void fileInfoGenerated(org.netbeans.lib.cvsclient.event.FileInfoEvent e) { org.netbeans.lib.cvsclient.command.FileInfoContainer fInfo = e.getInfoContainer(); // if (fInfo != null) { // addToResultList(fInfo); // } fireDisplayerEvent(new org.netbeans.modules.javacvs.events.InfoGeneratedDisplayerEvent(this,fInfo)); } private org.netbeans.lib.cvsclient.Client createClient() throws ClientCreationException { ClientProvider prov = getClientProvider(); if (prov == null) { throw new ClientCreationException("", //NOI18N NbBundle.getBundle(FileSystemCommand.class).getString( "FileSystemCommand.noClientAvailable")); //NOI18N } return prov.createClient(prov.getCvsRootString()); } /** The main loop of the command. * Is executed in it's own thread. */ public void run() { // resultList = new java.util.LinkedList(); try { if (libClient == null) { libClient = createClient(); } eventManager = libClient.getEventManager(); } catch (ClientCreationException exc) { executeFailed(exc); fireCommandErrorListener(true); setRunning(false); return; } eventManager.addCVSListener(this); boolean finished = false; try { initCommand(true); if (isStopped()) { executeFailed(null); fireCommandErrorListener(true); setRunning(false); finished = true; return; } Iterator it = toDoCommands.iterator(); while (it.hasNext()) { Command comm = (Command)it.next(); setCurrentCommand(comm); beforeEachExecute(); if (isStopped()) { executeFailed(null); fireCommandErrorListener(true); setRunning(false); finished = true; return; } //-- main part of loop ------------------------------------------------------------- try { provider.openConnection(libClient, provider.getCvsRootString()); libClient.executeCommand(comm,globalOptions); libClient.getConnection().close(); if (serverError) { throw new ServerErrorException(); } //---------------------------------------------------------------------------------- } catch (Exception exc) { executeFailed(exc); fireCommandErrorListener(true); stopCommand(); setRunning(false); finished = true; return; } afterEachExecute(); if (isStopped()) { executeFailed(null); fireCommandErrorListener(true); setRunning(false); finished = true; return; } } // fireCommandErrorListener(serverError); } finally { if (!finished) { finishedCommand(); setRunning(false); } } } public void addCommandErrorListener(org.netbeans.modules.javacvs.events.CommandErrorListener commErrListener) { if (errListeners == null) { errListeners = new ArrayList (); } errListeners.add (commErrListener); } public void removeCommandErrorListener(org.netbeans.modules.javacvs.events.CommandErrorListener commErrListener) { if (errListeners != null) { errListeners.remove (commErrListener); } } private void fireCommandErrorListener(boolean wasError) { ArrayList list; synchronized (this) { if (errListeners == null) return; list = (ArrayList) this.errListeners.clone(); } org.netbeans.modules.javacvs.events.CommandErrorEvent event = new org.netbeans.modules.javacvs.events.CommandErrorEvent(this, wasError); for (int i=0; i * Fires a MessageGeneratedDisplayerEvent * @param e The undelying MessageEvent */ public void messageSent(org.netbeans.lib.cvsclient.event.MessageEvent e) { fireDisplayerEvent(new org.netbeans.modules.javacvs.events.MessageGeneratedDisplayerEvent(this, e)); } /** 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 synchronized void addDisplayerListener(CommandDisplayerListener listener) { if (displayListeners==null || displayListeners.length==0) { displayListeners = new CommandDisplayerListener[1]; } else { // allocate a new array and copy existing listeners CommandDisplayerListener[] l = new CommandDisplayerListener[displayListeners.length+1]; for (int i=0; i < displayListeners.length; i++) { l[i] = displayListeners[i]; } displayListeners = l; } displayListeners[displayListeners.length-1] = listener; } /** Removes a CommandDisplayerListener from the FilesystemCommand. * All the listeners are removed once the command ends. * * @param listener the listener to remove */ public synchronized void removeDisplayerListener(CommandDisplayerListener listener) { // TODO: test this method!! if (displayListeners.length==1) { displayListeners = null; } else { CommandDisplayerListener[] l = new CommandDisplayerListener[displayListeners.length-1]; int i=0; while (i < l.length) { if (displayListeners[i] == listener) { for (int j=i+1; j < displayListeners.length; j++) { l[j-1] = displayListeners[j]; } break; } else { l[i] = displayListeners[i]; } i++; } displayListeners = l; } } /** * Fire a CVSEvent to all the listeners * @param e the event to send */ private void fireDisplayerEvent(org.netbeans.modules.javacvs.events.CommandDisplayerEvent event) { // if we have no listeners, then there is nothing to do if (displayListeners==null || displayListeners.length==0) return; CommandDisplayerListener[] l = null; synchronized(displayListeners) { l = new CommandDisplayerListener[displayListeners.length]; System.arraycopy(displayListeners, 0, l, 0, l.length); } for (int i=0; i < l.length; i++) { event.fireEvent(l[i]); } } /** Sets the cvs switches from the FileSystemCommand to the undelying library command. *
* The algorithm is following:

* For the FileSystem subclass, it reads the BeanDesriptor and gets all the properties.

* It considers these to be the cvs switches.

* It iterates through the properties and tries to find a setter in the library command, * that equals the setter/getter in the FileSystemCommand. If such match is found, it sets * the value to the library command. * * @param command the library command to be set. * @return true if everything succeeded. * */ public boolean setCommandArguments(Command command) { boolean ok = true; java.beans.BeanInfo info = null; try { info = java.beans.Introspector.getBeanInfo(getImpl().getClass()); } catch (java.beans.IntrospectionException exc) { return false; } if (info != null) { java.beans.PropertyDescriptor[] desc = info.getPropertyDescriptors(); for (int i = 0; i < desc.length; i++) { java.beans.PropertyDescriptor descriptor = desc[i]; Method beanGetter = descriptor.getReadMethod(); Method beanSetter = descriptor.getWriteMethod(); Method commandSetter = null; // System.out.println("GetCommandArguments =" + descriptor.getName()); // System.out.println("set=" + beanSetter); // System.out.println("get=" + beanGetter); Object value = null; try { commandSetter = command.getClass().getMethod( beanSetter.getName(), beanSetter.getParameterTypes()); value = beanGetter.invoke(getImpl(), null); if (commandSetter != null) { commandSetter.invoke(command, new Object[] {value}); } } catch (Exception e) { // the exception should nto be thrown is everything is set up correctly. // the only exception is the AddCommand's recursive property // this one is not present in library, so the exception is intentional. ok = false; /* System.out.println("command's class=" + command.getClass()); System.out.print("methods="); Method[] methods = command.getClass().getMethods(); for (int i2 = 0; i2 < methods.length; i2++) { System.out.print(methods[i2].getName() + ","); } System.out.println(""); System.out.println("beansetter=" + beanSetter.getName()); System.out.println("beangetter=" + beanGetter.getName()); System.out.println("commandSetter=" + commandSetter); System.out.println("value=" + value); */ // continue; } } } return ok; } /** Sets the cvs switches from the library command to the FIleSystemCommand. *
* For the algorithm, see setCommandArguments(Command). * @param command the library command that is used to set the cvs switches to the FileSystemCommand. * @return true if everything succeeded. */ public boolean getCommandArguments(Command command) { boolean ok = true; java.beans.BeanInfo info = null; try { info = java.beans.Introspector.getBeanInfo(getImpl().getClass()); // System.out.println("trida=" + getClass().getName()); // System.out.println("class=" + getImpl().getClass().getName()); // System.out.println("beandesc=" + info.getBeanDescriptor().getDisplayName()); } catch (IntrospectionException exc) { return false; } if (info != null) { PropertyDescriptor[] desc = info.getPropertyDescriptors(); for (int i = 0; i < desc.length; i++) { java.beans.PropertyDescriptor descriptor = desc[i]; Method beanGetter = descriptor.getReadMethod(); Method beanSetter = descriptor.getWriteMethod(); // System.out.println("GetCommandArguments =" + descriptor.getName()); // System.out.println("set=" + beanSetter); // System.out.println("get=" + beanGetter); Method commandGetter = null; try { commandGetter = command.getClass().getMethod( beanGetter.getName(), beanGetter.getParameterTypes()); Object value = commandGetter.invoke(command, null); beanSetter.invoke(getImpl(), new Object[] {value}); } catch (Exception e) { // System.out.println("not invoked=" + beanGetter.getName()); // e.printStackTrace(); ok = false; // continue; } } } return ok; } /** Needs to return a correct org.netbeans.lib.cvsclient.command.Command.java subclass. *
Is crutial for correct functionality of the parseCvsArguments(String) method. * @return Should return any subclass of org.netbeans.lib.cvsclient.command.Command.java subclass that is a cvs command. * */ protected abstract Class getMainCvsCommand(); /** Returns the cvs command's switches as a String. * * @return String representation of the Command's cvs switches. */ public String getCVSArguments() { Command comm = loadCommand(getMainCvsCommand()); boolean ok = setCommandArguments(comm); return comm.getCVSArguments(); } /** Returns the cvs command's name, switches and other arguments as a String. * Does not include files... * * @return String representation of the Command's cvs command */ public String getCVSCommand() { Command comm = loadCommand(getMainCvsCommand()); boolean ok = setCommandArguments(comm); return comm.getCVSCommand(); } /** After running this method you can be sure that all cvs switches are cleared.
* Resets all properties that are considered cvs switches. */ public void clearAllSwitches() { Command comm = loadCommand(getMainCvsCommand()); comm.resetCVSCommand(); getCommandArguments(comm); } public boolean copySwitchesFrom(FileSystemCommand com) { boolean ok = false; if (!com.getClass().equals(getClass())) { return ok; } Command comm = loadCommand(getMainCvsCommand()); ok = com.setCommandArguments(comm); if (!ok) { return ok; } ok = getCommandArguments(comm); return ok; } /** Displays what cvs commands will be run and with what switches.
* Since the FileSystemCommand can consist of more then 1 library cvs command, * the cvs commands are separated by newline.
* Filename/directory names in the commands are only symbolic, with no path. * (The actual path of the files is not displayed.) *
WARNING: Not to be called when command is running.. * @return String representation of the FileSystemCommand. */ public String getCVSEquivalent() { if (isRunning()) return ""; //NOI18N initCommand(false); StringBuffer buff = new StringBuffer(); Iterator it = toDoCommands.iterator(); while (it.hasNext()) { Command comm = (Command)it.next(); buff.append("cvs " + getGlobalOptions().getCVSCommand() + " "); //NOI18N String commandMess = comm.getCVSCommand(); commandMess = commandMess.replace('\n', ' '); buff.append(commandMess + "\n"); //NOI18N } clearCommandList(); return buff.toString(); } /** 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 comm.getCVSCommand(); } return ""; //NOI18N } /** 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) { Command comm = 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()); } getCommandArguments(comm); } /** * Save the files. This is strongly recommended before a command is executed. * @params fileObjects The array of FileObjects */ private void saveFiles(FileObject[] fileObjects) { if (fileObjects == null) return ; Collection folders = new LinkedList(); boolean wasSaved = false; for (int i = 0; i < fileObjects.length; i++) { org.openide.loaders.DataObject dobj = null; try { dobj = org.openide.loaders.DataObject.find(fileObjects[i]); } catch (org.openide.loaders.DataObjectNotFoundException exc) { // ignored } if (fileObjects[i].isFolder()) { folders.add(fileObjects[i]); } if (dobj != null && dobj.isModified()) { org.openide.nodes.Node.Cookie cake = dobj.getCookie(org.openide.cookies.SaveCookie.class); try { if (cake != null) { ((org.openide.cookies.SaveCookie) cake).save(); wasSaved = true; } } catch (java.io.IOException exc) { ErrorManager.getDefault().notify(exc); } } } if (!folders.isEmpty()) { DataObject[] modified = DataObject.getRegistry().getModified(); for (int i = 0; i < modified.length; i++) { DataObject dobj = modified[i]; SaveCookie sc = (SaveCookie) dobj.getCookie(SaveCookie.class); if (sc != null) { Set files = dobj.files(); if (isAFileInAFolder(folders, files)) { try { sc.save(); wasSaved = true; } catch (java.io.IOException exc) { ErrorManager.getDefault().notify(exc); } } } } } if (wasSaved) { // If we saved some data, we need to wait at least one second. // This will assure, that any further command, that will modify // the conent of a saved file will actually change the modification // time (time resolution is ~1s). See issue #36065 for details. try { Thread.currentThread().sleep(1000); } catch (InterruptedException iex) {} } } private static boolean isAFileInAFolder(Collection foldersCollection, Collection filesCollection) { boolean isIn = false; FileObject[] folders = (FileObject[]) foldersCollection.toArray(new FileObject[foldersCollection.size()]); FileObject[] files = (FileObject[]) filesCollection.toArray(new FileObject[filesCollection.size()]); boolean canBeIn = true; while (!isIn && canBeIn) { canBeIn = false; for (int i = 0; i < folders.length && !isIn; i++) { for (int j = 0; j < files.length; j++) { if (files[j] == null) continue; files[j] = files[j].getParent(); if (files[j] == null) continue; if (folders[i].equals(files[j])) { isIn = true; break; } else { if (files[j].getPath().startsWith(folders[i].getPath())) { canBeIn = true; } } } } } return isIn; } /** Converts from String fs-related representation of a file (path+name) * to absolute representation in File objects. */ protected File[] convertFileObjects(FileObject[] fileObjects) { // D.deb("getFiles() START"); if (fileObjects == null) return null; File[] files = new File[fileObjects.length]; for (int index = 0; index < fileObjects.length; index++) { FileObject fo = fileObjects[index]; File file = toFile(fo); if (file != null) { files[index] = file; } } return files; } /** That takes one file object and tries to convert it into local file. * The conversion can succeed only if the file object's file system * supports work with FileSystem.Environment. * * @param fo file object to convert * @return java.io.File for that file object */ public static java.io.File toFile (FileObject fo) { final String pne = fo.getPackageNameExt(File.separatorChar, '.'); final class Env extends FileSystem.Environment { /** the file found or null */ public File found; /** the file suggested or null */ //public File suggest; /* method of interface Environment */ public void addClassPath(String element) { if (found != null) { // file found, ignore the rest return; } File p = new File (element); if (! p.isDirectory ()) { // JAR entry, for example: return; } File f = new File (p, pne); found = f; } } Env env = new Env (); try { fo.getFileSystem ().prepareEnvironment(env); return env.found; } catch (java.io.IOException ex) { return null; } } /** * 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); serverError = e.isError(); } }

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