Commit 11530874 authored by mikecase's avatar mikecase Committed by Commit bot

[Third Party] Add Robolectric 3.0 build files.

BUG=522043

Review-Url: https://codereview.chromium.org/2051913002
Cr-Commit-Position: refs/heads/master@{#407620}
parent c5b3973d
...@@ -420,7 +420,7 @@ vs-chromium-project.txt ...@@ -420,7 +420,7 @@ vs-chromium-project.txt
/third_party/pywebsocket/src /third_party/pywebsocket/src
/third_party/re2/src /third_party/re2/src
/third_party/requests/src /third_party/requests/src
/third_party/robolectric/lib /third_party/robolectric/lib/*.jar
/third_party/scons-2.0.1 /third_party/scons-2.0.1
/third_party/sfntly/src /third_party/sfntly/src
/third_party/shaderc/src /third_party/shaderc/src
......
...@@ -462,8 +462,8 @@ deps_os = { ...@@ -462,8 +462,8 @@ deps_os = {
'src/third_party/netty4/src': 'src/third_party/netty4/src':
Var('chromium_git') + '/external/netty4.git' + '@' + 'e0f26303b4ce635365be19414d0ac81f2ef6ba3c', Var('chromium_git') + '/external/netty4.git' + '@' + 'e0f26303b4ce635365be19414d0ac81f2ef6ba3c',
'src/third_party/robolectric/lib': 'src/third_party/robolectric/robolectric':
Var('chromium_git') + '/chromium/third_party/robolectric.git' + '@' + '6b63c99a8b6967acdb42cbed0adb067c80efc810', Var('chromium_git') + '/external/robolectric.git' + '@' + 'fdf24a09a4550b9fe47028fb1e24f9f119573bd7',
'src/third_party/ub-uiautomator/lib': 'src/third_party/ub-uiautomator/lib':
Var('chromium_git') + '/chromium/third_party/ub-uiautomator.git' + '@' + '00270549ce3161ae72ceb24712618ea28b4f9434', Var('chromium_git') + '/chromium/third_party/ub-uiautomator.git' + '@' + '00270549ce3161ae72ceb24712618ea28b4f9434',
...@@ -633,6 +633,16 @@ hooks = [ ...@@ -633,6 +633,16 @@ hooks = [
'-l', 'third_party/espresso' '-l', 'third_party/espresso'
], ],
}, },
{
'name': 'robolectric_libs',
'pattern': '.',
'action': ['python',
'src/build/android/update_deps/update_third_party_deps.py',
'download',
'-b', 'chromium-robolectric',
'-l', 'third_party/robolectric'
],
},
{ {
'name': 'apache_velocity', 'name': 'apache_velocity',
'pattern': '.', 'pattern': '.',
......
...@@ -48,8 +48,11 @@ _java_target_whitelist = [ ...@@ -48,8 +48,11 @@ _java_target_whitelist = [
"//third_party/netty4:netty_all", "//third_party/netty4:netty_all",
"//third_party/netty-tcnative:netty-tcnative", "//third_party/netty-tcnative:netty-tcnative",
"//third_party/robolectric:android-all-4.3_r2-robolectric-0", "//third_party/robolectric:android-all-4.3_r2-robolectric-0",
"//third_party/robolectric:android-all-5.0.0_r2-robolectric-1",
"//third_party/robolectric:json-20080701", "//third_party/robolectric:json-20080701",
"//third_party/robolectric:tagsoup-1.2", "//third_party/robolectric:tagsoup-1.2",
"//third_party/robolectric:shadows-core-3.0",
"//third_party/robolectric:shadows-multidex-3.0",
] ]
# Targets that match the whitelist but are not actually java targets. # Targets that match the whitelist but are not actually java targets.
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
android_java_prebuilt("guava_java") { java_prebuilt("guava_java") {
jar_path = "lib/guava-18.0.jar" jar_path = "lib/guava-18.0.jar"
} }
...@@ -12,14 +12,14 @@ group("hamcrest_java") { ...@@ -12,14 +12,14 @@ group("hamcrest_java") {
] ]
} }
android_java_prebuilt("hamcrest_core_java") { java_prebuilt("hamcrest_core_java") {
jar_path = "lib/hamcrest-core-1.3.jar" jar_path = "lib/hamcrest-core-1.3.jar"
} }
android_java_prebuilt("hamcrest_integration_java") { java_prebuilt("hamcrest_integration_java") {
jar_path = "lib/hamcrest-integration-1.3.jar" jar_path = "lib/hamcrest-integration-1.3.jar"
} }
android_java_prebuilt("hamcrest_library_java") { java_prebuilt("hamcrest_library_java") {
jar_path = "lib/hamcrest-library-1.3.jar" jar_path = "lib/hamcrest-library-1.3.jar"
} }
This diff is collapsed.
Name: Robolectric Name: Robolectric
URL: http://robolectric.org URL: http://robolectric.org
Version: 2.4 Version: 3.0
License: Apache 2.0 License: Apache 2.0
License File: NOT_SHIPPED License File: NOT_SHIPPED
Security Critical: no Security Critical: no
License Android Compatible: yes License Android Compatible: yes
Description: Robolectric is a unit test framework for Android. To update the Description: Robolectric is a unit test framework for Android.
robolectric jars, go to robolectric.org/download and follow link to Local Modifications:
robolectric-X.X.X-jar-with-dependencies.jar. - Removed Robolectric's dependence on Maven jars.
Local Modifications: None - Switched Robolectric's XML parsing logic from using the vtd-xml library to
using the org.w3c.dom package.
- Hardcoded version number in robolectric-version.properties.
- Hardcoded ShadowProvider service config file. This file is normally generated
at compile time but it is difficult to use the generated file with GN.
\ No newline at end of file
1231c61c42da2b1db9cbe13e449251f0db318e46
\ No newline at end of file
7c63cd7aeb55d63e3e208b77882831c7ac588ed8
\ No newline at end of file
d652f102185530c93b66158b1859f35d45687258
\ No newline at end of file
53663a79a5a8adc2cbc4858f92a74286cd283976
\ No newline at end of file
639fd364750d7363c85797dc944b4a80f78fa684
\ No newline at end of file
// Copyright 2016 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.
package org.chromium.testing.robolectric.template;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.RuntimeConstants;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.file.PathMatcher;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.FileSystems;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
/**
* Class to process Robolectric template (*.vm) files using Apache Velocity.
*/
public final class ProcessRobolectricTemplate {
private ProcessRobolectricTemplate() {
}
public static void main(String[] args) {
final ProcessTemplateArgParser parser = ProcessTemplateArgParser.parse(args);
Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,
parser.getBaseTemplateDir().toString());
Velocity.init();
final VelocityContext context = new VelocityContext();
int api = parser.getApiLevel();
context.put("api", api);
if (api >= 21) {
context.put("ptrClass", "long");
context.put("ptrClassBoxed", "Long");
} else {
context.put("ptrClass", "int");
context.put("ptrClassBoxed", "Integer");
}
try {
final PathMatcher templatePathMatcher =
FileSystems.getDefault().getPathMatcher("glob:" + "**/*.vm");
Files.walkFileTree(parser.getBaseTemplateDir(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(
Path path, BasicFileAttributes attrs) throws IOException {
if (templatePathMatcher.matches(path)) {
processTemplate(context, path, parser.getBaseTemplateDir(), parser.getOutputDir());
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
System.err.println("Error processing template files for Robolectric! " + e.toString());
}
}
private static void processTemplate(VelocityContext context, Path templateFile, Path baseTemplateDir, Path outputDir) throws IOException {
final StringWriter stringWriter = new StringWriter();
Template template = Velocity.getTemplate(baseTemplateDir.relativize(templateFile).toString(), "UTF-8");
template.merge(context, stringWriter);
String relativeOutputFile = templateFile.toString().replace(baseTemplateDir.toString(), "").replace(".vm", "");
if (relativeOutputFile.startsWith("/")) {
relativeOutputFile = relativeOutputFile.substring(1);
}
Path outputFile = outputDir.resolve(relativeOutputFile);
if (!Files.exists(outputFile.getParent())) {
Files.createDirectories(outputFile.getParent());
}
Files.write(outputFile, stringWriter.toString().getBytes("UTF-8"));
}
}
\ No newline at end of file
// Copyright 2016 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.
package org.chromium.testing.robolectric.template;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* Parses command line arguments for ProcessRobolectricTemplate.
*/
public class ProcessTemplateArgParser {
private Path mBaseTemplateDir;
private Path mOutputDir;
private Integer mApiLevel;
public static ProcessTemplateArgParser parse(String[] args) {
ProcessTemplateArgParser parsed = new ProcessTemplateArgParser();
for (int i = 0; i < args.length; ++i) {
if (args[i].startsWith("-")) {
String argName;
if (args[i].startsWith("-", 1)) {
argName = args[i].substring(2, args[i].length());
} else {
argName = args[i].substring(1, args[i].length());
}
try {
if ("output-dir".equals(argName)) {
// Read the command line argument after the flag.
parsed.setOutputDir(args[++i]);
} else if ("base-template-dir".equals(argName)) {
// Read the command line argument after the flag.
parsed.setBaseTemplateDir(args[++i]);
} else if ("api-level".equals(argName)) {
// Read the command line argument after the flag.
parsed.setApiLevel(args[++i]);
} else {
System.out.println("Ignoring flag: \"" + argName + "\"");
}
} catch (ArrayIndexOutOfBoundsException e) {
System.err.println("No value specified for argument \"" + argName + "\"");
System.exit(1);
}
} else {
System.out.println("Ignoring argument: \"" + args[i] + "\"");
}
}
if (parsed.getOutputDir() == null) {
System.err.println("--output-dir argument required.");
System.exit(1);
}
if (parsed.getBaseTemplateDir() == null) {
System.err.println("--base-template-dir argument required.");
System.exit(1);
}
if (parsed.getApiLevel() == null) {
System.err.println("--api-level argument required.");
System.exit(1);
}
return parsed;
}
private ProcessTemplateArgParser() {
mBaseTemplateDir = null;
mOutputDir = null;
mApiLevel = null;
}
public Path getBaseTemplateDir() {
return mBaseTemplateDir;
}
public Path getOutputDir() {
return mOutputDir;
}
public Integer getApiLevel() {
return mApiLevel;
}
private void setBaseTemplateDir(String path) {
mBaseTemplateDir = Paths.get(path);
}
private void setOutputDir(String path) {
mOutputDir = Paths.get(path);
}
private void setApiLevel(String integer) {
mApiLevel = Integer.parseInt(integer);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment