blob: e296703bac423ba532cb19fba5d44b13c19a3c2a (
plain) (
blame)
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
|
/*******************************************************************************
* Copyright (c) 2008-2010 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.core.ui.internal.actions;
import org.apache.maven.project.MavenProject;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.window.Window;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.core.IMavenConstants;
import org.eclipse.m2e.core.embedder.MavenModelManager;
import org.eclipse.m2e.core.index.IndexedArtifactFile;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.ui.internal.Messages;
import org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AddPluginAction extends MavenActionSupport implements IWorkbenchWindowActionDelegate {
private static final Logger log = LoggerFactory.getLogger(AddPluginAction.class);
public static final String ID = "org.eclipse.m2e.addPluginAction"; //$NON-NLS-1$
public void run(IAction action) {
IFile file = getPomFileFromPomEditorOrViewSelection();
if(file == null) {
return;
}
MavenProject mp = null;
IProject prj = file.getProject();
if (prj != null && IMavenConstants.POM_FILE_NAME.equals(file.getProjectRelativePath().toString())) {
IMavenProjectFacade facade = MavenPlugin.getDefault().getMavenProjectManager().getProject(prj);
if (facade != null) {
mp = facade.getMavenProject();
}
}
MavenRepositorySearchDialog dialog = MavenRepositorySearchDialog.createSearchPluginDialog(getShell(), Messages.AddPluginAction_searchDialog_title,
mp, prj, false);
if(dialog.open() == Window.OK) {
final IndexedArtifactFile indexedArtifactFile = (IndexedArtifactFile) dialog.getFirstResult();
if(indexedArtifactFile != null) {
try {
MavenModelManager modelManager = MavenPlugin.getDefault().getMavenModelManager();
modelManager.updateProject(file, new MavenModelManager.PluginAdder( //
indexedArtifactFile.group, //
indexedArtifactFile.artifact, //
indexedArtifactFile.version));
} catch(Exception ex) {
log.error("Can't add plugin to " + file, ex);
}
}
}
}
public void dispose() {
}
public void init(IWorkbenchWindow window) {
}
}
|