use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class ProjectUtil method openProject.
@Nullable
public static Project openProject(final String path, @Nullable Project projectToClose, boolean forceOpenInNewFrame) {
File file = new File(path);
if (!file.exists()) {
Messages.showErrorDialog(IdeBundle.message("error.project.file.does.not.exist", path), CommonBundle.getErrorTitle());
return null;
}
if (file.isDirectory()) {
File dir = new File(file, Project.DIRECTORY_STORE_FOLDER);
if (!dir.exists()) {
String message = IdeBundle.message("error.project.file.does.not.exist", dir.getPath());
Messages.showErrorDialog(message, CommonBundle.getErrorTitle());
return null;
}
}
Project existing = findAndFocusExistingProjectForPath(path);
if (existing != null)
return existing;
Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
if (!forceOpenInNewFrame && openProjects.length > 0) {
int exitCode = confirmOpenNewProject(false);
if (exitCode == GeneralSettings.OPEN_PROJECT_SAME_WINDOW) {
final Project toClose = projectToClose != null ? projectToClose : openProjects[openProjects.length - 1];
if (!closeAndDispose(toClose))
return null;
} else if (exitCode != GeneralSettings.OPEN_PROJECT_NEW_WINDOW) {
return null;
}
}
if (isRemotePath(path) && !RecentProjectsManager.getInstance().hasPath(path)) {
if (!confirmLoadingFromRemotePath(path, "warning.load.project.from.share", "title.load.project.from.share")) {
return null;
}
}
ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
Project project = null;
try {
project = projectManager.loadAndOpenProject(path);
} catch (IOException e) {
Messages.showMessageDialog(IdeBundle.message("error.cannot.load.project", e.getMessage()), IdeBundle.message("title.cannot.load.project"), Messages.getErrorIcon());
} catch (JDOMException | InvalidDataException e) {
LOG.info(e);
Messages.showMessageDialog(IdeBundle.message("error.project.file.is.corrupted"), IdeBundle.message("title.cannot.load.project"), Messages.getErrorIcon());
}
return project;
}
use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class JavaDocInfoGenerator method generatePackageHtmlJavaDoc.
private void generatePackageHtmlJavaDoc(final StringBuilder buffer, final PsiFile packageHtmlFile, boolean generatePrologueAndEpilogue) {
String htmlText = packageHtmlFile.getText();
try {
final Document document = JDOMUtil.loadDocument(new ByteArrayInputStream(htmlText.getBytes(CharsetToolkit.UTF8_CHARSET)));
final Element rootTag = document.getRootElement();
final Element subTag = rootTag.getChild("body");
if (subTag != null) {
htmlText = subTag.getValue();
}
} catch (JDOMException | IOException ignore) {
}
htmlText = StringUtil.replace(htmlText, "*/", "*/");
final String fileText = "/** " + htmlText + " */";
final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(packageHtmlFile.getProject()).getElementFactory();
final PsiDocComment docComment;
try {
docComment = elementFactory.createDocCommentFromText(fileText);
} catch (IncorrectOperationException e) {
LOG.error(e);
return;
}
if (generatePrologueAndEpilogue)
generatePrologue(buffer);
generateCommonSection(buffer, docComment);
if (generatePrologueAndEpilogue)
generateEpilogue(buffer);
}
use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class InspectionProfileConvertor method renameOldDefaultsProfile.
private static void renameOldDefaultsProfile() {
Path directoryPath = Paths.get(PathManager.getConfigPath(), InspectionProfileManager.INSPECTION_DIR);
if (!PathKt.exists(directoryPath)) {
return;
}
File[] files = directoryPath.toFile().listFiles(pathname -> pathname.getPath().endsWith(File.separator + DEFAULT_XML));
if (files == null || files.length != 1 || !files[0].isFile() || files[0].length() == 0) {
return;
}
try {
Element root = JdomKt.loadElement(files[0].toPath());
if (root.getAttributeValue(VERSION_ATT) == null) {
JdomKt.write(root, directoryPath.resolve(OLD_DEFAUL_PROFILE + XML_EXTENSION));
FileUtil.delete(files[0]);
}
} catch (IOException | JDOMException e) {
LOG.error(e);
}
}
use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class IdeaPluginDescriptorImpl method readExternal.
public void readExternal(@NotNull URL url) throws InvalidDataException, FileNotFoundException {
try {
Document document = JDOMUtil.loadDocument(url);
readExternal(document, url, JDOMXIncluder.DEFAULT_PATH_RESOLVER);
} catch (FileNotFoundException e) {
throw e;
} catch (IOException e) {
throw new InvalidDataException(e);
} catch (JDOMException e) {
throw new InvalidDataException(e);
}
}
use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class JpsLoaderBase method loadRootElement.
protected static Element loadRootElement(final File file, final JpsMacroExpander macroExpander) {
try {
final Element element = tryLoadRootElement(file);
macroExpander.substitute(element, SystemInfo.isFileSystemCaseSensitive);
return element;
} catch (JDOMException e) {
throw new CannotLoadJpsModelException(file, "Cannot parse xml file " + file.getAbsolutePath() + ": " + e.getMessage(), e);
} catch (IOException e) {
throw new CannotLoadJpsModelException(file, "Cannot read file " + file.getAbsolutePath() + ": " + e.getMessage(), e);
}
}
Aggregations