Java 类org.robolectric.res.FsFile 实例源码

项目:MVP-Boilerplate    文件:PermissionsTest.java   
@Test
public void shouldMatchPermissions() {
    // Initialize: configure test for current app configuration
    FsFile mergedManifestFile;
    Object[] expectedPermissions;
    if (BuildConfig.DEBUG) {
        mergedManifestFile = Fs.fileFromPath(MERGED_DEBUG_MANIFEST_FILE);
        expectedPermissions = EXPECTED_DEBUG_PERMISSIONS;
    } else {
        mergedManifestFile = Fs.fileFromPath(MERGED_RELEASE_MANIFEST_FILE);
        expectedPermissions = EXPECTED_RELEASE_PERMISSIONS;
    }

    // Run: Creates a Robolectric configuration using specified manifest file
    AndroidManifest manifest = new AndroidManifest(mergedManifestFile, null, null);

    // Check: manifest file should contain only expected permissions
    assertThat(manifest.getUsedPermissions())
            .containsExactly(expectedPermissions);
}
项目:dora    文件:DoraTestRunner.java   
@Override
protected Properties getConfigProperties() {
    Properties configProperties = super.getConfigProperties();
    if (configProperties == null) {
        configProperties = new Properties();
    }
    String manifestPath = "src/test/AndroidManifest.xml";
    FsFile manifestFile = Fs.newFile(new File(manifestPath));
    if (manifestFile.exists()) {
        configProperties.put("manifest", manifestPath);
    } else {
        configProperties.put("manifest", "LikeOrmExample/" + manifestPath);
    }
    configProperties.put("emulateSdk", "16");
    return configProperties;
}
项目:stack-overflow-android    文件:MyRobolectricTestRunner.java   
@Override
protected AndroidManifest createAppManifest(FsFile manifestFile, FsFile resDir, FsFile assetsDir) {
    return new AndroidManifest(
            Fs.fileFromPath("src/main/AndroidManifest.xml"),
            Fs.fileFromPath("src/main/res"),
            Fs.fileFromPath("src/main/assets")) {

        @Override
        public int getTargetSdkVersion() {
            return 18;
        }

        @Override
        public String getThemeRef(Class<? extends Activity> activityClass) {
            return "@android:style/Theme.Holo.Light.NoActionBar";
        }
    };
}
项目:FullRobolectricTestSample    文件:ShadowAssetManager.java   
TypedResource getAndResolve(@NotNull ResName resName, String qualifiers, boolean resolveRefs) {
  TypedResource value = resourceLoader.getValue(resName, qualifiers);
  if (resolveRefs) {
    value = resolve(value, qualifiers, resName);
  }

  // todo: make the drawable loader put stuff into the normal spot...
  if (value == null && DrawableResourceLoader.isStillHandledHere(resName)) {
    DrawableNode drawableNode = resourceLoader.getDrawableNode(resName, qualifiers);
    return new TypedResource<FsFile>(drawableNode.getFsFile(), ResType.FILE);
  }

  // todo: gross. this is so resources.getString(R.layout.foo) works for ABS.
  if (value == null && "layout".equals(resName.type)) {
    throw new UnsupportedOperationException("ugh, this doesn't work still?");
  }

  return value;
}
项目:FullRobolectricTestSample    文件:TestRunnerSequenceTest.java   
@Test public void whenNoAppManifest_shouldRunThingsInTheRightOrder() throws Exception {
  StateHolder.transcript = new Transcript();
  assertNoFailures(run(new Runner(SimpleTest.class) {
    @Override protected AndroidManifest createAppManifest(FsFile manifestFile, FsFile resDir, FsFile assetsDir) {
      return null;
    }
  }));
  StateHolder.transcript.assertEventsSoFar(
      "configureShadows",
      "createApplication",
      "application.onCreate",
      "beforeTest",
      "application.beforeTest",
      "prepareTest",
      "application.prepareTest",
      "TEST!",
      "application.onTerminate",
      "afterTest",
      "application.afterTest"
  );
}
项目:open    文件:MapzenAndroidManifest.java   
protected List<FsFile> findLibraries() {
  FsFile baseDir = getBaseDir();
  List<FsFile> libraryBaseDirs = new ArrayList<FsFile>();

  Properties properties = getProperties(baseDir.join("project.properties"));
  // get the project.properties overrides and apply them (if any)
  Properties overrideProperties = getProperties(baseDir.join("test-project.properties"));
  if (overrideProperties!=null) properties.putAll(overrideProperties);
  if (properties != null) {
    int libRef = 1;
    String lib;
    while ((lib = properties.getProperty("android.library.reference." + libRef)) != null) {
      FsFile libraryBaseDir = baseDir.join(lib);
      if (libraryBaseDir.isDirectory()) {
        // Ignore directories without any files
        FsFile[] libraryBaseDirFiles = libraryBaseDir.listFiles();
        if (libraryBaseDirFiles != null && libraryBaseDirFiles.length > 0) {
          libraryBaseDirs.add(libraryBaseDir);
        }
      }

      libRef++;
    }
  }
  return libraryBaseDirs;
}
项目:materialandroid    文件:LibraryRobolectricTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
  AndroidManifest appManifest = super.getAppManifest(config);
  FsFile androidManifestFile = appManifest.getAndroidManifestFile();

  if (androidManifestFile.exists()) {
    return appManifest;
  } else {
    androidManifestFile = FileFsFile.from(appManifest.getAndroidManifestFile().getPath()
        .replace("manifests/full", "manifests/aapt"));
    return new AndroidManifest(androidManifestFile, appManifest.getResDirectory(), appManifest.getAssetsDirectory());
  }
}
项目:markdown-to-spanned    文件:ManifestedRobolectricGradeTestRunner.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();

    if (androidManifestFile.exists()) {
        return appManifest;
    } else {
        String moduleRoot = getModuleRootPath(config);
        androidManifestFile = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("bundles", "manifests/full"));
        FsFile resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath());
        FsFile assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath());
        return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);
    }
}
项目:foundry    文件:FoundryTestRunner.java   
@Override
protected AndroidManifest createAppManifest(final FsFile manifestFile, final FsFile resDir,
        final FsFile assetsDir) {
    FsFile moduleManifestFile = fixModuleDirectoryPathIfNeeded(manifestFile);
    FsFile moduleResDir = fixModuleDirectoryPathIfNeeded(resDir);
    FsFile moduleAssetsDir = fixModuleDirectoryPathIfNeeded(assetsDir);

    return super.createAppManifest(moduleManifestFile, moduleResDir, moduleAssetsDir);
}
项目:MVPAndroidBootstrap    文件:AppRobolectricRunner.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();

    if (androidManifestFile.exists()) {
        return appManifest;
    } else {
        String moduleRoot = getModuleRootPath(config);
        androidManifestFile = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("bundles", "manifests/full"));
        FsFile resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath());
        FsFile assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath());
        return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);
    }
}
项目:SnackbarBuilder    文件:LibraryRobolectricTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
  AndroidManifest appManifest = super.getAppManifest(config);
  FsFile androidManifestFile = appManifest.getAndroidManifestFile();

  if (androidManifestFile.exists()) {
    return appManifest;
  } else {
    androidManifestFile = FileFsFile.from(appManifest.getAndroidManifestFile().getPath()
        .replace("manifests/full", "manifests/aapt"));
    return new AndroidManifest(androidManifestFile, appManifest.getResDirectory(), appManifest.getAssetsDirectory());
  }
}
项目:lasso    文件:CustomRobolectricRunner.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();

    if (androidManifestFile.exists()) {
        return appManifest;
    } else {
        String moduleRoot = getModuleRootPath(config);
        androidManifestFile = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("bundles", "manifests/full"));
        FsFile resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath().replace("/res", "").replace("bundles", "res"));
        FsFile assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath().replace("/assets", "").replace("bundles", "assets"));
        return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);
    }
}
项目:okbuck    文件:BuckRobolectricTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    String buckManifest = System.getProperty(ROBOLECTRIC_MANIFEST);
    String buckResourcesProperty = System.getProperty(ROBOLECTRIC_RESOURCE_DIRECTORIES);

    if (buckManifest != null && buckResourcesProperty != null) {
        final List<String> buckResources = Arrays.asList(buckResourcesProperty.split(File.pathSeparator));

        final FsFile res = Fs.fileFromPath(buckResources.get(buckResources.size() - 1));
        final FsFile assets = Fs.fileFromPath(buckResources.get(buckResources.size() - 1));
        final FsFile manifest = Fs.fileFromPath(buckManifest);

        return new AndroidManifest(manifest, res, assets, config.packageName()) {

            @Override
            public List<ResourcePath> getIncludedResourcePaths() {
                Collection<ResourcePath> resourcePaths = new LinkedHashSet<>();
                resourcePaths.add(super.getResourcePath());

                ListIterator<String> it = buckResources.listIterator(buckResources.size());
                while (it.hasPrevious()) {
                    resourcePaths.add(new ResourcePath(
                            getRClass(),
                            getPackageName(),
                            Fs.fileFromPath(it.previous()),
                            getAssetsDirectory()));
                }
                return new ArrayList<>(resourcePaths);
            }
        };
    } else {
        return null;
    }
}
项目:FullRobolectricTestSample    文件:RobolectricTestRunner.java   
protected AndroidManifest createAppManifest(FsFile manifestFile, FsFile resDir, FsFile assetsDir) {
  if (!manifestFile.exists()) {
    System.out.print("WARNING: No manifest file found at " + manifestFile.getPath() + ".");
    System.out.println("Falling back to the Android OS resources only.");
    System.out.println("To remove this warning, annotate your test class with @Config(manifest=Config.NONE).");
    return null;
  }
  AndroidManifest manifest = new AndroidManifest(manifestFile, resDir, assetsDir);
  String packageName = System.getProperty("android.package");
  manifest.setPackageName(packageName);
  return manifest;
}
项目:FullRobolectricTestSample    文件:RobolectricTestRunner.java   
protected AndroidManifest getAppManifest(Config config) {
  if (config.manifest().equals(Config.NONE)) {
    return null;
  }

  String manifestProperty = System.getProperty("android.manifest");
  String resourcesProperty = System.getProperty("android.resources");
  String assetsProperty = System.getProperty("android.assets");

  FsFile fsFile = getBaseDir();
  FsFile manifestFile;
  FsFile resDir;
  FsFile assetsDir;

  boolean defaultManifest = config.manifest().equals(Config.DEFAULT);
  if (defaultManifest && manifestProperty != null) {
    manifestFile = Fs.fileFromPath(manifestProperty);
    resDir = Fs.fileFromPath(resourcesProperty);
    assetsDir = Fs.fileFromPath(assetsProperty);
  } else {
    manifestFile = fsFile.join(defaultManifest ? "AndroidManifest.xml" : config.manifest());
    resDir = manifestFile.getParent().join(config.resourceDir());
    assetsDir = manifestFile.getParent().join("assets");
  }

  synchronized (envHolder) {
    AndroidManifest appManifest;
    appManifest = envHolder.appManifestsByFile.get(manifestFile);
    if (appManifest == null) {
      long startTime = System.currentTimeMillis();
      appManifest = createAppManifest(manifestFile, resDir, assetsDir);
      if (DocumentLoader.DEBUG_PERF)
        System.out.println(String.format("%4dms spent in %s", System.currentTimeMillis() - startTime, manifestFile));

      envHolder.appManifestsByFile.put(manifestFile, appManifest);
    }
    return appManifest;
  }
}
项目:FullRobolectricTestSample    文件:ShadowAssetManager.java   
@Implementation
public final String[] list(String path) throws IOException {
  FsFile file = appManifest.getAssetsDirectory().join(path);
  if (file.isDirectory()) {
    return file.listFileNames();
  }
  return new String[0];
}
项目:FullRobolectricTestSample    文件:XmlFileBuilder.java   
public static XmlResourceParser getXmlResourceParser(String file, String packageName, ResourceIndex resourceIndex) {
  FsFile fsFile = Fs.fileFromPath(file);
  Document document = new XmlFileLoader(null, "xml").parse(fsFile);
  if (document == null) {
    throw new Resources.NotFoundException("couldn't find resource " + fsFile.getPath());
  }
  return new XmlFileBuilder().getXml(document, fsFile.getPath(), packageName, resourceIndex);
}
项目:tickmate    文件:TickmateTestRunner.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();

    if (androidManifestFile.exists()) {
        return appManifest;
    } else {
        androidManifestFile = FileFsFile.from(MODULE_ROOT, "src/main/AndroidManifest.xml");
        FsFile resDirectory = FileFsFile.from(MODULE_ROOT, "src/main/res");
        FsFile assetsDirectory = FileFsFile.from(MODULE_ROOT, "src/main/assets");

        return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);
    }
}
项目:crom    文件:CustomRobolectricRunner.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();

    if (androidManifestFile.exists()) {
        return appManifest;
    } else {
        String moduleRoot = getModuleRootPath(config);
        androidManifestFile = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath());
        FsFile resDirectory = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("AndroidManifest.xml", "res"));
        FsFile assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("AndroidManifest.xml", "assets"));
        return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);
    }
}
项目:open    文件:MapzenAndroidManifest.java   
/**
 * Creates a Robolectric configuration using specified locations.
 *
 * @param androidManifestFile location of the AndroidManifest.xml file
 * @param resDirectory        location of the res directory
 * @param assetsDirectory     location of the assets directory
 */
public MapzenAndroidManifest(FsFile androidManifestFile, FsFile resDirectory,
        FsFile assetsDirectory) {
  super(androidManifestFile, resDirectory, assetsDirectory);
  this.androidManifestFile = androidManifestFile;
  this.resDirectory = resDirectory;
  this.assetsDirectory = assetsDirectory;
}
项目:open    文件:MapzenAndroidManifest.java   
protected void createLibraryManifests() {
  libraryManifests = new ArrayList<AndroidManifest>();
  if (libraryDirectories == null) {
    libraryDirectories = findLibraries();
  }

  for (FsFile libraryBaseDir : libraryDirectories) {
    MapzenAndroidManifest libraryManifest = createLibraryAndroidManifest(libraryBaseDir);
    libraryManifest.createLibraryManifests();
    libraryManifests.add(libraryManifest);
  }
}
项目:open    文件:MapzenTestRunner.java   
/**
 * Uses custom manifest as workaround to maintain backward compatibility with library projects
 * that do not yet include the <code>&lt;application/&gt;</code> tag in AndroidManifest.xml.
 * <p />
 * See https://github.com/robolectric/robolectric/pull/1309 for more info.
 */
@Override
protected AndroidManifest createAppManifest(FsFile manifestFile,
        FsFile resDir, FsFile assetsDir) {
    AndroidManifest manifest = new MapzenAndroidManifest(manifestFile, resDir, assetsDir);
    String packageName = System.getProperty("android.package");
    manifest.setPackageName(packageName);
    return manifest;
}
项目:mobile-sdk-android    文件:RoboelectricTestRunnerWithResources.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();
    FsFile resDirectory;
    FsFile assetsDirectory;


    String moduleRoot = getModuleRootPath(config);
    androidManifestFile = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("bundles", "manifests/aapt"));

    if(appManifest.getResDirectory().getPath().contains("release")) {
        resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath().replace("release", "default"));
        assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath().replace("release", "default"));
    }else{
        resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath().replace("bundles/debug/res", "res/merged/debug"));
        assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath());
    }


    System.out.print(androidManifestFile.getPath() + '\n');
    System.out.print(resDirectory.getPath() + '\n');
    System.out.print(assetsDirectory.getPath() + '\n');


    return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);

}
项目:mobile-sdk-android    文件:RoboelectricTestRunnerWithResources.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();
    FsFile resDirectory;
    FsFile assetsDirectory;


        String moduleRoot = getModuleRootPath(config);
        androidManifestFile = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("bundles", "manifests/aapt"));

        if(appManifest.getResDirectory().getPath().contains("release")) {
            resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath().replace("release", "default"));
            assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath().replace("release", "default"));
        }else{
            resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath());
            assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath());
        }


        System.out.print(androidManifestFile.getPath() + '\n');
        System.out.print(resDirectory.getPath() + '\n');
        System.out.print(assetsDirectory.getPath() + '\n');


        return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);

}
项目:foundry    文件:FoundryTestRunner.java   
private FsFile fixModuleDirectoryPath(final FsFile fsFile) {
    return Fs.newFile(new File(fsFile.getPath().replace("./", "./" + MODULE_NAME + "/")));
}
项目:foundry    文件:FoundryTestRunner.java   
private FsFile fixModuleDirectoryPathIfNeeded(final FsFile fsFile) {
    if (!directoryPathsNeedFixing()) {
        return fsFile;
    }
    return fixModuleDirectoryPath(fsFile);
}
项目:FullRobolectricTestSample    文件:RobolectricTestRunner.java   
protected FsFile getBaseDir() {
  return Fs.currentDirectory();
}
项目:FullRobolectricTestSample    文件:Converter.java   
@Override public void fillTypedValue(FsFile data, TypedValue typedValue) {
  typedValue.type = TypedValue.TYPE_STRING;
  typedValue.data = 0;
  typedValue.string = data.getPath();
  typedValue.assetCookie = getNextStringCookie();
}
项目:FullRobolectricTestSample    文件:ShadowAssetManager.java   
public FsFile getAssetsDirectory() {
  return appManifest.getAssetsDirectory();
}
项目:FullRobolectricTestSample    文件:TestRunnerSequenceTest.java   
@Override
protected AndroidManifest createAppManifest(FsFile manifestFile, FsFile resDir, FsFile assetsDir) {
  return new AndroidManifest(resourceFile("TestAndroidManifest.xml"), resourceFile("res"), resourceFile("assets"));
}
项目:FullRobolectricTestSample    文件:TestRunners.java   
@Override
protected AndroidManifest createAppManifest(FsFile manifestFile, FsFile resDir, FsFile assetsDir) {
  return new AndroidManifest(resourceFile("TestAndroidManifest.xml"), resourceFile("res"), resourceFile("assets"));
}
项目:FullRobolectricTestSample    文件:TestRunners.java   
@Override protected AndroidManifest createAppManifest(FsFile manifestFile, FsFile resDir, FsFile assetsDir) {
  return null;
}
项目:FullRobolectricTestSample    文件:TestRunners.java   
@Override
protected AndroidManifest createAppManifest(FsFile manifestFile, FsFile resDir, FsFile assetsDir) {
  return new AndroidManifest(resourceFile("TestAndroidManifest.xml"), resourceFile("res"), resourceFile("assets"));
}
项目:FullRobolectricTestSample    文件:TestUtil.java   
public static FsFile resourcesBaseDir() {
  return Fs.newFile(resourcesBaseDirFile());
}
项目:FullRobolectricTestSample    文件:TestUtil.java   
public static FsFile resourceFile(String... pathParts) {
  return resourcesBaseDir().join(pathParts);
}
项目:Migratron    文件:MigratronTestRunner.java   
@Override protected AndroidManifest getAppManifest(Config config) {
    FsFile baseDir = Fs.newFile(new File(getClass().getResource("/").getPath()));
    return new AndroidManifest(baseDir.join("AndroidManifest.xml"), baseDir.join("/res"),baseDir.join("asserts"));
}
项目:open    文件:MapzenAndroidManifest.java   
public MapzenAndroidManifest(final FsFile androidManifestFile, final FsFile resDirectory) {
  this(androidManifestFile, resDirectory, resDirectory.getParent().join(DEFAULT_ASSETS_FOLDER));
}
项目:open    文件:MapzenAndroidManifest.java   
/**
 * @deprecated Use {@link #MapzenAndroidManifest(org.robolectric.res.FsFile, org.robolectric.res.FsFile, org.robolectric.res.FsFile)} instead.}
 */
public MapzenAndroidManifest(final FsFile baseDir) {
  this(baseDir.join(DEFAULT_MANIFEST_NAME), baseDir.join(DEFAULT_RES_FOLDER),
      baseDir.join(DEFAULT_ASSETS_FOLDER));
}
项目:open    文件:MapzenAndroidManifest.java   
public void setLibraryDirectories(List<FsFile> libraryDirectories) {
  this.libraryDirectories = libraryDirectories;
}
项目:open    文件:MapzenAndroidManifest.java   
protected FsFile getBaseDir() {
  return getResDirectory().getParent();
}