Search in sources :

Example 11 with Variant

use of com.android.builder.model.Variant in project android by JetBrains.

the class AndroidGradleProjectResolver method populateModuleContentRoots.

@Override
public void populateModuleContentRoots(@NotNull IdeaModule gradleModule, @NotNull DataNode<ModuleData> ideModule) {
    ImportedModule importedModule = new ImportedModule(gradleModule);
    ideModule.createChild(IMPORTED_MODULE, importedModule);
    GradleProject gradleProject = gradleModule.getGradleProject();
    GradleScript buildScript = null;
    try {
        buildScript = gradleProject.getBuildScript();
    } catch (UnsupportedOperationException ignore) {
    }
    if (buildScript == null || !isAndroidGradleProject()) {
        nextResolver.populateModuleContentRoots(gradleModule, ideModule);
        return;
    }
    // do not derive module root dir based on *.iml file location
    File moduleRootDirPath = new File(toSystemDependentName(ideModule.getData().getLinkedExternalProjectPath()));
    AndroidProject androidProject = resolverCtx.getExtraProject(gradleModule, AndroidProject.class);
    boolean androidProjectWithoutVariants = false;
    String moduleName = gradleModule.getName();
    if (androidProject != null) {
        Variant selectedVariant = myVariantSelector.findVariantToSelect(androidProject);
        if (selectedVariant == null) {
            // If an Android project does not have variants, it would be impossible to build. This is a possible but invalid use case.
            // For now we are going to treat this case as a Java library module, because everywhere in the IDE (e.g. run configurations,
            // editors, test support, variants tool window, project building, etc.) we have the assumption that there is at least one variant
            // per Android project, and changing that in the code base is too risky, for very little benefit.
            // See https://code.google.com/p/android/issues/detail?id=170722
            androidProjectWithoutVariants = true;
        } else {
            String variantName = selectedVariant.getName();
            AndroidModuleModel model = new AndroidModuleModel(moduleName, moduleRootDirPath, androidProject, variantName);
            ideModule.createChild(ANDROID_MODEL, model);
        }
    }
    NativeAndroidProject nativeAndroidProject = resolverCtx.getExtraProject(gradleModule, NativeAndroidProject.class);
    if (nativeAndroidProject != null) {
        NdkModuleModel ndkModuleModel = new NdkModuleModel(moduleName, moduleRootDirPath, nativeAndroidProject);
        ideModule.createChild(NDK_MODEL, ndkModuleModel);
    }
    File gradleSettingsFile = new File(moduleRootDirPath, FN_SETTINGS_GRADLE);
    if (gradleSettingsFile.isFile() && androidProject == null && nativeAndroidProject == null) {
        // This is just a root folder for a group of Gradle projects. We don't set an IdeaGradleProject so the JPS builder won't try to
        // compile it using Gradle. We still need to create the module to display files inside it.
        createJavaProject(gradleModule, ideModule, false);
        return;
    }
    BuildScriptClasspathModel buildScriptModel = resolverCtx.getExtraProject(BuildScriptClasspathModel.class);
    String gradleVersion = buildScriptModel != null ? buildScriptModel.getGradleVersion() : null;
    File buildFilePath = buildScript.getSourceFile();
    GradleModuleModel gradleModuleModel = new GradleModuleModel(moduleName, gradleProject, buildFilePath, gradleVersion);
    ideModule.createChild(GRADLE_MODULE_MODEL, gradleModuleModel);
    if (nativeAndroidProject == null && (androidProject == null || androidProjectWithoutVariants)) {
        // This is a Java lib module.
        createJavaProject(gradleModule, ideModule, androidProjectWithoutVariants);
    }
}
Also used : BuildScriptClasspathModel(org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel) ImportedModule(com.android.tools.idea.gradle.ImportedModule) AndroidProject(com.android.builder.model.AndroidProject) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) Variant(com.android.builder.model.Variant) GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) GradleScript(org.gradle.tooling.model.gradle.GradleScript) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) GradleProject(org.gradle.tooling.model.GradleProject) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) File(java.io.File)

Example 12 with Variant

use of com.android.builder.model.Variant in project android by JetBrains.

the class VariantSelectorTest method findVariantToSelectWithoutDebugVariant.

@Test
public void findVariantToSelectWithoutDebugVariant() {
    Variant aVariant = mock(Variant.class);
    Variant bVariant = mock(Variant.class);
    when(myAndroidProject.getVariants()).thenReturn(Lists.newArrayList(bVariant, aVariant));
    when(aVariant.getName()).thenReturn("a");
    when(bVariant.getName()).thenReturn("b");
    Variant variant = myVariantSelector.findVariantToSelect(myAndroidProject);
    assertSame(aVariant, variant);
}
Also used : Variant(com.android.builder.model.Variant) Test(org.junit.Test)

Example 13 with Variant

use of com.android.builder.model.Variant in project android by JetBrains.

the class AndroidGradleClassJarProvider method getCompilerOutputRoot.

@Nullable
private static VirtualFile getCompilerOutputRoot(@NotNull AndroidModuleModel model) {
    Variant variant = model.getSelectedVariant();
    String variantName = variant.getName();
    AndroidArtifact mainArtifactInfo = model.getMainArtifact();
    File classesFolder = mainArtifactInfo.getClassesFolder();
    //noinspection ConstantConditions
    if (classesFolder == null) {
        // For getOutput()
        @SuppressWarnings("deprecation") AndroidArtifactOutput output = GradleUtil.getOutput(mainArtifactInfo);
        File file = output.getMainOutputFile().getOutputFile();
        File buildFolder = file.getParentFile().getParentFile();
        // See AndroidContentRoot
        classesFolder = new File(buildFolder, "classes");
    }
    File outFolder = new File(classesFolder, // Change variant name variant-release into variant/release directories
    variantName.replace('-', File.separatorChar));
    if (outFolder.exists()) {
        return VfsUtil.findFileByIoFile(outFolder, true);
    }
    return null;
}
Also used : Variant(com.android.builder.model.Variant) AndroidArtifactOutput(com.android.builder.model.AndroidArtifactOutput) AndroidArtifact(com.android.builder.model.AndroidArtifact) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with Variant

use of com.android.builder.model.Variant in project android by JetBrains.

the class AppResourceRepository method getResourceVisibility.

@NotNull
public ResourceVisibilityLookup getResourceVisibility(@NotNull AndroidFacet facet) {
    // TODO: b/23032391
    AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
    if (androidModel != null) {
        ResourceVisibilityLookup.Provider provider = getResourceVisibilityProvider();
        if (provider != null) {
            AndroidProject androidProject = androidModel.getAndroidProject();
            Variant variant = androidModel.getSelectedVariant();
            return provider.get(androidProject, variant);
        }
    }
    return ResourceVisibilityLookup.NONE;
}
Also used : Variant(com.android.builder.model.Variant) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ResourceVisibilityLookup(com.android.ide.common.repository.ResourceVisibilityLookup) AndroidProject(com.android.builder.model.AndroidProject) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with Variant

use of com.android.builder.model.Variant in project android by JetBrains.

the class CompilerOutputModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull AndroidModuleModel androidModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    GradleVersion modelVersion = androidModel.getModelVersion();
    if (modelVersion == null) {
        // We are dealing with old model that does not have the 'class' folder.
        return;
    }
    Variant selectedVariant = androidModel.getSelectedVariant();
    File mainClassesFolder = selectedVariant.getMainArtifact().getClassesFolder();
    JavaArtifact testArtifact = androidModel.getUnitTestArtifactInSelectedVariant();
    File testClassesFolder = testArtifact == null ? null : testArtifact.getClassesFolder();
    ModifiableRootModel rootModel = ideModelsProvider.getModifiableRootModel(module);
    myCompilerSettingsSetup.setOutputPaths(rootModel, mainClassesFolder, testClassesFolder);
}
Also used : Variant(com.android.builder.model.Variant) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) JavaArtifact(com.android.builder.model.JavaArtifact) GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File)

Aggregations

Variant (com.android.builder.model.Variant)23 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)8 AndroidProject (com.android.builder.model.AndroidProject)6 File (java.io.File)6 Module (com.intellij.openapi.module.Module)5 NotNull (org.jetbrains.annotations.NotNull)5 AndroidLibrary (com.android.builder.model.AndroidLibrary)4 OutputFile (com.android.build.OutputFile)3 AndroidArtifact (com.android.builder.model.AndroidArtifact)3 AndroidArtifactOutput (com.android.builder.model.AndroidArtifactOutput)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 Nullable (org.jetbrains.annotations.Nullable)3 NonNull (com.android.annotations.NonNull)2 TestedTargetVariant (com.android.builder.model.TestedTargetVariant)2 GradleVersion (com.android.ide.common.repository.GradleVersion)2 VariantCheckboxTreeCellRenderer (com.android.tools.idea.gradle.variant.ui.VariantCheckboxTreeCellRenderer)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 CheckboxTree (com.intellij.ui.CheckboxTree)2 CheckedTreeNode (com.intellij.ui.CheckedTreeNode)2 IOException (java.io.IOException)2