use of org.eclipse.m2e.core.ui.internal.archetype.MavenArchetype in project m2e-core by eclipse-m2e.
the class MavenProjectWizard method performFinish.
/**
* To perform the actual project creation, an operation is created and run using this wizard as execution context.
* That way, messages about the progress of the project creation are displayed inside the wizard.
*/
@Override
public boolean performFinish() {
// First of all, we extract all the information from the wizard pages.
// Note that this should not be done inside the operation we will run
// since many of the wizard pages' methods can only be invoked from within
// the SWT event dispatcher thread. However, the operation spawns a new
// separate thread to perform the actual work, i.e. accessing SWT elements
// from within that thread would lead to an exception.
// final IProject project = locationPage.getProjectHandle();
// final String projectName = locationPage.getProjectName();
// Get the location where to create the project. For some reason, when using
// the default workspace location for a project, we have to pass null
// instead of the actual location.
final Model model = getModel();
final String projectName = ProjectConfigurationManager.getProjectName(importConfiguration, model);
IStatus nameStatus = validateProjectName(importConfiguration, model);
if (!nameStatus.isOK()) {
MessageDialog.openError(getShell(), NLS.bind(Messages.wizardProjectJobFailed, projectName), nameStatus.getMessage());
return false;
}
final IPath location = locationPage.isInWorkspace() ? null : locationPage.getLocationPath();
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IProject project = root.getProject(projectName);
boolean pomExists = (locationPage.isInWorkspace() ? root.getLocation().append(project.getName()) : location).append(IMavenConstants.POM_FILE_NAME).toFile().exists();
if (pomExists) {
MessageDialog.openError(getShell(), NLS.bind(Messages.wizardProjectJobFailed, projectName), Messages.wizardProjectErrorPomAlreadyExists);
return false;
}
final AbstractCreateMavenProjectJob job;
if (simpleProject.getSelection()) {
final String[] folders = artifactPage.getFolders();
job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreatingProject, projectName)) {
@Override
protected List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException {
//
MavenPlugin.getProjectConfigurationManager().createSimpleProject(//
project, //
location, //
model, //
folders, importConfiguration, new MavenProjectWorkspaceAssigner(workingSets), monitor);
return Arrays.asList(project);
}
};
} else {
final Archetype archetype = archetypePage.getArchetype();
final String groupId = model.getGroupId();
final String artifactId = model.getArtifactId();
final String version = model.getVersion();
final String javaPackage = parametersPage.getJavaPackage();
final Properties properties = parametersPage.getProperties();
job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreating, archetype.getArtifactId())) {
@Override
protected List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException {
List<IProject> projects = M2EUIPluginActivator.getDefault().getArchetypeManager().getGenerator().createArchetypeProjects(location, //
new MavenArchetype(archetype), //
groupId, //
artifactId, //
version, //
javaPackage, properties, importConfiguration, new MavenProjectWorkspaceAssigner(workingSets), monitor);
return projects;
}
};
}
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
final IStatus result = event.getResult();
if (!result.isOK()) {
Display.getDefault().asyncExec(() -> //
MessageDialog.openError(//
getShell(), NLS.bind(Messages.wizardProjectJobFailed, projectName), result.getMessage()));
}
MappingDiscoveryJob discoveryJob = new MappingDiscoveryJob(job.getCreatedProjects());
discoveryJob.schedule();
}
});
job.setRule(MavenPlugin.getProjectConfigurationManager().getRule());
job.schedule();
return true;
}
use of org.eclipse.m2e.core.ui.internal.archetype.MavenArchetype in project m2e-core by eclipse-m2e.
the class MavenModuleWizard method performFinish.
/**
* Performs the "finish" action.
*/
@Override
public boolean performFinish() {
// First of all, we extract all the information from the wizard pages.
// Note that this should not be done inside the operation we will run
// since many of the wizard pages' methods can only be invoked from within
// the SWT event dispatcher thread. However, the operation spawns a new
// separate thread to perform the actual work, i.e. accessing SWT elements
// from within that thread would lead to an exception.
final String moduleName = parentPage.getModuleName();
// Get the location where to create the project. For some reason, when using
// the default workspace location for a project, we have to pass null
// instead of the actual location.
final IPath location = parentPage.getParentContainer().getLocation();
final IFile parentPom = parentPage.getPom();
Job job;
if (parentPage.isSimpleProject()) {
final Model model = artifactPage.getModel();
if (model.getParent() != null) {
Parent par = model.getParent();
String relPath = location.makeRelativeTo(location.append(moduleName)).toOSString();
if (!"..".equals(relPath)) {
// $NON-NLS-1$
par.setRelativePath(relPath);
}
// #335331 remove current model's version and groupId if equal to parent, to prevent showing a warning marker
if (par.getGroupId() != null && par.getGroupId().equals(model.getGroupId())) {
model.setGroupId(null);
}
if (par.getVersion() != null && par.getVersion().equals(model.getVersion())) {
model.setVersion(null);
}
}
final String[] folders = artifactPage.getFolders();
job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreatingProject, moduleName)) {
@Override
protected List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException {
setProperty(IProgressConstants.ACTION_PROPERTY, new OpenMavenConsoleAction());
String projectName = ProjectConfigurationManager.getProjectName(importConfiguration, model);
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
// XXX respect parent's setting for separate projects for modules
// XXX should run update sources on parent instead of creating new module project
MavenPlugin.getProjectConfigurationManager().createSimpleProject(project, location.append(moduleName), model, folders, importConfiguration, new MavenProjectWorkspaceAssigner(workingSets), monitor);
setModule(projectName);
return Arrays.asList(project);
}
};
} else {
Model model = parametersPage.getModel();
final Archetype archetype = archetypePage.getArchetype();
final String groupId = model.getGroupId();
final String artifactId = model.getArtifactId();
final String version = model.getVersion();
final String javaPackage = parametersPage.getJavaPackage();
final Properties properties = parametersPage.getProperties();
job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreating, archetype.getArtifactId())) {
@Override
protected List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException {
List<IProject> projects = M2EUIPluginActivator.getDefault().getArchetypeManager().getGenerator().createArchetypeProjects(location, //
new MavenArchetype(archetype), //
groupId, //
artifactId, //
version, //
javaPackage, properties, importConfiguration, new MavenProjectWorkspaceAssigner(workingSets), monitor);
setModule(moduleName);
return projects;
}
};
}
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
final IStatus result = event.getResult();
if (result.isOK()) {
if (!isEditor) {
// add the <module> element to the parent pom
try {
performOnDOMDocument(new OperationTuple(parentPom, (Operation) document -> {
Element root = document.getDocumentElement();
Element modules = getChild(root, "modules");
if (findChild(modules, "module", textEquals(moduleName)) == null) {
format(createElementWithText(modules, "module", moduleName));
}
}));
} catch (Exception e) {
// $NON-NLS-1$
LOG.error("Cannot add module to parent POM", e);
}
}
} else {
Display.getDefault().asyncExec(() -> //
MessageDialog.openError(//
getShell(), //
NLS.bind(Messages.wizardProjectJobFailed, moduleName), result.getMessage()));
}
}
});
job.setRule(MavenPlugin.getProjectConfigurationManager().getRule());
job.schedule();
if (isEditor) {
try {
job.join();
} catch (InterruptedException ex) {
// ignore
}
}
return true;
}
Aggregations