void (final Project project, final GenerateSchemaFromInstanceDocumentDialog dialog) { FileDocumentManager.getInstance().saveAllDocuments(); final String url = dialog.getUrl().getText(); final VirtualFile relativeFile = VfsUtilCore.findRelativeFile(ExternalResourceManager.getInstance().getResourceLocation(url), null); VirtualFile relativeFileDir; if (relativeFile == null) { Messages.showErrorDialog(project, XmlBundle.message("file.doesnt.exist", url), XmlBundle.message("error")); return; } else { relativeFileDir = relativeFile.getParent(); } if (relativeFileDir == null) { Messages.showErrorDialog(project, XmlBundle.message("file.doesnt.exist", url), XmlBundle.message("error")); return; } @NonNls List<String> parameters = new LinkedList<>(); parameters.add("-design"); parameters.add(Holder.DESIGN_TYPES.get(dialog.getDesignType())); parameters.add("-simple-content-types"); parameters.add(Holder.CONTENT_TYPES.get(dialog.getSimpleContentType())); parameters.add("-enumerations"); String enumLimit = dialog.getEnumerationsLimit(); parameters.add("0".equals(enumLimit) ? "never" : enumLimit); parameters.add("-outDir"); final String dirPath = relativeFileDir.getPath(); parameters.add(dirPath); final File expectedSchemaFile = new File(dirPath + File.separator + relativeFile.getName() + "0.xsd"); if (expectedSchemaFile.exists()) { if (!expectedSchemaFile.delete()) { Messages.showErrorDialog(project, XmlBundle.message("cant.delete.file", expectedSchemaFile.getPath()), XmlBundle.message("error")); return; } } parameters.add("-outPrefix"); parameters.add(relativeFile.getName()); parameters.add(url); File xsd = new File(dirPath + File.separator + dialog.getTargetSchemaName()); final VirtualFile xsdFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(xsd); if (xsdFile != null) { ApplicationManager.getApplication().runWriteAction(() -> { try { xsdFile.delete(null); } catch (IOException e) {// } }); } // Inst2Xsd.main contains exit() calls, so we need to prevent this SecurityManager old = System.getSecurityManager(); try { System.setSecurityManager(new SecurityManager() { @Override public void checkExit(int status) { throw new SecurityException(); } @Override public void checkPermission(Permission perm) { } }); Inst2Xsd.main(ArrayUtilRt.toStringArray(parameters)); } catch (Exception e) { Messages.showErrorDialog(project, XmlBundle.message("xml2xsd.generator.error.message"), XmlBundle.message("xml2xsd.generator.error")); return; } finally { System.setSecurityManager(old); } if (expectedSchemaFile.exists()) { final boolean renamed = expectedSchemaFile.renameTo(xsd); if (! renamed) { Messages.showErrorDialog(project, XmlBundle.message("cant.rename.file", expectedSchemaFile.getPath(), xsd.getPath()), XmlBundle.message("error")); } } VirtualFile xsdVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(xsd); if (xsdVFile != null) { FileEditorManager.getInstance(project).openFile(xsdVFile, true); } else { Messages.showErrorDialog(project, XmlBundle.message("xml2xsd.generator.error.message"), XmlBundle.message("xml2xsd.generator.error")); } }