Index: diff/DiffAction.java =================================================================== RCS file: /cvs/diff/src/org/netbeans/modules/diff/DiffAction.java,v --- diff/DiffAction.java 5 Apr 2005 13:37:56 -0000 1.26 +++ diff/DiffAction.java 13 Apr 2005 14:00:18 -0000 @@ -124,6 +124,14 @@ * This is expected not to be called in AWT thread. */ public static void performAction(FileObject fo1, FileObject fo2) { + performAction(fo1, fo2, null); + } + /** + * Shows the diff between two FileObject objects. + * This is expected not to be called in AWT thread. + * @param type Use the type of that FileObject to load both files. + */ + static void performAction(FileObject fo1, FileObject fo2, FileObject type) { //System.out.println("performAction("+fo1+", "+fo2+")"); //doDiff(fo1, fo2); Diff diff = Diff.getDefault(); @@ -135,17 +143,35 @@ return ; } Component tp; + Reader r1 = null; + Reader r2 = null; try { EncodedReaderFactory rf = EncodedReaderFactory.getDefault(); - Reader r1 = rf.getReader(fo1, rf.getEncoding(fo1)); - Reader r2 = rf.getReader(fo2, rf.getEncoding(fo2)); + if (type != null) { + r1 = rf.getReader(fo1, rf.getEncoding(type), type); + r2 = rf.getReader(fo2, rf.getEncoding(type), type); + } else { + r1 = rf.getReader(fo1, rf.getEncoding(fo1), fo2.getExt()); + r2 = rf.getReader(fo2, rf.getEncoding(fo2), fo1.getExt()); + } + String mimeType; + if (type != null) { + mimeType = type.getMIMEType(); + } else { + mimeType = fo1.getMIMEType(); + } tp = diff.createDiff(fo1.getNameExt(), FileUtil.getFileDisplayName(fo1), r1, fo2.getNameExt(), FileUtil.getFileDisplayName(fo2), - r2, fo1.getMIMEType()); + r2, mimeType); } catch (IOException ioex) { ErrorManager.getDefault().notify(ioex); return ; + } finally { + try { + if (r1 != null) r1.close(); + if (r2 != null) r2.close(); + } catch (IOException ioex) {} } //System.out.println("tp = "+tp); if (tp != null) { Index: diff/EncodedReaderFactory.java =================================================================== RCS file: /cvs/diff/src/org/netbeans/modules/diff/EncodedReaderFactory.java,v --- diff/EncodedReaderFactory.java 8 Apr 2005 09:15:02 -0000 1.4 +++ diff/EncodedReaderFactory.java 13 Apr 2005 14:00:18 -0000 @@ -104,7 +104,7 @@ file = FileUtil.normalizeFile(file); FileObject fo = FileUtil.toFileObject(file); if (fo != null) { - r = getReaderFromEditorSupport(fo); + r = getReaderFromEditorSupport(fo, fo); } } catch (IllegalArgumentException iaex) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, iaex); @@ -121,6 +121,18 @@ } public Reader getReader(FileObject fo, String encoding) throws FileNotFoundException { + return getReader(fo, encoding, fo.getExt()); + } + + public Reader getReader(FileObject fo, String encoding, String secondFileExt) throws FileNotFoundException { + return getReader(fo, encoding, fo, secondFileExt); + } + + public Reader getReader(FileObject fo, String encoding, FileObject type) throws FileNotFoundException { + return getReader(fo, encoding, type, type.getExt()); + } + + private Reader getReader(FileObject fo, String encoding, FileObject type, String secondFileExt) throws FileNotFoundException { if (encoding != null) { try { return new InputStreamReader(fo.getInputStream(), encoding); @@ -129,12 +141,14 @@ } } Reader r = null; - String ext = fo.getExt(); - if (!"java".equalsIgnoreCase(ext)) {// We read the encoding for Java files explicitely + String ext = type.getExt(); + if (!"java".equalsIgnoreCase(ext) || !ext.equals(secondFileExt)) {// We read the encoding for Java files explicitely // If it's not defined, read with default encoding from stream (because of guarded blocks) - r = getReaderFromEditorSupport(fo); + // But when the extensions of the two files are different (comparing Java files with something else), + // we have to use the Document approach for both due to possible different line-endings. + r = getReaderFromEditorSupport(fo, type); if (r == null) { - r = getReaderFromKit(null, fo, fo.getMIMEType()); + r = getReaderFromKit(null, fo, type.getMIMEType()); } } if (r == null) { @@ -145,15 +159,15 @@ } /** @return The reader or null. */ - private Reader getReaderFromEditorSupport(FileObject fo) throws FileNotFoundException { + private Reader getReaderFromEditorSupport(FileObject fo, FileObject type) throws FileNotFoundException { //System.out.println("getReaderFromEditorSupport("+fo+")"); DataObject dobj; try { - dobj = DataObject.find(fo); + dobj = DataObject.find(type); } catch (DataObjectNotFoundException donfex) { return null; } - if (!fo.equals(dobj.getPrimaryFile())) { + if (!type.equals(dobj.getPrimaryFile())) { return null; } EditCookie edit = (EditCookie) dobj.getCookie(EditCookie.class); Index: diff/PatchAction.java =================================================================== RCS file: /cvs/diff/src/org/netbeans/modules/diff/PatchAction.java,v --- diff/PatchAction.java 5 Apr 2005 13:37:57 -0000 1.24 +++ diff/PatchAction.java 13 Apr 2005 14:00:18 -0000 @@ -246,11 +246,11 @@ } catch (IOException ioex) { return null; } finally { - if (lock != null) lock.releaseLock(); try { if (in != null) in.close(); if (out != null) out.close(); } catch (IOException ioex) {} + if (lock != null) lock.releaseLock(); } } @@ -268,7 +268,7 @@ OutputStream out = null; try { Reader patched = Patch.apply(diffs, new InputStreamReader(fo.getInputStream(), PATCHING_IO_ENCODING)); - FileUtil.copy(in = new ReaderInputStream(patched), out = new FileOutputStream(tmp)); + FileUtil.copy(in = new ReaderInputStream(patched, PATCHING_IO_ENCODING), out = new FileOutputStream(tmp)); } catch (IOException ioex) { // ErrorManager.getDefault().notify(ErrorManager.getDefault().annotate(ioex, // NbBundle.getMessage(PatchAction.class, "EXC_PatchApplicationFailed", ioex.getLocalizedMessage(), fo.getNameExt()))); @@ -311,7 +311,7 @@ for (int i = 0; i < files.size(); i++) { FileObject file = (FileObject) files.get(i); FileObject backup = (FileObject) backups.get(file); - DiffAction.performAction(backup, file); + DiffAction.performAction(backup, file, file); } }