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 125770 Details for
Bug 183238
[Apply Patch] API to get IHunks from IFilePatch and select which of them to apply
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Patch_v03
183238_v03.txt (text/plain), 30.08 KB, created by
Pawel Pogorzelski
on 2009-02-16 05:53:12 EST
(
hide
)
Description:
Patch_v03
Filename:
MIME Type:
Creator:
Pawel Pogorzelski
Created:
2009-02-16 05:53:12 EST
Size:
30.08 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.compare.tests >Index: src/org/eclipse/compare/tests/PatchTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java,v >retrieving revision 1.22 >diff -u -r1.22 PatchTest.java >--- src/org/eclipse/compare/tests/PatchTest.java 11 Dec 2008 13:39:35 -0000 1.22 >+++ src/org/eclipse/compare/tests/PatchTest.java 16 Feb 2009 10:55:14 -0000 >@@ -46,6 +46,8 @@ > import org.eclipse.compare.patch.ApplyPatchOperation; > import org.eclipse.compare.patch.IFilePatch; > import org.eclipse.compare.patch.IFilePatchResult; >+import org.eclipse.compare.patch.IHunk; >+import org.eclipse.compare.patch.IHunkFilter; > import org.eclipse.compare.patch.PatchConfiguration; > import org.eclipse.core.resources.IStorage; > import org.eclipse.core.resources.ResourcesPlugin; >@@ -53,6 +55,7 @@ > import org.eclipse.core.runtime.FileLocator; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.core.runtime.Path; > import org.eclipse.core.runtime.Platform; > import org.eclipse.core.runtime.Status; >@@ -202,7 +205,37 @@ > expected.add("UID: 42\n"); > assertEquals(LineReader.createString(false, expected), LineReader.createString(false, lines)); > } >- >+ >+ public void testHunkFilter() throws CoreException, IOException { >+ IStorage patchStorage = new StringStorage("patch_hunkFilter.txt"); >+ IStorage expStorage = new StringStorage("context.txt"); >+ IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage); >+ assertEquals(1, patches.length); >+ IHunk[] hunks = patches[0].getHunks(); >+ assertEquals(5, hunks.length); >+ PatchConfiguration pc = new PatchConfiguration(); >+ final IHunk toFilterOut = hunks[3]; >+ pc.addHunkFilter(new IHunkFilter() { >+ public boolean select(IHunk hunk) { >+ return hunk != toFilterOut; >+ } >+ }); >+ IFilePatchResult result = patches[0].apply(expStorage, pc, >+ new NullProgressMonitor()); >+ IHunk[] rejects = result.getRejects(); >+ assertEquals(2, rejects.length); >+ assertFalse(pc.getHunkFilters()[0].select(rejects[0])); >+ assertTrue(pc.getHunkFilters()[0].select(rejects[1])); >+ >+ InputStream actual = result.getPatchedContents(); >+ >+ LineReader lr = new LineReader(getReader("exp_hunkFilter.txt")); >+ List inLines = lr.readLines(); >+ String expected = LineReader.createString(false, inLines); >+ >+ assertEquals(expected, asString(actual)); >+ } >+ > public void testDateUnknown() throws CoreException { > IStorage patchStorage = new StringStorage("patch_dateunknown.txt"); > IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage); >Index: patchdata/exp_hunkFilter.txt >=================================================================== >RCS file: patchdata/exp_hunkFilter.txt >diff -N patchdata/exp_hunkFilter.txt >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ patchdata/exp_hunkFilter.txt 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,24 @@ >+[a] >+[b] >+[c] >+[c1] >+[c2] >+[d] >+[e] >+[f] >+[g] >+[h] >+[i1] >+[j] >+[k] >+[l] >+[m] >+[n] >+[p] >+[q] >+[r] >+[s] >+[t] >+[u] >+[v] >+[w] >Index: patchdata/patch_hunkFilter.txt >=================================================================== >RCS file: patchdata/patch_hunkFilter.txt >diff -N patchdata/patch_hunkFilter.txt >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ patchdata/patch_hunkFilter.txt 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,25 @@ >+--- old.txt 2005-05-07 00:16:20.000000000 +0200 >++++ new.txt 2005-05-07 00:16:32.000000000 +0200 >+@@ -3,2 +3,4 @@ >+ [c] >++[c1] >++[c2] >+ [d] >+@@ -8,3 +10,3 @@ >+ [h] >+-[i] >++[i1] >+ [j] >+@@ -14,3 +16,2 @@ >+ [n] >+-[o] >+ [p] >+@@ -19,2 +20,3 @@ >+ [s] >++[s1] >+ [t] >+@@ -29,2 +32,3 @@ >+ [yy] >++[xx] >+ [yy] >+ >\ No newline at end of file >#P org.eclipse.compare >Index: compare/org/eclipse/compare/internal/patch/Patcher.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java,v >retrieving revision 1.65 >diff -u -r1.65 Patcher.java >--- compare/org/eclipse/compare/internal/patch/Patcher.java 11 Dec 2008 13:39:37 -0000 1.65 >+++ compare/org/eclipse/compare/internal/patch/Patcher.java 16 Feb 2009 10:55:16 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -31,10 +31,11 @@ > import org.eclipse.compare.internal.core.patch.FileDiff; > import org.eclipse.compare.internal.core.patch.FileDiffResult; > import org.eclipse.compare.internal.core.patch.Hunk; >-import org.eclipse.compare.internal.core.patch.IHunkFilter; > import org.eclipse.compare.internal.core.patch.LineReader; > import org.eclipse.compare.internal.core.patch.PatchReader; > import org.eclipse.compare.internal.core.patch.Utilities; >+import org.eclipse.compare.patch.IHunk; >+import org.eclipse.compare.patch.IHunkFilter; > import org.eclipse.compare.patch.PatchConfiguration; > import org.eclipse.core.resources.IContainer; > import org.eclipse.core.resources.IFile; >@@ -92,7 +93,7 @@ > public Patcher() { > configuration = new PatchConfiguration(); > configuration.setProperty(PROP_PATCHER, this); >- configuration.setProperty(IHunkFilter.HUNK_FILTER_PROPERTY, this); >+ configuration.addHunkFilter(this); > } > > /* >@@ -193,8 +194,8 @@ > int removedLines = 0; > FileDiff fileDiff = fileDiffs[i]; > for (int j = 0; j < fileDiff.getHunkCount(); j++) { >- Hunk hunk = fileDiff.getHunks()[j]; >- String[] lines = hunk.getLines(); >+ IHunk hunk = fileDiff.getHunks()[j]; >+ String[] lines = ((Hunk) hunk).getLines(); > for (int k = 0; k < lines.length; k++) { > char c = lines[k].charAt(0); > switch (c) { >@@ -518,9 +519,9 @@ > } > > private void setEnabledFile(FileDiff fileDiff, boolean enabled) { >- Hunk[] hunks = fileDiff.getHunks(); >+ IHunk[] hunks = fileDiff.getHunks(); > for (int i = 0; i < hunks.length; i++) { >- setEnabledHunk(hunks[i], enabled); >+ setEnabledHunk((Hunk) hunks[i], enabled); > } > } > >@@ -753,7 +754,7 @@ > return false; > } > >- public boolean select(Hunk hunk) { >+ public boolean select(IHunk hunk) { > return isEnabled(hunk); > } > } >Index: compare/org/eclipse/compare/internal/patch/WorkspacePatcher.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/WorkspacePatcher.java,v >retrieving revision 1.15 >diff -u -r1.15 WorkspacePatcher.java >--- compare/org/eclipse/compare/internal/patch/WorkspacePatcher.java 15 Jul 2008 14:45:29 -0000 1.15 >+++ compare/org/eclipse/compare/internal/patch/WorkspacePatcher.java 16 Feb 2009 10:55:16 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -22,6 +22,7 @@ > import org.eclipse.compare.internal.core.patch.Hunk; > import org.eclipse.compare.internal.core.patch.LineReader; > import org.eclipse.compare.internal.core.patch.PatchReader; >+import org.eclipse.compare.patch.IHunk; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IMarker; > import org.eclipse.core.resources.IProject; >@@ -259,7 +260,7 @@ > > public void retargetDiff(FileDiff diff, IFile file) { > retargetedDiffs.put(diff, diff.getPath(false)); >- Hunk[] hunks = diff.getHunks(); >+ IHunk[] hunks = diff.getHunks(); > > if (isWorkspacePatch()){ > //since the diff has no more hunks to apply, remove it from the parent and the patcher >@@ -268,7 +269,7 @@ > removeDiff(diff); > FileDiff newDiff = getDiffForFile(file); > for (int i = 0; i < hunks.length; i++) { >- Hunk hunk = hunks[i]; >+ Hunk hunk = (Hunk) hunks[i]; > newDiff.add(hunk); > } > } >Index: compare/org/eclipse/compare/internal/patch/PreviewPatchPage2.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage2.java,v >retrieving revision 1.38 >diff -u -r1.38 PreviewPatchPage2.java >--- compare/org/eclipse/compare/internal/patch/PreviewPatchPage2.java 4 Aug 2008 12:08:10 -0000 1.38 >+++ compare/org/eclipse/compare/internal/patch/PreviewPatchPage2.java 16 Feb 2009 10:55:16 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >+ * Copyright (c) 2005, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -21,6 +21,7 @@ > import org.eclipse.compare.internal.ICompareUIConstants; > import org.eclipse.compare.internal.core.patch.FileDiff; > import org.eclipse.compare.internal.core.patch.Hunk; >+import org.eclipse.compare.patch.IHunk; > import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; >@@ -716,9 +717,9 @@ > > FileDiff[] fileDiffs = fPatcher.getDiffs(); > for (int i = 0; i < fileDiffs.length; i++) { >- Hunk[] hunks = fileDiffs[i].getHunks(); >+ IHunk[] hunks = fileDiffs[i].getHunks(); > for (int j = 0; j < hunks.length; j++) { >- String[] lines = hunks[j].getLines(); >+ String[] lines = ((Hunk) hunks[j]).getLines(); > for (int k = 0; k < lines.length; k++) { > String line = lines[k]; > if (addedPattern.matcher(line).find()) >Index: compare/org/eclipse/compare/internal/patch/HunkTypedElement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/HunkTypedElement.java,v >retrieving revision 1.11 >diff -u -r1.11 HunkTypedElement.java >--- compare/org/eclipse/compare/internal/patch/HunkTypedElement.java 15 Jul 2008 14:45:29 -0000 1.11 >+++ compare/org/eclipse/compare/internal/patch/HunkTypedElement.java 16 Feb 2009 10:55:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006, 2008 IBM Corporation and others. >+ * Copyright (c) 2006, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -15,6 +15,7 @@ > import org.eclipse.compare.IEncodedStreamContentAccessor; > import org.eclipse.compare.ITypedElement; > import org.eclipse.compare.internal.*; >+import org.eclipse.compare.internal.core.patch.FileDiffResult; > import org.eclipse.compare.internal.core.patch.HunkResult; > import org.eclipse.compare.patch.IHunk; > import org.eclipse.core.runtime.*; >@@ -71,7 +72,7 @@ > * @see org.eclipse.compare.ITypedElement#getName() > */ > public String getName() { >- return fHunkResult.getLabel(); >+ return fHunkResult.getHunk().getLabel(); > } > > /* (non-Javadoc) >@@ -86,7 +87,7 @@ > */ > public InputStream getContents() throws CoreException { > String contents = fHunkResult.getContents(fIsAfterState, fFullContext); >- return fHunkResult.asInputStream(contents); >+ return FileDiffResult.asInputStream(contents, fHunkResult.getCharset()); > } > > public String getCharset() throws CoreException { >#P org.eclipse.compare.core >Index: src/org/eclipse/compare/internal/core/patch/FileDiffResult.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java,v >retrieving revision 1.1 >diff -u -r1.1 FileDiffResult.java >--- src/org/eclipse/compare/internal/core/patch/FileDiffResult.java 15 Jul 2008 14:43:27 -0000 1.1 >+++ src/org/eclipse/compare/internal/core/patch/FileDiffResult.java 16 Feb 2009 10:55:18 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006, 2007 IBM Corporation and others. >+ * Copyright (c) 2006, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -99,9 +99,10 @@ > // results for display > fBeforeLines = new ArrayList(getLines(storage, false)); > fAfterLines = fMatches ? new ArrayList() : fBeforeLines; >- Hunk[] hunks = fDiff.getHunks(); >+ IHunk[] hunks = fDiff.getHunks(); > for (int i = 0; i < hunks.length; i++) { >- Hunk hunk = hunks[i]; >+ Hunk hunk = (Hunk) hunks[i]; >+ hunk.setCharset(charset); > HunkResult result = getHunkResult(hunk); > result.setMatches(false); > } >@@ -114,9 +115,9 @@ > if (fMatches) { > // Check to see if we have at least one hunk that matches > fMatches = false; >- Hunk[] hunks = fDiff.getHunks(); >+ IHunk[] hunks = fDiff.getHunks(); > for (int i = 0; i < hunks.length; i++) { >- Hunk hunk = hunks[i]; >+ Hunk hunk = (Hunk) hunks[i]; > HunkResult result = getHunkResult(hunk); > if (result.isOK()) { > fMatches = true; >@@ -157,9 +158,10 @@ > calculateFuzz(fBeforeLines, monitor); > } > int shift= 0; >- Hunk[] hunks = fDiff.getHunks(); >+ IHunk[] hunks = fDiff.getHunks(); > for (int i = 0; i < hunks.length; i++) { >- Hunk hunk = hunks[i]; >+ Hunk hunk = (Hunk) hunks[i]; >+ hunk.setCharset(charset); > HunkResult result = getHunkResult(hunk); > result.setShift(shift); > if (result.patch(lines)) { >@@ -226,9 +228,9 @@ > int shift= 0; > int highestFuzz = -1; // the maximum fuzz factor for all hunks > String name = getTargetPath() != null ? getTargetPath().lastSegment() : ""; //$NON-NLS-1$ >- Hunk[] hunks = fDiff.getHunks(); >+ IHunk[] hunks = fDiff.getHunks(); > for (int j = 0; j < hunks.length; j++) { >- Hunk h = hunks[j]; >+ Hunk h = (Hunk) hunks[j]; > monitor.subTask(NLS.bind(Messages.FileDiffResult_3, new String[] {name, Integer.toString(j + 1)})); > HunkResult result = getHunkResult(h); > result.setShift(shift); >@@ -264,16 +266,6 @@ > } > return failedHunks; > } >- >- private HunkResult[] getFailedHunkResults() { >- List failedHunks = new ArrayList(); >- for (Iterator iterator = fHunkResults.values().iterator(); iterator.hasNext();) { >- HunkResult result = (HunkResult) iterator.next(); >- if (!result.isOK()) >- failedHunks.add(result); >- } >- return (HunkResult[]) failedHunks.toArray(new HunkResult[failedHunks.size()]); >- } > > public FileDiff getDiff() { > return fDiff; >@@ -310,13 +302,14 @@ > } > > public IHunk[] getRejects() { >- return getFailedHunkResults(); >+ List failedHunks = getFailedHunks(); >+ return (IHunk[]) failedHunks.toArray(new IHunk[failedHunks.size()]); > } > > public boolean hasRejects() { >- return getFailedHunkResults().length > 0; >+ return getFailedHunks().size() > 0; > } >- >+ > public static InputStream asInputStream(String contents, String charSet) { > byte[] bytes = null; > if (charSet != null) { >Index: src/org/eclipse/compare/internal/core/patch/FileDiff.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiff.java,v >retrieving revision 1.1 >diff -u -r1.1 FileDiff.java >--- src/org/eclipse/compare/internal/core/patch/FileDiff.java 15 Jul 2008 14:43:27 -0000 1.1 >+++ src/org/eclipse/compare/internal/core/patch/FileDiff.java 16 Feb 2009 10:55:17 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006, 2008 IBM Corporation and others. >+ * Copyright (c) 2006, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -16,6 +16,7 @@ > > import org.eclipse.compare.patch.IFilePatch; > import org.eclipse.compare.patch.IFilePatchResult; >+import org.eclipse.compare.patch.IHunk; > import org.eclipse.compare.patch.PatchConfiguration; > import org.eclipse.core.resources.IStorage; > import org.eclipse.core.runtime.IPath; >@@ -124,8 +125,8 @@ > * Return the hunks associated with this file diff. > * @return the hunks associated with this file diff > */ >- public Hunk[] getHunks() { >- return (Hunk[]) fHunks.toArray(new Hunk[fHunks.size()]); >+ public IHunk[] getHunks() { >+ return (IHunk[]) fHunks.toArray(new IHunk[fHunks.size()]); > } > > /** >Index: src/org/eclipse/compare/internal/core/patch/IHunkFilter.java >=================================================================== >RCS file: src/org/eclipse/compare/internal/core/patch/IHunkFilter.java >diff -N src/org/eclipse/compare/internal/core/patch/IHunkFilter.java >--- src/org/eclipse/compare/internal/core/patch/IHunkFilter.java 15 Jul 2008 14:43:27 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,27 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.compare.internal.core.patch; >- >-/** >- * Filter that is used to determine if a hunk should be applied or not >- */ >-public interface IHunkFilter { >- >- public static final String HUNK_FILTER_PROPERTY = "org.eclipse.compare.core.hunkFilter"; //$NON-NLS-1$ >- >- /** >- * Returns true if the given hunk should be applied >- * @param hunk the hunk >- * @return true if the given hunk should be applied >- */ >- public boolean select(Hunk hunk); >- >-} >Index: src/org/eclipse/compare/internal/core/patch/HunkResult.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/HunkResult.java,v >retrieving revision 1.1 >diff -u -r1.1 HunkResult.java >--- src/org/eclipse/compare/internal/core/patch/HunkResult.java 15 Jul 2008 14:43:27 -0000 1.1 >+++ src/org/eclipse/compare/internal/core/patch/HunkResult.java 16 Feb 2009 10:55:18 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006, 2008 IBM Corporation and others. >+ * Copyright (c) 2006, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -10,15 +10,14 @@ > *******************************************************************************/ > package org.eclipse.compare.internal.core.patch; > >-import java.io.InputStream; > import java.util.List; > >-import org.eclipse.compare.patch.IHunk; >+import org.eclipse.compare.patch.IHunkFilter; > import org.eclipse.compare.patch.PatchConfiguration; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.OperationCanceledException; > >-public class HunkResult implements IHunk { >+public class HunkResult { > > private static final boolean DEBUG= false; > >@@ -251,10 +250,11 @@ > } > > private boolean isEnabled(PatchConfiguration configuration) { >- Object property = configuration.getProperty(IHunkFilter.HUNK_FILTER_PROPERTY); >- if (property instanceof IHunkFilter) { >- IHunkFilter filter = (IHunkFilter) property; >- return filter.select(fHunk); >+ IHunkFilter[] filters = configuration.getHunkFilters(); >+ for (int i = 0; i < filters.length; i++) { >+ if (!filters[i].select(fHunk)) { >+ return false; >+ } > } > return true; > } >@@ -263,29 +263,6 @@ > fMatches = matches; > } > >- public int getStartPosition() { >- return fHunk.getStart(getConfiguration().isReversed()) + fShift; >- } >- >- public String getLabel() { >- return getHunk().getDescription(); >- } >- >- public InputStream getOriginalContents() { >- String contents = getContents(false, false); >- return asInputStream(contents); >- } >- >- public InputStream asInputStream(String contents) { >- String charSet = getCharset(); >- return FileDiffResult.asInputStream(contents, charSet); >- } >- >- public InputStream getPatchedContents() { >- String contents = getContents(true, false); >- return asInputStream(contents); >- } >- > public String getCharset() { > return fDiffResult.getCharset(); > } >Index: src/org/eclipse/compare/internal/core/patch/Hunk.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java,v >retrieving revision 1.2 >diff -u -r1.2 Hunk.java >--- src/org/eclipse/compare/internal/core/patch/Hunk.java 9 Sep 2008 10:19:37 -0000 1.2 >+++ src/org/eclipse/compare/internal/core/patch/Hunk.java 16 Feb 2009 10:55:18 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -10,22 +10,25 @@ > *******************************************************************************/ > package org.eclipse.compare.internal.core.patch; > >+import java.io.InputStream; > import java.util.ArrayList; > import java.util.List; > >+import org.eclipse.compare.patch.IHunk; > import org.eclipse.compare.patch.PatchConfiguration; > import org.eclipse.core.runtime.Assert; > > /** > * A Hunk describes a range of changed lines and some context lines. > */ >-public class Hunk { >+public class Hunk implements IHunk { > > private FileDiff fParent; > private int fOldStart, fOldLength; > private int fNewStart, fNewLength; > private String[] fLines; > private int hunkType; >+ private String charset = null; > > public static Hunk createHunk(FileDiff parent, int[] oldRange, int[] newRange, List lines, boolean hasLineAdditions, boolean hasLineDeletions, boolean hasContextLines) { > int oldStart = 0; >@@ -461,4 +464,36 @@ > } > return result.toString(); > } >+ >+ public String getLabel() { >+ return getDescription(); >+ } >+ >+ public int getStartPosition() { >+ return getStart(false); >+ } >+ >+ public InputStream getOriginalContents() { >+ String contents = getContents(false, false); >+ return asInputStream(contents); >+ } >+ >+ public InputStream getPatchedContents() { >+ String contents = getContents(true, false); >+ return asInputStream(contents); >+ } >+ >+ private InputStream asInputStream(String contents) { >+ String charSet = getCharset(); >+ return FileDiffResult.asInputStream(contents, charSet); >+ } >+ >+ public void setCharset(String charset) { >+ this.charset = charset; >+ } >+ >+ public String getCharset() { >+ return charset; >+ } >+ > } >Index: src/org/eclipse/compare/patch/PatchConfiguration.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/patch/PatchConfiguration.java,v >retrieving revision 1.2 >diff -u -r1.2 PatchConfiguration.java >--- src/org/eclipse/compare/patch/PatchConfiguration.java 12 Aug 2008 11:20:56 -0000 1.2 >+++ src/org/eclipse/compare/patch/PatchConfiguration.java 16 Feb 2009 10:55:18 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007, 2008 IBM Corporation and others. >+ * Copyright (c) 2007, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -10,7 +10,9 @@ > *******************************************************************************/ > package org.eclipse.compare.patch; > >+import java.util.ArrayList; > import java.util.HashMap; >+import java.util.List; > > /** > * A patch configuration allows clients to set parameters that control how a >@@ -28,6 +30,7 @@ > private boolean fIgnoreWhitespace= false; > private boolean fReverse= false; > private HashMap properties = new HashMap(); >+ private List hunkFilters = new ArrayList(); > > /** > * Return whether the patch should be reversed when applied. >@@ -119,4 +122,37 @@ > public void setProperty(String key, Object value) { > properties.put(key, value); > } >+ >+ /** >+ * Adds a hunk filter. >+ * >+ * @param filter >+ * @since 3.5 >+ */ >+ public void addHunkFilter(IHunkFilter filter) { >+ hunkFilters.add(filter); >+ } >+ >+ /** >+ * Removes a hunk filter. >+ * >+ * @param filter >+ * @since 3.5 >+ */ >+ public void removeHunkFilter(IHunkFilter filter) { >+ hunkFilters.remove(filter); >+ } >+ >+ /** >+ * Return an array of hunk filters that have been added to this >+ * configuration. >+ * >+ * @return >+ * @since 3.5 >+ */ >+ public IHunkFilter[] getHunkFilters() { >+ return (IHunkFilter[]) hunkFilters.toArray(new IHunkFilter[hunkFilters >+ .size()]); >+ } >+ > } >Index: src/org/eclipse/compare/patch/IFilePatch.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/patch/IFilePatch.java,v >retrieving revision 1.2 >diff -u -r1.2 IFilePatch.java >--- src/org/eclipse/compare/patch/IFilePatch.java 12 Aug 2008 11:20:56 -0000 1.2 >+++ src/org/eclipse/compare/patch/IFilePatch.java 16 Feb 2009 10:55:18 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007, 2008 IBM Corporation and others. >+ * Copyright (c) 2007, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -83,4 +83,12 @@ > * @since 3.4 > */ > public long getAfterDate(); >+ >+ /** >+ * Returns all the hunks this file patch contains. >+ * >+ * @return array of hunks >+ * @since 3.5 >+ */ >+ public IHunk[] getHunks(); > } >Index: src/org/eclipse/compare/patch/IHunk.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/patch/IHunk.java,v >retrieving revision 1.2 >diff -u -r1.2 IHunk.java >--- src/org/eclipse/compare/patch/IHunk.java 12 Aug 2008 11:20:56 -0000 1.2 >+++ src/org/eclipse/compare/patch/IHunk.java 16 Feb 2009 10:55:18 -0000 >@@ -57,7 +57,7 @@ > * @return the contents that contain the modifications for this hunk > */ > public InputStream getPatchedContents(); >- >+ > /** > * Returns the name of a charset encoding to be used when decoding the contents > * of this hunk into characters. Returns <code>null</code> if a proper >@@ -72,8 +72,12 @@ > * @exception CoreException if an error happens while determining > * the charset. See any refinements for more information. > * @see IEncodedStorage >+ * @deprecated This method can be called before the first attempt to apply >+ * the hunk when it is impossible to determine the encoding and >+ * in this case it always resutns null. Please see >+ * {@link IFilePatchResult#getCharset()} as a poper way to obtain >+ * charset. > */ > public String getCharset() throws CoreException; >- >- >+ > } >Index: src/org/eclipse/compare/patch/IHunkFilter.java >=================================================================== >RCS file: src/org/eclipse/compare/patch/IHunkFilter.java >diff -N src/org/eclipse/compare/patch/IHunkFilter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/compare/patch/IHunkFilter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,29 @@ >+/******************************************************************************* >+ * Copyright (c) 2008, 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.compare.patch; >+ >+/** >+ * Filter that is used to determine if a hunk should be applied or not >+ * >+ * @since 3.5 >+ */ >+public interface IHunkFilter { >+ >+ /** >+ * Returns true if the given hunk should be applied >+ * >+ * @param hunk >+ * the hunk >+ * @return true if the given hunk should be applied >+ */ >+ public boolean select(IHunk hunk); >+ >+} >\ No newline at end of file
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 183238
:
125240
|
125371
|
125770
|
125776
|
125789