Changed the code to use forwarding service.
Change-Id: I2504ef01270f9c8e82acbe6a4069d2b4b77b35f2
This commit is contained in:
@@ -18,11 +18,18 @@ package com.android.dumprendertree2;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.dumprendertree2.forwarder.ForwarderManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -38,6 +45,9 @@ public class FileFilter {
|
||||
private static final String TEST_EXPECTATIONS_TXT_PATH =
|
||||
"platform/android/test_expectations.txt";
|
||||
|
||||
private static final String HTTP_TESTS_PATH = "http/tests/";
|
||||
private static final String SSL_PATH = "ssl/";
|
||||
|
||||
private static final String TOKEN_SKIP = "SKIP";
|
||||
private static final String TOKEN_IGNORE_RESULT = "IGNORE_RESULT";
|
||||
private static final String TOKEN_SLOW = "SLOW";
|
||||
@@ -52,7 +62,7 @@ public class FileFilter {
|
||||
/** It may or may not contain a trailing slash */
|
||||
this.mRootDirPath = rootDirPath;
|
||||
|
||||
reloadConfiguration();
|
||||
loadTestExpectations();
|
||||
}
|
||||
|
||||
private static final String trimTrailingSlashIfPresent(String path) {
|
||||
@@ -60,74 +70,89 @@ public class FileFilter {
|
||||
return file.getPath();
|
||||
}
|
||||
|
||||
public void reloadConfiguration() {
|
||||
File txt_exp = new File(mRootDirPath, TEST_EXPECTATIONS_TXT_PATH);
|
||||
|
||||
BufferedReader bufferedReader;
|
||||
public void loadTestExpectations() {
|
||||
URL url = null;
|
||||
try {
|
||||
bufferedReader =
|
||||
new BufferedReader(new FileReader(txt_exp));
|
||||
url = new URL(ForwarderManager.getHostSchemePort(false) + "LayoutTests/" +
|
||||
TEST_EXPECTATIONS_TXT_PATH);
|
||||
} catch (MalformedURLException e) {
|
||||
assert false;
|
||||
}
|
||||
|
||||
String line;
|
||||
String entry;
|
||||
String[] parts;
|
||||
String path;
|
||||
Set<String> tokens;
|
||||
Boolean skipped;
|
||||
while (true) {
|
||||
line = bufferedReader.readLine();
|
||||
if (line == null) {
|
||||
break;
|
||||
try {
|
||||
InputStream inputStream = null;
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
bufferedReader = new BufferedReader(new StringReader(new String(
|
||||
FsUtils.readDataFromUrl(url))));
|
||||
|
||||
String line;
|
||||
String entry;
|
||||
String[] parts;
|
||||
String path;
|
||||
Set<String> tokens;
|
||||
Boolean skipped;
|
||||
while (true) {
|
||||
line = bufferedReader.readLine();
|
||||
if (line == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
/** Remove the comment and trim */
|
||||
entry = line.split("//", 2)[0].trim();
|
||||
|
||||
/** Omit empty lines, advance to next line */
|
||||
if (entry.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/** Split on whitespace into path part and the rest */
|
||||
parts = entry.split("\\s", 2);
|
||||
|
||||
/** At this point parts.length >= 1 */
|
||||
if (parts.length == 1) {
|
||||
Log.w(LOG_TAG + "::reloadConfiguration",
|
||||
"There are no options specified for the test!");
|
||||
continue;
|
||||
}
|
||||
|
||||
path = trimTrailingSlashIfPresent(parts[0]);
|
||||
|
||||
/** Split on whitespace */
|
||||
tokens = new HashSet<String>(Arrays.asList(parts[1].split("\\s", 0)));
|
||||
|
||||
/** Chose the right collections to add to */
|
||||
skipped = false;
|
||||
if (tokens.contains(TOKEN_SKIP)) {
|
||||
mSkipList.add(path);
|
||||
skipped = true;
|
||||
}
|
||||
|
||||
/** If test is on skip list we ignore any further options */
|
||||
if (skipped) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tokens.contains(TOKEN_IGNORE_RESULT)) {
|
||||
mIgnoreResultList.add(path);
|
||||
}
|
||||
|
||||
if (tokens.contains(TOKEN_SLOW)) {
|
||||
mSlowList.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
/** Remove the comment and trim */
|
||||
entry = line.split("//", 2)[0].trim();
|
||||
|
||||
/** Omit empty lines, advance to next line */
|
||||
if (entry.isEmpty()) {
|
||||
continue;
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
|
||||
/** Split on whitespace into path part and the rest */
|
||||
parts = entry.split("\\s", 2);
|
||||
|
||||
/** At this point parts.length >= 1 */
|
||||
if (parts.length == 1) {
|
||||
Log.w(LOG_TAG + "::reloadConfiguration",
|
||||
"There are no options specified for the test!");
|
||||
continue;
|
||||
}
|
||||
|
||||
path = trimTrailingSlashIfPresent(parts[0]);
|
||||
|
||||
/** Split on whitespace */
|
||||
tokens = new HashSet<String>(Arrays.asList(parts[1].split("\\s", 0)));
|
||||
|
||||
/** Chose the right collections to add to */
|
||||
skipped = false;
|
||||
if (tokens.contains(TOKEN_SKIP)) {
|
||||
mSkipList.add(path);
|
||||
skipped = true;
|
||||
}
|
||||
|
||||
/** If test is on skip list we ignore any further options */
|
||||
if (skipped) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tokens.contains(TOKEN_IGNORE_RESULT)) {
|
||||
mIgnoreResultList.add(path);
|
||||
}
|
||||
|
||||
if (tokens.contains(TOKEN_SLOW)) {
|
||||
mSlowList.add(path);
|
||||
if (bufferedReader != null) {
|
||||
bufferedReader.close();
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.w(LOG_TAG, "mRootDirPath=" + mRootDirPath + ": File not found: " +
|
||||
txt_exp.getPath(), e);
|
||||
Log.w(LOG_TAG, "reloadConfiguration(): File not found: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
Log.e(LOG_TAG, "mRootDirPath=" + mRootDirPath, e);
|
||||
Log.e(LOG_TAG, "url=" + url, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,6 +261,37 @@ public class FileFilter {
|
||||
return testName.endsWith(".html") || testName.endsWith(".xhtml");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a URL of the test on the server.
|
||||
*
|
||||
* @param relativePath
|
||||
* @return a URL of the test on the server
|
||||
*/
|
||||
public static URL getUrl(String relativePath) {
|
||||
String urlBase = ForwarderManager.getHostSchemePort(false);
|
||||
|
||||
/**
|
||||
* URL is formed differently for HTTP vs non-HTTP tests, because HTTP tests
|
||||
* expect different document root. See run_apache2.py and .conf file for details
|
||||
*/
|
||||
if (relativePath.startsWith(HTTP_TESTS_PATH)) {
|
||||
relativePath = relativePath.substring(HTTP_TESTS_PATH.length());
|
||||
if (relativePath.startsWith(SSL_PATH)) {
|
||||
urlBase = ForwarderManager.getHostSchemePort(true);
|
||||
}
|
||||
} else {
|
||||
relativePath = "LayoutTests/" + relativePath;
|
||||
}
|
||||
|
||||
try {
|
||||
return new URL(urlBase + relativePath);
|
||||
} catch (MalformedURLException e) {
|
||||
Log.e(LOG_TAG, "Malformed URL!", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the path to the file relative to the tests root dir
|
||||
*
|
||||
|
||||
@@ -18,11 +18,23 @@ package com.android.dumprendertree2;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.dumprendertree2.forwarder.ForwarderManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -30,6 +42,9 @@ import java.io.OutputStream;
|
||||
public class FsUtils {
|
||||
public static final String LOG_TAG = "FsUtils";
|
||||
|
||||
private static final String SCRIPT_URL = ForwarderManager.getHostSchemePort(false) +
|
||||
"WebKitTools/DumpRenderTree/android/get_layout_tests_dir_contents.php";
|
||||
|
||||
public static void writeDataToStorage(File file, byte[] bytes, boolean append) {
|
||||
Log.d(LOG_TAG, "writeDataToStorage(): " + file.getAbsolutePath());
|
||||
try {
|
||||
@@ -37,7 +52,7 @@ public class FsUtils {
|
||||
try {
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
Log.d(LOG_TAG, "writeDataToStorage(): File created.");
|
||||
Log.d(LOG_TAG, "writeDataToStorage(): File created: " + file.getAbsolutePath());
|
||||
outputStream = new FileOutputStream(file, append);
|
||||
outputStream.write(bytes);
|
||||
} finally {
|
||||
@@ -46,7 +61,8 @@ public class FsUtils {
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(LOG_TAG, "file.getAbsolutePath=" + file.getAbsolutePath(), e);
|
||||
Log.e(LOG_TAG, "file.getAbsolutePath=" + file.getAbsolutePath() + " append=" + append,
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +78,7 @@ public class FsUtils {
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
bytes = new byte[(int) file.length()];
|
||||
bytes = new byte[(int)file.length()];
|
||||
fis.read(bytes);
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
@@ -75,4 +91,89 @@ public class FsUtils {
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] readDataFromUrl(URL url) {
|
||||
if (url == null) {
|
||||
Log.w(LOG_TAG, "readDataFromUrl(): url is null!");
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] bytes = null;
|
||||
try {
|
||||
InputStream inputStream = null;
|
||||
ByteArrayOutputStream outputStream = null;
|
||||
try {
|
||||
URLConnection urlConnection = url.openConnection();
|
||||
inputStream = urlConnection.getInputStream();
|
||||
outputStream = new ByteArrayOutputStream();
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int length;
|
||||
while ((length = inputStream.read(buffer)) > 0) {
|
||||
outputStream.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
bytes = outputStream.toByteArray();
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
if (outputStream != null) {
|
||||
outputStream.close();
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.w(LOG_TAG, "readDataFromUrl(): File not found: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
Log.e(LOG_TAG, "url=" + url, e);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static List<String> getLayoutTestsDirContents(String dirRelativePath, boolean recurse,
|
||||
boolean mode) {
|
||||
String modeString = (mode ? "folders" : "files");
|
||||
|
||||
List<String> results = new LinkedList<String>();
|
||||
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(SCRIPT_URL +
|
||||
"?path=" + dirRelativePath +
|
||||
"&recurse=" + recurse +
|
||||
"&mode=" + modeString);
|
||||
} catch (MalformedURLException e) {
|
||||
Log.e(LOG_TAG, "path=" + dirRelativePath + " recurse=" + recurse + " mode=" +
|
||||
modeString, e);
|
||||
return results;
|
||||
}
|
||||
|
||||
try {
|
||||
InputStream inputStream = null;
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
URLConnection urlConnection = url.openConnection();
|
||||
inputStream = urlConnection.getInputStream();
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
String relativePath;
|
||||
while ((relativePath = bufferedReader.readLine()) != null) {
|
||||
results.add(relativePath);
|
||||
}
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
if (bufferedReader != null) {
|
||||
bufferedReader.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(LOG_TAG, "path=" + dirRelativePath + " recurse=" + recurse + " mode=" +
|
||||
modeString, e);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,8 @@ import android.webkit.GeolocationPermissions;
|
||||
import android.webkit.WebStorage.QuotaUpdater;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -306,6 +308,8 @@ public class LayoutTestsExecutor extends Activity {
|
||||
*/
|
||||
webView.setTouchInterval(-1);
|
||||
|
||||
webView.clearCache(true);
|
||||
|
||||
WebSettings webViewSettings = webView.getSettings();
|
||||
webViewSettings.setAppCacheEnabled(true);
|
||||
webViewSettings.setAppCachePath(getApplicationContext().getCacheDir().getPath());
|
||||
@@ -353,10 +357,11 @@ public class LayoutTestsExecutor extends Activity {
|
||||
}
|
||||
|
||||
mCurrentTestRelativePath = mTestsList.remove(0);
|
||||
Log.d(LOG_TAG + "::runNextTest", "Start: " + mCurrentTestRelativePath +
|
||||
"(" + mCurrentTestIndex + ")");
|
||||
mCurrentTestUri =
|
||||
Uri.fromFile(new File(TESTS_ROOT_DIR_PATH, mCurrentTestRelativePath)).toString();
|
||||
|
||||
Log.i(LOG_TAG, "runNextTest(): Start: " + mCurrentTestRelativePath +
|
||||
" (" + mCurrentTestIndex + ")");
|
||||
|
||||
mCurrentTestUri = FileFilter.getUrl(mCurrentTestRelativePath).toString();
|
||||
|
||||
reset();
|
||||
|
||||
@@ -607,4 +612,4 @@ public class LayoutTestsExecutor extends Activity {
|
||||
mCurrentWebView.setMockDeviceOrientation(canProvideAlpha, alpha, canProvideBeta, beta,
|
||||
canProvideGamma, gamma);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ public class ManagerService extends Service {
|
||||
int size = EXPECTED_RESULT_LOCATION_RELATIVE_DIR_PREFIXES.size();
|
||||
for (int i = 0; bytes == null && i < size; i++) {
|
||||
relativePath = locations.get(i) + originalRelativePath;
|
||||
bytes = FsUtils.readDataFromStorage(new File(TESTS_ROOT_DIR_PATH, relativePath));
|
||||
bytes = FsUtils.readDataFromUrl(FileFilter.getUrl(relativePath));
|
||||
}
|
||||
|
||||
return bytes;
|
||||
|
||||
@@ -18,8 +18,6 @@ package com.android.dumprendertree2;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
@@ -64,17 +62,10 @@ public class TestsListPreloaderThread extends Thread {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
/** Check if the path is correct */
|
||||
File file = new File(TESTS_ROOT_DIR_PATH, mRelativePath);
|
||||
if (!file.exists()) {
|
||||
Log.e(LOG_TAG + "::run", "Path does not exist: " + mRelativePath);
|
||||
if (FileFilter.isTestFile(mRelativePath)) {
|
||||
mTestsList.add(mRelativePath);
|
||||
} else {
|
||||
/** Populate the tests' list accordingly */
|
||||
if (file.isDirectory()) {
|
||||
preloadTests(mRelativePath);
|
||||
} else {
|
||||
mTestsList.add(mRelativePath);
|
||||
}
|
||||
loadTestsFromUrl(mRelativePath);
|
||||
}
|
||||
|
||||
mDoneMsg.obj = mTestsList;
|
||||
@@ -87,29 +78,29 @@ public class TestsListPreloaderThread extends Thread {
|
||||
*
|
||||
* @param dirRelativePath
|
||||
*/
|
||||
private void preloadTests(String dirRelativePath) {
|
||||
private void loadTestsFromUrl(String dirRelativePath) {
|
||||
LinkedList<String> foldersList = new LinkedList<String>();
|
||||
foldersList.add(dirRelativePath);
|
||||
|
||||
String relativePath;
|
||||
String currentDirRelativePath;
|
||||
String itemName;
|
||||
File[] items;
|
||||
while (!foldersList.isEmpty()) {
|
||||
currentDirRelativePath = foldersList.removeFirst();
|
||||
items = new File(TESTS_ROOT_DIR_PATH, currentDirRelativePath).listFiles();
|
||||
for (File item : items) {
|
||||
itemName = item.getName();
|
||||
relativePath = currentDirRelativePath + File.separator + itemName;
|
||||
relativePath = foldersList.removeFirst();
|
||||
|
||||
if (item.isDirectory() && FileFilter.isTestDir(itemName)) {
|
||||
foldersList.add(relativePath);
|
||||
continue;
|
||||
for (String folderRelativePath : FsUtils.getLayoutTestsDirContents(relativePath,
|
||||
false, true)) {
|
||||
itemName = new File(folderRelativePath).getName();
|
||||
if (FileFilter.isTestDir(itemName)) {
|
||||
foldersList.add(folderRelativePath);
|
||||
}
|
||||
}
|
||||
|
||||
for (String testRelativePath : FsUtils.getLayoutTestsDirContents(relativePath,
|
||||
false, false)) {
|
||||
itemName = new File(testRelativePath).getName();
|
||||
if (FileFilter.isTestFile(itemName)) {
|
||||
if (!mFileFilter.isSkip(relativePath)) {
|
||||
mTestsList.add(relativePath);
|
||||
if (!mFileFilter.isSkip(testRelativePath)) {
|
||||
mTestsList.add(testRelativePath);
|
||||
} else {
|
||||
//mSummarizer.addSkippedTest(relativePath);
|
||||
/** TODO: Summarizer is now in service - figure out how to send the info */
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.dumprendertree2.forwarder;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -37,6 +39,8 @@ public class ForwarderManager {
|
||||
public static final int HTTP_PORT = 8080;
|
||||
public static final int HTTPS_PORT = 8443;
|
||||
|
||||
public static final String HOST = "localhost";
|
||||
|
||||
private static ForwarderManager forwarderManager;
|
||||
|
||||
private Set<Forwarder> mServers;
|
||||
@@ -47,6 +51,33 @@ public class ForwarderManager {
|
||||
mServers.add(new Forwarder(HTTPS_PORT, HOST_IP));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the main part of the URL with the trailing slash
|
||||
*
|
||||
* @param isHttps
|
||||
* @return
|
||||
*/
|
||||
public static final String getHostSchemePort(boolean isHttps) {
|
||||
int port;
|
||||
String protocol;
|
||||
if (isHttps) {
|
||||
protocol = "https";
|
||||
port = HTTPS_PORT;
|
||||
} else {
|
||||
protocol = "http";
|
||||
port = HTTP_PORT;
|
||||
}
|
||||
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(protocol, HOST, port, "/");
|
||||
} catch (MalformedURLException e) {
|
||||
assert false : "isHttps=" + isHttps;
|
||||
}
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
public static synchronized ForwarderManager getForwarderManager() {
|
||||
if (forwarderManager == null) {
|
||||
forwarderManager = new ForwarderManager();
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.dumprendertree2.TestsListActivity;
|
||||
import com.android.dumprendertree2.forwarder.ForwarderManager;
|
||||
|
||||
/**
|
||||
* A class which provides methods that can be invoked by a script running on the host machine to
|
||||
@@ -45,6 +46,8 @@ public class Starter extends ActivityInstrumentationTestCase2<TestsListActivity>
|
||||
ScriptTestRunner runner = (ScriptTestRunner)getInstrumentation();
|
||||
String relativePath = runner.getTestsRelativePath();
|
||||
|
||||
ForwarderManager.getForwarderManager().start();
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName("com.android.dumprendertree2", "TestsListActivity");
|
||||
intent.setAction(Intent.ACTION_RUN);
|
||||
@@ -70,5 +73,7 @@ public class Starter extends ActivityInstrumentationTestCase2<TestsListActivity>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ForwarderManager.getForwarderManager().stop();
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,10 @@
|
||||
package com.android.dumprendertree2.ui;
|
||||
|
||||
import com.android.dumprendertree2.FileFilter;
|
||||
import com.android.dumprendertree2.FsUtils;
|
||||
import com.android.dumprendertree2.TestsListActivity;
|
||||
import com.android.dumprendertree2.R;
|
||||
import com.android.dumprendertree2.forwarder.ForwarderManager;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
@@ -43,7 +45,6 @@ import android.widget.TextView;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -143,7 +144,7 @@ public class DirListActivity extends ListActivity {
|
||||
return false;
|
||||
}
|
||||
|
||||
return mRelativePath.equals(((ListItem) o).getRelativePath());
|
||||
return mRelativePath.equals(((ListItem)o).getRelativePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,10 +173,10 @@ public class DirListActivity extends ListActivity {
|
||||
LayoutInflater inflater = mContext.getLayoutInflater();
|
||||
View row = inflater.inflate(R.layout.dirlist_row, null);
|
||||
|
||||
TextView label = (TextView) row.findViewById(R.id.label);
|
||||
TextView label = (TextView)row.findViewById(R.id.label);
|
||||
label.setText(mItems[position].getName());
|
||||
|
||||
ImageView icon = (ImageView) row.findViewById(R.id.icon);
|
||||
ImageView icon = (ImageView)row.findViewById(R.id.icon);
|
||||
if (mItems[position].isDirectory()) {
|
||||
icon.setImageResource(R.drawable.folder);
|
||||
} else {
|
||||
@@ -190,13 +191,15 @@ public class DirListActivity extends ListActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
ForwarderManager.getForwarderManager().start();
|
||||
|
||||
mFileFilter = new FileFilter(ROOT_DIR_PATH);
|
||||
mListView = getListView();
|
||||
|
||||
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
ListItem item = (ListItem) parent.getItemAtPosition(position);
|
||||
ListItem item = (ListItem)parent.getItemAtPosition(position);
|
||||
|
||||
if (item.isDirectory()) {
|
||||
showDir(item.getRelativePath());
|
||||
@@ -214,7 +217,7 @@ public class DirListActivity extends ListActivity {
|
||||
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
ListItem item = (ListItem) parent.getItemAtPosition(position);
|
||||
ListItem item = (ListItem)parent.getItemAtPosition(position);
|
||||
|
||||
if (item.isDirectory()) {
|
||||
Bundle arguments = new Bundle(1);
|
||||
@@ -376,25 +379,22 @@ public class DirListActivity extends ListActivity {
|
||||
* The dirPath is relative.
|
||||
*/
|
||||
private ListItem[] getDirList(String dirPath) {
|
||||
File dir = new File(mRootDirPath, dirPath);
|
||||
|
||||
if (!dir.exists()) {
|
||||
return new ListItem[0];
|
||||
}
|
||||
|
||||
List<ListItem> subDirs = new ArrayList<ListItem>();
|
||||
List<ListItem> subFiles = new ArrayList<ListItem>();
|
||||
|
||||
for (File item : dir.listFiles()) {
|
||||
if (item.isDirectory() && FileFilter.isTestDir(item.getName())) {
|
||||
subDirs.add(new ListItem(mFileFilter.getRelativePath(item), true));
|
||||
} else if (FileFilter.isTestFile(item.getName())) {
|
||||
subFiles.add(new ListItem(mFileFilter.getRelativePath(item), false));
|
||||
for (String dirRelativePath : FsUtils.getLayoutTestsDirContents(dirPath, false,
|
||||
true)) {
|
||||
if (FileFilter.isTestDir(new File(dirRelativePath).getName())) {
|
||||
subDirs.add(new ListItem(dirRelativePath, true));
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(subDirs);
|
||||
Collections.sort(subFiles);
|
||||
for (String testRelativePath : FsUtils.getLayoutTestsDirContents(dirPath, false,
|
||||
false)) {
|
||||
if (FileFilter.isTestFile(new File(testRelativePath).getName())) {
|
||||
subFiles.add(new ListItem(testRelativePath, false));
|
||||
}
|
||||
}
|
||||
|
||||
/** Concatenate the two lists */
|
||||
subDirs.addAll(subFiles);
|
||||
|
||||
Reference in New Issue
Block a user