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
83
84
85
86
87
88
89
90
91
|
/*******************************************************************************
* 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.discovery;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.maven.plugin.MojoExecution;
import org.eclipse.equinox.internal.p2.discovery.Catalog;
import org.eclipse.equinox.internal.p2.discovery.DiscoveryCore;
import org.eclipse.equinox.internal.p2.discovery.compatibility.RemoteBundleDiscoveryStrategy;
import org.eclipse.equinox.internal.p2.discovery.model.Tag;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.m2e.internal.discovery.wizards.MavenCatalogConfiguration;
import org.eclipse.m2e.internal.discovery.wizards.MavenDiscoveryWizard;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.internal.Workbench;
@SuppressWarnings("restriction")
public class MavenDiscovery {
public static final Tag APPLICABLE_TAG = new Tag("applicable", Messages.MavenDiscovery_Wizard_Applicable_Tag); //$NON-NLS-1$
private static final Tag EXTRAS_TAG = new Tag("extras", Messages.MavenDiscovery_Wizard_ExtrasTag); //$NON-NLS-1$
private static final Tag LIFECYCLES_TAG = new Tag("lifecycles", Messages.MavenDiscovery_Wizard_LifecyclesTag); //$NON-NLS-1$
private static final Tag MAVEN_TAG = new Tag("maven", Messages.MavenDiscovery_Wizard_MavenTag); //$NON-NLS-1$
private static final String PATH = "http://download.eclipse.org/technology/m2e/discovery/directory.xml"; //$NON-NLS-1$
public static void launchWizard(final Collection<String> packagingTypes, final Collection<MojoExecution> mojos) {
final Display display = Workbench.getInstance().getDisplay();
display.asyncExec(new Runnable() {
public void run() {
launchWizard(display.getActiveShell(), packagingTypes, mojos);
}
});
}
public static void launchWizard(Shell shell, Collection<String> packagingTypes, Collection<MojoExecution> mojos) {
Catalog catalog = new Catalog();
catalog.setEnvironment(DiscoveryCore.createEnvironment());
catalog.setVerifyUpdateSiteAvailability(false);
// look for remote descriptor
RemoteBundleDiscoveryStrategy remoteDiscoveryStrategy = new RemoteBundleDiscoveryStrategy();
remoteDiscoveryStrategy.setDirectoryUrl(PATH);
catalog.getDiscoveryStrategies().add(remoteDiscoveryStrategy);
// Build the list of tags to show in the Wizard header
List<Tag> tags = new ArrayList<Tag>(3);
if(!packagingTypes.isEmpty()) {
tags.add(APPLICABLE_TAG);
}
tags.add(EXTRAS_TAG);
tags.add(LIFECYCLES_TAG);
tags.add(MAVEN_TAG);
catalog.setTags(tags);
// Create configuration for the catalog
MavenCatalogConfiguration configuration = new MavenCatalogConfiguration();
configuration.setShowTagFilter(true);
if(!packagingTypes.isEmpty()) {
tags = new ArrayList<Tag>(1);
tags.add(APPLICABLE_TAG);
configuration.setSelectedTags(tags);
} else {
configuration.setSelectedTags(tags);
}
configuration.setShowInstalledFilter(false);
configuration.setSelectedPackagingTypes(packagingTypes);
configuration.setSelectedMojos(mojos);
MavenDiscoveryWizard wizard = new MavenDiscoveryWizard(catalog, configuration);
WizardDialog dialog = new WizardDialog(shell, wizard);
dialog.open();
}
}
|