mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
prepare to fix IDEA-133542 Eclipse integration: external change or .classpath or .eml does not suggest to reload project (regression)
This commit is contained in:
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,11 +22,11 @@ package com.intellij.openapi.roots;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class LanguageLevelModuleExtensionImpl extends ModuleExtension<LanguageLevelModuleExtensionImpl> implements LanguageLevelModuleExtension {
|
||||
@@ -62,7 +62,7 @@ public class LanguageLevelModuleExtensionImpl extends ModuleExtension<LanguageL
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(final Element element) throws InvalidDataException {
|
||||
public void readExternal(@NotNull Element element) {
|
||||
final String languageLevel = element.getAttributeValue(LANGUAGE_LEVEL_ELEMENT_NAME);
|
||||
if (languageLevel != null) {
|
||||
try {
|
||||
|
||||
+1
-2
@@ -20,7 +20,6 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootModel;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
@@ -59,7 +58,7 @@ public interface ClasspathStorageProvider {
|
||||
interface ClasspathConverter {
|
||||
FileSet getFileSet();
|
||||
|
||||
void getClasspath(ModifiableRootModel model, final Element element) throws IOException, InvalidDataException;
|
||||
void getClasspath(@NotNull ModifiableRootModel model, @NotNull Element element) throws IOException;
|
||||
|
||||
void setClasspath(ModuleRootModel model) throws IOException, WriteExternalException;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.idea.eclipse;
|
||||
|
||||
public class ConversionException extends Exception {
|
||||
public class ConversionException extends RuntimeException {
|
||||
public ConversionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
+18
-21
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@ package org.jetbrains.idea.eclipse.conversion;
|
||||
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.eclipse.IdeaXml;
|
||||
|
||||
@@ -28,23 +29,13 @@ import java.util.Map;
|
||||
* Date: 11/8/12
|
||||
*/
|
||||
public abstract class AbstractIdeaSpecificSettings<T, C, SdkType> {
|
||||
public void readIDEASpecific(final Element root, T model, @Nullable SdkType projectSdkType, Map<String, String> levels) throws InvalidDataException {
|
||||
public void readIdeaSpecific(@NotNull Element root, T model, @Nullable SdkType projectSdkType, Map<String, String> levels) {
|
||||
expandElement(root, model);
|
||||
|
||||
readLanguageLevel(root, model);
|
||||
|
||||
setupCompilerOutputs(root, model);
|
||||
final List entriesElements = root.getChildren(IdeaXml.CONTENT_ENTRY_TAG);
|
||||
if (!entriesElements.isEmpty()) {
|
||||
for (Object o : entriesElements) {
|
||||
readContentEntry((Element)o, createContentEntry(model, ((Element)o).getAttributeValue(IdeaXml.URL_ATTR)), model);
|
||||
}
|
||||
} else {
|
||||
final C[] entries = getEntries(model);//todo
|
||||
if (entries.length > 0) {
|
||||
readContentEntry(root, entries[0], model);
|
||||
}
|
||||
}
|
||||
readContentEntry(root, model);
|
||||
|
||||
setupJdk(root, model, projectSdkType);
|
||||
setupLibraryRoots(root, model);
|
||||
@@ -61,17 +52,23 @@ public abstract class AbstractIdeaSpecificSettings<T, C, SdkType> {
|
||||
public void updateEntries(Element root, T model, @Nullable SdkType projectSdkType) {
|
||||
setupJdk(root, model, projectSdkType);
|
||||
setupCompilerOutputs(root, model);
|
||||
final List entriesElements = root.getChildren(IdeaXml.CONTENT_ENTRY_TAG);
|
||||
if (!entriesElements.isEmpty()) {
|
||||
for (Object o : entriesElements) {
|
||||
readContentEntry((Element)o, createContentEntry(model, ((Element)o).getAttributeValue(IdeaXml.URL_ATTR)), model);
|
||||
}
|
||||
} else {
|
||||
final C[] entries = getEntries(model);//todo
|
||||
readContentEntry(root, model);
|
||||
}
|
||||
|
||||
private void readContentEntry(Element root, T model) {
|
||||
List<Element> entriesElements = root.getChildren(IdeaXml.CONTENT_ENTRY_TAG);
|
||||
if (entriesElements.isEmpty()) {
|
||||
// todo
|
||||
C[] entries = getEntries(model);
|
||||
if (entries.length > 0) {
|
||||
readContentEntry(root, entries[0], model);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (Element element : entriesElements) {
|
||||
readContentEntry(element, createContentEntry(model, element.getAttributeValue(IdeaXml.URL_ATTR)), model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void readLibraryLevels(Element root, Map<String, String> levels);
|
||||
@@ -86,7 +83,7 @@ public abstract class AbstractIdeaSpecificSettings<T, C, SdkType> {
|
||||
|
||||
protected abstract void setupCompilerOutputs(Element root, T model);
|
||||
|
||||
protected abstract void readLanguageLevel(Element root, T model) throws InvalidDataException;
|
||||
protected abstract void readLanguageLevel(Element root, T model);
|
||||
|
||||
protected abstract void expandElement(Element root, T model);
|
||||
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.jps.eclipse.model;
|
||||
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -121,7 +120,7 @@ class JpsIdeaSpecificSettings extends AbstractIdeaSpecificSettings<JpsModule, St
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readLanguageLevel(Element root, JpsModule model) throws InvalidDataException {
|
||||
protected void readLanguageLevel(Element root, JpsModule model) {
|
||||
final String languageLevel = root.getAttributeValue("LANGUAGE_LEVEL");
|
||||
final JpsJavaModuleExtension extension = getService().getOrCreateModuleExtension(model);
|
||||
if (languageLevel != null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,46 +18,41 @@ package org.jdom.output;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import org.jdom.Document;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.io.*;
|
||||
|
||||
public class EclipseJDOMUtil {
|
||||
|
||||
@NonNls private static final String ENCODING = CharsetToolkit.UTF8;
|
||||
|
||||
|
||||
private EclipseJDOMUtil() {
|
||||
}
|
||||
|
||||
|
||||
private static EclipseXMLOutputter createOutputter(String lineSeparator) {
|
||||
EclipseXMLOutputter xmlOutputter = new EclipseXMLOutputter(lineSeparator);
|
||||
Format format = Format.getCompactFormat().
|
||||
setIndent("\t").
|
||||
setTextMode(Format.TextMode.NORMALIZE).
|
||||
setEncoding(ENCODING).
|
||||
setEncoding(CharsetToolkit.UTF8).
|
||||
setOmitEncoding(false).
|
||||
setOmitDeclaration(false);
|
||||
xmlOutputter.setFormat(format);
|
||||
return xmlOutputter;
|
||||
}
|
||||
|
||||
public static void output(final Document doc, final File file, final Project project) throws IOException {
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
public static void output(@NotNull Element element, @NotNull File file, @NotNull Project project) throws IOException {
|
||||
Writer writer = new OutputStreamWriter(new FileOutputStream(file), CharsetToolkit.UTF8);
|
||||
try {
|
||||
createOutputter(CodeStyleSettingsManager.getSettings(project).getLineSeparator()).output(doc, out);
|
||||
output(element, writer, project);
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void output(final Document document, final Writer writer, Project project) throws IOException {
|
||||
createOutputter(CodeStyleSettingsManager.getSettings(project).getLineSeparator()).output(document, writer);
|
||||
public static void output(@NotNull Element element, @NotNull Writer writer, @NotNull Project project) throws IOException {
|
||||
String lineSeparator = CodeStyleSettingsManager.getSettings(project).getLineSeparator();
|
||||
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
writer.write(lineSeparator);
|
||||
createOutputter(lineSeparator).output(element, writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import com.intellij.openapi.vfs.StandardFileSystems;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import gnu.trove.THashMap;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jdom.output.EclipseJDOMUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -40,8 +40,8 @@ import java.util.Set;
|
||||
|
||||
public class CachedXmlDocumentSet implements FileSet {
|
||||
protected final Map<String, String> nameToDir = new THashMap<String, String>();
|
||||
protected final Map<String, Document> savedContent = new THashMap<String, Document>();
|
||||
protected final Map<String, Document> modifiedContent = new THashMap<String, Document>();
|
||||
protected final Map<String, Element> savedContent = new THashMap<String, Element>();
|
||||
protected final Map<String, Element> modifiedContent = new THashMap<String, Element>();
|
||||
protected final Set<String> deletedContent = new THashSet<String>();
|
||||
private final Project project;
|
||||
|
||||
@@ -49,16 +49,18 @@ public class CachedXmlDocumentSet implements FileSet {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public Document read(@NotNull String name) throws IOException, JDOMException {
|
||||
@NotNull
|
||||
public Element read(@NotNull String name) throws IOException, JDOMException {
|
||||
return read(name, true);
|
||||
}
|
||||
|
||||
public Document read(@NotNull String name, final boolean refresh) throws IOException, JDOMException {
|
||||
@NotNull
|
||||
public Element read(@NotNull String name, final boolean refresh) throws IOException, JDOMException {
|
||||
return load(name, refresh).clone();
|
||||
}
|
||||
|
||||
public void write(Document document, String name) throws IOException {
|
||||
update(document.clone(), name);
|
||||
public void write(Element element, String name) throws IOException {
|
||||
update(element.clone(), name);
|
||||
}
|
||||
|
||||
public String getParent(@NotNull String name) {
|
||||
@@ -101,15 +103,15 @@ public class CachedXmlDocumentSet implements FileSet {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Document load(@NotNull String name, boolean refresh) throws IOException, JDOMException {
|
||||
protected Element load(@NotNull String name, boolean refresh) throws IOException, JDOMException {
|
||||
assertKnownName(name);
|
||||
|
||||
Document logical = modifiedContent.get(name);
|
||||
Element logical = modifiedContent.get(name);
|
||||
if (logical != null) {
|
||||
return logical;
|
||||
}
|
||||
|
||||
Document physical = savedContent.get(name);
|
||||
Element physical = savedContent.get(name);
|
||||
if (physical == null) {
|
||||
VirtualFile file = deletedContent.contains(name) ? null : getFile(name, refresh);
|
||||
if (file == null) {
|
||||
@@ -118,7 +120,7 @@ public class CachedXmlDocumentSet implements FileSet {
|
||||
|
||||
InputStream inputStream = file.getInputStream();
|
||||
try {
|
||||
physical = JDOMUtil.loadDocument(inputStream);
|
||||
physical = JDOMUtil.load(inputStream);
|
||||
}
|
||||
finally {
|
||||
inputStream.close();
|
||||
@@ -128,7 +130,7 @@ public class CachedXmlDocumentSet implements FileSet {
|
||||
return physical;
|
||||
}
|
||||
|
||||
public void update(Document content, final String name) {
|
||||
public void update(Element content, final String name) {
|
||||
assertKnownName(name);
|
||||
modifiedContent.put(name, content);
|
||||
deletedContent.remove(name);
|
||||
@@ -160,12 +162,12 @@ public class CachedXmlDocumentSet implements FileSet {
|
||||
return !deletedContent.isEmpty();
|
||||
}
|
||||
|
||||
private boolean hasChanged(final String key) {
|
||||
final Document content = modifiedContent.get(key);
|
||||
final Document physical1 = content == null ? null : content;
|
||||
final Document physical2 = savedContent.get(key);
|
||||
private boolean hasChanged(@NotNull String key) {
|
||||
Element content = modifiedContent.get(key);
|
||||
Element physical1 = content == null ? null : content;
|
||||
Element physical2 = savedContent.get(key);
|
||||
if (physical1 != null && physical2 != null) {
|
||||
return !JDOMUtil.areDocumentsEqual(physical1, physical2);
|
||||
return !JDOMUtil.areElementsEqual(physical1, physical2);
|
||||
}
|
||||
return physical1 != physical2;
|
||||
}
|
||||
@@ -173,7 +175,7 @@ public class CachedXmlDocumentSet implements FileSet {
|
||||
public void commit() throws IOException {
|
||||
for (String key : modifiedContent.keySet()) {
|
||||
if (hasChanged(key)) {
|
||||
Document content = modifiedContent.get(key);
|
||||
Element content = modifiedContent.get(key);
|
||||
if (content != null) {
|
||||
Writer writer = new OutputStreamWriter(getOrCreateVFile(key).getOutputStream(this), CharsetToolkit.UTF8_CHARSET);
|
||||
try {
|
||||
|
||||
+11
-15
@@ -24,7 +24,6 @@ import com.intellij.openapi.roots.impl.storage.ClassPathStorageUtil;
|
||||
import com.intellij.openapi.roots.impl.storage.ClasspathStorage;
|
||||
import com.intellij.openapi.roots.impl.storage.ClasspathStorageProvider;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -33,7 +32,6 @@ import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.SmartList;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
@@ -49,6 +47,7 @@ import org.jetbrains.jps.eclipse.model.JpsEclipseClasspathSerializer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Kaznacheev
|
||||
@@ -186,7 +185,7 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getClasspath(@NotNull ModifiableRootModel model, @NotNull Element element) throws IOException, InvalidDataException {
|
||||
public void getClasspath(@NotNull ModifiableRootModel model, @NotNull Element element) throws IOException {
|
||||
try {
|
||||
CachedXmlDocumentSet documentSet = getFileSet();
|
||||
String path = documentSet.getParent(EclipseXml.PROJECT_FILE);
|
||||
@@ -202,14 +201,14 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
|
||||
classpathReader.init(model);
|
||||
if (documentSet.exists(EclipseXml.CLASSPATH_FILE)) {
|
||||
classpathReader.readClasspath(model, new SmartList<String>(), new SmartList<String>(), new THashSet<String>(), null,
|
||||
documentSet.read(EclipseXml.CLASSPATH_FILE, false).getRootElement());
|
||||
documentSet.read(EclipseXml.CLASSPATH_FILE, false));
|
||||
}
|
||||
else {
|
||||
EclipseClasspathReader.setOutputUrl(model, path + "/bin");
|
||||
}
|
||||
String eml = model.getModule().getName() + EclipseXml.IDEA_SETTINGS_POSTFIX;
|
||||
if (documentSet.exists(eml)) {
|
||||
IdeaSpecificSettings.readIDEASpecific(model, documentSet, eml);
|
||||
new IdeaSpecificSettings().readIdeaSpecific(documentSet.read(eml, false), model, null, new HashMap<String, String>());
|
||||
}
|
||||
else {
|
||||
model.getModuleExtension(CompilerModuleExtension.class).setExcludeOutput(false);
|
||||
@@ -217,14 +216,11 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
|
||||
|
||||
((RootModelImpl)model).writeExternal(element);
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
throw new InvalidDataException(e);
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
throw new InvalidDataException(e);
|
||||
throw new IOException(e);
|
||||
}
|
||||
catch (JDOMException e) {
|
||||
throw new InvalidDataException(e);
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +233,7 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
|
||||
|
||||
Element element;
|
||||
try {
|
||||
element = fileSet.read(EclipseXml.CLASSPATH_FILE).getRootElement();
|
||||
element = fileSet.read(EclipseXml.CLASSPATH_FILE);
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
element = null;
|
||||
@@ -245,7 +241,7 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
|
||||
|
||||
if (element != null || model.getSourceRoots().length > 0 || model.getOrderEntries().length > 2) {
|
||||
classpathWriter.writeClasspath(classpathElement, element);
|
||||
fileSet.write(new Document(classpathElement), EclipseXml.CLASSPATH_FILE);
|
||||
fileSet.write(classpathElement, EclipseXml.CLASSPATH_FILE);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -255,10 +251,10 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider
|
||||
DotProjectFileHelper.saveDotProjectFile(module, fileSet.getParent(EclipseXml.PROJECT_FILE));
|
||||
}
|
||||
|
||||
final Element ideaSpecific = new Element(IdeaXml.COMPONENT_TAG);
|
||||
final String emlFilename = model.getModule().getName() + EclipseXml.IDEA_SETTINGS_POSTFIX;
|
||||
Element ideaSpecific = new Element(IdeaXml.COMPONENT_TAG);
|
||||
String emlFilename = model.getModule().getName() + EclipseXml.IDEA_SETTINGS_POSTFIX;
|
||||
if (IdeaSpecificSettings.writeIDEASpecificClasspath(ideaSpecific, model)) {
|
||||
fileSet.write(new Document(ideaSpecific), emlFilename);
|
||||
fileSet.write(ideaSpecific, emlFilename);
|
||||
}
|
||||
else {
|
||||
fileSet.delete(emlFilename);
|
||||
|
||||
+10
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,7 +29,6 @@ import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jdom.output.EclipseJDOMUtil;
|
||||
import org.jetbrains.idea.eclipse.EclipseXml;
|
||||
@@ -45,19 +44,22 @@ public class DotProjectFileHelper {
|
||||
|
||||
public static void saveDotProjectFile(Module module, String storageRoot) throws IOException {
|
||||
try {
|
||||
final Document doc;
|
||||
Document doc;
|
||||
if (ModuleType.get(module) instanceof JavaModuleType) {
|
||||
doc = JDOMUtil.loadDocument(DotProjectFileHelper.class.getResource("template.project.xml"));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
doc = JDOMUtil.loadDocument(DotProjectFileHelper.class.getResource("template.empty.project.xml"));
|
||||
}
|
||||
|
||||
final Element nameElement = doc.getRootElement().getChild(EclipseXml.NAME_TAG);
|
||||
nameElement.setText(module.getName());
|
||||
doc.getRootElement().getChild(EclipseXml.NAME_TAG).setText(module.getName());
|
||||
|
||||
final File projectFile = new File(storageRoot, EclipseXml.PROJECT_FILE);
|
||||
if (!FileUtil.createIfDoesntExist(projectFile)) return;
|
||||
EclipseJDOMUtil.output(doc, projectFile, module.getProject());
|
||||
if (!FileUtil.createIfDoesntExist(projectFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
EclipseJDOMUtil.output(doc.getRootElement(), projectFile, module.getProject());
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(projectFile.getPath()));
|
||||
|
||||
+2
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,6 @@ import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -42,15 +41,12 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.eclipse.IdeaXml;
|
||||
import org.jetbrains.idea.eclipse.config.CachedXmlDocumentSet;
|
||||
import org.jetbrains.idea.eclipse.config.EclipseModuleManagerImpl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.idea.eclipse.conversion.EPathUtil.areUrlsPointTheSame;
|
||||
@@ -70,13 +66,6 @@ public class IdeaSpecificSettings extends AbstractIdeaSpecificSettings<Modifiabl
|
||||
@NonNls private static final String JAVADOCROOT_ATTR = "javadocroot_attr";
|
||||
public static final String INHERIT_JDK = "inheritJdk";
|
||||
|
||||
private IdeaSpecificSettings() {
|
||||
}
|
||||
|
||||
public static void readIDEASpecific(ModifiableRootModel model, CachedXmlDocumentSet documentSet, String eml) throws InvalidDataException, IOException, JDOMException {
|
||||
new IdeaSpecificSettings().readIDEASpecific(documentSet.read(eml, false).getRootElement(), model, null, new HashMap<String, String>());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readLibraryLevels(Element root, Map<String, String> levels) {
|
||||
}
|
||||
@@ -151,7 +140,7 @@ public class IdeaSpecificSettings extends AbstractIdeaSpecificSettings<Modifiabl
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readLanguageLevel(Element root, ModifiableRootModel model) throws InvalidDataException {
|
||||
protected void readLanguageLevel(Element root, ModifiableRootModel model) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtensionImpl.class).readExternal(root);
|
||||
}
|
||||
|
||||
|
||||
+14
-12
@@ -36,7 +36,6 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.output.EclipseJDOMUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -122,24 +121,27 @@ public class ExportEclipseProjectsAction extends AnAction implements DumbAware {
|
||||
}
|
||||
else {
|
||||
for (Module module : dialog.getSelectedModules()) {
|
||||
final ModuleRootModel model = ModuleRootManager.getInstance(module);
|
||||
final VirtualFile[] contentRoots = model.getContentRoots(); //todo
|
||||
final String storageRoot =
|
||||
contentRoots.length == 1 ? contentRoots[0].getPath() : ClasspathStorage.getStorageRootFromOptions(module);
|
||||
ModuleRootModel model = ModuleRootManager.getInstance(module);
|
||||
VirtualFile[] contentRoots = model.getContentRoots();
|
||||
String storageRoot = contentRoots.length == 1 ? contentRoots[0].getPath() : ClasspathStorage.getStorageRootFromOptions(module);
|
||||
try {
|
||||
Element classpathElement = new Element(EclipseXml.CLASSPATH_TAG);
|
||||
|
||||
final EclipseClasspathWriter classpathWriter = new EclipseClasspathWriter(model);
|
||||
EclipseClasspathWriter classpathWriter = new EclipseClasspathWriter(model);
|
||||
classpathWriter.writeClasspath(classpathElement, null);
|
||||
final File classpathFile = new File(storageRoot, EclipseXml.CLASSPATH_FILE);
|
||||
if (!FileUtil.createIfDoesntExist(classpathFile)) continue;
|
||||
EclipseJDOMUtil.output(new Document(classpathElement), classpathFile, project);
|
||||
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)) {
|
||||
final File emlFile = new File(storageRoot, module.getName() + EclipseXml.IDEA_SETTINGS_POSTFIX);
|
||||
if (!FileUtil.createIfDoesntExist(emlFile)) continue;
|
||||
EclipseJDOMUtil.output(new Document(ideaSpecific), emlFile, project);
|
||||
File emlFile = new File(storageRoot, module.getName() + EclipseXml.IDEA_SETTINGS_POSTFIX);
|
||||
if (!FileUtil.createIfDoesntExist(emlFile)) {
|
||||
continue;
|
||||
}
|
||||
EclipseJDOMUtil.output(ideaSpecific, emlFile, project);
|
||||
}
|
||||
|
||||
DotProjectFileHelper.saveDotProjectFile(module, storageRoot);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -79,13 +79,10 @@ public class EclipseEmlTest extends IdeaTestCase {
|
||||
replaceRoot(path, EclipseXml.DOT_CLASSPATH_EXT, project);
|
||||
|
||||
|
||||
final EclipseClasspathStorageProvider.EclipseClasspathConverter converter =
|
||||
new EclipseClasspathStorageProvider.EclipseClasspathConverter(module);
|
||||
EclipseClasspathStorageProvider.EclipseClasspathConverter converter = new EclipseClasspathStorageProvider.EclipseClasspathConverter(module);
|
||||
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
|
||||
final Element classpathElement =
|
||||
JDOMUtil.loadDocument(FileUtil.loadFile(new File(path, EclipseXml.DOT_CLASSPATH_EXT))).getRootElement();
|
||||
converter.getClasspath(rootModel, classpathElement);
|
||||
converter.getClasspath(rootModel, JDOMUtil.load(new File(path, EclipseXml.DOT_CLASSPATH_EXT)));
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
rootModel.commit();
|
||||
|
||||
Reference in New Issue
Block a user