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

Unified Diff: testing/android/junit/java/src/org/chromium/testing/local/RobolectricClasspathDependencyResolver.java

Issue 1057783002: Add new GN junit binary template and new GYP java binary template. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed cjhopman's feedback. Created 5 years, 8 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 | « testing/android/junit/java/src/org/chromium/testing/local/LocalRobolectricTestRunner.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/android/junit/java/src/org/chromium/testing/local/RobolectricClasspathDependencyResolver.java
diff --git a/testing/android/junit/java/src/org/chromium/testing/local/RobolectricClasspathDependencyResolver.java b/testing/android/junit/java/src/org/chromium/testing/local/RobolectricClasspathDependencyResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..47bc1ba0dd5e4045f0bafe7a5a35c410c099cd8d
--- /dev/null
+++ b/testing/android/junit/java/src/org/chromium/testing/local/RobolectricClasspathDependencyResolver.java
@@ -0,0 +1,72 @@
+// Copyright 2015 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.local;
+
+import org.robolectric.DependencyJar;
+import org.robolectric.DependencyResolver;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.regex.Pattern;
+
+/**
+ * A Robolectric dependency resolver that looks for the Robolectric dependencies
+ * in the Java classpath.
+ */
+public class RobolectricClasspathDependencyResolver implements DependencyResolver {
+ private static final Pattern COLON = Pattern.compile(":");
+ private final String[] mClassPathJars;
+
+ /**
+ * Creates a {@link ClasspathDependencyResolver}.
+ */
+ public RobolectricClasspathDependencyResolver() {
+ mClassPathJars = COLON.split(System.getProperty("java.class.path"));
+ }
+
+ /**
+ * Returns the {@link URL} for a Robolectric dependency. It looks through the jars
+ * in the classpath to find the dependency's filepath.
+ */
+ @Override
+ public URL getLocalArtifactUrl(DependencyJar dependency) {
+ // Jar filenames are constructed identically to how they are built in Robolectric's
+ // own LocalDependencyResolver.
+ String dependencyJar = dependency.getArtifactId() + "-" + dependency.getVersion() + "."
+ + dependency.getType();
+
+ for (String jarPath : mClassPathJars) {
+ if (jarPath.endsWith(dependencyJar)) {
+ return fileToUrl(new File(jarPath));
+ }
+ }
+ throw new IllegalStateException(
+ String.format("Robolectric jar %s was not found in classpath.", dependencyJar));
+ }
+
+ /**
+ * Returns the {@link URL} for a list of Robolectric dependencies.
+ */
+ @Override
+ public URL[] getLocalArtifactUrls(DependencyJar... dependencies) {
+ URL[] urls = new URL[dependencies.length];
+
+ for (int i = 0; i < dependencies.length; i++) {
+ urls[i] = getLocalArtifactUrl(dependencies[i]);
+ }
+
+ return urls;
+ }
+
+ private static URL fileToUrl(File file) {
+ try {
+ return file.toURI().toURL();
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException(
+ String.format("File \"%s\" cannot be represented as a URL: %s", file, e));
+ }
+ }
+}
« no previous file with comments | « testing/android/junit/java/src/org/chromium/testing/local/LocalRobolectricTestRunner.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698