Index: src/org/netbeans/modules/web/context/Bundle.properties =================================================================== RCS file: /cvs/web/core/src/org/netbeans/modules/web/context/Bundle.properties,v retrieving revision 1.11 diff -c -r1.11 Bundle.properties *** src/org/netbeans/modules/web/context/Bundle.properties 14 Mar 2003 16:19:33 -0000 1.11 --- src/org/netbeans/modules/web/context/Bundle.properties 24 Mar 2003 18:04:46 -0000 *************** *** 78,80 **** --- 78,82 ---- CTL_WarArchivesMask=WAR File (*.WAR) CTL_NewWebModuleMountWizardPanel.newFolderBrowseB.mnemonic=R + + ERR_cannotDeleteWebInf=WEB-INF object cannot be deleted. Index: src/org/netbeans/modules/web/context/ProjectViewManager.java =================================================================== RCS file: /cvs/web/core/src/org/netbeans/modules/web/context/ProjectViewManager.java,v retrieving revision 1.1 diff -c -r1.1 ProjectViewManager.java *** src/org/netbeans/modules/web/context/ProjectViewManager.java 6 Mar 2003 16:04:33 -0000 1.1 --- src/org/netbeans/modules/web/context/ProjectViewManager.java 24 Mar 2003 18:04:47 -0000 *************** *** 34,40 **** private boolean projectSwitchInProgress = false; ! /** Private constructor. */ public ProjectViewManager() { } --- 34,43 ---- private boolean projectSwitchInProgress = false; ! private java.util.Map contexts = new java.util.HashMap (); ! ! /** Private constructor. ! * XXX should be really private */ public ProjectViewManager() { } *************** *** 79,84 **** --- 82,88 ---- if (dobj instanceof WebContextObject) { WebContextObject wc = (WebContextObject)dobj; wc.setupContext(); + registerWebContext (fs, wc); } else { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new RuntimeException(fs.getSystemName())); *************** *** 124,142 **** } public void fileSystemRemoved(RepositoryEvent ev) { - // just check the project if (!projectSwitchInProgress) { FileSystem fs = ev.getFileSystem(); FileObject root = fs.getRoot(); ! try { ! DataObject dobj = DataObject.find(root); ! if (dobj instanceof WebContextObject) { ! ((WebContextObject)dobj).destroyContext(); ! } ! } ! catch (DataObjectNotFoundException e) { ! ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); } } } --- 128,141 ---- } public void fileSystemRemoved(RepositoryEvent ev) { // just check the project if (!projectSwitchInProgress) { FileSystem fs = ev.getFileSystem(); FileObject root = fs.getRoot(); ! DataObject dobj = (WebContextObject)contexts.remove (fs); ! ! if (dobj != null) { ! ((WebContextObject)dobj).destroyContext(); } } } *************** *** 147,155 **** --- 146,162 ---- public void propertyChange(java.beans.PropertyChangeEvent evt) { if (CurrentProjectNode.PROP_PROJECT_BEFORE_OPEN.equals(evt.getPropertyName())) { projectSwitchInProgress = true; + contexts.clear (); } if (CurrentProjectNode.PROP_PROJECT_AFTER_OPEN.equals(evt.getPropertyName())) { projectSwitchInProgress = false; + } + } + + private void registerWebContext (FileSystem fs, WebContextObject wco) { + // only the first WCO is right - when unmounting there can be another one created after setValid call + if (!contexts.containsKey (fs)) { + contexts.put (fs, wco); } } Index: src/org/netbeans/modules/web/context/WebClassesObject.java =================================================================== RCS file: /cvs/web/core/src/org/netbeans/modules/web/context/WebClassesObject.java,v retrieving revision 1.5 diff -c -r1.5 WebClassesObject.java *** src/org/netbeans/modules/web/context/WebClassesObject.java 4 Dec 2002 15:05:51 -0000 1.5 --- src/org/netbeans/modules/web/context/WebClassesObject.java 24 Mar 2003 18:04:47 -0000 *************** *** 47,53 **** try { WebContextObject wc = WebContextLoader.findContext(getPrimaryFile().getFileSystem()); if (wc != null) { ! classesFSRoot = (DataFolder) DataObject.find(wc.getClassesBase().getRoot()); } else { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new NullPointerException()); --- 47,56 ---- try { WebContextObject wc = WebContextLoader.findContext(getPrimaryFile().getFileSystem()); if (wc != null) { ! FileSystem classesFS = wc.getClassesBase(); ! if (classesFS != null) { ! classesFSRoot = (DataFolder) DataObject.find(classesFS.getRoot()); ! } } else { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new NullPointerException()); Index: src/org/netbeans/modules/web/context/WebContextLoader.java =================================================================== RCS file: /cvs/web/core/src/org/netbeans/modules/web/context/WebContextLoader.java,v retrieving revision 1.12 diff -c -r1.12 WebContextLoader.java *** src/org/netbeans/modules/web/context/WebContextLoader.java 6 Mar 2003 16:04:34 -0000 1.12 --- src/org/netbeans/modules/web/context/WebContextLoader.java 24 Mar 2003 18:04:47 -0000 *************** *** 148,154 **** public static boolean isWebApplication(FileSystem documentBase) { if (documentBase == Repository.getDefault().getDefaultFileSystem()) return false; ! return (documentBase.findResource(WebContextObject.FOLDER_WEB_INF + "/web.xml") != null);//NOI18N } public static boolean isWebApplication(DataObject dobj) { --- 148,157 ---- public static boolean isWebApplication(FileSystem documentBase) { if (documentBase == Repository.getDefault().getDefaultFileSystem()) return false; ! FileObject webinfFo = documentBase.findResource(WebContextObject.FOLDER_WEB_INF); ! return (webinfFo != null ! && !Boolean.TRUE.equals (webinfFo.getAttribute (WebInfObject.ATTR_PENDING_DELETE)) ! && webinfFo.getFileObject ("web.xml") != null); // NOI18N } public static boolean isWebApplication(DataObject dobj) { Index: src/org/netbeans/modules/web/context/WebContextObject.java =================================================================== RCS file: /cvs/web/core/src/org/netbeans/modules/web/context/WebContextObject.java,v retrieving revision 1.32 diff -c -r1.32 WebContextObject.java *** src/org/netbeans/modules/web/context/WebContextObject.java 14 Mar 2003 08:53:38 -0000 1.32 --- src/org/netbeans/modules/web/context/WebContextObject.java 24 Mar 2003 18:04:47 -0000 *************** *** 161,167 **** private transient String appName; private transient FileSystem classesFS; ! private transient Hashtable libs = new Hashtable(); private transient WebModuleCookie cookie; private transient ServerExecSupport serverExecSupport; private transient Set contextDeleteListenerSet = null; --- 161,167 ---- private transient String appName; private transient FileSystem classesFS; ! private Hashtable libs = new Hashtable(); private transient WebModuleCookie cookie; private transient ServerExecSupport serverExecSupport; private transient Set contextDeleteListenerSet = null; *************** *** 177,182 **** --- 177,184 ---- /** Creates new WebContextObject. */ public WebContextObject(FileObject fo,DataLoader dl) throws IOException { super(fo,dl); + //System.out.println("WebContextObject. "+fo+", "+System.identityHashCode (this)); + //Thread.dumpStack (); documentBase = fo.getFileSystem(); init(); } *************** *** 186,191 **** --- 188,213 ---- //setupContext(); } + public String debugToString() { + try { + FileSystem fs = getPrimaryFile().getFileSystem(); + return "WebContextObject: " + this + "\n" + // NOI18N + " fs : " + fs.getSystemName() + "\n" + // NOI18N + " valid : " + isValid() + "\n" + // NOI18N + " mounted: " + isMounted() + "\n"; // NOI18N + } + catch (FileStateInvalidException e) { + e.printStackTrace(); + return this.toString(); + } + } + + private boolean isMounted() throws FileStateInvalidException { + FileSystem fs = getPrimaryFile().getFileSystem(); + FileSystem fs2 = Repository.getDefault().findFileSystem(fs.getSystemName()); + return fs == fs2; + } + /* public void debugPrintClasses() { System.out.println("WEBCONTEXTOBJECT: classes is " + classesFS); }*/ *************** *** 266,271 **** --- 288,303 ---- if (debug) err.log (ErrorManager.INFORMATIONAL, "WebContextObject["+documentBase+"]:: disabled()");//NOI18N } + /* + public void setValid(boolean valid) throws PropertyVetoException { + if (debug) err.log (ErrorManager.INFORMATIONAL, "WebContextObject["+documentBase+"]:: setValid("+valid+")");//NOI18N + if (!valid) { + removeProjectView(); + } + super.setValid (valid); + } + */ + public void handleDelete() { if (debug) err.log (ErrorManager.INFORMATIONAL, "WebContextObject["+documentBase+"]:: handleDelete()");//NOI18N *************** *** 298,313 **** private void removeProjectView() { final FileObject prjV = projectView (); if (prjV != null) { ! RequestProcessor.getDefault ().post(new Runnable() { ! public void run() { try { DataObject.find(prjV).delete(); } catch (Exception e) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); } ! } ! }); } } --- 330,345 ---- private void removeProjectView() { final FileObject prjV = projectView (); if (prjV != null) { ! // RequestProcessor.getDefault ().post(new Runnable() { ! // public void run() { try { DataObject.find(prjV).delete(); } catch (Exception e) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); } ! // } ! // }); } } *************** *** 513,518 **** --- 545,551 ---- /** Posts request for unmounting of FileSystem. */ static void removeFS(FileSystem fs) { + if (debug) err.log (ErrorManager.INFORMATIONAL, "WebContextObject]:: removeFS "+fs);//NOI18N FSRemover rem = new FSRemover(fs, null); requestProcessor ().post(rem); } *************** *** 784,795 **** void unmountLib(FileObject lib) { FileSystem fs = removeLib(lib); ! removeFS(fs); } FileSystem removeLib(FileObject lib) { ! if (debug) err.log (ErrorManager.INFORMATIONAL, "WebContextObject[" + documentBase + "]::removeLib " + lib + " libs.size()=" + libs.size());//NOI18N ! if (debug) err.log (ErrorManager.INFORMATIONAL, " libs.containskey(lib)=" + libs.containsKey(lib));//NOI18N // try not firing the web context event. perhaps this is // holding on to the lib and not letting us delete. --- 817,833 ---- void unmountLib(FileObject lib) { FileSystem fs = removeLib(lib); ! if (fs != null) { ! // this can be already unmounted (once from destroyContext, 2nd attempt from LibMountingListener) ! removeFS(fs); ! } } FileSystem removeLib(FileObject lib) { ! if (debug) { ! err.log (ErrorManager.INFORMATIONAL, "WebContextObject[" + documentBase + "]::removeLib " + lib + " libs.size()=" + libs.size()+//NOI18N ! "\n libs.containskey(lib)=" + libs.containsKey(lib));//NOI18N ! } // try not firing the web context event. perhaps this is // holding on to the lib and not letting us delete. *************** *** 855,866 **** ErrorManager.getDefault().notify(ErrorManager.WARNING, t); ! if(debug) System.err.println("WCO::mountLib on thread caught exception mounting " + lib);//NOI18N ! if(debug) System.err.println(" ex: " + ex); ! if(debug) System.err.println(" msg: " + msg); ! if(debug) System.err.println(" ex.getMessage(): " + ex.getMessage()); ! if(debug) System.err.println(" ex.getLocalizedMessage(): " + ex.getMessage()); ! if (debug) ex.printStackTrace(); } } }); --- 893,906 ---- ErrorManager.getDefault().notify(ErrorManager.WARNING, t); ! if(debug) { ! err.log (ErrorManager.INFORMATIONAL, "WCO::mountLib on thread caught exception mounting " + lib +//NOI18N ! "\n ex: " + ex + // NOI18N ! "\n msg: " + msg + // NOI18N ! "\n ex.getMessage(): " + ex.getMessage() + // NOI18N ! "\n ex.getLocalizedMessage(): " + ex.getMessage()); // NOI18N ! err.notify (ErrorManager.INFORMATIONAL, ex); ! } } } }); *************** *** 969,975 **** libs.put(lib,fs); // now fire web context event to tell other subsystems about this lib fireWebContextEvent(new WebContextEvent(this,lib,true)); ! if (debugdetail) { err.log (ErrorManager.INFORMATIONAL, "WCO: mounted lib. libs hashtable contains:");//NOI18N for (Enumeration en = libs.keys(); en.hasMoreElements(); ) { FileObject fsi = (FileObject)en.nextElement(); --- 1009,1015 ---- libs.put(lib,fs); // now fire web context event to tell other subsystems about this lib fireWebContextEvent(new WebContextEvent(this,lib,true)); ! if (debug) { err.log (ErrorManager.INFORMATIONAL, "WCO: mounted lib. libs hashtable contains:");//NOI18N for (Enumeration en = libs.keys(); en.hasMoreElements(); ) { FileObject fsi = (FileObject)en.nextElement(); *************** *** 1051,1061 **** --- 1091,1107 ---- return WebDataFactory.getFactory().findWebModule(getPrimaryFile()); } + /** Returns the classes filesystem associated with this WebContextObject. + * The method may block until the classes mounting process is finished, + * if it is in progress. May return null if this object's filesystem is not + * currently mounted. + */ public FileSystem getClassesBase() throws IOException { associateClassesFS(); if (classesFS != null) { return classesFS; } + if (isMounted()) { // should not return null, so we wait for the mounting requestprocessor long t = System.currentTimeMillis(); for (int i = 0; i < 200; i++) { // 10 seconds *************** *** 1072,1077 **** --- 1118,1125 ---- } } throw new IllegalStateException("" + (System.currentTimeMillis() - t)); // NOI18N + } + return null; } public FileSystem getDocumentBase() { Index: src/org/netbeans/modules/web/context/WebInfObject.java =================================================================== RCS file: /cvs/web/core/src/org/netbeans/modules/web/context/WebInfObject.java,v retrieving revision 1.13 diff -c -r1.13 WebInfObject.java *** src/org/netbeans/modules/web/context/WebInfObject.java 12 Mar 2003 14:40:08 -0000 1.13 --- src/org/netbeans/modules/web/context/WebInfObject.java 24 Mar 2003 18:04:47 -0000 *************** *** 54,59 **** --- 54,61 ---- public static final String PROP_SERVER_INSTANCE = "serverInstnace";// NOI18N private static final String ICON_LOC = "org/netbeans/modules/web/context/resources/webmodule.gif"; // NOI18N + /** Flag used to mark WEB-INF object that is going to be deleted. */ + static final String ATTR_PENDING_DELETE = "pendingDelete"; private static List cookieGenerators = new LinkedList(); private static List sheetGenerators = new LinkedList(); *************** *** 165,190 **** } public void handleDelete() throws java.io.IOException { try { ! WebContextObject wco = WebContextLoader.findContext(getPrimaryFile().getFileSystem()); if(wco != null) { wco.handleWebInfDelete(); ! wco.destroyContext(); ! ! super.handleDelete(); ! wco.setValid(false); } } catch (PropertyVetoException e) { ! ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); } ! catch (FileStateInvalidException e) { ! ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); ! } ! catch (DataObjectNotFoundException de) { ! ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, de); ! } } public boolean isCopyAllowed() { return false;} --- 167,193 ---- } public void handleDelete() throws java.io.IOException { + WebContextObject wco; try { ! wco = WebContextLoader.findContext(getPrimaryFile().getFileSystem()); if(wco != null) { wco.handleWebInfDelete(); ! getPrimaryFile ().setAttribute (ATTR_PENDING_DELETE, Boolean.TRUE); wco.setValid(false); + wco.destroyContext(); } + } + catch (FileStateInvalidException e) { + java.io.IOException ioe = new java.io.IOException (NbBundle.getMessage (WebContextObject.class, "ERR_cannotDeleteWebInf")); + ErrorManager.getDefault().annotate (new java.io.IOException (), e); + throw ioe; } catch (PropertyVetoException e) { ! java.io.IOException ioe = new java.io.IOException (NbBundle.getMessage (WebContextObject.class, "ERR_cannotDeleteWebInf")); ! ErrorManager.getDefault().annotate (new java.io.IOException (), e); ! throw ioe; } ! super.handleDelete(); } public boolean isCopyAllowed() { return false;}