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

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

Issue 596303002: Revert of Revert of [Android] JUnit runner + gyp changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@deps-changes
Patch Set: Created 6 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
Index: testing/android/junit/java/src/org/chromium/testing/local/JunitTestArgParser.java
diff --git a/testing/android/junit/java/src/org/chromium/testing/local/JunitTestArgParser.java b/testing/android/junit/java/src/org/chromium/testing/local/JunitTestArgParser.java
new file mode 100644
index 0000000000000000000000000000000000000000..9de7874dc7db37ffd3d1babc321c8f7702e569fc
--- /dev/null
+++ b/testing/android/junit/java/src/org/chromium/testing/local/JunitTestArgParser.java
@@ -0,0 +1,90 @@
+// Copyright 2014 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 java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Parses command line arguments for JunitTestMain.
+ */
+public class JunitTestArgParser {
+
+ private final Set<String> mPackageFilters;
+ private final Set<Class<?>> mRunnerFilters;
+ private final Set<String> mGtestFilters;
+
+ public static JunitTestArgParser parse(String[] args) {
+
+ JunitTestArgParser parsed = new JunitTestArgParser();
+
+ 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 ("package-filter".equals(argName)) {
+ // Read the command line argument after the flag.
+ parsed.addPackageFilter(args[++i]);
+ } else if ("runner-filter".equals(argName)) {
+ // Read the command line argument after the flag.
+ parsed.addRunnerFilter(Class.forName(args[++i]));
+ } else if ("gtest-filter".equals(argName)) {
+ // Read the command line argument after the flag.
+ parsed.addGtestFilter(args[++i]);
+ } else {
+ System.out.println("Ignoring flag: \"" + argName + "\"");
+ }
+ } catch (ArrayIndexOutOfBoundsException e) {
+ System.err.println("No value specified for argument \"" + argName + "\"");
+ System.exit(1);
+ } catch (ClassNotFoundException e) {
+ System.err.println("Class not found. (" + e.toString() + ")");
+ System.exit(1);
+ }
+ } else {
+ System.out.println("Ignoring argument: \"" + args[i] + "\"");
+ }
+ }
+
+ return parsed;
+ }
+
+ private JunitTestArgParser() {
+ mPackageFilters = new HashSet<String>();
+ mRunnerFilters = new HashSet<Class<?>>();
+ mGtestFilters = new HashSet<String>();
+ }
+
+ public Set<String> getPackageFilters() {
+ return mPackageFilters;
+ }
+
+ public Set<Class<?>> getRunnerFilters() {
+ return mRunnerFilters;
+ }
+
+ public Set<String> getGtestFilters() {
+ return mGtestFilters;
+ }
+
+ private void addPackageFilter(String packageFilter) {
+ mPackageFilters.add(packageFilter);
+ }
+
+ private void addRunnerFilter(Class<?> runnerFilter) {
+ mRunnerFilters.add(runnerFilter);
+ }
+
+ private void addGtestFilter(String gtestFilter) {
+ mGtestFilters.add(gtestFilter);
+ }
+
+}
+

Powered by Google App Engine
This is Rietveld 408576698