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.
21 package org
.jetbrains
.idea
.devkit
.build
.ant
;
23 import com
.intellij
.compiler
.ant
.*;
24 import com
.intellij
.compiler
.ant
.taskdefs
.*;
25 import com
.intellij
.openapi
.module
.Module
;
26 import com
.intellij
.openapi
.roots
.CompilerModuleExtension
;
27 import com
.intellij
.openapi
.roots
.OrderRootType
;
28 import com
.intellij
.openapi
.roots
.libraries
.Library
;
29 import com
.intellij
.openapi
.vfs
.JarFileSystem
;
30 import com
.intellij
.openapi
.vfs
.VfsUtil
;
31 import com
.intellij
.openapi
.vfs
.VirtualFile
;
32 import org
.jetbrains
.annotations
.NonNls
;
33 import org
.jetbrains
.idea
.devkit
.DevKitBundle
;
34 import org
.jetbrains
.idea
.devkit
.build
.PluginBuildConfiguration
;
35 import org
.jetbrains
.idea
.devkit
.build
.PluginBuildUtil
;
36 import org
.jetbrains
.idea
.devkit
.build
.PrepareToDeployAction
;
39 import java
.io
.IOException
;
40 import java
.util
.HashSet
;
42 public class BuildJarTarget
extends Target
{
43 public BuildJarTarget(final ModuleChunk chunk
,
44 final GenerationOptions genOptions
,
45 final PluginBuildConfiguration moduleBuildProperties
) {
46 super(PluginBuildProperties
.getBuildJarTargetName(chunk
.getName()), null, DevKitBundle
.message("ant.build.jar.description", chunk
.getName()), null);
48 final File moduleBaseDir
= chunk
.getBaseDir();
50 final Module
[] modules
= chunk
.getModules();
52 final Module module
= modules
[0];
54 final String moduleName
= module
.getName();
57 final HashSet
<Library
> libs
= new HashSet
<Library
>();
58 for (Module module1
: modules
) {
59 PluginBuildUtil
.getLibraries(module1
, libs
);
62 final String jarPathPropertyRef
= BuildProperties
.propertyRef(PluginBuildProperties
.getJarPathProperty(moduleName
));
65 add(createPluginsJar(jarPathPropertyRef
, modules
, moduleBaseDir
, genOptions
, moduleBuildProperties
));
67 @NonNls final String tempSuffix
= "temp";
68 final File jarDir
= new File(moduleBaseDir
.getParentFile(), tempSuffix
);
69 String tempDir
= GenerationUtils
.toRelativePath(jarDir
.getPath(), chunk
, genOptions
);
70 final String tempDirProperty
= BuildProperties
.getTempDirForModuleProperty(moduleName
);
72 add(new Property(tempDirProperty
, tempDir
));
73 add(new Mkdir(BuildProperties
.propertyRef(tempDirProperty
)));
75 add(new Mkdir(BuildProperties
.propertyRef(tempDirProperty
) + "/lib"));
77 final @NonNls String libRelativePath
= BuildProperties
.propertyRef(tempDirProperty
) + "/lib/";
79 add(createPluginsJar(libRelativePath
+ chunk
.getName() + ".jar", modules
, moduleBaseDir
, genOptions
, moduleBuildProperties
));
81 for (Library lib
: libs
) {
82 final VirtualFile
[] files
= lib
.getFiles(OrderRootType
.CLASSES
);
83 for (VirtualFile file
: files
) {
84 final String relativePath
= GenerationUtils
.toRelativePath(file
, chunk
, genOptions
);
85 if (file
.getFileSystem() instanceof JarFileSystem
) {
86 add(new Copy(relativePath
, libRelativePath
+ file
.getName()));
88 final Jar jar
= new Jar(libRelativePath
+ file
.getNameWithoutExtension() + ".jar", "preserve");
89 jar
.add(new ZipFileSet(relativePath
, "", true));
95 final Tag zipTag
= new Zip(jarPathPropertyRef
);
96 zipTag
.add(new FileSet(tempDir
));
99 add(new Delete(BuildProperties
.propertyRef(tempDirProperty
)));
103 private static Tag
createPluginsJar(@NonNls final String jarPathProperty
,
104 final Module
[] modules
, final File moduleBaseDir
,
105 final GenerationOptions genOptions
,
106 final PluginBuildConfiguration moduleBuildProperties
) {
107 final Tag jarTag
= new Jar(jarPathProperty
, "preserve");
108 for (Module m
: modules
) {
109 final String path
= VfsUtil
.urlToPath(CompilerModuleExtension
.getInstance(m
).getCompilerOutputUrl());
110 final String relativePath
= GenerationUtils
.toRelativePath(path
, moduleBaseDir
, m
, genOptions
);
111 jarTag
.add(new ZipFileSet(relativePath
, "", true));
113 final Module module
= modules
[0];
117 final String pluginXmlPath
= moduleBuildProperties
.getPluginXmlPath();
118 final String relativePluginXMLPath
= GenerationUtils
.toRelativePath(pluginXmlPath
, moduleBaseDir
, module
, genOptions
);
119 jarTag
.add(new ZipFileSet(relativePluginXMLPath
, "META-INF/plugin.xml", false));
122 final Manifest manifestTag
= new Manifest();
123 jarTag
.add(manifestTag
);
124 final java
.util
.jar
.Manifest manifest
;
126 manifest
= PrepareToDeployAction
.createOrFindManifest(moduleBuildProperties
);
128 catch (IOException e
) {
131 manifestTag
.applyAttributes(manifest
);