use of com.android.builder.model.AndroidLibrary in project atlas by alibaba.
the class BundleInfoUtils method update.
/**
* 解析manifest文件,得到BundleInfo
*
* @return
*/
private static void update(AwbBundle awbBundle, Map<String, BundleInfo> bundleInfoMap, AppVariantContext appVariantContext, String apkVersion) throws DocumentException {
String artifactId = awbBundle.getResolvedCoordinates().getArtifactId();
BundleInfo bundleInfo = bundleInfoMap.get(artifactId);
if (null != bundleInfo) {
awbBundle.bundleInfo = bundleInfo;
} else {
bundleInfo = awbBundle.bundleInfo;
}
awbBundle.isRemote = appVariantContext.getAtlasExtension().getTBuildConfig().getOutOfApkBundles().contains(artifactId);
bundleInfo.setIsInternal(!awbBundle.isRemote);
bundleInfo.setVersion(apkVersion + "@" + awbBundle.getResolvedCoordinates().getVersion());
bundleInfo.setPkgName(awbBundle.getPackageName());
String applicationName = ManifestFileUtils.getApplicationName(awbBundle.getOrgManifestFile());
if (StringUtils.isNotEmpty(applicationName)) {
bundleInfo.setApplicationName(applicationName);
}
SAXReader reader = new SAXReader();
// 读取XML文件
Document document = reader.read(awbBundle.getManifest());
// 得到根节点
Element root = document.getRootElement();
List<? extends Node> metadataNodes = root.selectNodes("//meta-data");
for (Node node : metadataNodes) {
Element element = (Element) node;
Attribute attribute = element.attribute("name");
if (attribute.getValue().equals("label")) {
Attribute labelAttribute = element.attribute("value");
bundleInfo.setName(labelAttribute.getValue());
} else if (attribute.getValue().equals("description")) {
Attribute descAttribute = element.attribute("value");
bundleInfo.setDesc(descAttribute.getValue());
}
}
addComponents(bundleInfo, root);
for (AndroidLibrary depLib : awbBundle.getLibraryDependencies()) {
SAXReader reader2 = new SAXReader();
// 读取XML文件
Document document2 = reader2.read(depLib.getManifest());
// 得到根节点
Element root2 = document2.getRootElement();
addComponents(bundleInfo, root2);
}
}
use of com.android.builder.model.AndroidLibrary in project android by JetBrains.
the class ManifestPanel method describePosition.
private void describePosition(@NotNull HtmlBuilder sb, @NotNull AndroidFacet facet, @NotNull SourceFilePosition sourceFilePosition) {
SourceFile sourceFile = sourceFilePosition.getFile();
SourcePosition sourcePosition = sourceFilePosition.getPosition();
File file = sourceFile.getSourceFile();
if (file == GRADLE_MODEL_MARKER_FILE) {
VirtualFile gradleBuildFile = GradleUtil.getGradleBuildFile(facet.getModule());
if (gradleBuildFile != null) {
file = VfsUtilCore.virtualToIoFile(gradleBuildFile);
sb.addHtml("<a href=\"");
sb.add(file.toURI().toString());
sb.addHtml("\">");
sb.add(file.getName());
sb.addHtml("</a>");
sb.add(" injection");
} else {
sb.add("build.gradle injection (source location unknown)");
}
return;
}
AndroidLibrary library;
if (file != null) {
String source = null;
Module libraryModule = null;
Module[] modules = ModuleManager.getInstance(facet.getModule().getProject()).getModules();
VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(file);
if (vFile != null) {
Module module = ModuleUtilCore.findModuleForFile(vFile, facet.getModule().getProject());
if (module != null) {
if (modules.length >= 2) {
source = module.getName();
}
// AAR Library?
if (file.getPath().contains(EXPLODED_AAR)) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel != null) {
library = GradleUtil.findLibrary(file.getParentFile(), androidModel.getSelectedVariant(), androidModel.getModelVersion());
if (library != null) {
if (library.getProject() != null) {
libraryModule = GradleUtil.findModuleByGradlePath(facet.getModule().getProject(), library.getProject());
if (libraryModule != null) {
module = libraryModule;
source = module.getName();
} else {
source = library.getProject();
source = StringUtil.trimStart(source, ":");
}
} else {
MavenCoordinates coordinates = library.getResolvedCoordinates();
source = /*coordinates.getGroupId() + ":" +*/
coordinates.getArtifactId() + ":" + coordinates.getVersion();
}
}
}
}
}
IdeaSourceProvider provider = ManifestUtils.findManifestSourceProvider(facet, vFile);
if (provider != null) /*&& !provider.equals(facet.getMainIdeaSourceProvider())*/
{
String providerName = provider.getName();
if (source == null) {
source = providerName;
} else {
// "the app main manifest" - "app" is the module name, "main" is the source provider name
source = source + " " + providerName;
}
}
}
if (source == null) {
source = file.getName();
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
source += ":" + String.valueOf(sourcePosition);
}
}
sb.addHtml("<a href=\"");
boolean redirected = false;
if (libraryModule != null) {
AndroidFacet libraryFacet = AndroidFacet.getInstance(libraryModule);
if (libraryFacet != null) {
File manifestFile = libraryFacet.getMainSourceProvider().getManifestFile();
if (manifestFile.exists()) {
sb.add(manifestFile.toURI().toString());
redirected = true;
// Line numbers probably aren't right
sourcePosition = SourcePosition.UNKNOWN;
// TODO: Set URL which points to the element/attribute path
}
}
}
if (!redirected) {
sb.add(file.toURI().toString());
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
sb.add(":");
sb.add(String.valueOf(sourcePosition.getStartLine()));
sb.add(":");
sb.add(String.valueOf(sourcePosition.getStartColumn()));
}
}
sb.addHtml("\">");
sb.add(source);
sb.addHtml("</a>");
sb.add(" manifest");
if (FileUtil.filesEqual(file, VfsUtilCore.virtualToIoFile(myFile))) {
sb.add(" (this file)");
}
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
sb.add(", line ");
sb.add(Integer.toString(sourcePosition.getStartLine()));
}
}
}
use of com.android.builder.model.AndroidLibrary in project android by JetBrains.
the class AppResourceRepository method findAarLibraries.
@NotNull
private static Map<File, String> findAarLibraries(@NotNull AndroidFacet facet, @NotNull List<AndroidFacet> dependentFacets) {
// Use the gradle model if available, but if not, fall back to using plain IntelliJ library dependencies
// which have been persisted since the most recent sync
AndroidModuleModel androidModuleModel = AndroidModuleModel.get(facet);
if (androidModuleModel != null) {
List<AndroidLibrary> libraries = Lists.newArrayList();
addGradleLibraries(libraries, androidModuleModel);
for (AndroidFacet dependentFacet : dependentFacets) {
AndroidModuleModel dependentGradleModel = AndroidModuleModel.get(dependentFacet);
if (dependentGradleModel != null) {
addGradleLibraries(libraries, dependentGradleModel);
}
}
return findAarLibrariesFromGradle(androidModuleModel.getModelVersion(), dependentFacets, libraries);
}
return findAarLibrariesFromIntelliJ(facet, dependentFacets);
}
use of com.android.builder.model.AndroidLibrary in project android by JetBrains.
the class AppResourceRepository method addGradleLibrary.
private static void addGradleLibrary(List<AndroidLibrary> list, AndroidLibrary library, Set<File> unique) {
File folder = library.getFolder();
if (!unique.add(folder)) {
return;
}
list.add(library);
for (AndroidLibrary dependency : library.getLibraryDependencies()) {
addGradleLibrary(list, dependency, unique);
}
}
use of com.android.builder.model.AndroidLibrary in project android by JetBrains.
the class AppResourceRepository method addGradleLibraries.
// TODO: b/23032391
private static void addGradleLibraries(List<AndroidLibrary> list, AndroidModuleModel androidModuleModel) {
Collection<AndroidLibrary> libraries = androidModuleModel.getSelectedMainCompileDependencies().getLibraries();
Set<File> unique = Sets.newHashSet();
for (AndroidLibrary library : libraries) {
addGradleLibrary(list, library, unique);
}
}
Aggregations