void (final @Nullable String projectName, String path, final boolean isModuleMode, @Nullable ProgressIndicator pI, boolean reportFailuresWithDialog) { final WizardInputField<?> basePackage = getBasePackageField(); try { Path dir = Paths.get(path); final class ExceptionConsumer implements Consumer<VelocityException> { private String myPath; private String myText; private final SmartList<Trinity<String, String, VelocityException>> myFailures = new SmartList<>(); @Override public void accept(VelocityException e) { myFailures.add(Trinity.create(myPath, myText, e)); } private void setCurrentFile(String path, String text) { myPath = path; myText = text; } private void reportFailures() { if (myFailures.isEmpty()) { return; } if(reportFailuresWithDialog) { String dialogMessage; if (myFailures.size() == 1) { dialogMessage = LangBundle.message("dialog.message.failed.to.decode.file", myFailures.get(0).getFirst()); } else { StringBuilder dialogMessageBuilder = new StringBuilder(); dialogMessageBuilder.append(LangBundle.message("dialog.message.failed.to.decode.files")).append('\n'); for (Trinity<String, String, VelocityException> failure : myFailures) { dialogMessageBuilder.append(failure.getFirst()).append("\n"); } dialogMessage = dialogMessageBuilder.toString(); //NON-NLS } Messages.showErrorDialog(dialogMessage, LangBundle.message("dialog.title.decoding.template")); } @NonNls StringBuilder reportBuilder = new StringBuilder(); for (Trinity<String, String, VelocityException> failure : myFailures) { reportBuilder.append("File: ").append(failure.getFirst()).append("\n"); reportBuilder.append("Exception:\n").append(ExceptionUtil.getThrowableText(failure.getThird())).append("\n"); reportBuilder.append("File content:\n'").append(failure.getSecond()).append("'\n"); reportBuilder.append("\n===========================================\n"); } LOG.error("Cannot decode files in template", (Throwable)null, new Attachment("Files in template", reportBuilder.toString())); } } ExceptionConsumer consumer = new ExceptionConsumer(); List<File> filesToRefresh = new ArrayList<>(); myTemplate.processStream(new ArchivedProjectTemplate.StreamProcessor<Void>() { @Override public Void consume(@NotNull ZipInputStream stream) throws IOException { ZipUtil.unzip(ProgressManager.getInstance().getProgressIndicator(), dir, stream, path1 -> { if (isModuleMode && path1.contains(Project.DIRECTORY_STORE_FOLDER)) { return null; } if (basePackage != null) { return path1.replace(getPathFragment(basePackage.getDefaultValue()), getPathFragment(basePackage.getValue())); } return path1; }, new ZipUtil.ContentProcessor() { @Override public byte[] processContent(byte[] content, File file) throws IOException { if(pI != null){ pI.checkCanceled(); } FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(file.getName()); String text = new String(content, StandardCharsets.UTF_8); consumer.setCurrentFile(file.getName(), text); return fileType.isBinary() ? content : processTemplates(projectName, text, file, consumer); } }, true); myTemplate.handleUnzippedDirectories(dir.toFile(), filesToRefresh); return null; } }); if (pI != null) { pI.setText(LangBundle.message("progress.title.refreshing")); } if (isModuleMode) { Path from; try (Stream<Path> list = Files.list(dir)) { from = list.filter(it -> it.toString().endsWith(".iml")).findFirst().orElse(null); } Files.move(Objects.requireNonNull(from), Paths.get(getModuleFilePath())); } RefreshQueue refreshQueue = RefreshQueue.getInstance(); LOG.assertTrue(!filesToRefresh.isEmpty()); for (File file : filesToRefresh) { VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); if (virtualFile == null) { throw new IOException("Can't find " + file); } refreshQueue.refresh(false, true, null, virtualFile); } consumer.reportFailures(); } catch (IOException e) { throw new RuntimeException(e); } }