Search in sources :

Example 11 with AndroidProject

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

the class LintIdeClient method getConfiguration.

@NonNull
@Override
public Configuration getConfiguration(@NonNull com.android.tools.lint.detector.api.Project project, @Nullable final LintDriver driver) {
    if (project.isGradleProject() && project.isAndroidProject() && !project.isLibrary()) {
        AndroidProject model = project.getGradleProjectModel();
        if (model != null) {
            try {
                LintOptions lintOptions = model.getLintOptions();
                final Map<String, Integer> overrides = lintOptions.getSeverityOverrides();
                if (overrides != null && !overrides.isEmpty()) {
                    return new DefaultConfiguration(this, project, null) {

                        @NonNull
                        @Override
                        public Severity getSeverity(@NonNull Issue issue) {
                            Integer severity = overrides.get(issue.getId());
                            if (severity != null) {
                                switch(severity.intValue()) {
                                    case LintOptions.SEVERITY_FATAL:
                                        return Severity.FATAL;
                                    case LintOptions.SEVERITY_ERROR:
                                        return Severity.ERROR;
                                    case LintOptions.SEVERITY_WARNING:
                                        return Severity.WARNING;
                                    case LintOptions.SEVERITY_INFORMATIONAL:
                                        return Severity.INFORMATIONAL;
                                    case LintOptions.SEVERITY_IGNORE:
                                    default:
                                        return Severity.IGNORE;
                                }
                            }
                            // This is a LIST lookup. I should make this faster!
                            if (!getIssues().contains(issue) && (driver == null || !driver.isCustomIssue(issue))) {
                                return Severity.IGNORE;
                            }
                            return super.getSeverity(issue);
                        }
                    };
                }
            } catch (Exception e) {
                LOG.error(e);
            }
        }
    }
    return new DefaultConfiguration(this, project, null) {

        @Override
        public boolean isEnabled(@NonNull Issue issue) {
            if (getIssues().contains(issue) && super.isEnabled(issue)) {
                return true;
            }
            return driver != null && driver.isCustomIssue(issue) || issue == IssueRegistry.BASELINE || issue == IssueRegistry.CANCELLED;
        }
    };
}
Also used : NonNull(com.android.annotations.NonNull) LintOptions(com.android.builder.model.LintOptions) AndroidProject(com.android.builder.model.AndroidProject) IOException(java.io.IOException) NonNull(com.android.annotations.NonNull)

Example 12 with AndroidProject

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

the class ProjectStructureCleanupStep method adjustInterModuleDependencies.

private void adjustInterModuleDependencies(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider) {
    // Verifies that inter-module dependencies between Android modules are correctly set. If module A depends on module B, and module B
    // does not contain sources but exposes an AAR as an artifact, the IDE should set the dependency in the 'exploded AAR' instead of trying
    // to find the library in module B. The 'exploded AAR' is in the 'build' folder of module A.
    // See: https://code.google.com/p/android/issues/detail?id=162634
    AndroidProject androidProject = getAndroidProject(module);
    if (androidProject == null) {
        return;
    }
    updateAarDependencies(module, modelsProvider, androidProject);
}
Also used : AndroidProject(com.android.builder.model.AndroidProject) GradleUtil.getNativeAndroidProject(com.android.tools.idea.gradle.util.GradleUtil.getNativeAndroidProject) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) GradleUtil.getAndroidProject(com.android.tools.idea.gradle.util.GradleUtil.getAndroidProject)

Example 13 with AndroidProject

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

the class ModuleVariantsInfoDialog method createDependenciesTree.

@NotNull
private static JTree createDependenciesTree(@NotNull Module module, @NotNull AndroidModuleModel androidModel) {
    VariantCheckboxTreeCellRenderer renderer = new VariantCheckboxTreeCellRenderer() {

        @Override
        public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (value instanceof DefaultMutableTreeNode) {
                Object data = ((DefaultMutableTreeNode) value).getUserObject();
                if (data instanceof String) {
                    appendVariant((String) data);
                } else if (data instanceof DependencyTreeElement) {
                    DependencyTreeElement dependency = (DependencyTreeElement) data;
                    appendModule(dependency.myModule, dependency.myVariant);
                }
            }
        }
    };
    //noinspection ConstantConditions
    CheckedTreeNode root = new CheckedTreeNode(null);
    AndroidProject androidProject = GradleUtil.getAndroidProject(module);
    assert androidProject != null;
    Multimap<String, DependencyTreeElement> dependenciesByVariant = HashMultimap.create();
    for (Variant variant : androidProject.getVariants()) {
        for (AndroidLibrary library : GradleUtil.getDirectLibraryDependencies(variant, androidModel)) {
            String gradlePath = library.getProject();
            if (gradlePath == null) {
                continue;
            }
            Module dependency = GradleUtil.findModuleByGradlePath(module.getProject(), gradlePath);
            if (dependency != null) {
                DependencyTreeElement element = new DependencyTreeElement(dependency, library.getProjectVariant());
                dependenciesByVariant.put(variant.getName(), element);
            }
        }
    }
    // Consolidate variants. This means if "debug" and "release" have the same dependencies, we show only one node as "debug, release".
    List<String> variantNames = Lists.newArrayList(dependenciesByVariant.keySet());
    Collections.sort(variantNames);
    List<String> consolidatedVariants = Lists.newArrayList();
    List<String> variantsToSkip = Lists.newArrayList();
    int variantCount = variantNames.size();
    for (int i = 0; i < variantCount; i++) {
        String variant1 = variantNames.get(i);
        if (variantsToSkip.contains(variant1)) {
            continue;
        }
        Collection<DependencyTreeElement> set1 = dependenciesByVariant.get(variant1);
        for (int j = i + 1; j < variantCount; j++) {
            String variant2 = variantNames.get(j);
            Collection<DependencyTreeElement> set2 = dependenciesByVariant.get(variant2);
            if (set1.equals(set2)) {
                variantsToSkip.add(variant2);
                if (!consolidatedVariants.contains(variant1)) {
                    consolidatedVariants.add(variant1);
                }
                consolidatedVariants.add(variant2);
            }
        }
        String variantName = variant1;
        if (!consolidatedVariants.isEmpty()) {
            variantName = Joiner.on(", ").join(consolidatedVariants);
        }
        DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(variantName);
        root.add(variantNode);
        List<DependencyTreeElement> dependencies = Lists.newArrayList(set1);
        Collections.sort(dependencies);
        for (DependencyTreeElement dependency : dependencies) {
            variantNode.add(new DefaultMutableTreeNode(dependency));
        }
        consolidatedVariants.clear();
    }
    CheckboxTree tree = new CheckboxTree(renderer, root);
    tree.setRootVisible(false);
    TreeUtil.expandAll(tree);
    return tree;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CheckboxTree(com.intellij.ui.CheckboxTree) CheckedTreeNode(com.intellij.ui.CheckedTreeNode) AndroidProject(com.android.builder.model.AndroidProject) Variant(com.android.builder.model.Variant) AndroidLibrary(com.android.builder.model.AndroidLibrary) Module(com.intellij.openapi.module.Module) VariantCheckboxTreeCellRenderer(com.android.tools.idea.gradle.variant.ui.VariantCheckboxTreeCellRenderer) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with AndroidProject

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

the class ExportSignedPackageTest method ignore_testFlavors.

// ignored: http://b.android.com/226579
public void ignore_testFlavors() {
    AndroidProject androidProject = getAndroidProject("multiflavor");
    assertNotNull(androidProject);
    // (free,pro) x (arm,x86) x (debug,release) = 8
    assertEquals(8, androidProject.getVariants().size());
    Set<String> assembleTasks = Sets.newHashSet(ExportSignedPackageWizard.getAssembleTasks("", androidProject, "release", Lists.newArrayList("pro-x86", "free-arm")));
    assertEquals(2, assembleTasks.size());
    assertTrue(assembleTasks.contains(":assembleProX86Release"));
    assertTrue(assembleTasks.contains(":assembleFreeArmRelease"));
}
Also used : AndroidProject(com.android.builder.model.AndroidProject)

Example 15 with AndroidProject

use of com.android.builder.model.AndroidProject 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)

Aggregations

AndroidProject (com.android.builder.model.AndroidProject)35 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)12 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)7 File (java.io.File)7 Variant (com.android.builder.model.Variant)6 Module (com.intellij.openapi.module.Module)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 NotNull (org.jetbrains.annotations.NotNull)6 ModuleNodeBuilder (com.android.tools.idea.gradle.AndroidModelView.ModuleNodeBuilder)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 NonNull (com.android.annotations.NonNull)3 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)3 Project (com.intellij.openapi.project.Project)3 IOException (java.io.IOException)3 AndroidLibrary (com.android.builder.model.AndroidLibrary)2 LintOptions (com.android.builder.model.LintOptions)2 ProductFlavorContainer (com.android.builder.model.ProductFlavorContainer)2 LibraryDependency (com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency)2 GradleUtil.getAndroidProject (com.android.tools.idea.gradle.util.GradleUtil.getAndroidProject)2 GradleUtil.getNativeAndroidProject (com.android.tools.idea.gradle.util.GradleUtil.getNativeAndroidProject)2