artifact editor: allow to add one artifact output into two different places
authornik <Nikolay.Chashnikov@jetbrains.com>
Tue, 3 Aug 2010 09:19:18 +0000 (13:19 +0400)
committernik <Nikolay.Chashnikov@jetbrains.com>
Wed, 4 Aug 2010 08:19:45 +0000 (12:19 +0400)
java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactElementType.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ArtifactsSourceItemsProvider.java

index 8addfc9c57e0aa37c5d773b209edfda13c7e2bbf..2d661ba96f490ab93a814733c0db9af72b783a57 100644 (file)
@@ -48,14 +48,14 @@ public class ArtifactElementType extends ComplexPackagingElementType<ArtifactPac
 
   @Override
   public boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact) {
-    return !getAvailableArtifacts(context, artifact).isEmpty();
+    return !getAvailableArtifacts(context, artifact, false).isEmpty();
   }
 
   @NotNull
   public List<? extends ArtifactPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
                                                                    @NotNull CompositePackagingElement<?> parent) {
     final Project project = context.getProject();
-    List<Artifact> artifacts = context.chooseArtifacts(getAvailableArtifacts(context, artifact), CompilerBundle.message("dialog.title.choose.artifacts"));
+    List<Artifact> artifacts = context.chooseArtifacts(getAvailableArtifacts(context, artifact, false), CompilerBundle.message("dialog.title.choose.artifacts"));
     final List<ArtifactPackagingElement> elements = new ArrayList<ArtifactPackagingElement>();
     for (Artifact selected : artifacts) {
       elements.add(new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).createPointer(selected, context.getArtifactModel())));
@@ -64,14 +64,18 @@ public class ArtifactElementType extends ComplexPackagingElementType<ArtifactPac
   }
 
   @NotNull
-  public static List<? extends Artifact> getAvailableArtifacts(@NotNull final ArtifactEditorContext context, @NotNull final Artifact artifact) {
+  public static List<? extends Artifact> getAvailableArtifacts(@NotNull final ArtifactEditorContext context,
+                                                               @NotNull final Artifact artifact,
+                                                               final boolean notIncludedOnly) {
     final Set<Artifact> result = new HashSet<Artifact>(Arrays.asList(context.getArtifactModel().getArtifacts()));
-    ArtifactUtil.processPackagingElements(artifact, ARTIFACT_ELEMENT_TYPE, new Processor<ArtifactPackagingElement>() {
-      public boolean process(ArtifactPackagingElement artifactPackagingElement) {
-        result.remove(artifactPackagingElement.findArtifact(context));
-        return true;
-      }
-    }, context, true);
+    if (notIncludedOnly) {
+      ArtifactUtil.processPackagingElements(artifact, ARTIFACT_ELEMENT_TYPE, new Processor<ArtifactPackagingElement>() {
+        public boolean process(ArtifactPackagingElement artifactPackagingElement) {
+          result.remove(artifactPackagingElement.findArtifact(context));
+          return true;
+        }
+      }, context, true);
+    }
     result.remove(artifact);
     final Iterator<Artifact> iterator = result.iterator();
     while (iterator.hasNext()) {
index d369a8ffcc6d772d16bacc157d32667993ec17bd..42869e1134de403df33e70285384b472dbe13a7e 100644 (file)
@@ -39,13 +39,13 @@ public class ArtifactsSourceItemsProvider extends PackagingSourceItemsProvider {
                                                                   @NotNull Artifact artifact,
                                                                   @Nullable PackagingSourceItem parent) {
     if (parent == null) {
-      if (!ArtifactElementType.getAvailableArtifacts(editorContext, artifact).isEmpty()) {
+      if (!ArtifactElementType.getAvailableArtifacts(editorContext, artifact, true).isEmpty()) {
         return Collections.singletonList(new ArtifactsGroupSourceItem());
       }
     }
     else if (parent instanceof ArtifactsGroupSourceItem) {
       List<PackagingSourceItem> items = new ArrayList<PackagingSourceItem>();
-      for (Artifact another : ArtifactElementType.getAvailableArtifacts(editorContext, artifact)) {
+      for (Artifact another : ArtifactElementType.getAvailableArtifacts(editorContext, artifact, true)) {
         items.add(new ArtifactSourceItem(another));
       }
       return items;