blob: 74a473b9f2b0b49cbd0f1865bbf1b173f5d487db (
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/*******************************************************************************
* Copyright (c) 2008-2013 Sonatype, Inc. 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:
* Sonatype, Inc. - initial API and implementation
* Red Hat, Inc. - refactored lifecycle mapping discovery out
*******************************************************************************/
package org.eclipse.m2e.core.ui.internal.wizards;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.MavenProjectInfo;
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
import org.eclipse.m2e.core.ui.internal.Messages;
import org.eclipse.m2e.core.ui.internal.WorkingSets;
import org.eclipse.m2e.core.ui.internal.actions.SelectionUtil;
/**
* Maven Import Wizard
*
* @author Eugene Kuleshov
*/
public class MavenImportWizard extends AbstractMavenProjectWizard implements IImportWizard {
//private static final Logger LOG = LoggerFactory.getLogger(MavenImportWizard.class);
private MavenImportWizardPage page;
private List<String> locations;
private boolean showLocation = true;
private boolean basedirRemameRequired = false;
private boolean initialized = false;
public MavenImportWizard() {
setNeedsProgressMonitor(true);
setWindowTitle(Messages.MavenImportWizard_title);
}
public MavenImportWizard(ProjectImportConfiguration importConfiguration, List<String> locations) {
this();
this.locations = locations;
this.showLocation = false;
}
public void setBasedirRemameRequired(boolean basedirRemameRequired) {
this.basedirRemameRequired = basedirRemameRequired;
}
public void init(IWorkbench workbench, IStructuredSelection selection) {
super.init(workbench, selection);
initialized = true;
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=341047
// prepopulate from workspace selection,
// allows convenient import of nested projects by right-click->import on a workspace project or folder
if(locations == null || locations.isEmpty()) {
IPath location = SelectionUtil.getSelectedLocation(selection);
if(location != null) {
locations = Collections.singletonList(location.toOSString());
}
}
}
public void addPages() {
if(!initialized) {
init(null, null);
}
page = new MavenImportWizardPage(importConfiguration);
page.setLocations(locations);
page.setShowLocation(showLocation);
page.setBasedirRemameRequired(basedirRemameRequired);
addPage(page);
}
public boolean performFinish() {
//mkleint: this sounds wrong.
if(!page.isPageComplete()) {
return false;
}
Collection<MavenProjectInfo> projects = getProjects();
List<IWorkingSet> workingSets = new ArrayList<IWorkingSet>(); // ignore any preselected working set
if(page.shouldCreateWorkingSet() && !projects.isEmpty()) {
IWorkingSet workingSet = WorkingSets.getOrCreateWorkingSet(page.getWorkingSetName());
if(!workingSets.contains(workingSet)) {
workingSets.add(workingSet);
}
}
ImportMavenProjectsJob job = new ImportMavenProjectsJob(projects, workingSets, importConfiguration);
job.setRule(MavenPlugin.getProjectConfigurationManager().getRule());
job.schedule();
return true;
}
public Collection<MavenProjectInfo> getProjects() {
return page.getProjects();
}
}
|