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 125622 Details for
Bug 263943
Make core.compare independent of core.resource - was: Provide RangeDifferencer API in the compare core plug-in
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Fix v02
263943_20090213.txt (text/plain), 68.19 KB, created by
Szymon Brandys
on 2009-02-13 07:23:42 EST
(
hide
)
Description:
Fix v02
Filename:
MIME Type:
Creator:
Szymon Brandys
Created:
2009-02-13 07:23:42 EST
Size:
68.19 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#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 13 Feb 2009 12:22:53 -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 >@@ -24,7 +24,7 @@ > 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.compare.patch.ReaderFactory; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.NullProgressMonitor; >@@ -63,18 +63,18 @@ > * Checks to see: > * 1) if the target file specified in fNewPath exists and is patchable > * 2) which hunks contained by this diff can actually be applied to the file >- * @param storage the contents being patched or <code>null</code> for an addition >+ * @param content the contents being patched or <code>null</code> for an addition > * @param monitor a progress monitor or <code>null</code> if no progress monitoring is desired > */ >- public void refresh(IStorage storage, IProgressMonitor monitor) { >+ public void refresh(ReaderFactory content, IProgressMonitor monitor) { > fMatches= false; > fDiffProblem= false; > boolean create= false; >- charset = Utilities.getCharset(storage); >+ charset = Utilities.getCharset(content); > //If this diff is an addition, make sure that it doesn't already exist >- boolean exists = targetExists(storage); >+ boolean exists = targetExists(content); > if (fDiff.getDiffType(getConfiguration().isReversed()) == FileDiff.ADDITION) { >- if ((!exists || isEmpty(storage)) && canCreateTarget(storage)) { >+ if ((!exists || isEmpty(content)) && canCreateTarget(content)) { > fMatches= true; > } else { > // file already exists >@@ -97,7 +97,7 @@ > // We couldn't find the target file or the patch is trying to add a > // file that already exists but we need to initialize the hunk > // results for display >- fBeforeLines = new ArrayList(getLines(storage, false)); >+ fBeforeLines = new ArrayList(getLines(content, false)); > fAfterLines = fMatches ? new ArrayList() : fBeforeLines; > Hunk[] hunks = fDiff.getHunks(); > for (int i = 0; i < hunks.length; i++) { >@@ -107,7 +107,7 @@ > } > } else { > // If this diff has no problems discovered so far, try applying the patch >- patch(getLines(storage, create), monitor); >+ patch(getLines(content, create), monitor); > } > > if (containsProblems()) { >@@ -127,20 +127,20 @@ > } > } > >- protected boolean canCreateTarget(IStorage storage) { >+ protected boolean canCreateTarget(ReaderFactory storage) { > return true; > } > >- protected boolean targetExists(IStorage storage) { >+ protected boolean targetExists(ReaderFactory storage) { > return storage != null; > } > >- protected List getLines(IStorage storage, boolean create) { >+ protected List getLines(ReaderFactory storage, boolean create) { > List lines = LineReader.load(storage, create); > return lines; > } > >- protected boolean isEmpty(IStorage storage) { >+ protected boolean isEmpty(ReaderFactory storage) { > if (storage == null) > return true; > return LineReader.load(storage, false).isEmpty(); >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 13 Feb 2009 12:22:53 -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 >@@ -14,10 +14,10 @@ > import java.util.Iterator; > import java.util.List; > >-import org.eclipse.compare.patch.IFilePatch; >+import org.eclipse.compare.patch.IFilePatch2; > import org.eclipse.compare.patch.IFilePatchResult; > import org.eclipse.compare.patch.PatchConfiguration; >-import org.eclipse.core.resources.IStorage; >+import org.eclipse.compare.patch.ReaderFactory; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.Path; >@@ -26,7 +26,7 @@ > * A file diff represents a set of hunks that were associated with the > * same path in a patch file. > */ >-public class FileDiff implements IFilePatch { >+public class FileDiff implements IFilePatch2 { > > /** > * Difference constant (value 1) indicating one side was added. >@@ -193,11 +193,11 @@ > length= Math.min(length, fNewPath.segmentCount()); > return length; > } >- >- public IFilePatchResult apply(IStorage contents, >+ >+ public IFilePatchResult apply(ReaderFactory content, > PatchConfiguration configuration, IProgressMonitor monitor) { > FileDiffResult result = new FileDiffResult(this, configuration); >- result.refresh(contents, monitor); >+ result.refresh(content, monitor); > return result; > } > >Index: src/org/eclipse/compare/internal/core/patch/DiffProject.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/DiffProject.java,v >retrieving revision 1.1 >diff -u -r1.1 DiffProject.java >--- src/org/eclipse/compare/internal/core/patch/DiffProject.java 15 Jul 2008 14:43:27 -0000 1.1 >+++ src/org/eclipse/compare/internal/core/patch/DiffProject.java 13 Feb 2009 12:22:52 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2006 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 >@@ -13,10 +13,6 @@ > import java.util.HashSet; > import java.util.Set; > >-import org.eclipse.core.resources.IFile; >-import org.eclipse.core.resources.IProject; >-import org.eclipse.core.runtime.IPath; >- > /** > * A diff project represents a project that was read from a workspace patch. > * It contains the set of file diffs that were associated with the project >@@ -24,15 +20,15 @@ > */ > public class DiffProject { > >- private IProject fProject; >+ private String project; > private Set fDiffs= new HashSet(); > > /** > * Create a diff project for the given workspace project. > * @param project a workspace project > */ >- public DiffProject(IProject project) { >- this.fProject= project; >+ public DiffProject(String project) { >+ this.project= project; > } > > /** >@@ -45,30 +41,12 @@ > diff.setProject(this); > } > >- >- /** >- * Return the workspace project associated with this diff project. >- * @return the workspace project associated with this project >- */ >- public IProject getProject() { >- return this.fProject; >- } >- > /** > * Return the name of this project. > * @return the name of this project > */ > public String getName() { >- return fProject.getName(); >- } >- >- /** >- * Return the file at the given path relative to this project. >- * @param path the relative path >- * @return the file at the given path relative to this project >- */ >- public IFile getFile(IPath path) { >- return fProject.getFile(path); >+ return project; > } > > /** >Index: src/org/eclipse/compare/internal/core/patch/PatchReader.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java,v >retrieving revision 1.2 >diff -u -r1.2 PatchReader.java >--- src/org/eclipse/compare/internal/core/patch/PatchReader.java 11 Sep 2008 12:34:08 -0000 1.2 >+++ src/org/eclipse/compare/internal/core/patch/PatchReader.java 13 Feb 2009 12:22:53 -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 >@@ -21,9 +21,7 @@ > import java.util.Locale; > import java.util.StringTokenizer; > >-import org.eclipse.compare.patch.IFilePatch; >-import org.eclipse.core.resources.IProject; >-import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.compare.patch.IFilePatch2; > import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.Path; >@@ -92,7 +90,7 @@ > String fileName= null; > // no project means this is a single patch,create a placeholder project for now > // which will be replaced by the target selected by the user in the preview pane >- String project= ""; //$NON-NLS-1$ >+ String projectName= ""; //$NON-NLS-1$ > fIsWorkspacePatch= false; > > LineReader lr= new LineReader(reader); >@@ -119,7 +117,7 @@ > continue; // too short > > if (line.startsWith(PatchReader.MULTIPROJECTPATCH_PROJECT)) { >- project= line.substring(2).trim(); >+ projectName= line.substring(2).trim(); > continue; > } > >@@ -138,12 +136,11 @@ > // reset the current project to the newly parsed one, create a new DiffProject > // and add it to the array > DiffProject diffProject; >- if (!diffProjects.containsKey(project)) { >- IProject iproject= ResourcesPlugin.getWorkspace().getRoot().getProject(project); >- diffProject= new DiffProject(iproject); >- diffProjects.put(project, diffProject); >+ if (!diffProjects.containsKey(projectName)) { >+ diffProject= new DiffProject(projectName); >+ diffProjects.put(projectName, diffProject); > } else { >- diffProject= (DiffProject) diffProjects.get(project); >+ diffProject= (DiffProject) diffProjects.get(projectName); > } > > line= readUnifiedDiff(diffs, lr, line, diffArgs, fileName, diffProject); >@@ -574,7 +571,7 @@ > } > // System.err.println("can't parse date: <" + line + ">"); > } >- return IFilePatch.DATE_UNKNOWN; >+ return IFilePatch2.DATE_UNKNOWN; > } > > /* >Index: src/org/eclipse/compare/internal/core/patch/LineReader.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java,v >retrieving revision 1.2 >diff -u -r1.2 LineReader.java >--- src/org/eclipse/compare/internal/core/patch/LineReader.java 11 Sep 2008 12:34:08 -0000 1.2 >+++ src/org/eclipse/compare/internal/core/patch/LineReader.java 13 Feb 2009 12:22:53 -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 >@@ -13,98 +13,48 @@ > > import java.io.BufferedReader; > import java.io.IOException; >-import java.io.InputStream; >-import java.io.InputStreamReader; >-import java.io.Reader; >-import java.io.UnsupportedEncodingException; > import java.util.ArrayList; > import java.util.Iterator; > import java.util.List; > > import org.eclipse.compare.internal.core.Activator; >-import org.eclipse.core.resources.IEncodedStorage; >-import org.eclipse.core.resources.IFile; >-import org.eclipse.core.resources.IStorage; >+import org.eclipse.compare.patch.ReaderFactory; > import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.Platform; > > public class LineReader { >- >- public static BufferedReader createReader(IStorage storage) throws CoreException { >- String charset = null; >- if (storage instanceof IEncodedStorage) { >- IEncodedStorage es = (IEncodedStorage) storage; >- charset = es.getCharset(); >- } >- InputStreamReader in = null; >- if (charset != null) { >- InputStream contents = storage.getContents(); >- try { >- in = new InputStreamReader(contents, charset); >- } catch (UnsupportedEncodingException e) { >- Activator.log(e); >- try { >- contents.close(); >- } catch (IOException e1) { >- // Ignore >- } >- } >- } >- if (in == null) { >- in = new InputStreamReader(storage.getContents()); >- } >- return new BufferedReader(in); >- } > > /* > * Reads the contents from the given file and returns them as > * a List of lines. > */ >- public static List load(IStorage file, boolean create) { >- List lines= null; >- if (!create && file != null && exists(file)) { >+ public static List load(ReaderFactory readerFactory, boolean create) { >+ List lines = null; >+ BufferedReader bufferedReader = null; >+ if (!create && readerFactory != null) { > // read current contents >- String charset = Utilities.getCharset(file); >- InputStream is= null; > try { >- is= file.getContents(); >- >- Reader streamReader= null; >- try { >- streamReader= new InputStreamReader(is, charset); >- } catch (UnsupportedEncodingException x) { >- // use default encoding >- streamReader= new InputStreamReader(is); >- } >- >- BufferedReader reader= new BufferedReader(streamReader); >- lines = readLines(reader); >- } catch(CoreException ex) { >- // TODO >+ bufferedReader = new BufferedReader(readerFactory >+ .createReader()); >+ lines = readLines(bufferedReader); >+ } catch (CoreException ex) { > Activator.log(ex); > } finally { >- if (is != null) >+ if (bufferedReader != null) > try { >- is.close(); >- } catch(IOException ex) { >+ bufferedReader.close(); >+ } catch (IOException ex) { > // silently ignored > } > } > } >- >+ > if (lines == null) >- lines= new ArrayList(); >+ lines = new ArrayList(); > return lines; > } > >- private static boolean exists(IStorage file) { >- if (file instanceof IFile) { >- return ((IFile) file).exists(); >- } >- return true; >- } >- > public static List readLines(BufferedReader reader) { > List lines; > LineReader lr= new LineReader(reader); >Index: src/org/eclipse/compare/internal/core/patch/Utilities.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Utilities.java,v >retrieving revision 1.1 >diff -u -r1.1 Utilities.java >--- src/org/eclipse/compare/internal/core/patch/Utilities.java 15 Jul 2008 14:43:27 -0000 1.1 >+++ src/org/eclipse/compare/internal/core/patch/Utilities.java 13 Feb 2009 12:22:53 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2008 IBM Corporation and others. >+ * Copyright (c) 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,14 @@ > *******************************************************************************/ > package org.eclipse.compare.internal.core.patch; > >-import org.eclipse.compare.internal.core.Activator; >-import org.eclipse.core.resources.IEncodedStorage; >-import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.core.runtime.CoreException; >+import java.io.InputStreamReader; > > public class Utilities { > > public static String getCharset(Object resource) { >- if (resource instanceof IEncodedStorage) { >- try { >- return ((IEncodedStorage)resource).getCharset(); >- } catch (CoreException ex) { >- Activator.log(ex); >- } >+ if (resource instanceof InputStreamReader) { >+ return ((InputStreamReader) resource).getEncoding(); > } >- return ResourcesPlugin.getEncoding(); >+ return null; > } >- > } >Index: src/org/eclipse/compare/patch/IFilePatch.java >=================================================================== >RCS file: src/org/eclipse/compare/patch/IFilePatch.java >diff -N src/org/eclipse/compare/patch/IFilePatch.java >--- src/org/eclipse/compare/patch/IFilePatch.java 12 Aug 2008 11:20:56 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,86 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2007, 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.patch; >- >-import org.eclipse.core.resources.IStorage; >-import org.eclipse.core.runtime.IPath; >-import org.eclipse.core.runtime.IProgressMonitor; >- >-/** >- * A representation of a file patch that can be applied to an input stream. >- * >- * @see ApplyPatchOperation#parsePatch(org.eclipse.core.resources.IStorage) >- * @since 3.3 >- * @noimplement This interface is not intended to be implemented by clients. >- * Clients can obtain file patches by calling >- * {@link ApplyPatchOperation#parsePatch(org.eclipse.core.resources.IStorage)}. >- */ >-public interface IFilePatch { >- >- /** >- * Special constant that will be returned from get getBeforeDate() or >- * getAfterDate() if the date is unknown. Equal to Midnight, Jan 1, 1970 >- * GMT. >- * >- * @since 3.4 >- */ >- public static long DATE_UNKNOWN = 0; >- >- /** >- * Return the target path for this patch. The target path may differ >- * depending on whether the patch is being reversed or not. >- * >- * @param configuration the patch configuration >- * @return the target path for this patch >- * @see PatchConfiguration#isReversed() >- */ >- public IPath getTargetPath(PatchConfiguration configuration); >- >- /** >- * Apply this patch to the given file contents. The result provides the >- * original and patch contents and also indicates whether some portions of >- * the patch (called hunks) failed to apply. >- * >- * @param contents the file contents >- * @param configuration the patch configuration >- * @param monitor a progress monitor >- * @return the result of the patch application >- */ >- public IFilePatchResult apply(IStorage contents, >- PatchConfiguration configuration, IProgressMonitor monitor); >- >- /** >- * Return the header information of the patch or >- * <code>null</code> if there was no header text. >- * The header may be multi-line. >- * @return the header information of the patch or >- * <code>null</code> >- */ >- public String getHeader(); >- >- /** >- * Returns the milliseconds time value of the before date from the patch, or >- * DATE_UNKNOWN if the date is unknown. >- * >- * @return milliseconds time value of the before date from the patch >- * @since 3.4 >- */ >- public long getBeforeDate(); >- >- /** >- * Returns the milliseconds time value of the after date from the patch, or >- * DATE_UNKNOWN if the date is unknown. >- * >- * @return milliseconds time value of the after date from the patch >- * @since 3.4 >- */ >- public long getAfterDate(); >-} >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 13 Feb 2009 12:22:53 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2007 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 >@@ -12,7 +12,6 @@ > > import java.io.InputStream; > >-import org.eclipse.core.resources.IEncodedStorage; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IAdaptable; > >@@ -71,7 +70,6 @@ > * @return the name of a charset, or <code>null</code> > * @exception CoreException if an error happens while determining > * the charset. See any refinements for more information. >- * @see IEncodedStorage > */ > public String getCharset() throws CoreException; > >Index: src/org/eclipse/compare/patch/PatchParser.java >=================================================================== >RCS file: src/org/eclipse/compare/patch/PatchParser.java >diff -N src/org/eclipse/compare/patch/PatchParser.java >--- src/org/eclipse/compare/patch/PatchParser.java 15 Jul 2008 14:43:27 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,52 +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.patch; >- >-import java.io.BufferedReader; >-import java.io.IOException; >- >-import org.eclipse.compare.internal.core.Activator; >-import org.eclipse.compare.internal.core.patch.LineReader; >-import org.eclipse.compare.internal.core.patch.PatchReader; >-import org.eclipse.core.resources.IStorage; >-import org.eclipse.core.runtime.CoreException; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Status; >- >-/** >- * Helper class for parsing patches. >- * >- * @since 3.4.100 >- */ >-public class PatchParser { >- >- /** >- * Parse the given patch and return the set of file patches that it contains. >- * @param storage the storage that contains the patch >- * @return the set of file patches that the storage contains >- * @throws CoreException if an error occurs reading the contents from the storage >- */ >- public static IFilePatch[] parsePatch(IStorage storage) throws CoreException { >- BufferedReader reader = LineReader.createReader(storage); >- try { >- PatchReader patchReader= new PatchReader(); >- patchReader.parse(reader); >- return patchReader.getAdjustedDiffs(); >- } catch (IOException e) { >- throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getMessage(), e)); >- } finally { >- try { >- reader.close(); >- } catch (IOException e) { //ignored >- } >- } >- } >-} >Index: src/org/eclipse/compare/patch/IFilePatchResult.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/patch/IFilePatchResult.java,v >retrieving revision 1.2 >diff -u -r1.2 IFilePatchResult.java >--- src/org/eclipse/compare/patch/IFilePatchResult.java 12 Aug 2008 11:20:56 -0000 1.2 >+++ src/org/eclipse/compare/patch/IFilePatchResult.java 13 Feb 2009 12:22:53 -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 >@@ -12,7 +12,6 @@ > > import java.io.InputStream; > >-import org.eclipse.core.resources.IEncodedStorage; > import org.eclipse.core.runtime.CoreException; > > /** >@@ -85,7 +84,6 @@ > * @return the name of a charset, or <code>null</code> > * @exception CoreException if an error happens while determining > * the charset. See any refinements for more information. >- * @see IEncodedStorage > */ > public String getCharset() throws CoreException; > >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/META-INF/MANIFEST.MF,v >retrieving revision 1.4 >diff -u -r1.4 MANIFEST.MF >--- META-INF/MANIFEST.MF 10 Oct 2008 14:55:33 -0000 1.4 >+++ META-INF/MANIFEST.MF 13 Feb 2009 12:22:52 -0000 >@@ -5,8 +5,7 @@ > Bundle-Version: 1.0.0.qualifier > Bundle-Activator: org.eclipse.compare.internal.core.Activator > Bundle-Vendor: %providerName >-Require-Bundle: org.eclipse.core.runtime, >- org.eclipse.core.resources;bundle-version="3.3.0" >+Require-Bundle: org.eclipse.core.runtime > Bundle-RequiredExecutionEnvironment: J2SE-1.4 > Bundle-ActivationPolicy: lazy > Export-Package: org.eclipse.compare.internal.core;x-internal:=true, >Index: src/org/eclipse/compare/patch/ReaderFactory.java >=================================================================== >RCS file: src/org/eclipse/compare/patch/ReaderFactory.java >diff -N src/org/eclipse/compare/patch/ReaderFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/compare/patch/ReaderFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,33 @@ >+/******************************************************************************* >+ * Copyright (c) 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; >+ >+import java.io.Reader; >+ >+import org.eclipse.core.runtime.CoreException; >+ >+/** >+ * Abstract class for creating readers. >+ * >+ * @since org.eclipse.compare.core 1.0.0 >+ */ >+public abstract class ReaderFactory { >+ >+ /** >+ * Creates new reader. The caller is responsible for closing the reader when >+ * finished. >+ * >+ * @return a reader >+ * @exception CoreException >+ * if the reader can't be created >+ */ >+ public abstract Reader createReader() throws CoreException; >+} >Index: src/org/eclipse/compare/patch/IFilePatch2.java >=================================================================== >RCS file: src/org/eclipse/compare/patch/IFilePatch2.java >diff -N src/org/eclipse/compare/patch/IFilePatch2.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/compare/patch/IFilePatch2.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,81 @@ >+/******************************************************************************* >+ * Copyright (c) 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; >+ >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+ >+/** >+ * A representation of a file patch that can be applied to an input stream. >+ * >+ * @noimplement This interface is not intended to be implemented by clients. >+ * @since org.eclipse.compare.core 1.0.0 >+ */ >+public interface IFilePatch2 { >+ >+ /** >+ * Special constant that will be returned from get getBeforeDate() or >+ * getAfterDate() if the date is unknown. Equal to Midnight, Jan 1, 1970 >+ * GMT. >+ */ >+ public static long DATE_UNKNOWN = 0; >+ >+ /** >+ * Return the target path for this patch. The target path may differ >+ * depending on whether the patch is being reversed or not. >+ * >+ * @param configuration >+ * the patch configuration >+ * @return the target path for this patch >+ * @see PatchConfiguration#isReversed() >+ */ >+ public IPath getTargetPath(PatchConfiguration configuration); >+ >+ /** >+ * Apply this patch to the given file contents. The result provides the >+ * original and patch contents and also indicates whether some portions of >+ * the patch (called hunks) failed to apply. >+ * >+ * @param content >+ * the file contents >+ * @param configuration >+ * the patch configuration >+ * @param monitor >+ * a progress monitor >+ * @return the result of the patch application >+ */ >+ public IFilePatchResult apply(ReaderFactory content, >+ PatchConfiguration configuration, IProgressMonitor monitor); >+ >+ /** >+ * Return the header information of the patch or <code>null</code> if there >+ * was no header text. The header may be multi-line. >+ * >+ * @return the header information of the patch or <code>null</code> >+ */ >+ public String getHeader(); >+ >+ /** >+ * Returns the milliseconds time value of the before date from the patch, or >+ * DATE_UNKNOWN if the date is unknown. >+ * >+ * @return milliseconds time value of the before date from the patch >+ */ >+ public long getBeforeDate(); >+ >+ /** >+ * Returns the milliseconds time value of the after date from the patch, or >+ * DATE_UNKNOWN if the date is unknown. >+ * >+ * @return milliseconds time value of the after date from the patch >+ */ >+ public long getAfterDate(); >+} >Index: src/org/eclipse/compare/patch/PatchParser2.java >=================================================================== >RCS file: src/org/eclipse/compare/patch/PatchParser2.java >diff -N src/org/eclipse/compare/patch/PatchParser2.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/compare/patch/PatchParser2.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,57 @@ >+/******************************************************************************* >+ * Copyright (c) 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; >+ >+import java.io.BufferedReader; >+import java.io.IOException; >+ >+import org.eclipse.compare.internal.core.Activator; >+import org.eclipse.compare.internal.core.patch.PatchReader; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+ >+/** >+ * Helper class for parsing patches. >+ * >+ * @since org.eclipse.compare.core 1.0.0 >+ */ >+public class PatchParser2 { >+ >+ /** >+ * Parse the given patch and return the set of file patches that it >+ * contains. >+ * >+ * @param content >+ * a patch reader factory >+ * @return the set of file patches that the patch contains >+ * @throws CoreException >+ * if an error occurs reading the contents >+ */ >+ public static IFilePatch2[] parsePatch(ReaderFactory content) >+ throws CoreException { >+ BufferedReader reader = new BufferedReader(content.createReader()); >+ try { >+ PatchReader patchReader = new PatchReader(); >+ patchReader.parse(reader); >+ return patchReader.getAdjustedDiffs(); >+ } catch (IOException e) { >+ throw new CoreException(new Status(IStatus.ERROR, >+ Activator.PLUGIN_ID, 0, e.getMessage(), e)); >+ } finally { >+ try { >+ reader.close(); >+ } catch (IOException e) { >+ // ignored >+ } >+ } >+ } >+} >#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 13 Feb 2009 12:22:55 -0000 >@@ -32,9 +32,7 @@ > 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.PatchConfiguration; > import org.eclipse.core.resources.IContainer; > import org.eclipse.core.resources.IFile; >@@ -731,7 +729,7 @@ > public IProject getTargetProject(FileDiff diff) { > DiffProject dp = getProject(diff); > if (dp != null) >- return dp.getProject(); >+ return Utilities.getProject(dp); > IResource tr = getTarget(); > if (tr instanceof IWorkspaceRoot) { > IWorkspaceRoot root = (IWorkspaceRoot) tr; >Index: compare/org/eclipse/compare/internal/patch/UnmatchedHunkTypedElement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/UnmatchedHunkTypedElement.java,v >retrieving revision 1.6 >diff -u -r1.6 UnmatchedHunkTypedElement.java >--- compare/org/eclipse/compare/internal/patch/UnmatchedHunkTypedElement.java 15 Jul 2008 14:45:28 -0000 1.6 >+++ compare/org/eclipse/compare/internal/patch/UnmatchedHunkTypedElement.java 13 Feb 2009 12:22:56 -0000 >@@ -23,7 +23,6 @@ > import org.eclipse.compare.internal.ContentChangeNotifier; > import org.eclipse.compare.internal.core.patch.FileDiff; > import org.eclipse.compare.internal.core.patch.HunkResult; >-import org.eclipse.compare.internal.core.patch.LineReader; > import org.eclipse.compare.patch.PatchConfiguration; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.runtime.CoreException; >Index: compare/org/eclipse/compare/internal/patch/PatchProjectDiffNode.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchProjectDiffNode.java,v >retrieving revision 1.5 >diff -u -r1.5 PatchProjectDiffNode.java >--- compare/org/eclipse/compare/internal/patch/PatchProjectDiffNode.java 15 Jul 2008 14:45:29 -0000 1.5 >+++ compare/org/eclipse/compare/internal/patch/PatchProjectDiffNode.java 13 Feb 2009 12:22:55 -0000 >@@ -40,7 +40,7 @@ > * @see org.eclipse.compare.structuremergeviewer.DiffNode#getImage() > */ > public Image getImage() { >- Image image = CompareUI.getImage(project.getProject()); >+ Image image = CompareUI.getImage(Utilities.getProject(project)); > if (containsProblems()) { > LocalResourceManager imageCache = PatchCompareEditorInput.getImageCache(getConfiguration()); > image = HunkTypedElement.getHunkErrorImage(image, imageCache, true); >Index: compare/org/eclipse/compare/internal/patch/WorkspaceFileDiffResult.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/WorkspaceFileDiffResult.java,v >retrieving revision 1.2 >diff -u -r1.2 WorkspaceFileDiffResult.java >--- compare/org/eclipse/compare/internal/patch/WorkspaceFileDiffResult.java 15 Jul 2008 14:45:29 -0000 1.2 >+++ compare/org/eclipse/compare/internal/patch/WorkspaceFileDiffResult.java 13 Feb 2009 12:22:56 -0000 >@@ -14,7 +14,6 @@ > > import org.eclipse.compare.internal.core.patch.FileDiff; > import org.eclipse.compare.internal.core.patch.FileDiffResult; >-import org.eclipse.compare.internal.core.patch.LineReader; > import org.eclipse.compare.patch.PatchConfiguration; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IProject; >@@ -52,7 +51,6 @@ > } > > public void refresh() { >- refresh(getTargetFile(), null); >+ refresh(Utilities.getReaderFactory(getTargetFile()), null); > } >- > } >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 13 Feb 2009 12:22:56 -0000 >@@ -20,7 +20,6 @@ > import org.eclipse.compare.internal.core.patch.DiffProject; > import org.eclipse.compare.internal.core.patch.FileDiff; > 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.core.resources.IFile; > import org.eclipse.core.resources.IMarker; >@@ -83,7 +82,7 @@ > List list= new ArrayList(); > for (int j= 0; j < fDiffProjects.length; j++) { > DiffProject diffProject= fDiffProjects[j]; >- if (diffProject.getProject().isAccessible()) >+ if (Utilities.getProject(diffProject).isAccessible()) > list.addAll(Arrays.asList(getTargetFiles(diffProject))); > } > // validate the files for editing >@@ -165,7 +164,7 @@ > } > > private boolean isAccessible(FileDiff diff) { >- return isEnabled(diff) && diff.getProject().getProject().isAccessible(); >+ return isEnabled(diff) && Utilities.getProject(diff.getProject()).isAccessible(); > } > > /** >@@ -190,7 +189,7 @@ > IPath path = diff.getStrippedPath(getStripPrefixSegments(), isReversed()); > DiffProject project = getProject(diff); > if (project != null) >- return project.getFile(path); >+ return Utilities.getProject(project).getFile(path); > return super.getTargetFile(diff); > } > >@@ -198,7 +197,7 @@ > IPath path = diff.getStrippedPath(getStripPrefixSegments(), isReversed()); > DiffProject project = getProject(diff); > if (project != null) >- return project.getFile(path).getFullPath(); >+ return Utilities.getProject(project).getFile(path).getFullPath(); > return getTarget().getFullPath().append(path); > } > >@@ -207,7 +206,7 @@ > IResourceRuleFactory ruleFactory= ResourcesPlugin.getWorkspace().getRuleFactory(); > // Determine the appropriate scheduling rules > for (int i= 0; i < fDiffProjects.length; i++) { >- IProject tempProject= fDiffProjects[i].getProject(); >+ IProject tempProject= Utilities.getProject(fDiffProjects[i]); > // The goal here is to lock as little of the workspace as necessary > // but still allow the patcher to obtain the locks it needs. > // As such, we need to get the modify rules from the rule factory for the .project file. A pessimistic >@@ -281,7 +280,7 @@ > IProject project = file.getProject(); > DiffProject[] diffProjects = getDiffProjects(); > for (int i = 0; i < diffProjects.length; i++) { >- if (diffProjects[i].getProject().equals(project)){ >+ if (Utilities.getProject(diffProjects[i]).equals(project)){ > diffProject = diffProjects[i]; > break; > } >@@ -326,7 +325,7 @@ > > private DiffProject addDiffProjectForProject(IProject project) { > DiffProject[] diffProjects = getDiffProjects(); >- DiffProject diffProject = new DiffProject(project); >+ DiffProject diffProject = new DiffProject(project.getName()); > DiffProject[] newProjectArray = new DiffProject[diffProjects.length + 1]; > System.arraycopy(diffProjects, 0, newProjectArray, 0, diffProjects.length); > newProjectArray[diffProjects.length] = diffProject; >@@ -340,7 +339,7 @@ > } > > public void retargetProject(DiffProject project, IProject targetProject) { >- retargetedDiffs.put(project, project.getProject().getFullPath()); >+ retargetedDiffs.put(project, Utilities.getProject(project).getFullPath()); > FileDiff[] diffs = project.getFileDiffs(); > DiffProject selectedProject = getDiffProject(targetProject); > if (selectedProject == null) >@@ -366,7 +365,7 @@ > return null; > DiffProject[] projects = getDiffProjects(); > for (int i = 0; i < projects.length; i++) { >- if (projects[i].getProject().equals(project)) >+ if (Utilities.getProject(projects[i]).equals(project)) > return projects[i]; > } > return null; >Index: compare/org/eclipse/compare/internal/patch/RetargetPatchElementDialog.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/RetargetPatchElementDialog.java,v >retrieving revision 1.2 >diff -u -r1.2 RetargetPatchElementDialog.java >--- compare/org/eclipse/compare/internal/patch/RetargetPatchElementDialog.java 15 Jul 2008 14:45:29 -0000 1.2 >+++ compare/org/eclipse/compare/internal/patch/RetargetPatchElementDialog.java 13 Feb 2009 12:22:56 -0000 >@@ -135,7 +135,7 @@ > } else if (fSelectedNode instanceof PatchProjectDiffNode) { > PatchProjectDiffNode node = (PatchProjectDiffNode) fSelectedNode; > DiffProject diffProject = node.getDiffProject(); >- return diffProject.getProject(); >+ return Utilities.getProject(diffProject); > } > return null; > } >Index: compare/org/eclipse/compare/internal/patch/PatchCompareEditorInput.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchCompareEditorInput.java,v >retrieving revision 1.9 >diff -u -r1.9 PatchCompareEditorInput.java >--- compare/org/eclipse/compare/internal/patch/PatchCompareEditorInput.java 15 Jul 2008 14:45:28 -0000 1.9 >+++ compare/org/eclipse/compare/internal/patch/PatchCompareEditorInput.java 13 Feb 2009 12:22:55 -0000 >@@ -59,7 +59,7 @@ > PatchDiffNode node = (PatchDiffNode) element; > if (node instanceof PatchProjectDiffNode) { > PatchProjectDiffNode projectNode = (PatchProjectDiffNode) node; >- if (!projectNode.getDiffProject().getProject().exists()) { >+ if (!Utilities.getProject(projectNode.getDiffProject()).exists()) { > text = NLS.bind(PatchMessages.Diff_2Args, new String[]{text, PatchMessages.PreviewPatchLabelDecorator_ProjectDoesNotExist}); > } > } >Index: compare/org/eclipse/compare/internal/patch/PatchFileTypedElement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchFileTypedElement.java,v >retrieving revision 1.6 >diff -u -r1.6 PatchFileTypedElement.java >--- compare/org/eclipse/compare/internal/patch/PatchFileTypedElement.java 15 Jul 2008 14:45:28 -0000 1.6 >+++ compare/org/eclipse/compare/internal/patch/PatchFileTypedElement.java 13 Feb 2009 12:22:55 -0000 >@@ -21,7 +21,6 @@ > import org.eclipse.compare.internal.CompareUIPlugin; > import org.eclipse.compare.internal.core.patch.DiffProject; > import org.eclipse.compare.internal.core.patch.FileDiffResult; >-import org.eclipse.compare.internal.core.patch.LineReader; > import org.eclipse.core.resources.IContainer; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IResource; >@@ -29,7 +28,8 @@ > import org.eclipse.jface.resource.LocalResourceManager; > import org.eclipse.swt.graphics.Image; > >-public class PatchFileTypedElement implements ITypedElement, IEncodedStreamContentAccessor { >+public class PatchFileTypedElement implements ITypedElement, >+ IEncodedStreamContentAccessor { > > private final FileDiffResult result; > private final boolean isAfterState; >@@ -45,11 +45,13 @@ > // We don't get a target file if the file doesn't exist > DiffProject project = result.getDiff().getProject(); > if (project != null) { >- file = project.getFile(result.getDiff().getPath(result.getConfiguration().isReversed())); >+ file = Utilities.getProject(project).getFile( >+ result.getDiff().getPath( >+ result.getConfiguration().isReversed())); > } else { > IResource target = getPatcher().getTarget(); > if (target instanceof IFile) { >- file = (IFile) target; >+ file = (IFile) target; > } else if (target instanceof IContainer) { > IContainer container = (IContainer) target; > file = container.getFile(result.getTargetPath()); >@@ -61,20 +63,25 @@ > image = CompareUI.getImage(file); > } > if (result.containsProblems()) { >- LocalResourceManager imageCache = PatchCompareEditorInput.getImageCache(result.getConfiguration()); >+ LocalResourceManager imageCache = PatchCompareEditorInput >+ .getImageCache(result.getConfiguration()); > image = HunkTypedElement.getHunkErrorImage(image, imageCache, true); > } > return image; > } > >- /* (non-Javadoc) >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.compare.ITypedElement#getName() > */ > public String getName() { > return result.getTargetPath().toString(); > } > >- /* (non-Javadoc) >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.compare.ITypedElement#getType() > */ > public String getType() { >@@ -89,7 +96,8 @@ > public InputStream getContents() throws CoreException { > // If there are cached contents, use them > if (isAfterState && getPatcher().hasCachedContents(result.getDiff())) >- return new ByteArrayInputStream(getPatcher().getCachedContents(result.getDiff())); >+ return new ByteArrayInputStream(getPatcher().getCachedContents( >+ result.getDiff())); > // Otherwise, get the lines from the diff result > List lines; > if (isAfterState) { >@@ -97,7 +105,8 @@ > } else { > lines = result.getBeforeLines(); > } >- String contents = LineReader.createString(getPatcher().isPreserveLineDelimeters(), lines); >+ String contents = LineReader.createString(getPatcher() >+ .isPreserveLineDelimeters(), lines); > String charSet = getCharset(); > byte[] bytes = null; > if (charSet != null) { >Index: compare/org/eclipse/compare/patch/IFilePatch.java >=================================================================== >RCS file: compare/org/eclipse/compare/patch/IFilePatch.java >diff -N compare/org/eclipse/compare/patch/IFilePatch.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ compare/org/eclipse/compare/patch/IFilePatch.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,86 @@ >+/******************************************************************************* >+ * Copyright (c) 2007, 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.patch; >+ >+import org.eclipse.core.resources.IStorage; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+ >+/** >+ * A representation of a file patch that can be applied to an input stream. >+ * >+ * @see ApplyPatchOperation#parsePatch(org.eclipse.core.resources.IStorage) >+ * @since 3.3 >+ * @noimplement This interface is not intended to be implemented by clients. >+ * Clients can obtain file patches by calling >+ * {@link ApplyPatchOperation#parsePatch(org.eclipse.core.resources.IStorage)}. >+ */ >+public interface IFilePatch { >+ >+ /** >+ * Special constant that will be returned from get getBeforeDate() or >+ * getAfterDate() if the date is unknown. Equal to Midnight, Jan 1, 1970 >+ * GMT. >+ * >+ * @since 3.4 >+ */ >+ public static long DATE_UNKNOWN = 0; >+ >+ /** >+ * Return the target path for this patch. The target path may differ >+ * depending on whether the patch is being reversed or not. >+ * >+ * @param configuration the patch configuration >+ * @return the target path for this patch >+ * @see PatchConfiguration#isReversed() >+ */ >+ public IPath getTargetPath(PatchConfiguration configuration); >+ >+ /** >+ * Apply this patch to the given file contents. The result provides the >+ * original and patch contents and also indicates whether some portions of >+ * the patch (called hunks) failed to apply. >+ * >+ * @param contents the file contents >+ * @param configuration the patch configuration >+ * @param monitor a progress monitor >+ * @return the result of the patch application >+ */ >+ public IFilePatchResult apply(IStorage contents, >+ PatchConfiguration configuration, IProgressMonitor monitor); >+ >+ /** >+ * Return the header information of the patch or >+ * <code>null</code> if there was no header text. >+ * The header may be multi-line. >+ * @return the header information of the patch or >+ * <code>null</code> >+ */ >+ public String getHeader(); >+ >+ /** >+ * Returns the milliseconds time value of the before date from the patch, or >+ * DATE_UNKNOWN if the date is unknown. >+ * >+ * @return milliseconds time value of the before date from the patch >+ * @since 3.4 >+ */ >+ public long getBeforeDate(); >+ >+ /** >+ * Returns the milliseconds time value of the after date from the patch, or >+ * DATE_UNKNOWN if the date is unknown. >+ * >+ * @return milliseconds time value of the after date from the patch >+ * @since 3.4 >+ */ >+ public long getAfterDate(); >+} >Index: compare/org/eclipse/compare/internal/patch/LineReader.java >=================================================================== >RCS file: compare/org/eclipse/compare/internal/patch/LineReader.java >diff -N compare/org/eclipse/compare/internal/patch/LineReader.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ compare/org/eclipse/compare/internal/patch/LineReader.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,276 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 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 >+ * Brock Janiczak <brockj@tpg.com.au> - Bug 181919 LineReader creating unneeded garbage >+ *******************************************************************************/ >+package org.eclipse.compare.internal.patch; >+ >+import java.io.BufferedReader; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.InputStreamReader; >+import java.io.Reader; >+import java.io.UnsupportedEncodingException; >+import java.util.ArrayList; >+import java.util.Iterator; >+import java.util.List; >+ >+import org.eclipse.compare.internal.core.Activator; >+import org.eclipse.core.resources.IEncodedStorage; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IStorage; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.Platform; >+ >+public class LineReader { >+ >+ public static BufferedReader createReader(IStorage storage) throws CoreException { >+ String charset = null; >+ if (storage instanceof IEncodedStorage) { >+ IEncodedStorage es = (IEncodedStorage) storage; >+ charset = es.getCharset(); >+ } >+ InputStreamReader in = null; >+ if (charset != null) { >+ InputStream contents = storage.getContents(); >+ try { >+ in = new InputStreamReader(contents, charset); >+ } catch (UnsupportedEncodingException e) { >+ Activator.log(e); >+ try { >+ contents.close(); >+ } catch (IOException e1) { >+ // Ignore >+ } >+ } >+ } >+ if (in == null) { >+ in = new InputStreamReader(storage.getContents()); >+ } >+ return new BufferedReader(in); >+ } >+ >+ /* >+ * Reads the contents from the given file and returns them as >+ * a List of lines. >+ */ >+ public static List load(IStorage file, boolean create) { >+ List lines= null; >+ if (!create && file != null && exists(file)) { >+ // read current contents >+ String charset = Utilities.getCharset(file); >+ InputStream is= null; >+ try { >+ is= file.getContents(); >+ >+ Reader streamReader= null; >+ try { >+ streamReader= new InputStreamReader(is, charset); >+ } catch (UnsupportedEncodingException x) { >+ // use default encoding >+ streamReader= new InputStreamReader(is); >+ } >+ >+ BufferedReader reader= new BufferedReader(streamReader); >+ lines = readLines(reader); >+ } catch(CoreException ex) { >+ // TODO >+ Activator.log(ex); >+ } finally { >+ if (is != null) >+ try { >+ is.close(); >+ } catch(IOException ex) { >+ // silently ignored >+ } >+ } >+ } >+ >+ if (lines == null) >+ lines= new ArrayList(); >+ return lines; >+ } >+ >+ private static boolean exists(IStorage file) { >+ if (file instanceof IFile) { >+ return ((IFile) file).exists(); >+ } >+ return true; >+ } >+ >+ public static List readLines(BufferedReader reader) { >+ List lines; >+ LineReader lr= new LineReader(reader); >+ if (!Platform.WS_CARBON.equals(Platform.getWS())) //$NON-NLS-1$ >+ lr.ignoreSingleCR(); // Don't treat single CRs as line feeds to be consistent with command line patch >+ lines= lr.readLines(); >+ return lines; >+ } >+ >+ /* >+ * Concatenates all strings found in the given List. >+ */ >+ public static String createString(boolean preserveLineDelimeters, List lines) { >+ StringBuffer sb= new StringBuffer(); >+ Iterator iter= lines.iterator(); >+ if (preserveLineDelimeters) { >+ while (iter.hasNext()) >+ sb.append((String)iter.next()); >+ } else { >+ String lineSeparator= System.getProperty("line.separator"); //$NON-NLS-1$ >+ while (iter.hasNext()) { >+ String line= (String)iter.next(); >+ int l= length(line); >+ if (l < line.length()) { // line has delimiter >+ sb.append(line.substring(0, l)); >+ sb.append(lineSeparator); >+ } else { >+ sb.append(line); >+ } >+ } >+ } >+ return sb.toString(); >+ } >+ >+ /* >+ * Returns the length (excluding a line delimiter CR, LF, CR/LF) >+ * of the given string. >+ */ >+ /* package */ static int length(String s) { >+ int l= s.length(); >+ if (l > 0) { >+ char c= s.charAt(l-1); >+ if (c == '\r') >+ return l-1; >+ if (c == '\n') { >+ if (l > 1 && s.charAt(l-2) == '\r') >+ return l-2; >+ return l-1; >+ } >+ } >+ return l; >+ } >+ >+ private boolean fHaveChar= false; >+ private int fLastChar; >+ private boolean fSawEOF= false; >+ private BufferedReader fReader; >+ private boolean fIgnoreSingleCR= false; >+ private StringBuffer fBuffer= new StringBuffer(); >+ >+ public LineReader(BufferedReader reader) { >+ fReader= reader; >+ Assert.isNotNull(reader); >+ } >+ >+ public void ignoreSingleCR() { >+ fIgnoreSingleCR= true; >+ } >+ >+ /** >+ * Reads a line of text. A line is considered to be terminated by any one >+ * of a line feed ('\n'), a carriage return ('\r'), or a carriage return >+ * followed immediately by a line-feed. >+ * @return A string containing the contents of the line including >+ * the line-termination characters, or <code>null</code> if the end of the >+ * stream has been reached >+ * @exception IOException If an I/O error occurs >+ */ >+ /* package */ String readLine() throws IOException { >+ try { >+ while (!fSawEOF) { >+ int c= readChar(); >+ if (c == -1) { >+ fSawEOF= true; >+ break; >+ } >+ fBuffer.append((char)c); >+ if (c == '\n') >+ break; >+ if (c == '\r') { >+ c= readChar(); >+ if (c == -1) { >+ fSawEOF= true; >+ break; // EOF >+ } >+ if (c != '\n') { >+ if (fIgnoreSingleCR) { >+ fBuffer.append((char)c); >+ continue; >+ } >+ fHaveChar= true; >+ fLastChar= c; >+ } else >+ fBuffer.append((char)c); >+ break; >+ } >+ } >+ >+ if (fBuffer.length() != 0) { >+ return fBuffer.toString(); >+ } >+ return null; >+ } finally { >+ fBuffer.setLength(0); >+ } >+ } >+ >+ /* package */ void close() { >+ try { >+ fReader.close(); >+ } catch (IOException ex) { >+ // silently ignored >+ } >+ } >+ >+ public List readLines() { >+ try { >+ List lines= new ArrayList(); >+ String line; >+ while ((line= readLine()) != null) >+ lines.add(line); >+ return lines; >+ } catch (IOException ex) { >+ // NeedWork >+ //System.out.println("error while reading file: " + fileName + "(" + ex + ")"); >+ } finally { >+ close(); >+ } >+ return null; >+ } >+ >+ /* >+ * Returns the number of characters in the given string without >+ * counting a trailing line separator. >+ */ >+ /* package */ int lineContentLength(String line) { >+ if (line == null) >+ return 0; >+ int length= line.length(); >+ for (int i= length-1; i >= 0; i--) { >+ char c= line.charAt(i); >+ if (c =='\n' || c == '\r') >+ length--; >+ else >+ break; >+ } >+ return length; >+ } >+ >+ //---- private >+ >+ private int readChar() throws IOException { >+ if (fHaveChar) { >+ fHaveChar= false; >+ return fLastChar; >+ } >+ return fReader.read(); >+ } >+} >Index: compare/org/eclipse/compare/internal/patch/FileDiffWrapper.java >=================================================================== >RCS file: compare/org/eclipse/compare/internal/patch/FileDiffWrapper.java >diff -N compare/org/eclipse/compare/internal/patch/FileDiffWrapper.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ compare/org/eclipse/compare/internal/patch/FileDiffWrapper.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,91 @@ >+package org.eclipse.compare.internal.patch; >+ >+import java.io.BufferedReader; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.InputStreamReader; >+import java.io.Reader; >+import java.io.UnsupportedEncodingException; >+ >+import org.eclipse.compare.internal.core.Activator; >+import org.eclipse.compare.internal.core.patch.FileDiff; >+import org.eclipse.compare.patch.IFilePatch; >+import org.eclipse.compare.patch.IFilePatchResult; >+import org.eclipse.compare.patch.PatchConfiguration; >+import org.eclipse.compare.patch.ReaderFactory; >+import org.eclipse.core.resources.IEncodedStorage; >+import org.eclipse.core.resources.IStorage; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+ >+public class FileDiffWrapper implements IFilePatch { >+ >+ private FileDiff fileDiff; >+ >+ public FileDiffWrapper(FileDiff fileDiff) { >+ this.fileDiff = fileDiff; >+ } >+ >+ /** >+ * @param contents >+ * @param configuration >+ * @param monitor >+ * @see org.eclipse.compare.internal.core.patch.FileDiff#apply(org.eclipse.compare.patch.ReaderFactory, >+ * org.eclipse.compare.patch.PatchConfiguration, >+ * org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ public IFilePatchResult apply(IStorage contents, >+ PatchConfiguration configuration, IProgressMonitor monitor) { >+ return fileDiff.apply(getReaderFactory(contents), configuration, monitor); >+ } >+ >+ public static ReaderFactory getReaderFactory(final IStorage storage){ >+ if (storage == null) >+ return null; >+ >+ return new ReaderFactory(){ >+ public Reader createReader() throws CoreException{ >+ String charset = null; >+ if (storage instanceof IEncodedStorage) { >+ IEncodedStorage es = (IEncodedStorage) storage; >+ charset = es.getCharset(); >+ } >+ InputStreamReader in = null; >+ if (charset != null) { >+ InputStream contents = storage.getContents(); >+ try { >+ in = new InputStreamReader(contents, charset); >+ } catch (UnsupportedEncodingException e) { >+ Activator.log(e); >+ try { >+ contents.close(); >+ } catch (IOException e1) { >+ // Ignore >+ } >+ } >+ } >+ if (in == null) { >+ in = new InputStreamReader(storage.getContents()); >+ } >+ return new BufferedReader(in); >+ } >+ }; >+ } >+ >+ public long getAfterDate() { >+ return fileDiff.getAfterDate(); >+ } >+ >+ public long getBeforeDate() { >+ return fileDiff.getBeforeDate(); >+ } >+ >+ public String getHeader() { >+ return fileDiff.getHeader(); >+ } >+ >+ public IPath getTargetPath(PatchConfiguration configuration) { >+ return fileDiff.getTargetPath(configuration); >+ } >+} >Index: compare/org/eclipse/compare/patch/PatchParser.java >=================================================================== >RCS file: compare/org/eclipse/compare/patch/PatchParser.java >diff -N compare/org/eclipse/compare/patch/PatchParser.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ compare/org/eclipse/compare/patch/PatchParser.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,89 @@ >+/******************************************************************************* >+ * 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.patch; >+ >+import java.io.BufferedReader; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.InputStreamReader; >+import java.io.UnsupportedEncodingException; >+ >+import org.eclipse.compare.internal.core.Activator; >+import org.eclipse.compare.internal.core.patch.FileDiff; >+import org.eclipse.compare.internal.core.patch.PatchReader; >+import org.eclipse.compare.internal.patch.FileDiffWrapper; >+import org.eclipse.core.resources.IEncodedStorage; >+import org.eclipse.core.resources.IStorage; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+ >+/** >+ * Helper class for parsing patches. >+ * @since 3.5 >+ */ >+public class PatchParser { >+ >+ /** >+ * Parse the given patch and return the set of file patches that it contains. >+ * @param storage the storage that contains the patch >+ * @return the set of file patches that the storage contains >+ * @throws CoreException if an error occurs reading the contents from the storage >+ */ >+ public static IFilePatch[] parsePatch(IStorage storage) throws CoreException { >+ BufferedReader reader = createReader(storage); >+ try { >+ PatchReader patchReader= new PatchReader(); >+ patchReader.parse(reader); >+ FileDiff[] fileDiffs = patchReader.getAdjustedDiffs(); >+ >+ IFilePatch[] fP = new IFilePatch[fileDiffs.length]; >+ for (int i=0; i<fileDiffs.length; i++){ >+ fP[i] = new FileDiffWrapper(fileDiffs[i]); >+ } >+ >+ return fP; >+ } catch (IOException e) { >+ throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getMessage(), e)); >+ } finally { >+ try { >+ reader.close(); >+ } catch (IOException e) { //ignored >+ } >+ } >+ } >+ >+ private static BufferedReader createReader(IStorage storage) throws CoreException { >+ String charset = null; >+ if (storage instanceof IEncodedStorage) { >+ IEncodedStorage es = (IEncodedStorage) storage; >+ charset = es.getCharset(); >+ } >+ InputStreamReader in = null; >+ if (charset != null) { >+ InputStream contents = storage.getContents(); >+ try { >+ in = new InputStreamReader(contents, charset); >+ } catch (UnsupportedEncodingException e) { >+ Activator.log(e); >+ try { >+ contents.close(); >+ } catch (IOException e1) { >+ // Ignore >+ } >+ } >+ } >+ if (in == null) { >+ in = new InputStreamReader(storage.getContents()); >+ } >+ return new BufferedReader(in); >+ } >+} >Index: compare/org/eclipse/compare/internal/patch/Utilities.java >=================================================================== >RCS file: compare/org/eclipse/compare/internal/patch/Utilities.java >diff -N compare/org/eclipse/compare/internal/patch/Utilities.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ compare/org/eclipse/compare/internal/patch/Utilities.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,76 @@ >+/******************************************************************************* >+ * 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.internal.patch; >+ >+import java.io.BufferedReader; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.InputStreamReader; >+import java.io.Reader; >+import java.io.UnsupportedEncodingException; >+ >+import org.eclipse.compare.internal.core.Activator; >+import org.eclipse.compare.internal.core.patch.DiffProject; >+import org.eclipse.compare.patch.ReaderFactory; >+import org.eclipse.core.resources.IEncodedStorage; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IStorage; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+ >+public class Utilities { >+ >+ public static String getCharset(Object resource) { >+ if (resource instanceof IEncodedStorage) { >+ try { >+ return ((IEncodedStorage) resource).getCharset(); >+ } catch (CoreException ex) { >+ Activator.log(ex); >+ } >+ } >+ return ResourcesPlugin.getEncoding(); >+ } >+ >+ public static IProject getProject(DiffProject diffProject) { >+ return ResourcesPlugin.getWorkspace().getRoot().getProject( >+ diffProject.getName()); >+ } >+ >+ public static ReaderFactory getReaderFactory(final IStorage storage){ >+ return new ReaderFactory(){ >+ public Reader createReader() throws CoreException{ >+ String charset = null; >+ if (storage instanceof IEncodedStorage) { >+ IEncodedStorage es = (IEncodedStorage) storage; >+ charset = es.getCharset(); >+ } >+ InputStreamReader in = null; >+ if (charset != null) { >+ InputStream contents = storage.getContents(); >+ try { >+ in = new InputStreamReader(contents, charset); >+ } catch (UnsupportedEncodingException e) { >+ Activator.log(e); >+ try { >+ contents.close(); >+ } catch (IOException e1) { >+ // Ignore >+ } >+ } >+ } >+ if (in == null) { >+ in = new InputStreamReader(storage.getContents()); >+ } >+ return new BufferedReader(in); >+ } >+ }; >+ } >+}
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 Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 263943
:
125131
|
125132
|
125622
|
125766