Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(562)

Unified Diff: build/android/ant/create-test-jar.js

Issue 10905138: Add test jar generation logic for ant builds. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/ant/common.xml ('k') | build/android/ant/sdk-targets.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/ant/create-test-jar.js
diff --git a/build/android/ant/create-test-jar.js b/build/android/ant/create-test-jar.js
new file mode 100644
index 0000000000000000000000000000000000000000..542a89e978feada38ddf99562bd856bc1ca0a623
--- /dev/null
+++ b/build/android/ant/create-test-jar.js
@@ -0,0 +1,70 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * Combines classes from javac.custom.classpath property and ${out.dir}/classes
+ * into a single jar file ${ant.project.name}-debug.jar and places the file in
+ * ${lib.java.dir}.
+ */
+
+importClass(java.io.File);
+importClass(org.apache.tools.ant.types.Reference);
+importClass(org.apache.tools.ant.types.FileSet);
+importClass(org.apache.tools.ant.types.ZipFileSet);
+importClass(org.apache.tools.ant.taskdefs.Zip);
+
+var echo = project.createTask("echo");
+var jarTask = project.createTask("jar");
+
+// Do not allow duplicates in the jar, the default behavior of Jar task
+// is "add" which means duplicates are allowed.
+// This can cause a class file to be included multiple times, setting the
+// duplicate to "preserve" ensures that only the first definition is included.
+
+var duplicate = Zip.Duplicate();
+duplicate.setValue("preserve");
+jarTask.setDuplicate(duplicate);
+
+var destFile = project.getProperty("ant.project.name") + "-debug.jar";
+var destPath = File(project.getProperty("test.lib.java.dir") + "/" + destFile);
+jarTask.setDestFile(destPath);
+
+// Include all the jars in the classpath.
+var javacCustomClasspath =
+ project.getReference("javac.custom.classpath").list();
+
+for (var i in javacCustomClasspath) {
+ var fileName = javacCustomClasspath[i]
+ var fileExtension = fileName.split("\\.").pop();
+ if(fileExtension == "jar")
+ {
+ var zipFileSet = ZipFileSet();
+ zipFileSet.setIncludes("**/*.class");
+ zipFileSet.setSrc(File(fileName));
+ jarTask.addFileset(zipFileSet);
+ }
+}
+
+// Add the compiled classes in ${out.dir}/classes.
+var projectClasses = FileSet();
+projectClasses.setIncludes("**/*.class");
+projectClasses.setDir(File(project.getProperty("out.dir") + "/classes"));
+jarTask.addFileset(projectClasses);
+
+// Exclude manifest and resource classes.
+var appPackagePath =
+ (project.getProperty("project.app.package")).replace('.','/');
+var excludedClasses = ["R.class", "R$*.class", "Manifest.class",
+ "Manifest$*.class", "BuildConfig.class"]
+
+var exclusionString = "";
+for (var i in excludedClasses) {
+ exclusionString += appPackagePath+ "/" + excludedClasses[i] + " ";
+}
+
+jarTask.setExcludes(exclusionString);
+echo.setMessage("Creating test jar: " +
+ jarTask.getDestFile().getAbsolutePath());
+echo.perform();
+jarTask.perform();
« no previous file with comments | « build/android/ant/common.xml ('k') | build/android/ant/sdk-targets.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698