Android Open Source - CucumberAndroidGradle Android Resource Loader






From Project

Back to project page CucumberAndroidGradle.

License

The source code is released under:

Apache License

If you think the Android project CucumberAndroidGradle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package cucumber.runtime.android;
//w  w w .  j  a  va 2s .  c  o m
import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import cucumber.api.android.CucumberInstrumentation;
import cucumber.runtime.io.Resource;
import cucumber.runtime.io.ResourceLoader;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class AndroidResourceLoader implements ResourceLoader {
    private Context mContext;

    public AndroidResourceLoader(Context context) {
        mContext = context;
    }

    @Override
    public Iterable<Resource> resources(String path, String suffix) {
        List<Resource> resources = new ArrayList<Resource>();
        AssetManager assetManager = mContext.getAssets();
        try {
            addResourceRecursive(resources, assetManager, path, suffix);
        } catch (IOException e) {
            Log.e(CucumberInstrumentation.TAG, "Error loading resources.", e);
        }
        return resources;
    }

    private void addResourceRecursive(List<Resource> res, AssetManager am, String path, String suffix) throws IOException {
        if (path.endsWith(suffix)) {
            res.add(new AndroidResource(mContext, path));
        } else {
            for (String name : am.list(path)) {
                if (name.endsWith(suffix)) {
                    Resource as = new AndroidResource(mContext, String.format("%s/%s", path, name));
                    res.add(as);
                } else {
                    addResourceRecursive(res, am, String.format("%s/%s", path, name), suffix);
                }
            }
        }
    }
}




Java Source Code List

com.example.cucumberandroid.MainActivity.java
cucumber.api.android.CucumberInstrumentationTestRunner.java
cucumber.api.android.CucumberInstrumentation.java
cucumber.api.android.RunWithCucumber.java
cucumber.runtime.android.AndroidBackend.java
cucumber.runtime.android.AndroidClasspathMethodScanner.java
cucumber.runtime.android.AndroidFormatter.java
cucumber.runtime.android.AndroidJavaStepDefinition.java
cucumber.runtime.android.AndroidMethodFormat.java
cucumber.runtime.android.AndroidObjectFactory.java
cucumber.runtime.android.AndroidResourceLoader.java
cucumber.runtime.android.AndroidResource.java
cucumber.runtime.android.JavaHookDefinition.java
cucumber.runtime.android.JavaSnippet.java
ext.com.android.internal.os.LoggingPrintStream.java
ext.com.google.android.collect.Maps.java
ext.com.google.android.collect.Sets.java