IRooInstall install = (useDefault ? RooCoreActivator.getDefault().getInstallManager()
.getDefaultRooInstall() : RooCoreActivator.getDefault().getInstallManager().getRooInstall(
rooInstall));
monitor.worked(1);
Bootstrap bootstrap = null;
try {
// Create project location
monitor.subTask("creating project location");
File projectFile = new File(new File(location), projectPage.getProjectName());
if (!projectFile.exists()) {
projectFile.mkdirs();
}
monitor.worked(2);
monitor.subTask("starting Spring Roo shell");
String javaVersion = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance");
String rooJavaVersion = (ROO_JAVA_VERSION_MAPPING.containsKey(javaVersion) ? ROO_JAVA_VERSION_MAPPING
.get(javaVersion)
: "6");
// Create Roo project by launching Roo and invoking the
// create project command
String projectLocation = projectFile.getCanonicalPath();
bootstrap = new Bootstrap(projectLocation, install.getHome(), install.getVersion(), new ProjectRefresher(null));
// Init Roo shell
bootstrap.start(new StyledTextAppender(shellPage.getRooShell()), projectPage.getProjectName());
monitor.worked(3);
ProjectType type = projectPage.getProjectType();
// Create project
monitor.subTask(String.format("execute Spring Roo '%s' command", type.getCommand()));
StringBuilder builder = new StringBuilder();
builder.append(type.getCommand());
builder.append(" --topLevelPackage ").append(projectPage.getPackageName());
if (type == ProjectType.PROJECT) {
builder.append(" --projectName ").append(projectPage.getProjectName());
builder.append(" --java ").append(rooJavaVersion);
if (RooUiUtil.isRoo120OrGreater(install)) {
builder.append(" --packaging ").append(packagingProvider);
}
}
else {
builder.append(" --description \"").append(projectPage.getDescription()).append("\"");
}
final String commandString = builder.toString();
Display.getDefault().asyncExec(new Runnable() {
public void run() {
shellPage.getRooShell().append(commandString + StyledTextAppender.NL);
}
});
bootstrap.execute(commandString);
// Shutdown Roo
bootstrap.shutdown();
bootstrap = null;
monitor.worked(4);
// Write our own .classpath file if M2E can't provide one for us
if (!DependencyManagementUtils.IS_M2ECLIPSE_PRESENT) {
monitor.subTask("configuring Eclipse project meta data");
// Setup Eclipse metadata
File classpathDescriptor = new File(projectFile, ".classpath");
FileWriter writer = new FileWriter(classpathDescriptor);
if (type == ProjectType.PROJECT) {
// For now, only Java projects & web projects
if (!RooUiUtil.isRoo120OrGreater(install) || "jar".equalsIgnoreCase(packagingProvider)
|| "war".equalsIgnoreCase(packagingProvider)) {
writer.write(CLASSPATH_FILE);
}
}
else {
// Add-on projects
writer.write(CLASSPATH_FILE);
}
writer.flush();
writer.close();
}
monitor.subTask("importing project into workspace");
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject project = workspace.getRoot().getProject(projectPage.getProjectName());
IProjectDescription desc = workspace.newProjectDescription(projectPage.getProjectName());
if (projectPage.isExternalProject()) {
desc.setLocation(new Path(projectLocation));
}
project.create(desc, new NullProgressMonitor());
project.open(0, new NullProgressMonitor());
project.setDescription(desc, new NullProgressMonitor());
if (type == ProjectType.PROJECT) {
if (!RooUiUtil.isRoo120OrGreater(install) || "jar".equalsIgnoreCase(packagingProvider)
|| "war".equalsIgnoreCase(packagingProvider)) {
// For now, only Java projects & web projects
SpringCoreUtils.addProjectBuilder(project, "org.eclipse.ajdt.core.ajbuilder", new NullProgressMonitor());
SpringCoreUtils.addProjectBuilder(project, SpringCore.BUILDER_ID, new NullProgressMonitor());
SpringCoreUtils.addProjectNature(project, JavaCore.NATURE_ID, new NullProgressMonitor());
SpringCoreUtils.addProjectNature(project, "org.eclipse.ajdt.ui.ajnature", new NullProgressMonitor());
}
SpringCoreUtils.addProjectNature(project, SpringCore.NATURE_ID, new NullProgressMonitor());
SpringCoreUtils.addProjectNature(project, RooCoreActivator.NATURE_ID, new NullProgressMonitor());
} else {
// Add-ons
SpringCoreUtils.addProjectBuilder(project, JavaCore.BUILDER_ID, new NullProgressMonitor());
SpringCoreUtils.addProjectNature(project, JavaCore.NATURE_ID, new NullProgressMonitor());
SpringCoreUtils.addProjectBuilder(project, SpringCore.BUILDER_ID, new NullProgressMonitor());
SpringCoreUtils.addProjectNature(project, SpringCore.NATURE_ID, new NullProgressMonitor());
}
SpringCorePreferences.getProjectPreferences(project, RooCoreActivator.PLUGIN_ID).putBoolean(
RooCoreActivator.PROJECT_PROPERTY_ID, useDefault);
SpringCorePreferences.getProjectPreferences(project, RooCoreActivator.PLUGIN_ID).putString(
RooCoreActivator.ROO_INSTALL_PROPERTY, rooInstall);
configureProjectUi(project);
if (DependencyManagementUtils.IS_M2ECLIPSE_PRESENT) {
DependencyManagementUtils.installDependencyManagement(project, dependencyManagement);
}
new OpenShellJob(project).schedule();
monitor.worked(6);
monitor.done();
}
catch (Throwable e) {
SpringCore.log(e);
}
finally {
if (bootstrap != null) {
// Shutdown Roo
try {
bootstrap.shutdown();
}
catch (Throwable e) {
}
}
}