|
What this is
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.vcs.advanced.projectsettings;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyDescriptor;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.EntityReference;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.w3c.dom.DOMException;
import org.openide.ErrorManager;
import org.openide.cookies.InstanceCookie;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileChangeListener;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.modules.ModuleInfo;
import org.openide.util.Lookup;
import org.openide.util.LookupEvent;
import org.openide.util.LookupListener;
import org.openide.util.RequestProcessor;
import org.openide.util.Task;
import org.openide.util.TaskListener;
import org.openide.util.WeakListener;
import org.openide.util.lookup.InstanceContent;
import org.openide.xml.XMLUtil;
import org.netbeans.modules.vcscore.VcsConfigVariable;
import org.netbeans.modules.vcs.advanced.CommandLineVcsFileSystem;
import org.netbeans.modules.vcs.advanced.Profile;
import org.netbeans.modules.vcs.advanced.ProfilesFactory;
import org.netbeans.modules.vcs.advanced.commands.ConditionedCommands;
import org.netbeans.modules.vcs.advanced.commands.UserCommandIO;
import org.netbeans.modules.vcs.advanced.variables.Condition;
import org.netbeans.modules.vcs.advanced.variables.ConditionedVariables;
import org.netbeans.modules.vcs.advanced.variables.ConditionedVariablesUpdater;
import org.netbeans.modules.vcs.advanced.variables.VariableIO;
import org.netbeans.modules.vcscore.Variables;
/**
*
* @author Martin Entlicher
*/
public class CommandLineVcsFileSystemInstance extends Object implements InstanceCookie.Of, FileChangeListener {
/**
* The FS Settings file extension.
*/
public static final String SETTINGS_EXT = "xml"; // NOI18N
public static final String SETTINGS_ROOT_ELEM = "fssettings"; // NOI18N
public static final String FS_PROPERTIES_ELEM = "fsproperties"; // NOI18N
public static final String FS_PROPERTY_ELEM = "property"; // NOI18N
public static final String PROPERTY_NAME_ATTR = "name"; // NOI18N
public static final String PROPERTY_VALUE_TAG = "value"; // NOI18N
/** The DTD for a configuration profile. */
public static final String PUBLIC_ID = "-//NetBeans//DTD VCS Advanced FSSettings 1.0//EN"; // NOI18N
public static final String SYSTEM_ID = "http://www.netbeans.org/dtds/vcs-advanced-fssettings-1_0.dtd"; // NOI18N
/** This variable is expected to contain the profile module information.
* When the required module is not installed, the FS settings file is ignored. */
public static final String MODULE_INFO_CODE_NAME_BASE_VAR = "MODULE_INFORMATION_CODE_NAME_BASE"; // NOI18N
/** The last FS instance. */
private WeakReference weakFsInstance = new WeakReference(null);
private static PropertyDescriptor[] fsProperties;
private static HashMap fsPropertiesByName;
private FileObject fo;
/** The number of how many changes to the settings file should be ignored.
* Increased by save task, decreesed by the file change listener */
//private int numIgnoredFileChanges = 0;
private Document doc;
private InstanceContent ic;
private FSPropertyChangeListener fsPropertyChangeListener;
/** The profile's module information */
private String moduleCodeNameBase = null;
//private long timeIgnoreFileChange = 0L;
//private static final int FILE_MODIFICATION_TIME_RANGE = 500;
static {
try {
fsProperties = new PropertyDescriptor[] {
// Stuff from AbstractFileSystem & VcsFileSystem
new PropertyDescriptor("rootFile", CommandLineVcsFileSystem.class, "getWorkingDirectory", "setRootDirectory"),
new PropertyDescriptor("systemName", CommandLineVcsFileSystem.class, "getSystemName", "setAdjustedSystemName"),
new PropertyDescriptor("displayName", CommandLineVcsFileSystem.class, "getDisplayName", null),
new PropertyDescriptor("preferredSystemName", CommandLineVcsFileSystem.class, "getPreferredSystemName", "setPreferredSystemName"),
new PropertyDescriptor("refreshTime", CommandLineVcsFileSystem.class, "getRefreshTimeStored", "setRefreshTimeStored"),
new PropertyDescriptor("hidden", CommandLineVcsFileSystem.class, "isHidden", "setHidden"),
new PropertyDescriptor("readOnly", CommandLineVcsFileSystem.class, "isReadOnly", "setReadOnly"),
new PropertyDescriptor("debug", CommandLineVcsFileSystem.class, "getDebug", "setDebug"),
new PropertyDescriptor("password", CommandLineVcsFileSystem.class, "getPasswordStored", "setPassword"),
new PropertyDescriptor("rememberPassword", CommandLineVcsFileSystem.class, "isRememberPassword", "setRememberPassword"),
new PropertyDescriptor("annotationPattern", CommandLineVcsFileSystem.class, "getAnnotationPattern", "setAnnotationPattern"),
new PropertyDescriptor("multiFilesAnnotationTypes", CommandLineVcsFileSystem.class, "getMultiFileAnnotationTypes", "setMultiFileAnnotationTypes"),
new PropertyDescriptor("processUnimportantFiles", CommandLineVcsFileSystem.class, "isProcessUnimportantFiles", "setProcessUnimportantFiles"),
new PropertyDescriptor("promptForVarsForEachFile", CommandLineVcsFileSystem.class, "isPromptForVarsForEachFile", "setPromptForVarsForEachFile"),
new PropertyDescriptor("expertMode", CommandLineVcsFileSystem.class, "isExpertMode", "setExpertMode"),
new PropertyDescriptor("userParams", CommandLineVcsFileSystem.class, "getUserParams", "setUserParams"),
new PropertyDescriptor("numberOfFinishedCmdsToCollect", CommandLineVcsFileSystem.class, "getNumberOfFinishedCmdsToCollect", "setNumberOfFinishedCmdsToCollect"),
new PropertyDescriptor("offLine", CommandLineVcsFileSystem.class, "isOffLine", "setOffLine"),
new PropertyDescriptor("autoRefresh", CommandLineVcsFileSystem.class, "getAutoRefresh", "setAutoRefresh"),
new PropertyDescriptor("hideShadowFiles", CommandLineVcsFileSystem.class, "isHideShadowFiles", "setHideShadowFiles"),
new PropertyDescriptor("showDeadFiles", CommandLineVcsFileSystem.class, "isShowDeadFiles", "setShowDeadFiles"),
new PropertyDescriptor("commandNotification", CommandLineVcsFileSystem.class, "isCommandNotification", "setCommandNotification"),
new PropertyDescriptor("createBackupFiles", CommandLineVcsFileSystem.class, "isCreateBackupFiles", "setCreateBackupFiles"),
// Stuff from CommandLineVcsFileSystem
new PropertyDescriptor("config", CommandLineVcsFileSystem.class, "getConfig", "setConfig"),
new PropertyDescriptor("configFileName", CommandLineVcsFileSystem.class, "getConfigFileName", "setConfigFileName"),
new PropertyDescriptor("cacheId", CommandLineVcsFileSystem.class, "getCacheId", "setCacheId"),
new PropertyDescriptor("shortFileStatuses", CommandLineVcsFileSystem.class, "isShortFileStatuses", "setShortFileStatuses"), //NOI18N
new PropertyDescriptor("VFSMessageLength", CommandLineVcsFileSystem.class, "getVFSMessageLength", "setVFSMessageLength"), //NOI18N
new PropertyDescriptor("VFSShowMessage", CommandLineVcsFileSystem.class, "getVFSShowMessage", "setVFSShowMessage"), //NOI18N
new PropertyDescriptor("VFSShowLocalFiles", CommandLineVcsFileSystem.class, "getVFSShowLocalFiles", "setVFSShowLocalFiles"), //NOI18N
new PropertyDescriptor("VFSShowUnimportantFiles", CommandLineVcsFileSystem.class, "getVFSShowUnimportantFiles", "setVFSShowUnimportantFiles"), //NOI18N
new PropertyDescriptor("VFSShowDeadFiles", CommandLineVcsFileSystem.class, "getVFSShowDeadFiles", "setVFSShowDeadFiles"), // NOI18N
};
} catch (java.beans.IntrospectionException iexc) {
ErrorManager.getDefault().notify(iexc);
if (fsProperties == null) {
fsProperties = new PropertyDescriptor[0];
}
}
fsPropertiesByName = new HashMap(fsProperties.length);
for (int i = 0; i < fsProperties.length; i++) {
fsPropertiesByName.put(fsProperties[i].getName(), fsProperties[i]);
}
}
/** Creates new CommandLineVcsFileSystemInstance */
public CommandLineVcsFileSystemInstance(FileObject fo, Document doc, InstanceContent ic) {
this(fo, doc, ic, true);
}
/** Creates new CommandLineVcsFileSystemInstance */
private CommandLineVcsFileSystemInstance(FileObject fo, Document doc, InstanceContent ic, boolean readModuleInfo) {
this.fo = fo;
this.doc = doc;
this.ic = ic;
fo.addFileChangeListener(WeakListener.fileChange(this, fo));
if (readModuleInfo) {
try {
readModuleInfo(doc);
} catch (DOMException dex) {}
}
}
public Object instanceCreate() throws java.io.IOException, ClassNotFoundException {
//if (!isModuleEnabled()) return new BrokenSettings(instanceName());
//System.out.println("instanceCreate(), fo = "+fo);
CommandLineVcsFileSystem fs;
boolean needToReadFSProperties = false;
synchronized (this) {
fs = (CommandLineVcsFileSystem) weakFsInstance.get();
//System.out.println(" fs = "+((fs == null) ? "null" : fs.getSystemName()));
if (fs == null && fo != null) {
fs = new CommandLineVcsFileSystem(true);
needToReadFSProperties = true;
weakFsInstance = new WeakReference(fs);
}
}
FileObject fo = this.fo;
if (fo == null) return null;
if (needToReadFSProperties) {
try {
if (doc == null) {
try {
org.openide.loaders.XMLDataObject dobj = (org.openide.loaders.XMLDataObject) org.openide.loaders.DataObject.find(fo);
try {
doc = dobj.getDocument();
} catch (org.xml.sax.SAXException sexc) {
throw (java.io.IOException) ErrorManager.getDefault().annotate(new java.io.IOException(), sexc);
}
} catch (org.openide.loaders.DataObjectNotFoundException donfexc) {
throw (java.io.IOException) ErrorManager.getDefault().annotate(new java.io.IOException(), donfexc);
}
if (doc == null) return null;
}
readFSProperties(fs, doc);
} catch (DOMException dexc) {
ErrorManager.getDefault().notify(dexc);
}
fsPropertyChangeListener = new FSPropertyChangeListener(fo);
fs.addPropertyChangeListener(fsPropertyChangeListener); //WeakListener.propertyChange(fsPropertyChangeListener, fs));
//System.out.println(" PROPERTIES READ: fs = "+fs.getSystemName());
}
return fs;
}
public Class instanceClass() throws java.io.IOException, ClassNotFoundException {
if (!isModuleEnabled()) return BrokenSettings.class;
return CommandLineVcsFileSystem.class;
}
public boolean instanceOf(Class clazz) {
if (!isModuleEnabled()) return BrokenSettings.class.isAssignableFrom(clazz);
return (clazz.isAssignableFrom(CommandLineVcsFileSystem.class));
}
public String instanceName() {
return org.netbeans.modules.vcs.advanced.CommandLineVcsFileSystem.class.getName();
}
public void setInstance(CommandLineVcsFileSystem fs) {
CommandLineVcsFileSystem oldFs = (CommandLineVcsFileSystem) weakFsInstance.get();
if (oldFs == fs) return ;
//numIgnoredFileChanges = 0;
weakFsInstance = new WeakReference(fs);
if (fs != null) {
fsPropertyChangeListener = new FSPropertyChangeListener(fo);
fs.addPropertyChangeListener(fsPropertyChangeListener); //WeakListener.propertyChange(fsPropertyChangeListener, fs));
} else {
if (oldFs != null) {
oldFs.removePropertyChangeListener(fsPropertyChangeListener);
}
fsPropertyChangeListener = null;
}
}
public static DataObject createVcsInstanceDataObject(
FileObject folder, CommandLineVcsFileSystem fs, String settingsName) throws IOException {
return Creator.createVcsInstanceDataObject(folder, fs, settingsName);
}
private static DataObject storeVcsSettings(
FileObject folder, CommandLineVcsFileSystem fs, String settingsName) throws IOException {
FileObject fo;
fo = folder.createData(settingsName, SETTINGS_EXT);
Document doc = createEmptyFSPropertiesDocument();
try {
writeFSProperties(fs, doc);
} catch (org.w3c.dom.DOMException dExc) {
ErrorManager.getDefault().notify(dExc);
}
FileLock lock = fo.lock();
OutputStream out = fo.getOutputStream(lock);
try {
org.openide.xml.XMLUtil.write(doc, out, null);
} finally {
out.close();
lock.releaseLock();
}
try {
DataObject myXMLDataObject = DataObject.find(fo);
//((CommandLineVcsFileSystemInstance) myXMLDataObject.getCookie(org.openide.cookies.InstanceCookie.Of.class)).setInstance(this);
org.openide.util.Lookup instanceLookup = org.openide.loaders.Environment.find(myXMLDataObject);
CommandLineVcsFileSystemInstance myInstance =
(CommandLineVcsFileSystemInstance) instanceLookup.lookup(org.openide.cookies.InstanceCookie.class);
//myInstance.setIgnoreSubsequentFileChange(System.currentTimeMillis());
myInstance.setInstance(fs);
//firePropertyChange("writeAllProperties", null, null);
//System.out.println("createInstanceDataObject() = "+myXMLDataObject);
return myXMLDataObject;
} catch (DataObjectNotFoundException donfExc) {
IOException ioex = new IOException(donfExc.getLocalizedMessage());
ioex.initCause(donfExc);
throw ioex;
}
}
/** Ignore FileObject changes done right after this time.
*
public void setIgnoreSubsequentFileChange(long time) {
this.timeIgnoreFileChange = time + FILE_MODIFICATION_TIME_RANGE;
System.out.println("timeIgnoreFileChange = "+timeIgnoreFileChange);
}
*/
private final Object MODULE_LST_LOCK = new Object();
/** due to asynchronous firing of PROP_ENABLED from ModuleInfo implementation in core. */
private boolean wasEnabled;
/** listen on ModuleInfo if module is enabled/disabled. */
private PropertyChangeListener moduleListener;
private boolean isModuleEnabled() {
if (moduleCodeNameBase == null) return true;
final ModuleInfo m = getModule(moduleCodeNameBase);
if (m == null) return false;
synchronized (MODULE_LST_LOCK) {
if (moduleListener == null) {
wasEnabled = m.isEnabled();
moduleListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
InstanceContent ic = CommandLineVcsFileSystemInstance.this.ic;
if (ic == null) {
synchronized (MODULE_LST_LOCK) {
moduleListener = null; // I will be detached by GC.
}
return ;
}
if (ModuleInfo.PROP_ENABLED.equals(evt.getPropertyName()) &&
Boolean.FALSE.equals(evt.getNewValue())) {
// a module has been disabled, use full checks
//aModuleHasBeenChanged = true;
}
if (wasEnabled != m.isEnabled() && evt.getPropertyName().equals(ModuleInfo.PROP_ENABLED)) {
wasEnabled = m.isEnabled();
setInstance(null);
if (!wasEnabled) {
ic.remove((InstanceCookie) CommandLineVcsFileSystemInstance.this);
} else {
CommandLineVcsFileSystemInstance newFSInstance = new CommandLineVcsFileSystemInstance(fo, doc, ic, false);
newFSInstance.moduleCodeNameBase = CommandLineVcsFileSystemInstance.this.moduleCodeNameBase;
ic.add(newFSInstance);
}
}
}
};
m.addPropertyChangeListener(
WeakListener.propertyChange(moduleListener, m));
}
}
if (!m.isEnabled()) return false;
// is release number ok?
//if (recog.getCodeNameRelease() > m.getCodeNameRelease()) return false;
// is specification ok?
//return recog.getSpecificationVersion() == null ||
// recog.getSpecificationVersion().compareTo(m.getSpecificationVersion()) <= 0;
return true;
}
/** all modules
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 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.