Ant TargetFilter - do not throw WriteExternalException

This commit is contained in:
Vladimir Krivosheev
2019-04-18 13:36:47 +02:00
parent 2a23aeecdd
commit 5f427ec585
8 changed files with 47 additions and 210 deletions
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.config;
import com.intellij.openapi.diagnostic.Logger;
@@ -76,7 +62,7 @@ public class ExternalizablePropertyContainer extends AbstractProperty.AbstractPr
}
private static <T> Externalizer<List<T>> createListExternalizer(final Externalizer<T> itemExternalizer, final String itemTagName) {
return new ListExternalizer(itemExternalizer, itemTagName);
return new ListExternalizer<>(itemExternalizer, itemTagName);
}
public void readExternal(@NotNull Element element) {
@@ -180,7 +166,9 @@ public class ExternalizablePropertyContainer extends AbstractProperty.AbstractPr
else {
Element element = new Element(myItemTagName);
myItemExternalizer.writeValue(element, item);
dataElement.addContent(element);
if (!(item instanceof SkippableValue) || !JDOMUtil.isEmpty(element)) {
dataElement.addContent(element);
}
}
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.config;
@@ -6,6 +6,7 @@ import com.intellij.openapi.util.Factory;
import com.intellij.openapi.util.JDOMExternalizable;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
@@ -30,7 +31,6 @@ public interface Externalizer<T> {
Externalizer<Storage> STORAGE = new StorageExternalizer();
abstract class BaseExternalizer<T> implements Externalizer<T> {
@Override
public void writeValue(Element dataElement, T value) {
dataElement.setAttribute(VALUE_ATTRIBUTE, value.toString());
@@ -47,10 +47,13 @@ public interface Externalizer<T> {
void writeValue(Element dataElement, T value);
interface SkippableValue {
}
class FactoryBased<T extends JDOMExternalizable> implements Externalizer<T> {
private final Factory<? extends T> myFactory;
public FactoryBased(Factory<? extends T> factory) {
public FactoryBased(@NotNull Factory<? extends T> factory) {
myFactory = factory;
}
@@ -66,7 +69,7 @@ public interface Externalizer<T> {
value.writeExternal(dataElement);
}
static <T extends JDOMExternalizable> FactoryBased<T> create(Factory<? extends T> factory) {
static <T extends JDOMExternalizable> FactoryBased<T> create(@NotNull Factory<? extends T> factory) {
return new FactoryBased<>(factory);
}
}
@@ -1,19 +1,4 @@
/*
* Copyright 2000-2009 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.config;
import org.jetbrains.annotations.NonNls;
@@ -68,10 +53,6 @@ public class ListProperty<T> extends AbstractProperty<List<T>> {
return modifiableList;
}
public void clearList(AbstractPropertyContainer container) {
getModifiableList(container).clear();
}
public Iterator<T> getIterator(AbstractPropertyContainer container) {
return get(container).iterator();
}
@@ -302,7 +302,7 @@ public class AntExplorer extends SimpleToolWindowPanel implements DataProvider,
public void setBuildFileProperties() {
final AntBuildFileBase buildFile = getCurrentBuildFile();
if (buildFile != null && BuildFilePropertiesPanel.editBuildFile(buildFile, myProject)) {
if (buildFile != null && BuildFilePropertiesPanel.editBuildFile(buildFile)) {
myConfig.updateBuildFile(buildFile);
}
}
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.ant.config.impl;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
@@ -44,8 +30,7 @@ import java.io.File;
import java.util.*;
public class AntBuildFileImpl implements AntBuildFileBase {
private static final Logger LOG = Logger.getInstance("#com.intellij.lang.ant.config.impl.AntBuildFileImpl");
private static final Logger LOG = Logger.getInstance(AntBuildFileImpl.class);
@NonNls private static final String ANT_LIB = "/.ant/lib";
private volatile Map<String, String> myCachedExternalProperties;
private final Object myOptionsLock = new Object();
@@ -1,35 +1,20 @@
/*
* Copyright 2000-2009 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.ant.config.impl;
import com.intellij.lang.ant.config.AntBuildTarget;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.util.config.Externalizer;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
public final class TargetFilter implements JDOMExternalizable {
public final class TargetFilter implements JDOMExternalizable, Externalizer.SkippableValue {
@NonNls private static final String FILTER_TARGET_NAME = "targetName";
@NonNls private static final String FILTER_IS_VISIBLE = "isVisible";
private String myTargetName;
private boolean myVisible;
private String myDescription = "";
public TargetFilter() {}
public TargetFilter(String targetName, boolean isVisible) {
myTargetName = targetName;
myVisible = isVisible;
@@ -54,11 +39,10 @@ public final class TargetFilter implements JDOMExternalizable {
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
public void writeExternal(@NotNull Element element) {
final String targetName = getTargetName();
if (targetName == null) {
// incomplete tag
throw new WriteExternalException();
return;
}
element.setAttribute(FILTER_TARGET_NAME, targetName);
element.setAttribute(FILTER_IS_VISIBLE, Boolean.valueOf(isVisible()).toString());
@@ -73,6 +57,7 @@ public final class TargetFilter implements JDOMExternalizable {
myDescription = target.getNotEmptyDescription();
}
@NotNull
public static TargetFilter fromTarget(AntBuildTarget target) {
TargetFilter filter = new TargetFilter(target.getName(), target.isDefault());
filter.myDescription = target.getNotEmptyDescription();
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2013 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.ant.config.impl.configuration;
import com.intellij.lang.ant.AntBundle;
@@ -21,7 +7,6 @@ import com.intellij.lang.ant.config.impl.*;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.ui.ProjectJdksEditor;
@@ -35,7 +20,6 @@ import com.intellij.util.config.AbstractProperty;
import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.ListTableModel;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -51,8 +35,8 @@ public class BuildFilePropertiesPanel {
private final Form myForm;
private AntBuildFileBase myBuildFile;
private BuildFilePropertiesPanel(@NotNull final Project project) {
myForm = new Form(project);
private BuildFilePropertiesPanel() {
myForm = new Form();
}
private void reset(final AntBuildFileBase buildFile) {
@@ -90,8 +74,8 @@ public class BuildFilePropertiesPanel {
Disposer.dispose(myForm);
}
public static boolean editBuildFile(AntBuildFileBase buildFile, @NotNull final Project project) {
BuildFilePropertiesPanel panel = new BuildFilePropertiesPanel(project);
public static boolean editBuildFile(AntBuildFileBase buildFile) {
BuildFilePropertiesPanel panel = new BuildFilePropertiesPanel();
panel.reset(buildFile);
return panel.showDialog();
}
@@ -135,20 +119,19 @@ public class BuildFilePropertiesPanel {
private JCheckBox myCollapseFinishedTargets;
private final Tab[] myTabs;
private final UIPropertyBinding.Composite myBinding = new UIPropertyBinding.Composite();
private final TabbedPaneWrapper myWrapper;
private Form(@NotNull final Project project) {
private Form() {
myTabs = new Tab[]{
new PropertiesTab(),
new ExecutionTab(GlobalAntConfiguration.getInstance(), project),
new ExecutionTab(GlobalAntConfiguration.getInstance()),
new AdditionalClasspathTab(),
new FiltersTab()
};
myHeapSizeLabel.setLabelFor(myXmx);
myWrapper = new TabbedPaneWrapper(this);
TabbedPaneWrapper wrapper = new TabbedPaneWrapper(this);
myTabsPlace.setLayout(new BorderLayout());
myTabsPlace.add(myWrapper.getComponent(), BorderLayout.CENTER);
myTabsPlace.add(wrapper.getComponent(), BorderLayout.CENTER);
myBinding.bindBoolean(myRunInBackground, AntBuildFileImpl.RUN_IN_BACKGROUND);
myBinding.bindBoolean(myCloseOnNoError, AntBuildFileImpl.CLOSE_ON_NO_ERRORS);
@@ -158,7 +141,7 @@ public class BuildFilePropertiesPanel {
myBinding.bindInt(myXss, AntBuildFileImpl.MAX_STACK_SIZE);
for (Tab tab : myTabs) {
myWrapper.addTab(tab.getDisplayName(), tab.getComponent());
wrapper.addTab(tab.getDisplayName(), tab.getComponent());
}
}
@@ -414,11 +397,9 @@ public class BuildFilePropertiesPanel {
private AntReference myProjectDefaultAnt = null;
private final GlobalAntConfiguration myAntGlobalConfiguration;
private final Project myProject;
ExecutionTab(final GlobalAntConfiguration antConfiguration, @NotNull final Project project) {
ExecutionTab(final GlobalAntConfiguration antConfiguration) {
myAntGlobalConfiguration = antConfiguration;
myProject = project;
myAntCommandLine.attachLabel(myAntCmdLineLabel);
myAntCommandLine.setDialogCaption(AntBundle.message("run.execution.tab.ant.command.line.dialog.title"));
setLabelFor(myJDKLabel, myJDKs);
@@ -1,12 +1,10 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.ant.config.impl.configuration;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Factory;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.ScrollingUtil;
import com.intellij.ui.SortedListModel;
import com.intellij.ui.TableUtil;
import com.intellij.ui.table.BaseTableView;
import com.intellij.util.config.AbstractProperty;
@@ -17,7 +15,10 @@ import com.intellij.util.ui.ListTableModel;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;
@@ -29,7 +30,10 @@ import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
public abstract class UIPropertyBinding {
public abstract void loadValues(AbstractProperty.AbstractPropertyContainer container);
@@ -48,10 +52,9 @@ public abstract class UIPropertyBinding {
public static class Composite extends UIPropertyBinding {
private final ArrayList<UIPropertyBinding> myBindings = new ArrayList<>();
public ToggleButtonBinding bindBoolean(JToggleButton toggleButton, AbstractProperty<Boolean> property) {
public void bindBoolean(JToggleButton toggleButton, AbstractProperty<Boolean> property) {
ToggleButtonBinding binding = new ToggleButtonBinding(toggleButton, property);
myBindings.add(binding);
return binding;
}
public void bindInt(JTextComponent textComponent, AbstractProperty<Integer> property) {
@@ -193,10 +196,6 @@ public abstract class UIPropertyBinding {
getProperty().set(container, getComponent().isSelected());
}
public void addChangeListener(PropertyChangeListener listener) {
myChangeSupport.addListener(listener);
}
@Override
public void beforeClose(AbstractProperty.AbstractPropertyContainer container) {
myChangeSupport.stop();
@@ -274,7 +273,7 @@ public abstract class UIPropertyBinding {
public static <Comp extends JComponent, Listener> ChangeValueSupport create(Comp component,
ListenerInstaller<Comp, Listener> installer,
String propertyName) {
return new ChangeValueSupport(component, installer, propertyName);
return new ChangeValueSupport<>(component, installer, propertyName);
}
public void stop() {
@@ -408,11 +407,8 @@ public abstract class UIPropertyBinding {
myModel.setItems(myProperty.getModifiableList(container));
if (myModel.isSortable()) {
final ColumnInfo[] columnInfos = myModel.getColumnInfos();
int sortByColumn = -1;
for (int idx = 0; idx < columnInfos.length; idx++) {
ColumnInfo columnInfo = columnInfos[idx];
for (ColumnInfo columnInfo : columnInfos) {
if (columnInfo.isSortable()) {
sortByColumn = idx;
break;
}
}
@@ -451,74 +447,9 @@ public abstract class UIPropertyBinding {
getComponent().getTableHeader().setResizingAllowed(true);
}
public void addAddFacility(JButton addButton, final Factory<T> factory) {
myComponents.add(addButton);
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JTable table = getComponent();
if (table.isEditing() && !table.getCellEditor().stopCellEditing()) {
return;
}
T item = factory.create();
if (item == null) {
return;
}
ArrayList<T> items = new ArrayList<>(myModel.getItems());
items.add(item);
myModel.setItems(items);
int newIndex = myModel.indexOf(item);
ListSelectionModel selectionModel = table.getSelectionModel();
selectionModel.clearSelection();
selectionModel.setSelectionInterval(newIndex, newIndex);
ColumnInfo[] columns = myModel.getColumnInfos();
for (int i = 0; i < columns.length; i++) {
ColumnInfo column = columns[i];
if (column.isCellEditable(item)) {
table.requestFocusInWindow();
table.editCellAt(newIndex, i);
break;
}
}
}
});
}
public void setSortable(boolean isSortable) {
myModel.setSortable(isSortable);
}
public void addRemoveFacility(final JButton button, final Condition<T> removable) {
myComponents.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TableUtil.removeSelectedItems(getComponent());
}
});
getComponent().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
updateRemoveButton(button, removable);
}
});
}
public void updateRemoveButton(JButton button, Condition<T> removable) {
final JTable table = getComponent();
final ListSelectionModel selectionModel = table.getSelectionModel();
boolean enable = false;
if (!selectionModel.isSelectionEmpty()) {
enable = true;
for (int i : table.getSelectedRows()) {
if (!removable.value(myModel.getItems().get(i))) {
enable = false;
break;
}
}
}
button.setEnabled(enable);
}
}
private static abstract class BaseListBinding<Item> extends UIPropertyBinding {
@@ -574,23 +505,6 @@ public abstract class UIPropertyBinding {
}
}
public static class SortedListBinding<T extends JDOMExternalizable> extends BaseListBinding<T> {
public SortedListBinding(JList list, ListProperty<T> property, Comparator<T> comparator) {
super(property, list);
list.setModel(new SortedListModel<>(comparator));
}
@Override
public void loadValues(AbstractProperty.AbstractPropertyContainer container) {
getModel().setAll(getProperty().get(container));
ScrollingUtil.ensureSelectionExists(getList());
}
private SortedListModel<T> getModel() {
return ((SortedListModel<T>)getList().getModel());
}
}
public static class OrderListBinding<T> extends BaseListBinding<T> {
public OrderListBinding(JList list, ListProperty<T> property) {
super(property, list);
@@ -613,7 +527,7 @@ public abstract class UIPropertyBinding {
return ((DefaultListModel)getList().getModel());
}
public void addAddManyFacility(JButton button, final Factory<List<T>> factory) {
public void addAddManyFacility(JButton button, final Factory<? extends List<T>> factory) {
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {