use of com.intellij.ide.util.projectWizard.ProjectBuilder in project intellij-community by JetBrains.
the class NewProjectUtil method doCreate.
private static Project doCreate(final AbstractProjectWizard dialog, @Nullable Project projectToClose) throws IOException {
final ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
final String projectFilePath = dialog.getNewProjectFilePath();
for (Project p : ProjectManager.getInstance().getOpenProjects()) {
if (ProjectUtil.isSameProject(projectFilePath, p)) {
ProjectUtil.focusProjectWindow(p, false);
return null;
}
}
final ProjectBuilder projectBuilder = dialog.getProjectBuilder();
try {
File projectDir = new File(projectFilePath).getParentFile();
LOG.assertTrue(projectDir != null, "Cannot create project in '" + projectFilePath + "': no parent file exists");
FileUtil.ensureExists(projectDir);
if (StorageScheme.DIRECTORY_BASED == dialog.getStorageScheme()) {
FileUtil.ensureExists(new File(projectFilePath, Project.DIRECTORY_STORE_FOLDER));
}
final Project newProject;
if (projectBuilder == null || !projectBuilder.isUpdate()) {
String name = dialog.getProjectName();
newProject = projectBuilder == null ? projectManager.newProject(name, projectFilePath, true, false) : projectBuilder.createProject(name, projectFilePath);
} else {
newProject = projectToClose;
}
if (newProject == null)
return projectToClose;
final Sdk jdk = dialog.getNewProjectJdk();
if (jdk != null) {
CommandProcessor.getInstance().executeCommand(newProject, () -> ApplicationManager.getApplication().runWriteAction(() -> applyJdkToProject(newProject, jdk)), null, null);
}
final String compileOutput = dialog.getNewCompileOutput();
CommandProcessor.getInstance().executeCommand(newProject, () -> ApplicationManager.getApplication().runWriteAction(() -> {
String canonicalPath = compileOutput;
try {
canonicalPath = FileUtil.resolveShortWindowsName(compileOutput);
} catch (IOException e) {
//file doesn't exist
}
canonicalPath = FileUtil.toSystemIndependentName(canonicalPath);
CompilerProjectExtension.getInstance(newProject).setCompilerOutputUrl(VfsUtilCore.pathToUrl(canonicalPath));
}), null, null);
if (!ApplicationManager.getApplication().isUnitTestMode()) {
newProject.save();
}
if (projectBuilder != null && !projectBuilder.validate(projectToClose, newProject)) {
return projectToClose;
}
if (newProject != projectToClose && !ApplicationManager.getApplication().isUnitTestMode()) {
closePreviousProject(projectToClose);
}
if (projectBuilder != null) {
projectBuilder.commit(newProject, null, ModulesProvider.EMPTY_MODULES_PROVIDER);
}
final boolean need2OpenProjectStructure = projectBuilder == null || projectBuilder.isOpenProjectSettingsAfter();
StartupManager.getInstance(newProject).registerPostStartupActivity(() -> {
// ensure the dialog is shown after all startup activities are done
ApplicationManager.getApplication().invokeLater(() -> {
if (newProject.isDisposed() || ApplicationManager.getApplication().isUnitTestMode())
return;
if (need2OpenProjectStructure) {
ModulesConfigurator.showDialog(newProject, null, null);
}
ApplicationManager.getApplication().invokeLater(() -> {
if (newProject.isDisposed())
return;
final ToolWindow toolWindow = ToolWindowManager.getInstance(newProject).getToolWindow(ToolWindowId.PROJECT_VIEW);
if (toolWindow != null) {
toolWindow.activate(null);
}
}, ModalityState.NON_MODAL);
}, ModalityState.NON_MODAL);
});
if (newProject != projectToClose) {
ProjectUtil.updateLastProjectLocation(projectFilePath);
if (WindowManager.getInstance().isFullScreenSupportedInCurrentOS()) {
IdeFocusManager instance = IdeFocusManager.findInstance();
IdeFrame lastFocusedFrame = instance.getLastFocusedFrame();
if (lastFocusedFrame instanceof IdeFrameEx) {
boolean fullScreen = ((IdeFrameEx) lastFocusedFrame).isInFullScreen();
if (fullScreen) {
newProject.putUserData(IdeFrameImpl.SHOULD_OPEN_IN_FULL_SCREEN, Boolean.TRUE);
}
}
}
projectManager.openProject(newProject);
}
if (!ApplicationManager.getApplication().isUnitTestMode()) {
newProject.save();
}
return newProject;
} finally {
if (projectBuilder != null) {
projectBuilder.cleanup();
}
}
}
use of com.intellij.ide.util.projectWizard.ProjectBuilder in project intellij-community by JetBrains.
the class ModulesConfigurator method addModule.
@Nullable
public List<Module> addModule(Component parent, boolean anImport) {
if (myProject.isDefault())
return null;
final ProjectBuilder builder = runModuleWizard(parent, anImport);
if (builder != null) {
final List<Module> modules = new ArrayList<>();
final List<Module> committedModules;
if (builder instanceof ProjectImportBuilder<?>) {
final ModifiableArtifactModel artifactModel = ProjectStructureConfigurable.getInstance(myProject).getArtifactsStructureConfigurable().getModifiableArtifactModel();
committedModules = ((ProjectImportBuilder<?>) builder).commit(myProject, myModuleModel, this, artifactModel);
} else {
committedModules = builder.commit(myProject, myModuleModel, this);
}
if (committedModules != null) {
modules.addAll(committedModules);
}
ApplicationManager.getApplication().runWriteAction(() -> {
for (Module module : modules) {
getOrCreateModuleEditor(module);
}
});
return modules;
}
return null;
}
use of com.intellij.ide.util.projectWizard.ProjectBuilder in project intellij-community by JetBrains.
the class GradleProjectWizardTest method testGradleProject.
public void testGradleProject() throws Exception {
final String projectName = "testProject";
Project project = createProject(new Consumer<Step>() {
@Override
public void consume(Step step) {
if (step instanceof ProjectTypeStep) {
assertTrue(((ProjectTypeStep) step).setSelectedTemplate("Gradle", null));
List<ModuleWizardStep> steps = myWizard.getSequence().getSelectedSteps();
assertEquals(5, steps.size());
final ProjectBuilder projectBuilder = myWizard.getProjectBuilder();
assertInstanceOf(projectBuilder, GradleModuleBuilder.class);
((GradleModuleBuilder) projectBuilder).setName(projectName);
}
}
});
assertEquals(projectName, project.getName());
Module[] modules = ModuleManager.getInstance(project).getModules();
assertEquals(1, modules.length);
final Module module = modules[0];
assertTrue(ModuleRootManager.getInstance(module).isSdkInherited());
assertEquals(projectName, module.getName());
VirtualFile root = ProjectRootManager.getInstance(project).getContentRoots()[0];
VirtualFile settingsScript = VfsUtilCore.findRelativeFile("settings.gradle", root);
assertNotNull(settingsScript);
assertEquals(String.format("rootProject.name = '%s'\n\n", projectName), StringUtil.convertLineSeparators(VfsUtilCore.loadText(settingsScript)));
VirtualFile buildScript = VfsUtilCore.findRelativeFile("build.gradle", root);
assertNotNull(buildScript);
assertEquals("group '" + projectName + "'\n" + "version '1.0-SNAPSHOT'\n" + "\n" + "apply plugin: 'java'\n" + "\n" + "sourceCompatibility = 1.8\n" + "\n" + "repositories {\n" + " mavenCentral()\n" + "}\n" + "\n" + "dependencies {\n" + " testCompile group: 'junit', name: 'junit', version: '4.12'\n" + "}\n", StringUtil.convertLineSeparators(VfsUtilCore.loadText(buildScript)));
}
Aggregations