forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Third Party] Add Robolectric 3.0 build files.
BUG=522043 Review-Url: https://codereview.chromium.org/2051913002 Cr-Commit-Position: refs/heads/master@{#407620}
- Loading branch information
Showing
14 changed files
with
825 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
1 change: 1 addition & 0 deletions
1
third_party/robolectric/lib/android-all-4.3_r2-robolectric-0.jar.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1231c61c42da2b1db9cbe13e449251f0db318e46 |
1 change: 1 addition & 0 deletions
1
third_party/robolectric/lib/android-all-5.0.0_r2-robolectric-1.jar.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7c63cd7aeb55d63e3e208b77882831c7ac588ed8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
d652f102185530c93b66158b1859f35d45687258 |
1 change: 1 addition & 0 deletions
1
third_party/robolectric/lib/robolectric-2.4-jar-with-dependencies.jar.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
53663a79a5a8adc2cbc4858f92a74286cd283976 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
639fd364750d7363c85797dc944b4a80f78fa684 |
88 changes: 88 additions & 0 deletions
88
...e_processor/src/org/chromium/testing/robolectric/template/ProcessRobolectricTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...ate_processor/src/org/chromium/testing/robolectric/template/ProcessTemplateArgParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |