aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis Windatt2013-08-15 09:56:30 (EDT)
committerDani Megert2013-08-15 09:56:30 (EDT)
commit4a135ef2eb1d77a8e170a2af3856ec3a37a0f408 (patch)
tree6a2cd3d802da9878f85d77ed204b24cf08330b45
parent70a46799bbb26c9e4d2c7c80ed2b8820773ac888 (diff)
downloadeclipse.platform.releng-4a135ef2eb1d77a8e170a2af3856ec3a37a0f408.zip
eclipse.platform.releng-4a135ef2eb1d77a8e170a2af3856ec3a37a0f408.tar.gz
eclipse.platform.releng-4a135ef2eb1d77a8e170a2af3856ec3a37a0f408.tar.bz2
Fixed bug 414985: POM version problem reporter could also support feature versionsI20130820-0800
Signed-off-by: Curtis Windatt <cwindatt@ca.ibm.com>
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/Messages.java1
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/PomVersionErrorReporter.java215
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/messages.properties1
3 files changed, 149 insertions, 68 deletions
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/Messages.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/Messages.java
index 49aded6..b0e3616 100644
--- a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/Messages.java
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/Messages.java
@@ -18,6 +18,7 @@ final class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.releng.internal.tools.pomversion.messages"; //$NON-NLS-1$
public static String PomVersionErrorReporter_pom_version_error_marker_message;
+ public static String PomVersionErrorReporter_pom_version_error_marker_message_feature;
public static String PomVersionMarkerResolution_label;
static {
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/PomVersionErrorReporter.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/PomVersionErrorReporter.java
index c44eb62..ee3bb60 100644
--- a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/PomVersionErrorReporter.java
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/PomVersionErrorReporter.java
@@ -19,10 +19,25 @@ import java.util.jar.JarFile;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-import org.eclipse.core.filebuffers.FileBuffers;
-import org.eclipse.core.filebuffers.ITextFileBuffer;
-import org.eclipse.core.filebuffers.ITextFileBufferManager;
-import org.eclipse.core.filebuffers.LocationKind;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import org.eclipse.osgi.util.ManifestElement;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.releng.tools.RelEngPlugin;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
@@ -33,24 +48,16 @@ import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+import org.eclipse.core.filebuffers.LocationKind;
+
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.osgi.util.ManifestElement;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.releng.tools.RelEngPlugin;
+
import org.eclipse.ui.texteditor.MarkerUtilities;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Version;
-import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
/**
@@ -70,10 +77,9 @@ public class PomVersionErrorReporter implements IResourceChangeListener, IEclips
if(delta.getKind() == IResourceDelta.REMOVED) {
return false;
}
- //Should we not care about non-plugin projects?
IProject project = (IProject) resource;
try {
- if(project.isAccessible() && project.getDescription().hasNature("org.eclipse.pde.PluginNature")) { //$NON-NLS-1$
+ if(project.isAccessible() && (project.getDescription().hasNature("org.eclipse.pde.PluginNature") || project.getDescription().hasNature("org.eclipse.pde.FeatureNature"))) { //$NON-NLS-1$ //$NON-NLS-2$
if((delta.getFlags() & IResourceDelta.OPEN) > 0) {
validate(project);
return false;
@@ -93,9 +99,9 @@ public class PomVersionErrorReporter implements IResourceChangeListener, IEclips
case IResource.FILE: {
switch(delta.getKind()) {
case IResourceDelta.REMOVED: {
- //if manifest removed, clean up markers
- if(resource.getProjectRelativePath().equals(MANIFEST_PATH)) {
- //manifest content changed
+ //if manifest or feature removed, clean up markers
+ if(resource.getProjectRelativePath().equals(FEATURE_PATH) ||
+ resource.getProjectRelativePath().equals(MANIFEST_PATH)) {
IProject p = resource.getProject();
if(p.isAccessible()) {
cleanMarkers(p);
@@ -104,8 +110,9 @@ public class PomVersionErrorReporter implements IResourceChangeListener, IEclips
break;
}
case IResourceDelta.ADDED: {
- //if the POM or manifest has been added scan them
- if(resource.getProjectRelativePath().equals(MANIFEST_PATH) ||
+ //if the POM, manifest or feature.xml has been added scan them
+ if(resource.getProjectRelativePath().equals(FEATURE_PATH) ||
+ resource.getProjectRelativePath().equals(MANIFEST_PATH) ||
resource.getProjectRelativePath().equals(POM_PATH)) {
validate(resource.getProject());
}
@@ -114,7 +121,8 @@ public class PomVersionErrorReporter implements IResourceChangeListener, IEclips
case IResourceDelta.CHANGED: {
//if the content has changed clean + scan
if((delta.getFlags() & IResourceDelta.CONTENT) > 0) {
- if(resource.getProjectRelativePath().equals(MANIFEST_PATH) ||
+ if(resource.getProjectRelativePath().equals(FEATURE_PATH) ||
+ resource.getProjectRelativePath().equals(MANIFEST_PATH) ||
resource.getProjectRelativePath().equals(POM_PATH)) {
validate(resource.getProject());
}
@@ -137,17 +145,23 @@ public class PomVersionErrorReporter implements IResourceChangeListener, IEclips
* XML parsing handler to check the POM version infos
*/
class PomVersionHandler extends DefaultHandler {
- private Version bundleVersion;
+ private Version version;
private Stack elements = new Stack();
private boolean checkVersion = false;
+ private boolean isFeatureProject = false;
private Locator locator;
IFile pom = null;
String severity = null;
public PomVersionHandler(IFile file, Version bundleVersion, String pref) {
+ this(file, bundleVersion, pref, false);
+ }
+
+ public PomVersionHandler(IFile file, Version version, String pref, boolean isFeatureProject) {
pom = file;
severity = pref;
- this.bundleVersion = bundleVersion;
+ this.version = version;
+ this.isFeatureProject = isFeatureProject;
}
public void setDocumentLocator(Locator locator) {
@@ -181,7 +195,7 @@ public class PomVersionErrorReporter implements IResourceChangeListener, IEclips
}
// Create corrected version (no qualifiers, add back snapshot suffix)
- Version bundleVersion2 = new Version(bundleVersion.getMajor(), bundleVersion.getMinor(), bundleVersion.getMicro());
+ Version bundleVersion2 = new Version(version.getMajor(), version.getMinor(), version.getMicro());
String correctedVersion = bundleVersion2.toString();
if (index >= 0) {
correctedVersion = correctedVersion.concat(SNAPSHOT_SUFFIX);
@@ -200,7 +214,9 @@ public class PomVersionErrorReporter implements IResourceChangeListener, IEclips
index = str.indexOf(origVer);
int charStart = lineOffset + index;
int charEnd = charStart + origVer.length();
- reportMarker(NLS.bind(Messages.PomVersionErrorReporter_pom_version_error_marker_message, versionString, bundleVersion2.toString()),
+
+ String message = isFeatureProject ? Messages.PomVersionErrorReporter_pom_version_error_marker_message_feature : Messages.PomVersionErrorReporter_pom_version_error_marker_message;
+ reportMarker(NLS.bind(message, versionString, bundleVersion2.toString()),
locator.getLineNumber(),
charStart,
charEnd,
@@ -224,7 +240,8 @@ public class PomVersionErrorReporter implements IResourceChangeListener, IEclips
index = str.indexOf(origVer);
int charStart = lineOffset + index;
int charEnd = charStart + origVer.length();
- reportMarker(NLS.bind(Messages.PomVersionErrorReporter_pom_version_error_marker_message, pomVersion2.toString(), bundleVersion2.toString()),
+ String message = isFeatureProject ? Messages.PomVersionErrorReporter_pom_version_error_marker_message_feature : Messages.PomVersionErrorReporter_pom_version_error_marker_message;
+ reportMarker(NLS.bind(message, pomVersion2.toString(), bundleVersion2.toString()),
locator.getLineNumber(),
charStart,
charEnd,
@@ -240,9 +257,35 @@ public class PomVersionErrorReporter implements IResourceChangeListener, IEclips
}
}
}
+
+ /**
+ * XML parsing handler to check the feature.xml version
+ */
+ class FeatureVersionHandler extends DefaultHandler {
+ private String featureVersion;
+
+ public FeatureVersionHandler() {
+ }
+
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ // The version is on the root element, check for the attribute then throw exception to exit early
+ featureVersion = attributes.getValue("version"); //$NON-NLS-1$
+ throw new OperationCanceledException();
+ }
+
+ /**
+ * Returns the string version value found in the feature.xml or <code>null</code>
+ *
+ * @return string version from feature.xml or <code>null</code>
+ */
+ public String getVersion() {
+ return featureVersion;
+ }
+
+ }
/**
- * Project relative path to the pom.xml file
+ * Project relative path to the pom.xml file.
*/
public static final IPath POM_PATH = new Path("pom.xml"); //$NON-NLS-1$
@@ -250,6 +293,12 @@ public class PomVersionErrorReporter implements IResourceChangeListener, IEclips
* Project relative path to the manifest file.
*/
public static final IPath MANIFEST_PATH = new Path(JarFile.MANIFEST_NAME);
+
+ /**
+ * Project relative path to the feature.xml file.
+ */
+ public static final IPath FEATURE_PATH = new Path("feature.xml"); //$NON-NLS-1$
+
private static final String ELEMENT_PROJECT = "project"; //$NON-NLS-1$
private static final String ELEMENT_VERSION = "version"; //$NON-NLS-1$
private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT"; //$NON-NLS-1$
@@ -270,7 +319,7 @@ public class PomVersionErrorReporter implements IResourceChangeListener, IEclips
}
/**
- * Validates the version in the Manifest.MF file against the version in the <code>pom.xml</code> file
+ * Validates the manifest or feature version against the version in the <code>pom.xml</code> file
*
* @param project
* @param severity
@@ -286,47 +335,77 @@ public class PomVersionErrorReporter implements IResourceChangeListener, IEclips
if (IPomVersionConstants.VALUE_IGNORE.equals(severity)) {
return;
}
- IFile manifest = project.getFile(MANIFEST_PATH);
- if(!manifest.exists()) {
- return;
- }
IFile pom = project.getFile(POM_PATH);
if(!pom.exists()) {
return;
}
- // Get the manifest version
- Version bundleVersion = Version.emptyVersion;
- try {
- Map headers = new HashMap();
- ManifestElement.parseBundleManifest(manifest.getContents(), headers);
- String ver = (String)headers.get(Constants.BUNDLE_VERSION);
- if(ver == null) {
+ IFile manifest = project.getFile(MANIFEST_PATH);
+ if(manifest.exists()) {
+ // Get the manifest version
+ Version bundleVersion = Version.emptyVersion;
+ try {
+ Map headers = new HashMap();
+ ManifestElement.parseBundleManifest(manifest.getContents(), headers);
+ String ver = (String)headers.get(Constants.BUNDLE_VERSION);
+ if(ver == null) {
+ return;
+ }
+ bundleVersion = Version.parseVersion(ver);
+ } catch (IOException e) {
+ // Ignored, if there is a problem with the manifest, don't create a marker
+ return;
+ } catch (CoreException e){
+ // Ignored, if there is a problem with the manifest, don't create a marker
+ return;
+ } catch (BundleException e) {
+ // Ignored, if there is a problem with the manifest, don't create a marker
+ return;
+ } catch (IllegalArgumentException e){
+ // Ignored, if there is a problem with the manifest, don't create a marker
return;
}
- bundleVersion = Version.parseVersion(ver);
- } catch (IOException e) {
- // Ignored, if there is a problem with the manifest, don't create a marker
- return;
- } catch (CoreException e){
- // Ignored, if there is a problem with the manifest, don't create a marker
- return;
- } catch (BundleException e) {
- // Ignored, if there is a problem with the manifest, don't create a marker
- return;
- } catch (IllegalArgumentException e){
- // Ignored, if there is a problem with the manifest, don't create a marker
- return;
- }
- // Compare it to the POM file version
- try {
- SAXParserFactory parserFactory = SAXParserFactory.newInstance();
- SAXParser parser = parserFactory.newSAXParser();
- PomVersionHandler handler = new PomVersionHandler(pom, bundleVersion, severity);
- parser.parse(pom.getContents(), handler);
- } catch (Exception e) {
- // Ignored, if there is a problem with the POM file don't create a marker
- return;
+ // Compare it to the POM file version
+ try {
+ SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+ SAXParser parser = parserFactory.newSAXParser();
+ PomVersionHandler handler = new PomVersionHandler(pom, bundleVersion, severity);
+ parser.parse(pom.getContents(), handler);
+ } catch (Exception e) {
+ // Ignored, if there is a problem with the POM file don't create a marker
+ return;
+ }
+
+ } else {
+ IFile feature = project.getFile(FEATURE_PATH);
+ if (feature.exists()){
+ try {
+ // Get the feature version
+ Version featureVersion = Version.emptyVersion;
+ SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+ SAXParser parser = parserFactory.newSAXParser();
+ FeatureVersionHandler handler = new FeatureVersionHandler();
+ try {
+ parser.parse(feature.getContents(), handler);
+ } catch (OperationCanceledException e){
+ // Do nothing, used to avoid parsing the entire file
+ }
+
+ String version = handler.getVersion();
+ if (version == null){
+ // Ignored, if there is a problem with the feature, don't create a marker
+ return;
+ }
+ featureVersion = Version.parseVersion(version);
+
+ // Compare it to the POM file version
+ PomVersionHandler pomHandler = new PomVersionHandler(pom, featureVersion, severity, true);
+ parser.parse(pom.getContents(), pomHandler);
+ } catch (Exception e) {
+ // Ignored, if there is a problem with the POM file don't create a marker
+ return;
+ }
+ }
}
}
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/messages.properties b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/messages.properties
index f4c4ba4..014eeb0 100644
--- a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/messages.properties
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/internal/tools/pomversion/messages.properties
@@ -10,4 +10,5 @@
###############################################################################
PomVersionErrorReporter_pom_version_error_marker_message=POM artifact version {0} does not match bundle version {1}
+PomVersionErrorReporter_pom_version_error_marker_message_feature=POM artifact version {0} does not match feature version {1}
PomVersionMarkerResolution_label=Replace version in pom.xml with {0}