From 7ffa411b1cf37fa7e28a3f1216b4cbe0ff45ec64 Mon Sep 17 00:00:00 2001 From: Konstantin Nisht Date: Wed, 30 Oct 2024 19:35:13 +0100 Subject: [PATCH] [eel] IJPL-165488: Use NIO in source root detection in NPW (cherry picked from commit c599899708204f1dfb7da5d9914d747f3b18240f) IJ-CR-148299 GitOrigin-RevId: ff80f4685295f5bd70dcde1b394822ff21d5d5c5 --- .../util/projectWizard/JavaModuleBuilder.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/java/openapi/src/com/intellij/ide/util/projectWizard/JavaModuleBuilder.java b/java/openapi/src/com/intellij/ide/util/projectWizard/JavaModuleBuilder.java index f0ff07ec967a..d041f0822ad9 100644 --- a/java/openapi/src/com/intellij/ide/util/projectWizard/JavaModuleBuilder.java +++ b/java/openapi/src/com/intellij/ide/util/projectWizard/JavaModuleBuilder.java @@ -17,6 +17,7 @@ import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.roots.ui.configuration.ModulesProvider; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.io.NioFiles; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VfsUtilCore; @@ -27,8 +28,10 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class JavaModuleBuilder extends ModuleBuilder implements SourcePathsBuilder { private static final Logger LOG = Logger.getInstance(JavaModuleBuilder.class); @@ -49,9 +52,16 @@ public class JavaModuleBuilder extends ModuleBuilder implements SourcePathsBuild public List> getSourcePaths() { if (mySourcePaths == null) { final List> paths = new ArrayList<>(); - @NonNls final String path = getContentEntryPath() + File.separator + "src"; - new File(path).mkdirs(); - paths.add(Pair.create(path, "")); + String contentEntry = Objects.requireNonNull(getContentEntryPath()); + @NonNls final Path path = Path.of(contentEntry).resolve("src"); + try { + NioFiles.createDirectories(path); + } + catch (IOException e) { + LOG.error(e); + new File(path.toString()).mkdirs(); // maybe this will succeed... + } + paths.add(Pair.create(path.toString(), "")); return paths; } return mySourcePaths;