DiffManagerImpl should be persistent component, don't save defaults (COMPARISON_POLICY="Default")

This commit is contained in:
Vladimir Krivosheev
2015-02-23 12:29:27 +01:00
parent 392d15f11b
commit f9174b74f0
17 changed files with 238 additions and 201 deletions
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2009 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.intellij.util.config; package com.intellij.util.config;
import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Comparing;
@@ -28,17 +27,28 @@ public abstract class AbstractProperty<T> {
} }
}; };
@NonNls public abstract String getName(); @NonNls
public abstract String getName();
public abstract T getDefault(AbstractPropertyContainer container); public abstract T getDefault(AbstractPropertyContainer container);
public abstract T copy(T value); public abstract T copy(T value);
public boolean areEqual(T value1, T value2) { public boolean areEqual(T value1, T value2) {
return Comparing.equal(value1, value2); return Comparing.equal(value1, value2);
} }
public T get(AbstractPropertyContainer container) { return (T) container.getValueOf(this); } public T get(AbstractPropertyContainer container) {
public void set(AbstractPropertyContainer container, T value) { container.setValueOf(this, value); } return (T)container.getValueOf(this);
public final T cast(Object value) { return (T) value; } }
public void set(AbstractPropertyContainer container, T value) {
container.setValueOf(this, value);
}
public final T cast(Object value) {
return (T)value;
}
public String toString() { public String toString() {
return getName(); return getName();
@@ -60,7 +70,9 @@ public abstract class AbstractProperty<T> {
}; };
protected abstract Object getValueOf(PropertyImpl property); protected abstract Object getValueOf(PropertyImpl property);
protected abstract void setValueOf(PropertyImpl property, Object value); protected abstract void setValueOf(PropertyImpl property, Object value);
public abstract boolean hasProperty(AbstractProperty property); public abstract boolean hasProperty(AbstractProperty property);
/** /**
@@ -73,7 +85,7 @@ public abstract class AbstractProperty<T> {
/** /**
* Only containers can delegate to another. * Only containers can delegate to another.
* Other clients should use {@link AbstractProperty#get AbstractProperty.get} * Other clients should use {@link AbstractProperty#get AbstractProperty.get}
*/ */
protected final <T> T delegateGet(AbstractPropertyContainer container, AbstractProperty<T> property) { protected final <T> T delegateGet(AbstractPropertyContainer container, AbstractProperty<T> property) {
return (T)container.getValueOf(property); return (T)container.getValueOf(property);
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2009 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,20 +13,28 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.intellij.util.config; package com.intellij.util.config;
import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.*; import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Factory;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.util.SmartList;
import gnu.trove.THashMap;
import org.jdom.Element; import org.jdom.Element;
import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class ExternalizablePropertyContainer extends AbstractProperty.AbstractPropertyContainer implements JDOMExternalizable { public class ExternalizablePropertyContainer extends AbstractProperty.AbstractPropertyContainer {
private static final Logger LOG = Logger.getInstance(ExternalizablePropertyContainer.class); private static final Logger LOG = Logger.getInstance(ExternalizablePropertyContainer.class);
private final Map<AbstractProperty, Object> myValues = new HashMap<AbstractProperty, Object>(); private final Map<AbstractProperty, Object> myValues = new THashMap<AbstractProperty, Object>();
private final Map<AbstractProperty, Externalizer> myExternalizers = new HashMap<AbstractProperty, Externalizer>(); private final Map<AbstractProperty, Externalizer> myExternalizers = new THashMap<AbstractProperty, Externalizer>();
public <T> void registerProperty(AbstractProperty<T> property, Externalizer<T> externalizer) { public <T> void registerProperty(AbstractProperty<T> property, Externalizer<T> externalizer) {
String name = property.getName(); String name = property.getName();
@@ -66,37 +74,34 @@ public class ExternalizablePropertyContainer extends AbstractProperty.AbstractPr
registerProperty(property, itemTagName, Externalizer.FactoryBased.create(factory)); registerProperty(property, itemTagName, Externalizer.FactoryBased.create(factory));
} }
private <T> Externalizer<List<T>> createListExternalizer(final Externalizer<T> itemExternalizer, final String itemTagName) { private static <T> Externalizer<List<T>> createListExternalizer(final Externalizer<T> itemExternalizer, final String itemTagName) {
return new ListExternalizer(itemExternalizer, itemTagName); return new ListExternalizer(itemExternalizer, itemTagName);
} }
@Override public void readExternal(@NotNull Element element) {
public void readExternal(Element element) throws InvalidDataException { Map<String, AbstractProperty> propertyByName = new THashMap<String, AbstractProperty>();
HashMap<String, AbstractProperty> propertyByName = new HashMap<String, AbstractProperty>();
for (AbstractProperty abstractProperty : myExternalizers.keySet()) { for (AbstractProperty abstractProperty : myExternalizers.keySet()) {
propertyByName.put(abstractProperty.getName(), abstractProperty); propertyByName.put(abstractProperty.getName(), abstractProperty);
} }
final List<Element> children = element.getChildren(); for (Element child : element.getChildren()) {
for (Element child : children) {
AbstractProperty property = propertyByName.get(child.getName()); AbstractProperty property = propertyByName.get(child.getName());
if (property == null) { if (property == null) {
continue; continue;
} }
final Externalizer externalizer = myExternalizers.get(property); Externalizer externalizer = myExternalizers.get(property);
if (externalizer == null) { if (externalizer == null) {
continue; continue;
} }
try { try {
myValues.put(property, externalizer.readValue(child)); myValues.put(property, externalizer.readValue(child));
} }
catch (InvalidDataException e) { catch (Exception e) {
LOG.info(e); LOG.info(e);
} }
} }
} }
@Override public void writeExternal(@NotNull Element element) {
public void writeExternal(Element element) throws WriteExternalException {
if (myExternalizers.isEmpty()) { if (myExternalizers.isEmpty()) {
return; return;
} }
@@ -147,12 +152,12 @@ public class ExternalizablePropertyContainer extends AbstractProperty.AbstractPr
} }
@Override @Override
public List<T> readValue(Element dataElement) throws InvalidDataException { public List<T> readValue(Element dataElement) {
ArrayList<T> list = new ArrayList<T>(); List<T> list = new SmartList<T>();
List<Element> children = dataElement.getChildren(); for (Element element : dataElement.getChildren()) {
for (Iterator<Element> iterator = children.iterator(); iterator.hasNext();) { if (NULL_ELEMENT.equals(element.getName())) {
Element element = iterator.next(); list.add(null);
if (NULL_ELEMENT.equals(element.getName())) list.add(null); }
else if (myItemTagName.equals(element.getName())) { else if (myItemTagName.equals(element.getName())) {
T item = myItemExternalizer.readValue(element); T item = myItemExternalizer.readValue(element);
if (item == null) { if (item == null) {
@@ -166,17 +171,17 @@ public class ExternalizablePropertyContainer extends AbstractProperty.AbstractPr
} }
@Override @Override
public void writeValue(Element dataElement, List<T> value) throws WriteExternalException { public void writeValue(Element dataElement, List<T> value) {
for (Iterator<T> iterator = value.iterator(); iterator.hasNext();) { for (T item : value) {
T item = iterator.next(); if (item == null) {
if (item != null) { dataElement.addContent(new Element(NULL_ELEMENT));
}
else {
Element element = new Element(myItemTagName); Element element = new Element(myItemTagName);
myItemExternalizer.writeValue(element, item); myItemExternalizer.writeValue(element, item);
dataElement.addContent(element); dataElement.addContent(element);
} }
else dataElement.addContent(new Element(NULL_ELEMENT));
} }
} }
} }
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2009 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ import org.jdom.Element;
import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NonNls;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
public interface Externalizer<T> { public interface Externalizer<T> {
@NonNls String VALUE_ATTRIBUTE = "value"; @NonNls String VALUE_ATTRIBUTE = "value";
@@ -60,9 +59,9 @@ public interface Externalizer<T> {
} }
}; };
T readValue(Element dataElement) throws InvalidDataException; T readValue(Element dataElement);
void writeValue(Element dataElement, T value) throws WriteExternalException; void writeValue(Element dataElement, T value);
class FactoryBased<T extends JDOMExternalizable> implements Externalizer<T> { class FactoryBased<T extends JDOMExternalizable> implements Externalizer<T> {
private final Factory<T> myFactory; private final Factory<T> myFactory;
@@ -72,15 +71,25 @@ public interface Externalizer<T> {
} }
@Override @Override
public T readValue(Element dataElement) throws InvalidDataException { public T readValue(Element dataElement) {
T data = myFactory.create(); T data = myFactory.create();
data.readExternal(dataElement); try {
data.readExternal(dataElement);
}
catch (InvalidDataException e) {
throw new RuntimeException(e);
}
return data; return data;
} }
@Override @Override
public void writeValue(Element dataElement, T value) throws WriteExternalException { public void writeValue(Element dataElement, T value) {
value.writeExternal(dataElement); try {
value.writeExternal(dataElement);
}
catch (WriteExternalException e) {
throw new RuntimeException(e);
}
} }
public static <T extends JDOMExternalizable> FactoryBased<T> create(Factory<T> factory) { public static <T extends JDOMExternalizable> FactoryBased<T> create(Factory<T> factory) {
@@ -94,25 +103,25 @@ public interface Externalizer<T> {
@NonNls private static final String VALUE_ATTR = "value"; @NonNls private static final String VALUE_ATTR = "value";
@Override @Override
public Storage readValue(Element dataElement) throws InvalidDataException { public Storage readValue(Element dataElement) {
Storage.MapStorage storage = new Storage.MapStorage(); Storage.MapStorage storage = new Storage.MapStorage();
List<Element> children = dataElement.getChildren(ITEM_TAG); for (Element element : dataElement.getChildren(ITEM_TAG)) {
for (Iterator<Element> iterator = children.iterator(); iterator.hasNext();) {
Element element = iterator.next();
storage.put(element.getAttributeValue(KEY_ATTR), element.getAttributeValue(VALUE_ATTR)); storage.put(element.getAttributeValue(KEY_ATTR), element.getAttributeValue(VALUE_ATTR));
} }
return storage; return storage;
} }
@Override @Override
public void writeValue(Element dataElement, Storage storage) throws WriteExternalException { public void writeValue(Element dataElement, Storage storage) {
Iterator<String> keys = ((Storage.MapStorage)storage).getKeys(); Iterator<String> keys = ((Storage.MapStorage)storage).getKeys();
while (keys.hasNext()) { while (keys.hasNext()) {
String key = keys.next(); String key = keys.next();
String value = storage.get(key); String value = storage.get(key);
Element element = new Element(ITEM_TAG); Element element = new Element(ITEM_TAG);
element.setAttribute(KEY_ATTR, key); element.setAttribute(KEY_ATTR, key);
if (value != null) element.setAttribute(VALUE_ATTR, value); if (value != null) {
element.setAttribute(VALUE_ATTR, value);
}
dataElement.addContent(element); dataElement.addContent(element);
} }
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2009 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ public interface DiffPanelEx extends DiffPanel, Disposable {
DiffPanelOptions getOptions(); DiffPanelOptions getOptions();
void setComparisonPolicy(ComparisonPolicy comparisonPolicy); void setComparisonPolicy(@NotNull ComparisonPolicy comparisonPolicy);
ComparisonPolicy getComparisonPolicy(); ComparisonPolicy getComparisonPolicy();
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2014 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -180,17 +180,16 @@ public class DiffPanelImpl implements DiffPanelEx, ContentChangeListener, TwoSid
myDataProvider = new MyGenericDataProvider(this); myDataProvider = new MyGenericDataProvider(this);
myPanel.setDataProvider(myDataProvider); myPanel.setDataProvider(myDataProvider);
final ComparisonPolicy comparisonPolicy = getComparisonPolicy(); ComparisonPolicy comparisonPolicy = getComparisonPolicy();
final ComparisonPolicy defaultComparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy(); if (comparisonPolicy != DiffManagerImpl.getInstanceEx().getComparisonPolicy()) {
final HighlightMode highlightMode = getHighlightMode(); setComparisonPolicy(comparisonPolicy);
final HighlightMode defaultHighlightMode = DiffManagerImpl.getInstanceEx().getHighlightMode(); }
if (defaultComparisonPolicy != null && comparisonPolicy != defaultComparisonPolicy) { HighlightMode highlightMode = getHighlightMode();
setComparisonPolicy(defaultComparisonPolicy); if (highlightMode != DiffManagerImpl.getInstanceEx().getHighlightMode()) {
} setHighlightMode(highlightMode);
if (defaultHighlightMode != null && highlightMode != defaultHighlightMode) {
setHighlightMode(defaultHighlightMode);
} }
myVisibleAreaListener = new VisibleAreaListener() { myVisibleAreaListener = new VisibleAreaListener() {
@Override @Override
public void visibleAreaChanged(VisibleAreaEvent e) { public void visibleAreaChanged(VisibleAreaEvent e) {
@@ -504,11 +503,11 @@ public class DiffPanelImpl implements DiffPanelEx, ContentChangeListener, TwoSid
return myData.getComparisonPolicy(); return myData.getComparisonPolicy();
} }
public void setComparisonPolicy(ComparisonPolicy comparisonPolicy) { public void setComparisonPolicy(@NotNull ComparisonPolicy comparisonPolicy) {
setComparisonPolicy(comparisonPolicy, true); setComparisonPolicy(comparisonPolicy, true);
} }
private void setComparisonPolicy(ComparisonPolicy policy, boolean notifyManager) { private void setComparisonPolicy(@NotNull ComparisonPolicy policy, boolean notifyManager) {
myData.setComparisonPolicy(policy); myData.setComparisonPolicy(policy);
rediff(); rediff();
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2009 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -18,7 +18,10 @@ package com.intellij.openapi.diff.impl.external;
import com.intellij.ide.highlighter.ArchiveFileType; import com.intellij.ide.highlighter.ArchiveFileType;
import com.intellij.openapi.Disposable; import com.intellij.openapi.Disposable;
import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.diff.*; import com.intellij.openapi.diff.DiffContent;
import com.intellij.openapi.diff.DiffRequest;
import com.intellij.openapi.diff.DiffTool;
import com.intellij.openapi.diff.DiffViewer;
import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.UIBasedFileType; import com.intellij.openapi.fileTypes.UIBasedFileType;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -26,16 +29,21 @@ import org.jetbrains.annotations.Nullable;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
class CompositeDiffTool implements DiffTool { class CompositeDiffTool implements DiffTool {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.diff.impl.external.CompositeDiffTool"); private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.diff.impl.external.CompositeDiffTool");
private final List<DiffTool> myTools; private final List<DiffTool> myTools;
public CompositeDiffTool(List<DiffTool> tools) { public CompositeDiffTool(@NotNull List<DiffTool> tools) {
myTools = new ArrayList<DiffTool>(tools); myTools = new ArrayList<DiffTool>(tools);
} }
public CompositeDiffTool(@NotNull DiffTool[] tools) {
myTools = Arrays.asList(tools);
}
public void show(DiffRequest data) { public void show(DiffRequest data) {
checkDiffData(data); checkDiffData(data);
DiffTool tool = chooseTool(data); DiffTool tool = chooseTool(data);
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2012 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,6 +16,10 @@
package com.intellij.openapi.diff.impl.external; package com.intellij.openapi.diff.impl.external;
import com.intellij.openapi.Disposable; import com.intellij.openapi.Disposable;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.components.StoragePathMacros;
import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.diff.DiffManager; import com.intellij.openapi.diff.DiffManager;
import com.intellij.openapi.diff.DiffPanel; import com.intellij.openapi.diff.DiffPanel;
@@ -29,8 +33,11 @@ import com.intellij.openapi.diff.impl.processing.HighlightMode;
import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.markup.MarkupEditorFilter; import com.intellij.openapi.editor.markup.MarkupEditorFilter;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.*; import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.util.SmartList;
import com.intellij.util.config.*; import com.intellij.util.config.*;
import com.intellij.util.containers.ContainerUtil;
import org.jdom.Element; import org.jdom.Element;
import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -39,8 +46,16 @@ import org.jetbrains.annotations.Nullable;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
public class DiffManagerImpl extends DiffManager implements JDOMExternalizable { @State(
name = "DiffManager",
storages = {
@Storage(file = StoragePathMacros.APP_CONFIG + "/diff.xml"),
@Storage(file = StoragePathMacros.APP_CONFIG + "/other.xml", deprecated = true)
}
)
public class DiffManagerImpl extends DiffManager implements PersistentStateComponent<Element> {
public static final int FULL_DIFF_DIVIDER_POLYGONS_OFFSET = 3; public static final int FULL_DIFF_DIVIDER_POLYGONS_OFFSET = 3;
private static final Logger LOG = Logger.getInstance(DiffManagerImpl.class); private static final Logger LOG = Logger.getInstance(DiffManagerImpl.class);
@@ -50,7 +65,10 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
@Override @Override
public String readValue(Element dataElement) { public String readValue(Element dataElement) {
String path = dataElement.getAttributeValue(NEW_VALUE); String path = dataElement.getAttributeValue(NEW_VALUE);
if (path != null) return path; if (path != null) {
return path;
}
String prevValue = dataElement.getAttributeValue(VALUE_ATTRIBUTE); String prevValue = dataElement.getAttributeValue(VALUE_ATTRIBUTE);
return prevValue != null ? prevValue.trim() : null; return prevValue != null ? prevValue.trim() : null;
} }
@@ -70,9 +88,8 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
public static final BooleanProperty ENABLE_FILES = new BooleanProperty("enableFiles", false); public static final BooleanProperty ENABLE_FILES = new BooleanProperty("enableFiles", false);
public static final BooleanProperty ENABLE_MERGE = new BooleanProperty("enableMerge", false); public static final BooleanProperty ENABLE_MERGE = new BooleanProperty("enableMerge", false);
private final ExternalizablePropertyContainer myProperties; private final ExternalizablePropertyContainer myProperties;
private final ArrayList<DiffTool> myAdditionTools = new ArrayList<DiffTool>(); private final List<DiffTool> myAdditionTools = new SmartList<DiffTool>();
public static final DiffTool INTERNAL_DIFF = new FrameDiffTool(); public static final DiffTool INTERNAL_DIFF = new FrameDiffTool();
public static final Key<Boolean> EDITOR_IS_DIFF_KEY = new Key<Boolean>("EDITOR_IS_DIFF_KEY"); public static final Key<Boolean> EDITOR_IS_DIFF_KEY = new Key<Boolean>("EDITOR_IS_DIFF_KEY");
@@ -82,8 +99,9 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
return DiffUtil.isDiffEditor(editor); return DiffUtil.isDiffEditor(editor);
} }
}; };
private ComparisonPolicy myComparisonPolicy;
private HighlightMode myHighlightMode; private ComparisonPolicy myComparisonPolicy = ComparisonPolicy.DEFAULT;
private HighlightMode myHighlightMode = HighlightMode.BY_WORD;
@NonNls public static final String COMPARISON_POLICY_ATTR_NAME = "COMPARISON_POLICY"; @NonNls public static final String COMPARISON_POLICY_ATTR_NAME = "COMPARISON_POLICY";
@NonNls public static final String HIGHLIGHT_MODE_ATTR_NAME = "HIGHLIGHT_MODE"; @NonNls public static final String HIGHLIGHT_MODE_ATTR_NAME = "HIGHLIGHT_MODE";
@@ -100,13 +118,15 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
} }
@Override @Override
public DiffTool getIdeaDiffTool() { return INTERNAL_DIFF; } public DiffTool getIdeaDiffTool() {
return INTERNAL_DIFF;
}
@Override @Override
public DiffTool getDiffTool() { public DiffTool getDiffTool() {
DiffTool[] standardTools; DiffTool[] standardTools;
// there is inner check in multiple tool for external viewers as well // there is inner check in multiple tool for external viewers as well
if (! ENABLE_FILES.value(myProperties) || ! ENABLE_FOLDERS.value(myProperties) || !ENABLE_MERGE.value(myProperties)) { if (!ENABLE_FILES.value(myProperties) || !ENABLE_FOLDERS.value(myProperties) || !ENABLE_MERGE.value(myProperties)) {
DiffTool[] embeddableTools = { DiffTool[] embeddableTools = {
INTERNAL_DIFF, INTERNAL_DIFF,
new MergeTool(), new MergeTool(),
@@ -121,7 +141,8 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
new MergeTool(), new MergeTool(),
BinaryDiffTool.INSTANCE BinaryDiffTool.INSTANCE
}; };
} else { }
else {
standardTools = new DiffTool[]{ standardTools = new DiffTool[]{
ExtCompareFolders.INSTANCE, ExtCompareFolders.INSTANCE,
ExtCompareFiles.INSTANCE, ExtCompareFiles.INSTANCE,
@@ -131,14 +152,22 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
BinaryDiffTool.INSTANCE BinaryDiffTool.INSTANCE
}; };
} }
ArrayList<DiffTool> allTools = new ArrayList<DiffTool>(myAdditionTools); if (myAdditionTools.isEmpty()) {
allTools.addAll(Arrays.asList(standardTools)); return new CompositeDiffTool(standardTools);
return new CompositeDiffTool(allTools); }
else {
List<DiffTool> allTools = new ArrayList<DiffTool>(myAdditionTools);
ContainerUtil.addAll(allTools, standardTools);
return new CompositeDiffTool(allTools);
}
} }
@Override @Override
public boolean registerDiffTool(@NotNull DiffTool tool) throws NullPointerException { public boolean registerDiffTool(@NotNull DiffTool tool) throws NullPointerException {
if (myAdditionTools.contains(tool)) return false; if (myAdditionTools.contains(tool)) {
return false;
}
myAdditionTools.add(tool); myAdditionTools.add(tool);
return true; return true;
} }
@@ -149,7 +178,7 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
LOG.assertTrue(!myAdditionTools.contains(tool)); LOG.assertTrue(!myAdditionTools.contains(tool));
} }
public ArrayList<DiffTool> getAdditionTools() { public List<DiffTool> getAdditionTools() {
return myAdditionTools; return myAdditionTools;
} }
@@ -174,28 +203,35 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
return (DiffManagerImpl)DiffManager.getInstance(); return (DiffManagerImpl)DiffManager.getInstance();
} }
@Nullable
@Override @Override
public void readExternal(@NotNull Element element) throws InvalidDataException { public Element getState() {
myProperties.readExternal(element); Element state = new Element("state");
readPolicy(element); myProperties.writeExternal(state);
readMode(element); if (myComparisonPolicy != ComparisonPolicy.DEFAULT) {
state.setAttribute(COMPARISON_POLICY_ATTR_NAME, myComparisonPolicy.getName());
}
if (myHighlightMode != HighlightMode.BY_WORD) {
state.setAttribute(HIGHLIGHT_MODE_ATTR_NAME, myHighlightMode.name());
}
return state;
} }
private void readPolicy(@NotNull final Element element) { @Override
final String policyName = element.getAttributeValue(COMPARISON_POLICY_ATTR_NAME); public void loadState(Element state) {
myProperties.readExternal(state);
String policyName = state.getAttributeValue(COMPARISON_POLICY_ATTR_NAME);
if (policyName != null) { if (policyName != null) {
ComparisonPolicy[] policies = ComparisonPolicy.getAllInstances(); for (ComparisonPolicy policy : ComparisonPolicy.getAllInstances()) {
for (ComparisonPolicy policy : policies) {
if (policy.getName().equals(policyName)) { if (policy.getName().equals(policyName)) {
myComparisonPolicy = policy; myComparisonPolicy = policy;
break; break;
} }
} }
} }
}
private void readMode(@NotNull final Element element) { String modeName = state.getAttributeValue(HIGHLIGHT_MODE_ATTR_NAME);
final String modeName = element.getAttributeValue(HIGHLIGHT_MODE_ATTR_NAME);
if (modeName != null) { if (modeName != null) {
try { try {
myHighlightMode = HighlightMode.valueOf(modeName); myHighlightMode = HighlightMode.valueOf(modeName);
@@ -205,19 +241,10 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
} }
} }
@Override public AbstractProperty.AbstractPropertyContainer getProperties() {
public void writeExternal(@NotNull Element element) throws WriteExternalException { return myProperties;
myProperties.writeExternal(element);
if (myComparisonPolicy != null) {
element.setAttribute(COMPARISON_POLICY_ATTR_NAME, myComparisonPolicy.getName());
}
if (myHighlightMode != null) {
element.setAttribute(HIGHLIGHT_MODE_ATTR_NAME, myHighlightMode.name());
}
} }
public AbstractProperty.AbstractPropertyContainer getProperties() { return myProperties; }
static DiffPanel createDiffPanel(DiffRequest data, Window window, @NotNull Disposable parentDisposable, FrameDiffTool tool) { static DiffPanel createDiffPanel(DiffRequest data, Window window, @NotNull Disposable parentDisposable, FrameDiffTool tool) {
DiffPanel diffPanel = null; DiffPanel diffPanel = null;
try { try {
@@ -236,21 +263,21 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
} }
} }
public void setComparisonPolicy(final ComparisonPolicy p) { @NotNull
myComparisonPolicy = p;
}
@Nullable
public ComparisonPolicy getComparisonPolicy() { public ComparisonPolicy getComparisonPolicy() {
return myComparisonPolicy; return myComparisonPolicy;
} }
public void setHighlightMode(HighlightMode highlightMode) { public void setComparisonPolicy(@NotNull ComparisonPolicy value) {
myHighlightMode = highlightMode; myComparisonPolicy = value;
} }
@Nullable @NotNull
public HighlightMode getHighlightMode() { public HighlightMode getHighlightMode() {
return myHighlightMode; return myHighlightMode;
} }
public void setHighlightMode(@NotNull HighlightMode highlightMode) {
myHighlightMode = highlightMode;
}
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2013 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@ import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.FrameWrapper; import com.intellij.openapi.ui.FrameWrapper;
import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.ex.MessagesEx; import com.intellij.openapi.ui.ex.MessagesEx;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -40,8 +39,6 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
// Author: dyoma
public class FrameDiffTool implements DiffTool { public class FrameDiffTool implements DiffTool {
public void show(DiffRequest request) { public void show(DiffRequest request) {
Collection hints = request.getHints(); Collection hints = request.getHints();
@@ -161,27 +158,27 @@ public class FrameDiffTool implements DiffTool {
// TODO remove check? // TODO remove check?
private boolean checkNoDifferenceAndNotify(DiffPanel diffPanel, DiffRequest data, final Window window, final boolean showMessage) { private boolean checkNoDifferenceAndNotify(DiffPanel diffPanel, DiffRequest data, final Window window, final boolean showMessage) {
if (!diffPanel.hasDifferences() && !data.getHints().contains(HINT_ALLOW_NO_DIFFERENCES)) { if (diffPanel.hasDifferences() || data.getHints().contains(HINT_ALLOW_NO_DIFFERENCES)) {
DiffManagerImpl manager = (DiffManagerImpl) DiffManager.getInstance(); return false;
if (!Comparing.equal(manager.getComparisonPolicy(), ComparisonPolicy.DEFAULT)) {
ComparisonPolicy oldPolicy = manager.getComparisonPolicy();
manager.setComparisonPolicy(ComparisonPolicy.DEFAULT);
Disposable parentDisposable = Disposer.newDisposable();
DiffPanel maybeDiffPanel = DiffManagerImpl.createDiffPanel(data, window, parentDisposable, this);
manager.setComparisonPolicy(oldPolicy);
boolean hasDiffs = maybeDiffPanel.hasDifferences();
Disposer.dispose(parentDisposable);
if (hasDiffs) return false;
}
if (! showMessage) {
return true;
}
return !askForceOpenDiff(data);
} }
return false;
DiffManagerImpl manager = (DiffManagerImpl)DiffManager.getInstance();
ComparisonPolicy oldPolicy = manager.getComparisonPolicy();
if (oldPolicy != ComparisonPolicy.DEFAULT) {
manager.setComparisonPolicy(ComparisonPolicy.DEFAULT);
Disposable parentDisposable = Disposer.newDisposable();
DiffPanel maybeDiffPanel = DiffManagerImpl.createDiffPanel(data, window, parentDisposable, this);
manager.setComparisonPolicy(oldPolicy);
boolean hasDiffs = maybeDiffPanel.hasDifferences();
Disposer.dispose(parentDisposable);
if (hasDiffs) {
return false;
}
}
return !showMessage || !askForceOpenDiff(data);
} }
private static boolean askForceOpenDiff(DiffRequest data) { private static boolean askForceOpenDiff(DiffRequest data) {
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2009 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -19,7 +19,10 @@ import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diff.impl.ComparisonPolicy; import com.intellij.openapi.diff.impl.ComparisonPolicy;
import com.intellij.openapi.diff.impl.ContentChangeListener; import com.intellij.openapi.diff.impl.ContentChangeListener;
import com.intellij.openapi.diff.impl.fragments.*; import com.intellij.openapi.diff.impl.fragments.FragmentHighlighterImpl;
import com.intellij.openapi.diff.impl.fragments.FragmentList;
import com.intellij.openapi.diff.impl.fragments.FragmentListImpl;
import com.intellij.openapi.diff.impl.fragments.LineFragment;
import com.intellij.openapi.diff.impl.processing.DiffPolicy; import com.intellij.openapi.diff.impl.processing.DiffPolicy;
import com.intellij.openapi.diff.impl.processing.HighlightMode; import com.intellij.openapi.diff.impl.processing.HighlightMode;
import com.intellij.openapi.diff.impl.processing.TextCompareProcessor; import com.intellij.openapi.diff.impl.processing.TextCompareProcessor;
@@ -58,7 +61,7 @@ public abstract class SimpleDiffPanelState implements Disposable {
return editorWrapper; return editorWrapper;
} }
public void setComparisonPolicy(ComparisonPolicy comparisonPolicy) { public void setComparisonPolicy(@NotNull ComparisonPolicy comparisonPolicy) {
myComparisonPolicy = comparisonPolicy; myComparisonPolicy = comparisonPolicy;
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2013 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,15 +16,16 @@
package com.intellij.openapi.diff.impl; package com.intellij.openapi.diff.impl;
import com.intellij.CommonBundle; import com.intellij.CommonBundle;
import com.intellij.openapi.diff.impl.string.DiffString;
import com.intellij.openapi.diff.ex.DiffFragment; import com.intellij.openapi.diff.ex.DiffFragment;
import com.intellij.openapi.diff.impl.highlighting.FragmentSide; import com.intellij.openapi.diff.impl.highlighting.FragmentSide;
import com.intellij.openapi.diff.impl.highlighting.Util; import com.intellij.openapi.diff.impl.highlighting.Util;
import com.intellij.openapi.diff.impl.processing.DiffCorrection; import com.intellij.openapi.diff.impl.processing.DiffCorrection;
import com.intellij.openapi.diff.impl.processing.Formatting; import com.intellij.openapi.diff.impl.processing.Formatting;
import com.intellij.openapi.diff.impl.processing.Word; import com.intellij.openapi.diff.impl.processing.Word;
import com.intellij.openapi.diff.impl.string.DiffString;
import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.diff.Diff; import com.intellij.util.diff.Diff;
import com.intellij.util.diff.FilesTooBigForDiffException; import com.intellij.util.diff.FilesTooBigForDiffException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -241,8 +242,7 @@ public abstract class ComparisonPolicy {
if (fragment.isOneSide()) { if (fragment.isOneSide()) {
FragmentSide side = FragmentSide.chooseSide(fragment); FragmentSide side = FragmentSide.chooseSide(fragment);
DiffString text = side.getText(fragment); DiffString text = side.getText(fragment);
DiffString trimed = text.trim(); if (StringUtil.isEmptyOrSpaces(text)) {
if (trimed.isEmpty()) {
collector.add(side.createFragment(text, DiffString.EMPTY, false)); collector.add(side.createFragment(text, DiffString.EMPTY, false));
return; return;
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2011 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package com.intellij.openapi.vcs.changes; package com.intellij.openapi.vcs.changes;
import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.diff.impl.ComparisonPolicy;
import com.intellij.openapi.diff.impl.external.DiffManagerImpl; import com.intellij.openapi.diff.impl.external.DiffManagerImpl;
import com.intellij.openapi.diff.impl.fragments.LineFragment; import com.intellij.openapi.diff.impl.fragments.LineFragment;
import com.intellij.openapi.diff.impl.highlighting.FragmentSide; import com.intellij.openapi.diff.impl.highlighting.FragmentSide;
@@ -87,11 +86,10 @@ public class FragmentedDiffRequestFromChange {
filePath.hardRefresh(); filePath.hardRefresh();
file = filePath.getVirtualFile(); file = filePath.getVirtualFile();
} }
final PreparedFragmentedContent preparedFragmentedContent = new PreparedFragmentedContent(myProject, fragmentedContent, return new PreparedFragmentedContent(myProject, fragmentedContent,
filePath.getName(), filePath.getFileType(), filePath.getName(), filePath.getFileType(),
change.getBeforeRevision() == null ? null : change.getBeforeRevision().getRevisionNumber(), change.getBeforeRevision() == null ? null : change.getBeforeRevision().getRevisionNumber(),
change.getAfterRevision() == null ? null : change.getAfterRevision().getRevisionNumber(), filePath, file); change.getAfterRevision() == null ? null : change.getAfterRevision().getRevisionNumber(), filePath, file);
return preparedFragmentedContent;
} }
private static class RangesCalculator { private static class RangesCalculator {
@@ -138,12 +136,8 @@ public class FragmentedDiffRequestFromChange {
} }
} }
ComparisonPolicy comparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy(); TextCompareProcessor processor = new TextCompareProcessor(DiffManagerImpl.getInstanceEx().getComparisonPolicy());
if (comparisonPolicy == null) { List<LineFragment> lineFragments = processor.process(myOldDocument.getText(), myDocument.getText());
comparisonPolicy = ComparisonPolicy.DEFAULT;
}
final TextCompareProcessor processor = new TextCompareProcessor(comparisonPolicy);
final List<LineFragment> lineFragments = processor.process(myOldDocument.getText(), myDocument.getText());
myRanges = new ArrayList<BeforeAfter<TextRange>>(lineFragments.size()); myRanges = new ArrayList<BeforeAfter<TextRange>>(lineFragments.size());
for (LineFragment lineFragment : lineFragments) { for (LineFragment lineFragment : lineFragments) {
if (!lineFragment.isEqual()) { if (!lineFragment.isEqual()) {
@@ -174,7 +168,7 @@ public class FragmentedDiffRequestFromChange {
} }
} }
private int correctRangeEnd(final int end, final Document document) { private static int correctRangeEnd(final int end, final Document document) {
if (end == 0) return end; if (end == 0) return end;
return "\n".equals(document.getText(new TextRange(end - 1, end))) ? end - 1 : end; return "\n".equals(document.getText(new TextRange(end - 1, end))) ? end - 1 : end;
} }
@@ -187,7 +181,7 @@ public class FragmentedDiffRequestFromChange {
return myException; return myException;
} }
private Document documentFromRevision(final ContentRevision cr) throws VcsException { private static Document documentFromRevision(final ContentRevision cr) throws VcsException {
final Document oldDocument = new DocumentImpl(StringUtil.convertLineSeparators(notNullContentRevision(cr)),true); final Document oldDocument = new DocumentImpl(StringUtil.convertLineSeparators(notNullContentRevision(cr)),true);
// todo !!! a question how to show line separators in diff etc // todo !!! a question how to show line separators in diff etc
// todo currently document doesn't allow to put \r as separator // todo currently document doesn't allow to put \r as separator
@@ -195,7 +189,7 @@ public class FragmentedDiffRequestFromChange {
return oldDocument; return oldDocument;
} }
private String notNullContentRevision(final ContentRevision cr) throws VcsException { private static String notNullContentRevision(final ContentRevision cr) throws VcsException {
if (cr == null) return ""; if (cr == null) return "";
String content = cr.getContent(); String content = cr.getContent();
return content == null ? "" : content; return content == null ? "" : content;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2012 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.roots.ui.CellAppearanceEx; import com.intellij.openapi.roots.ui.CellAppearanceEx;
import com.intellij.openapi.roots.ui.FileAppearanceService; import com.intellij.openapi.roots.ui.FileAppearanceService;
import com.intellij.openapi.roots.ui.ModifiableCellAppearanceEx; import com.intellij.openapi.roots.ui.ModifiableCellAppearanceEx;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.VirtualFileManager;
@@ -55,7 +54,7 @@ public class AllJarsUnderDirEntry implements AntClasspathEntry {
this(new File(osPath)); this(new File(osPath));
} }
public void writeExternal(final Element dataElement) throws WriteExternalException { public void writeExternal(final Element dataElement) {
String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, myDir.getAbsolutePath().replace(File.separatorChar, '/')); String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, myDir.getAbsolutePath().replace(File.separatorChar, '/'));
dataElement.setAttribute(DIR, url); dataElement.setAttribute(DIR, url);
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2012 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -18,9 +18,7 @@ package com.intellij.lang.ant.config.impl;
import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.roots.ui.CellAppearanceEx; import com.intellij.openapi.roots.ui.CellAppearanceEx;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.NullableFactory; import com.intellij.openapi.util.NullableFactory;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Function; import com.intellij.util.Function;
import com.intellij.util.PathUtil; import com.intellij.util.PathUtil;
@@ -35,23 +33,25 @@ import java.util.List;
public interface AntClasspathEntry { public interface AntClasspathEntry {
Externalizer<AntClasspathEntry> EXTERNALIZER = new Externalizer<AntClasspathEntry>() { Externalizer<AntClasspathEntry> EXTERNALIZER = new Externalizer<AntClasspathEntry>() {
@Override @Override
public AntClasspathEntry readValue(Element dataElement) throws InvalidDataException { public AntClasspathEntry readValue(Element dataElement) {
String pathUrl = dataElement.getAttributeValue(SinglePathEntry.PATH); String pathUrl = dataElement.getAttributeValue(SinglePathEntry.PATH);
if (pathUrl != null) if (pathUrl != null) {
return new SinglePathEntry(PathUtil.toPresentableUrl(pathUrl)); return new SinglePathEntry(PathUtil.toPresentableUrl(pathUrl));
}
String dirUrl = dataElement.getAttributeValue(AllJarsUnderDirEntry.DIR); String dirUrl = dataElement.getAttributeValue(AllJarsUnderDirEntry.DIR);
if (dirUrl != null) if (dirUrl != null) {
return new AllJarsUnderDirEntry(PathUtil.toPresentableUrl(dirUrl)); return new AllJarsUnderDirEntry(PathUtil.toPresentableUrl(dirUrl));
throw new InvalidDataException(); }
throw new IllegalStateException();
} }
@Override @Override
public void writeValue(Element dataElement, AntClasspathEntry entry) throws WriteExternalException { public void writeValue(Element dataElement, AntClasspathEntry entry) {
entry.writeExternal(dataElement); entry.writeExternal(dataElement);
} }
}; };
void writeExternal(Element dataElement) throws WriteExternalException; void writeExternal(Element dataElement);
void addFilesTo(List<File> files); void addFilesTo(List<File> files);
@@ -60,7 +60,7 @@ public interface AntClasspathEntry {
abstract class AddEntriesFactory implements NullableFactory<List<AntClasspathEntry>> { abstract class AddEntriesFactory implements NullableFactory<List<AntClasspathEntry>> {
private final JComponent myParentComponent; private final JComponent myParentComponent;
private final FileChooserDescriptor myDescriptor; private final FileChooserDescriptor myDescriptor;
private final Function<VirtualFile,AntClasspathEntry> myMapper; private final Function<VirtualFile, AntClasspathEntry> myMapper;
public AddEntriesFactory(final JComponent parentComponent, public AddEntriesFactory(final JComponent parentComponent,
final FileChooserDescriptor descriptor, final FileChooserDescriptor descriptor,
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2013 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@ package com.intellij.lang.ant.config.impl;
import com.intellij.lang.ant.AntBundle; import com.intellij.lang.ant.AntBundle;
import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.io.JarUtil; import com.intellij.openapi.util.io.JarUtil;
import com.intellij.util.config.*; import com.intellij.util.config.*;
import com.intellij.util.containers.Convertor; import com.intellij.util.containers.Convertor;
@@ -62,18 +60,18 @@ public class AntInstallation {
} }
public static final Externalizer<AntInstallation> EXTERNALIZER = new Externalizer<AntInstallation>() { public static final Externalizer<AntInstallation> EXTERNALIZER = new Externalizer<AntInstallation>() {
public AntInstallation readValue(Element dataElement) throws InvalidDataException { public AntInstallation readValue(Element dataElement) {
AntInstallation antInstallation = new AntInstallation(); AntInstallation antInstallation = new AntInstallation();
antInstallation.readExternal(dataElement); antInstallation.readExternal(dataElement);
return antInstallation; return antInstallation;
} }
public void writeValue(Element dataElement, AntInstallation antInstallation) throws WriteExternalException { public void writeValue(Element dataElement, AntInstallation antInstallation) {
antInstallation.myProperties.writeExternal(dataElement); antInstallation.myProperties.writeExternal(dataElement);
} }
}; };
private void readExternal(Element dataElement) throws InvalidDataException { private void readExternal(Element dataElement) {
myProperties.readExternal(dataElement); myProperties.readExternal(dataElement);
File antJar = new File(HOME_DIR.get(myProperties), PATH_TO_ANT_JAR); File antJar = new File(HOME_DIR.get(myProperties), PATH_TO_ANT_JAR);
updateVersion(antJar); updateVersion(antJar);
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2009 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ import com.intellij.execution.CantRunException;
import com.intellij.lang.ant.AntBundle; import com.intellij.lang.ant.AntBundle;
import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.util.config.AbstractProperty; import com.intellij.util.config.AbstractProperty;
import com.intellij.util.config.Externalizer; import com.intellij.util.config.Externalizer;
import org.jdom.Element; import org.jdom.Element;
@@ -35,11 +34,13 @@ public abstract class AntReference {
@NonNls private static final String BUNDLED_ANT_ATTR = "bundledAnt"; @NonNls private static final String BUNDLED_ANT_ATTR = "bundledAnt";
public static final Externalizer<AntReference> EXTERNALIZER = new Externalizer<AntReference>() { public static final Externalizer<AntReference> EXTERNALIZER = new Externalizer<AntReference>() {
public AntReference readValue(Element dataElement) throws InvalidDataException { public AntReference readValue(Element dataElement) {
if (Boolean.valueOf(dataElement.getAttributeValue(PROJECT_DEFAULT_ATTR)).booleanValue()) return PROJECT_DEFAULT; if (Boolean.valueOf(dataElement.getAttributeValue(PROJECT_DEFAULT_ATTR)).booleanValue()) return PROJECT_DEFAULT;
if (Boolean.valueOf(dataElement.getAttributeValue(BUNDLED_ANT_ATTR)).booleanValue()) return BUNDLED_ANT; if (Boolean.valueOf(dataElement.getAttributeValue(BUNDLED_ANT_ATTR)).booleanValue()) return BUNDLED_ANT;
String name = dataElement.getAttributeValue(NAME_ATTR); String name = dataElement.getAttributeValue(NAME_ATTR);
if (name == null) throw new InvalidDataException(); if (name == null) {
throw new IllegalStateException("no name");
}
return new MissingAntReference(name); return new MissingAntReference(name);
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2012 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -31,8 +31,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.ProjectJdkTable; import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.util.config.*; import com.intellij.util.config.*;
@@ -102,24 +100,13 @@ public class GlobalAntConfiguration implements PersistentStateComponent<Element>
@Override @Override
public Element getState() { public Element getState() {
Element element = new Element("state"); Element element = new Element("state");
try { myProperties.writeExternal(element);
myProperties.writeExternal(element);
}
catch (WriteExternalException e) {
LOG.error(e);
return null;
}
return element; return element;
} }
@Override @Override
public void loadState(Element state) { public void loadState(Element state) {
try { myProperties.readExternal(state);
myProperties.readExternal(state);
}
catch (InvalidDataException e) {
LOG.error(e);
}
} }
public static GlobalAntConfiguration getInstance() { public static GlobalAntConfiguration getInstance() {
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2012 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -18,8 +18,6 @@ package com.intellij.lang.ant.config.impl;
import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.roots.ui.CellAppearanceEx; import com.intellij.openapi.roots.ui.CellAppearanceEx;
import com.intellij.openapi.roots.ui.FileAppearanceService; import com.intellij.openapi.roots.ui.FileAppearanceService;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.VirtualFileManager;
@@ -51,12 +49,12 @@ public class SinglePathEntry implements AntClasspathEntry {
this(new File(osPath)); this(new File(osPath));
} }
public void readExternal(final Element element) throws InvalidDataException { public void readExternal(final Element element) {
String value = element.getAttributeValue(PATH); String value = element.getAttributeValue(PATH);
myFile = new File(PathUtil.toPresentableUrl(value)); myFile = new File(PathUtil.toPresentableUrl(value));
} }
public void writeExternal(final Element element) throws WriteExternalException { public void writeExternal(final Element element) {
String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, myFile.getAbsolutePath().replace(File.separatorChar, '/')); String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, myFile.getAbsolutePath().replace(File.separatorChar, '/'));
element.setAttribute(PATH, url); element.setAttribute(PATH, url);
} }