Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / build / android / ant / create-test-jar.js
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6  * Combines classes from javac.custom.classpath property and ${out.dir}/classes
7  * into a single jar file ${ant.project.name}.jar and places the file in
8  * ${lib.java.dir}.
9  */
10
11 importClass(java.io.File);
12 importClass(org.apache.tools.ant.types.Reference);
13 importClass(org.apache.tools.ant.types.FileSet);
14 importClass(org.apache.tools.ant.types.ZipFileSet);
15 importClass(org.apache.tools.ant.taskdefs.Zip);
16
17 var jarTask = project.createTask("jar");
18
19 // Do not allow duplicates in the jar, the default behavior of Jar task
20 // is "add" which means duplicates are allowed.
21 // This can cause a class file to be included multiple times, setting the
22 // duplicate to "preserve" ensures that only the first definition is included.
23
24 var duplicate = Zip.Duplicate();
25 duplicate.setValue("preserve");
26 jarTask.setDuplicate(duplicate);
27
28 var destPath = File(project.getProperty("TEST_JAR_PATH"));
29 jarTask.setDestFile(destPath);
30
31 // Include all the jars in the classpath.
32 var javacCustomClasspath =
33     project.getReference("javac.custom.classpath").list();
34
35 for (var i in javacCustomClasspath) {
36   var fileName = javacCustomClasspath[i]
37   var fileExtension = fileName.split("\\.").pop();
38   if(fileExtension == "jar")
39   {
40     var zipFileSet = ZipFileSet();
41     zipFileSet.setIncludes("**/*.class");
42     zipFileSet.setSrc(File(fileName));
43     jarTask.addFileset(zipFileSet);
44   }
45 }
46
47 // Add the compiled classes in ${out.dir}/classes.
48 var projectClasses = FileSet();
49 projectClasses.setIncludes("**/*.class");
50 projectClasses.setDir(File(project.getProperty("out.dir") + "/classes"));
51 jarTask.addFileset(projectClasses);
52
53 // Exclude manifest and resource classes.
54 var appPackagePath =
55     (project.getProperty("project.app.package")).replace('.','/');
56 var excludedClasses = ["R.class", "R$*.class", "Manifest.class",
57     "Manifest$*.class", "BuildConfig.class"]
58
59 var exclusionString = "";
60 for (var i in excludedClasses) {
61   exclusionString += appPackagePath+ "/" + excludedClasses[i] + " ";
62 }
63
64 jarTask.setExcludes(exclusionString);
65 jarTask.perform();