Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-08-28 07:47:14 +0000
committerEike Stepper2012-08-28 07:47:14 +0000
commit5a8360ab2bbf49f8eb9a84d48f31fee7af28bfe0 (patch)
treeca4493d3d4cfd41ed008031f94004fa357a3face /plugins
parentff51e06bbf700929d5f2a15e4fcb0281cfe70ebb (diff)
downloadcdo-5a8360ab2bbf49f8eb9a84d48f31fee7af28bfe0.tar.gz
cdo-5a8360ab2bbf49f8eb9a84d48f31fee7af28bfe0.tar.xz
cdo-5a8360ab2bbf49f8eb9a84d48f31fee7af28bfe0.zip
Add quickfix checks/applications to VersionBuilderTests
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.tests/src/org/eclipse/emf/cdo/releng/version/tests/VersionBuilderTest.java341
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/build.markers2
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/build.resolutions10
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/fix1.markers4
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/fix1.resolutions19
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionUtil.java10
6 files changed, 290 insertions, 96 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 6e64af5e30..6202a14bdf 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
@@ -24,11 +24,14 @@ import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolution2;
import java.io.File;
+import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
@@ -44,8 +47,6 @@ import junit.framework.TestCase;
*/
public class VersionBuilderTest extends TestCase
{
- private static final VersionResolutionGenerator FIX_GENERATOR = new VersionResolutionGenerator();
-
private static final IWorkspace WORKSPACE = ResourcesPlugin.getWorkspace();
private static final IWorkspaceRoot ROOT = WORKSPACE.getRoot();
@@ -56,6 +57,18 @@ public class VersionBuilderTest extends TestCase
private static final String DELETE_SUFFIX = "-DELETE";
+ private static final VersionResolutionGenerator FIX_GENERATOR = new VersionResolutionGenerator();
+
+ private static final String FIX_PREFIX = "*";
+
+ private static final String CHAR_START = "<" + IMarker.CHAR_START + ">";
+
+ private static final String CHAR_END = "<" + IMarker.CHAR_END + ">";
+
+ private static final String SEVERITY = "<" + IMarker.SEVERITY + ">";
+
+ private static final String MESSAGE = "<" + IMarker.MESSAGE + ">";
+
private static final PrintStream MSG = System.out;
private static String lineDelimiter;
@@ -93,23 +106,32 @@ public class VersionBuilderTest extends TestCase
private void runPhase(BundleFile phase, boolean clean) throws Throwable
{
+
+ int fixAttempt = 0;
+ String fileName = "build";
+ String lastContents = "";
+
MSG.println(" Update workspace");
updateWorkspace(phase);
- IMarker[] markers = buildWorkspace(phase, clean);
- String lastContents = processMarkers(phase, markers, "build.markers");
- int fixAttempt = 0;
- while (markers.length != 0)
+ for (;;)
{
- MSG.println(" Fix workspace (attempt " + ++fixAttempt + ")");
- fixWorkspace(phase, markers);
- markers = buildWorkspace(phase, false);
- String contents = processMarkers(phase, markers, "fix" + fixAttempt + ".markers");
- if (contents.equals(lastContents))
+ IMarker[] markers = buildWorkspace(phase, clean);
+ String contents = processMarkers(phase, markers, fileName);
+ if (markers.length == 0 || contents.equals(lastContents))
{
break;
}
+ boolean hasFixes = processFixes(phase, markers, contents, fileName);
+ if (!hasFixes)
+ {
+ break;
+ }
+
+ clean = false;
+ ++fixAttempt;
+ fileName = "fix" + fixAttempt;
lastContents = contents;
}
}
@@ -249,33 +271,17 @@ public class VersionBuilderTest extends TestCase
return ROOT.findMarkers(Markers.MARKER_TYPE, false, IResource.DEPTH_INFINITE);
}
- private void fixWorkspace(BundleFile phase, IMarker[] markers)
- {
- for (IMarker marker : markers)
- {
- IMarkerResolution[] resolutions = FIX_GENERATOR.getResolutions(marker);
- if (resolutions != null && resolutions.length != 0)
- {
- assertTrue("Marker has resolutions but hasResolutions() returns false", FIX_GENERATOR.hasResolutions(marker));
- for (IMarkerResolution resolution : resolutions)
- {
- msg(resolution.getLabel() + ": " + marker.getResource().getFullPath().makeRelative());
- resolution.run(marker);
- }
- }
- }
- }
-
private String processMarkers(BundleFile phase, IMarker[] markers, String fileName) throws Throwable
{
+ fileName += ".markers";
BundleFile markersFile = phase.getChild(fileName);
if (markersFile != null)
{
- MSG.println(" Check markers");
+ MSG.println(" Check " + fileName);
return checkMarkers(phase, markers, markersFile);
}
- MSG.println(" Generate markers");
+ MSG.println(" Generate " + fileName);
return generateMarkers(phase, markers, fileName);
}
@@ -283,7 +289,7 @@ public class VersionBuilderTest extends TestCase
{
String expected = markersFile.getContents();
String actual = createMarkers(markers);
- assertEquals("After " + phase.getName() + " build", expected, actual);
+ assertEquals("In " + markersFile, expected, actual);
return actual;
}
@@ -295,7 +301,7 @@ public class VersionBuilderTest extends TestCase
return contents;
}
- private static String createMarkers(IMarker[] markers) throws Throwable
+ private String createMarkers(IMarker[] markers) throws Throwable
{
if (markers.length == 0)
{
@@ -325,10 +331,9 @@ public class VersionBuilderTest extends TestCase
}
});
- IFile lastContentsFile = null;
- String contents = null;
-
+ FileContentsProvider fileContentsProvider = new FileContentsProvider();
StringBuilder builder = new StringBuilder();
+
for (IMarker marker : markers)
{
IFile file = (IFile)marker.getResource();
@@ -342,114 +347,232 @@ public class VersionBuilderTest extends TestCase
builder.append("Marker");
builder.append(lineDelimiter);
- addAttribute(builder, Markers.RESOURCE_ATTRIBUTE + " ", file.getFullPath().makeRelative());
+ addAttribute(builder, Markers.RESOURCE_ATTRIBUTE + " ", file.getFullPath().makeRelative(), true);
Map<String, Object> attributes = marker.getAttributes();
List<String> keys = new ArrayList<String>(attributes.keySet());
keys.remove(IMarker.LINE_NUMBER);
- if (keys.remove(IMarker.CHAR_START))
+ createLocationMarkers(builder, attributes, keys, file, fileContentsProvider, true);
+
+ if (keys.remove(IMarker.SEVERITY))
{
- int indexStart = (Integer)attributes.get(IMarker.CHAR_START);
- int indexEnd = -1;
- if (keys.remove(IMarker.CHAR_END))
+ int severity = (Integer)attributes.get(IMarker.SEVERITY);
+ addAttribute(builder, SEVERITY + " ", getSeverityLabel(severity), true);
+ }
+
+ if (keys.remove(IMarker.MESSAGE))
+ {
+ addAttribute(builder, MESSAGE + " ", attributes.get(IMarker.MESSAGE), true);
+ }
+
+ if (keys.remove(Markers.PROBLEM_TYPE))
+ {
+ addAttribute(builder, Markers.PROBLEM_TYPE, attributes.get(Markers.PROBLEM_TYPE), true);
+ }
+
+ Collections.sort(keys);
+ for (String key : keys)
+ {
+ Object value = attributes.get(key);
+ addAttribute(builder, key, value, true);
+ }
+
+ IMarkerResolution[] resolutions = FIX_GENERATOR.getResolutions(marker);
+ if (resolutions != null && resolutions.length != 0)
+ {
+ assertTrue("Marker has resolutions but hasResolutions() returns false", FIX_GENERATOR.hasResolutions(marker));
+ for (IMarkerResolution resolution : resolutions)
{
- indexEnd = (Integer)attributes.get(IMarker.CHAR_END);
+ addFix(builder, resolution);
}
+ }
+ }
+
+ return builder.toString();
+ }
+
+ private void createLocationMarkers(StringBuilder builder, Map<String, Object> attributes, List<String> keys,
+ IFile file, FileContentsProvider fileContentsProvider, boolean msg) throws CoreException, IOException
+ {
+ 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)
+ String contents = fileContentsProvider.getContents(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')
{
- contents = VersionUtil.getContents(file);
- lastContentsFile = file;
+ ++lf;
+ column = 1;
+ }
+ else if (c == '\r')
+ {
+ ++cr;
+ column = 1;
}
- int size = contents.length();
- for (int i = 0, lf = 1, cr = 1, column = 0; i < size; ++i, ++column)
+ if (i == indexStart || i == indexEnd)
{
- char c = contents.charAt(i);
- if (c == '\n')
- {
- ++lf;
- column = 1;
- }
- else if (c == '\r')
- {
- ++cr;
- column = 1;
- }
+ String value = "(" + Math.max(cr, lf) + "," + column + ")";
- if (i == indexStart || i == indexEnd)
+ if (i == indexStart)
{
- String value = "(" + Math.max(cr, lf) + "," + column + ")";
-
- if (i == indexStart)
- {
- addAttribute(builder, "<" + IMarker.CHAR_START + ">", value);
- if (indexEnd == -1)
- {
- break;
- }
- }
- else
+ addAttribute(builder, CHAR_START, value, msg);
+ if (indexEnd == -1)
{
- addAttribute(builder, "<" + IMarker.CHAR_END + "> ", value);
break;
}
}
+ else
+ {
+ addAttribute(builder, CHAR_END + " ", value, msg);
+ break;
+ }
}
-
}
+ }
+ }
- if (keys.remove(IMarker.SEVERITY))
+ private boolean processFixes(BundleFile phase, IMarker[] markers, String contents, String fileName) throws Throwable
+ {
+ fileName += ".resolutions";
+ BundleFile resolutionsFile = phase.getChild(fileName);
+ if (resolutionsFile != null)
+ {
+ MSG.println(" Apply " + fileName);
+ return applyFixes(phase, markers, resolutionsFile);
+ }
+
+ MSG.println(" Generate " + fileName);
+ generateFixes(phase, contents, fileName);
+ return false;
+ }
+
+ private boolean applyFixes(BundleFile phase, IMarker[] markers, BundleFile resolutionsFile) throws Throwable
+ {
+ boolean hasFixes = false;
+ IPath path = null;
+ String location = null;
+ String problemType = null;
+
+ String contents = resolutionsFile.getContents();
+ String[] lines = contents.split("[\n\r]");
+ for (int i = 0; i < lines.length; i++)
+ {
+ String line = lines[i].trim();
+
+ if (line.startsWith(Markers.RESOURCE_ATTRIBUTE))
{
- int severity = (Integer)attributes.get(IMarker.SEVERITY);
- addAttribute(builder, "<" + IMarker.SEVERITY + "> ", getSeverityLabel(severity));
+ path = new Path(parseValue(line)).makeAbsolute();
}
- if (keys.remove(IMarker.MESSAGE))
+ if (line.startsWith(CHAR_START))
{
- addAttribute(builder, "<" + IMarker.MESSAGE + "> ", attributes.get(IMarker.MESSAGE));
+ location = parseValue(line);
}
- if (keys.remove(Markers.PROBLEM_TYPE))
+ if (line.startsWith(Markers.PROBLEM_TYPE))
{
- addAttribute(builder, Markers.PROBLEM_TYPE, attributes.get(Markers.PROBLEM_TYPE));
+ problemType = parseValue(line);
}
- Collections.sort(keys);
- for (String key : keys)
+ if (line.startsWith(FIX_PREFIX))
{
- Object value = attributes.get(key);
- addAttribute(builder, key, value);
+ hasFixes = true;
+ String fix = parseValue(line);
+ applyFix(phase, markers, path, location, problemType, fix);
+
+ path = null;
+ location = null;
+ problemType = null;
}
+ }
- IMarkerResolution[] resolutions = FIX_GENERATOR.getResolutions(marker);
- if (resolutions != null && resolutions.length != 0)
+ return hasFixes;
+ }
+
+ private void applyFix(BundleFile phase, IMarker[] markers, IPath path, String location, String problemType, String fix)
+ throws Throwable
+ {
+ FileContentsProvider fileContentsProvider = new FileContentsProvider();
+ for (IMarker marker : markers)
+ {
+ IFile file = (IFile)marker.getResource();
+ if (file.getFullPath().equals(path))
{
- assertTrue("Marker has resolutions but hasResolutions() returns false", FIX_GENERATOR.hasResolutions(marker));
- for (int j = 0; j < resolutions.length; j++)
+ String markerProblemType = Markers.getProblemType(marker);
+ if (VersionUtil.equals(markerProblemType, problemType))
{
- IMarkerResolution resolution = resolutions[j];
- addFix(builder, j + 1, resolution);
+ Map<String, Object> attributes = marker.getAttributes();
+ List<String> keys = new ArrayList<String>();
+ keys.add(IMarker.CHAR_START);
+
+ StringBuilder builder = new StringBuilder();
+ createLocationMarkers(builder, attributes, keys, file, fileContentsProvider, false);
+ String markerLocation = parseValue(builder.toString());
+ if (VersionUtil.equals(markerLocation, location))
+ {
+ applyFix(phase, marker, fix);
+ return;
+ }
}
}
}
- return builder.toString();
+ // throw new IllegalStateException("No marker found for '" + path + "'");
+ }
+
+ private void applyFix(BundleFile phase, IMarker marker, String fix) throws Throwable
+ {
+ IMarkerResolution[] resolutions = FIX_GENERATOR.getResolutions(marker);
+ for (IMarkerResolution resolution : resolutions)
+ {
+ // msg(resolution.getLabel() + ": " + file.getFullPath().makeRelative());
+
+ StringBuilder builder = new StringBuilder();
+ addFix(builder, resolution);
+ String resolutionFix = parseValue(builder.toString());
+ if (VersionUtil.equals(resolutionFix, fix))
+ {
+ resolution.run(marker);
+ return;
+ }
+ }
+
+ throw new IllegalStateException("No resolution found for '" + fix + "'");
}
- private static void addAttribute(StringBuilder builder, String key, Object value)
+ private void generateFixes(BundleFile phase, String contents, String fileName) throws Throwable
+ {
+ BundleFile resolutionsFile = phase.addChild(fileName, false);
+ resolutionsFile.setContents(contents);
+ }
+
+ private static void addAttribute(StringBuilder builder, String key, Object value, boolean msg)
{
String str = " " + key + " = " + value;
- msg(str);
+ if (msg)
+ {
+ msg(str);
+ }
builder.append(str);
builder.append(lineDelimiter);
}
- private static void addFix(StringBuilder builder, int j, IMarkerResolution resolution)
+ private static void addFix(StringBuilder builder, IMarkerResolution resolution)
{
- String str = " FIX-" + j + " = " + resolution.getLabel();
+ String str = " FIX = " + resolution.getLabel();
if (resolution instanceof IMarkerResolution2)
{
IMarkerResolution2 resolution2 = (IMarkerResolution2)resolution;
@@ -482,8 +605,40 @@ public class VersionBuilderTest extends TestCase
return file.getAbsolutePath().substring(TRIM_LENGTH).replace('\\', '/');
}
+ private static String parseValue(String str)
+ {
+ int pos = str.indexOf('=');
+ if (pos == -1)
+ {
+ throw new IllegalArgumentException("Property syntax error");
+ }
+
+ return str.substring(pos + 1).trim();
+ }
+
private static void msg(String string)
{
MSG.println(" " + string);
}
+
+ /**
+ * @author Eike Stepper
+ */
+ private static class FileContentsProvider
+ {
+ private IFile file;
+
+ private String contents;
+
+ public String getContents(IFile file) throws CoreException, IOException
+ {
+ if (!VersionUtil.equals(this.file, file))
+ {
+ contents = VersionUtil.getContents(file);
+ this.file = file;
+ }
+
+ return contents;
+ }
+ }
}
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 7d4d0a3098..789c2b571a 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
@@ -7,4 +7,4 @@ Marker
problemType = component.version
quickFixPattern = Bundle-Version: *(\d+(\.\d+(\.\d+)?)?)
quickFixReplacement = 1.0.100
- FIX-1 = Change the version (Change the version to 1.0.100)
+ FIX = Change the version (Change the version to 1.0.100)
diff --git a/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/build.resolutions b/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/build.resolutions
new file mode 100644
index 0000000000..1f12894166
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/build.resolutions
@@ -0,0 +1,10 @@
+Marker
+ <resource> = com.foo.project1/META-INF/MANIFEST.MF
+ <charStart> = (4,18)
+ <charEnd> = (4,23)
+ <severity> = ERROR
+ <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
+ *FIX = Change the version (Change the version to 1.0.100)
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 9698a7776c..09e9d5fcca 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
@@ -8,8 +8,8 @@ Marker
quickFixConfigureOption = ignore.feature.content.changes
quickFixPattern = feature.*?version\s*=\s*["'](\d+(\.\d+(\.\d+)?)?)
quickFixReplacement = 1.0.100
- FIX-1 = Change the version (Change the version to 1.0.100)
- FIX-2 = Configure the project to ignore the problem (Set ignore.feature.content.changes = true in '/com.foo.project1-feature/.project')
+ FIX = Change the version (Change the version to 1.0.100)
+ FIX = Configure the project to ignore the problem (Set ignore.feature.content.changes = true in '/com.foo.project1-feature/.project')
Marker
<resource> = com.foo.project1-feature/feature.xml
<charStart> = (28,15)
diff --git a/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/fix1.resolutions b/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/fix1.resolutions
new file mode 100644
index 0000000000..3f15a04540
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.releng.version.tests/tests/00002-ProblemAfterChange/incremental/fix1.resolutions
@@ -0,0 +1,19 @@
+Marker
+ <resource> = com.foo.project1-feature/feature.xml
+ <charStart> = (5,17)
+ <charEnd> = (5,22)
+ <severity> = ERROR
+ <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
+ *FIX = Change the version (Change the version to 1.0.100)
+ FIX = Configure the project to ignore the problem (Set ignore.feature.content.changes = true in '/com.foo.project1-feature/.project')
+Marker
+ <resource> = com.foo.project1-feature/feature.xml
+ <charStart> = (28,15)
+ <charEnd> = (28,31)
+ <severity> = WARNING
+ <message> = Plug-in reference 'com.foo.project1' has been changed from 1.0.0 to 1.0.100
+ problemType = component.version
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 e08eceb915..0dc0b86b28 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
@@ -57,6 +57,16 @@ public final class VersionUtil
{
}
+ public static boolean equals(Object o1, Object o2)
+ {
+ if (o1 == null)
+ {
+ return o2 == null;
+ }
+
+ return o1.equals(o2);
+ }
+
public static Version normalize(Version version)
{
return new Version(version.getMajor(), version.getMinor(), version.getMicro());

Back to the top