IDEADEV-41212: Created an artifact from a folder, then renamed the artifact and it...
[fedora-idea.git] / java / compiler / impl / src / com / intellij / packaging / impl / run / BuildArtifactsBeforeRunTask.java
blob65a1d8d36be6c8a51ce8f39855f8468bc0e07504
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.packaging.impl.run;
18 import com.intellij.execution.BeforeRunTask;
19 import com.intellij.openapi.project.Project;
20 import com.intellij.packaging.artifacts.Artifact;
21 import com.intellij.packaging.artifacts.ArtifactPointer;
22 import com.intellij.packaging.artifacts.ArtifactPointerManager;
23 import org.jdom.Element;
24 import org.jetbrains.annotations.NonNls;
26 import java.util.ArrayList;
27 import java.util.Collections;
28 import java.util.List;
30 /**
31 * @author nik
33 public class BuildArtifactsBeforeRunTask extends BeforeRunTask {
34 @NonNls public static final String NAME_ATTRIBUTE = "name";
35 @NonNls public static final String ARTIFACT_ELEMENT = "artifact";
36 private List<ArtifactPointer> myArtifactPointers = new ArrayList<ArtifactPointer>();
37 private final Project myProject;
39 public BuildArtifactsBeforeRunTask(Project project) {
40 myProject = project;
43 @Override
44 public void readExternal(Element element) {
45 super.readExternal(element);
46 final List<Element> children = element.getChildren(ARTIFACT_ELEMENT);
47 final ArtifactPointerManager pointerManager = ArtifactPointerManager.getInstance(myProject);
48 for (Element child : children) {
49 myArtifactPointers.add(pointerManager.createPointer(child.getAttributeValue(NAME_ATTRIBUTE)));
53 @Override
54 public void writeExternal(Element element) {
55 super.writeExternal(element);
56 for (ArtifactPointer pointer : myArtifactPointers) {
57 element.addContent(new Element(ARTIFACT_ELEMENT).setAttribute(NAME_ATTRIBUTE, pointer.getArtifactName()));
61 @Override
62 public BeforeRunTask clone() {
63 final BuildArtifactsBeforeRunTask task = (BuildArtifactsBeforeRunTask)super.clone();
64 task.myArtifactPointers = new ArrayList<ArtifactPointer>(myArtifactPointers);
65 return task;
68 public List<ArtifactPointer> getArtifactPointers() {
69 return Collections.unmodifiableList(myArtifactPointers);
72 public void setArtifactPointers(List<ArtifactPointer> artifactPointers) {
73 myArtifactPointers = new ArrayList<ArtifactPointer>(artifactPointers);
76 public void addArtifact(Artifact artifact) {
77 final ArtifactPointer pointer = ArtifactPointerManager.getInstance(myProject).createPointer(artifact);
78 if (!myArtifactPointers.contains(pointer)) {
79 myArtifactPointers.add(pointer);
83 public void removeArtifact(Artifact artifact) {
84 myArtifactPointers.remove(ArtifactPointerManager.getInstance(myProject).createPointer(artifact));
87 public boolean equals(Object o) {
88 if (this == o) return true;
89 if (o == null || getClass() != o.getClass()) return false;
90 if (!super.equals(o)) return false;
92 BuildArtifactsBeforeRunTask that = (BuildArtifactsBeforeRunTask)o;
94 if (!myArtifactPointers.equals(that.myArtifactPointers)) return false;
95 if (!myProject.equals(that.myProject)) return false;
97 return true;
100 public int hashCode() {
101 int result = super.hashCode();
102 result = 31 * result + myArtifactPointers.hashCode();
103 result = 31 * result + myProject.hashCode();
104 return result;