Search in sources :

Example 6 with VisibleForTesting

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)));
    }
}
Also used : TObjectIntHashMap(gnu.trove.TObjectIntHashMap) HashMap(java.util.HashMap) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) ResourceType(com.android.resources.ResourceType) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) IntArrayWrapper(com.android.ide.common.resources.IntArrayWrapper) EnumMap(java.util.EnumMap) Pair(com.android.util.Pair) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 7 with VisibleForTesting

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());
}
Also used : Device(com.android.sdklib.devices.Device) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 8 with VisibleForTesting

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;
}
Also used : GpuMode(com.android.sdklib.internal.avd.GpuMode) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 9 with VisibleForTesting

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;
}
Also used : Variant(com.android.builder.model.Variant) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 10 with VisibleForTesting

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;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) Revision(com.android.repository.Revision) LintClient(com.android.tools.lint.client.api.LintClient) LintIdeClient(com.android.tools.idea.lint.LintIdeClient) GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File) RemotePackage(com.android.repository.api.RemotePackage) VisibleForTesting(com.android.annotations.VisibleForTesting) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

VisibleForTesting (com.android.annotations.VisibleForTesting)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 File (java.io.File)7 NotNull (org.jetbrains.annotations.NotNull)7 Module (com.intellij.openapi.module.Module)5 ResourceType (com.android.resources.ResourceType)3 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)3 Nullable (com.android.annotations.Nullable)2 GradleVersion (com.android.ide.common.repository.GradleVersion)2 Revision (com.android.repository.Revision)2 Device (com.android.sdklib.devices.Device)2 ModuleImporter (com.android.tools.idea.gradle.project.ModuleImporter)2 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)2 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)2 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)2 PsiFile (com.intellij.psi.PsiFile)2 BufferedImage (java.awt.image.BufferedImage)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 Nullable (org.jetbrains.annotations.Nullable)2 ApiObjectFactory (com.android.build.gradle.internal.ApiObjectFactory)1