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;
}
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;
}
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));
}
}
Aggregations