From f52fc127223336d9148c242341a7002f4c46e43c Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 12 Nov 2010 10:45:26 +0300 Subject: [PATCH] improved handling of artifacts with unknown elements --- .../ArtifactLoadingErrorDescription.java | 58 +++++++++ .../impl/artifacts/ArtifactManagerImpl.java | 117 +++++++++++------- .../impl/artifacts/ArtifactModelBase.java | 17 ++- .../impl/artifacts/InvalidArtifact.java | 40 ++++++ .../impl/artifacts/InvalidArtifactType.java | 58 +++++++++ .../UnknownPackagingElementTypeException.java | 31 +++++ .../elements/PackagingElementFactoryImpl.java | 2 +- .../packaging/artifacts/ArtifactModel.java | 3 + .../artifacts/ArtifactConfigurable.java | 48 +------ .../artifacts/ArtifactConfigurableBase.java | 72 +++++++++++ .../ArtifactsStructureConfigurable.java | 15 ++- .../artifacts/InvalidArtifactComponent.form | 40 ++++++ .../InvalidArtifactConfigurable.java | 75 +++++++++++ .../com/intellij/facet/FacetManagerImpl.java | 1 - resources/src/META-INF/IdeaPlugin.xml | 1 + 15 files changed, 485 insertions(+), 93 deletions(-) create mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactLoadingErrorDescription.java create mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/artifacts/InvalidArtifact.java create mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/artifacts/InvalidArtifactType.java create mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/artifacts/UnknownPackagingElementTypeException.java create mode 100644 java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactConfigurableBase.java create mode 100644 java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/InvalidArtifactComponent.form create mode 100644 java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/InvalidArtifactConfigurable.java diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactLoadingErrorDescription.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactLoadingErrorDescription.java new file mode 100644 index 000000000000..5ca3007d10e4 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactLoadingErrorDescription.java @@ -0,0 +1,58 @@ +/* + * Copyright 2000-2010 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.packaging.impl.artifacts; + +import com.intellij.openapi.application.Result; +import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.module.ConfigurationErrorDescription; +import com.intellij.openapi.project.Project; +import com.intellij.packaging.artifacts.ArtifactManager; +import com.intellij.packaging.artifacts.ModifiableArtifactModel; + +/** + * @author nik + */ +public class ArtifactLoadingErrorDescription extends ConfigurationErrorDescription { + private final Project myProject; + private final InvalidArtifact myArtifact; + + public ArtifactLoadingErrorDescription(Project project, InvalidArtifact artifact) { + super(artifact.getName(), "artifact", artifact.getErrorMessage()); + myProject = project; + myArtifact = artifact; + } + + @Override + public void removeInvalidElement() { + final ModifiableArtifactModel model = ArtifactManager.getInstance(myProject).createModifiableModel(); + model.removeArtifact(myArtifact); + new WriteAction() { + protected void run(final Result result) { + model.commit(); + } + }.execute(); + } + + @Override + public String getRemoveConfirmationMessage() { + return "Would you like to remove artifact '" + myArtifact.getName() + "?"; + } + + @Override + public boolean isValid() { + return ArtifactManager.getInstance(myProject).getAllArtifactsIncludingInvalid().contains(myArtifact); + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java index 6b6d04c3eed6..d02cbcf99906 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java @@ -20,6 +20,7 @@ import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.components.*; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.module.ProjectLoadingErrorsNotifier; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ex.ProjectRootManagerEx; import com.intellij.openapi.util.ModificationTracker; @@ -97,26 +98,37 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo return myModel.getArtifactsByType(type); } + @Override + public List getAllArtifactsIncludingInvalid() { + return myModel.getAllArtifactsIncludingInvalid(); + } + public ArtifactManagerState getState() { final ArtifactManagerState state = new ArtifactManagerState(); - for (Artifact artifact : getArtifacts()) { - final ArtifactState artifactState = new ArtifactState(); - artifactState.setBuildOnMake(artifact.isBuildOnMake()); - artifactState.setName(artifact.getName()); - artifactState.setOutputPath(artifact.getOutputPath()); - artifactState.setRootElement(serializePackagingElement(artifact.getRootElement())); - artifactState.setArtifactType(artifact.getArtifactType().getId()); - for (ArtifactPropertiesProvider provider : artifact.getPropertiesProviders()) { - final ArtifactPropertiesState propertiesState = serializeProperties(provider, artifact.getProperties(provider)); - if (propertiesState != null) { - artifactState.getPropertiesList().add(propertiesState); - } + for (Artifact artifact : getAllArtifactsIncludingInvalid()) { + final ArtifactState artifactState; + if (artifact instanceof InvalidArtifact) { + artifactState = ((InvalidArtifact)artifact).getState(); } - Collections.sort(artifactState.getPropertiesList(), new Comparator() { - public int compare(ArtifactPropertiesState o1, ArtifactPropertiesState o2) { - return o1.getId().compareTo(o2.getId()); + else { + artifactState = new ArtifactState(); + artifactState.setBuildOnMake(artifact.isBuildOnMake()); + artifactState.setName(artifact.getName()); + artifactState.setOutputPath(artifact.getOutputPath()); + artifactState.setRootElement(serializePackagingElement(artifact.getRootElement())); + artifactState.setArtifactType(artifact.getArtifactType().getId()); + for (ArtifactPropertiesProvider provider : artifact.getPropertiesProviders()) { + final ArtifactPropertiesState propertiesState = serializeProperties(provider, artifact.getProperties(provider)); + if (propertiesState != null) { + artifactState.getPropertiesList().add(propertiesState); + } } - }); + Collections.sort(artifactState.getPropertiesList(), new Comparator() { + public int compare(ArtifactPropertiesState o1, ArtifactPropertiesState o2) { + return o1.getId().compareTo(o2.getId()); + } + }); + } state.getArtifacts().add(artifactState); } return state; @@ -148,9 +160,13 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo return element; } - private PackagingElement deserializeElement(Element element) { + private PackagingElement deserializeElement(Element element) throws UnknownPackagingElementTypeException { final String id = element.getAttributeValue(TYPE_ID_ATTRIBUTE); PackagingElementType type = PackagingElementFactory.getInstance().findElementType(id); + if (type == null) { + throw new UnknownPackagingElementTypeException(id); + } + PackagingElement packagingElement = (PackagingElement)type.createEmpty(myProject); T state = packagingElement.getState(); if (state != null) { @@ -168,31 +184,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo public void loadState(ArtifactManagerState managerState) { final List artifacts = new ArrayList(); for (ArtifactState state : managerState.getArtifacts()) { - final Element element = state.getRootElement(); - ArtifactType type = ArtifactType.findById(state.getArtifactType()); - if (type == null) { - LOG.info("Unknown artifact type: " + state.getArtifactType()); - continue; - } - - final String artifactName = state.getName(); - final CompositePackagingElement rootElement; - if (element != null) { - rootElement = (CompositePackagingElement)deserializeElement(element); - } - else { - rootElement = type.createRootElement(artifactName); - } - - final ArtifactImpl artifact = new ArtifactImpl(artifactName, type, state.isBuildOnMake(), rootElement, state.getOutputPath()); - final List propertiesList = state.getPropertiesList(); - for (ArtifactPropertiesState propertiesState : propertiesList) { - final ArtifactPropertiesProvider provider = ArtifactPropertiesProvider.findById(propertiesState.getId()); - if (provider != null) { - deserializeProperties(artifact.getProperties(provider), propertiesState); - } - } - artifacts.add(artifact); + artifacts.add(loadArtifact(state)); } if (myLoaded) { @@ -205,6 +197,47 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo } } + private ArtifactImpl loadArtifact(ArtifactState state) { + ArtifactType type = ArtifactType.findById(state.getArtifactType()); + if (type == null) { + return createInvalidArtifact(state, "Unknown artifact type: " + state.getArtifactType()); + } + + final Element element = state.getRootElement(); + final String artifactName = state.getName(); + final CompositePackagingElement rootElement; + if (element != null) { + try { + rootElement = (CompositePackagingElement)deserializeElement(element); + } + catch (UnknownPackagingElementTypeException e) { + return createInvalidArtifact(state, "Unknown element: " + e.getTypeId()); + } + } + else { + rootElement = type.createRootElement(artifactName); + } + + final ArtifactImpl artifact = new ArtifactImpl(artifactName, type, state.isBuildOnMake(), rootElement, state.getOutputPath()); + final List propertiesList = state.getPropertiesList(); + for (ArtifactPropertiesState propertiesState : propertiesList) { + final ArtifactPropertiesProvider provider = ArtifactPropertiesProvider.findById(propertiesState.getId()); + if (provider != null) { + deserializeProperties(artifact.getProperties(provider), propertiesState); + } + else { + return createInvalidArtifact(state, "Unknown artifact properties: " + propertiesState.getId()); + } + } + return artifact; + } + + private InvalidArtifact createInvalidArtifact(ArtifactState state, String errorMessage) { + final InvalidArtifact artifact = new InvalidArtifact(state, errorMessage); + ProjectLoadingErrorsNotifier.getInstance(myProject).registerError(new ArtifactLoadingErrorDescription(myProject, artifact)); + return artifact; + } + private static void deserializeProperties(ArtifactProperties artifactProperties, ArtifactPropertiesState propertiesState) { final Element options = propertiesState.getOptions(); if (artifactProperties == null || options == null) { diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelBase.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelBase.java index ee67d33edb5e..9dbfa2a493fa 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelBase.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelBase.java @@ -15,9 +15,11 @@ */ package com.intellij.packaging.impl.artifacts; +import com.intellij.openapi.util.Condition; import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.artifacts.ArtifactModel; import com.intellij.packaging.artifacts.ArtifactType; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -28,18 +30,29 @@ import java.util.*; public abstract class ArtifactModelBase implements ArtifactModel { private Map myArtifactsMap; private Artifact[] myArtifactsArray; + public static final Condition VALID_ARTIFACT_CONDITION = new Condition() { + @Override + public boolean value(Artifact artifact) { + return !(artifact instanceof InvalidArtifact); + } + }; protected abstract List getArtifactsList(); @NotNull public Artifact[] getArtifacts() { if (myArtifactsArray == null) { - final List artifacts = getArtifactsList(); - myArtifactsArray = artifacts.toArray(new Artifact[artifacts.size()]); + final List validArtifacts = ContainerUtil.findAll(getArtifactsList(), VALID_ARTIFACT_CONDITION); + myArtifactsArray = validArtifacts.toArray(new Artifact[validArtifacts.size()]); } return myArtifactsArray; } + @Override + public List getAllArtifactsIncludingInvalid() { + return Collections.unmodifiableList(getArtifactsList()); + } + public Artifact findArtifact(@NotNull String name) { if (myArtifactsMap == null) { myArtifactsMap = new HashMap(); diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/InvalidArtifact.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/InvalidArtifact.java new file mode 100644 index 000000000000..6f25a287f881 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/InvalidArtifact.java @@ -0,0 +1,40 @@ +/* + * Copyright 2000-2010 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.packaging.impl.artifacts; + +import com.intellij.packaging.elements.PackagingElementFactory; + +/** + * @author nik + */ +public class InvalidArtifact extends ArtifactImpl { + private ArtifactState myState; + private final String myErrorMessage; + + public InvalidArtifact(ArtifactState state, String errorMessage) { + super(state.getName(), InvalidArtifactType.getInstance(), false, PackagingElementFactory.getInstance().createArtifactRootElement(), ""); + myState = state; + myErrorMessage = errorMessage; + } + + public String getErrorMessage() { + return myErrorMessage; + } + + public ArtifactState getState() { + return myState; + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/InvalidArtifactType.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/InvalidArtifactType.java new file mode 100644 index 000000000000..ef483f9b54e4 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/InvalidArtifactType.java @@ -0,0 +1,58 @@ +/* + * Copyright 2000-2010 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.packaging.impl.artifacts; + +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.util.IconLoader; +import com.intellij.packaging.artifacts.ArtifactType; +import com.intellij.packaging.elements.CompositePackagingElement; +import com.intellij.packaging.elements.PackagingElementFactory; +import com.intellij.packaging.elements.PackagingElementOutputKind; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** + * @author nik + */ +public class InvalidArtifactType extends ArtifactType { + public static final Icon ICON = IconLoader.getIcon("/fileTypes/unknown.png"); + + public static InvalidArtifactType getInstance() { + return ServiceManager.getService(InvalidArtifactType.class); + } + + public InvalidArtifactType() { + super("invalid", "Invalid"); + } + + @NotNull + @Override + public Icon getIcon() { + return ICON; + } + + @Override + public String getDefaultPathFor(@NotNull PackagingElementOutputKind kind) { + return ""; + } + + @NotNull + @Override + public CompositePackagingElement createRootElement(@NotNull String artifactName) { + return PackagingElementFactory.getInstance().createArtifactRootElement(); + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/UnknownPackagingElementTypeException.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/UnknownPackagingElementTypeException.java new file mode 100644 index 000000000000..9856fec18985 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/UnknownPackagingElementTypeException.java @@ -0,0 +1,31 @@ +/* + * Copyright 2000-2010 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.packaging.impl.artifacts; + +/** + * @author nik + */ +class UnknownPackagingElementTypeException extends Exception { + private final String myTypeId; + + public UnknownPackagingElementTypeException(String typeId) { + myTypeId = typeId; + } + + public String getTypeId() { + return myTypeId; + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java index 7ec062a7101a..1fadf9c7b11b 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java @@ -108,7 +108,7 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory { if (id.equals(ARTIFACT_ROOT_ELEMENT_TYPE.getId())) { return ARTIFACT_ROOT_ELEMENT_TYPE; } - throw new AssertionError(id + " not registered"); + return null; } @NotNull diff --git a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactModel.java b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactModel.java index 1a11ecbb4c67..91f3ae71c6ef 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactModel.java +++ b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactModel.java @@ -19,6 +19,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.List; /** * @author nik @@ -37,4 +38,6 @@ public interface ArtifactModel { Artifact getOriginalArtifact(@NotNull Artifact artifact); Collection getArtifactsByType(@NotNull ArtifactType type); + + List getAllArtifactsIncludingInvalid(); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactConfigurable.java index a1925aa881bb..fbf3989eebca 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactConfigurable.java @@ -16,14 +16,10 @@ package com.intellij.openapi.roots.ui.configuration.artifacts; import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.project.ProjectBundle; -import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectStructureElementConfigurable; -import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement; import com.intellij.openapi.ui.ComboBox; import com.intellij.openapi.util.Comparing; import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.artifacts.ArtifactType; -import org.jetbrains.annotations.Nls; import javax.swing.*; import java.awt.*; @@ -33,19 +29,13 @@ import java.awt.event.ActionListener; /** * @author nik */ -public class ArtifactConfigurable extends ProjectStructureElementConfigurable { - private final Artifact myOriginalArtifact; - private final ArtifactsStructureConfigurableContext myArtifactsStructureContext; +public class ArtifactConfigurable extends ArtifactConfigurableBase { private final ArtifactEditorImpl myEditor; private boolean myIsInUpdateName; - private final ProjectStructureElement myProjectStructureElement; public ArtifactConfigurable(Artifact originalArtifact, ArtifactsStructureConfigurableContextImpl artifactsStructureContext, final Runnable updateTree) { - super(true, updateTree); - myOriginalArtifact = originalArtifact; - myArtifactsStructureContext = artifactsStructureContext; + super(originalArtifact, artifactsStructureContext, updateTree, true); myEditor = artifactsStructureContext.getOrCreateEditor(originalArtifact); - myProjectStructureElement = myArtifactsStructureContext.getOrCreateArtifactElement(myOriginalArtifact); } public void setDisplayName(String name) { @@ -56,11 +46,6 @@ public class ArtifactConfigurable extends ProjectStructureElementConfigurable { + protected final Artifact myOriginalArtifact; + protected final ArtifactsStructureConfigurableContext myArtifactsStructureContext; + protected final ProjectStructureElement myProjectStructureElement; + + public ArtifactConfigurableBase(Artifact originalArtifact, + ArtifactsStructureConfigurableContextImpl artifactsStructureContext, + Runnable updateTree, + final boolean nameEditable) { + super(nameEditable, updateTree); + myOriginalArtifact = originalArtifact; + myArtifactsStructureContext = artifactsStructureContext; + myProjectStructureElement = myArtifactsStructureContext.getOrCreateArtifactElement(myOriginalArtifact); + } + + @Override + public ProjectStructureElement getProjectStructureElement() { + return myProjectStructureElement; + } + + protected Artifact getArtifact() { + return myArtifactsStructureContext.getArtifactModel().getArtifactByOriginal(myOriginalArtifact); + } + + public Artifact getEditableObject() { + return getArtifact(); + } + + public String getBannerSlogan() { + return ProjectBundle.message("banner.slogan.artifact.0", getDisplayName()); + } + + @Nls + public String getDisplayName() { + return getArtifact().getName(); + } + + public Icon getIcon() { + return getArtifact().getArtifactType().getIcon(); + } + + public void disposeUIResources() { + } +} diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java index 59a93707edc1..7a4ad7c84be6 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java @@ -35,8 +35,10 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.*; import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement; import com.intellij.openapi.ui.MasterDetailsState; import com.intellij.openapi.ui.MasterDetailsStateService; +import com.intellij.openapi.ui.NamedConfigurable; import com.intellij.packaging.artifacts.*; import com.intellij.packaging.impl.artifacts.ArtifactUtil; +import com.intellij.packaging.impl.artifacts.InvalidArtifact; import com.intellij.packaging.impl.artifacts.PackagingElementPath; import com.intellij.packaging.impl.artifacts.PackagingElementProcessor; import com.intellij.packaging.impl.elements.LibraryElementType; @@ -177,7 +179,7 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable { protected void loadTree() { myTree.setRootVisible(false); myTree.setShowsRootHandles(false); - for (Artifact artifact : myPackagingEditorContext.getArtifactModel().getArtifacts()) { + for (Artifact artifact : myPackagingEditorContext.getArtifactModel().getAllArtifactsIncludingInvalid()) { addArtifactNode(artifact); } } @@ -186,14 +188,21 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable { @Override protected Collection getProjectStructureElements() { final List elements = new ArrayList(); - for (Artifact artifact : myPackagingEditorContext.getArtifactModel().getArtifacts()) { + for (Artifact artifact : myPackagingEditorContext.getArtifactModel().getAllArtifactsIncludingInvalid()) { elements.add(myPackagingEditorContext.getOrCreateArtifactElement(artifact)); } return elements; } private MyNode addArtifactNode(final Artifact artifact) { - final MyNode node = new MyNode(new ArtifactConfigurable(artifact, myPackagingEditorContext, TREE_UPDATER)); + final NamedConfigurable configurable; + if (artifact instanceof InvalidArtifact) { + configurable = new InvalidArtifactConfigurable((InvalidArtifact)artifact, myPackagingEditorContext, TREE_UPDATER); + } + else { + configurable = new ArtifactConfigurable(artifact, myPackagingEditorContext, TREE_UPDATER); + } + final MyNode node = new MyNode(configurable); addNode(node, myRoot); return node; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/InvalidArtifactComponent.form b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/InvalidArtifactComponent.form new file mode 100644 index 000000000000..d291652cc74d --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/InvalidArtifactComponent.form @@ -0,0 +1,40 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/InvalidArtifactConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/InvalidArtifactConfigurable.java new file mode 100644 index 000000000000..2f4cd52613d4 --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/InvalidArtifactConfigurable.java @@ -0,0 +1,75 @@ +/* + * Copyright 2000-2010 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.openapi.roots.ui.configuration.artifacts; + +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.ui.ex.MultiLineLabel; +import com.intellij.openapi.util.IconLoader; +import com.intellij.packaging.impl.artifacts.InvalidArtifact; + +import javax.swing.*; + +/** + * @author nik + */ +public class InvalidArtifactConfigurable extends ArtifactConfigurableBase { + private String myErrorMessage; + + public InvalidArtifactConfigurable(InvalidArtifact originalArtifact, + ArtifactsStructureConfigurableContextImpl artifactsStructureContext, + Runnable updateTree) { + super(originalArtifact, artifactsStructureContext, updateTree, false); + myErrorMessage = originalArtifact.getErrorMessage(); + } + + @Override + public void setDisplayName(String name) { + } + + @Override + public JComponent createOptionsPanel() { + return new InvalidArtifactComponent(myErrorMessage).myMainPanel; + } + + @Override + public String getHelpTopic() { + return null; + } + + @Override + public boolean isModified() { + return false; + } + + @Override + public void apply() throws ConfigurationException { + } + + @Override + public void reset() { + } + + private static class InvalidArtifactComponent { + private JPanel myMainPanel; + private MultiLineLabel myDescriptionLabel; + private JLabel myIconLabel; + + private InvalidArtifactComponent(String errorMessage) { + myIconLabel.setIcon(IconLoader.getIcon("/runConfigurations/configurationWarning.png")); + myDescriptionLabel.setText(errorMessage); + } + } +} diff --git a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java index 87c324f654fd..9d79a0668894 100644 --- a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java @@ -213,7 +213,6 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P private void addInvalidFacet(final FacetState state, ModifiableFacetModel model, final Facet underlyingFacet, final String errorMessage) { final InvalidFacetManager invalidFacetManager = InvalidFacetManager.getInstance(myModule.getProject()); - final String typeId = StringUtil.notNullize(state.getFacetType()); final InvalidFacetType type = InvalidFacetType.getInstance(); final InvalidFacetConfiguration configuration = new InvalidFacetConfiguration(state, errorMessage); final InvalidFacet facet = createFacet(type, StringUtil.notNullize(state.getName()), configuration, underlyingFacet); diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index b76b0e883a3d..7f499a5444fc 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -373,6 +373,7 @@ serviceImplementation="com.intellij.packaging.impl.artifacts.ArtifactBySourceFileFinderImpl"/> +