Skip to content

Commit

Permalink
[Third Party] Add Robolectric 3.0 build files.
Browse files Browse the repository at this point in the history
BUG=522043

Review-Url: https://codereview.chromium.org/2051913002
Cr-Commit-Position: refs/heads/master@{#407620}
  • Loading branch information
case540 authored and Commit bot committed Jul 25, 2016
1 parent c5b3973 commit 1153087
Show file tree
Hide file tree
Showing 14 changed files with 825 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ vs-chromium-project.txt
/third_party/pywebsocket/src
/third_party/re2/src
/third_party/requests/src
/third_party/robolectric/lib
/third_party/robolectric/lib/*.jar
/third_party/scons-2.0.1
/third_party/sfntly/src
/third_party/shaderc/src
Expand Down
14 changes: 12 additions & 2 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ deps_os = {
'src/third_party/netty4/src':
Var('chromium_git') + '/external/netty4.git' + '@' + 'e0f26303b4ce635365be19414d0ac81f2ef6ba3c',

'src/third_party/robolectric/lib':
Var('chromium_git') + '/chromium/third_party/robolectric.git' + '@' + '6b63c99a8b6967acdb42cbed0adb067c80efc810',
'src/third_party/robolectric/robolectric':
Var('chromium_git') + '/external/robolectric.git' + '@' + 'fdf24a09a4550b9fe47028fb1e24f9f119573bd7',

'src/third_party/ub-uiautomator/lib':
Var('chromium_git') + '/chromium/third_party/ub-uiautomator.git' + '@' + '00270549ce3161ae72ceb24712618ea28b4f9434',
Expand Down Expand Up @@ -633,6 +633,16 @@ hooks = [
'-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',
'pattern': '.',
Expand Down
3 changes: 3 additions & 0 deletions build/config/android/internal_rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ _java_target_whitelist = [
"//third_party/netty4:netty_all",
"//third_party/netty-tcnative:netty-tcnative",
"//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: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.
Expand Down
2 changes: 1 addition & 1 deletion third_party/guava/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

import("//build/config/android/rules.gni")

android_java_prebuilt("guava_java") {
java_prebuilt("guava_java") {
jar_path = "lib/guava-18.0.jar"
}
6 changes: 3 additions & 3 deletions third_party/hamcrest/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

android_java_prebuilt("hamcrest_integration_java") {
java_prebuilt("hamcrest_integration_java") {
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"
}
604 changes: 604 additions & 0 deletions third_party/robolectric/BUILD.gn

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions third_party/robolectric/README.chromium
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
Name: Robolectric
URL: http://robolectric.org
Version: 2.4
Version: 3.0
License: Apache 2.0
License File: NOT_SHIPPED
Security Critical: no
License Android Compatible: yes
Description: Robolectric is a unit test framework for Android. To update the
robolectric jars, go to robolectric.org/download and follow link to
robolectric-X.X.X-jar-with-dependencies.jar.
Local Modifications: None
Description: Robolectric is a unit test framework for Android.
Local Modifications:
- Removed Robolectric's dependence on Maven jars.
- 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1231c61c42da2b1db9cbe13e449251f0db318e46
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7c63cd7aeb55d63e3e208b77882831c7ac588ed8
1 change: 1 addition & 0 deletions third_party/robolectric/lib/json-20080701.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d652f102185530c93b66158b1859f35d45687258
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
53663a79a5a8adc2cbc4858f92a74286cd283976
1 change: 1 addition & 0 deletions third_party/robolectric/lib/tagsoup-1.2.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
639fd364750d7363c85797dc944b4a80f78fa684
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// 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);
}
}

0 comments on commit 1153087

Please sign in to comment.