Lines 25-30
Link Here
|
25 |
import org.eclipse.compare.patch.ApplyPatchOperation; |
25 |
import org.eclipse.compare.patch.ApplyPatchOperation; |
26 |
import org.eclipse.compare.patch.IFilePatch; |
26 |
import org.eclipse.compare.patch.IFilePatch; |
27 |
import org.eclipse.compare.patch.IFilePatchResult; |
27 |
import org.eclipse.compare.patch.IFilePatchResult; |
|
|
28 |
import org.eclipse.compare.patch.IHunk; |
28 |
import org.eclipse.compare.patch.PatchConfiguration; |
29 |
import org.eclipse.compare.patch.PatchConfiguration; |
29 |
import org.eclipse.compare.patch.WorkspacePatcherUI; |
30 |
import org.eclipse.compare.patch.WorkspacePatcherUI; |
30 |
import org.eclipse.core.resources.IFile; |
31 |
import org.eclipse.core.resources.IFile; |
Lines 187-192
Link Here
|
187 |
} |
188 |
} |
188 |
|
189 |
|
189 |
} |
190 |
} |
|
|
191 |
|
192 |
/** |
193 |
* Tests applying a patch which creates a new file in a project. The file |
194 |
* already exists in the project, but has different contents. |
195 |
* |
196 |
* @throws CoreException |
197 |
*/ |
198 |
public void testEncoding() |
199 |
throws CoreException { |
200 |
IProject project = createProject("FileDiffResultTest", |
201 |
new String[] { NEW_FILENAME }); |
202 |
|
203 |
IFile newFile = project |
204 |
.getFile(NEW_FILENAME); |
205 |
newFile.setContents( |
206 |
new ByteArrayInputStream("I'm a different content".getBytes()), |
207 |
IResource.NONE, null); |
208 |
String charset = "ISO-8859-1"; |
209 |
newFile.setCharset(charset, null); |
210 |
|
211 |
try { |
212 |
// create the patch file |
213 |
IFile file = project.getFile(PATCH_FILE); |
214 |
file.create(new ByteArrayInputStream(createPatchAddingFile(project, |
215 |
NEW_FILENAME, false).getBytes()), true, null); |
216 |
|
217 |
assertTrue(newFile.exists()); |
218 |
|
219 |
file.setCharset(charset, null); |
220 |
|
221 |
IFilePatch[] filePatch = ApplyPatchOperation.parsePatch(file); |
222 |
assertNotNull(filePatch); |
223 |
assertEquals(1, filePatch.length); |
224 |
|
225 |
IFilePatchResult filePatchResult = filePatch[0].apply(newFile, patchConfiguration, |
226 |
nullProgressMonitor); |
227 |
assertFalse(filePatchResult.hasMatches()); |
228 |
assertEquals(1, filePatchResult.getRejects().length); |
229 |
assertEquals(charset, filePatchResult.getCharset()); |
230 |
IHunk[] hunks = filePatch[0].getHunks(); |
231 |
for (int i = 0; i < hunks.length; i++) { |
232 |
IHunk hunk = hunks[i]; |
233 |
assertEquals(charset, hunk.getCharset()); |
234 |
} |
235 |
|
236 |
assertNotNull(filePatchResult.getOriginalContents()); |
237 |
assertNotNull(filePatchResult.getPatchedContents()); |
238 |
|
239 |
assertEquals(new FileInputStream(newFile |
240 |
.getLocation().toFile()), filePatchResult |
241 |
.getOriginalContents()); |
242 |
assertEquals("I'm a different content", |
243 |
getStringFromStream(filePatchResult.getOriginalContents())); |
244 |
assertEquals(filePatchResult.getOriginalContents(), filePatchResult |
245 |
.getPatchedContents()); |
246 |
|
247 |
} catch (IOException e) { |
248 |
fail(); |
249 |
} |
250 |
|
251 |
} |
190 |
|
252 |
|
191 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185379 |
253 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185379 |
192 |
public void testFileDiffResultWithNullPath() { |
254 |
public void testFileDiffResultWithNullPath() { |