Search in sources :

Example 31 with AndroidLibrary

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

the class ModuleVariantsInfoDialog method createDependentsTree.

@NotNull
private static JTree createDependentsTree(@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 DependentTreeElement) {
                    DependentTreeElement dependent = (DependentTreeElement) data;
                    String variant = null;
                    if (!dependent.myVariants.isEmpty()) {
                        variant = Joiner.on(", ").join(dependent.myVariants);
                    }
                    appendModule(dependent.myModule, variant);
                }
            }
        }
    };
    //noinspection ConstantConditions
    CheckedTreeNode root = new CheckedTreeNode(null);
    AndroidProject androidProject = GradleUtil.getAndroidProject(module);
    assert androidProject != null;
    String gradlePath = GradleUtil.getGradlePath(module);
    assert gradlePath != null;
    Multimap<String, DependentTreeElement> dependentsByVariant = HashMultimap.create();
    ModuleManager moduleManager = ModuleManager.getInstance(module.getProject());
    for (Module dependent : moduleManager.getModuleDependentModules(module)) {
        AndroidProject dependentProject = GradleUtil.getAndroidProject(dependent);
        if (dependentProject == null) {
            continue;
        }
        DependentTreeElement element = new DependentTreeElement(dependent);
        for (Variant variant : dependentProject.getVariants()) {
            for (AndroidLibrary library : GradleUtil.getDirectLibraryDependencies(variant, androidModel)) {
                if (gradlePath.equals(library.getProject())) {
                    element.addVariant(variant.getName());
                    String projectVariant = library.getProjectVariant();
                    if (StringUtil.isNotEmpty(projectVariant)) {
                        dependentsByVariant.put(projectVariant, element);
                    }
                }
            }
        }
    }
    List<String> variantNames = Lists.newArrayList(dependentsByVariant.keySet());
    Collections.sort(variantNames);
    for (String variantName : variantNames) {
        Collection<DependentTreeElement> dependents = dependentsByVariant.get(variantName);
        if (!dependents.isEmpty()) {
            List<DependentTreeElement> sortedDependents = Lists.newArrayList(dependents);
            Collections.sort(sortedDependents);
            DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(variantName);
            for (DependentTreeElement dependent : dependents) {
                variantNode.add(new DefaultMutableTreeNode(dependent));
            }
            root.add(variantNode);
        }
    }
    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) ModuleManager(com.intellij.openapi.module.ModuleManager) 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 32 with AndroidLibrary

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

the class BuildVariantUpdater method updateSelectedVariant.

private boolean updateSelectedVariant(@NotNull AndroidFacet androidFacet, @NotNull AndroidModuleModel androidModel, @NotNull String variantToSelect, @NotNull List<AndroidFacet> affectedFacets) {
    Variant selectedVariant = androidModel.getSelectedVariant();
    if (variantToSelect.equals(selectedVariant.getName())) {
        return false;
    }
    androidModel.setSelectedVariantName(variantToSelect);
    androidModel.syncSelectedVariantAndTestArtifact(androidFacet);
    Module module = setUpModule(androidFacet.getModule(), androidModel);
    for (AndroidLibrary library : androidModel.getSelectedMainCompileDependencies().getLibraries()) {
        String gradlePath = library.getProject();
        if (isEmpty(gradlePath)) {
            continue;
        }
        String projectVariant = library.getProjectVariant();
        if (isNotEmpty(projectVariant)) {
            ensureVariantIsSelected(module.getProject(), gradlePath, projectVariant, affectedFacets);
        }
    }
    return true;
}
Also used : NdkVariant(com.android.tools.idea.gradle.project.model.NdkModuleModel.NdkVariant) Variant(com.android.builder.model.Variant) AndroidLibrary(com.android.builder.model.AndroidLibrary) Module(com.intellij.openapi.module.Module)

Example 33 with AndroidLibrary

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

the class GeneratedCodeMatchTest method findViewDataBindingClass.

@NotNull
private ClassReader findViewDataBindingClass() throws IOException {
    File classes = null;
    AndroidModuleModel model = AndroidModuleModel.get(myAndroidFacet);
    for (AndroidLibrary lib : model.getMainArtifact().getDependencies().getLibraries()) {
        if (lib.getName().startsWith("com.android.databinding:library")) {
            classes = lib.getJarFile();
        }
    }
    assert classes != null;
    assertTrue(classes.exists());
    try (JarFile classesJar = new JarFile(classes, true)) {
        ZipEntry entry = classesJar.getEntry(SdkConstants.CLASS_DATA_BINDING_BASE_BINDING.replace(".", "/") + ".class");
        assertNotNull(entry);
        return new ClassReader(classesJar.getInputStream(entry));
    }
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) ZipEntry(java.util.zip.ZipEntry) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AndroidLibrary (com.android.builder.model.AndroidLibrary)33 File (java.io.File)18 NotNull (org.jetbrains.annotations.NotNull)6 JavaLibrary (com.android.builder.model.JavaLibrary)5 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)5 Module (com.intellij.openapi.module.Module)5 SoLibrary (com.taobao.android.builder.dependency.model.SoLibrary)5 MavenCoordinates (com.android.builder.model.MavenCoordinates)4 Variant (com.android.builder.model.Variant)4 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)4 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)4 InputFile (org.gradle.api.tasks.InputFile)4 TaskAction (org.gradle.api.tasks.TaskAction)4 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)4 VariantScope (com.android.build.gradle.internal.scope.VariantScope)3 HashSet (java.util.HashSet)3 List (java.util.List)3 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)2 SymbolLoader (com.android.builder.internal.SymbolLoader)2 SymbolWriter (com.android.builder.internal.SymbolWriter)2