use of com.intellij.platform.templates.TemplateProjectDirectoryGenerator in project intellij-community by JetBrains.
the class AbstractNewProjectStep method doGenerateProject.
public static Project doGenerateProject(@Nullable final Project projectToClose, @NotNull final String locationString, @Nullable final DirectoryProjectGenerator generator, @NotNull final Function<VirtualFile, Object> settingsComputable) {
final File location = new File(FileUtil.toSystemDependentName(locationString));
if (!location.exists() && !location.mkdirs()) {
String message = ActionsBundle.message("action.NewDirectoryProject.cannot.create.dir", location.getAbsolutePath());
Messages.showErrorDialog(projectToClose, message, ActionsBundle.message("action.NewDirectoryProject.title"));
return null;
}
final VirtualFile baseDir = ApplicationManager.getApplication().runWriteAction((Computable<VirtualFile>) () -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(location));
if (baseDir == null) {
LOG.error("Couldn't find '" + location + "' in VFS");
return null;
}
VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);
if (baseDir.getChildren().length > 0) {
String message = ActionsBundle.message("action.NewDirectoryProject.not.empty", location.getAbsolutePath());
int rc = Messages.showYesNoDialog(projectToClose, message, ActionsBundle.message("action.NewDirectoryProject.title"), Messages.getQuestionIcon());
if (rc == Messages.YES) {
return PlatformProjectOpenProcessor.getInstance().doOpenProject(baseDir, null, false);
}
}
String generatorName = generator == null ? "empty" : ConvertUsagesUtil.ensureProperKey(generator.getName());
UsageTrigger.trigger("AbstractNewProjectStep." + generatorName);
Object settings = null;
if (generator != null) {
try {
settings = settingsComputable.fun(baseDir);
} catch (ProcessCanceledException e) {
return null;
}
}
RecentProjectsManager.getInstance().setLastProjectCreationLocation(location.getParent());
ProjectOpenedCallback callback = null;
if (generator instanceof TemplateProjectDirectoryGenerator) {
((TemplateProjectDirectoryGenerator) generator).generateProject(baseDir.getName(), locationString);
} else {
final Object finalSettings = settings;
callback = (p, module) -> {
if (generator != null) {
generator.generateProject(p, baseDir, finalSettings, module);
}
};
}
EnumSet<PlatformProjectOpenProcessor.Option> options = EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class);
return PlatformProjectOpenProcessor.doOpenProject(baseDir, projectToClose, -1, callback, options);
}
Aggregations