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
.lang
.ant
.config
.impl
;
18 import com
.intellij
.lang
.ant
.config
.*;
19 import com
.intellij
.openapi
.actionSystem
.impl
.SimpleDataContext
;
20 import com
.intellij
.openapi
.application
.ApplicationManager
;
21 import com
.intellij
.openapi
.compiler
.CompileContext
;
22 import com
.intellij
.openapi
.project
.Project
;
23 import com
.intellij
.openapi
.vfs
.VirtualFile
;
24 import com
.intellij
.packaging
.artifacts
.Artifact
;
25 import com
.intellij
.packaging
.artifacts
.ArtifactProperties
;
26 import com
.intellij
.packaging
.ui
.ArtifactPropertiesEditor
;
27 import com
.intellij
.packaging
.ui
.ArtifactEditorContext
;
28 import com
.intellij
.util
.xmlb
.XmlSerializerUtil
;
29 import com
.intellij
.util
.xmlb
.annotations
.Attribute
;
30 import com
.intellij
.util
.xmlb
.annotations
.Tag
;
31 import org
.jetbrains
.annotations
.NotNull
;
32 import org
.jetbrains
.annotations
.Nullable
;
37 public class AntArtifactPostprocessingProperties
extends ArtifactProperties
<AntArtifactPostprocessingProperties
> {
38 private String myFileUrl
;
39 private String myTargetName
;
40 private boolean myEnabled
;
42 public ArtifactPropertiesEditor
createEditor(@NotNull ArtifactEditorContext context
) {
43 return new AntArtifactPostprocessingPropertiesEditor(this, context
.getProject());
46 public AntArtifactPostprocessingProperties
getState() {
51 public void onBuildFinished(@NotNull Artifact artifact
, @NotNull final CompileContext compileContext
) {
53 final Project project
= compileContext
.getProject();
54 final AntBuildTarget target
= findTarget(AntConfiguration
.getInstance(project
));
56 ApplicationManager
.getApplication().invokeLater(new Runnable() {
58 target
.run(SimpleDataContext
.getProjectContext(project
), AntBuildListener
.NULL
);
65 public void loadState(AntArtifactPostprocessingProperties state
) {
66 XmlSerializerUtil
.copyBean(state
, this);
70 public String
getFileUrl() {
75 public String
getTargetName() {
80 public boolean isEnabled() {
84 public void setEnabled(boolean enabled
) {
88 public void setFileUrl(String fileUrl
) {
92 public void setTargetName(String targetName
) {
93 myTargetName
= targetName
;
97 public AntBuildTarget
findTarget(final AntConfiguration antConfiguration
) {
98 if (myFileUrl
== null || myTargetName
== null) return null;
100 final AntBuildFile
[] buildFiles
= antConfiguration
.getBuildFiles();
101 for (AntBuildFile buildFile
: buildFiles
) {
102 final VirtualFile file
= buildFile
.getVirtualFile();
103 if (file
!= null && file
.getUrl().equals(myFileUrl
)) {
104 final AntBuildModel buildModel
= buildFile
.getModel();
105 return buildModel
!= null ? buildModel
.findTarget(myTargetName
) : null;