use of com.android.builder.model.AndroidLibrary in project atlas by alibaba.
the class ManifestDependencyUtil method getManifestDependencies.
//public static List<ManifestDependencyImpl> getManifestDependencies(List<? extends LibraryDependency> libraries,
// Set<String> notMergedArtifacts,
// Logger logger) {
//
// List<ManifestDependencyImpl> list = Lists.newArrayListWithCapacity(libraries.size());
//
// for (LibraryDependency lib : libraries) {
// // get the dependencies
// List<ManifestDependencyImpl> children = ManifestDependencyUtil.getManifestDependencies(
// lib.getDependencies(),
// notMergedArtifacts,
// logger);
//
// // [vliux] respect manifestOption.notMergedBundle
// String cord = String.format("%s:%s",
// lib.getResolvedCoordinates().getGroupId(),
// lib.getResolvedCoordinates().getArtifactId());
// if (null == notMergedArtifacts || !notMergedArtifacts.contains(cord)) {
// list.add(new ManifestDependencyImpl(lib.getName(), lib.getManifest(), children));
// } else {
// logger.info("[NotMergedManifest] " + cord);
// }
// }
//
// return list;
//}
public static List<? extends AndroidLibrary> getManifestDependencies(List<? extends AndroidLibrary> libraries, Set<String> notMergedArtifacts, Logger logger) {
List<AndroidLibrary> list = Lists.newArrayListWithCapacity(libraries.size());
for (AndroidLibrary lib : libraries) {
// get the dependencies
List<? extends AndroidLibrary> children = ManifestDependencyUtil.getManifestDependencies(lib.getLibraryDependencies(), notMergedArtifacts, logger);
// [vliux] respect manifestOption.notMergedBundle
String cord = String.format("%s:%s", lib.getResolvedCoordinates().getGroupId(), lib.getResolvedCoordinates().getArtifactId());
if (null == notMergedArtifacts || !notMergedArtifacts.contains(cord)) {
list.add(lib);
if (null != children) {
list.addAll(children);
}
} else {
logger.info("[NotMergedManifest] " + cord);
}
}
return list;
}
use of com.android.builder.model.AndroidLibrary in project android by JetBrains.
the class AppResourceRepository method findAarLibraries.
@NotNull
public static Collection<AndroidLibrary> findAarLibraries(@NotNull AndroidFacet facet) {
List<AndroidLibrary> libraries = Lists.newArrayList();
if (facet.requiresAndroidModel()) {
AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
if (androidModel != null) {
List<AndroidFacet> dependentFacets = AndroidUtils.getAllAndroidDependencies(facet.getModule(), true);
addGradleLibraries(libraries, androidModel);
for (AndroidFacet dependentFacet : dependentFacets) {
AndroidModuleModel dependentGradleModel = AndroidModuleModel.get(dependentFacet);
if (dependentGradleModel != null) {
addGradleLibraries(libraries, dependentGradleModel);
}
}
}
}
return libraries;
}
use of com.android.builder.model.AndroidLibrary in project android by JetBrains.
the class AppResourceRepository method findAarLibrariesFromGradle.
/**
* Looks up the library dependencies from the Gradle tools model and returns the corresponding {@code .aar}
* resource directories.
*/
@NotNull
private static Map<File, String> findAarLibrariesFromGradle(@NotNull GradleVersion modelVersion, List<AndroidFacet> dependentFacets, List<AndroidLibrary> libraries) {
// Pull out the unique directories, in case multiple modules point to the same .aar folder
Map<File, String> files = new HashMap<>(libraries.size());
Set<String> moduleNames = Sets.newHashSet();
for (AndroidFacet f : dependentFacets) {
moduleNames.add(f.getModule().getName());
}
try {
for (AndroidLibrary library : libraries) {
// We should only add .aar dependencies if they aren't already provided as modules.
// For now, the way we associate them with each other is via the library name;
// in the future the model will provide this for us
String libraryName = null;
String projectName = library.getProject();
if (projectName != null && !projectName.isEmpty()) {
libraryName = projectName.substring(projectName.lastIndexOf(':') + 1);
// Since this library has project!=null, it exists in module form; don't
// add it here.
moduleNames.add(libraryName);
continue;
} else {
File folder = library.getFolder();
String name = folder.getName();
if (modelVersion.getMajor() > 2 || modelVersion.getMajor() == 2 && modelVersion.getMinor() >= 2) {
// Library.getName() was added in 2.2
libraryName = library.getName();
} else if (name.endsWith(DOT_AAR)) {
libraryName = name.substring(0, name.length() - DOT_AAR.length());
} else if (folder.getPath().contains(AndroidModuleModel.EXPLODED_AAR)) {
libraryName = folder.getParentFile().getName();
}
}
if (libraryName != null && !moduleNames.contains(libraryName)) {
File resFolder = library.getResFolder();
if (resFolder.exists()) {
files.put(resFolder, libraryName);
// Don't add it again!
moduleNames.add(libraryName);
}
}
}
} catch (UnsupportedMethodException e) {
// This happens when there is an incompatibility between the builder-model interfaces embedded in Android Studio and the
// cached model.
// If we got here is because this code got invoked before project sync happened (e.g. when reopening a project with open editors).
// Project sync now is smart enough to handle this case and will trigger a full sync.
LOG.warn("Incompatibility found between the IDE's builder-model and the cached Gradle model", e);
}
return files;
}
use of com.android.builder.model.AndroidLibrary in project kotlin by JetBrains.
the class PrivateResourceDetector method getLibraryName.
/** Pick a suitable name to describe the library defining the private resource */
@Nullable
private static String getLibraryName(@NonNull Context context, @NonNull ResourceType type, @NonNull String name) {
ResourceVisibilityLookup lookup = context.getProject().getResourceVisibility();
AndroidLibrary library = lookup.getPrivateIn(type, name);
if (library != null) {
String libraryName = library.getProject();
if (libraryName != null) {
return libraryName;
}
MavenCoordinates coordinates = library.getResolvedCoordinates();
if (coordinates != null) {
return coordinates.getGroupId() + ':' + coordinates.getArtifactId();
}
}
return "the library";
}
use of com.android.builder.model.AndroidLibrary in project android by JetBrains.
the class ProjectProfileSelectionDialog method createProjectStructureTree.
private void createProjectStructureTree() {
CheckboxTree.CheckboxTreeCellRenderer renderer = new CheckboxTree.CheckboxTreeCellRenderer() {
@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();
ColoredTreeCellRenderer textRenderer = getTextRenderer();
if (data instanceof ModuleTreeElement) {
ModuleTreeElement moduleElement = (ModuleTreeElement) data;
textRenderer.append(moduleElement.myModule.getName());
if (!moduleElement.myConflicts.isEmpty()) {
boolean allResolved = true;
for (Conflict conflict : moduleElement.myConflicts) {
if (!conflict.isResolved()) {
allResolved = false;
break;
}
}
SimpleTextAttributes attributes = allResolved ? UNRESOLVED_ATTRIBUTES : SimpleTextAttributes.GRAY_ATTRIBUTES;
textRenderer.append(" ");
textRenderer.append(myConflicts.size() == 1 ? "[Conflict]" : "[Conflicts]", attributes);
}
textRenderer.setIcon(AllIcons.Actions.Module);
} else if (data instanceof String) {
textRenderer.append((String) data, SimpleTextAttributes.REGULAR_ITALIC_ATTRIBUTES);
textRenderer.setIcon(AndroidIcons.Variant);
} else if (data instanceof DependencyTreeElement) {
DependencyTreeElement dependency = (DependencyTreeElement) data;
textRenderer.append(dependency.myModule.getName());
if (!StringUtil.isEmpty(dependency.myVariant)) {
textRenderer.append(" (" + dependency.myVariant + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
}
Icon icon = dependency.myConflict != null ? AllIcons.RunConfigurations.TestFailed : AllIcons.RunConfigurations.TestPassed;
textRenderer.setIcon(icon);
}
}
}
};
CheckedTreeNode rootNode = new FilterAwareCheckedTreeNode(null);
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
Module[] modules = moduleManager.getModules();
Arrays.sort(modules, ModulesAlphaComparator.INSTANCE);
Map<String, Module> modulesByGradlePath = Maps.newHashMap();
for (Module module : modules) {
String gradlePath = GradleUtil.getGradlePath(module);
if (StringUtil.isEmpty(gradlePath)) {
// We always want to include it, therefore we don't give users a chance to uncheck it in the "Project Structure" pane.
continue;
}
modulesByGradlePath.put(gradlePath, module);
ModuleTreeElement moduleElement = new ModuleTreeElement(module);
CheckedTreeNode moduleNode = new FilterAwareCheckedTreeNode(moduleElement);
rootNode.add(moduleNode);
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel == null) {
continue;
}
Multimap<String, DependencyTreeElement> dependenciesByVariant = HashMultimap.create();
for (Variant variant : androidModel.getAndroidProject().getVariants()) {
for (AndroidLibrary library : getDirectLibraryDependencies(variant, androidModel)) {
gradlePath = library.getProject();
if (gradlePath == null) {
continue;
}
Module dependency = modulesByGradlePath.get(gradlePath);
if (dependency == null) {
dependency = GradleUtil.findModuleByGradlePath(myProject, gradlePath);
}
if (dependency == null) {
continue;
}
Conflict conflict = getConflict(dependency);
modulesByGradlePath.put(gradlePath, dependency);
DependencyTreeElement dependencyElement = new DependencyTreeElement(dependency, gradlePath, library.getProjectVariant(), conflict);
dependenciesByVariant.put(variant.getName(), dependencyElement);
}
}
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);
moduleNode.add(variantNode);
List<DependencyTreeElement> dependencyElements = Lists.newArrayList(set1);
Collections.sort(dependencyElements);
for (DependencyTreeElement dependencyElement : dependencyElements) {
if (dependencyElement.myConflict != null) {
moduleElement.addConflict(dependencyElement.myConflict);
}
variantNode.add(new DefaultMutableTreeNode(dependencyElement));
}
consolidatedVariants.clear();
}
}
myProjectStructureTree = new CheckboxTreeView(renderer, rootNode) {
@Override
protected void onNodeStateChanged(@NotNull CheckedTreeNode node) {
Module module = null;
Object data = node.getUserObject();
if (data instanceof ModuleTreeElement) {
module = ((ModuleTreeElement) data).myModule;
}
if (module == null) {
return;
}
boolean updated = false;
Enumeration variantNodes = myConflictTree.myRoot.children();
while (variantNodes.hasMoreElements()) {
Object child = variantNodes.nextElement();
if (!(child instanceof CheckedTreeNode)) {
continue;
}
CheckedTreeNode variantNode = (CheckedTreeNode) child;
Enumeration moduleNodes = variantNode.children();
while (moduleNodes.hasMoreElements()) {
child = moduleNodes.nextElement();
if (!(child instanceof CheckedTreeNode)) {
continue;
}
CheckedTreeNode moduleNode = (CheckedTreeNode) child;
data = moduleNode.getUserObject();
if (!(data instanceof Conflict.AffectedModule)) {
continue;
}
Conflict.AffectedModule affected = (Conflict.AffectedModule) data;
boolean checked = node.isChecked();
if (module.equals(affected.getTarget()) && moduleNode.isChecked() != checked) {
affected.setSelected(checked);
moduleNode.setChecked(checked);
updated = true;
}
}
}
if (updated) {
repaintAll();
}
}
};
myProjectStructureTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
myProjectStructureTree.setRootVisible(false);
}
Aggregations