use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class CoreModuleManager method createAndLoadModule.
@NotNull
@Override
protected ModuleEx createAndLoadModule(@NotNull String filePath, @NotNull VirtualFile file) throws IOException {
final ModuleEx module = createModule(filePath);
try {
ModuleRootManagerImpl.ModuleRootManagerState state = new ModuleRootManagerImpl.ModuleRootManagerState();
state.readExternal(CoreProjectLoader.loadStorageFile(module, file).get("NewModuleRootManager"));
((ModuleRootManagerImpl) ModuleRootManager.getInstance(module)).loadState(state);
} catch (JDOMException e) {
throw new IOException(e);
}
return module;
}
use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class PathManagerEx method getCommunityModules.
private static synchronized Set<String> getCommunityModules() {
if (ourCommunityModules != null) {
return ourCommunityModules;
}
ourCommunityModules = new THashSet<>();
File modulesXml = findFileUnderCommunityHome(Project.DIRECTORY_STORE_FOLDER + "/modules.xml");
if (!modulesXml.exists()) {
throw new IllegalStateException("Cannot obtain test data path: " + modulesXml.getAbsolutePath() + " not found");
}
try {
Element element = JDomSerializationUtil.findComponent(JDOMUtil.load(modulesXml), ModuleManagerImpl.COMPONENT_NAME);
assert element != null;
for (ModulePath file : ModuleManagerImpl.getPathsToModuleFiles(element)) {
ourCommunityModules.add(file.getModuleName());
}
return ourCommunityModules;
} catch (JDOMException | IOException e) {
throw new RuntimeException("Cannot read modules from " + modulesXml.getAbsolutePath(), e);
}
}
use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class Configuration method load.
@Nullable
public static Configuration load(final InputStream is) throws IOException, JDOMException {
final List<Element> elements = new ArrayList<>();
final Element rootElement = JDOMUtil.load(is);
final Element state;
if (rootElement.getName().equals(COMPONENT_NAME)) {
state = rootElement;
} else {
elements.add(rootElement);
//noinspection unchecked
elements.addAll(rootElement.getChildren("component"));
state = ContainerUtil.find(elements, element -> "component".equals(element.getName()) && COMPONENT_NAME.equals(element.getAttributeValue("name")));
}
if (state != null) {
final Configuration cfg = new Configuration();
cfg.loadState(state);
return cfg;
}
return null;
}
use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class JpsPluginSyntheticArtifactProvider method createArtifact.
private static JpsArtifact createArtifact(JpsModule module, JpsPluginModuleProperties properties) {
JpsPackagingElementFactory factory = JpsPackagingElementFactory.getInstance();
JpsCompositePackagingElement root = factory.createArtifactRoot();
String pluginXmlUrl = properties.getPluginXmlUrl();
if (pluginXmlUrl != null) {
String pluginXmlPath = JpsPathUtil.urlToPath(pluginXmlUrl);
JpsCompositePackagingElement metaInfDir = factory.getOrCreateDirectory(root, "META-INF");
metaInfDir.addChild(factory.createFileCopy(pluginXmlPath, null));
File pluginXmlFile = JpsPathUtil.urlToFile(pluginXmlUrl);
if (pluginXmlFile.exists()) {
try {
Element rootElement = JDOMUtil.load(pluginXmlFile);
for (Element dependsElement : JDOMUtil.getChildren(rootElement, "depends")) {
String relativePath = dependsElement.getAttributeValue("config-file");
if (relativePath != null) {
File dependencyFile = new File(pluginXmlFile.getParent(), FileUtil.toSystemDependentName(relativePath));
String dependencyPath = FileUtil.toSystemIndependentName(dependencyFile.getAbsolutePath());
metaInfDir.addChild(factory.createFileCopy(dependencyPath, null));
}
}
} catch (JDOMException | IOException e) {
LOG.info(e);
}
}
}
JpsJavaDependenciesEnumerator enumerator = JpsJavaExtensionService.dependencies(module).recursively().includedIn(JpsJavaClasspathKind.PRODUCTION_RUNTIME);
JpsCompositePackagingElement classesDir = factory.getOrCreateDirectory(root, "classes");
for (JpsModule depModule : enumerator.getModules()) {
if (depModule.getModuleType().equals(JpsJavaModuleType.INSTANCE)) {
classesDir.addChild(JpsJavaExtensionService.getInstance().createProductionModuleOutput(depModule.createReference()));
}
}
classesDir.addChild(JpsJavaExtensionService.getInstance().createProductionModuleOutput(module.createReference()));
for (JpsLibrary library : enumerator.getLibraries()) {
JpsCompositePackagingElement parent;
if (hasDirsOnly(library)) {
parent = classesDir;
} else {
parent = factory.getOrCreateDirectory(root, "lib");
}
parent.addChild(factory.createLibraryElement(library.createReference()));
}
String name = module.getName() + ":plugin";
JpsArtifact artifact = JpsArtifactService.getInstance().createArtifact(name, root, DirectoryArtifactType.INSTANCE, JpsElementFactory.getInstance().createDummyElement());
JpsSdk<JpsSimpleElement<JpsIdeaSdkProperties>> sdk = module.getSdk(JpsIdeaSdkType.INSTANCE);
if (sdk != null) {
String sandboxHome = sdk.getSdkProperties().getData().getSandboxHome();
if (sandboxHome != null) {
artifact.setOutputPath(sandboxHome + "/plugins/" + module.getName());
}
}
return artifact;
}
use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class EclipseImportBuilder method validate.
@Override
public boolean validate(final Project currentProject, final Project dstProject) {
final Ref<Exception> refEx = new Ref<>();
final Set<String> variables = new THashSet<>();
final Map<String, String> naturesNames = new THashMap<>();
final List<String> projectsToConvert = getParameters().projectsToConvert;
final boolean oneProjectToConvert = projectsToConvert.size() == 1;
final String separator = oneProjectToConvert ? "<br>" : ", ";
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
try {
for (String path : projectsToConvert) {
File classPathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
if (classPathFile.exists()) {
EclipseClasspathReader.collectVariables(variables, JDOMUtil.load(classPathFile), path);
}
collectUnknownNatures(path, naturesNames, separator);
}
} catch (IOException | JDOMException e) {
refEx.set(e);
}
}, EclipseBundle.message("eclipse.import.converting"), false, currentProject);
if (!refEx.isNull()) {
Messages.showErrorDialog(dstProject, refEx.get().getMessage(), getTitle());
return false;
}
if (!ProjectMacrosUtil.checkNonIgnoredMacros(dstProject, variables)) {
return false;
}
if (!naturesNames.isEmpty()) {
final String title = "Unknown Natures Detected";
final String naturesByProject;
if (oneProjectToConvert) {
naturesByProject = naturesNames.values().iterator().next();
} else {
naturesByProject = StringUtil.join(naturesNames.keySet(), projectPath -> projectPath + "(" + naturesNames.get(projectPath) + ")", "<br>");
}
Notifications.Bus.notify(new Notification(title, title, "Imported projects contain unknown natures:<br>" + naturesByProject + "<br>" + "Some settings may be lost after import.", NotificationType.WARNING));
}
return true;
}
Aggregations