Search in sources :

Example 91 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class ProjectResourceCachedValueProvider method compute.

@Nullable
@Override
public final Result<T> compute() {
    AndroidFacet[] facets = myComponent.getDataBindingEnabledFacets();
    List<V> values = Lists.newArrayList();
    List<ModificationTracker> newDependencies = Lists.newArrayList();
    newDependencies.add(myComponent);
    Collections.addAll(newDependencies, myAdditionalTrackers);
    for (AndroidFacet facet : facets) {
        CachedValue<V> cachedValue = getCachedValue(facet);
        // we know this for sure since it is created from createCacheProvider
        if (cachedValue.getValueProvider() instanceof ModificationTracker) {
            newDependencies.add((ModificationTracker) cachedValue.getValueProvider());
        }
        V result = cachedValue.getValue();
        if (result != null) {
            values.add(result);
        }
    }
    myDependencies = Collections.unmodifiableList(newDependencies);
    myDependencyModificationCountOnCompute = calculateModificationCountFrom(myDependencies);
    return Result.create(merge(values), this);
}
Also used : ModificationTracker(com.intellij.openapi.util.ModificationTracker) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

Example 92 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class DependenciesModuleSetupStep method updateDependency.

private static void updateDependency(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull JavaModuleDependency dependency) {
    DependencySetupErrors setupErrors = DependencySetupErrors.getInstance(module.getProject());
    String moduleName = dependency.getModuleName();
    Module found = null;
    for (Module m : modelsProvider.getModules()) {
        if (moduleName.equals(m.getName())) {
            found = m;
        }
    }
    ModifiableRootModel moduleModel = modelsProvider.getModifiableRootModel(module);
    if (found != null) {
        AndroidFacet androidFacet = findFacet(found, modelsProvider, AndroidFacet.ID);
        if (androidFacet == null) {
            ModuleOrderEntry entry = moduleModel.addModuleOrderEntry(found);
            entry.setExported(true);
        } else {
            // If it depends on an android module, we should skip that.
            setupErrors.addInvalidModuleDependency(moduleModel.getModule(), found.getName(), "Java modules cannot depend on Android modules");
        }
        return;
    }
    setupErrors.addMissingModule(moduleName, module.getName(), null);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) DependencySetupErrors(com.android.tools.idea.gradle.project.sync.setup.module.common.DependencySetupErrors) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 93 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class AndroidLintConvertToWebpInspection method getQuickFixes.

@Override
@NotNull
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
    return new AndroidLintQuickFix[] { new DefaultLintQuickFix("Convert images to WebP...") {

        @Override
        public boolean isApplicable(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.ContextType contextType) {
            return AndroidFacet.getInstance(startElement) != null;
        }

        @Override
        public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
            AndroidFacet facet = AndroidFacet.getInstance(startElement);
            if (facet != null) {
                AndroidModuleInfo info = AndroidModuleInfo.get(facet);
                int minSdkVersion = info.getMinSdkVersion().getApiLevel();
                List<VirtualFile> folders = facet.getResourceFolderManager().getFolders();
                ConvertToWebpAction action = new ConvertToWebpAction();
                action.perform(startElement.getProject(), minSdkVersion, folders.toArray(VirtualFile.EMPTY_ARRAY));
            }
        }
    } };
}
Also used : AndroidModuleInfo(com.android.tools.idea.model.AndroidModuleInfo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ConvertToWebpAction(com.android.tools.idea.rendering.webp.ConvertToWebpAction) AndroidLintQuickFix(org.jetbrains.android.inspections.lint.AndroidLintQuickFix) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 94 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class BuildVariantUpdater method updateSelectedVariant.

/**
   * Updates a module's structure when the user selects a build variant from the tool window.
   *
   * @param project          the module's project.
   * @param moduleName       the module's name.
   * @param buildVariantName the name of the selected build variant.
   * @return {@code true} if the module update was successful, {@code false} otherwise.
   */
boolean updateSelectedVariant(@NotNull Project project, @NotNull String moduleName, @NotNull String buildVariantName) {
    List<AndroidFacet> affectedAndroidFacets = new ArrayList<>();
    List<NdkFacet> affectedNdkFacets = new ArrayList<>();
    executeProjectChanges(project, () -> {
        Module updatedModule = doUpdate(project, moduleName, buildVariantName, affectedAndroidFacets, affectedNdkFacets);
        if (updatedModule != null) {
            ConflictSet conflicts = findConflicts(project);
            conflicts.showSelectionConflicts();
        }
        PostSyncProjectSetup.Request setupRequest = new PostSyncProjectSetup.Request();
        setupRequest.setGenerateSourcesAfterSync(false).setCleanProjectAfterSync(false);
        PostSyncProjectSetup.getInstance(project).setUpProject(setupRequest, null);
        generateSourcesIfNeeded(affectedAndroidFacets);
    });
    return !affectedAndroidFacets.isEmpty() || !affectedNdkFacets.isEmpty();
}
Also used : PostSyncProjectSetup(com.android.tools.idea.gradle.project.sync.setup.post.PostSyncProjectSetup) ArrayList(java.util.ArrayList) ConflictSet(com.android.tools.idea.gradle.variant.conflict.ConflictSet) NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 95 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class BuildVariantView method updateContents.

public void updateContents() {
    GradleSyncState syncState = GradleSyncState.getInstance(myProject);
    if (syncState.isSyncInProgress() && !syncState.isSyncSkipped()) {
        projectImportStarted();
        return;
    }
    final List<Object[]> rows = Lists.newArrayList();
    final List<BuildVariantItem[]> variantNamesPerRow = Lists.newArrayList();
    for (Module module : getGradleModulesWithAndroidProjects()) {
        AndroidFacet androidFacet = AndroidFacet.getInstance(module);
        NdkFacet ndkFacet = NdkFacet.getInstance(module);
        // getGradleModules() returns only relevant modules.
        assert androidFacet != null || ndkFacet != null;
        String variantName = null;
        if (androidFacet != null) {
            JpsAndroidModuleProperties facetProperties = androidFacet.getProperties();
            variantName = facetProperties.SELECTED_BUILD_VARIANT;
        }
        BuildVariantItem[] variantNames = getVariantItems(module);
        if (variantNames != null) {
            if (androidFacet != null) {
                AndroidModuleModel androidModel = AndroidModuleModel.get(module);
                // AndroidModel may be null when applying a quick fix (e.g. "Fix Gradle version")
                if (androidModel != null) {
                    variantName = androidModel.getSelectedVariant().getName();
                }
            } else {
                // As only the modules backed by either AndroidGradleModel or NativeAndroidGradleModel are shown in the Build Variants View,
                // when a module is not backed by AndroidGradleModel, it surely contains a valid NativeAndroidGradleModel.
                NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
                if (ndkModuleModel != null) {
                    variantName = ndkModuleModel.getSelectedVariant().getName();
                }
            }
            variantNamesPerRow.add(variantNames);
        }
        if (variantName != null) {
            Object[] row = { module, variantName };
            rows.add(row);
        }
    }
    Runnable setModelTask = () -> getVariantsTable().setModel(rows, variantNamesPerRow);
    Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
        setModelTask.run();
    } else {
        application.invokeLater(setModelTask);
    }
}
Also used : NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) GradleSyncState(com.android.tools.idea.gradle.project.sync.GradleSyncState) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) Application(com.intellij.openapi.application.Application)

Aggregations

AndroidFacet (org.jetbrains.android.facet.AndroidFacet)299 Module (com.intellij.openapi.module.Module)122 VirtualFile (com.intellij.openapi.vfs.VirtualFile)73 NotNull (org.jetbrains.annotations.NotNull)61 Nullable (org.jetbrains.annotations.Nullable)51 Project (com.intellij.openapi.project.Project)39 File (java.io.File)29 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)28 PsiFile (com.intellij.psi.PsiFile)24 XmlFile (com.intellij.psi.xml.XmlFile)20 PsiElement (com.intellij.psi.PsiElement)17 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)16 XmlTag (com.intellij.psi.xml.XmlTag)16 ArrayList (java.util.ArrayList)16 Manifest (org.jetbrains.android.dom.manifest.Manifest)14 IAndroidTarget (com.android.sdklib.IAndroidTarget)13 ResourceFolderType (com.android.resources.ResourceFolderType)11 Configuration (com.android.tools.idea.configurations.Configuration)10 PsiClass (com.intellij.psi.PsiClass)10 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)10