|
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.cvsclient;
import org.netbeans.modules.cvsclient.caching.NbCvsFsCache;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.NotActiveException;
import java.text.MessageFormat;
import org.netbeans.modules.javacvs.util.Debug;
import org.netbeans.lib.cvsclient.file.FileStatus;
import org.netbeans.lib.cvsclient.command.*;
import org.netbeans.lib.cvsclient.command.status.*;
import org.netbeans.lib.cvsclient.command.log.*;
import org.netbeans.lib.cvsclient.connection.AuthenticationException;
import org.netbeans.lib.cvsclient.util.*;
import org.openide.filesystems.DefaultAttributes;
import org.openide.filesystems.AbstractFileSystem;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.FileStateInvalidException;
import org.openide.windows.Workspace;
import org.openide.windows.Mode;
import org.openide.loaders.*;
import org.openide.nodes.Node;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileSystemCapability;
import org.openide.*;
import org.openide.util.*;
import org.netbeans.modules.javacvs.caching.*;
import org.netbeans.modules.javacvs.events.*;
import org.netbeans.modules.javacvs.*;
import org.netbeans.modules.javacvs.commands.JavaCvsCommandFactory;
import org.netbeans.modules.javacvs.commands.*;
import org.netbeans.modules.cvsclient.JavaCvsRuntimeCommandsProvider;
import org.netbeans.modules.cvsclient.actions.*;
import org.netbeans.modules.cvsclient.caching.*;
import org.netbeans.modules.cvsclient.versioning.*;
import org.netbeans.modules.cvsclient.commands.ErrorLogPanel;
import org.netbeans.modules.cvsclient.commands.CommandLineParamInput;
import org.netbeans.modules.cvsclient.commands.JavaCvsRuntimeCommand;
import org.netbeans.modules.cvsclient.commands.checkout.ModulesListPanel;
import org.netbeans.modules.cvsclient.commands.checkout.NbCheckoutParamInput;
import org.netbeans.modules.cvsclient.commands.commit.NbSimpleCommitParamInput;
import org.netbeans.modules.cvsclient.commands.tag.NbSimpleTagParamInput;
//import org.netbeans.modules.cvsclient.commands.log.RevisionExplorerInfo;
import org.netbeans.modules.javacvs.passwd.PasswdEntry;
import org.netbeans.modules.javacvs.passwd.CVSPasswd;
// override java.io.FileSystem
import org.openide.util.actions.SystemAction;
import org.netbeans.modules.vcscore.actions.*;
import org.netbeans.modules.vcscore.annotation.AnnotationProvider;
import org.netbeans.modules.vcscore.cache.*;
import org.netbeans.modules.vcscore.search.VcsSearchTypeFileSystem;
import org.netbeans.modules.vcscore.versioning.*;
import org.netbeans.modules.vcscore.VcsAttributes;
import org.netbeans.modules.vcscore.commands.VcsCommand;
import org.netbeans.modules.vcscore.settings.*;
import org.netbeans.modules.vcscore.runtime.*;
import org.netbeans.modules.vcscore.util.virtuals.VirtualsDataLoader;
import org.netbeans.modules.vcscore.util.virtuals.VcsRefreshRequest;
import org.netbeans.modules.vcscore.util.virtuals.VirtualsRefreshing;
import org.netbeans.modules.vcscore.grouping.*;
import org.netbeans.modules.vcscore.actions.*;
import java.lang.ref.Reference;
import java.util.*;
import java.beans.FeatureDescriptor;
import java.awt.Rectangle;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import org.openide.DialogDisplayer;
import org.openide.ErrorManager;
/** A file system.
*
* @author mkleint
*/
public class NbJavaCvsFileSystem extends org.netbeans.modules.javacvs.JavaCvsFileSystem
implements VcsSearchTypeFileSystem, VirtualsRefreshing {
static final long serialVersionUID = 7883103611633487336L;
private transient Debug E=new Debug("JavaCvsFileSystem", false); // NOI18N
private transient Debug D=E; //transient??
/** refresher */
private transient VcsRefreshRequest refresher;
public static final String JAVACVS_MODE = "JavaCvsFileSystem.mode"; // NOI18N
// public static final String JAVACVS_NATIVE_FS = "JavaCvsFileSystemAttributeIdentifier"; //NOI18N
// public static final String JAVACVS_NATIVE_PACKAGE_NAME_EXT = "JAvaCvsFileSystemNativeFOPath"; //NOI18N
public static final String PROP_USER_INTERFACE_MODE = "uiMode"; // NOI18N
public static final String PROP_DISPLAY_TYPE = "displayType"; // NOI18N
public static final String PROP_PROCESS_ALL_FILES = "processAllFiles"; //NOI18N
public static final int MODE_NOVICE = 0;
public static final int MODE_ADVANCED = 1;
public static final int MODE_COMMAND_LINE = 2;
public static final int DISP_TYPE_SIMPLE = 0;
public static final int DISP_TYPE_FORMATTED = 1;
public static final int DISP_TYPE_LIMITED = 2;
// properties
private int uiMode = 0;
private int displayType = 1;
/** Holds value of property processAllFiles. */
private boolean processAllFiles = false;
private transient JavaCvsVersioningSystem versioningSystem;
private transient Object versioningSystemAccessLock = new Object();
// due to vcscore's cvs mount wizard.
private boolean initialCheckout = false;
//---
private String oldFsSystemName;
private Integer numberOfFinishedCmdsToCollect = new Integer(RuntimeFolderNode.DEFAULT_NUM_OF_FINISHED_CMDS_TO_COLLECT);
private Boolean versioningFileSystemShowMessage = null;
private Integer versioningFileSystemMessageLength = null;
private String versioningFileSystemIgnoreFiles = null;
public NbJavaCvsFileSystem() {
// Create and use implementations of file system functionality:
super();
info = new NbInfoImpl();
list = new NbListImpl();
JavaCvsAttributes defAttr = new JavaCvsAttributes(info, change, list , FsCommandFactory.getFsInstance().getSupporter());
defAttr.setRuntimeProvider(new JavaCvsRuntimeCommandsProvider(this));
attr = defAttr;
list = defAttr;
// load defaults from the Settings object
// cache = new CvsFsCache(this);
// initCache();
JavaCvsSettings settings = (JavaCvsSettings)SharedClassObject.findObject(
JavaCvsSettings.class, true);
setOffLine(settings.isOffLine());
setUiMode(settings.getUiMode());
setAutoRefresh(settings.getAutoRefresh());
setDisplayType(settings.getDisplayType());
setHideShadowFiles(settings.isHideShadowFiles());
setProcessAllFiles(false);
setHomeDirectory(settings.getHome());
dependantInit();
}
public NbJavaCvsFileSystem(FileSystemCapability cap) {
this ();
setCapability (cap);
}
public JavaCvsAttributes getVcsAttributes() {
return (JavaCvsAttributes) attr;
}
protected void initCache() {
CacheHandler handler = CacheHandler.getInstance();
JavaCvsCache cache = (JavaCvsCache)handler.getCache(JavaCvsCache.JAVA_CACHE_NAME);
if (cache == null) {
cache = new JavaCvsCache();
handler.registerCacheType(JavaCvsCache.JAVA_CACHE_NAME, cache);
}
super.initCache();
}
private transient PropertyChangeListener settingsChangeList;
protected void dependantInit() {
if (this.getClass().equals(NbJavaCvsFileSystem.class) ||
this.getClass().equals(org.netbeans.modules.cvsclient.JavaCvsFileSystem.class)) {
settingsChangeList = new PropertyChangeListener() {
public void propertyChange(final PropertyChangeEvent event) {
settingsChanged(event.getPropertyName(), event.getOldValue(), event.getNewValue());
}
};
JavaCvsSettings settings = (JavaCvsSettings)SharedClassObject.findObject(
JavaCvsSettings.class, true);
settings.addPropertyChangeListener(WeakListener.propertyChange(settingsChangeList, settings));
// setHomeDirectory(settings.getHome());
// initCache();
if (cache == null) {
cache = new NbCvsFsCache(this, getHomeDirectory());
}
// init cache..
// to addNotify setVcsRefreshTime(REFRESH_TIME);
cache.setAutoRefresh(getAutoRefresh());
cache.setHideShadowFiles(isHideShadowFiles());
cache.setOffLine(isOffLine());
cache.setFsRootFile(new File(constructRootDirectory()));
oldFsSystemName = getSystemName();
// status = new MyStatus();
// globalOptions = new GlobalOptions();
// globalOptions.setCVSRoot(getCvsRootString());
if (numberOfFinishedCmdsToCollect == null) {
numberOfFinishedCmdsToCollect = new Integer(RuntimeFolderNode.DEFAULT_NUM_OF_FINISHED_CMDS_TO_COLLECT);
}
}
}
public void adjustSystemName() {
org.openide.filesystems.Repository repos = org.openide.filesystems.Repository.getDefault();
boolean ok = false;
int seed = 0;
while (!ok) {
ok = true;
String mySystemName = computeSystemName(getRootDirectory(), seed);
Enumeration enum = repos.getFileSystems();
while (enum.hasMoreElements()) {
org.openide.filesystems.FileSystem fs = (org.openide.filesystems.FileSystem)enum.nextElement();
if (fs.getSystemName().equals(mySystemName)) {
ok = false;
seed = seed + 1;
break;
}
}
}
try {
setSystemName(computeSystemName(getRootDirectory(), seed));
} catch (java.beans.PropertyVetoException exc) {
ErrorManager.getDefault().notify(ErrorManager.WARNING, exc);
// should not happen at all..
}
}
// --------- NAMING AND PROPERTIES ---------
public AbstractFileSystem.Info getVcsInfo() {
return info;
}
public JavaCvsCommandFactory getCommandFactory() {
return FsCommandFactory.getInstance();
}
public int getNumberOfFinishedCmdsToCollect() {
return numberOfFinishedCmdsToCollect.intValue();
}
public void setNumberOfFinishedCmdsToCollect(int numberOfFinishedCmdsToCollect) {
this.numberOfFinishedCmdsToCollect = new Integer(numberOfFinishedCmdsToCollect);
firePropertyChange(RuntimeFolderNode.PROPERTY_NUM_OF_FINISHED_CMDS_TO_COLLECT,
null, this.numberOfFinishedCmdsToCollect);
}
//Bean getter
public int getUiMode() {
return uiMode;
}
//bean setter
public void setUiMode(int newMode) {
if (newMode != uiMode) {
int oldMode = uiMode;
uiMode = newMode;
firePropertyChange (PROP_USER_INTERFACE_MODE, new Integer(oldMode), new Integer(uiMode));
// D.deb("setUiMode", "new uiMode=" + uiMode);
}
}
/** Getter for property displayType.
* @return Value of property displayType.
*/
public int getDisplayType() {
return displayType;
}
/** Setter for property displayType.
* @param displayType New value of property displayType.
*/
public void setDisplayType(int newType) {
if (newType != displayType) {
int oldType = displayType;
displayType = newType;
firePropertyChange (PROP_DISPLAY_TYPE, new Integer(oldType), new Integer(displayType));
}
}
/** if true, the cvs commands will get all fileobjects in the node.
* if false, onthe the fileobjects that are marked important are being processed.
*/
public boolean isProcessAllFiles() {
return this.processAllFiles;
}
/** if true, the cvs commands will get all fileobjects in the node.
* if false, onthe the fileobjects that are marked important are being processed.
*/
public void setProcessAllFiles(boolean processAllFiles) {
if (processAllFiles != this.processAllFiles) {
this.processAllFiles = processAllFiles;
firePropertyChange (PROP_PROCESS_ALL_FILES, !processAllFiles ? Boolean.TRUE : Boolean.FALSE, processAllFiles ? Boolean.TRUE : Boolean.FALSE);
}
}
public String getStatus(DataObject dObj) {
Set files = dObj.files();
Object[] oo = files.toArray();
int len = oo.length;
if (len == 0) return null;
for (int i = 0; i < len; i++) {
oo[i] = convertForeignFileObjectToMyFileObject((FileObject) oo[i]);
}
if (len == 1) {
String status = NbJavaCvsStatusManager.getInstance().getStatus(cache.getFileStatusOnly(getImportantFiles(oo)).trim());
// HACK??
return status;
}
else {
String status = NbJavaCvsStatusManager.getInstance().getStatus(cache.getFileStatusOnly(getImportantFiles(oo)));;
return status;
}
}
/**
* Get states of all important files inside the DataObject. To get the status,
* wait for the status reader command if necessary.
*/
public String[] getStates(DataObject dObj) {
Set files = dObj.files();
Object[] oo = files.toArray();
int len = oo.length;
if (len == 0) return new String[0];
for (int i = 0; i < len; i++) {
oo[i] = convertForeignFileObjectToMyFileObject((FileObject) oo[i]);
}
Vector ifiles = getImportantFiles(oo);
String[] states = new String[ifiles.size()];
for (int i = 0; i < states.length; i++) {
states[i] = NbJavaCvsStatusManager.getInstance().getStatus(cache.getFileStatusOnly((String) ifiles.get(i)).trim());
}
return states;
}
/** Converts a FileObject from a different file system (usually
* a multifilesystem which I'm a part of) to a FileObject from my (this)
* filesystem. */
private FileObject convertForeignFileObjectToMyFileObject(FileObject fo) {
FileSystem fs = null;
try {
fs = fo.getFileSystem();
} catch (FileStateInvalidException fsiex) {}
if (fs != null) {
if (!this.equals(fs)) {
java.io.File file = org.openide.filesystems.FileUtil.toFile(fo);
if (file != null) {
String filePath = file.getAbsolutePath().replace(java.io.File.separatorChar, '/');
java.io.File root = org.openide.filesystems.FileUtil.toFile(this.getRoot());
String rootPath = root.getAbsolutePath().replace(java.io.File.separatorChar, '/');
if (filePath.startsWith(rootPath)) {
String foPath = filePath.substring(rootPath.length());
while (foPath.startsWith("/")) foPath = foPath.substring(1);
fo = findResource(foPath);
}
}
}
}
return fo;
}
/** VcsSearchTypeFileSystem interface stuff */
/** It should return all possible VCS states in which the files in the filesystem
* can reside.
*/
public String[] getPossibleFileStatuses() {
return NbJavaCvsStatusManager.getInstance().getAllStates();
}
protected JavaCvsStatusManager getStatusManager() {
return NbJavaCvsStatusManager.getInstance();
}
// Filesystem-specific actions, such as version-control operations.
// The actions should typically be CookieActions looking for DataObject
// cookies, where the object's primary file is on this type of file system.
public SystemAction[] getActions() {
SystemAction[] actions = new SystemAction[3];
CollectingAction cvsAction = (CollectingAction)SharedClassObject.findObject(CollectingAction.class, true);
actions[0] = cvsAction;
actions[2] = (AddToGroupAction)SharedClassObject.findObject(AddToGroupAction.class, true);
/* JRevisionExplorerCommandAction act = (JRevisionExplorerCommandAction)SharedClassObject.findObject(JRevisionExplorerCommandAction.class, true);
act.delegateToAbstractAction(false);
actions[1] = act;
*/
actions[1] = (VersioningExplorerAction)SharedClassObject.findObject(VersioningExplorerAction.class, true);
// actions[1] = (org.netbeans.modules.cvsclient.actions.JCvsClientCommandAction)SharedClassObject.findObject(org.netbeans.modules.cvsclient.actions.JCvsClientCommandAction.class, true);
return actions;
}
/**
* Get the VCS actions on a collection of FileObject s.
* @param fos the collection of FileObject s to act on.
* @return the actions retrieved from VcsFactory.getActions(fos)
*/
public SystemAction[] getActions(Set fos) {
SystemAction[] actions = new SystemAction[3];
CollectingAction cvsAction2 = (CollectingAction)SharedClassObject.findObject(CollectingAction.class, true);
// cvsAction2.setFileSystem(this);
// cvsAction2.setSelectedFileObjects(fos);
actions[0] = cvsAction2;
/* JRevisionExplorerCommandAction act = (JRevisionExplorerCommandAction)SharedClassObject.findObject(JRevisionExplorerCommandAction.class, true);
act.delegateToAbstractAction(false);
actions[1] = act;
*/
actions[2] = (AddToGroupAction)SharedClassObject.findObject(AddToGroupAction.class, true);
// actions[1] = (org.netbeans.modules.cvsclient.actions.JCvsClientCommandAction)SharedClassObject.findObject(org.netbeans.modules.cvsclient.actions.JCvsClientCommandAction.class, true);
actions[1] = (VersioningExplorerAction)SharedClassObject.findObject(VersioningExplorerAction.class, true);
return actions;
}
private JavaCvsVersioningSystem createVersioningSystem(boolean [] created) {
synchronized (versioningSystemAccessLock) {
if (created[0] = (versioningSystem == null)) {
versioningSystem = new JavaCvsVersioningSystem(NbJavaCvsFileSystem.this, NbJavaCvsFileSystem.this.cache);
VersioningRepository.getRepository().addVersioningFileSystem(versioningSystem);
}
return versioningSystem;
}
}
private JavaCvsVersioningSystem getVersioningSystem() {
synchronized (versioningSystemAccessLock) {
return versioningSystem;
}
}
private void removeVersioningSystem() {
synchronized (versioningSystemAccessLock) {
if (versioningSystem != null) {
VersioningRepository.getRepository().removeVersioningFileSystem(versioningSystem);
}
versioningSystem = null;
}
}
public void saveVersioningFileSystemProperties(String propName, Object newValue) {
if (propName.equals(JavaCvsVersioningSystem.PROP_MESSAGE_LENGTH)) {
versioningFileSystemMessageLength = (Integer)newValue;
} else if (propName.equals(JavaCvsVersioningSystem.PROP_SHOW_MESSAGES)) {
versioningFileSystemShowMessage = (Boolean)newValue;
} else if (propName.equals(JavaCvsVersioningSystem.PROP_IGNORE_FILES)) {
versioningFileSystemIgnoreFiles = (String)newValue;
}
firePropertyChange(propName, null, newValue);
}
protected void handleDelete(String name) {
addParentToRefresher(name);
}
private void addParentToRefresher(String name) {
int lastIndex = name.lastIndexOf('/');
String parent;
if (lastIndex > 0) {
parent = name.substring(0, lastIndex);
} else {
parent = "";
}
if (refresher != null) {
refresher.addPrefferedFolder(parent);
}
}
protected void handleRename(String oldName, String newName) {
cache.fileModified(getFile(newName), false);
addParentToRefresher(oldName);
}
// ----------- IMPLEMENTATIONS OF ABSTRACT FUNCTIONALITY ----------
// Information about files and operations on the contents which do
// not affect the file's presence or name.
// MK: no changes needed for javacvs in order the interface to be functional..
protected class NbInfoImpl extends InfoImpl {
static final long serialVersionUID = -7503287378756255278L;
public InputStream inputStream (String name) throws FileNotFoundException {
//D.deb("inputStream("+name+")"); // NOI18N
InputStream in = null;
try {
in = new FileInputStream (getFile (name));
} catch (java.io.FileNotFoundException exc) {
final String fname = name;
throw (java.io.FileNotFoundException) ErrorManager.getDefault().annotate(
new java.io.FileNotFoundException() {
public String getLocalizedMessage() {
return MessageFormat.format (NbBundle.getBundle(NbJavaCvsFileSystem.class).getString("MSG_FileNotExist"), new Object[] { fname }); // NOI18N
}
}, MessageFormat.format (NbBundle.getBundle(NbJavaCvsFileSystem.class).getString("MSG_FileNotExist"), new Object[] { fname })); // NOI18N
}
return in;
}
public OutputStream outputStream(String name) throws IOException {
VcsGroupSettings grSettings = (VcsGroupSettings)SharedClassObject.findObject(VcsGroupSettings.class, true);
if (!grSettings.isDisableGroups()) {
if (grSettings.getAutoAddition() == VcsGroupSettings.ADDITION_TO_DEFAULT
|| grSettings.getAutoAddition() == VcsGroupSettings.ADDITION_ASK) {
FileObject fo = NbJavaCvsFileSystem.this.findResource(name);
// System.out.println("stream for=" + name);
if (fo != null) {
synchronized (this) {
try {
DataObject dobj = DataObject.find(fo);
if (NbJavaCvsFileSystem.this.isImportant(name)) {
// System.out.println("do=" + dobj.getName() + " " + dobj.getClass().getName());
DataShadow shadow = GroupUtils.findDOInGroups(dobj);
if (shadow == null) {
// it doesn't exist in groups, add it..
if (grSettings.getAutoAddition() == VcsGroupSettings.ADDITION_ASK) {
AddToGroupDialog.openChooseDialog(dobj);
} else {
GroupUtils.addToDefaultGroup(new Node[] {dobj.getNodeDelegate()});
}
}
}
} catch (DataObjectNotFoundException exc) {
}
}
}
}
}
OutputStream retValue;
retValue = super.outputStream(name);
if (isCreateBackups()) {
addParentToRefresher(name);
}
return retValue;
}
}
public class NbListImpl extends ListImpl {
private static final long serialVersionUID = -6002001971220606463L;
public String[] children (String name) {
String[] toReturn = super.children(name);
JavaCvsVersioningSystem versioningSystem = getVersioningSystem();
if (versioningSystem != null) {
FileObject fo = versioningSystem.findExistingResource(name);
if (fo != null) {
fo.refresh();
}
}
/* if (toReturn != null && toReturn.length != 0) {
HashMap removedFilesScheduledForRemove = new HashMap();
toReturn = filterScheduledSecondaryFiles(name, toReturn, removedFilesScheduledForRemove);
}
*/
return toReturn;
}
}
/** itility method used from within the RuntimeMainChildren object to force the writing of the Runtime node's property within the filesystem.
* the runtime nodes don't get serialized normally..
*/
public void numOfFinishedCmdsToCollectChanged() {
firePropertyChange(org.netbeans.modules.vcscore.runtime.RuntimeFolderNode.PROPERTY_NUM_OF_FINISHED_CMDS_TO_COLLECT, null, null);
}
//------------------------------------------------------------------------------
// ---------------- serialization stuff
//-------------------------------------------
private void readObject(ObjectInputStream in) throws
ClassNotFoundException, IOException, NotActiveException{
// cache is transient
// cache = new CvsFsCache(this);
in.defaultReadObject();
versioningSystemAccessLock = new Object();
if (this.getClass().equals(NbJavaCvsFileSystem.class)) {
dependantInit();
}
attr = new JavaCvsAttributes(info, change, list, FsCommandFactory.getFsInstance().getSupporter());
((JavaCvsAttributes) attr).setRuntimeProvider(new JavaCvsRuntimeCommandsProvider(this));
// init();
}
//-------------------------------------------
private void writeObject(ObjectOutputStream out) throws IOException {
/* moved to javacvsmoduleinstall.close()
if (cache != null) {
cache.saveToDisk();
}
*/
/* String TMP_ROOT=System.getProperty("netbeans.user")+File.separator+ // NOI18N
"system"+File.separator+"javacvs"+File.separator+"tmp"; // NOI18N
File tmpDir = new File(TMP_ROOT);
if (tmpDir.exists()) {
File[] fls = tmpDir.listFiles();
if (fls != null && fls.length > 0) {
for (int i = 0; i < fls.length; i++) {
fls[i].delete();
}
}
tmpDir.delete();
}
*/
out.defaultWriteObject();
}
//------------------------------------------------------------------------
// do commands
public ClientProvider createClientProvider() {
IndependantClient client = new IndependantClient(getHomeDirectory());
client.setCvsRootString(getCvsRootString());
client.setCvsPort(getCvsPort());
client.setLocalPath(getRootDirectory().getAbsolutePath());
java.util.List ignoreList = NbJavaCvsFileSystem.constructIgnoreList(getHomeDirectory(),
new File(getWorkingDir(), "CVSROOT")); // NOI18N
IgnoreFileFilter ignoreFilter = new DefaultIgnoreFileFilter(ignoreList);
client.setIgnoreFilter(ignoreFilter);
FsGlobalOptionsImpl glOptions = (FsGlobalOptionsImpl)getCommandFactory().getGlobalOptions();
glOptions.setCVSRoot(getCvsRootString());
client.setGlobalOptions(glOptions.getLibraryGlobalOptions());
client.setUiMode(getUiMode());
client.setDisplayType(getDisplayType());
return client;
}
private FsCommandFactory getFsFactory() {
return (FsCommandFactory)FsCommandFactory.getInstance();
}
public String[] getCvsIgnoreList() {
JavaCvsSettings settings = (JavaCvsSettings)SharedClassObject.findObject(
JavaCvsSettings.class, true);
String[] array;
Object obj = null;
if (ignoreListReference == null || ((obj = ignoreListReference.get()) == null)) {
// obj = ignoreListReference.get();
java.util.List ignoreList = JavaCvsFileSystem.constructIgnoreList(settings.getHome(),
new File(getWorkingDir(), "CVSROOT")); //NOI18N
array = new String[ignoreList.size()];
array = (String[])ignoreList.toArray(array);
ignoreListReference = new java.lang.ref.WeakReference(array);
} else {
array = (String[])obj;
}
return array;
}
public boolean checkOffLine() {
if (isOffLine()) {
String message = NbBundle.getBundle(NbJavaCvsFileSystem.class).getString("MSG_switch_to_online"); // NOI18N
NotifyDescriptor desc = new NotifyDescriptor.Confirmation(message,
NotifyDescriptor.Confirmation.YES_NO_OPTION,
NotifyDescriptor.Confirmation.QUESTION_MESSAGE);
Object value = DialogDisplayer.getDefault().notify(desc);
if (value.equals(NotifyDescriptor.YES_OPTION)) {
setOffLine(false);
}
}
return isOffLine();
}
/** Performs a status refresh on the filesystem.
* @param fileNames Array of FileObjects that should be refreshed.
* @param recursive boolean parameter - if true, do recursive refresh for all the directories.
*/
public void doRefresh(FileObject[] fileNames, boolean recursive) {
if (isOffLine()) {
((NbCvsFsCache)cache).doOfflineRefresh(fileNames, recursive);
/* String status = NbBundle.getMessage(NbJavaCvsFileSystem.class, "MSG_NoRefresh_When_OffLine", getDisplayName()); // NOI18N
TopManager.getDefault().setStatusText(status);
*/
return;
}
LinkedList reposFos = new LinkedList();
File[] files = getFiles(fileNames);
for (int i = 0; i < files.length; i++) {
File cvsSub;
if (files[i].isDirectory()) {
cvsSub = new File(files[i], "CVS/Entries"); //NOI18N
} else {
cvsSub = new File(files[i].getParentFile(), "CVS/Entries"); //NOI18N
}
if (!cvsSub.exists()) {
fileNames[i].refresh();
} else {
reposFos.add(fileNames[i]);
}
}
if (reposFos.size() > 0) {
FileObject[] fos = new FileObject[reposFos.size()];
fos = (FileObject[])reposFos.toArray(fos);
super.doRefresh(fos, recursive);
}
}
public void doCommand(Class commandClass, FileObject[] files, boolean CtrlDown) {
if (checkOffLine()) {
//TODO add question/notification..
return;
}
if (commandClass.equals(CvsCheckout.class)) {
doCheckout(files, CtrlDown);
return;
}
FileSystemCommand myStat = getFsFactory().createCommand(commandClass,
true, files, createClientProvider());
// Do the runtime stuff...
prepareCommand(myStat);
boolean skipParams = false;
if (!CtrlDown && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE) {
if (myStat.getClass().equals(CvsCommit.class)) {
getFsFactory().showCustomizerAndRun(myStat, new NbSimpleCommitParamInput(), false);
return;
}
if (myStat.getClass().equals(CvsTag.class)) {
getFsFactory().showCustomizerAndRun(myStat, new NbSimpleTagParamInput(), false);
return;
}
skipParams = true;
}
if (getUiMode() == NbJavaCvsFileSystem.MODE_COMMAND_LINE) {
getFsFactory().showCustomizerAndRun(myStat, new CommandLineParamInput(), false);
return;
}
getFsFactory().showCustomizerAndRun(myStat, skipParams, false);
}
public JavaCvsRuntimeCommand prepareCommand(FileSystemCommand command) {
JavaCvsRuntimeCommand rCom = new JavaCvsRuntimeCommand(command,
(JavaCvsRuntimeCommandsProvider) ((JavaCvsAttributes) attr).getRuntimeProvider());
// rCom.setState(RuntimeCommand.STATE_WAITING);
// RuntimeSupport.getInstance().updateCommand(getSystemName(), rCom);
command.addDisplayerListener(rCom);
command.addCommandErrorListener(rCom);
return rCom;
}
/**
* @deprecated
*/
/* public void doStatus(FileObject[] files, boolean CtrlDown) {
if (checkOffLine()) return;
CvsStatus myStat = (CvsStatus)getFsFactory().createCommand(CvsStatus.class,
true, files, createClientProvider());
boolean skipParams = false;
if (!CtrlDown && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE) {
skipParams = true;
}
getFsFactory().showCustomizerAndRun(myStat, skipParams, false);
}
*/
/**
* @deprecated
*/
/* public void doLog(FileObject[] files, boolean CtrlDown) {
if (checkOffLine()) return;
CvsLog myStat = (CvsLog)getFsFactory().createCommand(CvsLog.class,
true, files, createClientProvider());
boolean skipParams = false;
if (!CtrlDown && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE) {
skipParams = true;
}
getFsFactory().showCustomizerAndRun(myStat, skipParams, false);
}
*/
/**
* @deprecated
*/
/* public void doAnnotate(FileObject[] files, boolean CtrlDown) {
if (checkOffLine()) return;
CvsAnnotate myStat = (CvsAnnotate)getFsFactory().createCommand(CvsAnnotate.class,
true, files, createClientProvider());
boolean skipParams = false;
if (!CtrlDown && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE) {
skipParams = true;
}
getFsFactory().showCustomizerAndRun(myStat, skipParams, false);
}
*/
public void doImport(FileObject[] files) {
if (checkOffLine()) return;
FileObject[] fos = null;
FileObject currDir = files[0];
IndependantClient ind = (IndependantClient)createClientProvider();
ind.setLocalPath(getFile(currDir.getPackageNameExt('/','.')).getAbsolutePath());
String start = getRelMount() + File.separator;
if (start.length() == 1) {
start = "";
}
start = start.replace('\\', '/');
if (start.startsWith("/")) { // NOI18N
start = start.substring(1);
}
String module = start + currDir.getPackageNameExt('/','.');
CvsImport myStat = (CvsImport)getFsFactory().createCommand(CvsImport.class,
true, fos, ind);
myStat.setModule(module);
boolean skipParams = false;
/* if (!CtrlDown && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE) {
skipParams = true;
}
*/
// Do the runtime stuff...
prepareCommand(myStat);
getFsFactory().showCustomizerAndRun(myStat, skipParams, false);
}
public void doHistory() {
if (checkOffLine()) return;
FileObject[] fos = null;
CvsHistory myStat = (CvsHistory)getFsFactory().createCommand(CvsHistory.class,
true, fos, createClientProvider());
boolean skipParams = false;
// Do the runtime stuff...
prepareCommand(myStat);
getFsFactory().showCustomizerAndRun(myStat, skipParams, false);
}
public void doExport(FileObject[] files) {
if (checkOffLine()) return;
String start = getRelMount() + File.separator;
start = start.replace('\\', '/');
if (start.startsWith("/")) { // NOI18N
start = start.substring(1);
}
IndependantClient ind = (IndependantClient)createClientProvider();
ind.setLocalPath(getWorkingDir().getAbsolutePath());
String[] names = new String[files.length];
for (int index = 0; index < files.length; index++) {
String modName = files[index].getPackageNameExt('/', '.');
names[index] = start + modName;
}
FileObject[] fos = null;
CvsExport myStat = (CvsExport)getFsFactory().createCommand(CvsExport.class,
true, fos, ind);
boolean skipParams = false;
myStat.setModules(names);
ind.setLocalPath(getWorkingDir().getAbsolutePath());
// System.out.println("indhashcode=" + ind.hashCode());
// System.out.println("original localdi = " + ind.getLocalPath());
/* if (!CtrlDown && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE) {
skipParams = true;
}
*/
// Do the runtime stuff...
prepareCommand(myStat);
myStat.addDisplayerListener(new CommandDisplayerAdapter() {
public void showFinishedCommand() {
java.util.Enumeration en = NbJavaCvsFileSystem.this.existingFileObjects(findResource(""));
while (en.hasMoreElements()) {
FileObject fo = (FileObject)en.nextElement();
if (fo.isFolder()) {
fo.refresh();
}
}
// fireFileStatusForExisting();
}
});
getFsFactory().showCustomizerAndRun(myStat, skipParams, false);
}
/**
* @deprecated
*/
public void doDiff(FileObject[] files, boolean CtrlDown) {
if (checkOffLine()) return;
CvsDiff myStat = (CvsDiff)getFsFactory().createCommand(CvsDiff.class,
true, files, createClientProvider());
boolean skipParams = false;
if (!CtrlDown && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE) {
skipParams = true;
}
getFsFactory().showCustomizerAndRun(myStat, skipParams, false);
}
/**
* @deprecated
*/
public void doUpdate(FileObject[] files, boolean CtrlDown) {
if (checkOffLine()) return;
CvsUpdate myStat = (CvsUpdate)getFsFactory().createCommand(CvsUpdate.class,
true, files, createClientProvider());
boolean skipParams = false;
if (!CtrlDown && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE) {
skipParams = true;
}
getFsFactory().showCustomizerAndRun(myStat, skipParams, false);
//TODO
}
/**
*
*/
public void doCheckout(FileObject[] files, boolean CtrlDown) {
if (checkOffLine()) return;
String start = getRelMount() + File.separator;
start = start.replace('\\', '/');
if (start.startsWith("/")) { // NOI18N
start = start.substring(1);
}
IndependantClient ind = (IndependantClient)createClientProvider();
ind.setLocalPath(getWorkingDir().getAbsolutePath());
String[] names = new String[files.length];
for (int index = 0; index < files.length; index++) {
if (files[index].isRoot()) {
if (getRelMount().trim().length() > 0) {
names[index] = getRelMount();
} else {
names[index] = "."; //NOI18N
}
} else {
String modName = files[index].getPackageNameExt('/', '.');
names[index] = start + modName;
}
}
CvsCheckout myStat = (CvsCheckout)getFsFactory().createCommand(CvsCheckout.class,
true, new FileObject[] {}, ind);
myStat.setModules(names);
myStat.setLocalPath(getWorkingDir().getAbsolutePath());
// this is needed because the checkout command is not working relatively
// but always requires the whole path
// -> we want to checkout selected node it iself and not into a different structure
boolean skipParams = false;
if (!CtrlDown && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE) {
skipParams = true;
}
// Do the runtime stuff...
prepareCommand(myStat);
if (getUiMode() == NbJavaCvsFileSystem.MODE_COMMAND_LINE) {
getFsFactory().showCustomizerAndRun(myStat, new CommandLineParamInput(), false);
return;
}
if ((!skipParams && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE)
|| getUiMode() == NbJavaCvsFileSystem.MODE_ADVANCED) {
getFsFactory().showCustomizerAndRun(myStat, new NbCheckoutParamInput(), false);
} else {
getFsFactory().showCustomizerAndRun(myStat, skipParams, false);
}
}
public void doListModules() {
if (checkOffLine()) return;
CvsCompleteModList myStat = new CvsCompleteModList(createClientProvider());
// Do the runtime stuff...
prepareCommand(myStat);
myStat.addDisplayerListener(new ModulesListPanel());
myStat.addDisplayerListener(new ErrorLogPanel(myStat));
myStat.startCommand();
}
/**
* @deprecated
*/
public void doAdd(FileObject[] files, boolean CtrlDown) {
if (checkOffLine()) return;
CvsAdd myStat = (CvsAdd)getFsFactory().createCommand(CvsAdd.class,
true, files, createClientProvider());
boolean skipParams = false;
if (!CtrlDown && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE) {
skipParams = true;
}
getFsFactory().showCustomizerAndRun(myStat, skipParams, false);
}
/**
* @deprecated
*/
public void doRemove(FileObject[] files, boolean CtrlDown) {
if (checkOffLine()) return;
CvsRemove myStat = (CvsRemove)getFsFactory().createCommand(CvsRemove.class,
true, files, createClientProvider());
boolean skipParams = false;
if (!CtrlDown && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE) {
skipParams = true;
}
getFsFactory().showCustomizerAndRun(myStat, skipParams, false);
}
/**
* @deprecated
*/
public void doCommit(FileObject[] files, boolean CtrlDown) {
if (checkOffLine()) return;
CvsCommit myStat = (CvsCommit)getFsFactory().createCommand(CvsCommit.class,
true, files, createClientProvider());
if (!CtrlDown && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE) {
getFsFactory().showCustomizerAndRun(myStat, new NbSimpleCommitParamInput(), false);
} else {
getFsFactory().showCustomizerAndRun(myStat, false, false);
}
// never skip customizer
//TODO
}
/**
* @deprecated
*/
public void doTag(FileObject[] files, boolean CtrlDown) {
if (checkOffLine()) return;
CvsTag myStat = (CvsTag)getFsFactory().createCommand(CvsTag.class,
true, files, createClientProvider());
if (!CtrlDown && getUiMode() == NbJavaCvsFileSystem.MODE_NOVICE) {
getFsFactory().showCustomizerAndRun(myStat, new NbSimpleTagParamInput(), false);
} else {
getFsFactory().showCustomizerAndRun(myStat, false, false);
}
}
/*
public void doRevisionExplorer(FileObject[] files) {
if (checkOffLine()) return;
CvsLog myStat = (CvsLog)getFsFactory().createCommand(CvsLog.class,
false, files, createClientProvider());
myStat.addDisplayerListener(new RevisionExplorerInfo(this));
myStat.addDisplayerListener(new ErrorLogPanel(myStat));
// Do the runtime stuff...
prepareCommand(myStat);
myStat.startCommand();
}
*/
// run when the filesystem is being removed.
// do write all cache to files..
protected void notifyFSRemoved() {
// D.deb("removeNofify() - now save cache"); // NOI18N
// remove the node for the fs in the runtime tab
/* RuntimeFolderNode folder = RuntimeSupport.initRuntime(getSystemName());
if (folder != null) {
try {
folder.destroy();
} catch (IOException exc) {
}
}
*/
super.notifyFSRemoved();
JavaCvsSettings settings = (JavaCvsSettings)SharedClassObject.findObject(
JavaCvsSettings.class);
if (settings != null) {
settings.removePropertyChangeListener(settingsChangeList);
}
org.openide.util.RequestProcessor.postRequest(new Runnable() {
public void run() {
//VersioningExplorer.getRevisionExplorer().open();
removeVersioningSystem();
}
});
setVcsRefreshTime(0); //stop the refreshing thread..
}
// run when the filesystem is being added.
// do write all cache to files..
protected void notifyFSAdded() {
// D.deb("removeNofify() - now save cache"); // NOI18N
// cache.saveToDiskFromNode("");
super.notifyFSAdded();
setVcsRefreshTime(REFRESH_TIME);
// init the fs in the runtime tab.
/* RuntimeFolderNode folder = RuntimeSupport.initRuntime(getSystemName());
folder.setDisplayName(getDisplayName());
folder.setIconBase("/org/netbeans/modules/javacvs/JavaCvsFileSystemIcon"); // NOI18N
*/
if (initialCheckout) {
setInitialCheckout(false);
FileObject[] fls = {getRoot()};
doCheckout(fls, true);
}
final CvsFsCache fsCache = cache;
org.openide.util.RequestProcessor.postRequest(new Runnable() {
public void run() {
//VersioningExplorer.getRevisionExplorer().open();
boolean[] created = { false };
JavaCvsVersioningSystem versioningSystem = createVersioningSystem(created);
if (created[0]) {
synchronized (NbJavaCvsFileSystem.this) {
if (versioningFileSystemShowMessage != null) {
versioningSystem.setShowMessages(versioningFileSystemShowMessage.booleanValue());
}
if (versioningFileSystemMessageLength != null) {
versioningSystem.setMessageLength(versioningFileSystemMessageLength.intValue());
}
if (versioningFileSystemIgnoreFiles != null) {
versioningSystem.setIgnoredFiles(versioningFileSystemIgnoreFiles);
}
if (fsCache != null) {
JavaCvsCache cache = fsCache.getCacheObject();
if (cache != null) {
cache.addCacheHandlerListener(
(CacheHandlerListener) WeakListener.create(CacheHandlerListener.class, (CacheHandlerListener) versioningSystem, cache));
}
}
}
}
}
});
}
public static Mode getDockingMode(Workspace workspace) {
Mode mode =workspace.findMode(NbJavaCvsFileSystem.JAVACVS_MODE);
if (mode == null) {
mode = workspace.createMode(
NbJavaCvsFileSystem.JAVACVS_MODE,
NbBundle.getMessage(NbJavaCvsFileSystem.class, "JavaCvsFileSystem.modeTitle"), // NOI18N
NbJavaCvsFileSystem.class.getResource(
"/org/netbeans/modules/cvsclient/JavaCvsFileSystemIcon.gif" // NOI18N
));
mode.setBounds(new Rectangle(500, 500 ));
}
return mode;
}
public static void errorMessage(String message) {
final String mess = message;
javax.swing.SwingUtilities.invokeLater(new Runnable () {
public void run () {
DialogDisplayer.getDefault ().notify (new NotifyDescriptor.Message(mess));
}
});
}
/** run when the JavaCvsSettings object fires propertyChange
*/
private void settingsChanged(String propName, Object oldVal, Object newVal) {
JavaCvsSettings settings = (JavaCvsSettings)SharedClassObject.findObject(
JavaCvsSettings.class, true);
if (propName == null) return;
if (propName.equals(JavaCvsSettings.PROP_CVS_FILE_STATES)) {
NbJavaCvsStatusManager.getInstance().assignNewValues(settings.getCvsFileStates());
FileObject foRoot= findResource(""); // NOI18N
fireFileStatusForExisting(foRoot);
}
if (propName.equals(JavaCvsSettings.PROP_ANNOTATION_PATTERN)) {
FileObject foRoot= findResource(""); // NOI18N
fireFileStatusForExisting(foRoot);
}
if (propName.equals(GeneralVcsSettings.PROP_HOME)) {
setHomeDirectory(settings.getHome());
}
if (propName.equals(GeneralVcsSettings.PROP_USE_GLOBAL)) {
Boolean newBool = (Boolean)newVal;
if (newBool.booleanValue() == true) {
setOffLine(settings.isOffLine());
setUiMode(settings.getUiMode());
setAutoRefresh(settings.getAutoRefresh());
setDisplayType(settings.getDisplayType());
setHideShadowFiles(settings.isHideShadowFiles());
}
} else {
if (settings.isUseGlobal()) {
// do change the fs settings only in case the global ones have priority
if (propName.equals(GeneralVcsSettings.PROP_AUTO_REFRESH)) {
Integer intVal = (Integer)newVal;
setAutoRefresh(intVal.intValue());
}
if (propName.equals(JavaCvsSettings.PROP_UI_MODE)) {
Integer intVal = (Integer)newVal;
setUiMode(intVal.intValue());
}
if (propName.equals(GeneralVcsSettings.PROP_OFFLINE)) {
Boolean boolVal = (Boolean)newVal;
setOffLine(boolVal.booleanValue());
}
if (propName.equals(JavaCvsSettings.PROP_DISPLAY_TYPE)) {
Integer intVal = (Integer)newVal;
setDisplayType(intVal.intValue());
}
if (propName.equals(GeneralVcsSettings.PROP_HIDE_SHADOW_FILES)) {
Boolean boolVal = (Boolean)newVal;
setHideShadowFiles(boolVal.booleanValue());
}
}
}
}
/**
* Stuff added because of the vcscore's CVS Mount wizard
*/
public boolean checkLogin(String cvsRoot, String passwd)
throws IOException, AuthenticationException {
String password = null;
boolean loggedIn = false;
JavaCvsSettings settings = (JavaCvsSettings)SharedClassObject.findObject(
JavaCvsSettings.class, true);
String dir = settings.getHome().getAbsolutePath();
CVSPasswd passFile = new CVSPasswd(dir, ".cvspass"); // NOI18N
passFile.loadPassFile();
PasswdEntry entry = new PasswdEntry();
entry.setEntry(cvsRoot + " " + CVSPasswd.scramble(passwd)); // NOI18N
loggedIn = passFile.checkServer(entry, entry.getPort());
if (loggedIn) {
passFile.add(cvsRoot, passwd);
passFile.savePassFile();
}
return loggedIn;
}
public void setInitialCheckout(boolean doIt) {
initialCheckout = doIt;
firePropertyChange("PROP_INITIAL_CHECKOUT", !doIt ? Boolean.TRUE : Boolean.FALSE, doIt ? Boolean.TRUE : Boolean.FALSE); //NOI18N
}
public boolean isInitialCheckout() {
return initialCheckout;
}
/** Sets the working directory property. Equals the root of the checked out sources.
*/
public void setWorkingDir(java.io.File newWorking) {
super.setWorkingDir(newWorking);
oldFsSystemName = getSystemName();
}
/** Sets the relative mountpoint. It is a relative part to the filesystem root from the working directory.
* Eg.
*
* If I want to mount the cvs library that is stored under c:\src\netbeans\javacvs\srclib
* I need to set the working directory to c:\src\netbeans
* and the relative mountpoint to javacvs/srclib
* Warning: If not set correctly, some commands can have strange effects (mostly the checkout command)
*
*
*/
public void setRelMount(String newMount) {
super.setRelMount(newMount);
oldFsSystemName = this.getSystemName();
}
private void checkScheduledStates(Set fos) {
/* FileStatusProvider status = getStatusProvider();
if (status == null) return ;
VcsConfigVariable schVar = (VcsConfigVariable) variablesByName.get(VAR_STATUS_SCHEDULED_ADD);
String scheduledStatusAdd = (schVar != null) ? schVar.getValue() : null;
schVar = (VcsConfigVariable) variablesByName.get(VAR_STATUS_SCHEDULED_REMOVE);
String scheduledStatusRemove = (schVar != null) ? schVar.getValue() : null;
*/
JavaCvsStatusManager manager = JavaCvsStatusManager.getInstance();
String scheduledStatusAdd = manager.getStatus(manager.convertStatus(FileStatus.ADDED));
String scheduledStatusRemove = manager.getStatus(manager.convertStatus(FileStatus.REMOVED));
//System.out.println("checkScheduledStates(): scheduledStatusAdd = "+scheduledStatusAdd+", scheduledStatusRemove = "+scheduledStatusRemove);
for (Iterator it = fos.iterator(); it.hasNext(); ) {
FileObject fo = (FileObject) it.next();
//System.out.println("checkScheduledStates("+fo.getPackageNameExt('/', '.')+")");
String attr = (String) fo.getAttribute(VcsAttributes.VCS_SCHEDULED_FILE_ATTR);
//System.out.println("attr("+VcsAttributes.VCS_SCHEDULED_FILE_ATTR+") = "+attr);
Vector vec = new Vector();
vec.add(fo.getPackageNameExt('/','.'));
String status = cache.getFileStatusOnly(vec);
if (VcsAttributes.VCS_SCHEDULING_ADD.equals(attr) && scheduledStatusAdd != null &&
!scheduledStatusAdd.equals(status) &&
isSchedulingDone(fo.getPackageNameExt('/', '.'))) {
try {
fo.setAttribute(VcsAttributes.VCS_SCHEDULED_FILE_ATTR, null);
} catch (IOException exc) {}
removeScheduledFromPrimary(fo, 1);
}
if (VcsAttributes.VCS_SCHEDULING_REMOVE.equals(attr) && scheduledStatusRemove != null &&
!scheduledStatusRemove.equals(status)) {
try {
fo.setAttribute(VcsAttributes.VCS_SCHEDULED_FILE_ATTR, null);
} catch (IOException exc) {}
removeScheduledFromPrimary(fo, 0);
}
}
}
/**
* The file scheduled for remove is onthe disk.
* If it does not contain VcsAttributes.VCS_SCHEDULING_REMOVE,
* it will be removed from the list of scheduled files, because it was
* deleted and reappeared.
*/
/* private void checkScheduledLocals(String path, Collection locals, Map removedFilesScheduledForRemove) {
JavaCvsStatusManager manager = JavaCvsStatusManager.getInstance();
String scheduledStatusRemove = manager.getStatus(manager.convertStatus(FileStatus.REMOVED));
if (scheduledStatusRemove == null) return ;
for (Iterator it = locals.iterator(); it.hasNext(); ) {
String name = path + "/" + it.next();
if (removedFilesScheduledForRemove.containsKey(name)) {
String primary = (String) removedFilesScheduledForRemove.get(name);
//System.out.println("checkScheduledLocals("+name+")");
String attribute = (String) attr.readAttribute(name, VcsAttributes.VCS_SCHEDULED_FILE_ATTR);
//System.out.println("attr("+VcsAttributes.VCS_SCHEDULED_FILE_ATTR+") = "+attr);
if (!VcsAttributes.VCS_SCHEDULING_REMOVE.equals(attribute)) {
removeScheduledFromPrimary(name, primary, 0);
}
}
}
}
*/
private static void removeScheduledFromPrimary(FileObject fo, int id) {
DataObject dobj;
try {
dobj = DataObject.find(fo);
} catch (org.openide.loaders.DataObjectNotFoundException exc) {
return ;
}
FileObject primary = dobj.getPrimaryFile();
Set[] scheduled = (Set[]) primary.getAttribute(VcsAttributes.VCS_SCHEDULED_FILES_ATTR);
if (scheduled != null && scheduled[id] != null) {
scheduled[id].remove(fo.getPackageNameExt('/', '.'));
scheduled = cleanScheduledAttrs(scheduled);
try {
primary.setAttribute(VcsAttributes.VCS_SCHEDULED_FILES_ATTR, scheduled);
if (scheduled == null) {
primary.setAttribute(VcsAttributes.VCS_SCHEDULING_MASTER_FILE_NAME_ATTR, null);
}
} catch (IOException exc) {}
}
}
private void removeScheduledFromPrimary(String scheduledFile, String primaryFile, int id) {
Set[] scheduled = (Set[]) attr.readAttribute(primaryFile, VcsAttributes.VCS_SCHEDULED_FILES_ATTR);
if (scheduled != null && scheduled[id] != null) {
scheduled[id].remove(scheduledFile);
scheduled = cleanScheduledAttrs(scheduled);
try {
attr.writeAttribute(primaryFile, VcsAttributes.VCS_SCHEDULED_FILES_ATTR, scheduled);
if (scheduled == null) {
attr.writeAttribute(primaryFile, VcsAttributes.VCS_SCHEDULING_MASTER_FILE_NAME_ATTR, null);
}
} catch (IOException exc) {}
}
}
private transient Vector scheduledFilesToBeProcessed;
void addScheduledFileToBeProcessed(String name) {
if (scheduledFilesToBeProcessed == null) {
scheduledFilesToBeProcessed = new Vector();
}
scheduledFilesToBeProcessed.add(name);
}
void removeScheduledFileToBeProcessed(String name) {
if (scheduledFilesToBeProcessed == null) {
scheduledFilesToBeProcessed = new Vector();
}
scheduledFilesToBeProcessed.remove(name);
}
private boolean isSchedulingDone(String name) {
return scheduledFilesToBeProcessed == null || !scheduledFilesToBeProcessed.contains(name);
}
private String[] filterScheduledSecondaryFiles(String packageName, String[] files, Map removedFiles) {
ArrayList filtered = new ArrayList(Arrays.asList(files));
boolean emptyPackage = (packageName.length() == 0);
for (int i = 0; i < files.length; i++) {
if (files[i] == null) continue;
String fileName = (emptyPackage) ? files[i] : (packageName + "/" + files[i]); //NOI18N
// System.out.println("file name=" + fileName);
Set[] scheduled = (Set[]) attr.readAttribute(fileName, VcsAttributes.VCS_SCHEDULED_FILES_ATTR);
//System.out.println("filterScheduledSecondaryFiles("+packageName+"): "+ packageName + "/" + files[i]+" scheduled = "+scheduled);
if (scheduled != null && scheduled[0] != null) {
LinkedList toRemove = new LinkedList();
for (Iterator it = scheduled[0].iterator(); it.hasNext(); ) {
String secFile = (String) it.next();
//System.out.println("secFile = '"+secFile+"'");
if (!emptyPackage && secFile.startsWith(packageName) ||
emptyPackage && secFile.indexOf('/') < 0) {
//System.out.println("removing '"+secFile.substring(packageName.length() + 1)+"'");
String nameOnly = (emptyPackage) ? secFile : secFile.substring(packageName.length() + 1);
boolean removed = filtered.remove(nameOnly);
//System.out.println("removed = "+removed+", filtered.contains("+secFile.substring(packageName.length() + 1)+") = "+filtered.contains(secFile.substring(packageName.length() + 1)));
if (!removed) {
toRemove.add(secFile);
try {
attr.writeAttribute(secFile, VcsAttributes.VCS_SCHEDULED_FILE_ATTR, null);
} catch (IOException exc) {}
} else {
// the file was removed from the list and put to the list of removed files
removedFiles.put(secFile, fileName);
}
}
}
if (toRemove.size() > 0) {
scheduled[0].removeAll(toRemove);
scheduled = cleanScheduledAttrs(scheduled);
try {
attr.writeAttribute(fileName, VcsAttributes.VCS_SCHEDULED_FILES_ATTR, scheduled);
if (scheduled == null) {
attr.writeAttribute(fileName, VcsAttributes.VCS_SCHEDULING_MASTER_FILE_NAME_ATTR, null);
}
} catch (IOException exc) {}
}
}
}
return (String[]) filtered.toArray(new String[0]);
}
private static final Set[] cleanScheduledAttrs(Set[] scheduled) {
//System.out.print("cleanScheduledAttrs("+scheduled+") = ");
boolean canClean = true;
for (int k = 0; k < scheduled.length; k++) {
if (scheduled[k] != null && scheduled[k].size() == 0) scheduled[k] = null;
if (scheduled[k] != null) {
canClean = false;
break;
}
}
if (canClean) scheduled = null;
//System.out.println(scheduled);
return scheduled;
}
/**
* Get the important files.
* @return the Vector of important files as Strings (package + name + extension)
*/
protected Vector getImportantFiles(Object[] oo) {
Vector retValue;
retValue = super.getImportantFiles(oo);
int len=oo.length;
for(int i=0;i0 if refreshing is disabled
*/
protected final int getVcsRefreshTime () {
VcsRefreshRequest r = refresher;
return r == null ? 0 : r.getRefreshTime ();
}
protected void setVirtualDataLoader(FileObject fo) {
try {
if (checkVirtual(fo.getPackageNameExt(File.separatorChar,'.'))) {
fo.setAttribute ("NetBeansAttrAssignedLoader", VirtualsDataLoader.class.getName()); //NoI18N
/*
DataLoader loader = DataLoaderPool.getPreferredLoader(fo);
if (loader == null || (loader != null && !loader.getClass().equals(VirtualsDataLoader.class))) {
DataLoaderPool.setPreferredLoader(fo,
(VirtualsDataLoader) org.openide.util.SharedClassObject.findObject(VirtualsDataLoader.class, true));
reload = true;
// System.out.println("to vitrual..");
}
*/
} else {
Reference ref = findReference (fo.getPath());
if ( (ref instanceof CacheReference) && ((CacheReference)ref).isVirtual()) {
fo.setAttribute ("NetBeansAttrAssignedLoader",null); //NoI18N
}
/*
DataLoader loader = DataLoaderPool.getPreferredLoader(fo);
if (loader != null && loader.getClass().equals(VirtualsDataLoader.class)) {
// System.out.println("resetitting loader");
DataLoaderPool.setPreferredLoader(fo, null);
reload = true;
}
*/
}
} catch (java.io.IOException exc) {}
}
public class JavaCvsAttributes extends DefaultAttributes {
private transient CommandActionSupporter supporter;
private transient RuntimeCommandsProvider runtimeProvider;
static final long serialVersionUID = 5320181565426569135L;
/** Creates new VcsAttributes */
public JavaCvsAttributes(AbstractFileSystem.Info info, AbstractFileSystem.Change change,
AbstractFileSystem.List list, CommandActionSupporter supp) {
super(info, change, list);
supporter = supp;
}
public void setRuntimeProvider(RuntimeCommandsProvider runtimeProvider) {
this.runtimeProvider = runtimeProvider;
}
public RuntimeCommandsProvider getRuntimeProvider() {
return runtimeProvider;
}
/**
* Get the file attribute with the specified name.
* @param name the file name
* @param attrName name of the attribute
* @return appropriate (serializable) value or null if the attribute is unset
* (or could not be properly restored for some reason).
* If the attribute name is the {@link VCS_STATUS}, then the VCS status
* of the file is returned.
*/
public Object readAttribute(String name, String attrName) {
if (VcsAttributes.VCS_STATUS.equals(attrName)) {
if (NbJavaCvsFileSystem.this.getFile(name).exists()) return VcsAttributes.VCS_STATUS_MISSING;
/** TODO FileStatusProvider statusProvider = fileSystem.getStatusProvider();
if (statusProvider != null) {
String status = statusProvider.getFileStatus(name);
//CacheFile file = cacheProvider.getFile?name);
if (statusProvider.getLocalFileStatus().equals(status)) {
return VCS_STATUS_LOCAL;
}
return VCS_STATUS_UP_TO_DATE;
}
*/
return VcsAttributes.VCS_STATUS_UNKNOWN;
} else if ("org.netbeans.modules.vcscore.runtime.RuntimeCommandsProvider".equals(attrName)) { // NOI18N
return runtimeProvider;
} else if ("NetBeansAttrAssignedLoader".equals(attrName)) { /* DataObject.EA_ASSIGNED_LOADER */ //NOI18N
CacheReference ref = getCacheReference(name);
if (ref != null) {
if (ref.isVirtual()) {
// System.out.println("is virtual.." + name);
return VirtualsDataLoader.class.getName();
}
}
} else if ("NetBeansAttrAssignedLoaderModule".equals(attrName)) { /* DataObject.EA_ASSIGNED_LOADER_MODULE */ //NOI18N
CacheReference ref = getCacheReference(name);
if (ref != null) {
if (ref.isVirtual()) {
// System.out.println("is vitrual module..");
return "org.netbeans.modules.vcscore"; //NOI18N
}
}
} else if (GeneralCommandAction.VCS_ACTION_ATTRIBUTE.equals(attrName)) {
FsCommandFactory fact = (FsCommandFactory)FsCommandFactory.getInstance();
return fact.getSupporter();
} else if (AnnotationProvider.ANN_PROVIDER_FO_ATTRIBUTE.equals(attrName)) {
if (cache != null) {
return ((NbCvsFsCache)cache).getAnnotationProvider(name);
}
return null;
} else if (VcsAttributes.VCS_NATIVE_FS.equals(attrName)) {
return NbJavaCvsFileSystem.this;
} else if (VcsAttributes.VCS_NATIVE_PACKAGE_NAME_EXT.equals(attrName)) {
return name;
} else if ("java.io.File".equals(attrName)) { //NOI18N
return NbJavaCvsFileSystem.this.getFile(name);
} else if (VcsSearchTypeFileSystem.VCS_SEARCH_TYPE_ATTRIBUTE.equals(attrName)) {
return NbJavaCvsFileSystem.this;
}
return super.readAttribute(name, attrName);
}
/**
* Set the file attribute with the specified name. If the name is {@link VCS_ACTION},
* and the value is an instance of FeatureDescriptor, then it's not set as file attribute,
* but is interpreted as a VCS command. The name of the command is taken from
* value.getName() and commands options from attributes of that feature descriptor.
* @param name the file name
* @param attrName name of the attribute
* @param value new value or null to clear the attribute. Must be serializable,
* with the exception of VCS command attribute.
* @throws IOException if the attribute cannot be set. If serialization is
* used to store it, this may in fact be a subclass such
* as NotSerializableException.
* @throws UnknownServiceException if the requested VCS action is not provided.
* A subclass of IOException was chosen, since
* FileObject.setAttribute throws IOException.
*/
public void writeAttribute(final String name, final String attrName, final Object value) throws IOException, java.net.UnknownServiceException {
if (VcsAttributes.VCS_ACTION.equals(attrName) && value instanceof FeatureDescriptor) {
performVcsAction(name, (FeatureDescriptor) value);
} else if (VcsAttributes.VCS_SCHEDULING_SECONDARY_FO_ACTION.equals(attrName) && value instanceof String) {
FeatureDescriptor desc = new FeatureDescriptor();
if ("ADD".equals(value)) { //NOI18N
desc.setName(VcsCommand.NAME_SCHEDULE_ADD);
performVcsAction(name, desc);
} else if ("REMOVE".equals(value)) { //NOI18N
desc.setName(VcsCommand.NAME_SCHEDULE_REMOVE);
performVcsAction(name, desc);
}
/*
// Set the scheduling action for a secondary file. value is the action name,
// currently "ADD" and "REMOVE" are the only supported values
final FileObject fo = NbJavaCvsFileSystem.this.findResource(name);
//System.out.println("scheduleSecondaryFOVcsAction("+name+", "+actionName+") = "+fo);
if (fo == null) return ;
FileObject primary;
try {
org.openide.loaders.DataObject dobj = org.openide.loaders.DataObject.find(fo);
primary = dobj.getPrimaryFile();
//System.out.println(" primary("+primary+").equals("+fo+") = "+primary.equals(fo));
if (primary.equals(fo)) return ;
} catch (org.openide.loaders.DataObjectNotFoundException exc) {
exc.printStackTrace();
return ;
}
// The scheduling is started. When all scheduling actions are done, a refresh is introduced.
startFileScheduling(name);
final FileObject primaryFO = primary;
RequestProcessor.postRequest(new Runnable() {
public void run() {
scheduleSecondaryFOVcsAction(name, (String) value, fo, primaryFO);
}
});
super.writeAttribute(name, VcsAttributes.VCS_SCHEDULED_FILE_ATTR, value);
*/
}
else {
if ("NetBeansAttrAssignedLoader".equals(attrName)) { /* DataObject.EA_ASSIGNED_LOADER */ //NOI18N
if (VirtualsDataLoader.class.getName().equals(value)) {
// System.out.println("dont write loader attribute,.," + name);
//don't write to .nbattrs file..
CacheReference ref = getCacheReference(name);
if (ref != null) {
// System.out.println("writed is virtual");
ref.setVirtual(true);
}
return;
}
if (value == null) {
CacheReference ref = getCacheReference(name);
if (ref != null) {
ref.setVirtual(false);
try {
DataObject.find (findResource(name)).setValid (false);
} catch (java.beans.PropertyVetoException pve) {}
}
}
// System.out.println("write assigned loader for=" + name);
}
if ("NetBeansAttrAssignedLoaderModule".equals(attrName)) { /* DataObject.EA_ASSIGNED_LOADER_MODULE */ //NOI18N
if (value != null && "org.netbeans.modules.vcscore".equals(value.toString()) //NOI18N
&& checkVirtual(name)) {
//don't write to .nbattrs file..
return;
}
// System.out.println("write assigned module=" + value);
}
super.writeAttribute(name, attrName, value);
}
}
private void performVcsAction(final String name, final FeatureDescriptor descriptor) throws java.net.UnknownServiceException {
String cmdName = descriptor.getName();
FileSystemCommand command = null;
FileObject fo = NbJavaCvsFileSystem.this.findResource(name);
// System.out.println("running.." + cmdName + " file=" + name);
// System.out.println("fo=" + fo);
if (cmdName.equals(VcsCommand.NAME_SCHEDULE_ADD)) {
FsAdd addCom = NbJavaCvsFileSystem.this.createAdd();
command = ((CvsAdd.AddImpl)addCom).getOuterClassInstance();
} else if (cmdName.equals(VcsCommand.NAME_SCHEDULE_REMOVE)) {
FsRemove remCom = NbJavaCvsFileSystem.this.createRemove();
remCom.setDeleteBeforeRemove(true);
command = ((CvsRemove.RemoveImpl)remCom).getOuterClassInstance();
} else throw new java.net.UnknownServiceException(cmdName);
command.setFileObjects(new FileObject[] { fo });
command.addDisplayerListener(new ErrorLogPanel(command));
NbJavaCvsFileSystem.this.prepareCommand(command);
CommandDisplayerListener displ = new AttrCommandDisplayer(descriptor);
command.addDisplayerListener(displ);
command.startCommand();
}
/**
* Schedule a secondary file for "ADD" or "REMOVE". Files scheduled for remove are filtered from children().
* Files scheduled are added as a special file attribute to the primary file.
* @param name the name of a secondary file to be scheduled.
* @param actionName "ADD" or "REMOVE"
* @param fo the file object associated to the file
* @param primary the associated primary file
*/
/* private boolean scheduleSecondaryFOVcsAction(final String name, final String actionName, FileObject fo, FileObject primary) {
if (VcsAttributes.VCS_STATUS_LOCAL.equals(primary.getAttribute(VcsAttributes.VCS_STATUS))) {
// do not schedule local files
endFileScheduling(name);
return false;
}
int id;
// create the descriptor of a scheduling action
FeatureDescriptor descriptor = new FeatureDescriptor() {
public void setValue(String attrName, Object value) {
if (VcsAttributes.VCS_ACTION_DONE.equals(attrName)) {
// the scheduling action is done, inform the file system
NbJavaCvsFileSystem.this.removeScheduledFileToBeProcessed(name);
endFileScheduling(name);
}
super.setValue(attrName, value);
}
};
boolean endOfScheduling = false;
if (VcsAttributes.VCS_SCHEDULING_ADD.equals(actionName)) {
//fileSystem.addScheduledSecondaryFO(name, VcsFileSystem.SCHEDULING_ACTION_ADD_ID);
//FeatureDescriptor descriptor = new FeatureDescriptor();
descriptor.setName(VcsCommand.NAME_SCHEDULE_ADD);
try {
NbJavaCvsFileSystem.this.addScheduledFileToBeProcessed(name);
performVcsAction(name, descriptor);
} catch (java.net.UnknownServiceException unsExc) {
NbJavaCvsFileSystem.this.removeScheduledFileToBeProcessed(name);
endOfScheduling = true;
}
id = 1;
} else if (VcsAttributes.VCS_SCHEDULING_REMOVE.equals(actionName)) {
//fileSystem.addScheduledSecondaryFO(name, VcsFileSystem.SCHEDULING_ACTION_REMOVE_ID);
//FeatureDescriptor descriptor = new FeatureDescriptor();
descriptor.setName(VcsCommand.NAME_SCHEDULE_REMOVE);
try {
NbJavaCvsFileSystem.this.addScheduledFileToBeProcessed(name);
performVcsAction(name, descriptor);
} catch (java.net.UnknownServiceException unsExc) {
NbJavaCvsFileSystem.this.removeScheduledFileToBeProcessed(name);
endOfScheduling = true;
}
id = 0;
} else {
endFileScheduling(name);
return false;
}
// the file is being scheduled, add it to the primary file attribute.
Set[] scheduled = (Set[]) primary.getAttribute(VcsAttributes.VCS_SCHEDULED_FILES_ATTR);
if (scheduled == null) scheduled = new HashSet[2];
if (scheduled[id] == null) scheduled[id] = new HashSet();
scheduled[id].add(name);
try {
primary.setAttribute(VcsAttributes.VCS_SCHEDULED_FILES_ATTR, scheduled);
java.io.File file = org.openide.filesystems.FileUtil.toFile(primary);
if (file != null) {
primary.setAttribute(VcsAttributes.VCS_SCHEDULING_MASTER_FILE_NAME_ATTR, file.getAbsolutePath());
}
} catch (IOException ioExc) {
if (endOfScheduling) endFileScheduling(name);
return false;
}
if (endOfScheduling) endFileScheduling(name);
return true;
}
private transient java.util.Map schedulingFilesByFolders;
*/
/**
* Remember the file as being scheduled for it's folder.
*/
/* private void startFileScheduling(String name) {
synchronized (this) {
if (schedulingFilesByFolders == null) {
schedulingFilesByFolders = new HashMap();
}
int index = name.lastIndexOf('/');
String dir = (index < 0) ? "" : name.substring(0, index);
String file = (index < 0) ? name : index < (name.length() - 1) ? name.substring(index + 1) : "";
Set files = (Set) schedulingFilesByFolders.get(dir);
if (files == null) {
files = new HashSet();
}
files.add(file);
schedulingFilesByFolders.put(dir, files);
}
}
*/
/**
* The scheduling action for this file was done, if no more actions are being
* processed in the file's folder, do a refresh of that folder.
*/
/* private void endFileScheduling(String name) {
Set files;
String dir;
synchronized (this) {
if (schedulingFilesByFolders == null) {
schedulingFilesByFolders = new HashMap();
}
int index = name.lastIndexOf('/');
dir = (index < 0) ? "" : name.substring(0, index);
String file = (index < 0) ? name : index < (name.length() - 1) ? name.substring(index + 1) : "";
files = (Set) schedulingFilesByFolders.get(dir);
if (files != null) {
files.remove(file);
if (files.size() == 0) files = null;
}
if (files == null) {
schedulingFilesByFolders.remove(dir);
}
}
*/
/* no refresh is needed after remove/add
if (files == null) {
performRefresh(dir, Boolean.FALSE);
}
*/
// }
public class AttrCommandDisplayer extends CommandDisplayerAdapter {
private FeatureDescriptor desc;
public AttrCommandDisplayer(FeatureDescriptor d) {
desc = d;
}
/**
* This is the last method to be called in the displayer.
* Is called when the execution finishes. Any filan touchups can be made here.
*/
public void showFinishedCommand() {
desc.setValue(VcsAttributes.VCS_ACTION_DONE, Boolean.TRUE);
}
/**
* this one is called when the command's execution fails for any reason.
*/
public void showExecutionFailed(Exception exception) {
desc.setValue(VcsAttributes.VCS_ACTION_DONE, Boolean.FALSE);
}
}
}
}
|