use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class SchemeImportUtil method loadSchemeDom.
@NotNull
public static Element loadSchemeDom(@NotNull VirtualFile file) throws SchemeImportException {
InputStream inputStream = null;
try {
inputStream = file.getInputStream();
final Document document = JDOMUtil.loadDocument(inputStream);
final Element root = document.getRootElement();
inputStream.close();
return root;
} catch (IOException | JDOMException e) {
throw new SchemeImportException("Can't read from" + file.getName() + ", " + e.getMessage());
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// ignore
}
}
}
}
use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class CoreProjectLoader method loadDirectoryProject.
private static void loadDirectoryProject(MockProject project, @NotNull VirtualFile dotIdea) throws IOException, JDOMException {
VirtualFile modulesXml = dotIdea.findChild("modules.xml");
if (modulesXml == null)
throw new FileNotFoundException("Missing 'modules.xml' in " + dotIdea.getPath());
TreeMap<String, Element> storageData = loadStorageFile(project, modulesXml);
final Element moduleManagerState = storageData.get("ProjectModuleManager");
if (moduleManagerState == null) {
throw new JDOMException("cannot find ProjectModuleManager state in modules.xml");
}
final CoreModuleManager moduleManager = (CoreModuleManager) ModuleManager.getInstance(project);
moduleManager.loadState(moduleManagerState);
VirtualFile miscXml = dotIdea.findChild("misc.xml");
if (miscXml != null) {
storageData = loadStorageFile(project, miscXml);
final Element projectRootManagerState = storageData.get("ProjectRootManager");
if (projectRootManagerState == null) {
throw new JDOMException("cannot find ProjectRootManager state in misc.xml");
}
((ProjectRootManagerImpl) ProjectRootManager.getInstance(project)).loadState(projectRootManagerState);
}
VirtualFile libraries = dotIdea.findChild("libraries");
if (libraries != null) {
Map<String, Element> data = DirectoryStorageUtil.loadFrom(libraries, PathMacroManager.getInstance(project));
Element libraryTable = DefaultStateSerializer.deserializeState(DirectoryStorageUtil.getCompositeState(data, new ProjectLibraryTable.LibraryStateSplitter()), Element.class, null);
((LibraryTableBase) ProjectLibraryTable.getInstance(project)).loadState(libraryTable);
}
moduleManager.loadModules();
project.projectOpened();
}
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);
}
}
Aggregations