From 21e4d0cf71dfab91a0baedaefc73a74aae1ef983 Mon Sep 17 00:00:00 2001 From: Sergei Vorobyov Date: Thu, 26 Jun 2025 12:20:20 +0200 Subject: [PATCH] [NPW] cleanup: create project/module directory inside NewProjectWizardBaseStep The base NPW step specifies, prepares and validates project location. Therefore it should ensure that the project/module directory is created. Also, all project file and scripts generators should ensure that the parent directories is created. Because the IO cannot be protected from external modification. And the NPW API cannot guarantee that project/module directory is exists during the whole project/module creation process. GitOrigin-RevId: e1332ce096846629c6c86234032fbee142dbb7e5 --- platform/platform-api/resources/messages/UIBundle.properties | 1 + .../src/com/intellij/ide/wizard/NewProjectWizardBaseStep.kt | 4 ++++ .../service/project/wizard/AbstractGradleModuleBuilder.java | 2 -- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/platform/platform-api/resources/messages/UIBundle.properties b/platform/platform-api/resources/messages/UIBundle.properties index e8dea453cc95..96c01494409a 100644 --- a/platform/platform-api/resources/messages/UIBundle.properties +++ b/platform/platform-api/resources/messages/UIBundle.properties @@ -333,6 +333,7 @@ label.project.wizard.new.assets.step.generate.sources.progress=Generating projec error.project.wizard.new.project.title=New {0,choice,0#Module|1#Project} Wizard Error error.project.wizard.new.project.sample.code=Unable to generate {0,choice,0#module|1#project} sources error.project.wizard.new.project.git=Unable to create a Git repository +error.project.wizard.new.project.directory=Unable to create a {0,choice,0#module|1#project} directory kotlin.dsl.validation.missing.value=Field must be set kotlin.dsl.validation.no.whitespaces=Whitespaces are not allowed here diff --git a/platform/platform-impl/src/com/intellij/ide/wizard/NewProjectWizardBaseStep.kt b/platform/platform-impl/src/com/intellij/ide/wizard/NewProjectWizardBaseStep.kt index 927b6a4104fa..21e979a36ca0 100644 --- a/platform/platform-impl/src/com/intellij/ide/wizard/NewProjectWizardBaseStep.kt +++ b/platform/platform-impl/src/com/intellij/ide/wizard/NewProjectWizardBaseStep.kt @@ -33,6 +33,7 @@ import com.intellij.ui.UIBundle import com.intellij.ui.dsl.builder.* import com.intellij.ui.util.getTextWidth import com.intellij.util.applyIf +import java.nio.file.Files import java.nio.file.Path import kotlin.io.path.name @@ -141,6 +142,9 @@ class NewProjectWizardBaseStep(parent: NewProjectWizardStep) : AbstractNewProjec } override fun setupProject(project: Project) { + setupProjectSafe(project, UIBundle.message("error.project.wizard.new.project.directory", context.isCreatingNewProjectInt)) { + Files.createDirectories(Path.of(path).resolve(name)) + } if (context.isCreatingNewProject) { invokeAndWaitIfNeeded { runWriteAction { diff --git a/plugins/gradle/java/src/service/project/wizard/AbstractGradleModuleBuilder.java b/plugins/gradle/java/src/service/project/wizard/AbstractGradleModuleBuilder.java index 2887ed4e603d..efe4f9568b33 100644 --- a/plugins/gradle/java/src/service/project/wizard/AbstractGradleModuleBuilder.java +++ b/plugins/gradle/java/src/service/project/wizard/AbstractGradleModuleBuilder.java @@ -43,7 +43,6 @@ import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.util.io.NioPathUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.*; @@ -149,7 +148,6 @@ public abstract class AbstractGradleModuleBuilder extends AbstractExternalModule return; } File contentRootDir = new File(contentEntryPath); - FileUtilRt.createDirectory(contentRootDir); LocalFileSystem fileSystem = LocalFileSystem.getInstance(); VirtualFile modelContentRootDir = fileSystem.refreshAndFindFileByIoFile(contentRootDir); if (modelContentRootDir == null) {