LocalPlatformPkgInfo extends LocalPkgInfo { @VisibleForTesting static List<OptionalLibrary> getLibsFromJson(@NonNull File jsonFile) { Gson gson = new Gson(); try { Type collectionType = new TypeToken<Collection<Library>>() { }.getType(); Collection<Library> libs = gson .fromJson(Files.newReader(jsonFile, Charsets.UTF_8), collectionType); List<OptionalLibrary> optionalLibraries = Lists.newArrayListWithCapacity(libs.size()); File rootFolder = jsonFile.getParentFile(); for (Library lib : libs) { optionalLibraries.add(new OptionalLibraryImpl( lib.name, new File(rootFolder, lib.jar), lib.name, lib.manifest)); } return optionalLibraries; } catch (FileNotFoundException e) { return Collections.emptyList(); } } LocalPlatformPkgInfo(@NonNull LocalSdk localSdk,
                                @NonNull File localDir,
                                @NonNull Properties sourceProps,
                                @NonNull AndroidVersion version,
                                @NonNull MajorRevision revision,
                                @NonNull FullRevision minToolsRev); @NonNull @Override IPkgDesc getDesc(); @NonNull String getTargetHash(); @Nullable IAndroidTarget getAndroidTarget(); boolean isLoaded(); static final String PROP_VERSION_SDK; static final String PROP_VERSION_CODENAME; static final String PROP_VERSION_RELEASE; }
@Test public void testOptionalLibWith1() throws Exception { String content = "[\n" + " {\n" + " \"name\": \"org.apache.http.legacy\",\n" + " \"jar\": \"org.apache.http.legacy.jar\",\n" + " \"manifest\": false\n" + " }\n" + "]\n"; File json = getJsonFile(content); List<IAndroidTarget.OptionalLibrary> libs = LocalPlatformPkgInfo.getLibsFromJson(json); assertEquals(1, libs.size()); IAndroidTarget.OptionalLibrary lib = libs.get(0); assertEquals("org.apache.http.legacy", lib.getName()); assertEquals(new File(json.getParentFile(), "org.apache.http.legacy.jar"), lib.getJar()); assertEquals(false, lib.isManifestEntryRequired()); }