1package org.robolectric.internal; 2 3import java.util.ArrayList; 4import java.util.Collections; 5import java.util.List; 6import javax.annotation.Nonnull; 7import org.robolectric.annotation.Config; 8import org.robolectric.res.FsFile; 9 10public class ManifestIdentifier { 11 private final FsFile manifestFile; 12 private final FsFile resDir; 13 private final FsFile assetDir; 14 private final String packageName; 15 private final List<ManifestIdentifier> libraries; 16 17 public ManifestIdentifier(String packageName, 18 FsFile manifestFile, FsFile resDir, FsFile assetDir, 19 List<ManifestIdentifier> libraries) { 20 this.manifestFile = manifestFile; 21 this.resDir = resDir; 22 this.assetDir = assetDir; 23 this.packageName = packageName; 24 this.libraries = libraries == null ? Collections.emptyList() : libraries; 25 } 26 27 /** 28 * @deprecated Use {@link #ManifestIdentifier(String, FsFile, FsFile, FsFile, List)} instead. 29 */ 30 @Deprecated 31 public ManifestIdentifier(FsFile manifestFile, FsFile resDir, FsFile assetDir, String packageName, 32 List<FsFile> libraryDirs) { 33 this.manifestFile = manifestFile; 34 this.resDir = resDir; 35 this.assetDir = assetDir; 36 this.packageName = packageName; 37 38 List<ManifestIdentifier> libraries = new ArrayList<>(); 39 if (libraryDirs != null) { 40 for (FsFile libraryDir : libraryDirs) { 41 libraries.add(new ManifestIdentifier( 42 null, 43 libraryDir.join(Config.DEFAULT_MANIFEST_NAME), 44 libraryDir.join(Config.DEFAULT_RES_FOLDER), 45 libraryDir.join(Config.DEFAULT_ASSET_FOLDER), 46 null)); 47 } 48 } 49 this.libraries = Collections.unmodifiableList(libraries); 50 } 51 52 public FsFile getManifestFile() { 53 return manifestFile; 54 } 55 56 public FsFile getResDir() { 57 return resDir; 58 } 59 60 public FsFile getAssetDir() { 61 return assetDir; 62 } 63 64 public String getPackageName() { 65 return packageName; 66 } 67 68 @Nonnull 69 public List<ManifestIdentifier> getLibraries() { 70 return libraries; 71 } 72 73 @Override 74 public boolean equals(Object o) { 75 if (this == o) return true; 76 if (o == null || getClass() != o.getClass()) return false; 77 78 ManifestIdentifier that = (ManifestIdentifier) o; 79 80 if (manifestFile != null ? !manifestFile.equals(that.manifestFile) : that.manifestFile != null) return false; 81 if (resDir != null ? !resDir.equals(that.resDir) : that.resDir != null) return false; 82 if (assetDir != null ? !assetDir.equals(that.assetDir) : that.assetDir != null) return false; 83 if (packageName != null ? !packageName.equals(that.packageName) : that.packageName != null) return false; 84 return libraries != null ? libraries.equals(that.libraries) : that.libraries == null; 85 86 } 87 88 @Override 89 public int hashCode() { 90 int result = manifestFile != null ? manifestFile.hashCode() : 0; 91 result = 31 * result + (resDir != null ? resDir.hashCode() : 0); 92 result = 31 * result + (assetDir != null ? assetDir.hashCode() : 0); 93 result = 31 * result + (packageName != null ? packageName.hashCode() : 0); 94 result = 31 * result + (libraries != null ? libraries.hashCode() : 0); 95 return result; 96 } 97 98 @Override 99 public String toString() { 100 return "ManifestIdentifier{" + 101 "manifestFile=" + manifestFile + 102 ", resDir=" + resDir + 103 ", assetDir=" + assetDir + 104 ", packageName='" + packageName + '\'' + 105 ", libraries=" + libraries + 106 '}'; 107 } 108} 109