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
.util
.UserDataHolderBase
;
19 import com
.intellij
.packaging
.artifacts
.*;
20 import com
.intellij
.packaging
.elements
.CompositePackagingElement
;
21 import com
.intellij
.util
.EventDispatcher
;
22 import org
.jetbrains
.annotations
.NotNull
;
23 import org
.jetbrains
.annotations
.NonNls
;
25 import java
.util
.Collection
;
26 import java
.util
.Collections
;
27 import java
.util
.HashMap
;
33 public class ArtifactImpl
extends UserDataHolderBase
implements ModifiableArtifact
{
34 private CompositePackagingElement
<?
> myRootElement
;
35 private String myName
;
36 private boolean myBuildOnMake
;
37 private String myOutputPath
;
38 private final EventDispatcher
<ArtifactListener
> myDispatcher
;
39 private ArtifactType myArtifactType
;
40 private Map
<ArtifactPropertiesProvider
, ArtifactProperties
<?
>> myProperties
;
42 public ArtifactImpl(@NotNull String name
, @NotNull ArtifactType artifactType
, boolean buildOnMake
, @NotNull CompositePackagingElement
<?
> rootElement
,
44 this(name
, artifactType
, buildOnMake
, rootElement
, outputPath
, null);
46 public ArtifactImpl(@NotNull String name
, @NotNull ArtifactType artifactType
, boolean buildOnMake
, @NotNull CompositePackagingElement
<?
> rootElement
,
48 EventDispatcher
<ArtifactListener
> dispatcher
) {
50 myArtifactType
= artifactType
;
51 myBuildOnMake
= buildOnMake
;
52 myRootElement
= rootElement
;
53 myOutputPath
= outputPath
;
54 myDispatcher
= dispatcher
;
55 myProperties
= new HashMap
<ArtifactPropertiesProvider
, ArtifactProperties
<?
>>();
59 private void resetProperties() {
61 for (ArtifactPropertiesProvider provider
: ArtifactPropertiesProvider
.getProviders()) {
62 if (provider
.isAvailableFor(myArtifactType
)) {
63 myProperties
.put(provider
, provider
.createProperties(myArtifactType
));
69 public ArtifactType
getArtifactType() {
70 return myArtifactType
;
73 public String
getName() {
77 public boolean isBuildOnMake() {
82 public CompositePackagingElement
<?
> getRootElement() {
86 public String
getOutputPath() {
90 public Collection
<?
extends ArtifactPropertiesProvider
> getPropertiesProviders() {
91 return Collections
.unmodifiableCollection(myProperties
.keySet());
94 public ArtifactImpl
createCopy(EventDispatcher
<ArtifactListener
> dispatcher
) {
95 final ArtifactImpl artifact
= new ArtifactImpl(myName
, myArtifactType
, myBuildOnMake
, myRootElement
, myOutputPath
, dispatcher
);
96 for (Map
.Entry
<ArtifactPropertiesProvider
, ArtifactProperties
<?
>> entry
: myProperties
.entrySet()) {
97 final ArtifactProperties newProperties
= artifact
.myProperties
.get(entry
.getKey());
98 //noinspection unchecked
99 newProperties
.loadState(entry
.getValue().getState());
104 public void setName(@NotNull String name
) {
105 String oldName
= myName
;
107 if (myDispatcher
!= null) {
108 myDispatcher
.getMulticaster().artifactChanged(this, oldName
);
113 public String
toString() {
114 return "artifact:" + myName
;
117 public void setRootElement(CompositePackagingElement
<?
> root
) {
118 myRootElement
= root
;
121 public void setProperties(ArtifactPropertiesProvider provider
, ArtifactProperties
<?
> properties
) {
122 if (properties
!= null) {
123 myProperties
.put(provider
, properties
);
126 myProperties
.remove(provider
);
130 public void setArtifactType(@NotNull ArtifactType selected
) {
131 myArtifactType
= selected
;
135 public void setBuildOnMake(boolean buildOnMake
) {
136 myBuildOnMake
= buildOnMake
;
139 public void setOutputPath(String outputPath
) {
140 myOutputPath
= outputPath
;
143 public ArtifactProperties
<?
> getProperties(@NotNull ArtifactPropertiesProvider provider
) {
144 return myProperties
.get(provider
);
147 public void copyFrom(ArtifactImpl modified
) {
148 myName
= modified
.getName();
149 myOutputPath
= modified
.getOutputPath();
150 myBuildOnMake
= modified
.isBuildOnMake();
151 myRootElement
= modified
.getRootElement();
152 myProperties
= modified
.myProperties
;
153 myArtifactType
= modified
.getArtifactType();