org.robolectric.res.Fs.fileFromPath()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中org.robolectric.res.Fs.fileFromPath()方法的一些代码示例,展示了Fs.fileFromPath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Fs.fileFromPath()方法的具体详情如下:
包路径:org.robolectric.res.Fs
类名称:Fs
方法名:fileFromPath

Fs.fileFromPath介绍

暂无

代码示例

代码示例来源:origin: Karumi/Rosie

@Override
 protected AndroidManifest getAppManifest(Config config) {
  String manifestProperty = "../rosie/src/test/AndroidManifest.xml";
  String resProperty = "../rosie/src/main/res";
  return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty)) {
   @Override
   public int getTargetSdkVersion() {
    return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC;
   }

  };
 }
}

代码示例来源:origin: airbnb/epoxy

@Override
 protected AndroidManifest getAppManifest(Config config) {
  String res = String.format("../lib/build/intermediates/res/merged/%1$s/%2$s",
    BuildConfig.FLAVOR, BuildConfig.BUILD_TYPE);
  String asset = "src/main/assets";
  return new AndroidManifest(Fs.fileFromPath(MANIFEST_PATH), Fs.fileFromPath(res),
    Fs.fileFromPath(asset));
 }
}

代码示例来源:origin: org.robolectric/robolectric

private FsFile getFsFileFromProperty(String name) {
  String path = properties.getProperty(name);
  if (path == null || path.isEmpty()) {
   return null;
  }

  if (path.startsWith("jar")) {
   try {
    URL url = new URL(path);
    return Fs.fromURL(url);
   } catch (MalformedURLException e) {
    throw new RuntimeException(e);
   }
  } else {
   return Fs.fileFromPath(path);
  }
 }
}

代码示例来源:origin: org.robolectric/robolectric

@Nonnull
 private List<FsFile> getDirectoriesFromProperty(String property) {
  if (property == null) {
   return Collections.emptyList();
  }

  List<String> dirs;
  if (property.startsWith("@")) {
   String filename = property.substring(1);
   try {
    dirs = Arrays.asList(
      new String(Util.readBytes(new FileInputStream(filename)), UTF_8).split("\\n"));
   } catch (IOException e) {
    throw new RuntimeException("Cannot read file " + filename);
   }
  } else {
   dirs = Arrays.asList(property.split(File.pathSeparator));
  }

  List<FsFile> files = new ArrayList<>();
  for (String dir : dirs) {
   files.add(Fs.fileFromPath(dir));
  }
  return files;
 }
}

代码示例来源:origin: org.robolectric/robolectric

@Override
public ManifestIdentifier identify(Config config) {
 String buckManifest = System.getProperty(BUCK_ROBOLECTRIC_MANIFEST);
 FsFile manifestFile = Fs.fileFromPath(buckManifest);
 String buckResDirs = System.getProperty(BUCK_ROBOLECTRIC_RES_DIRECTORIES);
 String buckAssetsDirs = System.getProperty(BUCK_ROBOLECTRIC_ASSETS_DIRECTORIES);
 String packageName = config.packageName();
 final List<FsFile> buckResources = getDirectoriesFromProperty(buckResDirs);
 final List<FsFile> buckAssets = getDirectoriesFromProperty(buckAssetsDirs);
 final FsFile resDir = buckResources.size() == 0 ? null : buckResources.get(buckResources.size() - 1);
 final FsFile assetsDir = buckAssets.size() == 0 ? null : buckAssets.get(buckAssets.size() - 1);
 final List<ManifestIdentifier> libraries;
 if (resDir == null && assetsDir == null) {
  libraries = null;
 } else {
  libraries = new ArrayList<>();
  for (int i = 0; i < buckResources.size() - 1; i++) {
   libraries.add(new ManifestIdentifier((String) null, null, buckResources.get(i), null, null));
  }
  for (int i = 0; i < buckAssets.size() - 1; i++) {
   libraries.add(new ManifestIdentifier(null, null, null, buckAssets.get(i), null));
  }
 }
 return new ManifestIdentifier(packageName, manifestFile, resDir, assetsDir, libraries);
}

代码示例来源:origin: org.robolectric/robolectric

Logger.info("Using Robolectric classes from %s", buildPathPropertiesUrl.getPath());
FsFile propertiesFile = Fs.fileFromPath(buildPathPropertiesUrl.getFile());
try {
 dependencyResolver = new PropertiesDependencyResolver(propertiesFile, dependencyResolver);

代码示例来源:origin: org.robolectric/shadows-framework

private FsFile getFsFileFromPath(String property) {
 if (property.startsWith("jar")) {
  try {
   URL url = new URL(property);
   return Fs.fromURL(url);
  } catch (MalformedURLException e) {
   throw new RuntimeException(e);
  }
 } else {
  return Fs.fileFromPath(property);
 }
}

代码示例来源:origin: blundell/tests-app-robolectric-junit

@Override
  protected AndroidManifest getAppManifest(Config config) {
    String manifestProperty = "../app/src/main/AndroidManifest.xml";
    String resProperty = "../app/src/main/res";
    return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty)) {
      @Override
      public int getTargetSdkVersion() {
        return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC;
      }
    };
  }
}

代码示例来源:origin: org.robolectric/framework

public File getNativeLibraryPath() {
 String tempPath = System.getProperty("java.io.tmpdir");
 if (tempPath == null) {
  throw new IllegalStateException("Java temporary directory is not defined (java.io.tmpdir)");
 }
 return new File(Fs.fileFromPath(tempPath).join("robolectric-libs", getLibName()).getPath());
}

代码示例来源:origin: org.robolectric/shadows-core-v23

public File getNativeLibraryPath() {
 String tempPath = System.getProperty("java.io.tmpdir");
 if (tempPath == null) {
  throw new IllegalStateException("Java temporary directory is not defined (java.io.tmpdir)");
 }
 return new File(Fs.fileFromPath(tempPath).join("robolectric-libs", getLibName()).getPath());
}

代码示例来源:origin: org.robolectric/shadows-core

public File getNativeLibraryPath() {
 String tempPath = System.getProperty("java.io.tmpdir");
 if (tempPath == null) {
  throw new IllegalStateException("Java temporary directory is not defined (java.io.tmpdir)");
 }
 return new File(Fs.fileFromPath(tempPath).join("robolectric-libs", getLibName()).getPath());
}

代码示例来源:origin: org.robolectric/shadows-core

@Implementation
public final XmlResourceParser openXmlResourceParser(int cookie, String fileName) throws IOException {
 XmlBlock xmlBlock = XmlBlock.create(Fs.fileFromPath(fileName), "fixme");
 if (xmlBlock == null) {
  throw new Resources.NotFoundException(fileName);
 }
 return getXmlResourceParser(null, xmlBlock, "fixme");
}

代码示例来源:origin: org.robolectric/framework

@Implementation
public final XmlResourceParser openXmlResourceParser(int cookie, String fileName) throws IOException {
 XmlBlock xmlBlock = XmlBlock.create(Fs.fileFromPath(fileName), "fixme");
 if (xmlBlock == null) {
  throw new Resources.NotFoundException(fileName);
 }
 return getXmlResourceParser(null, xmlBlock, "fixme");
}

代码示例来源:origin: robospock/RoboSpock

manifestFile = Fs.fileFromPath(manifestProperty);
  baseDir = manifestFile.getParent();
} else {
  resDir = Fs.fileFromPath(resourcesProperty);
} else {
  resDir = baseDir.join(config.resourceDir());
  assetDir = Fs.fileFromPath(assetsProperty);
} else {
  assetDir = baseDir.join(config.assetDir());

代码示例来源:origin: org.robolectric/shadows-framework

@Implementation
protected final XmlResourceParser openXmlResourceParser(int cookie, String fileName)
  throws IOException {
 XmlBlock xmlBlock = XmlBlock.create(Fs.fileFromPath(fileName), resourceTable.getPackageName());
 if (xmlBlock == null) {
  throw new Resources.NotFoundException(fileName);
 }
 return getXmlResourceParser(resourceTable, xmlBlock, resourceTable.getPackageName());
}

代码示例来源:origin: amahi/android

@Test
public void permissionCheck() {
  AndroidManifest androidManifest = new AndroidManifest(Fs.fileFromPath("build/intermediates/manifests/full/debug/AndroidManifest.xml"), null, null);
  List<String> permissions = androidManifest.getUsedPermissions();
  //List of expected permissions to be present in AndroidManifest.xml
  String[] expectedPermissions = {
    "android.permission.ACCESS_NETWORK_STATE",
    "android.permission.DOWNLOAD_WITHOUT_NOTIFICATION",
    "android.permission.INTERNET",
    "android.permission.READ_EXTERNAL_STORAGE",
    "android.permission.WRITE_EXTERNAL_STORAGE",
    "android.permission.AUTHENTICATE_ACCOUNTS",
    "android.permission.GET_ACCOUNTS",
    "android.permission.MANAGE_ACCOUNTS",
    "android.permission.USE_CREDENTIALS",
    "android.permission.WAKE_LOCK"
  };
  //Checking expected permissions one by one
  for (String permission : expectedPermissions) {
    if (!permissions.contains(permission)) {
      showError(permission);
    }
  }
}

相关文章