summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMatthew Piggott2011-02-15 12:48:41 (EST)
committer Pascal Rapicault2011-02-15 12:50:00 (EST)
commit00f8f1ecd056757d0439421e7b5f345ba68fe1ec (patch)
treea1450824a767a627bb581a1a0091898a123fe472
parent5b5f880781053a7afb763f4cd4fd85377e44c753 (diff)
downloadm2e-core-00f8f1ecd056757d0439421e7b5f345ba68fe1ec.zip
m2e-core-00f8f1ecd056757d0439421e7b5f345ba68fe1ec.tar.gz
m2e-core-00f8f1ecd056757d0439421e7b5f345ba68fe1ec.tar.bz2
Bug 337166 - Avoid early activation of m2e
-rw-r--r--org.eclipse.m2e.usagedata/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.m2e.usagedata/src/org/eclipse/m2e/internal/udc/Activator.java78
-rw-r--r--org.eclipse.m2e.usagedata/src/org/eclipse/m2e/internal/udc/MavenListener.java77
-rw-r--r--org.eclipse.m2e.usagedata/src/org/eclipse/m2e/internal/udc/PomImportMonitor.java78
4 files changed, 175 insertions, 62 deletions
diff --git a/org.eclipse.m2e.usagedata/META-INF/MANIFEST.MF b/org.eclipse.m2e.usagedata/META-INF/MANIFEST.MF
index 65743ac..b65d04d 100644
--- a/org.eclipse.m2e.usagedata/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.usagedata/META-INF/MANIFEST.MF
@@ -5,6 +5,8 @@ Bundle-SymbolicName: org.eclipse.m2e.usagedata;singleton:=true
Bundle-Version: 0.13.0.qualifier
Require-Bundle: org.eclipse.epp.usagedata.gathering;resolution:=optional,
org.eclipse.m2e.core
-Import-Package: org.eclipse.core.runtime
+Import-Package: org.eclipse.core.runtime,
+ org.osgi.framework
Bundle-RequiredExecutionEnvironment: J2SE-1.5,
JavaSE-1.6
+Export-Package: org.eclipse.m2e.internal.udc;x-internal:=true
diff --git a/org.eclipse.m2e.usagedata/src/org/eclipse/m2e/internal/udc/Activator.java b/org.eclipse.m2e.usagedata/src/org/eclipse/m2e/internal/udc/Activator.java
new file mode 100644
index 0000000..1fd9368
--- /dev/null
+++ b/org.eclipse.m2e.usagedata/src/org/eclipse/m2e/internal/udc/Activator.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Sonatype, Inc.
+ * 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:
+ * Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2e.internal.udc;
+
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+
+/*
+ * Listen for the maven core bundle starting to avoid early activation by the usage data collector
+ */
+public class Activator implements BundleActivator, BundleListener {
+
+ private static final String ORG_ECLIPSE_M2E_CORE = "org.eclipse.m2e.core"; //$NON-NLS-1$
+
+ private static Activator instance;
+
+ private volatile MavenListener listener;
+
+ private PomImportMonitor monitor;
+
+ private BundleContext context;
+
+ public void start(BundleContext context) throws Exception {
+ this.context = context;
+ instance = this;
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ context.removeBundleListener(this);
+ if (listener != null) {
+ listener.stopListener();
+ listener = null;
+ }
+ }
+
+ public void bundleChanged(BundleEvent event) {
+ if (event.getType() == BundleEvent.STARTED && ORG_ECLIPSE_M2E_CORE.equals(event.getBundle().getSymbolicName())) {
+ createListener();
+ // Don't care about future events so the listener can be removed
+ context.removeBundleListener(this);
+ }
+ }
+
+ static Activator getDefault() {
+ return instance;
+ }
+
+ void setMonitor(PomImportMonitor monitor) {
+ this.monitor = monitor;
+
+ // If the m2e core bundle is already active create listener for project
+ // changes, otherwise listen for bundle started events
+ Bundle b = Platform.getBundle(ORG_ECLIPSE_M2E_CORE);
+ if (b.getState() == Bundle.ACTIVE) {
+ createListener();
+ } else {
+ context.addBundleListener(this);
+ }
+ }
+
+ private synchronized void createListener() {
+ if (listener == null) {
+ listener = new MavenListener(monitor);
+ }
+ }
+}
diff --git a/org.eclipse.m2e.usagedata/src/org/eclipse/m2e/internal/udc/MavenListener.java b/org.eclipse.m2e.usagedata/src/org/eclipse/m2e/internal/udc/MavenListener.java
new file mode 100644
index 0000000..795f2e6
--- /dev/null
+++ b/org.eclipse.m2e.usagedata/src/org/eclipse/m2e/internal/udc/MavenListener.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Sonatype, Inc.
+ * 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:
+ * Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2e.internal.udc;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.project.IMavenProjectChangedListener;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.core.project.MavenProjectChangedEvent;
+import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
+
+/*
+ * Listens for Add project events and captures packaging and plugin types
+ */
+public class MavenListener implements IMavenProjectChangedListener {
+
+ private static final String SEPARATOR = ":"; //$NON-NLS-1$
+
+ private static final String PLUGINS = "m2e.plugins"; //$NON-NLS-1$
+
+ private static final String PACKAGING = "m2e.packaging"; //$NON-NLS-1$
+
+ private static final String VERSION = "0.13.0"; //$NON-NLS-1$
+
+ private static final String ID = "org.eclipse.m2e.core"; //$NON-NLS-1$
+
+ private PomImportMonitor udcMonitor;
+
+ MavenListener(PomImportMonitor udcMonitor) {
+ this.udcMonitor = udcMonitor;
+ MavenPlugin.getDefault().getMavenProjectManagerImpl().addMavenProjectChangedListener(this);
+ }
+
+ public void mavenProjectChanged(MavenProjectChangedEvent[] events, IProgressMonitor monitor) {
+ SubMonitor subMon = SubMonitor.convert(monitor, 2 * events.length);
+ try {
+ for (MavenProjectChangedEvent event : events) {
+ if (monitor.isCanceled()) {
+ return;
+ }
+ if (event.getKind() != MavenProjectChangedEvent.KIND_ADDED) {
+ continue;
+ }
+ IMavenProjectFacade facade = event.getMavenProject();
+ udcMonitor.recordEvent(facade.getPackaging(), PACKAGING, facade.getPackaging(), ID, VERSION);
+ subMon.worked(1);
+
+ if (facade.getMojoExecutionMapping() != null) {
+ for (MojoExecutionKey key : facade.getMojoExecutionMapping().keySet()) {
+ udcMonitor.recordEvent(key.getGoal() + SEPARATOR + key.getExecutionId() + SEPARATOR + key.getLifecyclePhase(), PLUGINS, key.getGroupId() + SEPARATOR + key.getArtifactId()
+ + SEPARATOR + key.getVersion(), ID, VERSION);
+ }
+ }
+ subMon.worked(1);
+
+ if (subMon.isCanceled()) {
+ return;
+ }
+ }
+ } finally {
+ subMon.done();
+ }
+ }
+
+ void stopListener() {
+ MavenPlugin.getDefault().getMavenProjectManagerImpl().removeMavenProjectChangedListener(this);
+ }
+}
diff --git a/org.eclipse.m2e.usagedata/src/org/eclipse/m2e/internal/udc/PomImportMonitor.java b/org.eclipse.m2e.usagedata/src/org/eclipse/m2e/internal/udc/PomImportMonitor.java
index 0e87d1c..0c182a5 100644
--- a/org.eclipse.m2e.usagedata/src/org/eclipse/m2e/internal/udc/PomImportMonitor.java
+++ b/org.eclipse.m2e.usagedata/src/org/eclipse/m2e/internal/udc/PomImportMonitor.java
@@ -10,75 +10,31 @@
*******************************************************************************/
package org.eclipse.m2e.internal.udc;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.epp.usagedata.internal.gathering.monitors.UsageMonitor;
import org.eclipse.epp.usagedata.internal.gathering.services.UsageDataService;
-import org.eclipse.m2e.core.MavenPlugin;
-import org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager;
-import org.eclipse.m2e.core.project.IMavenProjectChangedListener;
-import org.eclipse.m2e.core.project.IMavenProjectFacade;
-import org.eclipse.m2e.core.project.MavenProjectChangedEvent;
-import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
-
+/*
+ * Monitor for Usage Data Collector
+ */
@SuppressWarnings("restriction")
-public class PomImportMonitor implements UsageMonitor, IMavenProjectChangedListener {
-
- private static final String SEPARATOR = ":"; //$NON-NLS-1$
-
- private static final String PLUGINS = "m2e.plugins"; //$NON-NLS-1$
-
- private static final String PACKAGING = "m2e.packaging"; //$NON-NLS-1$
-
- private static final String VERSION = "0.13.0"; //$NON-NLS-1$
-
- private static final String ID = "org.eclipse.m2e.core"; //$NON-NLS-1$
-
- private UsageDataService usageDataService;
+public class PomImportMonitor implements UsageMonitor {
- private ProjectRegistryManager manager;
+ private UsageDataService usageDataService;
- public void startMonitoring(UsageDataService usageDataService) {
- this.usageDataService = usageDataService;
- manager = MavenPlugin.getDefault().getMavenProjectManagerImpl();
- manager.addMavenProjectChangedListener(this);
- }
+ public PomImportMonitor() {
+ Activator.getDefault().setMonitor(this);
+ }
- public void stopMonitoring() {
- usageDataService = null;
- manager.removeMavenProjectChangedListener(this);
- }
- public void mavenProjectChanged(MavenProjectChangedEvent[] events, IProgressMonitor monitor) {
- SubMonitor subMon = SubMonitor.convert(monitor, 2 * events.length);
- try {
- for(MavenProjectChangedEvent event : events) {
- if(monitor.isCanceled()) {
- return;
- }
- if(event.getKind() != MavenProjectChangedEvent.KIND_ADDED) {
- continue;
- }
- IMavenProjectFacade facade = event.getMavenProject();
- usageDataService.recordEvent(facade.getPackaging(), PACKAGING, facade.getPackaging(), ID, VERSION);
- subMon.worked(1);
+ public void startMonitoring(UsageDataService usageDataService) {
+ this.usageDataService = usageDataService;
+ }
- if(facade.getMojoExecutionMapping() != null) {
- for(MojoExecutionKey key : facade.getMojoExecutionMapping().keySet()) {
- usageDataService.recordEvent(
- key.getGoal() + SEPARATOR + key.getExecutionId() + SEPARATOR + key.getLifecyclePhase(), PLUGINS,
- key.getGroupId() + SEPARATOR + key.getArtifactId() + SEPARATOR + key.getVersion(), ID, VERSION);
- }
- }
- subMon.worked(1);
+ public void stopMonitoring() {
+ usageDataService = null;
+ }
- if(subMon.isCanceled()) {
- return;
- }
- }
- } finally {
- subMon.done();
- }
- }
+ void recordEvent(String what, String kind, String description, String bundleId, String bundleVersion) {
+ usageDataService.recordEvent(what, kind, description, bundleId, bundleVersion);
+ }
}