Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-08-25 05:57:24 +0000
committerEike Stepper2012-08-25 05:57:24 +0000
commit5850f0be086f21ba6a18fcbcc9dc283e0938dd80 (patch)
treeffd6e274ec21181949711b480be06e0dfbd63de1 /plugins
parentfe241340b4bae9e73bcd9029866acaed41e7519b (diff)
downloadcdo-5850f0be086f21ba6a18fcbcc9dc283e0938dd80.tar.gz
cdo-5850f0be086f21ba6a18fcbcc9dc283e0938dd80.tar.xz
cdo-5850f0be086f21ba6a18fcbcc9dc283e0938dd80.zip
Fix position handling
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.tests/src/org/eclipse/emf/cdo/releng/version/tests/VersionBuilderTest.java80
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/build.markers9
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/fix1.markers18
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/Release.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilder.java18
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Markers.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionUtil.java74
7 files changed, 174 insertions, 30 deletions
diff --git a/plugins/org.eclipse.emf.cdo.releng.version.tests/src/org/eclipse/emf/cdo/releng/version/tests/VersionBuilderTest.java b/plugins/org.eclipse.emf.cdo.releng.version.tests/src/org/eclipse/emf/cdo/releng/version/tests/VersionBuilderTest.java
index d1022125b3..bf032201df 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version.tests/src/org/eclipse/emf/cdo/releng/version/tests/VersionBuilderTest.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version.tests/src/org/eclipse/emf/cdo/releng/version/tests/VersionBuilderTest.java
@@ -14,6 +14,7 @@ import org.eclipse.emf.cdo.releng.version.Markers;
import org.eclipse.emf.cdo.releng.version.VersionUtil;
import org.eclipse.emf.cdo.releng.version.ui.quickfixes.VersionResolutionGenerator;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -285,7 +286,7 @@ public class VersionBuilderTest extends TestCase
resultsFile.setContents(contents);
}
- private static String createMarkers(IMarker[] markers) throws CoreException
+ private static String createMarkers(IMarker[] markers) throws Throwable
{
if (markers.length == 0)
{
@@ -315,17 +316,90 @@ public class VersionBuilderTest extends TestCase
}
});
+ IFile lastContentsFile = null;
+ String contents = null;
+
StringBuilder builder = new StringBuilder();
for (IMarker marker : markers)
{
msg("Marker");
builder.append("Marker\n");
- addAttribute(builder, Markers.RESOURCE_ATTRIBUTE, marker.getResource().getFullPath());
+
+ IFile file = (IFile)marker.getResource();
+ addAttribute(builder, Markers.RESOURCE_ATTRIBUTE, file.getFullPath());
Map<String, Object> attributes = marker.getAttributes();
List<String> keys = new ArrayList<String>(attributes.keySet());
- Collections.sort(keys);
+ keys.remove(IMarker.LINE_NUMBER);
+
+ if (keys.remove(IMarker.CHAR_START))
+ {
+ int indexStart = (Integer)attributes.get(IMarker.CHAR_START);
+ int indexEnd = -1;
+ if (keys.remove(IMarker.CHAR_END))
+ {
+ indexEnd = (Integer)attributes.get(IMarker.CHAR_END);
+ }
+
+ if (file != lastContentsFile)
+ {
+ contents = VersionUtil.getContents(file);
+ lastContentsFile = file;
+ }
+ int size = contents.length();
+ for (int i = 0, lf = 1, cr = 1, column = 0; i < size; ++i, ++column)
+ {
+ char c = contents.charAt(i);
+ if (c == '\n')
+ {
+ ++lf;
+ column = 1;
+ }
+ else if (c == '\r')
+ {
+ ++cr;
+ column = 1;
+ }
+
+ if (i == indexStart || i == indexEnd)
+ {
+ String value = "(" + Math.max(cr, lf) + "," + column + ")";
+
+ if (i == indexStart)
+ {
+ addAttribute(builder, "<" + IMarker.CHAR_START + ">", value);
+ if (indexEnd == -1)
+ {
+ break;
+ }
+ }
+ else
+ {
+ addAttribute(builder, "<" + IMarker.CHAR_END + ">", value);
+ break;
+ }
+ }
+ }
+
+ }
+
+ if (keys.remove(IMarker.SEVERITY))
+ {
+ addAttribute(builder, "<" + IMarker.SEVERITY + ">", attributes.get(IMarker.SEVERITY));
+ }
+
+ if (keys.remove(IMarker.MESSAGE))
+ {
+ addAttribute(builder, "<" + IMarker.MESSAGE + ">", attributes.get(IMarker.MESSAGE));
+ }
+
+ if (keys.remove(Markers.PROBLEM_TYPE))
+ {
+ addAttribute(builder, Markers.PROBLEM_TYPE, attributes.get(Markers.PROBLEM_TYPE));
+ }
+
+ Collections.sort(keys);
for (String key : keys)
{
Object value = attributes.get(key);
diff --git a/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/build.markers b/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/build.markers
index f7be5a0cd0..e01bee70b2 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/build.markers
+++ b/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/build.markers
@@ -1,10 +1,9 @@
Marker
<resource> = /com.foo.project1/META-INF/MANIFEST.MF
- charEnd = 107
- charStart = 102
- lineNumber = 3
- message = Version must be increased to 1.0.100 because the project's contents have changed
+ <charStart> = (4,18)
+ <charEnd> = (4,23)
+ <severity> = 2
+ <message> = Version must be increased to 1.0.100 because the project's contents have changed
problemType = component.version
quickFixPattern = Bundle-Version: *(\d+(\.\d+(\.\d+)?)?)
quickFixReplacement = 1.0.100
- severity = 2
diff --git a/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/fix1.markers b/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/fix1.markers
index 9a006e0f02..2c9c6ff8c4 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/fix1.markers
+++ b/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/fix1.markers
@@ -1,20 +1,18 @@
Marker
<resource> = /com.foo.project1-feature/feature.xml
- charEnd = 681
- charStart = 665
- lineNumber = 27
- message = Plug-in reference 'com.foo.project1' has been changed from 1.0.0 to 1.0.100
+ <charStart> = (28,15)
+ <charEnd> = (28,31)
+ <severity> = 1
+ <message> = Plug-in reference 'com.foo.project1' has been changed from 1.0.0 to 1.0.100
problemType = component.version
quickFixConfigureOption = ignore.feature.content.changes
- severity = 1
Marker
<resource> = /com.foo.project1-feature/feature.xml
- charEnd = 124
- charStart = 119
- lineNumber = 4
- message = Version must be increased to 1.0.100 because the feature's references have changed
+ <charStart> = (5,17)
+ <charEnd> = (5,22)
+ <severity> = 2
+ <message> = Version must be increased to 1.0.100 because the feature's references have changed
problemType = component.version
quickFixConfigureOption = ignore.feature.content.changes
quickFixPattern = feature.*?version\s*=\s*["'](\d+(\.\d+(\.\d+)?)?)
quickFixReplacement = 1.0.100
- severity = 2
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/Release.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/Release.java
index 6c31017fc3..b54eaae725 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/Release.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/Release.java
@@ -124,6 +124,7 @@ public class Release implements IRelease
writeRelease(builder);
String xml = builder.toString();
+ xml = xml.replace("\n", VersionUtil.getLineDelimiter(file));
ByteArrayInputStream contents = new ByteArrayInputStream(xml.getBytes("UTF-8"));
if (file.exists())
{
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilder.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilder.java
index 4217038170..5b1cb5eb42 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilder.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilder.java
@@ -86,8 +86,6 @@ public class VersionBuilder extends IncrementalProjectBuilder implements IElemen
private static final Pattern DEBUG_OPTION_PATTERN = Pattern.compile("^( *)([^/ \\n\\r]+)/([^ =]+)( *=.*)$",
Pattern.MULTILINE);
- private static final String NL = System.getProperty("line.separator");
-
private static IResourceChangeListener postBuildListener;
private static final Set<String> releasePaths = new HashSet<String>();
@@ -684,8 +682,9 @@ public class VersionBuilder extends IncrementalProjectBuilder implements IElemen
integration = true;
rootProjects = new HashSet<String>();
- String contents = INTEGRATION_PROPERTY_KEY + " = " + integration + NL + DEVIATIONS_PROPERTY_KEY + " = "
- + deviations + NL + ROOT_PROJECTS_KEY + " = ";
+ String lineDelimiter = VersionUtil.getLineDelimiter(propertiesFile);
+ String contents = INTEGRATION_PROPERTY_KEY + " = " + integration + lineDelimiter + DEVIATIONS_PROPERTY_KEY + " = "
+ + deviations + lineDelimiter + ROOT_PROJECTS_KEY + " = ";
String charsetName = propertiesFile.getCharset();
byte[] bytes = contents.getBytes(charsetName);
@@ -934,7 +933,7 @@ public class VersionBuilder extends IncrementalProjectBuilder implements IElemen
{
try
{
- String content = VersionUtil.getContent(file);
+ String content = VersionUtil.getContents(file);
Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
Matcher matcher = pattern.matcher(content);
if (matcher.find())
@@ -1118,9 +1117,10 @@ public class VersionBuilder extends IncrementalProjectBuilder implements IElemen
IMarker marker = Markers.addMarker(file, msg, IMarker.SEVERITY_WARNING, regex);
marker.setAttribute(Markers.PROBLEM_TYPE, Markers.SCHEMA_BUILDER_PROBLEM);
marker.setAttribute(Markers.QUICK_FIX_PATTERN, regex);
- marker.setAttribute(Markers.QUICK_FIX_REPLACEMENT, NL + "\t\t<buildCommand>" + NL
- + "\t\t\t<name>org.eclipse.pde.SchemaBuilder</name>" + NL + "\t\t\t<arguments>" + NL + "\t\t\t</arguments>"
- + NL + "\t\t</buildCommand>" + NL + "\t\t");
+ String lineDelimiter = VersionUtil.getLineDelimiter(file);
+ marker.setAttribute(Markers.QUICK_FIX_REPLACEMENT, lineDelimiter + "\t\t<buildCommand>" + lineDelimiter
+ + "\t\t\t<name>org.eclipse.pde.SchemaBuilder</name>" + lineDelimiter + "\t\t\t<arguments>" + lineDelimiter
+ + "\t\t\t</arguments>" + lineDelimiter + "\t\t</buildCommand>" + lineDelimiter + "\t\t");
marker
.setAttribute(Markers.QUICK_FIX_CONFIGURE_OPTION, IVersionBuilderArguments.IGNORE_SCHEMA_BUILDER_ARGUMENT);
return;
@@ -1153,7 +1153,7 @@ public class VersionBuilder extends IncrementalProjectBuilder implements IElemen
Markers.deleteAllMarkers(file, Markers.DEBUG_OPTION_PROBLEM);
String symbolicName = pluginModel.getBundleDescription().getSymbolicName();
- String content = VersionUtil.getContent(file);
+ String content = VersionUtil.getContents(file);
Matcher matcher = DEBUG_OPTION_PATTERN.matcher(content);
while (matcher.find())
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 dff7bad1b8..f19b4597c8 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
@@ -196,7 +196,7 @@ public final class Markers
public static IMarker addMarker(IFile file, String message, int severity, String regex) throws CoreException,
IOException
{
- String string = VersionUtil.getContent(file);
+ String string = VersionUtil.getContents(file);
Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
Matcher matcher = pattern.matcher(string);
@@ -207,7 +207,7 @@ public final class Markers
int endChar = matcher.end(1);
matcher = NL_PATTERN.matcher(string);
- int line = 0;
+ int line = 1;
while (matcher.find())
{
if (matcher.start(1) > startChar)
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionUtil.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionUtil.java
index 99090a84dd..e08eceb915 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionUtil.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionUtil.java
@@ -15,9 +15,13 @@ import org.eclipse.emf.cdo.releng.internal.version.Activator;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.pde.core.IModel;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
@@ -33,6 +37,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.io.Reader;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -65,7 +70,7 @@ public final class VersionUtil
return root.getFile(newPath);
}
- public static String getContent(IFile file) throws CoreException, IOException
+ public static String getContents(IFile file) throws CoreException, IOException
{
InputStream contents = null;
@@ -89,6 +94,73 @@ public final class VersionUtil
}
}
+ public static String getLineDelimiter(IFile file) throws IOException
+ {
+ InputStream inputStream = null;
+ try
+ {
+ inputStream = file.getContents();
+ String encoding = file.getCharset();
+ Reader reader = encoding == null ? new InputStreamReader(inputStream) : new InputStreamReader(inputStream,
+ encoding);
+ char[] text = new char[4048];
+ char target = 0;
+ for (int count = reader.read(text); count > -1; count = reader.read(text))
+ {
+ for (int i = 0; i < count; ++i)
+ {
+ char character = text[i];
+ if (character == '\n')
+ {
+ if (target == '\n')
+ {
+ return "\n";
+ }
+ else if (target == '\r')
+ {
+ return "\r\n";
+ }
+ else
+ {
+ target = '\n';
+ }
+ }
+ else if (character == '\r')
+ {
+ if (target == '\n')
+ {
+ return "\n\r";
+ }
+ else if (target == '\r')
+ {
+ return "\r";
+ }
+ else
+ {
+ target = '\r';
+ }
+ }
+ }
+ }
+ }
+ catch (Exception exception)
+ {
+ // If we can't determine it by reading the file,
+ // look at the preferences instead.
+ }
+ finally
+ {
+ if (inputStream != null)
+ {
+ inputStream.close();
+ }
+ }
+
+ return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR,
+ System.getProperty(Platform.PREF_LINE_SEPARATOR),
+ new IScopeContext[] { new ProjectScope(file.getProject()), InstanceScope.INSTANCE });
+ }
+
public static synchronized byte[] getSHA1(IFile file) throws NoSuchAlgorithmException, CoreException, IOException
{
InputStream stream = null;

Back to the top