This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 57515
Collapse All | Expand All

(-)diff/DiffAction.java (-3 / +29 lines)
Lines 124-129 Link Here
124
     * This is expected not to be called in AWT thread.
124
     * This is expected not to be called in AWT thread.
125
     */
125
     */
126
    public static void performAction(FileObject fo1, FileObject fo2) {
126
    public static void performAction(FileObject fo1, FileObject fo2) {
127
        performAction(fo1, fo2, null);
128
    }
129
    /**
130
     * Shows the diff between two FileObject objects.
131
     * This is expected not to be called in AWT thread.
132
     * @param type Use the type of that FileObject to load both files.
133
     */
134
    static void performAction(FileObject fo1, FileObject fo2, FileObject type) {
127
        //System.out.println("performAction("+fo1+", "+fo2+")");
135
        //System.out.println("performAction("+fo1+", "+fo2+")");
128
        //doDiff(fo1, fo2);
136
        //doDiff(fo1, fo2);
129
        Diff diff = Diff.getDefault();
137
        Diff diff = Diff.getDefault();
Lines 135-151 Link Here
135
            return ;
143
            return ;
136
        }
144
        }
137
        Component tp;
145
        Component tp;
146
        Reader r1 = null;
147
        Reader r2 = null;
138
        try {
148
        try {
139
            EncodedReaderFactory rf = EncodedReaderFactory.getDefault();
149
            EncodedReaderFactory rf = EncodedReaderFactory.getDefault();
140
            Reader r1 = rf.getReader(fo1, rf.getEncoding(fo1));
150
            if (type != null) {
141
            Reader r2 = rf.getReader(fo2, rf.getEncoding(fo2));
151
                r1 = rf.getReader(fo1, rf.getEncoding(type), type);
152
                r2 = rf.getReader(fo2, rf.getEncoding(type), type);
153
            } else {
154
                r1 = rf.getReader(fo1, rf.getEncoding(fo1), fo2.getExt());
155
                r2 = rf.getReader(fo2, rf.getEncoding(fo2), fo1.getExt());
156
            }
157
            String mimeType;
158
            if (type != null) {
159
                mimeType = type.getMIMEType();
160
            } else {
161
                mimeType = fo1.getMIMEType();
162
            }
142
            tp = diff.createDiff(fo1.getNameExt(), FileUtil.getFileDisplayName(fo1),
163
            tp = diff.createDiff(fo1.getNameExt(), FileUtil.getFileDisplayName(fo1),
143
                                 r1,
164
                                 r1,
144
                                 fo2.getNameExt(), FileUtil.getFileDisplayName(fo2),
165
                                 fo2.getNameExt(), FileUtil.getFileDisplayName(fo2),
145
                                 r2, fo1.getMIMEType());
166
                                 r2, mimeType);
146
        } catch (IOException ioex) {
167
        } catch (IOException ioex) {
147
            ErrorManager.getDefault().notify(ioex);
168
            ErrorManager.getDefault().notify(ioex);
148
            return ;
169
            return ;
170
        } finally {
171
            try {
172
                if (r1 != null) r1.close();
173
                if (r2 != null) r2.close();
174
            } catch (IOException ioex) {}
149
        }
175
        }
150
        //System.out.println("tp = "+tp);
176
        //System.out.println("tp = "+tp);
151
        if (tp != null) {
177
        if (tp != null) {
(-)diff/EncodedReaderFactory.java (-8 / +22 lines)
Lines 104-110 Link Here
104
                file = FileUtil.normalizeFile(file);
104
                file = FileUtil.normalizeFile(file);
105
                FileObject fo = FileUtil.toFileObject(file);
105
                FileObject fo = FileUtil.toFileObject(file);
106
                if (fo != null) {
106
                if (fo != null) {
107
                    r = getReaderFromEditorSupport(fo);
107
                    r = getReaderFromEditorSupport(fo, fo);
108
                }
108
                }
109
            } catch (IllegalArgumentException iaex) {
109
            } catch (IllegalArgumentException iaex) {
110
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, iaex);
110
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, iaex);
Lines 121-126 Link Here
121
    }
121
    }
122
    
122
    
123
    public Reader getReader(FileObject fo, String encoding) throws FileNotFoundException {
123
    public Reader getReader(FileObject fo, String encoding) throws FileNotFoundException {
124
        return getReader(fo, encoding, fo.getExt());
125
    }
126
    
127
    public Reader getReader(FileObject fo, String encoding, String secondFileExt) throws FileNotFoundException {
128
        return getReader(fo, encoding, fo, secondFileExt);
129
    }
130
    
131
    public Reader getReader(FileObject fo, String encoding, FileObject type) throws FileNotFoundException {
132
        return getReader(fo, encoding, type, type.getExt());
133
    }
134
    
135
    private Reader getReader(FileObject fo, String encoding, FileObject type, String secondFileExt) throws FileNotFoundException {
124
        if (encoding != null) {
136
        if (encoding != null) {
125
            try {
137
            try {
126
                return new InputStreamReader(fo.getInputStream(), encoding);
138
                return new InputStreamReader(fo.getInputStream(), encoding);
Lines 129-140 Link Here
129
            }
141
            }
130
        }
142
        }
131
        Reader r = null;
143
        Reader r = null;
132
        String ext = fo.getExt();
144
        String ext = type.getExt();
133
        if (!"java".equalsIgnoreCase(ext)) {// We read the encoding for Java files explicitely
145
        if (!"java".equalsIgnoreCase(ext) || !ext.equals(secondFileExt)) {// We read the encoding for Java files explicitely
134
                                            // If it's not defined, read with default encoding from stream (because of guarded blocks)
146
                                            // If it's not defined, read with default encoding from stream (because of guarded blocks)
135
            r = getReaderFromEditorSupport(fo);
147
                                            // But when the extensions of the two files are different (comparing Java files with something else),
148
                                            // we have to use the Document approach for both due to possible different line-endings.
149
            r = getReaderFromEditorSupport(fo, type);
136
            if (r == null) {
150
            if (r == null) {
137
                r = getReaderFromKit(null, fo, fo.getMIMEType());
151
                r = getReaderFromKit(null, fo, type.getMIMEType());
138
            }
152
            }
139
        }
153
        }
140
        if (r == null) {
154
        if (r == null) {
Lines 145-159 Link Here
145
    }
159
    }
146
    
160
    
147
    /** @return The reader or <code>null</code>. */
161
    /** @return The reader or <code>null</code>. */
148
    private Reader getReaderFromEditorSupport(FileObject fo) throws FileNotFoundException {
162
    private Reader getReaderFromEditorSupport(FileObject fo, FileObject type) throws FileNotFoundException {
149
        //System.out.println("getReaderFromEditorSupport("+fo+")");
163
        //System.out.println("getReaderFromEditorSupport("+fo+")");
150
        DataObject dobj;
164
        DataObject dobj;
151
        try {
165
        try {
152
            dobj = DataObject.find(fo);
166
            dobj = DataObject.find(type);
153
        } catch (DataObjectNotFoundException donfex) {
167
        } catch (DataObjectNotFoundException donfex) {
154
            return null;
168
            return null;
155
        }
169
        }
156
        if (!fo.equals(dobj.getPrimaryFile())) {
170
        if (!type.equals(dobj.getPrimaryFile())) {
157
            return null;
171
            return null;
158
        }
172
        }
159
        EditCookie edit = (EditCookie) dobj.getCookie(EditCookie.class);
173
        EditCookie edit = (EditCookie) dobj.getCookie(EditCookie.class);
(-)diff/PatchAction.java (-3 / +3 lines)
Lines 246-256 Link Here
246
        } catch (IOException ioex) {
246
        } catch (IOException ioex) {
247
            return null;
247
            return null;
248
        } finally {
248
        } finally {
249
            if (lock != null) lock.releaseLock();
250
            try {
249
            try {
251
                if (in != null) in.close();
250
                if (in != null) in.close();
252
                if (out != null) out.close();
251
                if (out != null) out.close();
253
            } catch (IOException ioex) {}
252
            } catch (IOException ioex) {}
253
            if (lock != null) lock.releaseLock();
254
        }
254
        }
255
    }
255
    }
256
256
Lines 268-274 Link Here
268
        OutputStream out = null;
268
        OutputStream out = null;
269
        try {
269
        try {
270
            Reader patched = Patch.apply(diffs, new InputStreamReader(fo.getInputStream(), PATCHING_IO_ENCODING));
270
            Reader patched = Patch.apply(diffs, new InputStreamReader(fo.getInputStream(), PATCHING_IO_ENCODING));
271
            FileUtil.copy(in = new ReaderInputStream(patched), out = new FileOutputStream(tmp));
271
            FileUtil.copy(in = new ReaderInputStream(patched, PATCHING_IO_ENCODING), out = new FileOutputStream(tmp));
272
        } catch (IOException ioex) {
272
        } catch (IOException ioex) {
273
//            ErrorManager.getDefault().notify(ErrorManager.getDefault().annotate(ioex,
273
//            ErrorManager.getDefault().notify(ErrorManager.getDefault().annotate(ioex,
274
//                NbBundle.getMessage(PatchAction.class, "EXC_PatchApplicationFailed", ioex.getLocalizedMessage(), fo.getNameExt())));
274
//                NbBundle.getMessage(PatchAction.class, "EXC_PatchApplicationFailed", ioex.getLocalizedMessage(), fo.getNameExt())));
Lines 311-317 Link Here
311
        for (int i = 0; i < files.size(); i++) {
311
        for (int i = 0; i < files.size(); i++) {
312
            FileObject file = (FileObject) files.get(i);
312
            FileObject file = (FileObject) files.get(i);
313
            FileObject backup = (FileObject) backups.get(file);
313
            FileObject backup = (FileObject) backups.get(file);
314
            DiffAction.performAction(backup, file);
314
            DiffAction.performAction(backup, file, file);
315
        }
315
        }
316
    }
316
    }
317
317

Return to bug 57515