/*
- * 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.
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)
/*
- * 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.
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;
return moduleLoader;
}
+ @Override
@NotNull
public Module createModule(@NotNull ModifiableModuleModel moduleModel)
throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException {
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();
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 + "$");
/*
- * 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.
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();
myUpdaters.add(updater);
}
+ @Override
public boolean hasRootsFromOtherDetectors(ProjectStructureDetector thisDetector) {
for (ProjectStructureDetector projectStructureDetector : Extensions.getExtensions(ProjectStructureDetector.EP_NAME)) {
if (projectStructureDetector != thisDetector && !getProjectRoots(projectStructureDetector).isEmpty()) {
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);
}
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);
}
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);
/*
- * 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.
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;
}
}
+/*
+ * 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;
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;
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));
}
}
- 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");
}
}
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();
/*
- * 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.
return new Element("application");
}
try {
- return JDOMUtil.loadDocument(configFile).getRootElement();
+ return JDOMUtil.load(configFile);
}
catch (JDOMException e) {
throw new RuntimeException(e);
/*
- * 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.
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);
}
catch (InterruptedException ignored) { }
}
- return JDOMUtil.loadDocument(file).getRootElement();
+ return JDOMUtil.load(file);
}
}
/*
- * 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.
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) {
/*
- * 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.
}
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) {
}
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) {
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();
/*
- * 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.
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;
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;
@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);
}
};
}
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);
}
});
}
}
};
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);
}
}
});
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);
}
}
/*
- * 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.
@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);
}
}
/*
- * 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.
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 {
@Nullable
public abstract VirtualFile getFile(@NotNull Project project);
-
+
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getProject();
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();
}
}
}
-
+
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]);
}
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) {
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)) {
/*
- * 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.
* 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;
CLASS_STRATEGY_CACHE.put(aClass, determineLookupStrategy(substitutor));
}
}
-
+
private static FileSystemLocation computeClassLocation(Class<?> clazz) {
String classRootPath = PathManager.getJarPathForClass(clazz);
if (classRootPath == null) {
}
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) {
/*
- * 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.
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);
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;
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;
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);
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();
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
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;
}
}
- @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());
}
/*
- * 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.
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;
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")) {
/*
- * 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.
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;
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;
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) {
/*
- * 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.
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;
}
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);
}
+/*
+ * 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;
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 {
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);
}
/*
- * 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.
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);
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);
}
/*
- * 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.
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;
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);
/*
- * 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.
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;
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());
}
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);
}
});
}
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();
+/*
+ * 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;
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;
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);
/*
- * 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.
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>();