1 package com
.intellij
.compiler
.ant
;
3 import com
.intellij
.compiler
.ant
.artifacts
.ArtifactsGenerator
;
4 import com
.intellij
.compiler
.ant
.taskdefs
.AntProject
;
5 import com
.intellij
.compiler
.ant
.taskdefs
.Target
;
6 import com
.intellij
.openapi
.compiler
.CompilerBundle
;
7 import com
.intellij
.openapi
.project
.Project
;
8 import com
.intellij
.packaging
.artifacts
.ArtifactManager
;
10 import java
.io
.IOException
;
11 import java
.io
.PrintWriter
;
12 import java
.util
.List
;
15 * @author Eugene Zhuravlev
18 public abstract class ProjectBuild
extends Generator
{
19 protected final Project myProject
;
20 private final AntProject myAntProject
;
22 public ProjectBuild(Project project
, GenerationOptions genOptions
) {
24 myAntProject
= new AntProject(BuildProperties
.getProjectBuildFileName(myProject
), BuildProperties
.DEFAULT_TARGET
);
26 myAntProject
.add(new BuildPropertiesImpl(myProject
, genOptions
), 1);
28 // the sequence in which modules are imported is important cause output path properties for dependent modules should be defined first
30 final StringBuilder alltargetNames
= new StringBuilder();
31 alltargetNames
.append(BuildProperties
.TARGET_INIT
);
32 alltargetNames
.append(", ");
33 alltargetNames
.append(BuildProperties
.TARGET_CLEAN
);
34 final ModuleChunk
[] chunks
= genOptions
.getModuleChunks();
36 if (chunks
.length
> 0) {
37 myAntProject
.add(new Comment(CompilerBundle
.message("generated.ant.build.modules.section.title")), 1);
39 for (final ModuleChunk chunk
: chunks
) {
40 myAntProject
.add(createModuleBuildGenerator(chunk
, genOptions
), 1);
41 final String
[] targets
= ChunkBuildExtension
.getAllTargets(chunk
);
42 for (String target
: targets
) {
43 if (alltargetNames
.length() > 0) {
44 alltargetNames
.append(", ");
46 alltargetNames
.append(target
);
51 final Target initTarget
= new Target(BuildProperties
.TARGET_INIT
, null,
52 CompilerBundle
.message("generated.ant.build.initialization.section.title"), null);
53 initTarget
.add(new Comment(CompilerBundle
.message("generated.ant.build.initialization.section.comment")));
54 myAntProject
.add(initTarget
, 1);
56 ArtifactsGenerator artifactsGenerator
;
57 if (ArtifactManager
.getInstance(project
).getArtifacts().length
> 0) {
58 artifactsGenerator
= new ArtifactsGenerator(project
, genOptions
);
61 artifactsGenerator
= null;
64 myAntProject
.add(new CleanProject(genOptions
, artifactsGenerator
), 1);
66 if (artifactsGenerator
!= null) {
67 List
<Generator
> generators
= artifactsGenerator
.generate();
68 for (Generator generator
: generators
) {
69 myAntProject
.add(generator
, 1);
72 if (alltargetNames
.length() > 0) {
73 alltargetNames
.append(", ");
75 alltargetNames
.append(ArtifactsGenerator
.BUILD_ALL_ARTIFACTS_TARGET
);
78 myAntProject
.add(new Target(BuildProperties
.TARGET_ALL
, alltargetNames
.toString(),
79 CompilerBundle
.message("generated.ant.build.build.all.target.name"), null), 1);
82 public void generate(PrintWriter out
) throws IOException
{
83 //noinspection HardCodedStringLiteral
85 myAntProject
.generate(out
);
88 protected abstract Generator
createModuleBuildGenerator(final ModuleChunk chunk
, GenerationOptions genOptions
);