use of org.jdom.JDOMException in project intellij-plugins by JetBrains.
the class RslUtil method getSwcPathToRslUrlsMap.
private static synchronized Map<String, List<String>> getSwcPathToRslUrlsMap(final String sdkHome) {
final String configFilePath = sdkHome + "/frameworks/flex-config.xml";
final File configFile = new File(configFilePath);
if (!configFile.isFile()) {
LOG.warn("File not found: " + configFilePath);
ourConfigFilePathToTimestampAndSwcPathToRslUrls.remove(configFilePath);
return Collections.emptyMap();
}
Pair<Long, Map<String, List<String>>> data = ourConfigFilePathToTimestampAndSwcPathToRslUrls.get(configFilePath);
final Long currentTimestamp = configFile.lastModified();
final Long cachedTimestamp = data == null ? null : data.first;
if (cachedTimestamp == null || !cachedTimestamp.equals(currentTimestamp)) {
ourConfigFilePathToTimestampAndSwcPathToRslUrls.remove(configFilePath);
final Map<String, List<String>> swcPathToRslMap = new THashMap<>();
try {
final Element rootElement = JDOMUtil.load(configFile);
for (Element rslElement : rootElement.getChildren("runtime-shared-library-path", rootElement.getNamespace())) {
final Element swcPathElement = rslElement.getChild("path-element", rslElement.getNamespace());
if (swcPathElement != null) {
final List<String> rslUrls = new ArrayList<>(2);
for (Element rslUrlElement : rslElement.getChildren("rsl-url", rootElement.getNamespace())) {
final String rslUrl = rslUrlElement.getTextNormalize();
rslUrls.add(rslUrl);
}
final String swcPath = PathUtilRt.getParentPath(configFilePath) + "/" + swcPathElement.getTextNormalize();
swcPathToRslMap.put(SystemInfo.isFileSystemCaseSensitive ? swcPath : swcPath.toLowerCase(), rslUrls);
}
}
} catch (IOException | JDOMException e) {
LOG.warn(configFilePath, e);
}
data = Pair.create(currentTimestamp, swcPathToRslMap);
ourConfigFilePathToTimestampAndSwcPathToRslUrls.put(configFilePath, data);
}
return data.second;
}
use of org.jdom.JDOMException in project intellij-plugins by JetBrains.
the class JSConditionalCompilationDefinitionsProviderImpl method getDefinitionsFromConfigFile.
private Collection<Pair<String, String>> getDefinitionsFromConfigFile(final String configFilePath) {
if (StringUtil.isEmptyOrSpaces(configFilePath))
return Collections.emptyList();
final VirtualFile configFile = LocalFileSystem.getInstance().findFileByPath(configFilePath);
if (configFile == null || configFile.isDirectory())
return Collections.emptyList();
final FileDocumentManager documentManager = FileDocumentManager.getInstance();
final Document cachedDocument = documentManager.getCachedDocument(configFile);
final Long currentTimestamp = cachedDocument != null ? cachedDocument.getModificationStamp() : configFile.getModificationCount();
final Long cachedTimestamp = configFileToTimestamp.get(configFile);
if (cachedTimestamp == null || !cachedTimestamp.equals(currentTimestamp)) {
configFileToTimestamp.remove(configFile);
configFileToConditionalCompilerDefinitions.remove(configFile);
try {
final Element rootElement = cachedDocument == null ? JDOMUtil.load(configFile.getInputStream()) : JDOMUtil.load(cachedDocument.getCharsSequence());
final Collection<Pair<String, String>> result = new ArrayList<>();
if (rootElement.getName().equals(FlexCompilerConfigFileUtilBase.FLEX_CONFIG)) {
// noinspection unchecked
for (Element compilerElement : rootElement.getChildren(FlexCompilerConfigFileUtilBase.COMPILER, rootElement.getNamespace())) {
// noinspection unchecked
for (Element defineElement : compilerElement.getChildren(DEFINE, rootElement.getNamespace())) {
final String name = defineElement.getChildText(NAME, rootElement.getNamespace());
final String value = defineElement.getChildText(VALUE, rootElement.getNamespace());
if (!StringUtil.isEmpty(name) && value != null) {
result.add(Pair.create(name, value));
}
}
}
}
configFileToTimestamp.put(configFile, currentTimestamp);
configFileToConditionalCompilerDefinitions.put(configFile, result);
return result;
} catch (JDOMException ignored) {
/*ignore*/
} catch (IOException ignored) {
/*ignore*/
}
return Collections.emptyList();
} else {
return configFileToConditionalCompilerDefinitions.get(configFile);
}
}
use of org.jdom.JDOMException in project intellij-plugins by JetBrains.
the class FlexCompilationUtils method fixInitialContent.
private static String fixInitialContent(final VirtualFile descriptorFile, final String swfName) throws FlexCompilerException {
try {
final Document document;
try {
document = JDOMUtil.loadDocument(descriptorFile.getInputStream());
} catch (IOException e) {
throw new FlexCompilerException("Failed to read AIR descriptor content: " + e.getMessage(), descriptorFile.getUrl(), -1, -1);
}
final Element rootElement = document.getRootElement();
if (!"application".equals(rootElement.getName())) {
throw new FlexCompilerException("AIR descriptor file has incorrect root tag", descriptorFile.getUrl(), -1, -1);
}
Element initialWindowElement = rootElement.getChild("initialWindow", rootElement.getNamespace());
if (initialWindowElement == null) {
initialWindowElement = new Element("initialWindow", rootElement.getNamespace());
rootElement.addContent(initialWindowElement);
}
Element contentElement = initialWindowElement.getChild("content", rootElement.getNamespace());
if (contentElement == null) {
contentElement = new Element("content", rootElement.getNamespace());
initialWindowElement.addContent(contentElement);
}
contentElement.setText(swfName);
return JDOMUtil.writeDocument(document, SystemProperties.getLineSeparator());
} catch (JDOMException e) {
throw new FlexCompilerException("AIR descriptor file has incorrect format: " + e.getMessage(), descriptorFile.getUrl(), -1, -1);
}
}
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();
}
Aggregations