<commit_before>package org.robolectric.res;

import android.R;
import org.robolectric.util.PropertiesHelper;

import java.io.*;
import java.util.Properties;

public class AndroidResourcePathFinder {
    private final int sdkVersion;
    private final ResourcePath resourcePath;

    public static ResourcePath getSystemResourcePath(int sdkVersion, ResourcePath resourcePath) {
        String pathToAndroidResources = new AndroidResourcePathFinder(sdkVersion, resourcePath).getPathToAndroidResources();
        return new ResourcePath(R.class, new File(pathToAndroidResources), null);
    }

    public AndroidResourcePathFinder(int sdkVersion, ResourcePath resourcePath) {
        this.resourcePath = resourcePath == null ? new ResourcePath(null, new File("."), null) : resourcePath;
        this.sdkVersion = sdkVersion;
    }

    String getPathToAndroidResources() {
        String resourcePath;
        if ((resourcePath = getAndroidResourcePathFromLocalProperties()) != null) {
            return resourcePath;
        } else if ((resourcePath = getAndroidResourcePathFromSystemEnvironment()) != null) {
            return resourcePath;
        } else if ((resourcePath = getAndroidResourcePathFromSystemProperty()) != null) {
            return resourcePath;
        } else if ((resourcePath = getAndroidResourcePathByExecingWhichAndroid()) != null) {
            return resourcePath;
        }

        throw new RuntimeException("Unable to find path to Android SDK, (you probably need a local.properties file, see: http://pivotal.github.com/robolectric/resources.html");
    }

    private String getAndroidResourcePathFromLocalProperties() {
        // Hand tested
        // This is the path most often taken by IntelliJ
        File rootDir = resourcePath.resourceBase.getParentFile();
        String localPropertiesFileName = "local.properties";
        File localPropertiesFile = new File(rootDir, localPropertiesFileName);
        if (!localPropertiesFile.exists()) {
            localPropertiesFile = new File(localPropertiesFileName);<commit_msg>Just look for the android resource path one time. We should be confident that it won't move between tests.<commit_after>package org.robolectric.res;

import android.R;
import org.robolectric.util.PropertiesHelper;

import java.io.*;
import java.util.Properties;

public class AndroidResourcePathFinder {
    private static String pathToAndroidResources = null;
    private final int sdkVersion;
    private final ResourcePath resourcePath;

    public static ResourcePath getSystemResourcePath(int sdkVersion, ResourcePath resourcePath) {
        String pathToAndroidResources = new AndroidResourcePathFinder(sdkVersion, resourcePath).getPathToAndroidResources();
        return new ResourcePath(R.class, new File(pathToAndroidResources), null);
    }

    public AndroidResourcePathFinder(int sdkVersion, ResourcePath resourcePath) {
        this.resourcePath = resourcePath == null ? new ResourcePath(null, new File("."), null) : resourcePath;
        this.sdkVersion = sdkVersion;
    }

    String getPathToAndroidResources() {
        if (pathToAndroidResources != null) {
            return pathToAndroidResources;
        }

        if ((pathToAndroidResources = getAndroidResourcePathFromLocalProperties()) != null) {
            return pathToAndroidResources;
        } else if ((pathToAndroidResources = getAndroidResourcePathFromSystemEnvironment()) != null) {
            return pathToAndroidResources;
        } else if ((pathToAndroidResources = getAndroidResourcePathFromSystemProperty()) != null) {
            return pathToAndroidResources;
        } else if ((pathToAndroidResources = getAndroidResourcePathByExecingWhichAndroid()) != null) {
            return pathToAndroidResources;
        }

        throw new RuntimeException("Unable to find path to Android SDK, (you probably need a local.properties file, see: http://pivotal.github.com/robolectric/resources.html");
    }

    private String getAndroidResourcePathFromLocalProperties() {
        // Hand tested
        // This is the path most often taken by IntelliJ
        File rootDir = resourcePath.resourceBase.getParentFile();
        String localPropertiesFileName = "local.properties";
        File localPropertiesFile = new File(rootDir, localPropertiesFileName);
        if (!localPropertiesFile.exists()) {
            localPropertiesFile = new File(localPropertiesFileName);
{'fraction_non_alphanumeric': 0.08022598870056497, 'fraction_numerical': 0.0, 'mean_word_length': 3.718550106609808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7589521', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1049, 'n_words': 291}