Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 128117 Details for
Bug 265030
[Patch] Create patch for any 2 IResources
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Patch v3
patch_v3.txt (text/plain), 36.95 KB, created by
Krzysztof Pog這dzi雟ki
on 2009-03-09 18:22:36 EDT
(
hide
)
Description:
Patch v3
Filename:
MIME Type:
Creator:
Krzysztof Pog這dzi雟ki
Created:
2009-03-09 18:22:36 EDT
Size:
36.95 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.compare >Index: compare/org/eclipse/compare/internal/GenerateDiffFileWizard.java >=================================================================== >--- compare/org/eclipse/compare/internal/GenerateDiffFileWizard.java 1 Jan 1970 00:00:00 -0000 >+++ compare/org/eclipse/compare/internal/GenerateDiffFileWizard.java 1 Jan 1970 00:00:00 -0000 >@@ -15,13 +15,26 @@ > > import java.io.File; > import java.io.IOException; >+import java.io.InputStream; > import java.net.MalformedURLException; > import java.net.URL; > import java.util.ArrayList; > import java.util.Iterator; > import java.util.List; > >+import org.eclipse.compare.CompareConfiguration; >+import org.eclipse.compare.CompareEditorInput; >+import org.eclipse.compare.ITypedElement; >+import org.eclipse.compare.ResourceNode; >+import org.eclipse.compare.contentmergeviewer.ITokenComparator; >+import org.eclipse.compare.contentmergeviewer.TokenComparator; >+import org.eclipse.compare.internal.ResourceCompareInput.FilteredBufferedResourceNode; > import org.eclipse.compare.internal.merge.DocumentMerger; >+import org.eclipse.compare.internal.merge.DocumentMerger.IDocumentMergerInput; >+import org.eclipse.compare.structuremergeviewer.DiffNode; >+import org.eclipse.compare.structuremergeviewer.Differencer; >+import org.eclipse.compare.structuremergeviewer.ICompareInput; >+import org.eclipse.compare.structuremergeviewer.IDiffElement; > import org.eclipse.core.resources.IContainer; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IProject; >@@ -35,10 +48,14 @@ > import org.eclipse.jface.dialogs.Dialog; > import org.eclipse.jface.dialogs.IDialogConstants; > import org.eclipse.jface.dialogs.IDialogSettings; >+import org.eclipse.jface.dialogs.IPageChangingListener; > import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.dialogs.PageChangingEvent; > import org.eclipse.jface.dialogs.TitleAreaDialog; > import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.text.Document; > import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.Position; > import org.eclipse.jface.viewers.DoubleClickEvent; > import org.eclipse.jface.viewers.IDoubleClickListener; > import org.eclipse.jface.viewers.ISelection; >@@ -69,6 +86,7 @@ > import org.eclipse.swt.widgets.Listener; > import org.eclipse.swt.widgets.Shell; > import org.eclipse.swt.widgets.Text; >+import org.eclipse.ui.IWorkbenchPart; > import org.eclipse.ui.model.BaseWorkbenchContentProvider; > import org.eclipse.ui.model.WorkbenchLabelProvider; > import org.eclipse.ui.views.navigator.ResourceComparator; >@@ -88,10 +106,43 @@ > final GenerateDiffFileWizard wizard = new GenerateDiffFileWizard(merger, rightToLeft); > wizard.setWindowTitle(title); > WizardDialog dialog = new WizardDialog(shell, wizard); >+ >+ dialog.addPageChangingListener(new IPageChangingListener() { >+ >+ public void handlePageChanging(PageChangingEvent event) { >+ if(event.getTargetPage() instanceof LocationPage) { >+ LocationPage page = (LocationPage) event.getTargetPage(); >+ page.updateAssociatedResources(); >+ } >+ } >+ >+ }); >+ > dialog.setMinimumPageSize(INITIAL_WIDTH, INITIAL_HEIGHT); > dialog.open(); > } >+ public static void run(IResource[] input, Shell shell) { >+ final String title = CompareMessages.GenerateLocalDiff_title; >+ final GenerateDiffFileWizard wizard = new GenerateDiffFileWizard(input); >+ wizard.setWindowTitle(title); >+ WizardDialog dialog = new WizardDialog(shell, wizard); >+ >+ dialog.addPageChangingListener(new IPageChangingListener() { > >+ public void handlePageChanging(PageChangingEvent event) { >+ if(event.getTargetPage() instanceof LocationPage) { >+ LocationPage page = (LocationPage) event.getTargetPage(); >+ page.updateAssociatedResources(); >+ } >+ } >+ >+ }); >+ >+ dialog.setMinimumPageSize(INITIAL_WIDTH, INITIAL_HEIGHT); >+ dialog.open(); >+ >+ } >+ > protected class DirectionSelectionPage extends WizardPage { > > public final static int LEFT_OPTION = 1; >@@ -214,7 +265,6 @@ > */ > private final DefaultValuesStore store; > >- > class LocationPageContentProvider extends BaseWorkbenchContentProvider { > //Never show closed projects > boolean showClosedProjects=false; >@@ -448,6 +498,19 @@ > this.store= store; > } > >+ public void updateAssociatedResources() { >+ Differencer dif = new Differencer(); >+ if(directionSelectionPage.isRightToLeft()) >+ startNode = (DiffNode) dif.findDifferences(false, null, null, null, >+ new FilteredBufferedResourceNode(rightResource), >+ new FilteredBufferedResourceNode(leftResource)); >+ else if(!directionSelectionPage.isRightToLeft()) >+ startNode = (DiffNode) dif.findDifferences(false, null, null, null, >+ new FilteredBufferedResourceNode(leftResource), >+ new FilteredBufferedResourceNode(rightResource)); >+ associatedResources = buildMap(startNode); >+ } >+ > /** > * Allow the user to finish if a valid file has been entered. > */ >@@ -463,7 +526,7 @@ > pageValid= true; > break; > } >- >+ > /** > * Avoid draw flicker by clearing error message > * if all is valid. >@@ -623,7 +686,9 @@ > public void createControl(Composite parent) { > > final Composite composite= new Composite(parent, SWT.NULL); >- composite.setLayout(new GridLayout()); >+ GridLayout lay = new GridLayout(); >+ lay.verticalSpacing = 15; >+ composite.setLayout(lay); > setControl(composite); > initializeDialogUnits(composite); > >@@ -632,9 +697,9 @@ > > //Create a location group > setupLocationControls(composite); >- >+ > initializeDefaultValues(); >- >+ > Dialog.applyDialogFont(parent); > > validatePage(); >@@ -643,6 +708,7 @@ > setupListeners(); > } > >+ > /** > * Setup the controls for the location. > */ >@@ -815,7 +881,7 @@ > }); > > } >- >+ > /** > * Enable and disable controls based on the selected radio button. > */ >@@ -1158,7 +1224,6 @@ > > private final DefaultValuesStore defaultValuesStore; > >- private DocumentMerger merger; > private IDocument leftDoc; > private IDocument rightDoc; > private String leftPath; >@@ -1170,23 +1235,120 @@ > private Text unified_customRelativeText; > private Button unified_customRelativeOption; > >+ private IResource rightResource; >+ private IResource leftResource; >+ >+ private ArrayList associatedResources; >+ > public GenerateDiffFileWizard() { > super(); > setWindowTitle(CompareMessages.GenerateLocalDiff_title); > initializeDefaultPageImageDescriptor(); > defaultValuesStore = new DefaultValuesStore(); >+ associatedResources = new ArrayList(); > } > >+ private DiffNode startNode; >+ >+ public GenerateDiffFileWizard(IResource[] input) { >+ this(); >+ >+ this.leftDoc = new Document(); >+ this.rightDoc = new Document(); >+ >+ leftResource = input[0]; >+ rightResource = input[1]; >+ >+ leftPath = leftResource.getFullPath().toString(); >+ rightPath = rightResource.getFullPath().toString(); >+ >+ Differencer dif = new Differencer(); >+ startNode = (DiffNode) dif.findDifferences(false, null, null, null, >+ new FilteredBufferedResourceNode(leftResource), >+ new FilteredBufferedResourceNode(rightResource)); >+ associatedResources = buildMap(startNode); >+ >+ } >+ > public GenerateDiffFileWizard(DocumentMerger merger, boolean rightToLeft) { > this(); >- this.merger = merger; > this.leftDoc = merger.getDocument(MergeViewerContentProvider.LEFT_CONTRIBUTOR); > this.rightDoc = merger.getDocument(MergeViewerContentProvider.RIGHT_CONTRIBUTOR); > this.leftPath = merger.getCompareConfiguration().getLeftLabel(leftDoc); > this.rightPath = merger.getCompareConfiguration().getRightLabel(rightDoc); > this.rightToLeft = rightToLeft; >+ IWorkbenchPart workbenchPart = merger.getCompareConfiguration().getContainer().getWorkbenchPart(); >+ >+ if(workbenchPart instanceof CompareEditor) { >+ >+ CompareEditor editor = (CompareEditor)workbenchPart; >+ >+ CompareEditorInput input = (CompareEditorInput)editor.getEditorInput(); >+ input.getCompareResult(); >+ if(input.getCompareResult() instanceof ICompareInput) { >+ ICompareInput node = (ICompareInput)input.getCompareResult(); >+ >+ leftResource = ((ResourceNode)node.getLeft()).getResource(); >+ rightResource = ((ResourceNode)node.getRight()).getResource(); >+ Differencer dif = new Differencer(); >+ startNode = (DiffNode) dif.findDifferences(false, null, null, null, >+ new FilteredBufferedResourceNode(leftResource), >+ new FilteredBufferedResourceNode(rightResource)); >+ >+ if(leftResource instanceof IFile && rightResource instanceof IFile) >+ associatedResources.add(new Object[] {leftResource, rightResource}); >+ >+ } >+ >+ } > } >+ >+ private ArrayList buildMap(DiffNode diff) { >+ ArrayList res = new ArrayList(); >+ IResource lresource = null; >+ IResource rresource = null; >+ IDiffElement[] children = diff.getChildren(); >+ if (children != null) { >+ for (int i = 0; i < children.length; i++) { >+ if (children[i] instanceof DiffNode) { >+ DiffNode o = (DiffNode) children[i]; >+ if (o != null && o.getKind() != Differencer.NO_CHANGE) { >+ DiffNode node = o; > >+ ITypedElement left = node.getLeft(); >+ if (left instanceof BufferedResourceNode) { >+ BufferedResourceNode bn = (BufferedResourceNode) left; >+ IResource resource = bn.getResource(); >+ if (resource instanceof IFile) { >+ lresource = resource; >+ } >+ >+ } >+ >+ ITypedElement right = node.getRight(); >+ if (right instanceof BufferedResourceNode) { >+ BufferedResourceNode bn = (BufferedResourceNode) right; >+ IResource resource = bn.getResource(); >+ if (resource instanceof IFile) { >+ rresource = resource; >+ } >+ } >+ >+ if(rresource != null || lresource != null) >+ res.add(new Object[] {lresource, rresource}); >+ lresource = null; >+ rresource = null; >+ } >+ >+ res.addAll(buildMap((DiffNode) children[i])); >+ } >+ } >+ return res; >+ } >+ return res; >+ } >+ >+ > public void addPages() { > String pageTitle = CompareMessages.GenerateLocalDiff_pageTitle; > String pageDescription = CompareMessages.GenerateLocalDiff_Specify_the_file_which_contributes_the_changes; >@@ -1286,7 +1448,7 @@ > public boolean needsProgressMonitor() { > return true; > } >- >+ > /** > * Completes processing of the wizard. If this method returns <code> > * true</code>, the wizard will close; otherwise, it will stay active. >@@ -1301,24 +1463,24 @@ > } > > //Validation of patch root >- if(optionsPage.getRootSelection() == OptionsPage.ROOT_CUSTOM) { >- String path = optionsPage.getPath(); >- IFile file2; >- try { >- file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)); >- } catch(IllegalArgumentException e) { >- final String title = CompareMessages.GenerateLocalDiff_3; >- final String msg = CompareMessages.GenerateLocalDiff_4; >- final MessageDialog dialog = new MessageDialog(getShell(), title, >- null, msg, MessageDialog.ERROR, >- new String[] { IDialogConstants.OK_LABEL }, 0); >- dialog.open(); >- return false; >- } >- if(!validateFile2(file2)) { >- return false; >- } >- } >+// if(optionsPage.getRootSelection() == OptionsPage.ROOT_CUSTOM) { >+// String path = optionsPage.getPath(); >+// IFile file2; >+// try { >+// file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)); >+// } catch(IllegalArgumentException e) { >+// final String title = CompareMessages.GenerateLocalDiff_3; >+// final String msg = CompareMessages.GenerateLocalDiff_4; >+// final MessageDialog dialog = new MessageDialog(getShell(), title, >+// null, msg, MessageDialog.ERROR, >+// new String[] { IDialogConstants.OK_LABEL }, 0); >+// dialog.open(); >+// return false; >+// } >+// if(!validateFile2(file2)) { >+// return false; >+// } >+// } > > // Create the patch > generateDiffFile(file); >@@ -1385,13 +1547,12 @@ > } else { > oldPath = this.rightPath; > } >- >- UnifiedDiffFormatter formatter = new UnifiedDiffFormatter(merger >- .getAllDiffs(), leftDoc, rightDoc, oldPath, toPath, >- directionSelectionPage.isRightToLeft()); >+ >+ //TODO extend formatter to use list of mergers. >+ UnifiedDiffFormatter formatter = new UnifiedDiffFormatter(createFormatterInput()); > try { > if (file == null) { >- formatter.generateDiffToClipboard(); >+ formatter.generateDiff(); > } else { > formatter.generateDiff(file); > } >@@ -1399,6 +1560,123 @@ > throw new RuntimeException(e); > } > } >+ >+ private Object[][] createFormatterInput() { >+ Object[] resArr = associatedResources.toArray(); >+ int size = resArr.length; >+ Object[][] result = new Object[size][3]; >+ DocumentMerger merg = null; >+ for (int j = 0; j < size; j++) { >+ IFile sourceRes = (IFile) ((Object[])resArr[j])[0]; >+ IFile targetRes = (IFile) ((Object[])resArr[j])[1]; >+ merg = createDocumentMerger(sourceRes, targetRes); >+ result[j][0] = merg; >+ result[j][1] = sourceRes ; >+ result[j][2] = targetRes ; >+ } >+ return result; >+ } >+ >+ private DocumentMerger createDocumentMerger(IFile leftFile, IFile rightFile){ >+ IDocument leftDoc = convertFileToDocument(leftFile); >+ IDocument rightDoc = convertFileToDocument(rightFile); >+ if (leftDoc == null) { >+ leftDoc = new Document(); >+ } >+ if (rightDoc == null) { >+ rightDoc = new Document(); >+ } >+ DocumentMerger docMerger; >+ docMerger = new DocumentMerger(new LocalDiffMergerInput(leftDoc, rightDoc)); >+ try { >+ docMerger.doDiff(); >+ } catch (Exception e) { >+ throw new RuntimeException(e); >+ } >+ return docMerger; >+ } >+ >+ private IDocument convertFileToDocument(IFile file) { >+ if(file == null) >+ return null; >+ StringBuffer str = new StringBuffer(); >+ int c; >+ try{ >+ InputStream inputStream = file.getContents(); >+ while ((c = inputStream.read())!=-1){ >+ str.append((char)c); >+ } >+ inputStream.close(); >+ return new Document(str.toString()); >+ }catch(Exception ex){ >+ CompareUIPlugin.log(ex); >+ } >+ >+ return null; >+ } >+ >+ private class LocalDiffMergerInput implements IDocumentMergerInput { >+ >+ private IDocument leftDoc; >+ private IDocument rightDoc; >+ >+ public LocalDiffMergerInput(IDocument leftDoc, IDocument rightDoc) { >+ this.leftDoc = leftDoc ; >+ this.rightDoc= rightDoc; >+ } >+ >+ public ITokenComparator createTokenComparator(String line) { >+ return new TokenComparator(line); >+ } >+ public CompareConfiguration getCompareConfiguration() { >+ return new CompareConfiguration(); >+ } >+ public IDocument getDocument(char contributor) { >+ switch (contributor) { >+ case MergeViewerContentProvider.LEFT_CONTRIBUTOR: >+ return leftDoc; >+ case MergeViewerContentProvider.RIGHT_CONTRIBUTOR: >+ return rightDoc; >+ case MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR: >+ return null; >+ } >+ return null; >+ } >+ public int getHunkStart() { >+ return 0; >+ } >+ public Position getRegion(char contributor) { >+ switch (contributor) { >+ case MergeViewerContentProvider.LEFT_CONTRIBUTOR: >+ return new Position(0, leftDoc.getLength()); >+ case MergeViewerContentProvider.RIGHT_CONTRIBUTOR: >+ return new Position(0, rightDoc.getLength()); >+ case MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR: >+ return new Position(0, 0); >+ } >+ return null; >+ } >+ public boolean isHunkOnLeft() { >+ return false; >+ } >+ public boolean isIgnoreAncestor() { >+ return true; >+ } >+ public boolean isPatchHunk() { >+ return false; >+ } >+ >+ public boolean isShowPseudoConflicts() { >+ return false; >+ } >+ public boolean isThreeWay() { >+ return false; >+ } >+ public boolean isPatchHunkOk() { >+ return false; >+ } >+ >+ } > > public boolean validateFile(File file) { > >Index: compare/org/eclipse/compare/internal/CompareMessages.properties >=================================================================== >--- compare/org/eclipse/compare/internal/CompareMessages.properties 1 Jan 1970 00:00:00 -0000 >+++ compare/org/eclipse/compare/internal/CompareMessages.properties 1 Jan 1970 00:00:00 -0000 >@@ -150,6 +150,7 @@ > > ReaderCreator_fileIsNotAccessible=Cannot create a reader because the file is inaccessible. > >+CreatePatchActionTitle=Create Patch... > WorkspacePatchDialogTitle=Set a Patch Location > WorkspacePatchDialogDescription=Select a folder in the workspace and enter a name for the patch. > Save_To_Clipboard_2=&Clipboard >@@ -193,7 +194,7 @@ > GenerateDiffFileWizard_13=Use only &file path: > GenerateDiffFileWizard_Left=&Left: > GenerateDiffFileWizard_Right=&Right: >-CreatePatchActionTitle=Create Patch... >+CreatePatchActionTitle=Create Patch > WorkspacePatchDialogTitle=Set a Patch Location > WorkspacePatchDialogDescription=Select a folder in the workspace and enter a name for the patch. > Save_To_Clipboard_2=&Clipboard >@@ -236,4 +237,7 @@ > GenerateDiffFileWizard_ProjectClosed=The specified path points to a closed project. > GenerateDiffFileWizard_13=Use only &file path: > GenerateDiffFileWizard_Left=&Left: >-GenerateDiffFileWizard_Right=&Right: >\ No newline at end of file >+GenerateDiffFileWizard_Right=&Right: >+GenerateDiffFileWizard_SelectAll=Select &All >+GenerateDiffFileWizard_DeselectAll=&Deselect All >+GenerateDiffFileWizard_noChangesSelected=No changes selected. >\ No newline at end of file >Index: compare/org/eclipse/compare/internal/ICompareUIConstants.java >=================================================================== >--- compare/org/eclipse/compare/internal/ICompareUIConstants.java 1 Jan 1970 00:00:00 -0000 >+++ compare/org/eclipse/compare/internal/ICompareUIConstants.java 1 Jan 1970 00:00:00 -0000 >@@ -40,7 +40,7 @@ > public static final String PROP_TITLE_IMAGE = PREFIX + "TitleImage"; //$NON-NLS-1$ > public static final String PROP_SELECTED_EDITION = PREFIX + "SelectedEdition"; //$NON-NLS-1$ > >- public static final int COMPARE_IMAGE_WIDTH= 22; >+ public static final int COMPARE_IMAGE_WIDTH= 17; > > public static final String PREF_NAVIGATION_END_ACTION= PREFIX + "NavigationEndAction"; //$NON-NLS-1$ > public static final String PREF_NAVIGATION_END_ACTION_LOCAL= PREFIX + "NavigationEndActionLocal"; //$NON-NLS-1$ >Index: compare/org/eclipse/compare/internal/GenerateDiffAction.java >=================================================================== >--- compare/org/eclipse/compare/internal/GenerateDiffAction.java 1 Jan 1970 00:00:00 -0000 >+++ compare/org/eclipse/compare/internal/GenerateDiffAction.java 1 Jan 1970 00:00:00 -0000 >@@ -13,19 +13,9 @@ > package org.eclipse.compare.internal; > > >-import java.io.InputStream; >- > import org.eclipse.compare.CompareConfiguration; >-import org.eclipse.compare.contentmergeviewer.ITokenComparator; >-import org.eclipse.compare.contentmergeviewer.TokenComparator; >-import org.eclipse.compare.internal.merge.DocumentMerger; >-import org.eclipse.compare.internal.merge.DocumentMerger.IDocumentMergerInput; >-import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IResource; > import org.eclipse.jface.action.IAction; >-import org.eclipse.jface.text.Document; >-import org.eclipse.jface.text.IDocument; >-import org.eclipse.jface.text.Position; > import org.eclipse.jface.viewers.ISelection; > import org.eclipse.swt.widgets.Shell; > import org.eclipse.ui.IObjectActionDelegate; >@@ -49,13 +39,7 @@ > boolean ok = fInput.setSelection(selection,shell, showSelectAncestorDialog); > if (!ok) return; > >- DocumentMerger merger = null; >- if(ir[0] instanceof IFile && ir[1] instanceof IFile) { >- merger = createDocumentMerger((IFile)ir[0], (IFile)ir[1]); >- merger.getCompareConfiguration().setLeftLabel(ir[0].getFullPath().toString()); >- merger.getCompareConfiguration().setRightLabel(ir[1].getFullPath().toString()); >- GenerateDiffFileWizard.run(merger, shell, true); >- } >+ GenerateDiffFileWizard.run(ir, shell); > > > } >@@ -73,106 +57,5 @@ > fWorkbenchPage= targetPart.getSite().getPage(); > } > >- private DocumentMerger createDocumentMerger(IFile leftFile, IFile rightFile){ >- IDocument leftDoc = convertFileToDocument(leftFile); >- IDocument rightDoc = convertFileToDocument(rightFile); >- if (leftDoc == null) { >- leftDoc = new Document(); >- } >- if (rightDoc == null) { >- rightDoc = new Document(); >- } >- DocumentMerger docMerger; >- docMerger = new DocumentMerger(new LocalDiffMergerInput(leftDoc, rightDoc)); >- try { >- docMerger.doDiff(); >- } catch (Exception e) { >- throw new RuntimeException(e); >- } >- return docMerger; >- } >- >- private IDocument convertFileToDocument(IFile file) { >- if(file == null) >- return null; >- StringBuffer str = new StringBuffer(); >- int c; >- try{ >- InputStream inputStream = file.getContents(); >- while ((c = inputStream.read())!=-1){ >- str.append((char)c); >- } >- inputStream.close(); >- return new Document(str.toString()); >- }catch(Exception ex){ >- CompareUIPlugin.log(ex); >- } >- >- return null; >- } >- >- private class LocalDiffMergerInput implements IDocumentMergerInput { >- >- private IDocument leftDoc; >- private IDocument rightDoc; >- >- public LocalDiffMergerInput(IDocument leftDoc, IDocument rightDoc) { >- this.leftDoc = leftDoc ; >- this.rightDoc= rightDoc; >- } >- >- public ITokenComparator createTokenComparator(String line) { >- return new TokenComparator(line); >- } >- public CompareConfiguration getCompareConfiguration() { >- return fInput.getCompareConfiguration(); >- } >- public IDocument getDocument(char contributor) { >- switch (contributor) { >- case MergeViewerContentProvider.LEFT_CONTRIBUTOR: >- return leftDoc; >- case MergeViewerContentProvider.RIGHT_CONTRIBUTOR: >- return rightDoc; >- case MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR: >- return null; >- } >- return null; >- } >- public int getHunkStart() { >- return 0; >- } >- public Position getRegion(char contributor) { >- switch (contributor) { >- case MergeViewerContentProvider.LEFT_CONTRIBUTOR: >- return new Position(0, leftDoc.getLength()); >- case MergeViewerContentProvider.RIGHT_CONTRIBUTOR: >- return new Position(0, rightDoc.getLength()); >- case MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR: >- return new Position(0, 0); >- } >- return null; >- } >- public boolean isHunkOnLeft() { >- return false; >- } >- public boolean isIgnoreAncestor() { >- return true; >- } >- public boolean isPatchHunk() { >- return false; >- } >- >- public boolean isShowPseudoConflicts() { >- return false; >- } >- public boolean isThreeWay() { >- return false; >- } >- public boolean isPatchHunkOk() { >- return false; >- } >- >- } >- > } > >Index: compare/org/eclipse/compare/internal/UnifiedDiffFormatter.java >=================================================================== >--- compare/org/eclipse/compare/internal/UnifiedDiffFormatter.java 1 Jan 1970 00:00:00 -0000 >+++ compare/org/eclipse/compare/internal/UnifiedDiffFormatter.java 1 Jan 1970 00:00:00 -0000 >@@ -17,16 +17,19 @@ > import java.io.File; > import java.io.FileOutputStream; > import java.io.IOException; >+import java.io.InputStream; > import java.io.PrintStream; > import java.util.ArrayList; > import java.util.Arrays; > import java.util.Calendar; > import java.util.Date; >-import java.util.List; > >+import org.eclipse.compare.internal.merge.DocumentMerger; > import org.eclipse.compare.internal.merge.DocumentMerger.Diff; > import org.eclipse.compare.rangedifferencer.RangeDifference; >+import org.eclipse.core.resources.IFile; > import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.Document; > import org.eclipse.jface.text.IDocument; > import org.eclipse.swt.dnd.Clipboard; > import org.eclipse.swt.dnd.TextTransfer; >@@ -52,22 +55,10 @@ > public static final String RANGE_INFORMATION_PREFIX = "@@ -"; //$NON-NLS-1$ > public static final String RANGE_INFORMATION_AFFIX = " @@"; //$NON-NLS-1$ > >- private List fAllDiffs; >- private IDocument leftDoc; >- private IDocument rightDoc; >- private String oldPath; >- private String newPath; >- private boolean rightToLeft; >+ private Object[][] input; > >- public UnifiedDiffFormatter(List allDiffs, IDocument leftDoc, >- IDocument rightDoc, String oldPath, String newPath, >- boolean rightToLeft) { >- this.fAllDiffs = allDiffs; >- this.leftDoc = leftDoc; >- this.rightDoc = rightDoc; >- this.oldPath = oldPath; >- this.newPath = newPath; >- this.rightToLeft = rightToLeft; >+ public UnifiedDiffFormatter(Object[][] input) { >+ this.input = input; > } > > /** >@@ -78,7 +69,7 @@ > * > * @throws IOException > */ >- public void generateDiffToClipboard() throws IOException { >+ public void generateDiff() throws IOException { > ByteArrayOutputStream bos = new ByteArrayOutputStream(); > PrintStream ps = new PrintStream(bos); > >@@ -148,95 +139,136 @@ > * @param strictUnixFormat determinates if the format should be fully compatible with the Unix one. > */ > private void generateDiff(PrintStream output, boolean strictUnixFormat) { >- // If the first block isn't the only one, or first block is different >- if (fAllDiffs.size() > 1 || isPartDifferent(0)) { >- output.println(INDEX_MARKER + oldPath); >- output.println(DELIMITER); >- Date oldDate = Calendar.getInstance().getTime(); >- Date newDate = Calendar.getInstance().getTime(); >- String oldDateFormat = DateFormat.getDateTimeInstance().format(oldDate); >- String newDateFormat = DateFormat.getDateTimeInstance().format(newDate); >- output.println(OLD_FILE_PREFIX + oldPath + '\t' >- + oldDateFormat + " -0000"); //$NON-NLS-1$ >- output.println(NEW_FILE_PREFIX + newPath + '\t' >- + newDateFormat + " -0000"); //$NON-NLS-1$ >+ for (int fileNr = 0; fileNr < input.length; fileNr++) { >+ DocumentMerger merger = (DocumentMerger) input[fileNr][0]; >+ IDocument leftDoc = convertFileToDocument((IFile)input[fileNr][1]); >+ IDocument rightDoc = convertFileToDocument((IFile)input[fileNr][2]); >+ String oldPath; >+ String newPath; >+ if (leftDoc == null) { >+ leftDoc = new Document(); >+ newPath = ((IFile)input[fileNr][2]).getFullPath().toString(); >+ oldPath = ((IFile)input[fileNr][2]).getFullPath().toString(); >+ } >+ else if (rightDoc == null) { >+ rightDoc = new Document(); >+ newPath = ((IFile)input[fileNr][1]).getFullPath().toString(); >+ oldPath = ((IFile)input[fileNr][1]).getFullPath().toString(); >+ } >+ else { >+ oldPath = ((IFile)input[fileNr][1]).getFullPath().toString(); >+ newPath = ((IFile)input[fileNr][2]).getFullPath().toString(); >+ } >+ >+ ArrayList allDiffs = merger.getAllDiffs(); >+ // If the first block isn't the only one, or first block is different >+ if (allDiffs.size() > 1 || isPartDifferent(allDiffs, 0)) { >+ output.println(INDEX_MARKER + oldPath); >+ output.println(DELIMITER); >+ Date oldDate = Calendar.getInstance().getTime(); >+ Date newDate = Calendar.getInstance().getTime(); >+ String oldDateFormat = DateFormat.getDateTimeInstance().format(oldDate); >+ String newDateFormat = DateFormat.getDateTimeInstance().format(newDate); >+ output.println(OLD_FILE_PREFIX + oldPath + '\t' >+ + oldDateFormat + " -0000"); //$NON-NLS-1$ >+ output.println(NEW_FILE_PREFIX + newPath + '\t' >+ + newDateFormat + " -0000"); //$NON-NLS-1$ > >- boolean firstHunk = true; >- Hunk currentHunk = null; >+ boolean firstHunk = true; >+ Hunk currentHunk = null; > >- int currentLineNumberOld = 0; >- int currentLineNumberNew = 0; >+ int currentLineNumberOld = 0; >+ int currentLineNumberNew = 0; > >- for (int i = 0; i < fAllDiffs.size(); i++) { >+ for (int partNumber = 0; partNumber < allDiffs.size(); partNumber++) { > >- List oldPart = getPart(i, LEFT_CONTRIBUTOR); >- List newPart = getPart(i, RIGHT_CONTRIBUTOR); >+ ArrayList oldPart = getPart(partNumber, LEFT_CONTRIBUTOR, merger, leftDoc, rightDoc); >+ ArrayList newPart = getPart(partNumber, RIGHT_CONTRIBUTOR, merger, leftDoc, rightDoc); > >- if (isPartDifferent(i)) { >- // This part has some changes >- if (firstHunk) { >- // Hunk will start with changed block >- currentHunk = new Hunk(0, 0, strictUnixFormat); >- firstHunk = false; >- } >- if (i == (fAllDiffs.size() - 1)) { >- // If it is the last part >- currentHunk.addPartRangeToOld(oldPart, 0, oldPart >- .size(), true); >- currentHunk.addPartRangeToNew(newPart, 0, newPart >- .size(), true); >- } else { >- currentHunk.addPartRangeToOld(oldPart, 0, oldPart >- .size(), false); >- currentHunk.addPartRangeToNew(newPart, 0, newPart >- .size(), false); >- } >- } else { >- if (firstHunk) { >- // Hunk will start with context >- currentHunk = new Hunk((oldPart.size() - 1) - NUMBER_OF_CONTEXT_LINES, >- (oldPart.size() - 1) - NUMBER_OF_CONTEXT_LINES, strictUnixFormat); >- firstHunk = false; >- currentHunk.addPartRangeToBoth(oldPart, >- (oldPart.size() - 1) - NUMBER_OF_CONTEXT_LINES, oldPart.size(), false); >- } else { >- if (i == (fAllDiffs.size() - 1)) { >+ if (isPartDifferent(allDiffs, partNumber)) { >+ // This part has some changes >+ if (firstHunk) { >+ // Hunk will start with changed block >+ currentHunk = new Hunk(0, 0, strictUnixFormat); >+ firstHunk = false; >+ } >+ if (partNumber == (allDiffs.size() - 1)) { > // If it is the last part >- currentHunk.addPartRangeToBoth(oldPart, 0, NUMBER_OF_CONTEXT_LINES, true); >+ currentHunk.addPartRangeToOld(oldPart, 0, oldPart >+ .size(), true); >+ currentHunk.addPartRangeToNew(newPart, 0, newPart >+ .size(), true); > } else { >- if (oldPart.size() - 1 < 2*NUMBER_OF_CONTEXT_LINES) { >- // Context too short to start new hunk >- currentHunk.addPartRangeToBoth(oldPart, 0, >- oldPart.size(), false); >+ currentHunk.addPartRangeToOld(oldPart, 0, oldPart >+ .size(), false); >+ currentHunk.addPartRangeToNew(newPart, 0, newPart >+ .size(), false); >+ } >+ } else { >+ if (firstHunk) { >+ // Hunk will start with context >+ currentHunk = new Hunk((oldPart.size() - 1) - NUMBER_OF_CONTEXT_LINES, >+ (oldPart.size() - 1) - NUMBER_OF_CONTEXT_LINES, strictUnixFormat); >+ firstHunk = false; >+ currentHunk.addPartRangeToBoth(oldPart, >+ (oldPart.size() - 1) - NUMBER_OF_CONTEXT_LINES, oldPart.size(), false); >+ } else { >+ if (partNumber == (allDiffs.size() - 1)) { >+ // If it is the last part >+ currentHunk.addPartRangeToBoth(oldPart, 0, NUMBER_OF_CONTEXT_LINES, true); > } else { >- // Context long enough to start new hunk >- currentHunk.addPartRangeToBoth(oldPart, 0, NUMBER_OF_CONTEXT_LINES, >- false); >- currentHunk.printTo(output); >- currentHunk = new Hunk(currentLineNumberOld >- + (oldPart.size() - 1) - NUMBER_OF_CONTEXT_LINES, >- currentLineNumberNew + (oldPart.size() - 1) >- - NUMBER_OF_CONTEXT_LINES, strictUnixFormat); >- currentHunk.addPartRangeToBoth(oldPart, >- (oldPart.size() - 1) - NUMBER_OF_CONTEXT_LINES, >- oldPart.size(), false); >+ if (oldPart.size() - 1 < 2*NUMBER_OF_CONTEXT_LINES) { >+ // Context too short to start new hunk >+ currentHunk.addPartRangeToBoth(oldPart, 0, >+ oldPart.size(), false); >+ } else { >+ // Context long enough to start new hunk >+ currentHunk.addPartRangeToBoth(oldPart, 0, NUMBER_OF_CONTEXT_LINES, >+ false); >+ currentHunk.printTo(output); >+ currentHunk = new Hunk(currentLineNumberOld >+ + (oldPart.size() - 1) - NUMBER_OF_CONTEXT_LINES, >+ currentLineNumberNew + (oldPart.size() - 1) >+ - NUMBER_OF_CONTEXT_LINES, strictUnixFormat); >+ currentHunk.addPartRangeToBoth(oldPart, >+ (oldPart.size() - 1) - NUMBER_OF_CONTEXT_LINES, >+ oldPart.size(), false); >+ } > } > } > } >+ currentLineNumberOld += oldPart.size(); >+ currentLineNumberNew += newPart.size(); > } >- currentLineNumberOld += oldPart.size(); >- currentLineNumberNew += newPart.size(); >+ // Print the last hunk >+ currentHunk.printTo(output); >+ } >+ } >+ } >+ >+ private IDocument convertFileToDocument(IFile file) { >+ if(file == null) >+ return null; >+ StringBuffer str = new StringBuffer(); >+ int c; >+ try{ >+ InputStream inputStream = file.getContents(); >+ while ((c = inputStream.read())!=-1){ >+ str.append((char)c); > } >- // Print the last hunk >- currentHunk.printTo(output); >+ inputStream.close(); >+ return new Document(str.toString()); >+ }catch(Exception ex){ >+ CompareUIPlugin.log(ex); > } >+ >+ return null; > } >- >- private List getPart(int i, char side) { >+ >+ private ArrayList getPart(int nr, char side, DocumentMerger merger, IDocument leftDoc, IDocument rightDoc) { > try { >- String s = extract(i, side).replaceAll("\r\n", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ >- s.replaceAll("\r", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ >- List diffLines = new ArrayList(Arrays >+ String s = extract(nr, side, merger, leftDoc, rightDoc).replaceAll("\r", ""); //$NON-NLS-1$ //$NON-NLS-2$ >+ ArrayList diffLines = new ArrayList(Arrays > .asList(s.split("\n", -1))); //$NON-NLS-1$ > return diffLines; > } catch (BadLocationException e) { >@@ -245,10 +277,9 @@ > return null; > } > >- private String extract(int i, char side) throws BadLocationException { >- Diff diff = ((Diff) fAllDiffs.get(i)); >- if (side == LEFT_CONTRIBUTOR && !rightToLeft >- || side == RIGHT_CONTRIBUTOR && rightToLeft) { >+ private String extract(int nr, char side, DocumentMerger merger, IDocument leftDoc, IDocument rightDoc) throws BadLocationException { >+ Diff diff = ((Diff) merger.getAllDiffs().get(nr)); >+ if (side == LEFT_CONTRIBUTOR) { > return leftDoc.get(diff.getPosition(LEFT_CONTRIBUTOR).offset, diff > .getPosition(LEFT_CONTRIBUTOR).length); > } >@@ -256,8 +287,8 @@ > .getPosition(RIGHT_CONTRIBUTOR).length); > } > >- private boolean isPartDifferent(int i) { >- Diff diff = ((Diff) fAllDiffs.get(i)); >+ private boolean isPartDifferent(ArrayList allDiffs, int nr) { >+ Diff diff = ((Diff) allDiffs.get(nr)); > if (diff.getKind() == RangeDifference.CHANGE) { > return true; > } >@@ -271,7 +302,7 @@ > private int newLength; > private boolean strictUnixFormat; > private boolean printNoNewlineMarker; >- List lines; >+ ArrayList lines; > > public Hunk(int oldStart, int newStart, boolean strictUnixFormat) { > if (oldStart < 0) >@@ -287,7 +318,7 @@ > lines = new ArrayList(); > } > >- public void addPartRangeToOld(List part, int start, int end, >+ public void addPartRangeToOld(ArrayList part, int start, int end, > boolean lastPart) { > if (start < 0) > start = 0; >@@ -322,7 +353,7 @@ > } > } > >- public void addPartRangeToNew(List part, int start, int end, >+ public void addPartRangeToNew(ArrayList part, int start, int end, > boolean lastPart) { > if (start < 0) > start = 0; >@@ -356,7 +387,7 @@ > } > } > >- public void addPartRangeToBoth(List part, int start, int end, >+ public void addPartRangeToBoth(ArrayList part, int start, int end, > boolean lastPart) { > if (start < 0) > start = 0; >Index: compare/org/eclipse/compare/internal/CompareMessages.java >=================================================================== >--- compare/org/eclipse/compare/internal/CompareMessages.java 1 Jan 1970 00:00:00 -0000 >+++ compare/org/eclipse/compare/internal/CompareMessages.java 1 Jan 1970 00:00:00 -0000 >@@ -181,6 +181,9 @@ > public static String GenerateLocalDiff_4; > public static String GenerateLocalDiff_5; > public static String GenerateLocalDiff_6; >+ public static String GenerateDiffFileWizard_SelectAll; >+ public static String GenerateDiffFileWizard_DeselectAll; >+ public static String GenerateDiffFileWizard_noChangesSelected; > > static { > NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 265030
:
126799
|
128110
| 128117