cleanup — getRootElement
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Mon, 2 May 2016 13:14:19 +0000 (15:14 +0200)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Mon, 2 May 2016 14:54:00 +0000 (16:54 +0200)
24 files changed:
build/scripts/moduleLoader.gant
java/idea-ui/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java
java/idea-ui/src/com/intellij/ide/util/projectWizard/importSources/impl/ProjectFromSourcesBuilderImpl.java
java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java
java/testFramework/src/com/intellij/testFramework/codeInsight/hierarchy/HierarchyViewTestBase.java
jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsGlobalElementSaver.java
jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsLoaderBase.java
platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProfileLoadUtil.java
platform/lang-impl/src/com/intellij/ide/impl/convert/JDomConvertingUtil.java
platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java
platform/projectModel-impl/src/com/intellij/core/CoreProjectLoader.java
platform/smRunner/src/com/intellij/execution/testframework/sm/runner/history/actions/AbstractImportTestsAction.java
platform/testFramework/src/com/intellij/openapi/application/ex/PathManagerEx.java
platform/testFramework/src/com/intellij/testFramework/InspectionTestUtil.java
platform/util/src/com/intellij/openapi/util/JDOMUtil.java
plugins/copyright/src/com/maddyhome/idea/copyright/options/ExternalOptionHelper.java
plugins/devkit/jps-plugin/src/org/jetbrains/jps/devkit/builder/JpsPluginSyntheticArtifactProvider.java
plugins/eclipse/common-eclipse-util/src/EclipseProjectFinder.java
plugins/eclipse/jps-plugin/src/org/jetbrains/jps/eclipse/model/JpsEclipseClasspathSerializer.java
plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImlTest.java
plugins/gradle/jps-plugin/src/org/jetbrains/jps/gradle/model/impl/JpsGradleExtensionServiceImpl.java
plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleResourceCompilerConfigurationGenerator.java
plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/impl/JpsMavenExtensionServiceImpl.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java

index 50dcda444624a9dd3e8161fff8112c99b75b41b3..d3c6597e296c96388b84e7889b29fa386ce6baef 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -34,7 +34,7 @@ binding.setVariable("loadModule", {File moduleFile ->
   def moduleName = FileUtil.getNameWithoutExtension(moduleFile)
   def module = JpsElementFactory.instance.createModule(moduleName, JpsJavaModuleType.INSTANCE, JpsElementFactory.instance.createDummyElement())
   def expander = createModuleMacroExpander(new HashMap<String, String>(), moduleFile)
-  def rootElement = JDOMUtil.loadDocument(moduleFile).rootElement
+  def rootElement = JDOMUtil.load(moduleFile)
   expander.substitute(rootElement, SystemInfo.isFileSystemCaseSensitive)
   JpsModuleRootModelSerializer.loadRootModel(module, JDomSerializationUtil.findComponent(rootElement, "NewModuleRootManager"),
                                              JpsJavaSdkType.INSTANCE)
index c545cca19bf14a26013ade3a5ebf27e01fc392ae..cb458b2493fb401c3965ebd891bc96b458a47799 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -34,7 +34,6 @@ import com.intellij.openapi.roots.ModifiableRootModel;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.InvalidDataException;
 import com.intellij.openapi.util.JDOMUtil;
-import org.jdom.Document;
 import org.jdom.Element;
 import org.jdom.JDOMException;
 import org.jetbrains.annotations.NotNull;
@@ -62,6 +61,7 @@ public class ExistingModuleLoader extends ModuleBuilder {
     return moduleLoader;
   }
 
+  @Override
   @NotNull
   public Module createModule(@NotNull ModifiableModuleModel moduleModel)
     throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException {
@@ -75,14 +75,17 @@ public class ExistingModuleLoader extends ModuleBuilder {
     return moduleModel.loadModule(moduleFilePath);
   }
 
+  @Override
   public void setupRootModel(ModifiableRootModel modifiableRootModel) throws ConfigurationException {
     // empty
   }
 
+  @Override
   public ModuleType getModuleType() {
     return null; // no matter
   }
 
+  @Override
   public boolean validate(final Project current, final Project dest) {
     if (getName() == null) return false;
     String moduleFilePath = getModuleFilePath();
@@ -94,8 +97,7 @@ public class ExistingModuleLoader extends ModuleBuilder {
         if (result.openingIsCanceled()) {
           return false;
         }
-        final Document document = JDOMUtil.loadDocument(file);
-        final Element root = document.getRootElement();
+        final Element root = JDOMUtil.load(file);
         final Set<String> usedMacros = PathMacrosCollector.getMacroNames(root);
         final Set<String> definedMacros = PathMacros.getInstance().getAllMacroNames();
         usedMacros.remove("$" + PathMacrosImpl.MODULE_DIR_MACRO_NAME + "$");
index 26e133464ebdf481b57d50a7fde72d4f661f6317..5e84612e1b343bd039d99a49b367dfe62c803684 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -166,10 +166,12 @@ public class ProjectFromSourcesBuilderImpl extends ProjectImportBuilder implemen
   public void setOpenProjectSettingsAfter(boolean on) {
   }
 
+  @Override
   public void setFileToImport(String path) {
     setBaseProjectPath(path);
   }
 
+  @Override
   public List<Module> commit(@NotNull final Project project, final ModifiableModuleModel model, final ModulesProvider modulesProvider) {
     final boolean fromProjectStructure = model != null;
     ModifiableModelsProvider modelsProvider = new IdeaModifiableModelsProvider();
@@ -306,6 +308,7 @@ public class ProjectFromSourcesBuilderImpl extends ProjectImportBuilder implemen
     myUpdaters.add(updater);
   }
 
+  @Override
   public boolean hasRootsFromOtherDetectors(ProjectStructureDetector thisDetector) {
     for (ProjectStructureDetector projectStructureDetector : Extensions.getExtensions(ProjectStructureDetector.EP_NAME)) {
       if (projectStructureDetector != thisDetector && !getProjectRoots(projectStructureDetector).isEmpty()) {
@@ -321,7 +324,7 @@ public class ProjectFromSourcesBuilderImpl extends ProjectImportBuilder implemen
       List<ModuleDescriptor> modules = new ArrayList<ModuleDescriptor>();
       for (DetectedProjectRoot root : roots) {
         if (root instanceof DetectedContentRoot) {
-          modules.add(new ModuleDescriptor(root.getDirectory(), ((DetectedContentRoot)root).getModuleType(), Collections.<DetectedSourceRoot>emptyList()));
+          modules.add(new ModuleDescriptor(root.getDirectory(), ((DetectedContentRoot)root).getModuleType(), Collections.emptyList()));
         }
       }
       projectDescriptor.setModules(modules);
@@ -405,10 +408,10 @@ public class ProjectFromSourcesBuilderImpl extends ProjectImportBuilder implemen
   }
 
   private static boolean isTestRootName(final String name) {
-    return "test".equalsIgnoreCase(name) || 
-           "tests".equalsIgnoreCase(name) || 
-           "testSource".equalsIgnoreCase(name) || 
-           "testSources".equalsIgnoreCase(name) || 
+    return "test".equalsIgnoreCase(name) ||
+           "tests".equalsIgnoreCase(name) ||
+           "testSource".equalsIgnoreCase(name) ||
+           "testSources".equalsIgnoreCase(name) ||
            "testSrc".equalsIgnoreCase(name) ||
            "tst".equalsIgnoreCase(name);
   }
@@ -437,7 +440,7 @@ public class ProjectFromSourcesBuilderImpl extends ProjectImportBuilder implemen
     if (moduleDescriptor.isReuseExistingElement()) {
       final File file = new File(moduleDescriptor.computeModuleFilePath());
       if (file.exists()) {
-        final Element rootElement = JDOMUtil.loadDocument(file).getRootElement();
+        final Element rootElement = JDOMUtil.load(file);
         final String type = rootElement.getAttributeValue("type");
         if (type != null) {
           return ModuleTypeManager.getInstance().findByID(type);
index d74923370e6e15f1a59776880928462ccdaaf32b..c8710e6e290c13f54a94cd858fe4d713757de8f3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -44,14 +44,14 @@ public class InspectionProfilesConverterTest extends LightIdeaTestCase {
     try {
       final String relativePath = "/inspection/converter/";
       final File projectFile = new File(JavaTestUtil.getJavaTestDataPath() + relativePath + dirName + "/options.ipr");
-      for (Element element : JDOMUtil.loadDocument(projectFile).getRootElement().getChildren("component")) {
+      for (Element element : JDOMUtil.load(projectFile).getChildren("component")) {
         if (Comparing.strEqual(element.getAttributeValue("name"), "InspectionProjectProfileManager")) {
           final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(getProject());
           profileManager.loadState(element);
 
           Element configElement = profileManager.getState();
           final File file = new File(JavaTestUtil.getJavaTestDataPath() + relativePath + dirName + "/options.after.xml");
-          PlatformTestUtil.assertElementsEqual(JDOMUtil.loadDocument(file).getRootElement(), configElement);
+          PlatformTestUtil.assertElementsEqual(JDOMUtil.load(file), configElement);
           break;
         }
       }
index 5e6a31fb1dfa3014f486c6ad84afa39731908883..9a249e4d2993abc34a58c97c986b7999f4d18e8e 100755 (executable)
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2000-2016 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package com.intellij.testFramework.codeInsight.hierarchy;
 
 import com.intellij.codeInsight.CodeInsightTestCase;
@@ -6,7 +21,6 @@ import com.intellij.ide.hierarchy.HierarchyTreeStructure;
 import com.intellij.openapi.util.Computable;
 import com.intellij.openapi.util.JDOMUtil;
 import com.intellij.openapi.util.io.FileUtil;
-import org.jdom.Document;
 import org.jdom.Element;
 import org.jetbrains.annotations.Nullable;
 
@@ -36,7 +50,7 @@ public abstract class HierarchyViewTestBase extends CodeInsightTestCase {
     final String verificationFilePath = getTestDataPath() + "/" + getBasePath() + "/" + getTestName(false) + "_verification.xml";
     HierarchyTreeStructure structure = treeStructureComputable.compute();
     try {
-      checkHierarchyTreeStructure(structure, JDOMUtil.loadDocument(new File(verificationFilePath)));
+      checkHierarchyTreeStructure(structure, JDOMUtil.load(new File(verificationFilePath)));
     } catch (Throwable e)  {
       assertEquals("XML structure comparison for your convenience, actual failure details BELOW",
                    FileUtil.loadFile(new File(verificationFilePath)), dump(structure, null, 0));
@@ -80,10 +94,9 @@ public abstract class HierarchyViewTestBase extends CodeInsightTestCase {
     }
   }
 
-  private static void checkHierarchyTreeStructure(final HierarchyTreeStructure treeStructure, final Document document) {
+  private static void checkHierarchyTreeStructure(final HierarchyTreeStructure treeStructure, final Element rootElement) {
     final HierarchyNodeDescriptor rootNodeDescriptor = (HierarchyNodeDescriptor)treeStructure.getRootElement();
     rootNodeDescriptor.update();
-    final Element rootElement = document.getRootElement();
     if (rootElement == null || !NODE_ELEMENT_NAME.equals(rootElement.getName())) {
       throw new IllegalArgumentException("Incorrect root element in verification resource");
     }
@@ -130,20 +143,11 @@ public abstract class HierarchyViewTestBase extends CodeInsightTestCase {
     }
     assertEquals(messageBuilder.toString(), expectedChildren.size(), children.length);
 
-    Arrays.sort(children, new Comparator<Object>() {
-      @Override
-      public int compare(final Object first, final Object second) {
-        return ((HierarchyNodeDescriptor)first).getHighlightedText().getText()
-          .compareTo(((HierarchyNodeDescriptor)second).getHighlightedText().getText());
-      }
-    });
+    Arrays.sort(children, (first, second) -> ((HierarchyNodeDescriptor)first).getHighlightedText().getText()
+      .compareTo(((HierarchyNodeDescriptor)second).getHighlightedText().getText()));
 
-    Collections.sort(expectedChildren, new Comparator<Element>() {
-      @Override
-      public int compare(final Element first, final Element second) {
-        return first.getAttributeValue(TEXT_ATTR_NAME).compareTo(second.getAttributeValue(TEXT_ATTR_NAME));
-      }
-    });
+    Collections.sort(expectedChildren,
+                     (first, second) -> first.getAttributeValue(TEXT_ATTR_NAME).compareTo(second.getAttributeValue(TEXT_ATTR_NAME)));
 
     //noinspection unchecked
     final Iterator<Element> iterator = expectedChildren.iterator();
index eee77c804894bcc50e3f428dbc61c3f1cf65d92e..736a0036d3f904c3d09ee21984467c7dad86f358 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -63,7 +63,7 @@ public class JpsGlobalElementSaver {
       return new Element("application");
     }
     try {
-      return JDOMUtil.loadDocument(configFile).getRootElement();
+      return JDOMUtil.load(configFile);
     }
     catch (JDOMException e) {
       throw new RuntimeException(e);
index 9825cb4ed5168722a93e32c4239495ddf591b0e2..88af24c3a2d86cab93aa6e14b709e5f946594ab5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -83,7 +83,7 @@ public abstract class JpsLoaderBase {
   private static Element tryLoadRootElement(File file) throws IOException, JDOMException {
     for (int i = 0; i < MAX_ATTEMPTS - 1; i++) {
       try {
-        return JDOMUtil.loadDocument(file).getRootElement();
+        return JDOMUtil.load(file);
       }
       catch (Exception e) {
         LOG.info("Loading attempt #" + i + " failed", e);
@@ -95,6 +95,6 @@ public abstract class JpsLoaderBase {
       }
       catch (InterruptedException ignored) { }
     }
-    return JDOMUtil.loadDocument(file).getRootElement();
+    return JDOMUtil.load(file);
   }
 }
index 7595ebe0d62d22a289b4a5d1c9ebeb65a6ba58c1..83c06dc51f20cb9e885cd5d5099dfd979ecdce2f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -60,7 +60,7 @@ public class InspectionProfileLoadUtil {
   public static Profile load(@NotNull File file,
                              @NotNull InspectionToolRegistrar registrar,
                              @NotNull ProfileManager profileManager) throws JDOMException, IOException, InvalidDataException {
-    Element element = JDOMUtil.loadDocument(file).getRootElement();
+    Element element = JDOMUtil.load(file);
     InspectionProfileImpl profile = new InspectionProfileImpl(getProfileName(file, element), registrar, profileManager);
     final Element profileElement = element.getChild(PROFILE_TAG);
     if (profileElement != null) {
index 21e55f9ab08969a03eb906e1b118b6f346bf1da1..29990f4cb6d5480bf1ccb48173098ca599110838 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -78,12 +78,7 @@ public class JDomConvertingUtil extends JDomSerializationUtil {
   }
 
   public static Condition<Element> createAttributeValueFilter(@NonNls final String name, @NonNls final Collection<String> value) {
-    return new Condition<Element>() {
-      @Override
-      public boolean value(final Element element) {
-        return value.contains(element.getAttributeValue(name));
-      }
-    };
+    return element -> value.contains(element.getAttributeValue(name));
   }
 
   public static Condition<Element> createOptionElementFilter(@NonNls final String optionName) {
@@ -103,25 +98,20 @@ public class JDomConvertingUtil extends JDomSerializationUtil {
   }
 
   public static void copyChildren(Element from, Element to) {
-    copyChildren(from, to, Conditions.<Element>alwaysTrue());
+    copyChildren(from, to, Conditions.alwaysTrue());
   }
 
   public static void copyChildren(Element from, Element to, Condition<Element> filter) {
     final List<Element> list = from.getChildren();
     for (Element element : list) {
       if (filter.value(element)) {
-        to.addContent((Element)element.clone());
+        to.addContent(element.clone());
       }
     }
   }
 
   public static Condition<Element> createElementNameFilter(@NonNls final String elementName) {
-    return new Condition<Element>() {
-      @Override
-      public boolean value(final Element element) {
-        return elementName.equals(element.getName());
-      }
-    };
+    return element -> elementName.equals(element.getName());
   }
 
   public static List<Element> removeChildren(final Element element, final Condition<Element> filter) {
@@ -145,25 +135,6 @@ public class JDomConvertingUtil extends JDomSerializationUtil {
     return element;
   }
 
-  public static void addChildAfter(final Element parent, final Element child, final Condition<Element> filter, boolean addFirstIfNotFound) {
-    List list = parent.getContent();
-    for (int i = 0; i < list.size(); i++) {
-      Object o = list.get(i);
-      if (o instanceof Element && filter.value((Element)o)) {
-        if (i < list.size() - 1) {
-          parent.addContent(i + 1, child);
-        }
-        else {
-          parent.addContent(child);
-        }
-        return;
-      }
-    }
-    if (addFirstIfNotFound) {
-      parent.addContent(0, child);
-    }
-  }
-
   @Nullable
   public static Element findChild(Element parent, final Condition<Element> filter) {
     final List<Element> list = parent.getChildren();
index 4e5234445b24f23dcd6543fec7fe9f7a4bfdc052..a70a3dafc0a30236978c433e9451bef850dd610f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -45,7 +45,10 @@ import com.intellij.openapi.options.ConfigurationException;
 import com.intellij.openapi.options.SearchableConfigurable;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.Messages;
-import com.intellij.openapi.util.*;
+import com.intellij.openapi.util.Comparing;
+import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.util.InvalidDataException;
+import com.intellij.openapi.util.JDOMUtil;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.VfsUtilCore;
@@ -59,7 +62,6 @@ import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel;
 import com.intellij.ui.IdeBorderFactory;
 import com.intellij.ui.ListCellRendererWrapper;
 import com.intellij.util.Alarm;
-import com.intellij.util.Consumer;
 import com.intellij.util.SystemProperties;
 import com.intellij.util.containers.HashMap;
 import com.intellij.util.ui.UIUtil;
@@ -185,13 +187,10 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
 
   @Override
   public Runnable enableSearch(final String option) {
-    return new Runnable() {
-      @Override
-      public void run() {
-        SingleInspectionProfilePanel panel = getSelectedPanel();
-        if (panel != null) {
-          panel.setFilter(option);
-        }
+    return () -> {
+      SingleInspectionProfilePanel panel = getSelectedPanel();
+      if (panel != null) {
+        panel.setFilter(option);
       }
     };
   }
@@ -382,30 +381,27 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
       public void export() {
         final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
         descriptor.setDescription("Choose directory to store profile file");
-        FileChooser.chooseFile(descriptor, getProject(), wholePanel, null, new Consumer<VirtualFile>() {
-          @Override
-          public void consume(VirtualFile file) {
-            final Element element = new Element("inspections");
-            try {
-              final SingleInspectionProfilePanel panel = getSelectedPanel();
-              LOG.assertTrue(panel != null);
-              final InspectionProfileImpl profile = getSelectedObject();
-              LOG.assertTrue(true);
-              profile.writeExternal(element);
-              final String filePath =
-                FileUtil.toSystemDependentName(file.getPath()) + File.separator + FileUtil.sanitizeFileName(profile.getName()) + ".xml";
-              if (new File(filePath).isFile()) {
-                if (Messages
-                      .showOkCancelDialog(wholePanel, "File \'" + filePath + "\' already exist. Do you want to overwrite it?", "Warning",
-                                          Messages.getQuestionIcon()) != Messages.OK) {
-                  return;
-                }
+        FileChooser.chooseFile(descriptor, getProject(), wholePanel, null, file -> {
+          final Element element = new Element("inspections");
+          try {
+            final SingleInspectionProfilePanel panel = getSelectedPanel();
+            LOG.assertTrue(panel != null);
+            final InspectionProfileImpl profile = getSelectedObject();
+            LOG.assertTrue(true);
+            profile.writeExternal(element);
+            final String filePath =
+              FileUtil.toSystemDependentName(file.getPath()) + File.separator + FileUtil.sanitizeFileName(profile.getName()) + ".xml";
+            if (new File(filePath).isFile()) {
+              if (Messages
+                    .showOkCancelDialog(wholePanel, "File \'" + filePath + "\' already exist. Do you want to overwrite it?", "Warning",
+                                        Messages.getQuestionIcon()) != Messages.OK) {
+                return;
               }
-              JDOMUtil.writeDocument(new Document(element), filePath, SystemProperties.getLineSeparator());
-            }
-            catch (IOException e1) {
-              LOG.error(e1);
             }
+            JDOMUtil.writeDocument(new Document(element), filePath, SystemProperties.getLineSeparator());
+          }
+          catch (IOException e1) {
+            LOG.error(e1);
           }
         });
       }
@@ -419,38 +415,35 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
           }
         };
         descriptor.setDescription("Choose profile file");
-        FileChooser.chooseFile(descriptor, getProject(), wholePanel, null, new Consumer<VirtualFile>() {
-          @Override
-          public void consume(VirtualFile file) {
-            if (file != null) {
-              final InspectionProfileImpl profile;
-              try {
-                Element rootElement = JDOMUtil.loadDocument(VfsUtilCore.virtualToIoFile(file)).getRootElement();
-                profile = importInspectionProfile(rootElement, myApplicationProfileManager, getProject(), wholePanel);
-                if (getProfilePanel(profile) != null) {
-                  if (Messages.showOkCancelDialog(wholePanel, "Profile with name \'" +
-                                                              profile.getName() +
-                                                              "\' already exists. Do you want to overwrite it?", "Warning",
-                                                  Messages.getInformationIcon()) != Messages.OK) {
-                    return;
-                  }
+        FileChooser.chooseFile(descriptor, getProject(), wholePanel, null, file -> {
+          if (file != null) {
+            final InspectionProfileImpl profile;
+            try {
+              Element rootElement = JDOMUtil.load(VfsUtilCore.virtualToIoFile(file));
+              profile = importInspectionProfile(rootElement, myApplicationProfileManager, getProject(), wholePanel);
+              if (getProfilePanel(profile) != null) {
+                if (Messages.showOkCancelDialog(wholePanel, "Profile with name \'" +
+                                                            profile.getName() +
+                                                            "\' already exists. Do you want to overwrite it?", "Warning",
+                                                Messages.getInformationIcon()) != Messages.OK) {
+                  return;
                 }
-                final ModifiableModel model = profile.getModifiableModel();
-                model.setModified(true);
-                addProfile((InspectionProfileImpl)model, profile);
-
-                //TODO myDeletedProfiles ? really need this
-                myDeletedProfiles.remove(profile);
-              }
-              catch (JDOMException e) {
-                LOG.error(e);
-              }
-              catch (IOException e) {
-                LOG.error(e);
-              }
-              catch (InvalidDataException e) {
-                LOG.error(e);
               }
+              final ModifiableModel model = profile.getModifiableModel();
+              model.setModified(true);
+              addProfile((InspectionProfileImpl)model, profile);
+
+              //TODO myDeletedProfiles ? really need this
+              myDeletedProfiles.remove(profile);
+            }
+            catch (JDOMException e) {
+              LOG.error(e);
+            }
+            catch (IOException e) {
+              LOG.error(e);
+            }
+            catch (InvalidDataException e) {
+              LOG.error(e);
             }
           }
         });
@@ -628,12 +621,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
       panel.setVisible(true);//make sure that UI was initialized
       mySelectionAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
       mySelectionAlarm.cancelAllRequests();
-      mySelectionAlarm.addRequest(new Runnable() {
-        @Override
-        public void run() {
-          panel.updateSelection();
-        }
-      }, 200);
+      mySelectionAlarm.addRequest(panel::updateSelection, 200);
     }
   }
 
index 2a33411b15fe0ab10e1bf9aef3ef745fd8b7c2b4..9e5bd02c9ba2113d7e97a81a7e549803594c8842 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -96,6 +96,6 @@ public class CoreProjectLoader {
 
   @NotNull
   public static TreeMap<String, Element> loadStorageFile(@NotNull ComponentManager componentManager, @NotNull VirtualFile modulesXml) throws JDOMException, IOException {
-    return FileStorageCoreUtil.load(JDOMUtil.loadDocument(modulesXml.contentsToByteArray()).getRootElement(), PathMacroManager.getInstance(componentManager), false);
+    return FileStorageCoreUtil.load(JDOMUtil.load(modulesXml.getInputStream()), PathMacroManager.getInstance(componentManager), false);
   }
 }
index 17be3356e8b2263ebf3d9d9ef3283649e9069dad..c5b16f374eab99a8d4337c0bd5897ed131fa2a1a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -37,22 +37,19 @@ import com.intellij.openapi.util.JDOMUtil;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VfsUtilCore;
 import com.intellij.openapi.vfs.VirtualFile;
-import org.jdom.Document;
 import org.jdom.Element;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.io.File;
-import java.io.FilenameFilter;
 import java.util.Arrays;
-import java.util.Comparator;
 
 /**
  * 1. chooses file where test results were saved
  * 2. finds the configuration element saved during export
  * 3. creates corresponding configuration with {@link SMTRunnerConsoleProperties} if configuration implements {@link SMRunnerConsolePropertiesProvider}
- * 
+ *
  * Without console properties no navigation, no rerun failed is possible.
  */
 public abstract class AbstractImportTestsAction extends AnAction {
@@ -87,7 +84,7 @@ public abstract class AbstractImportTestsAction extends AnAction {
 
   @Nullable
   public abstract VirtualFile getFile(@NotNull Project project);
-  
+
   @Override
   public void actionPerformed(AnActionEvent e) {
     final Project project = e.getProject();
@@ -102,7 +99,7 @@ public abstract class AbstractImportTestsAction extends AnAction {
           LOG.info("Failed to detect test framework in " + file.getPath() +
                    "; use " + (properties != null ? properties.getTestFrameworkName() + " from toolbar" : "no properties"));
         }
-        final Executor executor = properties != null ? properties.getExecutor() 
+        final Executor executor = properties != null ? properties.getExecutor()
                                                      : ExecutorRegistry.getInstance().getExecutorById(DefaultRunExecutor.EXECUTOR_ID);
         ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.create(project, executor, profile);
         ExecutionTarget target = profile.getTarget();
@@ -122,25 +119,19 @@ public abstract class AbstractImportTestsAction extends AnAction {
       }
     }
   }
-  
+
   public static void adjustHistory(Project project) {
     int historySize = getHistorySize();
 
-    final File[] files = TestStateStorage.getTestHistoryRoot(project).listFiles(new FilenameFilter() {
-      @Override
-      public boolean accept(File dir, String name) {
-        return name.endsWith(".xml");
-      }
+    final File[] files = TestStateStorage.getTestHistoryRoot(project).listFiles((dir, name) -> {
+      return name.endsWith(".xml");
     });
     if (files != null && files.length >= historySize + 1) {
-      Arrays.sort(files, new Comparator<File>() {
-        @Override
-        public int compare(File o1, File o2) {
-          final long l1 = o1.lastModified();
-          final long l2 = o2.lastModified();
-          if (l1 == l2) return FileUtil.compareFiles(o1, o2);
-          return l1 < l2 ? -1 : 1;
-        }
+      Arrays.sort(files, (o1, o2) -> {
+        final long l1 = o1.lastModified();
+        final long l2 = o2.lastModified();
+        if (l1 == l2) return FileUtil.compareFiles(o1, o2);
+        return l1 < l2 ? -1 : 1;
       });
       FileUtil.delete(files[0]);
     }
@@ -158,8 +149,7 @@ public abstract class AbstractImportTestsAction extends AnAction {
       myFile = file;
       myProject = project;
       try {
-        final Document document = JDOMUtil.loadDocument(VfsUtilCore.virtualToIoFile(myFile));
-        final Element config = document.getRootElement().getChild("config");
+        final Element config = JDOMUtil.load(VfsUtilCore.virtualToIoFile(myFile)).getChild("config");
         if (config != null) {
           String configTypeId = config.getAttributeValue("configId");
           if (configTypeId != null) {
@@ -189,7 +179,7 @@ public abstract class AbstractImportTestsAction extends AnAction {
         if (DefaultExecutionTarget.INSTANCE.getId().equals(myTargetId)) {
           return DefaultExecutionTarget.INSTANCE;
         }
-        final RunnerAndConfigurationSettingsImpl settings = 
+        final RunnerAndConfigurationSettingsImpl settings =
           new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(myProject), myConfiguration, false);
         for (ExecutionTargetProvider provider : Extensions.getExtensions(ExecutionTargetProvider.EXTENSION_NAME)) {
           for (ExecutionTarget target : provider.getTargets(myProject, settings)) {
index d417ea7ade77cf69a3749ce3a5a7e9898c7daf62..b7bcdcf94d57d1d5b8c09c9db44daedab1fa29ac 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -19,7 +19,7 @@
  * User: mike
  * Date: Aug 19, 2002
  * Time: 8:21:52 PM
- * To change template for new class use 
+ * To change template for new class use
  * Code Style | Class Templates options (Tools | IDE Options).
  */
 package com.intellij.openapi.application.ex;
@@ -369,7 +369,7 @@ public class PathManagerEx {
       CLASS_STRATEGY_CACHE.put(aClass, determineLookupStrategy(substitutor));
     }
   }
-  
+
   private static FileSystemLocation computeClassLocation(Class<?> clazz) {
     String classRootPath = PathManager.getJarPathForClass(clazz);
     if (classRootPath == null) {
@@ -406,7 +406,7 @@ public class PathManagerEx {
     }
 
     try {
-      Element element = JDomSerializationUtil.findComponent(JDOMUtil.loadDocument(modulesXml).getRootElement(), ModuleManagerImpl.COMPONENT_NAME);
+      Element element = JDomSerializationUtil.findComponent(JDOMUtil.load(modulesXml), ModuleManagerImpl.COMPONENT_NAME);
       assert element != null;
       ModuleManagerImpl.ModulePath[] files = ModuleManagerImpl.getPathsToModuleFiles(element);
       for (ModuleManagerImpl.ModulePath file : files) {
index eef33713165d4a7c3a9e324595536775f17fcd4d..e44c9650d9eb5060374c662fbf02d0ae33b5c0e1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -143,9 +143,7 @@ expected:
 
     File file = new File(testDir + "/expected.xml");
     try {
-      Document expectedDocument = JDOMUtil.loadDocument(file);
-
-      compareWithExpected(expectedDocument, doc, checkRange);
+      compareWithExpected(JDOMUtil.loadDocument(file), doc, checkRange);
     }
     catch (Exception e) {
       throw new RuntimeException(e);
index 9c7a2d6b163de9e2e5e352f899fecca3fd7aff63..22ca5440df47fc2f2dc0f2bd5a2f094977e7ff2a 100644 (file)
@@ -19,22 +19,17 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.CharsetToolkit;
 import com.intellij.util.ArrayUtil;
-import com.intellij.util.SmartList;
 import com.intellij.util.containers.StringInterner;
 import com.intellij.util.io.URLUtil;
 import com.intellij.util.text.CharArrayUtil;
 import com.intellij.util.text.CharSequenceReader;
 import com.intellij.util.text.StringFactory;
 import org.jdom.*;
-import org.jdom.filter.ElementFilter;
 import org.jdom.filter.Filter;
-import org.jdom.input.DOMBuilder;
 import org.jdom.input.SAXBuilder;
-import org.jdom.output.DOMOutputter;
 import org.jdom.output.Format;
 import org.jdom.output.XMLOutputter;
 import org.jetbrains.annotations.Contract;
-import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.xml.sax.EntityResolver;
@@ -137,17 +132,6 @@ public class JDOMUtil {
     return list.toArray(new Element[list.size()]);
   }
 
-  @Deprecated
-  @SuppressWarnings("unused")
-  @NotNull
-  public static String concatTextNodesValues(@NotNull final Object[] nodes) {
-    StringBuilder result = new StringBuilder();
-    for (Object node : nodes) {
-      result.append(((Content)node).getValue());
-    }
-    return result.toString();
-  }
-
   public static void addContent(@NotNull final Element targetElement, final Object node) {
     if (node instanceof Content) {
       Content content = (Content)node;
@@ -253,11 +237,6 @@ public class JDOMUtil {
     return getSaxBuilder().build(new CharArrayReader(chars, 0, length));
   }
 
-  @NotNull
-  public static Document loadDocument(byte[] bytes) throws IOException, JDOMException {
-    return loadDocument(new ByteArrayInputStream(bytes));
-  }
-
   private static SAXBuilder getSaxBuilder() {
     SoftReference<SAXBuilder> reference = ourSaxBuilder.get();
     SAXBuilder saxBuilder = com.intellij.reference.SoftReference.dereference(reference);
@@ -305,9 +284,6 @@ public class JDOMUtil {
     return loadDocument(new InputStreamReader(stream, CharsetToolkit.UTF8_CHARSET));
   }
 
-  /**
-   * @deprecated Use com.intellij.util.loadElement
-   */
   @Contract("null -> null; !null -> !null")
   public static Element load(Reader reader) throws JDOMException, IOException {
     return reader == null ? null : loadDocument(reader).detachRootElement();
@@ -548,19 +524,6 @@ public class JDOMUtil {
     return buffer == null ? text : buffer.toString();
   }
 
-  @SuppressWarnings("unused")
-  @Deprecated
-  @NotNull
-  public static List<Element> getChildrenFromAllNamespaces(@NotNull final Element element, @NotNull @NonNls final String name) {
-    List<Element> result = new SmartList<Element>();
-    for (Element child : element.getChildren()) {
-      if (name.equals(child.getName())) {
-        result.add(child);
-      }
-    }
-    return result;
-  }
-
   public static class MyXMLOutputter extends XMLOutputter {
     @Override
     @NotNull
@@ -665,35 +628,6 @@ public class JDOMUtil {
     public boolean hasNullAttributes = false;
   }
 
-  @SuppressWarnings("unused")
-  @Deprecated
-  public static org.w3c.dom.Element convertToDOM(@NotNull Element e) {
-    try {
-      final Document d = new Document();
-      final Element newRoot = new Element(e.getName());
-      final List attributes = e.getAttributes();
-
-      for (Object o : attributes) {
-        Attribute attr = (Attribute)o;
-        newRoot.setAttribute(attr.getName(), attr.getValue(), attr.getNamespace());
-      }
-
-      d.addContent(newRoot);
-      newRoot.addContent(e.cloneContent());
-
-      return new DOMOutputter().output(d).getDocumentElement();
-    }
-    catch (JDOMException e1) {
-      throw new RuntimeException(e1);
-    }
-  }
-
-  @SuppressWarnings("unused")
-  @Deprecated
-  public static Element convertFromDOM(org.w3c.dom.Element e) {
-    return new DOMBuilder().build(e);
-  }
-
   public static String getValue(Object node) {
     if (node instanceof Content) {
       Content content = (Content)node;
@@ -708,39 +642,6 @@ public class JDOMUtil {
     }
   }
 
-  @SuppressWarnings("unused")
-  @Nullable
-  @Deprecated
-  public static Element cloneElement(@NotNull Element element, @NotNull ElementFilter elementFilter) {
-    Element result = new Element(element.getName(), element.getNamespace());
-    List<Attribute> attributes = element.getAttributes();
-    if (!attributes.isEmpty()) {
-      ArrayList<Attribute> list = new ArrayList<Attribute>(attributes.size());
-      for (Attribute attribute : attributes) {
-        list.add(attribute.clone());
-      }
-      result.setAttributes(list);
-    }
-
-    for (Namespace namespace : element.getAdditionalNamespaces()) {
-      result.addNamespaceDeclaration(namespace);
-    }
-
-    boolean hasContent = false;
-    for (Content content : element.getContent()) {
-      if (content instanceof Element) {
-        if (elementFilter.matches(content)) {
-          hasContent = true;
-        }
-        else {
-          continue;
-        }
-      }
-      result.addContent(content.clone());
-    }
-    return hasContent ? result : null;
-  }
-
   public static boolean isEmpty(@Nullable Element element) {
     return element == null || (element.getAttributes().isEmpty() && element.getContent().isEmpty());
   }
index f5f971a37abef40bedda30a6df2bc1051e98f1be..dd410cf69dc3c20ac4267d80317b3d29395c8f99 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -20,7 +20,6 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.JDOMUtil;
 import com.maddyhome.idea.copyright.CopyrightProfile;
-import org.jdom.Document;
 import org.jdom.Element;
 import org.jetbrains.annotations.Nullable;
 
@@ -35,15 +34,13 @@ public class ExternalOptionHelper {
   public static List<CopyrightProfile> loadOptions(File file) {
     try {
       List<CopyrightProfile> profiles = new ArrayList<CopyrightProfile>();
-      Document doc = JDOMUtil.loadDocument(file);
-      Element root = doc.getRootElement();
+      Element root = JDOMUtil.load(file);
       if (root.getName().equals("component")) {
         final Element copyrightElement = root.getChild("copyright");
         if (copyrightElement != null) extractNewNoticeAndKeyword(copyrightElement, profiles);
-      } else {
-        List list = root.getChildren("component");
-        for (Object element : list) {
-          Element component = (Element)element;
+      }
+      else {
+        for (Element component : root.getChildren("component")) {
           String name = component.getAttributeValue("name");
           if (name.equals("CopyrightManager")) {
             for (Object o : component.getChildren("copyright")) {
index b432f86b3fe264901666acda33f875d8444c2928..a31b2e41411de75f90a705609e2df1ee8403f70c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -21,7 +21,6 @@ import com.intellij.openapi.util.io.FileUtil;
 import org.jdom.Element;
 import org.jdom.JDOMException;
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jps.util.JpsPathUtil;
 import org.jetbrains.jps.devkit.model.JpsIdeaSdkProperties;
 import org.jetbrains.jps.devkit.model.JpsIdeaSdkType;
 import org.jetbrains.jps.devkit.model.JpsPluginModuleProperties;
@@ -44,6 +43,7 @@ import org.jetbrains.jps.model.library.JpsOrderRootType;
 import org.jetbrains.jps.model.library.sdk.JpsSdk;
 import org.jetbrains.jps.model.module.JpsModule;
 import org.jetbrains.jps.model.module.JpsTypedModule;
+import org.jetbrains.jps.util.JpsPathUtil;
 
 import java.io.File;
 import java.io.IOException;
@@ -77,7 +77,7 @@ public class JpsPluginSyntheticArtifactProvider extends JpsSyntheticArtifactProv
       File pluginXmlFile = JpsPathUtil.urlToFile(pluginXmlUrl);
       if (pluginXmlFile.exists()) {
         try {
-          Element rootElement = JDOMUtil.loadDocument(pluginXmlFile).getRootElement();
+          Element rootElement = JDOMUtil.load(pluginXmlFile);
           for (Element dependsElement : JDOMUtil.getChildren(rootElement, "depends")) {
             String relativePath = dependsElement.getAttributeValue("config-file");
             if (relativePath != null) {
index a22a4066c38b715c85015572a8df4accc46af7af..f72e313fb4d08c0ce7ea4d1e3b7745b6d61e60c3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -62,7 +62,7 @@ public class EclipseProjectFinder implements EclipseXml {
     final File file = new File(rootPath, DOT_PROJECT_EXT);
     if (file.isFile()) {
       try {
-        name = JDOMUtil.loadDocument(file).getRootElement().getChildText(NAME_TAG);
+        name = JDOMUtil.load(file).getChildText(NAME_TAG);
         if (StringUtil.isEmptyOrSpaces(name)) {
           return null;
         }
@@ -89,19 +89,19 @@ public class EclipseProjectFinder implements EclipseXml {
     final File file = new File(projectPath, DOT_PROJECT_EXT);
     if (file.isFile()) {
       try {
-        for (Object o : JDOMUtil.loadDocument(file).getRootElement().getChildren(LINKED_RESOURCES)) {
-          for (Object l : ((Element)o).getChildren(LINK)) {
-            if (Comparing.strEqual(((Element)l).getChildText(NAME_TAG), resourceName)) {
+        for (Element o : JDOMUtil.load(file).getChildren(LINKED_RESOURCES)) {
+          for (Element l : o.getChildren(LINK)) {
+            if (Comparing.strEqual(l.getChildText(NAME_TAG), resourceName)) {
               LinkedResource linkedResource = new LinkedResource();
               final String relativeToLinkedResourcePath =
                 independentPath.length() > resourceName.length() ? independentPath.substring(resourceName.length()) : "";
 
-              final Element locationURI = ((Element)l).getChild("locationURI");
+              final Element locationURI = l.getChild("locationURI");
               if (locationURI != null) {
                 linkedResource.setURI(FileUtil.toSystemIndependentName(locationURI.getText()) + relativeToLinkedResourcePath);
               }
 
-              final Element location = ((Element)l).getChild("location");
+              final Element location = l.getChild("location");
               if (location != null) {
                 linkedResource.setLocation(FileUtil.toSystemIndependentName(location.getText()) + relativeToLinkedResourcePath);
               }
index c7124f8ca8eacd13240336edd3c8cde885197a34..104e6ad0256f8bea3663a7f31413de7b660cb1e6 100644 (file)
@@ -1,9 +1,23 @@
+/*
+ * Copyright 2000-2016 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.jetbrains.jps.eclipse.model;
 
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.util.JDOMUtil;
 import com.intellij.util.containers.HashSet;
-import org.jdom.Document;
 import org.jdom.Element;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
@@ -51,8 +65,7 @@ public class JpsEclipseClasspathSerializer extends JpsModuleClasspathSerializer
       final JpsIdeaSpecificSettings settings;
       final Element root;
       if (emlFile.isFile()) {
-        final Document emlDocument = JDOMUtil.loadDocument(emlFile);
-        root = emlDocument.getRootElement();
+        root = JDOMUtil.load(emlFile);
         settings = new JpsIdeaSpecificSettings(expander);
         settings.initLevels(root, module, levels);
       } else {
@@ -60,9 +73,8 @@ public class JpsEclipseClasspathSerializer extends JpsModuleClasspathSerializer
         root = null;
       }
 
-      final Document document = JDOMUtil.loadDocument(classpathFile);
       final JpsEclipseClasspathReader reader = new JpsEclipseClasspathReader(classpathDir, paths, new HashSet<String>(), levels);
-      reader.readClasspath(module, null, document.getRootElement(), expander);//todo
+      reader.readClasspath(module, null, JDOMUtil.load(classpathFile), expander);//todo
       if (settings != null) {
         settings.updateEntries(root, module, projectSdkType);
       }
index 9cf5e2295d1ca2e61d8d213dd30be9e35718a8f6..8a2f6ed77023666c93178173239be3957656a9b2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -90,11 +90,7 @@ public class EclipseImlTest extends IdeaTestCase {
     EclipseClasspathReader classpathReader = new EclipseClasspathReader(path, project, null);
     classpathReader.init(rootModel);
     classpathReader.readClasspath(rootModel, classpathElement);
-    ApplicationManager.getApplication().runWriteAction(new Runnable() {
-      public void run() {
-        rootModel.commit();
-      }
-    });
+    ApplicationManager.getApplication().runWriteAction(rootModel::commit);
 
     final Element actualImlElement = new Element("root");
     ((ModuleRootManagerImpl)ModuleRootManager.getInstance(module)).getState().writeExternal(actualImlElement);
@@ -104,8 +100,7 @@ public class EclipseImlTest extends IdeaTestCase {
     PathMacroManager.getInstance(project).collapsePaths(actualImlElement);
     PathMacros.getInstance().removeMacro(JUNIT);
 
-    final Element expectedIml =
-      JDOMUtil.loadDocument(new File(project.getBaseDir().getPath() + "/expected", "expected.iml")).getRootElement();
+    Element expectedIml = JDOMUtil.load(new File(project.getBaseDir().getPath() + "/expected", "expected.iml"));
     PlatformTestUtil.assertElementsEqual(expectedIml, actualImlElement);
   }
 
index 81ed9076f13ea274a29925170c67d838be513e4f..477213d7a0335977b77848e74bb64a0c764725af 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2016 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,7 +22,6 @@ import com.intellij.util.containers.ConcurrentFactoryMap;
 import com.intellij.util.containers.FactoryMap;
 import com.intellij.util.xmlb.XmlSerializer;
 import gnu.trove.THashMap;
-import org.jdom.Document;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.jps.builders.storage.BuildDataPaths;
@@ -122,8 +121,7 @@ public class JpsGradleExtensionServiceImpl extends JpsGradleExtensionService {
       if (config == null) {
         config = new GradleProjectConfiguration();
         try {
-          final Document document = JDOMUtil.loadDocument(configFile);
-          XmlSerializer.deserializeInto(config, document.getRootElement());
+          XmlSerializer.deserializeInto(config, JDOMUtil.load(configFile));
         }
         catch (Exception e) {
           LOG.info(e);
index 1ac9c000a39f6f4e98c8e242f714621d1f5241cd..87f603606473e94c006eb005b89146d64f7f559b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -24,7 +24,6 @@ import com.intellij.openapi.compiler.CompilerMessageCategory;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType;
 import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
-import com.intellij.openapi.externalSystem.util.ExternalSystemConstants;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.ModuleAdapter;
 import com.intellij.openapi.project.Project;
@@ -80,6 +79,7 @@ public class GradleResourceCompilerConfigurationGenerator {
     assert externalProjectDataCache != null;
 
     project.getMessageBus().connect(project).subscribe(ProjectTopics.MODULES, new ModuleAdapter() {
+      @Override
       public void moduleRemoved(@NotNull Project project, @NotNull Module module) {
         myModulesConfigurationHash.remove(module.getName());
       }
@@ -130,20 +130,17 @@ public class GradleResourceCompilerConfigurationGenerator {
     final Document document = new Document(new Element("gradle-project-configuration"));
     XmlSerializer.serializeInto(projectConfig, document.getRootElement());
     final boolean finalConfigurationUpdateRequired = configurationUpdateRequired;
-    buildManager.runCommand(new Runnable() {
-      @Override
-      public void run() {
-        if (finalConfigurationUpdateRequired) {
-          buildManager.clearState(myProject);
-        }
-        FileUtil.createIfDoesntExist(gradleConfigFile);
-        try {
-          JDOMUtil.writeDocument(document, gradleConfigFile, "\n");
-          myModulesConfigurationHash.putAll(affectedConfigurationHash);
-        }
-        catch (IOException e) {
-          throw new RuntimeException(e);
-        }
+    buildManager.runCommand(() -> {
+      if (finalConfigurationUpdateRequired) {
+        buildManager.clearState(myProject);
+      }
+      FileUtil.createIfDoesntExist(gradleConfigFile);
+      try {
+        JDOMUtil.writeDocument(document, gradleConfigFile, "\n");
+        myModulesConfigurationHash.putAll(affectedConfigurationHash);
+      }
+      catch (IOException e) {
+        throw new RuntimeException(e);
       }
     });
   }
@@ -153,8 +150,7 @@ public class GradleResourceCompilerConfigurationGenerator {
     final GradleProjectConfiguration projectConfig = new GradleProjectConfiguration();
     if (gradleConfigFile.exists()) {
       try {
-        final Document document = JDOMUtil.loadDocument(gradleConfigFile);
-        XmlSerializer.deserializeInto(projectConfig, document.getRootElement());
+        XmlSerializer.deserializeInto(projectConfig, JDOMUtil.load(gradleConfigFile));
 
         // filter orphan modules
         final Set<String> actualModules = myModulesConfigurationHash.keySet();
index 991f428d74ba705e6260b81fddfd3d8e740a755f..c40aa7ed9f8b2af495e1a5981ee7cc77e8e50b75 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2000-2016 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.jetbrains.jps.maven.model.impl;
 
 import com.intellij.openapi.diagnostic.Logger;
@@ -7,7 +22,6 @@ import com.intellij.util.containers.ConcurrentFactoryMap;
 import com.intellij.util.containers.FactoryMap;
 import com.intellij.util.xmlb.XmlSerializer;
 import gnu.trove.THashMap;
-import org.jdom.Document;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.jps.builders.storage.BuildDataPaths;
@@ -108,8 +122,7 @@ public class JpsMavenExtensionServiceImpl extends JpsMavenExtensionService {
       if (config == null) {
         config = new MavenProjectConfiguration();
         try {
-          final Document document = JDOMUtil.loadDocument(configFile);
-          XmlSerializer.deserializeInto(config, document.getRootElement());
+          XmlSerializer.deserializeInto(config, JDOMUtil.load(configFile));
         }
         catch (Exception e) {
           LOG.info(e);
index cb5c1ec75a030b1e7d68b92fe76266dab0355bd9..3bd2e369b31c6aac1edfc6feeb7a3a4113ef911c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -335,9 +335,7 @@ public class MavenIndicesManager implements Disposable {
       File file = getUserArchetypesFile();
       if (!file.exists()) return;
 
-      Document doc = JDOMUtil.loadDocument(file);
-      Element root = doc.getRootElement();
-      if (root == null) return;
+      Element root = JDOMUtil.load(file);
 
       // Store artifact to set to remove duplicate created by old IDEA (https://youtrack.jetbrains.com/issue/IDEA-72105)
       Collection<MavenArchetype> result = new LinkedHashSet<MavenArchetype>();