Search in sources :

Example 1 with VisibleForTesting

use of com.android.annotations.VisibleForTesting in project atlas by alibaba.

the class BasePlugin method createAndroidTasks.

@VisibleForTesting
final void createAndroidTasks(boolean force) {
    // Make sure unit tests set the required fields.
    checkState(extension.getBuildToolsRevision() != null, "buildToolsVersion is not specified.");
    checkState(extension.getCompileSdkVersion() != null, "compileSdkVersion is not specified.");
    ndkHandler.setCompileSdkVersion(extension.getCompileSdkVersion());
    // get current plugins and look for the default Java plugin.
    if (project.getPlugins().hasPlugin(JavaPlugin.class)) {
        throw new BadPluginException("The 'java' plugin has been applied, but it is not compatible with the Android plugins.");
    }
    ensureTargetSetup();
    // See AppPluginDslTest
    if (!force && (!project.getState().getExecuted() || project.getState().getFailure() != null) && SdkHandler.sTestSdkFolder == null) {
        return;
    }
    if (hasCreatedTasks) {
        return;
    }
    hasCreatedTasks = true;
    extension.disableWrite();
    ProcessRecorder.getProject(project.getPath()).setBuildToolsVersion(extension.getBuildToolsRevision().toString());
    // setup SDK repositories.
    sdkHandler.addLocalRepositories(project);
    taskManager.addDataBindingDependenciesIfNecessary(extension.getDataBinding());
    addDependencies(project);
    ThreadRecorder.get().record(ExecutionType.VARIANT_MANAGER_CREATE_ANDROID_TASKS, project.getPath(), null, new Recorder.Block<Void>() {

        @Override
        public Void call() throws Exception {
            variantManager.createAndroidTasks();
            ApiObjectFactory apiObjectFactory = new ApiObjectFactory(androidBuilder, extension, variantFactory, instantiator);
            for (BaseVariantData variantData : variantManager.getVariantDataList()) {
                apiObjectFactory.create(variantData);
            }
            return null;
        }
    });
    // Create and read external native build JSON files depending on what's happening right
    // now.
    //
    // CREATE PHASE:
    // Creates JSONs by shelling out to external build system when:
    //   - Any one of AndroidProject.PROPERTY_INVOKED_FROM_IDE,
    //      AndroidProject.PROPERTY_BUILD_MODEL_ONLY_ADVANCED,
    //      AndroidProject.PROPERTY_BUILD_MODEL_ONLY,
    //      AndroidProject.PROPERTY_REFRESH_EXTERNAL_NATIVE_MODEL are set.
    //   - *and* AndroidProject.PROPERTY_REFRESH_EXTERNAL_NATIVE_MODEL is set
    //      or JSON files don't exist or are out-of-date.
    // Create phase may cause ProcessException (from cmake.exe for example)
    //
    // READ PHASE:
    // Reads and deserializes JSONs when:
    //   - Any one of AndroidProject.PROPERTY_INVOKED_FROM_IDE,
    //      AndroidProject.PROPERTY_BUILD_MODEL_ONLY_ADVANCED,
    //      AndroidProject.PROPERTY_BUILD_MODEL_ONLY,
    //      AndroidProject.PROPERTY_REFRESH_EXTERNAL_NATIVE_MODEL are set.
    // Read phase may produce IOException if the file can't be read for standard IO reasons.
    // Read phase may produce JsonSyntaxException in the case that the content of the file is
    // corrupt.
    boolean forceRegeneration = AndroidGradleOptions.refreshExternalNativeModel(project);
    if (ExternalNativeBuildTaskUtils.shouldRegenerateOutOfDateJsons(project)) {
        ThreadRecorder.get().record(ExecutionType.VARIANT_MANAGER_EXTERNAL_NATIVE_CONFIG_VALUES, project.getPath(), null, new Recorder.Block<Void>() {

            @Override
            public Void call() throws Exception {
                for (BaseVariantData variantData : variantManager.getVariantDataList()) {
                    ExternalNativeJsonGenerator generator = variantData.getScope().getExternalNativeJsonGenerator();
                    if (generator != null) {
                        // This will generate any out-of-date or non-existent JSONs.
                        // When refreshExternalNativeModel() is true it will also
                        // force update all JSONs.
                        generator.build(forceRegeneration);
                        variantData.getScope().addExternalNativeBuildConfigValues(generator.readExistingNativeBuildConfigurations());
                    }
                }
                return null;
            }
        });
    }
}
Also used : BaseVariantData(com.android.build.gradle.internal.variant.BaseVariantData) BadPluginException(com.android.build.gradle.internal.BadPluginException) Recorder(com.android.builder.profile.Recorder) ThreadRecorder(com.android.builder.profile.ThreadRecorder) ProcessRecorder(com.android.builder.profile.ProcessRecorder) ExternalNativeJsonGenerator(com.android.build.gradle.tasks.ExternalNativeJsonGenerator) StopExecutionException(org.gradle.api.tasks.StopExecutionException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) UnsupportedVersionException(org.gradle.tooling.UnsupportedVersionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BadPluginException(com.android.build.gradle.internal.BadPluginException) GradleException(org.gradle.api.GradleException) ApiObjectFactory(com.android.build.gradle.internal.ApiObjectFactory) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 2 with VisibleForTesting

use of com.android.annotations.VisibleForTesting in project android by JetBrains.

the class IconPreviewFactory method load.

/**
   * Load preview images for each component into a file cache.
   * Each combination of theme, device density, and API level will have its own cache.
   *
   * @param configuration a hardware configuration to generate previews for
   * @param palette a palette with the components to generate previews of
   * @param reload if true replace the existing preview images
   * @param requestedIds for testing only: gather the IDs of the components whose previews were requested
   * @param generatedIds for testing only: gather the IDs of the components whose preview images where generated
   * @return true if the images were loaded, false if they already existed
   */
@VisibleForTesting
boolean load(@NotNull final Configuration configuration, @NotNull final Palette palette, boolean reload, @Nullable final List<String> requestedIds, @Nullable final List<String> generatedIds) {
    File cacheDir = getPreviewCacheDirForConfiguration(configuration);
    String[] files = cacheDir.list();
    if (files != null && files.length > 0) {
        // The previews have already been generated.
        if (!reload) {
            return false;
        }
        FileUtil.delete(cacheDir);
    }
    ApplicationManager.getApplication().runReadAction(new Computable<Void>() {

        @Override
        public Void compute() {
            List<StringBuilder> sources = Lists.newArrayList();
            loadSources(sources, requestedIds, palette.getItems());
            for (StringBuilder source : sources) {
                String preview = String.format(LINEAR_LAYOUT, CONTAINER_ID, source);
                addResultToCache(renderImage(myExecutorService, myRenderTimeoutSeconds, getRenderTask(configuration), preview), generatedIds, configuration);
            }
            return null;
        }
    });
    return true;
}
Also used : List(java.util.List) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 3 with VisibleForTesting

use of com.android.annotations.VisibleForTesting in project android by JetBrains.

the class ModuleResourceRepository method createForTest.

@NotNull
@VisibleForTesting
public static ModuleResourceRepository createForTest(@NotNull AndroidFacet facet, @NotNull Collection<VirtualFile> resourceDirectories, @NotNull Collection<LocalResourceRepository> otherDelegates) {
    assert ApplicationManager.getApplication().isUnitTestMode();
    List<LocalResourceRepository> delegates = new ArrayList<LocalResourceRepository>(resourceDirectories.size() + otherDelegates.size());
    for (VirtualFile resourceDirectory : resourceDirectories) {
        delegates.add(ResourceFolderRegistry.get(facet, resourceDirectory));
    }
    delegates.addAll(otherDelegates);
    return new ModuleResourceRepository(facet, delegates);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VisibleForTesting(com.android.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Example 4 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 5 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)

Aggregations

VisibleForTesting (com.android.annotations.VisibleForTesting)34 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 File (java.io.File)8 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