• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
11importClass(java.io.File);
12importClass(org.apache.tools.ant.types.Reference);
13importClass(org.apache.tools.ant.types.FileSet);
14importClass(org.apache.tools.ant.types.ZipFileSet);
15importClass(org.apache.tools.ant.taskdefs.Zip);
16
17var 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
24var duplicate = Zip.Duplicate();
25duplicate.setValue("preserve");
26jarTask.setDuplicate(duplicate);
27
28var destPath = File(project.getProperty("TEST_JAR_PATH"));
29jarTask.setDestFile(destPath);
30
31// Include all the jars in the classpath.
32var javacCustomClasspath =
33    project.getReference("javac.custom.classpath").list();
34
35for (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.
48var projectClasses = FileSet();
49projectClasses.setIncludes("**/*.class");
50projectClasses.setDir(File(project.getProperty("out.dir") + "/classes"));
51jarTask.addFileset(projectClasses);
52
53// Exclude manifest and resource classes.
54var appPackagePath =
55    (project.getProperty("project.app.package")).replace('.','/');
56var excludedClasses = ["R.class", "R$*.class", "Manifest.class",
57    "Manifest$*.class", "BuildConfig.class"]
58
59var exclusionString = "";
60for (var i in excludedClasses) {
61  exclusionString += appPackagePath+ "/" + excludedClasses[i] + " ";
62}
63
64jarTask.setExcludes(exclusionString);
65jarTask.perform();
66