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
.artifacts
;
18 import com
.intellij
.openapi
.project
.Project
;
19 import com
.intellij
.packaging
.artifacts
.*;
20 import org
.jetbrains
.annotations
.NotNull
;
22 import java
.util
.HashMap
;
23 import java
.util
.List
;
29 public class ArtifactPointerManagerImpl
extends ArtifactPointerManager
{
30 private final Map
<String
, ArtifactPointerImpl
> myUnresolvedPointers
= new HashMap
<String
, ArtifactPointerImpl
>();
31 private final Map
<Artifact
, ArtifactPointerImpl
> myPointers
= new HashMap
<Artifact
, ArtifactPointerImpl
>();
32 private ArtifactManager myArtifactManager
;
34 public ArtifactPointerManagerImpl(Project project
) {
35 project
.getMessageBus().connect().subscribe(ArtifactManager
.TOPIC
, new ArtifactAdapter() {
37 public void artifactRemoved(@NotNull Artifact artifact
) {
38 disposePointer(artifact
);
42 public void artifactAdded(@NotNull Artifact artifact
) {
43 final ArtifactPointerImpl pointer
= myPointers
.get(artifact
);
44 if (pointer
!= null) {
45 pointer
.setName(artifact
.getName());
48 final ArtifactPointerImpl unresolved
= myUnresolvedPointers
.remove(artifact
.getName());
49 if (unresolved
!= null) {
50 unresolved
.setArtifact(artifact
);
51 if (pointer
== null) {
52 myPointers
.put(artifact
, unresolved
);
58 public void artifactChanged(@NotNull Artifact artifact
, @NotNull String oldName
) {
59 final ArtifactPointerImpl pointer
= myPointers
.get(artifact
);
60 if (pointer
!= null) {
61 pointer
.setName(artifact
.getName());
64 final ArtifactPointerImpl unresolved
= myUnresolvedPointers
.remove(artifact
.getName());
65 if (unresolved
!= null) {
66 unresolved
.setArtifact(artifact
);
67 if (pointer
== null) {
68 myPointers
.put(artifact
, unresolved
);
75 public void setArtifactManager(ArtifactManager artifactManager
) {
76 myArtifactManager
= artifactManager
;
79 private void disposePointer(Artifact artifact
) {
80 final ArtifactPointerImpl pointer
= myPointers
.remove(artifact
);
81 if (pointer
!= null) {
82 pointer
.setArtifact(null);
83 myUnresolvedPointers
.put(pointer
.getArtifactName(), pointer
);
87 public ArtifactPointer
createPointer(@NotNull String name
) {
88 if (myArtifactManager
!= null) {
89 final Artifact artifact
= myArtifactManager
.findArtifact(name
);
90 if (artifact
!= null) {
91 return createPointer(artifact
);
95 ArtifactPointerImpl pointer
= myUnresolvedPointers
.get(name
);
96 if (pointer
== null) {
97 pointer
= new ArtifactPointerImpl(name
);
98 myUnresolvedPointers
.put(name
, pointer
);
103 public ArtifactPointer
createPointer(@NotNull Artifact artifact
) {
104 ArtifactPointerImpl pointer
= myPointers
.get(artifact
);
105 if (pointer
== null) {
106 pointer
= myUnresolvedPointers
.get(artifact
.getName());
107 if (pointer
!= null) {
108 pointer
.setArtifact(artifact
);
111 pointer
= new ArtifactPointerImpl(artifact
);
113 myPointers
.put(artifact
, pointer
);
119 public ArtifactPointer
createPointer(@NotNull Artifact artifact
, @NotNull ArtifactModel artifactModel
) {
120 return createPointer(artifactModel
.getOriginalArtifact(artifact
));
123 public void disposePointers(List
<Artifact
> artifacts
) {
124 for (Artifact artifact
: artifacts
) {
125 disposePointer(artifact
);