Search in sources :

Example 26 with AndroidLibrary

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);
    }
}
Also used : BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) Attribute(org.dom4j.Attribute) AndroidLibrary(com.android.builder.model.AndroidLibrary) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) Node(org.dom4j.Node) Document(org.dom4j.Document)

Example 27 with AndroidLibrary

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()));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeaSourceProvider(org.jetbrains.android.facet.IdeaSourceProvider) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) MavenCoordinates(com.android.builder.model.MavenCoordinates) AndroidLibrary(com.android.builder.model.AndroidLibrary) SourcePosition(com.android.ide.common.blame.SourcePosition) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) SourceFile(com.android.ide.common.blame.SourceFile) Module(com.intellij.openapi.module.Module) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFile(com.android.ide.common.blame.SourceFile) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) File(java.io.File)

Example 28 with AndroidLibrary

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);
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with AndroidLibrary

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);
    }
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) File(java.io.File)

Example 30 with AndroidLibrary

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);
    }
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) File(java.io.File)

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