• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.robolectric.internal;
2 
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.List;
6 import javax.annotation.Nonnull;
7 import org.robolectric.annotation.Config;
8 import org.robolectric.res.FsFile;
9 
10 public 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   private final FsFile apkFile;
17 
ManifestIdentifier(String packageName, FsFile manifestFile, FsFile resDir, FsFile assetDir, List<ManifestIdentifier> libraries)18   public ManifestIdentifier(String packageName,
19       FsFile manifestFile, FsFile resDir, FsFile assetDir,
20       List<ManifestIdentifier> libraries) {
21     this(packageName, manifestFile, resDir, assetDir, libraries, null);
22   }
23 
ManifestIdentifier(String packageName, FsFile manifestFile, FsFile resDir, FsFile assetDir, List<ManifestIdentifier> libraries, FsFile apkFile)24   public ManifestIdentifier(String packageName,
25       FsFile manifestFile, FsFile resDir, FsFile assetDir,
26       List<ManifestIdentifier> libraries, FsFile apkFile) {
27     this.manifestFile = manifestFile;
28     this.resDir = resDir;
29     this.assetDir = assetDir;
30     this.packageName = packageName;
31     this.libraries = libraries == null ? Collections.emptyList() : libraries;
32     this.apkFile = apkFile;
33   }
34 
35   /**
36    * @deprecated Use {@link #ManifestIdentifier(String, FsFile, FsFile, FsFile, List)} instead.
37    */
38   @Deprecated
ManifestIdentifier(FsFile manifestFile, FsFile resDir, FsFile assetDir, String packageName, List<FsFile> libraryDirs)39   public ManifestIdentifier(FsFile manifestFile, FsFile resDir, FsFile assetDir, String packageName,
40       List<FsFile> libraryDirs) {
41     this.manifestFile = manifestFile;
42     this.resDir = resDir;
43     this.assetDir = assetDir;
44     this.packageName = packageName;
45 
46     List<ManifestIdentifier> libraries = new ArrayList<>();
47     if (libraryDirs != null) {
48       for (FsFile libraryDir : libraryDirs) {
49         libraries.add(new ManifestIdentifier(
50             null,
51             libraryDir.join(Config.DEFAULT_MANIFEST_NAME),
52             libraryDir.join(Config.DEFAULT_RES_FOLDER),
53             libraryDir.join(Config.DEFAULT_ASSET_FOLDER),
54             null));
55       }
56     }
57     this.libraries = Collections.unmodifiableList(libraries);
58     this.apkFile = null;
59   }
60 
getManifestFile()61   public FsFile getManifestFile() {
62     return manifestFile;
63   }
64 
getResDir()65   public FsFile getResDir() {
66     return resDir;
67   }
68 
getAssetDir()69   public FsFile getAssetDir() {
70     return assetDir;
71   }
72 
getPackageName()73   public String getPackageName() {
74     return packageName;
75   }
76 
77   @Nonnull
getLibraries()78   public List<ManifestIdentifier> getLibraries() {
79     return libraries;
80   }
81 
getApkFile()82   public FsFile getApkFile() {
83     return apkFile;
84   }
85 
86   @Override
equals(Object o)87   public boolean equals(Object o) {
88     if (this == o) {
89       return true;
90     }
91     if (o == null || getClass() != o.getClass()) {
92       return false;
93     }
94 
95     ManifestIdentifier that = (ManifestIdentifier) o;
96 
97     if (manifestFile != null ? !manifestFile.equals(that.manifestFile)
98         : that.manifestFile != null) {
99       return false;
100     }
101     if (resDir != null ? !resDir.equals(that.resDir) : that.resDir != null) {
102       return false;
103     }
104     if (assetDir != null ? !assetDir.equals(that.assetDir) : that.assetDir != null) {
105       return false;
106     }
107     if (packageName != null ? !packageName.equals(that.packageName) : that.packageName != null) {
108       return false;
109     }
110     if (libraries != null ? !libraries.equals(that.libraries) : that.libraries != null) {
111       return false;
112     }
113     return apkFile != null ? apkFile.equals(that.apkFile) : that.apkFile == null;
114   }
115 
116   @Override
hashCode()117   public int hashCode() {
118     int result = manifestFile != null ? manifestFile.hashCode() : 0;
119     result = 31 * result + (resDir != null ? resDir.hashCode() : 0);
120     result = 31 * result + (assetDir != null ? assetDir.hashCode() : 0);
121     result = 31 * result + (packageName != null ? packageName.hashCode() : 0);
122     result = 31 * result + (libraries != null ? libraries.hashCode() : 0);
123     result = 31 * result + (apkFile != null ? apkFile.hashCode() : 0);
124     return result;
125   }
126 
127   @Override
toString()128   public String toString() {
129     return "ManifestIdentifier{" +
130         "manifestFile=" + manifestFile +
131         ", resDir=" + resDir +
132         ", assetDir=" + assetDir +
133         ", packageName='" + packageName + '\'' +
134         ", libraries=" + libraries +
135         ", apkFile=" + apkFile +
136         '}';
137   }
138 }
139