use of com.android.annotations.VisibleForTesting in project android by JetBrains.
the class ViewLoader method loadAndParseRClass.
@VisibleForTesting
void loadAndParseRClass(@NotNull String className) throws ClassNotFoundException, InconvertibleClassError {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("loadAndParseRClass(%s)", anonymizeClassName(className)));
}
Class<?> aClass = myLoadedClasses.get(className);
AppResourceRepository appResources = AppResourceRepository.getAppResources(myModule, true);
if (aClass == null) {
if (LOG.isDebugEnabled()) {
LOG.debug(" The R class is not loaded.");
}
final ModuleClassLoader moduleClassLoader = getModuleClassLoader();
final boolean isClassLoaded = moduleClassLoader.isClassLoaded(className);
aClass = moduleClassLoader.loadClass(className);
if (!isClassLoaded && aClass != null) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format(" Class found in module %s, first time load.", anonymize(myModule)));
}
// This is the first time we've found the resources. The dynamic R classes generated for aar libraries are now stale and must be
// regenerated. Clear the ModuleClassLoader and reload the R class.
myLoadedClasses.clear();
ModuleClassLoader.clearCache(myModule);
myModuleClassLoader = null;
aClass = getModuleClassLoader().loadClass(className);
if (appResources != null) {
appResources.resetDynamicIds(true);
}
} else {
if (LOG.isDebugEnabled()) {
if (isClassLoaded) {
LOG.debug(String.format(" Class already loaded in module %s.", anonymize(myModule)));
}
}
}
if (aClass != null) {
if (LOG.isDebugEnabled()) {
LOG.debug(" Class loaded");
}
assert myLogger != null;
myLoadedClasses.put(className, aClass);
myLogger.setHasLoadedClasses(true);
}
}
if (aClass != null) {
final Map<ResourceType, TObjectIntHashMap<String>> res2id = new EnumMap<>(ResourceType.class);
final TIntObjectHashMap<Pair<ResourceType, String>> id2res = new TIntObjectHashMap<>();
final Map<IntArrayWrapper, String> styleableId2res = new HashMap<>();
if (parseClass(aClass, id2res, styleableId2res, res2id)) {
if (appResources != null) {
appResources.setCompiledResources(id2res, styleableId2res, res2id);
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("END loadAndParseRClass(%s)", anonymizeClassName(className)));
}
}
use of com.android.annotations.VisibleForTesting in project android by JetBrains.
the class AvdDisplayList method getScreenSize.
/**
* @return the device screen size of this AVD
*/
@VisibleForTesting
static Dimension getScreenSize(@NotNull AvdInfo info) {
DeviceManagerConnection deviceManager = DeviceManagerConnection.getDefaultDeviceManagerConnection();
Device device = deviceManager.getDevice(info.getDeviceName(), info.getDeviceManufacturer());
if (device == null) {
return null;
}
return device.getScreenSize(device.getDefaultState().getOrientation());
}
use of com.android.annotations.VisibleForTesting in project android by JetBrains.
the class ConfigureAvdOptionsStep method gpuOtherMode.
@VisibleForTesting
static GpuMode gpuOtherMode(int apiLevel, boolean isIntel, boolean isGoogle, boolean isMac) {
boolean supportGuest = (apiLevel >= 23) && isIntel && isGoogle;
GpuMode otherMode = GpuMode.OFF;
if (supportGuest) {
otherMode = GpuMode.SWIFT;
} else if (!isMac) {
otherMode = GpuMode.MESA;
}
return otherMode;
}
use of com.android.annotations.VisibleForTesting in project android by JetBrains.
the class ExportSignedPackageWizard method getAssembleTasks.
@VisibleForTesting
public static List<String> getAssembleTasks(String gradleProjectPath, AndroidProject androidProject, String buildType, List<String> flavors) {
Map<String, Variant> variantsByFlavor = Maps.newHashMapWithExpectedSize(flavors.size());
for (Variant v : androidProject.getVariants()) {
if (!v.getBuildType().equals(buildType)) {
continue;
}
variantsByFlavor.put(getMergedFlavorName(v), v);
}
if (flavors.isEmpty()) {
// if there are no flavors defined, then the default merged flavor name is empty..
Variant v = variantsByFlavor.get("");
if (v != null) {
String taskName = v.getMainArtifact().getAssembleTaskName();
return Collections.singletonList(GradleBuildInvoker.createBuildTask(gradleProjectPath, taskName));
} else {
LOG.error("Unable to find default variant");
return Collections.emptyList();
}
}
List<String> assembleTasks = Lists.newArrayListWithExpectedSize(flavors.size());
for (String flavor : flavors) {
Variant v = variantsByFlavor.get(flavor);
if (v != null) {
String taskName = v.getMainArtifact().getAssembleTaskName();
assembleTasks.add(GradleBuildInvoker.createBuildTask(gradleProjectPath, taskName));
}
}
return assembleTasks;
}
use of com.android.annotations.VisibleForTesting in project android by JetBrains.
the class RepositoryUrlManager method resolveDynamicCoordinateVersion.
@Nullable
@VisibleForTesting
String resolveDynamicCoordinateVersion(@NotNull GradleCoordinate coordinate, @Nullable Project project, @NotNull AndroidSdkHandler sdkHandler) {
if (coordinate.getGroupId() == null || coordinate.getArtifactId() == null) {
return null;
}
String filter = coordinate.getRevision();
if (!filter.endsWith("+")) {
// Already resolved. That was easy.
return filter;
}
filter = filter.substring(0, filter.length() - 1);
File sdkLocation = sdkHandler.getLocation();
if (sdkLocation != null) {
// If this coordinate points to an artifact in one of our repositories, mark it will a comment if they don't
// have that repository available.
String libraryCoordinate = getLibraryRevision(coordinate.getGroupId(), coordinate.getArtifactId(), filter, false, sdkLocation, sdkHandler.getFileOp());
if (libraryCoordinate != null) {
return libraryCoordinate;
}
// If that didn't yield any matches, try again, this time allowing preview platforms.
// This is necessary if the artifact filter includes enough of a version where there are
// only preview matches.
libraryCoordinate = getLibraryRevision(coordinate.getGroupId(), coordinate.getArtifactId(), filter, true, sdkLocation, sdkHandler.getFileOp());
if (libraryCoordinate != null) {
return libraryCoordinate;
}
}
// Regular Gradle dependency? Look in Gradle cache
GradleVersion versionFound = GradleLocalCache.getInstance().findLatestArtifactVersion(coordinate, project, filter);
if (versionFound != null) {
return versionFound.toString();
}
// Maybe it's available for download as an SDK component
RemotePackage sdkPackage = SdkMavenRepository.findLatestRemoteVersion(coordinate, sdkHandler, new StudioLoggerProgressIndicator(getClass()));
if (sdkPackage != null) {
GradleCoordinate found = SdkMavenRepository.getCoordinateFromSdkPath(sdkPackage.getPath());
if (found != null) {
return found.getRevision();
}
}
// Perform network lookup to resolve current best version, if possible
if (project != null) {
LintClient client = new LintIdeClient(project);
Revision latest = GradleDetector.getLatestVersionFromRemoteRepo(client, coordinate, coordinate.isPreview());
if (latest != null) {
String version = latest.toShortString();
if (version.startsWith(filter)) {
return version;
}
}
}
return null;
}
Aggregations