2 * Copyright (C) 2006 Robin Rosenberg
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License, version 2.1, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org
.spearce
.egit
.core
;
19 import java
.io
.BufferedReader
;
20 import java
.io
.CharArrayWriter
;
21 import java
.io
.IOException
;
22 import java
.io
.InputStream
;
23 import java
.io
.InputStreamReader
;
25 import org
.eclipse
.core
.resources
.IFile
;
26 import org
.eclipse
.core
.resources
.IStorage
;
27 import org
.eclipse
.core
.runtime
.CoreException
;
28 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
29 import org
.eclipse
.jface
.text
.Document
;
30 import org
.eclipse
.jface
.text
.IDocument
;
31 import org
.eclipse
.team
.core
.RepositoryProvider
;
32 import org
.eclipse
.team
.core
.history
.IFileHistory
;
33 import org
.eclipse
.team
.core
.history
.IFileHistoryProvider
;
34 import org
.eclipse
.team
.core
.history
.IFileRevision
;
35 import org
.eclipse
.ui
.IEditorInput
;
36 import org
.eclipse
.ui
.ide
.ResourceUtil
;
37 import org
.eclipse
.ui
.texteditor
.ITextEditor
;
38 import org
.eclipse
.ui
.texteditor
.quickdiff
.IQuickDiffReferenceProvider
;
40 public class GitQuickDiffProvider
implements IQuickDiffReferenceProvider
{
44 private Document document
;
48 public void dispose() {
49 // No resources to free
52 public String
getId() {
56 public IDocument
getReference(IProgressMonitor monitor
)
57 throws CoreException
{
58 System
.out
.println("GitQuickDiffProvider.getReference()=" + document
);
59 document
= new Document();
60 System
.out
.println("GitQuickDiffProvider.getReference() file=" + file
);
62 RepositoryProvider provider
= RepositoryProvider
63 .getProvider(file
.getProject());
64 if (provider
!= null) {
66 IFileHistoryProvider fileHistoryProvider
= provider
67 .getFileHistoryProvider();
68 IFileHistory fileHistoryFor
= fileHistoryProvider
69 .getFileHistoryFor(file
,
70 IFileHistoryProvider
.SINGLE_REVISION
, null);
71 IFileRevision
[] revisions
= fileHistoryFor
.getFileRevisions();
72 if (revisions
!= null && revisions
.length
> 0) {
73 IFileRevision revision
= revisions
[0];
74 System
.out
.println("Comparing with "
75 + revision
.getContentIdentifier());
76 IStorage storage
= revision
.getStorage(null);
77 InputStream contents
= storage
.getContents();
78 BufferedReader in
= new BufferedReader(
79 new InputStreamReader(contents
));
80 final int DEFAULT_FILE_SIZE
= 15 * 1024;
82 CharArrayWriter caw
= new CharArrayWriter(DEFAULT_FILE_SIZE
);
83 char[] readBuffer
= new char[2048];
84 int n
= in
.read(readBuffer
);
86 caw
.write(readBuffer
, 0, n
);
87 n
= in
.read(readBuffer
);
89 String s
= caw
.toString();
90 System
.out
.println("GitQuickDiffProvider: got data:" + s
);
95 .println("GitQuickDiffProvider: got no data (new file?):");
97 } catch (CoreException e
) {
98 // TODO Auto-generated catch block
100 } catch (IOException e
) {
101 // TODO Auto-generated catch block
106 System
.out
.println("GitQuickDiffProvider: no provider found for "
112 public boolean isEnabled() {
116 public void setActiveEditor(ITextEditor editor
) {
117 System
.out
.println("GitQuickDiffProvider.setActiveEdtor()");
118 IEditorInput editorInput
= editor
.getEditorInput();
119 file
= ResourceUtil
.getFile(editorInput
);
122 public void setId(String id
) {