# This patch file was generated by NetBeans IDE # It uses platform neutral UTF-8 encoding and \n newlines. --- Base (BASE) +++ Locally Modified (Based On LOCAL) @@ -45,12 +45,8 @@ package org.netbeans.modules.project.ant; import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.lang.ref.Reference; import java.lang.ref.WeakReference; @@ -168,7 +164,7 @@ public @Override boolean isProject(FileObject dir) { File dirF = FileUtil.toFile(dir); if (dirF == null) { - return false; + return dir.getFileObject("nbproject/project.xml") != null; } // Just check whether project.xml exists. Do not attempt to parse it, etc. // Do not use FileObject.getFileObject since that may load other sister files. @@ -177,21 +173,24 @@ } public @Override Result isProject2(FileObject projectDirectory) { + boolean virtual = false; if (FileUtil.toFile(projectDirectory) == null) { - return null; + virtual = true; } FileObject projectFile = projectDirectory.getFileObject(PROJECT_XML_PATH); //#54488: Added check for virtual if (projectFile == null || !projectFile.isData() || projectFile.isVirtual()) { return null; } + if (!virtual) { File projectDiskFile = FileUtil.toFile(projectFile); //#63834: if projectFile exists and projectDiskFile does not, do nothing: if (projectDiskFile == null) { return null; } + } try { - Document projectXml = loadProjectXml(projectDiskFile); + Document projectXml = loadProjectXml(projectFile); if (projectXml != null) { Element typeEl = XMLUtil.findElement(projectXml.getDocumentElement(), "type", PROJECT_NS); // NOI18N if (typeEl != null) { @@ -218,9 +217,10 @@ public @Override Project loadProject(FileObject projectDirectory, ProjectState state) throws IOException { + boolean virtual = false; if (FileUtil.toFile(projectDirectory) == null) { LOG.log(Level.FINE, "no disk dir {0}", projectDirectory); - return null; + virtual = true; } FileObject projectFile = projectDirectory.getFileObject(PROJECT_XML_PATH); //#54488: Added check for virtual @@ -229,12 +229,14 @@ return null; } File projectDiskFile = FileUtil.toFile(projectFile); + if (!virtual) { //#63834: if projectFile exists and projectDiskFile does not, do nothing: if (projectDiskFile == null) { LOG.log(Level.FINE, "{0} not mappable to file", projectFile); return null; } - Document projectXml = loadProjectXml(projectDiskFile); + } + Document projectXml = loadProjectXml(projectFile); if (projectXml == null) { LOG.log(Level.FINE, "could not load {0}", projectDiskFile); return null; @@ -320,17 +322,10 @@ LOG.fine(b.toString()); } } - private Document loadProjectXml(File projectDiskFile) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - InputStream is = new FileInputStream(projectDiskFile); - try { - FileUtil.copy(is, baos); - } finally { - is.close(); - } - byte[] data = baos.toByteArray(); + private Document loadProjectXml(FileObject projectDiskFile) throws IOException { + byte[] data = projectDiskFile.asBytes(); InputSource src = new InputSource(new ByteArrayInputStream(data)); - src.setSystemId(projectDiskFile.toURI().toString()); + src.setSystemId(projectDiskFile.getURL().toString()); try { // Document projectXml = XMLUtil.parse(src, false, true, Util.defaultErrorHandler(), null); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -353,14 +348,14 @@ LOG.log(Level.FINE, "got namespace {0}", namespace); if (!PROJECT_NS.equals(namespace)) { LOG.log(Level.FINE, "{0} had wrong root element namespace {1} when parsed from {2}", - new Object[] {projectDiskFile, namespace, baos}); + new Object[] {projectDiskFile, namespace, data}); dumpFields(projectXml); dumpFields(projectEl); return null; } if (!"project".equals(projectEl.getLocalName())) { // NOI18N LOG.log(Level.FINE, "{0} had wrong root element name {1} when parsed from {2}", - new Object[] {projectDiskFile, projectEl.getLocalName(), baos}); + new Object[] {projectDiskFile, projectEl.getLocalName(), data}); return null; } // #142680: try to cache CRC-32s of project.xml files known to be valid, since validation can be slow. @@ -395,7 +390,7 @@ // Try to correct on disk if possible. // (If not, any changes from the IDE will write out a corrected file anyway.) if (projectDiskFile.canWrite()) { - OutputStream os = new FileOutputStream(projectDiskFile); + OutputStream os = projectDiskFile.getOutputStream(); try { XMLUtil.write(projectXml, os, "UTF-8"); } finally {