use of org.jetbrains.idea.eclipse.conversion.EclipseClasspathWriter in project intellij-community by JetBrains.
the class ClasspathSaveSession method setState.
@Override
public void setState(Object component, @NotNull String componentName, @NotNull Object state) {
try {
CachedXmlDocumentSet fileSet = EclipseClasspathStorageProvider.getFileCache(module);
Element oldClassPath;
try {
oldClassPath = fileSet.load(EclipseXml.CLASSPATH_FILE, true);
} catch (Exception e) {
EclipseClasspathWriter.LOG.warn(e);
oldClassPath = null;
}
ModuleRootManagerImpl moduleRootManager = (ModuleRootManagerImpl) component;
if (oldClassPath != null || moduleRootManager.getSourceRoots().length > 0 || moduleRootManager.getOrderEntries().length > 2) {
Element newClassPathElement = new EclipseClasspathWriter().writeClasspath(oldClassPath, moduleRootManager);
if (oldClassPath == null || !JDOMUtil.areElementsEqual(newClassPathElement, oldClassPath)) {
update(newClassPathElement, EclipseXml.CLASSPATH_FILE);
}
}
if (fileSet.getFile(EclipseXml.PROJECT_FILE, true) == null) {
DotProjectFileHelper.saveDotProjectFile(module, fileSet.getParent(EclipseXml.PROJECT_FILE));
}
Element ideaSpecific = new Element(IdeaXml.COMPONENT_TAG);
String emlFilename = moduleRootManager.getModule().getName() + EclipseXml.IDEA_SETTINGS_POSTFIX;
if (IdeaSpecificSettings.writeIdeaSpecificClasspath(ideaSpecific, moduleRootManager)) {
update(ideaSpecific, emlFilename);
} else {
delete(emlFilename);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.jetbrains.idea.eclipse.conversion.EclipseClasspathWriter in project intellij-community by JetBrains.
the class EclipseClasspathTest method checkModule.
static void checkModule(String path, Module module) throws IOException, JDOMException, ConversionException {
final File classpathFile1 = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
if (!classpathFile1.exists())
return;
String fileText1 = FileUtil.loadFile(classpathFile1).replaceAll("\\$ROOT\\$", module.getProject().getBaseDir().getPath());
if (!SystemInfo.isWindows) {
fileText1 = fileText1.replaceAll(EclipseXml.FILE_PROTOCOL + "/", EclipseXml.FILE_PROTOCOL);
}
Element classpathElement1 = JDOMUtil.load(fileText1);
ModuleRootModel model = ModuleRootManager.getInstance(module);
Element resultClasspathElement = new EclipseClasspathWriter().writeClasspath(classpathElement1, model);
assertThat(resultClasspathElement).isEqualTo(resultClasspathElement);
}
use of org.jetbrains.idea.eclipse.conversion.EclipseClasspathWriter in project intellij-community by JetBrains.
the class ExportEclipseProjectsAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
// to flush iml files
if (project == null) {
return;
}
project.save();
List<Module> modules = new SmartList<>();
List<Module> incompatibleModules = new SmartList<>();
for (Module module : ModuleManager.getInstance(project).getModules()) {
if (!EclipseModuleManagerImpl.isEclipseStorage(module)) {
try {
ClasspathStorageProvider provider = ClasspathStorage.getProvider(JpsEclipseClasspathSerializer.CLASSPATH_STORAGE_ID);
if (provider != null) {
provider.assertCompatible(ModuleRootManager.getInstance(module));
}
modules.add(module);
} catch (ConfigurationException ignored) {
incompatibleModules.add(module);
}
}
}
//todo suggest smth with hierarchy modules
if (incompatibleModules.isEmpty()) {
if (modules.isEmpty()) {
Messages.showInfoMessage(project, EclipseBundle.message("eclipse.export.nothing.to.do"), EclipseBundle.message("eclipse.export.dialog.title"));
return;
}
} else if (Messages.showOkCancelDialog(project, "<html><body>Eclipse incompatible modules found:<ul><br><li>" + StringUtil.join(incompatibleModules, module -> module.getName(), "<br><li>") + "</ul><br>Would you like to proceed and possibly lose your configurations?</body></html>", EclipseBundle.message("eclipse.export.dialog.title"), Messages.getWarningIcon()) != Messages.OK) {
return;
}
modules.addAll(incompatibleModules);
ExportEclipseProjectsDialog dialog = new ExportEclipseProjectsDialog(project, modules);
if (!dialog.showAndGet()) {
return;
}
if (dialog.isLink()) {
for (Module module : dialog.getSelectedModules()) {
ClasspathStorage.setStorageType(ModuleRootManager.getInstance(module), JpsEclipseClasspathSerializer.CLASSPATH_STORAGE_ID);
}
} else {
LinkedHashMap<Module, String> module2StorageRoot = new LinkedHashMap<>();
for (Module module : dialog.getSelectedModules()) {
VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
String storageRoot = contentRoots.length == 1 ? contentRoots[0].getPath() : ClasspathStorage.getStorageRootFromOptions(module);
module2StorageRoot.put(module, storageRoot);
try {
DotProjectFileHelper.saveDotProjectFile(module, storageRoot);
} catch (Exception e1) {
LOG.error(e1);
}
}
for (Module module : module2StorageRoot.keySet()) {
ModuleRootModel model = ModuleRootManager.getInstance(module);
String storageRoot = module2StorageRoot.get(module);
try {
Element classpathElement = new EclipseClasspathWriter().writeClasspath(null, model);
File classpathFile = new File(storageRoot, EclipseXml.CLASSPATH_FILE);
if (!FileUtil.createIfDoesntExist(classpathFile)) {
continue;
}
EclipseJDOMUtil.output(classpathElement, classpathFile, project);
final Element ideaSpecific = new Element(IdeaXml.COMPONENT_TAG);
if (IdeaSpecificSettings.writeIdeaSpecificClasspath(ideaSpecific, model)) {
File emlFile = new File(storageRoot, module.getName() + EclipseXml.IDEA_SETTINGS_POSTFIX);
if (!FileUtil.createIfDoesntExist(emlFile)) {
continue;
}
EclipseJDOMUtil.output(ideaSpecific, emlFile, project);
}
} catch (Exception e1) {
LOG.error(e1);
}
}
}
try {
EclipseUserLibrariesHelper.appendProjectLibraries(project, dialog.getUserLibrariesFile());
} catch (IOException e1) {
LOG.error(e1);
}
project.save();
}
Aggregations