From f9830d60906fc51e6b4abb03dae6b93b86a7cb14 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 2 May 2016 15:14:19 +0200 Subject: [PATCH] =?UTF-8?q?cleanup=20=E2=80=94=20getRootElement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/scripts/moduleLoader.gant | 4 +- .../projectWizard/ExistingModuleLoader.java | 10 +- .../impl/ProjectFromSourcesBuilderImpl.java | 17 ++- .../InspectionProfilesConverterTest.java | 6 +- .../hierarchy/HierarchyViewTestBase.java | 38 +++--- .../serialization/JpsGlobalElementSaver.java | 4 +- .../model/serialization/JpsLoaderBase.java | 6 +- .../InspectionProfileLoadUtil.java | 4 +- .../ide/impl/convert/JDomConvertingUtil.java | 39 +----- .../header/InspectionToolsConfigurable.java | 124 ++++++++---------- .../com/intellij/core/CoreProjectLoader.java | 4 +- .../actions/AbstractImportTestsAction.java | 38 ++---- .../openapi/application/ex/PathManagerEx.java | 8 +- .../testFramework/InspectionTestUtil.java | 6 +- .../com/intellij/openapi/util/JDOMUtil.java | 99 -------------- .../options/ExternalOptionHelper.java | 13 +- .../JpsPluginSyntheticArtifactProvider.java | 6 +- .../src/EclipseProjectFinder.java | 14 +- .../model/JpsEclipseClasspathSerializer.java | 22 +++- .../idea/eclipse/EclipseImlTest.java | 11 +- .../impl/JpsGradleExtensionServiceImpl.java | 6 +- ...esourceCompilerConfigurationGenerator.java | 32 ++--- .../impl/JpsMavenExtensionServiceImpl.java | 19 ++- .../maven/indices/MavenIndicesManager.java | 6 +- 24 files changed, 201 insertions(+), 335 deletions(-) diff --git a/build/scripts/moduleLoader.gant b/build/scripts/moduleLoader.gant index 50dcda444624..d3c6597e296c 100644 --- a/build/scripts/moduleLoader.gant +++ b/build/scripts/moduleLoader.gant @@ -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(), 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) diff --git a/java/idea-ui/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java b/java/idea-ui/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java index c545cca19bf1..cb458b2493fb 100644 --- a/java/idea-ui/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java +++ b/java/idea-ui/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java @@ -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 usedMacros = PathMacrosCollector.getMacroNames(root); final Set definedMacros = PathMacros.getInstance().getAllMacroNames(); usedMacros.remove("$" + PathMacrosImpl.MODULE_DIR_MACRO_NAME + "$"); diff --git a/java/idea-ui/src/com/intellij/ide/util/projectWizard/importSources/impl/ProjectFromSourcesBuilderImpl.java b/java/idea-ui/src/com/intellij/ide/util/projectWizard/importSources/impl/ProjectFromSourcesBuilderImpl.java index 26e133464ebd..5e84612e1b34 100644 --- a/java/idea-ui/src/com/intellij/ide/util/projectWizard/importSources/impl/ProjectFromSourcesBuilderImpl.java +++ b/java/idea-ui/src/com/intellij/ide/util/projectWizard/importSources/impl/ProjectFromSourcesBuilderImpl.java @@ -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 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 modules = new ArrayList(); for (DetectedProjectRoot root : roots) { if (root instanceof DetectedContentRoot) { - modules.add(new ModuleDescriptor(root.getDirectory(), ((DetectedContentRoot)root).getModuleType(), Collections.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); diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java index d74923370e6e..c8710e6e290c 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java @@ -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; } } diff --git a/java/testFramework/src/com/intellij/testFramework/codeInsight/hierarchy/HierarchyViewTestBase.java b/java/testFramework/src/com/intellij/testFramework/codeInsight/hierarchy/HierarchyViewTestBase.java index 5e6a31fb1dfa..9a249e4d2993 100755 --- a/java/testFramework/src/com/intellij/testFramework/codeInsight/hierarchy/HierarchyViewTestBase.java +++ b/java/testFramework/src/com/intellij/testFramework/codeInsight/hierarchy/HierarchyViewTestBase.java @@ -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() { - @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() { - @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 iterator = expectedChildren.iterator(); diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsGlobalElementSaver.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsGlobalElementSaver.java index eee77c804894..736a0036d3f9 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsGlobalElementSaver.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsGlobalElementSaver.java @@ -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); diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsLoaderBase.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsLoaderBase.java index 9825cb4ed516..88af24c3a2d8 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsLoaderBase.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsLoaderBase.java @@ -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); } } diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProfileLoadUtil.java b/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProfileLoadUtil.java index 7595ebe0d62d..83c06dc51f20 100644 --- a/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProfileLoadUtil.java +++ b/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProfileLoadUtil.java @@ -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) { diff --git a/platform/lang-impl/src/com/intellij/ide/impl/convert/JDomConvertingUtil.java b/platform/lang-impl/src/com/intellij/ide/impl/convert/JDomConvertingUtil.java index 21e55f9ab089..29990f4cb6d5 100644 --- a/platform/lang-impl/src/com/intellij/ide/impl/convert/JDomConvertingUtil.java +++ b/platform/lang-impl/src/com/intellij/ide/impl/convert/JDomConvertingUtil.java @@ -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 createAttributeValueFilter(@NonNls final String name, @NonNls final Collection value) { - return new Condition() { - @Override - public boolean value(final Element element) { - return value.contains(element.getAttributeValue(name)); - } - }; + return element -> value.contains(element.getAttributeValue(name)); } public static Condition 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.alwaysTrue()); + copyChildren(from, to, Conditions.alwaysTrue()); } public static void copyChildren(Element from, Element to, Condition filter) { final List list = from.getChildren(); for (Element element : list) { if (filter.value(element)) { - to.addContent((Element)element.clone()); + to.addContent(element.clone()); } } } public static Condition createElementNameFilter(@NonNls final String elementName) { - return new Condition() { - @Override - public boolean value(final Element element) { - return elementName.equals(element.getName()); - } - }; + return element -> elementName.equals(element.getName()); } public static List removeChildren(final Element element, final Condition filter) { @@ -145,25 +135,6 @@ public class JDomConvertingUtil extends JDomSerializationUtil { return element; } - public static void addChildAfter(final Element parent, final Element child, final Condition 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 filter) { final List list = parent.getChildren(); diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java index 4e5234445b24..a70a3dafc0a3 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java @@ -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() { - @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() { - @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); + } + 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); - } + //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); } } diff --git a/platform/projectModel-impl/src/com/intellij/core/CoreProjectLoader.java b/platform/projectModel-impl/src/com/intellij/core/CoreProjectLoader.java index 2a33411b15fe..9e5bd02c9ba2 100644 --- a/platform/projectModel-impl/src/com/intellij/core/CoreProjectLoader.java +++ b/platform/projectModel-impl/src/com/intellij/core/CoreProjectLoader.java @@ -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 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); } } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/history/actions/AbstractImportTestsAction.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/history/actions/AbstractImportTestsAction.java index 17be3356e8b2..c5b16f374eab 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/history/actions/AbstractImportTestsAction.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/history/actions/AbstractImportTestsAction.java @@ -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() { - @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)) { diff --git a/platform/testFramework/src/com/intellij/openapi/application/ex/PathManagerEx.java b/platform/testFramework/src/com/intellij/openapi/application/ex/PathManagerEx.java index d417ea7ade77..b7bcdcf94d57 100644 --- a/platform/testFramework/src/com/intellij/openapi/application/ex/PathManagerEx.java +++ b/platform/testFramework/src/com/intellij/openapi/application/ex/PathManagerEx.java @@ -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) { diff --git a/platform/testFramework/src/com/intellij/testFramework/InspectionTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/InspectionTestUtil.java index eef33713165d..e44c9650d9eb 100644 --- a/platform/testFramework/src/com/intellij/testFramework/InspectionTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/InspectionTestUtil.java @@ -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); diff --git a/platform/util/src/com/intellij/openapi/util/JDOMUtil.java b/platform/util/src/com/intellij/openapi/util/JDOMUtil.java index 9c7a2d6b163d..22ca5440df47 100644 --- a/platform/util/src/com/intellij/openapi/util/JDOMUtil.java +++ b/platform/util/src/com/intellij/openapi/util/JDOMUtil.java @@ -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 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 getChildrenFromAllNamespaces(@NotNull final Element element, @NotNull @NonNls final String name) { - List result = new SmartList(); - 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 attributes = element.getAttributes(); - if (!attributes.isEmpty()) { - ArrayList list = new ArrayList(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()); } diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/options/ExternalOptionHelper.java b/plugins/copyright/src/com/maddyhome/idea/copyright/options/ExternalOptionHelper.java index f5f971a37abe..dd410cf69dc3 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/options/ExternalOptionHelper.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/options/ExternalOptionHelper.java @@ -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 loadOptions(File file) { try { List profiles = new ArrayList(); - 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")) { diff --git a/plugins/devkit/jps-plugin/src/org/jetbrains/jps/devkit/builder/JpsPluginSyntheticArtifactProvider.java b/plugins/devkit/jps-plugin/src/org/jetbrains/jps/devkit/builder/JpsPluginSyntheticArtifactProvider.java index b432f86b3fe2..a31b2e41411d 100644 --- a/plugins/devkit/jps-plugin/src/org/jetbrains/jps/devkit/builder/JpsPluginSyntheticArtifactProvider.java +++ b/plugins/devkit/jps-plugin/src/org/jetbrains/jps/devkit/builder/JpsPluginSyntheticArtifactProvider.java @@ -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) { diff --git a/plugins/eclipse/common-eclipse-util/src/EclipseProjectFinder.java b/plugins/eclipse/common-eclipse-util/src/EclipseProjectFinder.java index a22a4066c38b..f72e313fb4d0 100644 --- a/plugins/eclipse/common-eclipse-util/src/EclipseProjectFinder.java +++ b/plugins/eclipse/common-eclipse-util/src/EclipseProjectFinder.java @@ -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); } diff --git a/plugins/eclipse/jps-plugin/src/org/jetbrains/jps/eclipse/model/JpsEclipseClasspathSerializer.java b/plugins/eclipse/jps-plugin/src/org/jetbrains/jps/eclipse/model/JpsEclipseClasspathSerializer.java index c7124f8ca8ea..104e6ad0256f 100644 --- a/plugins/eclipse/jps-plugin/src/org/jetbrains/jps/eclipse/model/JpsEclipseClasspathSerializer.java +++ b/plugins/eclipse/jps-plugin/src/org/jetbrains/jps/eclipse/model/JpsEclipseClasspathSerializer.java @@ -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(), 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); } diff --git a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImlTest.java b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImlTest.java index 9cf5e2295d1c..8a2f6ed77023 100644 --- a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImlTest.java +++ b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImlTest.java @@ -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); } diff --git a/plugins/gradle/jps-plugin/src/org/jetbrains/jps/gradle/model/impl/JpsGradleExtensionServiceImpl.java b/plugins/gradle/jps-plugin/src/org/jetbrains/jps/gradle/model/impl/JpsGradleExtensionServiceImpl.java index 81ed9076f13e..477213d7a033 100644 --- a/plugins/gradle/jps-plugin/src/org/jetbrains/jps/gradle/model/impl/JpsGradleExtensionServiceImpl.java +++ b/plugins/gradle/jps-plugin/src/org/jetbrains/jps/gradle/model/impl/JpsGradleExtensionServiceImpl.java @@ -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); diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleResourceCompilerConfigurationGenerator.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleResourceCompilerConfigurationGenerator.java index 1ac9c000a39f..87f603606473 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleResourceCompilerConfigurationGenerator.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleResourceCompilerConfigurationGenerator.java @@ -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 actualModules = myModulesConfigurationHash.keySet(); diff --git a/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/impl/JpsMavenExtensionServiceImpl.java b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/impl/JpsMavenExtensionServiceImpl.java index 991f428d74ba..c40aa7ed9f8b 100644 --- a/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/impl/JpsMavenExtensionServiceImpl.java +++ b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/impl/JpsMavenExtensionServiceImpl.java @@ -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); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java index cb5c1ec75a03..3bd2e369b31c 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java @@ -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 result = new LinkedHashSet();