1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*******************************************************************************
* 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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* Listens for Add project events and captures packaging and plugin types
*/
public class MavenListener implements IMavenProjectChangedListener {
private static final Logger log = LoggerFactory.getLogger( MavenListener.class );
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;
}
}
} catch (Exception e) {
log.error( e.getMessage(), e );
} finally {
subMon.done();
}
}
void stopListener() {
MavenPlugin.getDefault().getMavenProjectManagerImpl().removeMavenProjectChangedListener(this);
}
}
|