Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-07-26 05:51:47 +0000
committerEike Stepper2012-07-26 05:51:47 +0000
commit1734aeaae08c9204fbbae064afc075aec07a8a6c (patch)
tree05262d3bf5988d6df7363939f51120c4e09b9177 /plugins
parente224e60cc286e109e06a375c550f9a94406d88e0 (diff)
downloadcdo-1734aeaae08c9204fbbae064afc075aec07a8a6c.tar.gz
cdo-1734aeaae08c9204fbbae064afc075aec07a8a6c.tar.xz
cdo-1734aeaae08c9204fbbae064afc075aec07a8a6c.zip
Fix encoding
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.ui/plugin.xml2
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/QuickFixer.java (renamed from plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/Quickfixer.java)105
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Markers.java17
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java81
4 files changed, 162 insertions, 43 deletions
diff --git a/plugins/org.eclipse.emf.cdo.releng.version.ui/plugin.xml b/plugins/org.eclipse.emf.cdo.releng.version.ui/plugin.xml
index dbd3bf1d93..7c3d49483a 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version.ui/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.releng.version.ui/plugin.xml
@@ -85,7 +85,7 @@
<extension
point="org.eclipse.ui.ide.markerResolution">
<markerResolutionGenerator
- class="org.eclipse.emf.cdo.releng.version.ui.Quickfixer"
+ class="org.eclipse.emf.cdo.releng.version.ui.QuickFixer"
markerType="org.eclipse.emf.cdo.releng.version.VersionProblem">
</markerResolutionGenerator>
</extension>
diff --git a/plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/Quickfixer.java b/plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/QuickFixer.java
index 0a24cdd715..184f2ae839 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/Quickfixer.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/QuickFixer.java
@@ -14,27 +14,75 @@ import org.eclipse.emf.cdo.releng.version.Markers;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IMarkerResolution;
-import org.eclipse.ui.IMarkerResolution2;
import org.eclipse.ui.IMarkerResolutionGenerator2;
+import org.eclipse.ui.views.markers.WorkbenchMarkerResolution;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.CharArrayWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Eike Stepper
*/
-public class Quickfixer /* extends WorkbenchMarkerResolution */implements IMarkerResolutionGenerator2
+public class QuickFixer implements IMarkerResolutionGenerator2
{
- private static final IMarkerResolution MARKER_RESOLUTION = new IMarkerResolution2()
+ private static final IMarkerResolution[] NO_MARKER_RESOLUTIONS = {};
+
+ public QuickFixer()
+ {
+ }
+
+ public IMarkerResolution[] getResolutions(IMarker marker)
+ {
+ if (hasResolutions(marker))
+ {
+ IMarkerResolution[] markers = { new VersionMarkerResolution(marker) };
+ return markers;
+ }
+
+ return NO_MARKER_RESOLUTIONS;
+ }
+
+ public boolean hasResolutions(IMarker marker)
{
+ return Markers.hasQuickFixes(marker);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class VersionMarkerResolution extends WorkbenchMarkerResolution
+ {
+ private IMarker marker;
+
+ public VersionMarkerResolution(IMarker marker)
+ {
+ this.marker = marker;
+ }
+
+ public String getLabel()
+ {
+ return "Foo";
+ }
+
+ public String getDescription()
+ {
+ return "Foo Foo Foo";
+ }
+
+ public Image getImage()
+ {
+ return null;
+ }
+
public void run(IMarker marker)
{
try
@@ -45,8 +93,7 @@ public class Quickfixer /* extends WorkbenchMarkerResolution */implements IMarke
{
IFile file = (IFile)marker.getResource();
InputStream contents = file.getContents();
- String charset = file.getCharset();
- BufferedReader reader = new BufferedReader(new InputStreamReader(contents, charset));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(contents, file.getCharset()));
CharArrayWriter caw = new CharArrayWriter();
int c;
@@ -74,7 +121,7 @@ public class Quickfixer /* extends WorkbenchMarkerResolution */implements IMarke
replacement = "";
}
- file.setContents(new ByteArrayInputStream((before + replacement + after).getBytes(charset)), true, true,
+ file.setContents(new ByteArrayInputStream((before + replacement + after).getBytes(file.getCharset())), true, true,
null);
}
}
@@ -85,41 +132,19 @@ public class Quickfixer /* extends WorkbenchMarkerResolution */implements IMarke
}
}
- public String getLabel()
- {
- return "Foo";
- }
-
- public Image getImage()
- {
- return null;
- }
-
- public String getDescription()
+ @Override
+ public IMarker[] findOtherMarkers(IMarker[] markers)
{
- return "Foo Foo Foo";
- }
- };
-
- private static final IMarkerResolution[] MARKER_RESOLUTIONS = new IMarkerResolution[] { MARKER_RESOLUTION };
-
- private static final IMarkerResolution[] NO_MARKER_RESOLUTIONS = new IMarkerResolution[0];
-
- public IMarkerResolution[] getResolutions(IMarker marker)
- {
- return hasResolutions(marker) ? MARKER_RESOLUTIONS : NO_MARKER_RESOLUTIONS;
- }
+ List<IMarker> result = new ArrayList<IMarker>();
+ for (IMarker marker : markers)
+ {
+ if (marker != this.marker && Markers.hasQuickFixes(marker))
+ {
+ result.add(marker);
+ }
+ }
- public boolean hasResolutions(IMarker marker)
- {
- try
- {
- return marker.getAttribute(Markers.QUICK_FIX_PATTERN) != null;
- }
- catch (CoreException ex)
- {
- Activator.log(ex);
- return false;
+ return result.toArray(new IMarker[result.size()]);
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Markers.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Markers.java
index 0e76c650df..dadc1d4f3b 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Markers.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Markers.java
@@ -32,7 +32,7 @@ public final class Markers
public static final String QUICK_FIX_PATTERN = "quickFixPattern";
- public static final String QUICK_FIX_REPLACEMENT = "quickReplacement";
+ public static final String QUICK_FIX_REPLACEMENT = "quickReplacement";
private static final Pattern NL_PATTERN = Pattern.compile("([\\n][\\r]?|[\\r][\\n]?)", Pattern.MULTILINE);
@@ -40,6 +40,19 @@ public final class Markers
{
}
+ public static boolean hasQuickFixes(IMarker marker)
+ {
+ try
+ {
+ return marker.getAttribute(QUICK_FIX_PATTERN) != null;
+ }
+ catch (CoreException ex)
+ {
+ Activator.log(ex);
+ return false;
+ }
+ }
+
public static IMarker addMarker(IResource resource, String message) throws CoreException
{
return addMarker(resource, message, IMarker.SEVERITY_ERROR);
@@ -93,7 +106,7 @@ public final class Markers
try
{
contents = file.getContents();
- BufferedReader reader = new BufferedReader(new InputStreamReader(contents));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(contents, file.getCharset()));
CharArrayWriter caw = new CharArrayWriter();
int c;
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
index 05987c36bc..e3c136122f 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
@@ -26,9 +26,11 @@ import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.InvalidObjectException;
import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.internal.cdo.session.CDOSessionImpl;
import org.eclipse.emf.internal.cdo.view.CDOViewImpl;
import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.ReflectUtil;
import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;
@@ -40,6 +42,10 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.spi.cdo.FSMUtil;
import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -48,6 +54,81 @@ import java.util.concurrent.TimeUnit;
*/
public class InvalidationTest extends AbstractCDOTest
{
+ public void testIvalidationMemoryLeak() throws Exception
+ {
+ final CDOSession session = openSession();
+
+ /**
+ * @author Eike Stepper
+ */
+ class MyTransTest implements Runnable
+ {
+ private int nr;
+
+ public MyTransTest(int nr)
+ {
+ this.nr = nr;
+ }
+
+ public void run()
+ {
+ for (int i = 0; i < 10; i++)
+ {
+ Category category = getModel1Factory().createCategory();
+ category.setName("Category " + System.currentTimeMillis());
+
+ CDOTransaction transaction = session.openTransaction();
+
+ try
+ {
+ CDOResource resource = transaction.getOrCreateResource(getResourcePath("/test1_" + nr));
+ resource.getContents().add(category);
+ transaction.commit();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ finally
+ {
+ transaction.close();
+ }
+ }
+ }
+ }
+
+ List<Thread> threads = new ArrayList<Thread>();
+ for (int i = 0; i < 20; i++)
+ {
+ threads.add(new Thread(new MyTransTest(i + 1)));
+ }
+
+ for (Thread thread : threads)
+ {
+ thread.start();
+ }
+
+ for (Thread thread : threads)
+ {
+ thread.join();
+ }
+
+ // session.refresh();
+ // sleep(2000);
+
+ new MyTransTest(0).run();
+
+ sleep(60000);
+
+ // session.refresh();
+
+ Field field = ReflectUtil.getField(CDOSessionImpl.class, "outOfSequenceInvalidations");
+ Map<?, ?> outOfSequenceInvalidations = (Map<?, ?>)ReflectUtil.getValue(field, session);
+
+ int size = outOfSequenceInvalidations.size();
+ assertEquals(0, size);
+ }
+
public void testSeparateView() throws Exception
{
final CDOSession session = openSession();

Back to the top