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 205407 Details for
Bug 347557
[Edit] NPE when saving a file in a compare editor (always)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
org.eclipse.team.ui fix with tests v07
patch_347557_6.txt (text/plain), 13.51 KB, created by
Malgorzata Janczarska
on 2011-10-18 06:05:23 EDT
(
hide
)
Description:
org.eclipse.team.ui fix with tests v07
Filename:
MIME Type:
Creator:
Malgorzata Janczarska
Created:
2011-10-18 06:05:23 EDT
Size:
13.51 KB
patch
obsolete
>diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java >index 0008fa9..fb839b4 100644 >--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java >+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java >@@ -248,10 +248,10 @@ public abstract class LocalResourceSaveableComparison extends SaveableComparison > */ > public String getName() { > // Return the name of the file element as held in the compare input >- if (fileElement.equals(input.getLeft())) { >+ if (input.getLeft().equals(fileElement)) { > return input.getLeft().getName(); > } >- if (fileElement.equals(input.getRight())) { >+ if (input.getRight().equals(fileElement)) { > return input.getRight().getName(); > } > // Fallback call returning name of the main non-null element of the input >@@ -289,14 +289,14 @@ public abstract class LocalResourceSaveableComparison extends SaveableComparison > > ContentMergeViewer cmv = (ContentMergeViewer) e.getSource(); > >- if (fileElement.equals(input.getLeft())) { >+ if (input.getLeft().equals(fileElement)) { > if (changed && cmv.internalIsLeftDirty()) > setDirty(changed); > else if (!changed && !cmv.internalIsLeftDirty()) { > setDirty(changed); > } > } >- if (fileElement.equals(input.getRight())) { >+ if (input.getRight().equals(fileElement)) { > if (changed && cmv.internalIsRightDirty()) > setDirty(changed); > else if (!changed && !cmv.internalIsRightDirty()) { >diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ReflectionUtils.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ReflectionUtils.java >index 538738a..d3d23f1 100644 >--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ReflectionUtils.java >+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ReflectionUtils.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2009 IBM Corporation and others. >+ * Copyright (c) 2009, 2011 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 >@@ -53,4 +53,27 @@ public class ReflectionUtils { > return ret; > } > >+ public static Object getField(Object object, String name, boolean deep) >+ throws IllegalArgumentException, IllegalAccessException, >+ SecurityException, NoSuchFieldException { >+ Class clazz = object.getClass(); >+ NoSuchFieldException ex = null; >+ while (clazz != null) { >+ try { >+ Field field = clazz.getDeclaredField(name); >+ field.setAccessible(true); >+ return field.get(object); >+ } catch (NoSuchFieldException e) { >+ if (ex == null) { >+ ex = e; >+ } >+ if (!deep) >+ break; >+ clazz = clazz.getSuperclass(); >+ >+ } >+ } >+ throw ex; >+ } >+ > } >\ No newline at end of file >diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamUITests.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamUITests.java >index 198465f..b8dc987 100644 >--- a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamUITests.java >+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamUITests.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007 IBM Corporation and others. >+ * Copyright (c) 2007, 2011 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 junit.framework.TestSuite; > > import org.eclipse.core.tests.resources.ResourceTest; > import org.eclipse.team.tests.core.mapping.ScopeTests; >+import org.eclipse.team.tests.ui.SaveableCompareEditorInputTest; > > public class AllTeamUITests extends ResourceTest { > >@@ -29,6 +30,7 @@ public class AllTeamUITests extends ResourceTest { > public static Test suite() { > TestSuite suite = new TestSuite(); > suite.addTest(ScopeTests.suite()); >+ suite.addTest(SaveableCompareEditorInputTest.suite()); > return suite; > } > } >diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/SaveableCompareEditorInputTest.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/SaveableCompareEditorInputTest.java >new file mode 100644 >index 0000000..f8d1add >--- /dev/null >+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/SaveableCompareEditorInputTest.java >@@ -0,0 +1,275 @@ >+/******************************************************************************* >+ * Copyright (c) 2011 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.team.tests.ui; >+ >+import java.io.ByteArrayInputStream; >+import java.io.IOException; >+import java.lang.reflect.InvocationTargetException; >+import java.util.ArrayList; >+import java.util.List; >+ >+import junit.framework.Test; >+ >+import org.eclipse.compare.CompareConfiguration; >+import org.eclipse.compare.ITypedElement; >+import org.eclipse.compare.contentmergeviewer.TextMergeViewer; >+import org.eclipse.compare.internal.MergeSourceViewer; >+import org.eclipse.compare.structuremergeviewer.Differencer; >+import org.eclipse.compare.structuremergeviewer.ICompareInput; >+import org.eclipse.compare.tests.ReflectionUtils; >+import org.eclipse.core.internal.runtime.RuntimeLog; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.ILogListener; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.swt.custom.StyledText; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.team.internal.ui.mapping.AbstractCompareInput; >+import org.eclipse.team.internal.ui.mapping.CompareInputChangeNotifier; >+import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement; >+import org.eclipse.team.tests.core.TeamTest; >+import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput; >+import org.eclipse.ui.PlatformUI; >+ >+public class SaveableCompareEditorInputTest extends TeamTest { >+ >+ public static Test suite() { >+ return suite(SaveableCompareEditorInputTest.class); >+ } >+ >+ private IFile file1; >+ private IFile file2; >+ private String appendFileContents = "_append"; >+ private String fileContents1 = "FileContents"; >+ private String fileContents2 = "FileContents2"; >+ private TestLogListener logListener = new TestLogListener(); >+ >+ protected void setUp() throws Exception { >+ super.setUp(); >+ >+ IProject project = createProject("Project_", new String[] { >+ "File1.txt", "File2.txt" }); >+ >+ file1 = project.getFile("File1.txt"); >+ file2 = project.getFile("File2.txt"); >+ file1.setContents(new ByteArrayInputStream(fileContents1.getBytes()), >+ true, true, null); >+ file2.setContents(new ByteArrayInputStream(fileContents2.getBytes()), >+ true, true, null); >+ >+ RuntimeLog.addLogListener(logListener); >+ } >+ >+ protected void tearDown() throws Exception { >+ // remove log listener >+ RuntimeLog.removeLogListener(logListener); >+ super.tearDown(); >+ } >+ >+ private class TestFileElement implements ITypedElement { >+ >+ private IFile file; >+ >+ public IFile getFile() { >+ return file; >+ } >+ >+ public TestFileElement(IFile file) { >+ super(); >+ this.file = file; >+ } >+ >+ public String getName() { >+ return file.getName(); >+ } >+ >+ public Image getImage() { >+ return null; >+ } >+ >+ public String getType() { >+ return TEXT_TYPE; >+ } >+ } >+ >+ private class TestLogListener implements ILogListener { >+ public void logging(IStatus status, String plugin) { >+ fail(status.getMessage()); >+ } >+ } >+ >+ private class TestDiffNode extends AbstractCompareInput { >+ >+ private CompareInputChangeNotifier notifier = new CompareInputChangeNotifier() { >+ >+ private IResource getResource(ITypedElement el) { >+ if (el instanceof LocalResourceTypedElement) { >+ return ((LocalResourceTypedElement) el).getResource(); >+ } >+ if (el instanceof TestFileElement) { >+ return ((TestFileElement) el).getFile(); >+ } >+ return null; >+ } >+ >+ protected IResource[] getResources(ICompareInput input) { >+ >+ List resources = new ArrayList(); >+ if (getResource(getLeft()) != null) { >+ resources.add(getResource(getLeft())); >+ } >+ if (getResource(getRight()) != null) { >+ resources.add(getResource(getRight())); >+ } >+ return (IResource[]) resources.toArray(new IResource[2]); >+ } >+ }; >+ >+ public TestDiffNode(ITypedElement left, ITypedElement right) { >+ super(Differencer.CHANGE, null, left, right); >+ } >+ >+ public void fireChange() { >+ super.fireChange(); >+ } >+ >+ protected CompareInputChangeNotifier getChangeNotifier() { >+ return notifier; >+ } >+ >+ public boolean needsUpdate() { >+ // The remote never changes >+ return false; >+ } >+ >+ public void update() { >+ fireChange(); >+ } >+ } >+ >+ private class TestSaveableEditorInput extends SaveableCompareEditorInput { >+ >+ protected ITypedElement left; >+ protected ITypedElement right; >+ private ICompareInput input; >+ >+ public Object getCompareResult() { >+ return input; >+ } >+ >+ public TestSaveableEditorInput(ITypedElement left, ITypedElement right, >+ CompareConfiguration conf) { >+ super(conf, PlatformUI.getWorkbench().getActiveWorkbenchWindow() >+ .getActivePage()); >+ this.left = left; >+ this.right = right; >+ } >+ >+ protected ICompareInput prepareCompareInput(IProgressMonitor monitor) >+ throws InvocationTargetException, InterruptedException { >+ input = createCompareInput(); >+ getCompareConfiguration().setLeftEditable(true); >+ getCompareConfiguration().setRightEditable(false); >+ return null; >+ } >+ >+ private ICompareInput createCompareInput() { >+ return new TestDiffNode(left, right); >+ } >+ >+ protected void fireInputChange() { >+ ((TestDiffNode) getCompareResult()).fireChange(); >+ } >+ } >+ >+ private void verifyDirtyStateChanges( >+ TestSaveableEditorInput compareEditorInput) >+ throws IllegalArgumentException, SecurityException, >+ IllegalAccessException, NoSuchFieldException { >+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() >+ .getShell(); >+ >+ TextMergeViewer viewer = (TextMergeViewer) compareEditorInput >+ .findContentViewer(null, compareEditorInput.input, shell); >+ viewer.setInput(compareEditorInput.getCompareResult()); >+ >+ MergeSourceViewer left = (MergeSourceViewer) ReflectionUtils.getField( >+ viewer, "fLeft"); >+ >+ StyledText leftText = left.getSourceViewer().getTextWidget(); >+ >+ // modify the left side of editor >+ leftText.append(appendFileContents); >+ >+ assertTrue(compareEditorInput.isDirty()); >+ >+ // save editor >+ viewer.flush(null); >+ >+ assertFalse(compareEditorInput.isDirty()); >+ } >+ >+ public void testDirtyFlagOnLocalResourceTypedElement() >+ throws CoreException, InvocationTargetException, >+ InterruptedException, IllegalArgumentException, SecurityException, >+ IllegalAccessException, NoSuchFieldException, >+ NoSuchMethodException, IOException { >+ >+ // Create left element by SaveableCompareEditorInput to be properly >+ // saved, see javadoc to SaveableCompareEditorInput >+ LocalResourceTypedElement el1 = (LocalResourceTypedElement) SaveableCompareEditorInput >+ .createFileElement(file1); >+ ITypedElement el2 = new TestFileElement(file2); >+ >+ CompareConfiguration conf = new CompareConfiguration(); >+ conf.setLeftEditable(true); >+ TestSaveableEditorInput compareEditorInput = new TestSaveableEditorInput( >+ el1, el2, conf); >+ >+ compareEditorInput.prepareCompareInput(null); >+ >+ verifyDirtyStateChanges(compareEditorInput); >+ >+ // check whether file was saved >+ >+ assertTrue(compareContent(new ByteArrayInputStream( >+ (fileContents1 + appendFileContents).getBytes()), >+ file1.getContents())); >+ } >+ >+ public void testDirtyFlagOnCustomTypedElement() throws CoreException, >+ InvocationTargetException, InterruptedException, >+ IllegalArgumentException, SecurityException, >+ IllegalAccessException, NoSuchFieldException, >+ NoSuchMethodException, IOException { >+ >+ ITypedElement el1 = new TestFileElement(file1); >+ ITypedElement el2 = new TestFileElement(file2); >+ >+ CompareConfiguration conf = new CompareConfiguration(); >+ conf.setLeftEditable(true); >+ TestSaveableEditorInput compareEditorInput = new TestSaveableEditorInput( >+ el1, el2, conf); >+ >+ compareEditorInput.prepareCompareInput(null); >+ >+ verifyDirtyStateChanges(compareEditorInput); >+ >+ /* >+ * not checking if changes were saved because in this case saving is not >+ * handled, see javadoc to SaveableCompareEditorInput. >+ */ >+ } >+}
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 347557
:
201902
|
201906
|
204202
|
204452
|
204457
|
204502
|
204754
|
204957
|
205359
|
205361
| 205407 |
205708