aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Rennie2013-05-21 15:37:44 (EDT)
committerCurtis Windatt2013-05-21 15:37:44 (EDT)
commit3374a4984385f416c5b3cc207f4aac697cc3f452 (patch)
treef78a7d836f96a74717ac6b8a07c2a4363d142c20
parent16a98d7dced5f9eb6d712d8adae5824fb08dd934 (diff)
downloadeclipse.platform.releng-3374a4984385f416c5b3cc207f4aac697cc3f452.zip
eclipse.platform.releng-3374a4984385f416c5b3cc207f4aac697cc3f452.tar.gz
eclipse.platform.releng-3374a4984385f416c5b3cc207f4aac697cc3f452.tar.bz2
Bug 408152 - [relengtools] Add POM version tool to Releng Tools
-rw-r--r--bundles/org.eclipse.releng.tools/.settings/org.eclipse.core.resources.prefs2
-rw-r--r--bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF1
-rw-r--r--bundles/org.eclipse.releng.tools/plugin.properties16
-rw-r--r--bundles/org.eclipse.releng.tools/plugin.xml48
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/RelEngPlugin.java45
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/IPomVersionConstants.java4
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/Messages.java28
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/PomVersionBuilder.java139
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/PomVersionErrorReporter.java351
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/messages.properties1
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/Messages.java29
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/PomErrorLevelBlock.java8
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/PomVersionPreferencePage.java2
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/messages.properties2
14 files changed, 417 insertions, 259 deletions
diff --git a/bundles/org.eclipse.releng.tools/.settings/org.eclipse.core.resources.prefs b/bundles/org.eclipse.releng.tools/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..6a629b7
--- /dev/null
+++ b/bundles/org.eclipse.releng.tools/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding//src/org/eclipse/releng/tools/pomversion/PomVersionErrorReporter.java=UTF-8
diff --git a/bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF b/bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF
index 865eb79..06d4623 100644
--- a/bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF
@@ -24,7 +24,6 @@ Require-Bundle: org.eclipse.ui.ide;resolution:=optional,
org.eclipse.ui.console,
org.eclipse.jgit;bundle-version="1.3.0";resolution:=optional,
org.eclipse.egit.core;bundle-version="1.3.0";resolution:=optional
-Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Export-Package: org.eclipse.releng.tools,
org.eclipse.releng.tools.git;x-friends:="org.eclipse.releng.tests",
diff --git a/bundles/org.eclipse.releng.tools/plugin.properties b/bundles/org.eclipse.releng.tools/plugin.properties
index b1d30a5..92208bc 100644
--- a/bundles/org.eclipse.releng.tools/plugin.properties
+++ b/bundles/org.eclipse.releng.tools/plugin.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2003, 2007 IBM Corporation and others.
+# Copyright (c) 2003, 2013 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
@@ -16,3 +16,17 @@ RelEng=RelEng Tools
RelEngActionSet.description=RelEng Tool Action Set
RelEngActionSet.Release=Releasing...
RelEngActionSet.tooltip=Release Projects
+
+releaseAction.label = Re&lease...
+releasedAction.label = Released
+compareProjectsAction.tooltip = Compare the selected project(s) with the released versions
+replaceProjectsAction.tooltip = Replace the selcted project(s) with the released versions
+loadMapProjectsAction.label = Load Map Projects
+tagMapProjectsAction.label = Tag Map Projects
+fixCopyrightsAction.label = Fix Copyrights
+copyrightToolPrefPage.name = Copyright Tool
+relengMapProjectPrefPage.name = Releng Map Project Selection
+pomPrefPage.name = POM Version Tool
+pomVersionMarker.name = POM Version Problem
+pomVersionMarkerCategory.name = POM Version Problems
+action.label = Release... \ No newline at end of file
diff --git a/bundles/org.eclipse.releng.tools/plugin.xml b/bundles/org.eclipse.releng.tools/plugin.xml
index a212745..b81e724 100644
--- a/bundles/org.eclipse.releng.tools/plugin.xml
+++ b/bundles/org.eclipse.releng.tools/plugin.xml
@@ -14,22 +14,22 @@
value="org.eclipse.team.core.repository=org.eclipse.team.cvs.core.cvsnature">
</filter>
<action
- label="Re&amp;lease..."
+ label="%releaseAction.label"
class="org.eclipse.releng.tools.TagAndReleaseAction"
menubarPath="team.main/group2"
id="org.eclipse.releng.tools.tagAndRelease">
</action>
<action
- label="Released"
- tooltip="Compare the selected project(s) with the released versions"
+ label="%releasedAction.label"
+ tooltip="%compareProjectsAction.tooltip"
class="org.eclipse.releng.tools.CompareLocalToMap"
menubarPath="compareWithMenu/compareWithGroup"
id="org.eclipse.releng.tools.compareWithReleased">
</action>
<action
- label="Released"
+ label="%releasedAction.label"
class="org.eclipse.releng.tools.ReplaceLocalFromMap"
- tooltip="Replace the selcted project(s) with the released versions"
+ tooltip="%replaceProjectsAction.tooltip"
menubarPath="replaceWithMenu/replaceWithGroup"
id="org.eclipse.releng.tools.replaceWithReleased">
</action>
@@ -39,27 +39,27 @@
objectClass="org.eclipse.ui.IWorkingSet"
id="org.eclipse.releng.tools.WorkingSetContributions">
<action
- label="Release..."
+ label="%action.label"
class="org.eclipse.releng.tools.TagAndReleaseAction"
menubarPath="team.main/group2"
id="org.eclipse.releng.tools.tagAndRelease">
</action>
<action
- label="Released"
- tooltip="Compare the selected project(s) with the released versions"
+ label="%releasedAction.label"
+ tooltip="%compareProjectsAction.tooltip"
class="org.eclipse.releng.tools.CompareLocalToMap"
menubarPath="compareWithMenu/compareWithGroup"
id="org.eclipse.releng.tools.compareWithReleased">
</action>
<action
- label="Released"
+ label="%releasedAction.label"
class="org.eclipse.releng.tools.ReplaceLocalFromMap"
- tooltip="Replace the selcted project(s) with the released versions"
+ tooltip="%replaceProjectsAction.tooltip"
menubarPath="replaceWithMenu/replaceWithGroup"
id="org.eclipse.releng.tools.replaceWithReleased">
</action>
<action
- label="Fix Copyrights"
+ label="%fixCopyrightsAction.label"
class="org.eclipse.releng.tools.AdvancedFixCopyrightAction"
menubarPath="additions"
enablesFor="+"
@@ -72,13 +72,13 @@
nameFilter="*.map"
id="org.eclipse.releng.cvs.mapActions">
<action
- label="Load Map Projects"
+ label="%loadMapProjectsAction.label"
class="org.eclipse.releng.tools.LoadMap"
menubarPath="team.main/group1"
id="org.eclipse.releng.cvs.LoadMap">
</action>
<action
- label="Tag Map Projects"
+ label="%tagMapProjectsAction.label"
class="org.eclipse.releng.tools.TagMap"
menubarPath="team.main/group1"
id="org.eclipse.releng.cvs.TagMap">
@@ -89,7 +89,7 @@
objectClass="org.eclipse.core.resources.IResource"
id="org.eclipse.releng.internal.tools.AdvancedCopyrightContribution">
<action
- label="Fix Copyrights"
+ label="%fixCopyrightsAction.label"
class="org.eclipse.releng.tools.AdvancedFixCopyrightAction"
menubarPath="additions"
enablesFor="+"
@@ -119,20 +119,20 @@
<!-- ********** Preference Pages ************** -->
<extension point="org.eclipse.ui.preferencePages">
<page
- name="Copyright Tool"
+ name="%copyrightToolPrefPage.name"
class="org.eclipse.releng.tools.preferences.CopyrightPreferencePage"
id="org.eclipse.releng.tools.preferences.CopyrightPreferencePage">
</page>
<page
class="org.eclipse.releng.tools.preferences.MapProjectPreferencePage"
id="org.eclipse.releng.tools.preferences.MapProjectPreferencePage"
- name="Releng Map Project Selection"
+ name="%relengMapProjectPrefPage.name"
category="org.eclipse.team.ui.TeamPreferences">
</page>
<page
class="org.eclipse.releng.tools.preferences.PomVersionPreferencePage"
id="org.eclipse.releng.tools.preferences.PomVersionPreferencePage"
- name="POM Version Tool">
+ name="%pomPrefPage.name">
</page>
</extension>
@@ -158,7 +158,7 @@
</adapter>
</factory>
</extension>
-<extension id="org.eclipse.releng.tools.pomVersionProblem" point="org.eclipse.core.resources.markers" name="POM Version Problem">
+<extension id="pomVersionProblem" point="org.eclipse.core.resources.markers" name="%pomVersionMarker.name">
<super type="org.eclipse.core.resources.problemmarker"/>
<super type="org.eclipse.core.resources.textmarker"/>
<persistent value="true"/>
@@ -166,7 +166,7 @@
<extension
point="org.eclipse.ui.ide.markerSupport">
<markerTypeCategory
- name="POM Version Problems">
+ name="%pomVersionMarkerCategory.name">
<markerTypeReference
id="org.eclipse.releng.tools.pomVersionProblem">
</markerTypeReference>
@@ -180,14 +180,8 @@
</markerResolutionGenerator>
</extension>
<extension
- id="PomVersionBuilder"
- name="Pom Version Tool"
- point="org.eclipse.core.resources.builders">
- <builder>
- <run
- class="org.eclipse.releng.tools.pomversion.PomVersionBuilder">
- </run>
- </builder>
+ point="org.eclipse.ui.startup">
+ <startup></startup>
</extension>
</plugin>
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/RelEngPlugin.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/RelEngPlugin.java
index de43964..e4efca1 100644
--- a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/RelEngPlugin.java
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/RelEngPlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -14,14 +14,21 @@ import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.releng.tools.pomversion.IPomVersionConstants;
+import org.eclipse.releng.tools.pomversion.PomVersionErrorReporter;
import org.eclipse.team.core.RepositoryProvider;
+import org.eclipse.ui.IStartup;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
/**
@@ -32,13 +39,14 @@ import org.eclipse.ui.plugin.AbstractUIPlugin;
* <li>Builder and associated project nature
* <li>Fix Copyright action
*/
-public class RelEngPlugin extends AbstractUIPlugin {
+public class RelEngPlugin extends AbstractUIPlugin implements IStartup {
public static final String ID = "org.eclipse.releng.tools"; //$NON-NLS-1$
public static final String MAP_PROJECT_NAME = Messages.getString("RelEngPlugin.1"); //$NON-NLS-1$
public static final String MAP_FOLDER = Messages.getString("RelEngPlugin.2"); //$NON-NLS-1$
private static final String BINARY_REPOSITORY_PROVIDER_CLASS_NAME= "org.eclipse.pde.internal.core.BinaryRepositoryProvider"; //$NON-NLS-1$
+ PomVersionErrorReporter fPomReporter = new PomVersionErrorReporter();
//The shared instance.
private static RelEngPlugin plugin;
@@ -57,6 +65,33 @@ public class RelEngPlugin extends AbstractUIPlugin {
}
}
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ IEclipsePreferences node = InstanceScope.INSTANCE.getNode(ID);
+ if(node != null) {
+ node.addPreferenceChangeListener(fPomReporter);
+ String severity = getPreferenceStore().getString(IPomVersionConstants.POM_VERSION_ERROR_LEVEL);
+ if(!IPomVersionConstants.VALUE_IGNORE.equals(severity)) {
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(fPomReporter, IResourceChangeEvent.POST_BUILD);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ IEclipsePreferences node = InstanceScope.INSTANCE.getNode(ID);
+ if(node != null) {
+ node.removePreferenceChangeListener(fPomReporter);
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(fPomReporter);
+ }
+ super.stop(context);
+ }
+
/**
* Returns the shared instance.
*/
@@ -155,6 +190,12 @@ public class RelEngPlugin extends AbstractUIPlugin {
return provider != null && !BINARY_REPOSITORY_PROVIDER_CLASS_NAME.equals(provider.getClass().getName());
}
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IStartup#earlyStartup()
+ */
+ public void earlyStartup() {
+ }
+
/**
* The following code is a sample of how to assign a
* RelEng nature to a project. This only ever needed
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/IPomVersionConstants.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/IPomVersionConstants.java
index 10360f2..da33349 100644
--- a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/IPomVersionConstants.java
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/IPomVersionConstants.java
@@ -21,7 +21,7 @@ public interface IPomVersionConstants {
* The marker type id for POM version problems specified in the markers extension.
* Value is: <code>org.eclipse.releng.tools.pomVersionProblem</code>
*/
- public final static String PROBLEM_MARKER_TYPE = RelEngPlugin.ID + "pomVersionProblem"; //$NON-NLS-1$
+ public final static String PROBLEM_MARKER_TYPE = RelEngPlugin.ID + ".pomVersionProblem"; //$NON-NLS-1$
/**
* String attribute stored in the problem marker for the correct version that should be in the POM file
@@ -32,7 +32,7 @@ public interface IPomVersionConstants {
* Preference setting that stores the severity level for pom version problem markers.
* Preference value must be a string and one of {@link #VALUE_ERROR}, {@link #VALUE_WARNING} or {@link #VALUE_IGNORE}.
*/
- public final static String POM_VERSION_ERROR_LEVEL = RelEngPlugin.ID + "invalidPomVersionErrorLevel"; //$NON-NLS-1$
+ public final static String POM_VERSION_ERROR_LEVEL = RelEngPlugin.ID + ".invalidPomVersionErrorLevel"; //$NON-NLS-1$
/**
* Constant representing the preference value 'ignore'.
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/Messages.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/Messages.java
new file mode 100644
index 0000000..c10ffe8
--- /dev/null
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/Messages.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.releng.tools.pomversion;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ *
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.releng.tools.pomversion.messages"; //$NON-NLS-1$
+ public static String PomVersionErrorReporter_pom_version_error_marker_message;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/PomVersionBuilder.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/PomVersionBuilder.java
deleted file mode 100644
index b0b050c..0000000
--- a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/PomVersionBuilder.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 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.releng.tools.pomversion;
-
-import java.util.Map;
-import java.util.jar.JarFile;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IResourceDeltaVisitor;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
-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.core.runtime.SubMonitor;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.releng.tools.RelEngPlugin;
-
-/**
- * Builder for creating POM version problems
- */
-public class PomVersionBuilder extends IncrementalProjectBuilder {
-
- /**
- * Project relative path to the pom.xml file
- */
- public static final IPath POM_PATH = new Path("pom.xml"); //$NON-NLS-1$
-
- /**
- * Project relative path to the manifest file.
- */
- public static final IPath MANIFEST_PATH = new Path(JarFile.MANIFEST_NAME);
-
- /* (non-Javadoc)
- * @see org.eclipse.core.resources.IncrementalProjectBuilder#build(int, java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
- */
- protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
- if (!getProject().isAccessible()) {
- return null;
- }
-
- if (kind == FULL_BUILD) {
- fullBuild(monitor);
- } else {
- IResourceDelta delta = getDelta(getProject());
- if (delta == null) {
- fullBuild(monitor);
- } else {
- incrementalBuild(delta, monitor);
- }
- }
- return null;
- }
-
- private void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) {
- PomResourceDeltaVisitor visitor = new PomResourceDeltaVisitor();
- try {
- delta.accept(visitor);
- } catch (CoreException e) {
- RelEngPlugin.log(e);
- }
- if (visitor.doBuild()){
- fullBuild(monitor);
- }
- }
-
- private void fullBuild(IProgressMonitor monitor) {
- IProject project = getProject();
- SubMonitor localMonitor = SubMonitor.convert(monitor, NLS.bind("Comparing POM and plug-in version in {0}", project.getName()), 10);
- IFile pomFile = project.getFile(POM_PATH);
- IFile manifestFile = project.getFile(MANIFEST_PATH);
- if (pomFile.exists() && manifestFile.exists()){
- PomVersionErrorReporter reporter = new PomVersionErrorReporter(manifestFile, pomFile);
- reporter.validate(localMonitor);
- }
- localMonitor.done();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.core.resources.IncrementalProjectBuilder#clean(org.eclipse.core.runtime.IProgressMonitor)
- */
- protected void clean(IProgressMonitor monitor) throws CoreException {
- getProject().deleteMarkers(IPomVersionConstants.PROBLEM_MARKER_TYPE, false, IResource.DEPTH_INFINITE);
- }
-
- private class PomResourceDeltaVisitor implements IResourceDeltaVisitor {
- private boolean build;
-
- public boolean visit(IResourceDelta delta) {
- build = false;
- if (delta != null) {
- int kind = delta.getKind();
- // A file being removed doesn't affect the pom version check (markers are already cleaned)
- if (kind == IResourceDelta.REMOVED) {
- return false;
- }
-
- IResource resource = delta.getResource();
- // by ignoring derived resources we should scale a bit better.
- if (resource.isDerived())
- return false;
- if (resource.getType() == IResource.FILE) {
- IFile file = (IFile) resource;
- IFile pomFile = file.getProject().getFile(POM_PATH);
- if (file.equals(pomFile)){
- build = true;
- return false;
- }
- IFile manifestFile = file.getProject().getFile(MANIFEST_PATH);
- if (file.equals(manifestFile)){
- build = true;
- return false;
- }
- return false;
- }
- }
- return true;
- }
-
- /**
- * @return whether the delta contained a file requiring a build
- */
- public boolean doBuild() {
- return build;
- }
- }
-
-}
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/PomVersionErrorReporter.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/PomVersionErrorReporter.java
index c24bdff..15e7e6d 100644
--- a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/PomVersionErrorReporter.java
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/PomVersionErrorReporter.java
@@ -10,7 +10,11 @@
*******************************************************************************/
package org.eclipse.releng.tools.pomversion;
+import java.io.IOException;
+import java.util.HashMap;
import java.util.Stack;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
@@ -21,17 +25,24 @@ import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+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.IProgressMonitor;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.SubMonitor;
-import org.eclipse.core.runtime.preferences.IPreferencesService;
-import org.eclipse.core.runtime.preferences.IScopeContext;
+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.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.osgi.util.NLS;
import org.eclipse.releng.tools.RelEngPlugin;
+import org.eclipse.ui.texteditor.MarkerUtilities;
import org.osgi.framework.Version;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
@@ -43,87 +54,92 @@ import org.xml.sax.helpers.DefaultHandler;
* version specified in pom.xml matches the bundle version.
*
*/
-public class PomVersionErrorReporter {
+public class PomVersionErrorReporter implements IResourceChangeListener, IEclipsePreferences.IPreferenceChangeListener {
- 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$
-
- private SAXParserFactory parserFactory = SAXParserFactory.newInstance();
- private String pomVersionSeverity;
-
- private IFile manifestFile;
- private IFile pomFile;
-
- public PomVersionErrorReporter(IFile manifest, IFile pom) {
- manifestFile = manifest;
- pomFile = pom;
- }
-
- protected void validate(IProgressMonitor monitor) {
- SubMonitor subMon = SubMonitor.convert(monitor, 10);
- try {
- if (subMon.isCanceled()) {
- return;
- }
- if (!manifestFile.exists() || !pomFile.exists()){
- return;
- }
-
- IPreferencesService service = Platform.getPreferencesService();
- pomVersionSeverity = service.getString(RelEngPlugin.ID, IPomVersionConstants.POM_VERSION_ERROR_LEVEL, IPomVersionConstants.VALUE_IGNORE, new IScopeContext[] {new ProjectScope(manifestFile.getProject())});
- if (pomVersionSeverity == IPomVersionConstants.VALUE_IGNORE) {
- return;
- }
-
- // Get the manifest version
- Version bundleVersion = Version.emptyVersion;
-
- // Compare it to the pom file version
- try {
- SAXParser parser = parserFactory.newSAXParser();
- PomVersionHandler handler = new PomVersionHandler(pomFile, bundleVersion);
- parser.parse(pomFile.getContents(), handler);
- } catch (Exception e1) {
- // Ignored, if there is a problem with the pom file don't create a marker
- }
-
- } finally {
- subMon.done();
- if (monitor != null) {
- monitor.done();
- }
- }
-
- }
+ class PomResourceDeltaVisitor implements IResourceDeltaVisitor {
- private void reportMarker(String message, int lineNumber, int charStart, int charEnd, String correctedVersion) {
- try {
- IMarker marker = pomFile.createMarker(IPomVersionConstants.PROBLEM_MARKER_TYPE);
- marker.setAttribute(IMarker.MESSAGE, message);
- if (pomVersionSeverity != null && pomVersionSeverity.equals(IPomVersionConstants.VALUE_WARNING)){
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
- } else {
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
- }
- if (lineNumber == -1)
- lineNumber = 1;
- marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
- marker.setAttribute(IMarker.CHAR_START, charStart);
- marker.setAttribute(IMarker.CHAR_END, charEnd);
- marker.setAttribute(IPomVersionConstants.POM_CORRECT_VERSION, correctedVersion);
- } catch (CoreException e){
- RelEngPlugin.log(e);
+ public boolean visit(IResourceDelta delta) {
+ if (delta != null) {
+ IResource resource = delta.getResource();
+ switch(resource.getType()) {
+ case IResource.PROJECT: {
+ //Should we not care about non-plugin projects?
+ IProject project = (IProject) resource;
+ try {
+ if(project.getDescription().hasNature("org.eclipse.pde.PluginNature")) { //$NON-NLS-1$
+ if((delta.getFlags() & IResourceDelta.OPEN) > 0) {
+ validate(project);
+ return false;
+ }
+ return true;
+ }
+ }
+ catch(CoreException ce) {
+ RelEngPlugin.log(ce);
+ }
+ return false;
+ }
+ case IResource.ROOT:
+ case IResource.FOLDER: {
+ return true;
+ }
+ case IResource.FILE: {
+ switch(delta.getKind()) {
+ case IResourceDelta.REMOVED: {
+ //if manifest removed, clean up markers
+ if(resource.getProjectRelativePath().equals(MANIFEST_PATH)) {
+ //manifest content changed
+ IProject p = resource.getProject();
+ if(p.isAccessible()) {
+ cleanMarkers(p);
+ }
+ }
+ break;
+ }
+ case IResourceDelta.ADDED: {
+ //if the POM or manifest has been added scan them
+ if(resource.getProjectRelativePath().equals(MANIFEST_PATH) ||
+ resource.getProjectRelativePath().equals(POM_PATH)) {
+ validate(resource.getProject());
+ }
+ break;
+ }
+ case IResourceDelta.CHANGED: {
+ //if the content has changed clean + scan
+ if((delta.getFlags() & IResourceDelta.CONTENT) > 0) {
+ if(resource.getProjectRelativePath().equals(MANIFEST_PATH) ||
+ resource.getProjectRelativePath().equals(POM_PATH)) {
+ validate(resource.getProject());
+ }
+ }
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+ return false;
+ }
+ }
+ }
+ return false;
}
}
-
+
+ /**
+ * XML parsing handler to check the POM version infos
+ */
class PomVersionHandler extends DefaultHandler {
private Version bundleVersion;
private Stack elements = new Stack();
private boolean checkVersion = false;
private Locator locator;
+ IFile pom = null;
+ String severity = null;
- public PomVersionHandler(IFile file, Version bundleVersion) {
+ public PomVersionHandler(IFile file, Version bundleVersion, String pref) {
+ pom = file;
+ severity = pref;
this.bundleVersion = bundleVersion;
}
@@ -149,6 +165,7 @@ public class PomVersionErrorReporter {
checkVersion = false;
// Compare the versions
String versionString = new String(ch, start, length);
+ String origVer = versionString;
try {
// Remove snapshot suffix
int index = versionString.indexOf(SNAPSHOT_SUFFIX);
@@ -168,11 +185,20 @@ public class PomVersionErrorReporter {
try {
// Need to create a document to calculate the markers charstart and charend
- IDocument doc = createDocument(pomFile);
- int offset = doc.getLineOffset(locator.getLineNumber() - 1); // locator lines start at 1
- int charEnd = offset + locator.getColumnNumber() - 1; // returns column at end of character string, columns start at 1
- int charStart = charEnd - length;
- reportMarker(NLS.bind("POM artifact version {0} does not match bundle version {1}", pomVersion2.toString(), bundleVersion2.toString()), locator.getLineNumber(), charStart, charEnd, correctedVersion);
+ IDocument doc = createDocument(pom);
+ int lineOffset = doc.getLineOffset(locator.getLineNumber() - 1); // locator lines start at 1
+ int linLength = doc.getLineLength(locator.getLineNumber() - 1);
+ String str = doc.get(lineOffset, linLength);
+ 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()),
+ locator.getLineNumber(),
+ charStart,
+ charEnd,
+ correctedVersion,
+ pom,
+ severity);
} catch (BadLocationException e) {
RelEngPlugin.log(e);
}
@@ -184,6 +210,128 @@ public class PomVersionErrorReporter {
}
}
+ /**
+ * Project relative path to the pom.xml file
+ */
+ public static final IPath POM_PATH = new Path("pom.xml"); //$NON-NLS-1$
+
+ /**
+ * Project relative path to the manifest file.
+ */
+ public static final IPath MANIFEST_PATH = new Path(JarFile.MANIFEST_NAME);
+ 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$
+
+
+ /**
+ * Clean up all markers
+ *
+ * @param project
+ */
+ void cleanMarkers(IResource resource) {
+ try {
+ resource.deleteMarkers(IPomVersionConstants.PROBLEM_MARKER_TYPE, false, IResource.DEPTH_INFINITE);
+ }
+ catch(CoreException e) {
+ RelEngPlugin.log(e);
+ }
+ }
+
+ /**
+ * Validates the version in the Manifest.MF file against the version in the <code>pom.xml</code> file
+ *
+ * @param project
+ * @param severity
+ */
+ public void validate(IProject project) {
+ if(project == null || !project.isAccessible()) {
+ return;
+ }
+ //clean up existing markers
+ cleanMarkers(project);
+
+ String severity = RelEngPlugin.getPlugin().getPreferenceStore().getString(IPomVersionConstants.POM_VERSION_ERROR_LEVEL);
+ 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 {
+ Manifest mani = new Manifest(manifest.getContents());
+ java.util.jar.Attributes attributes = mani.getMainAttributes();
+ String ver = attributes.getValue("Bundle-Version"); //$NON-NLS-1$
+ if(ver == null) {
+ return;
+ }
+ bundleVersion = new Version(ver);
+ } catch (IOException e) {
+ RelEngPlugin.log(e);
+ return;
+ } catch (CoreException e) {
+ RelEngPlugin.log(e);
+ 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 e1) {
+ // Ignored, if there is a problem with the POM file don't create a marker
+ }
+ }
+
+ /**
+ * Creates a new POM version problem marker with the given attributes
+ * @param message the message for the marker
+ * @param lineNumber the line number of the problem
+ * @param charStart the starting character offset
+ * @param charEnd the ending character offset
+ * @param correctedVersion the correct version to be inserted
+ * @param pom the handle to the POM file
+ * @param severity the severity of the marker to create
+ */
+ void reportMarker(String message, int lineNumber, int charStart, int charEnd, String correctedVersion, IFile pom, String severity) {
+ try {
+ HashMap attributes = new HashMap();
+ attributes.put(IMarker.MESSAGE, message);
+ if (severity.equals(IPomVersionConstants.VALUE_WARNING)){
+ attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
+ } else {
+ attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
+ }
+ if (lineNumber == -1) {
+ lineNumber = 1;
+ }
+ attributes.put(IMarker.LINE_NUMBER, new Integer(lineNumber));
+ attributes.put(IMarker.CHAR_START, new Integer(charStart));
+ attributes.put(IMarker.CHAR_END, new Integer(charEnd));
+ attributes.put(IPomVersionConstants.POM_CORRECT_VERSION, correctedVersion);
+ MarkerUtilities.createMarker(pom, attributes, IPomVersionConstants.PROBLEM_MARKER_TYPE);
+ } catch (CoreException e){
+ RelEngPlugin.log(e);
+ }
+ }
+
+ /**
+ * Creates a new {@link IDocument} for the given {@link IFile}. <code>null</code>
+ * is returned if the {@link IFile} does not exist or the {@link ITextFileBufferManager}
+ * cannot be acquired or there was an exception trying to create the {@link IDocument}.
+ *
+ * @param file
+ * @return a new {@link IDocument} or <code>null</code>
+ */
protected IDocument createDocument(IFile file) {
if (!file.exists()) {
return null;
@@ -203,4 +351,43 @@ public class PomVersionErrorReporter {
}
return null;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
+ */
+ public void resourceChanged(IResourceChangeEvent event) {
+ IResourceDelta delta = event.getDelta();
+ if(delta != null) {
+ final PomResourceDeltaVisitor visitor = new PomResourceDeltaVisitor();
+ try {
+ delta.accept(visitor);
+ } catch (CoreException e) {
+ RelEngPlugin.log(e);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
+ */
+ public void preferenceChange(PreferenceChangeEvent event) {
+ if(IPomVersionConstants.POM_VERSION_ERROR_LEVEL.equals(event.getKey())) {
+ final String severity = (String) event.getNewValue();
+ if(severity != null) {
+ if(IPomVersionConstants.VALUE_IGNORE.equals(severity)) {
+ //we turned it off
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ }
+ else if(IPomVersionConstants.VALUE_IGNORE.equals(event.getOldValue())) {
+ // we turned it on
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_BUILD);
+ }
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IProject[] projects = root.getProjects();
+ for (int i = 0; i < projects.length; i++) {
+ validate(projects[i]);
+ }
+ }
+ }
+ }
}
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/messages.properties b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/messages.properties
new file mode 100644
index 0000000..9d40048
--- /dev/null
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/pomversion/messages.properties
@@ -0,0 +1 @@
+PomVersionErrorReporter_pom_version_error_marker_message=POM artifact version {0} does not match bundle version {1}
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/Messages.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/Messages.java
new file mode 100644
index 0000000..ccae890
--- /dev/null
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/Messages.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.releng.tools.preferences;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ *
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.releng.tools.preferences.messages"; //$NON-NLS-1$
+ public static String PomErrorLevelBlock_mismatched_pom_versions_pref;
+ public static String PomVersionPreferencePage_pom_pref_message;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/PomErrorLevelBlock.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/PomErrorLevelBlock.java
index ce2190e..3059194 100644
--- a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/PomErrorLevelBlock.java
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/PomErrorLevelBlock.java
@@ -185,9 +185,9 @@ public class PomErrorLevelBlock extends ConfigurationBlock {
* Constant representing the severity values presented in the combo boxes for each option
*/
private static final String[] SEVERITIES_LABELS = {
- "Error",
- "Warning",
- "Ignore"
+ "Error", //$NON-NLS-1$
+ "Warning", //$NON-NLS-1$
+ "Ignore" //$NON-NLS-1$
};
/**
@@ -275,7 +275,7 @@ public class PomErrorLevelBlock extends ConfigurationBlock {
fMainComp.setLayout(gl);
fMainComp.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
fMainComp.setFont(parent.getFont());
- this.fCombo = createComboControl(fMainComp, "Mismatched plug-in and pom.xml version numbers", KEY_POM_VERSION_ERROR_LEVEL);
+ this.fCombo = createComboControl(fMainComp, Messages.PomErrorLevelBlock_mismatched_pom_versions_pref, KEY_POM_VERSION_ERROR_LEVEL);
Dialog.applyDialogFont(fMainComp);
return fMainComp;
}
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/PomVersionPreferencePage.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/PomVersionPreferencePage.java
index d97616a..7231d8e 100644
--- a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/PomVersionPreferencePage.java
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/PomVersionPreferencePage.java
@@ -51,7 +51,7 @@ public class PomVersionPreferencePage extends PreferencePage implements
GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
gd.widthHint = 400;
label.setLayoutData(gd);
- label.setText("The POM Version tool will compare the artifact version in a pom.xml file at the root of the project to the plug-in version in the manifest. If the two versions do not match a problem marker will be created. The severity of this problem can be configured on this page.");
+ label.setText(Messages.PomVersionPreferencePage_pom_pref_message);
label.setFont(comp.getFont());
block = new PomErrorLevelBlock((IWorkbenchPreferenceContainer)getContainer());
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/messages.properties b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/messages.properties
new file mode 100644
index 0000000..62514a8
--- /dev/null
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/preferences/messages.properties
@@ -0,0 +1,2 @@
+PomErrorLevelBlock_mismatched_pom_versions_pref=&Mismatched plug-in and pom.xml version numbers
+PomVersionPreferencePage_pom_pref_message=The POM Version tool will compare the artifact version in a pom.xml file at the root of the project to the plug-in version in the manifest. If the two versions do not match a problem marker will be created. The severity of this problem can be configured on this page. \ No newline at end of file