@Override public String toString() { return String.format("OptionalLibrary[name=\"%1$s\" description=\"%2$s\" jar=\"%3$s\"]", getName(), getDescription(), getLocalJarPath()); } }
@Override public int hashCode() { return Objects.hashCode(getLocalJarPath(), getName()); }
/** * Parses {@link IAndroidTarget.OptionalLibrary}s from the given json file. */ @VisibleForTesting @NonNull 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); // convert into the right format. 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) { // shouldn't happen since we've checked the file is here, but can happen in // some cases (too many files open). return Collections.emptyList(); } }
@Nullable @Override public String getLocalJarPath() { return getJar().getName(); }
public boolean equals(Object o) { if (!(o instanceof IAndroidTarget.OptionalLibrary)) { return false; } IAndroidTarget.OptionalLibrary lib = (IAndroidTarget.OptionalLibrary)o; return Objects.equal(lib.getLocalJarPath(), getLocalJarPath()) && lib.getName() .equals(getName()); }
@Override @NonNull public TypeDetails getTypeDetails() { if (mDetails == null) { int layoutlibApi = 0; if (mWrapped instanceof RemotePlatformPkgInfo) { LayoutlibVersion layoutlibVersion = ((RemotePlatformPkgInfo) mWrapped) .getLayoutLibVersion(); if (layoutlibVersion != null) { layoutlibApi = layoutlibVersion.getApi(); } } List<IAndroidTarget.OptionalLibrary> libs = Lists.newArrayList(); if (mWrapped instanceof RemoteAddonPkgInfo) { for (RemoteAddonPkgInfo.Lib wrappedLib : ((RemoteAddonPkgInfo) mWrapped) .getLibs()) { libs.add(new OptionalLibraryImpl(wrappedLib.getName(), new File(""), wrappedLib.getDescription(), false)); } } ProgressIndicator progress = new ConsoleProgressIndicator(); mDetails = LegacyRepoUtils .createTypeDetails(mWrapped.getPkgDesc(), layoutlibApi, libs, null, progress, FileOpUtils.create()); } return mDetails; }