com.android.builder.model.AndroidLibrary Java Examples

The following examples show how to use com.android.builder.model.AndroidLibrary. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DependencyConvertUtils.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Simple transformations, no dependencies
 *
 * @param resolvedDependencyInfo
 * @return
 */
public static AndroidLibrary toAndroidLibrary(ResolvedDependencyInfo resolvedDependencyInfo, Project project,
                                              boolean bundle) {

    ResolvedArtifact artifact = resolvedDependencyInfo.getResolvedArtifact();

    AndroidDependency androidDependency = AndroidDependency.createExplodedAarLibrary(artifact.getFile(),
                                                                                     convert(artifact,bundle?Type.AWB:Type.AAR),
                                                                                     resolvedDependencyInfo
                                                                                         .getDependencyName(),
                                                                                     null,
                                                                                     resolvedDependencyInfo
                                                                                         .getExplodedDir());

    List<File> localJars = new ArrayList<>();

    return new AtlasAndroidLibraryImpl(androidDependency,
                                  false,
                                  false,
                                  ImmutableList.<AndroidLibrary>of(),
                                  ImmutableList.<JavaLibrary>of(),
                                  localJars);
}
 
Example #2
Source File: PrivateResourceDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/** 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";
}
 
Example #3
Source File: ManifestHelper.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static List<? extends AndroidLibrary> getManifestDependencies(List<AwbBundle> awbBundles,
                                                                     Set<String> notMergedArtifacts,
                                                                     org.gradle.api.logging.Logger logger) {

    List<AndroidLibrary> list = new ArrayList<>();

    for (AwbBundle lib : awbBundles) {
        // get the dependencies
        // [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.getAndroidLibrary());
            list.addAll(lib.getAndroidLibraries());

        } else {
            logger.info("[NotMergedManifest] " + cord);
        }
    }

    return list;
}
 
Example #4
Source File: DependenciesImpl.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private static AndroidLibrary convertAndroidLibrary(
        @NonNull LibraryDependency libraryDependency) {
    List<LibraryDependency> deps = libraryDependency.getDependencies();
    List<AndroidLibrary> clonedDeps = Lists.newArrayListWithCapacity(deps.size());
    for (LibraryDependency child : deps) {
        AndroidLibrary clonedLib = sCache.get(child);
        if (clonedLib != null) {
            clonedDeps.add(clonedLib);
        }
    }

    // compute local jar even if the bundle isn't exploded.
    Collection<File> localJarOverride = findLocalJar(libraryDependency);

    return new AndroidLibraryImpl(
            libraryDependency,
            clonedDeps,
            localJarOverride,
            libraryDependency.getProject(),
            libraryDependency.getProjectVariant(),
            libraryDependency.getRequestedCoordinates(),
            libraryDependency.getResolvedCoordinates());
}
 
Example #5
Source File: PrivateResourceDetectorTest.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public static AndroidLibrary createMockLibrary(String allResources, String publicResources,
        List<AndroidLibrary> dependencies)
        throws IOException {
    final File tempDir = TestUtils.createTempDirDeletedOnExit();

    Files.write(allResources, new File(tempDir, FN_RESOURCE_TEXT), Charsets.UTF_8);
    File publicTxtFile = new File(tempDir, FN_PUBLIC_TXT);
    if (publicResources != null) {
        Files.write(publicResources, publicTxtFile, Charsets.UTF_8);
    }
    AndroidLibrary library = mock(AndroidLibrary.class);
    when(library.getPublicResources()).thenReturn(publicTxtFile);

    // Work around wildcard capture
    //when(mock.getLibraryDependencies()).thenReturn(dependencies);
    List libraryDependencies = library.getLibraryDependencies();
    OngoingStubbing<List> setter = when(libraryDependencies);
    setter.thenReturn(dependencies);
    return library;
}
 
Example #6
Source File: ExternalAnnotationRepository.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private static void addLibraries(
        @NonNull List<File> result,
        @NonNull AndroidLibrary library,
        Set<AndroidLibrary> seen) {
    if (seen.contains(library)) {
        return;
    }
    seen.add(library);

    // As of 1.2 this is available in the model:
    //  https://android-review.googlesource.com/#/c/137750/
    // Switch over to this when it's in more common usage
    // (until it is, we'll pay for failed proxying errors)
    File zip = new File(library.getResFolder().getParent(), FN_ANNOTATIONS_ZIP);
    if (zip.exists()) {
        result.add(zip);
    }

    for (AndroidLibrary dependency : library.getLibraryDependencies()) {
        addLibraries(result, dependency, seen);
    }
}
 
Example #7
Source File: LintGradleProject.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private static LibraryProject createLibrary(@NonNull LintGradleClient client,
                                            @NonNull AndroidLibrary library,
                                            @NonNull Set<AndroidLibrary> seen, List<File> customRules) {
    seen.add(library);
    File dir = library.getFolder();
    LibraryProject project = new LibraryProject(client, dir, dir, library);

    File ruleJar = library.getLintJar();
    if (ruleJar.exists()) {
        customRules.add(ruleJar);
    }

    for (AndroidLibrary dependent : library.getLibraryDependencies()) {
        if (!seen.contains(dependent)) {
            project.addDirectLibrary(createLibrary(client, dependent, seen, customRules));
        }
    }

    return project;
}
 
Example #8
Source File: LintGradleProject.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
protected static boolean dependsOn(@NonNull AndroidLibrary library, @NonNull String artifact) {
    if (SUPPORT_LIB_ARTIFACT.equals(artifact)) {
        if (library.getJarFile().getName().startsWith("support-v4-")) {
            return true;
        }

    } else if (APPCOMPAT_LIB_ARTIFACT.equals(artifact)) {
        File bundle = library.getBundle();
        if (bundle.getName().startsWith("appcompat-v7-")) {
            return true;
        }
    }

    for (AndroidLibrary dependency : library.getLibraryDependencies()) {
        if (dependsOn(dependency, artifact)) {
            return true;
        }
    }

    return false;
}
 
Example #9
Source File: AndroidClassPathProvider.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
public void addAndroidLibraryDependencies(List<URL> roots, Map<URL, ArtifactData> libs, AndroidLibrary lib) {
    String name = lib.getName();
    URL url = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(lib.getJarFile()));
    if (!roots.contains(url)) {
        roots.add(url);
        libs.put(url, new ArtifactData(lib, project));
    }
    List<? extends AndroidLibrary> libraryDependencies = lib.getLibraryDependencies();
    for (AndroidLibrary libraryDependencie : libraryDependencies) {
        addAndroidLibraryDependencies(roots, libs, libraryDependencie);
    }
    Iterator<File> localJars = lib.getLocalJars().iterator();
    if (localJars != null) {
        while (localJars.hasNext()) {
            File next = localJars.next();
            url = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(next));
            if (!roots.contains(url)) {
                roots.add(url);
                libs.put(url, new ArtifactData(lib, project));
            }

        }
    }

}
 
Example #10
Source File: LintGradleProject.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a {@link LintGradleProject} from
 * the given {@link com.android.builder.model.AndroidProject} definition for
 * a given {@link com.android.builder.model.Variant}, and returns it along with
 * a set of lint custom rule jars applicable for the given model project.
 *
 * @param client        the client
 * @param project       the model project
 * @param variant       the variant
 * @param gradleProject the gradle project
 * @return a pair of new project and list of custom rule jars
 */
@NonNull
public static Pair<LintGradleProject, List<File>> create(
        @NonNull LintGradleClient client,
        @NonNull AndroidProject project,
        @NonNull Variant variant,
        @NonNull org.gradle.api.Project gradleProject) {
    File dir = gradleProject.getProjectDir();
    AppGradleProject lintProject = new AppGradleProject(client, dir,
            dir, project, variant);

    List<File> customRules = Lists.newArrayList();
    File appLintJar = new File(gradleProject.getBuildDir(),
            "lint" + separatorChar + "lint.jar");
    if (appLintJar.exists()) {
        customRules.add(appLintJar);
    }

    Set<AndroidLibrary> libraries = Sets.newHashSet();
    Dependencies dependencies = variant.getMainArtifact().getDependencies();
    for (AndroidLibrary library : dependencies.getLibraries()) {
        lintProject.addDirectLibrary(createLibrary(client, library, libraries, customRules));
    }

    return Pair.<LintGradleProject, List<File>>of(lintProject, customRules);
}
 
Example #11
Source File: AtlasDependencyTree.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Get all aar and awb Rely on
 *
 * @return
 */
public List<AndroidLibrary> getAllAndroidLibrarys() {

    if (null == allAndroidLibrarys) {

        allAndroidLibrarys = new ArrayList<>();

        allAndroidLibrarys.addAll(getMainBundle().getAndroidLibraries());

        for (AwbBundle awbBundle : getAwbBundles()) {
            allAndroidLibrarys.add(awbBundle.getAndroidLibrary());
            allAndroidLibrarys.addAll(awbBundle.getAndroidLibraries());
        }
    }

    return allAndroidLibrarys;
}
 
Example #12
Source File: AwbBundle.java    From atlas with Apache License 2.0 6 votes vote down vote up
public List<ManifestProvider> getManifestProviders() {
    if (null != _cacheManifestProviders) {
        return _cacheManifestProviders;
    }

    _cacheManifestProviders = new ArrayList<>();
    List<AndroidLibrary> androidLibraries = new ArrayList<>(getAndroidLibraries());
    androidLibraries.add(getAndroidLibrary());
    for (AndroidLibrary androidLibrary : androidLibraries) {
        _cacheManifestProviders.add(new ManifestProvider() {
            @Override
            public File getManifest() {
                return androidLibrary.getManifest();
            }

            @Override
            public String getName() {
                return androidLibrary.getName();
            }
        });
    }
    return _cacheManifestProviders;
}
 
Example #13
Source File: ResourceVisibilityLookup.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public AndroidLibrary getPrivateIn(@NonNull ResourceType type, @NonNull String name) {
    if (isPrivate(type, name)) {
        return mLibrary;
    }

    return null;
}
 
Example #14
Source File: PostProcessManifestAction.java    From atlas with Apache License 2.0 5 votes vote down vote up
private List<? extends AndroidLibrary> getAwbLibraries() {
    return ManifestHelper.getManifestDependencies(
            AtlasBuildContext.androidDependencyTrees
                    .get(appVariantContext.getScope().getVariantConfiguration().getFullName()).getAwbBundles(),
            appVariantContext.getAtlasExtension().manifestOptions.getNotMergedBundles(),
            appVariantContext.getProject().getLogger());
}
 
Example #15
Source File: ResourceVisibilityLookup.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("ForLoopReplaceableByForEach")
@Nullable
@Override
public AndroidLibrary getPrivateIn(@NonNull ResourceType type, @NonNull String name) {
    for (int i = 0, n = mRepositories.size(); i < n; i++) {
        ResourceVisibilityLookup r = mRepositories.get(i);
        if (r.isPrivate(type, name)) {
            return r.getPrivateIn(type, name);
        }
    }
    return null;
}
 
Example #16
Source File: ResourceVisibilityLookup.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a {@link ResourceVisibilityLookup} for the set of libraries.
 * <p>
 * NOTE: The {@link Provider} class can be used to share/cache {@link ResourceVisibilityLookup}
 * instances, e.g. when you have library1 and library2 each referencing libraryBase, the {@link
 * Provider} will ensure that a the libraryBase data is shared.
 *
 * @param libraries the list of libraries
 * @param provider  an optional manager instance for caching of individual libraries, if any
 * @return a corresponding {@link ResourceVisibilityLookup}
 */
@NonNull
public static ResourceVisibilityLookup create(@NonNull List<AndroidLibrary> libraries,
        @Nullable Provider provider) {
    List<ResourceVisibilityLookup> list = Lists.newArrayListWithExpectedSize(libraries.size());
    for (AndroidLibrary library : libraries) {
        ResourceVisibilityLookup v = provider != null ? provider.get(library) : create(library);
        if (!v.isEmpty()) {
            list.add(v);
        }
    }
    return new MultipleLibraryResourceVisibility(list);
}
 
Example #17
Source File: ExternalAnnotationRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static AnnotationsDatabase getDatabase(
        @NonNull LintClient client,
        @NonNull AndroidLibrary library) {
    // As of 1.2 this is available in the model:
    //  https://android-review.googlesource.com/#/c/137750/
    // Switch over to this when it's in more common usage
    // (until it is, we'll pay for failed proxying errors)
    File zip = new File(library.getResFolder().getParent(), FN_ANNOTATIONS_ZIP);
    return getDatabase(client, zip);
}
 
Example #18
Source File: GradleSourceForBinaryQuery.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private Result findAarLibraryRoots(final URL binaryRoot) {
        // FileUtil.getArchiveFile(binaryRoot);
        AndroidLibrary aLib = null;
        Variant variant = buildConfig.getCurrentVariant();
        if (variant != null) {
            aLib = Iterables.find(
                    variant.getMainArtifact().getDependencies().getLibraries(),
                    new Predicate<AndroidLibrary>() {

                @Override
                public boolean apply(AndroidLibrary lib) {
                    URL libUrl = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(lib.getJarFile()));
                    return binaryRoot.equals(libUrl);
                }
            },
                    null);
        }
        if (aLib == null) {
            return null;
        }
//    if (aLib instanceof AndroidLibraryProject) {
//      AndroidLibraryProject libPrj = (AndroidLibraryProject) aLib;
//      LOG.log(Level.FINE, "Found binary from AndroidLibrary {0}", libPrj.getProjectPath());
//    } else {
        LOG.log(Level.FINE, "Found unknown binary from AndroidLibrary {0}", aLib.getJarFile());
//    }
        return null;
    }
 
Example #19
Source File: AndroidClassPathProvider.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends File> get() {
    Variant variant = buildConfig.getCurrentVariant();
    if (variant != null) {
        AndroidArtifact testArtifact = AndroidBuildVariants.instrumentTestArtifact(variant.getExtraAndroidArtifacts());
        Iterable<File> testCompileCPEntries
                = Collections.<File>singleton(variant.getMainArtifact().getClassesFolder());
        if (testArtifact != null) {
            List<File> javaLibs = new ArrayList<>();
            for (JavaLibrary lib : testArtifact.getDependencies().getJavaLibraries()) {
                collectJavaLibraries(javaLibs, lib);
            }
            testCompileCPEntries = Iterables.concat(
                    testCompileCPEntries,
                    Iterables.transform(
                            testArtifact.getDependencies().getLibraries(),
                            new Function<AndroidLibrary, File>() {
                        @Override
                        public File apply(AndroidLibrary f) {
                            return f.getJarFile();
                        }
                    }),
                    javaLibs);
        }
        return testCompileCPEntries;
    }
    return Collections.<File>emptyList();
}
 
Example #20
Source File: ArtifactData.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private String makeJavadocFileName() {
    File f;
    if (library instanceof AndroidLibrary) {
        f = ((AndroidLibrary) library).getBundle();
    } else {
        f = ((JavaLibrary) library).getJarFile();
    }
    String name = f.getName();
    String baseName = FilenameUtils.getBaseName(name);
    return baseName + JAVADOC_NAME;
}
 
Example #21
Source File: ArtifactData.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private String makePomFileName() {
    File f;
    if (library instanceof AndroidLibrary) {
        f = ((AndroidLibrary) library).getBundle();
    } else {
        f = ((JavaLibrary) library).getJarFile();
    }
    String name = f.getName();
    String baseName = FilenameUtils.getBaseName(name);
    return baseName + DependencyNode.POM_NAME;
}
 
Example #22
Source File: ArtifactData.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private String makeSrcFileName() {
    File f;
    if (library instanceof AndroidLibrary) {
        f = ((AndroidLibrary) library).getBundle();
    } else {
        f = ((JavaLibrary) library).getJarFile();
    }
    String name = f.getName();
    String baseName = FilenameUtils.getBaseName(name);
    return baseName + SRC_NAME;
}
 
Example #23
Source File: AndroidSupport.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
private void parseExtraJavaArtifacts(Set<ProjectDependency> dependencies, Variant variant) {
  String buildType = variant.getBuildType();
  boolean debugBuild = buildType.equals(DEBUG_BUILD);
  Collection<JavaArtifact> extraJavaArtifacts = variant.getExtraJavaArtifacts();
  for (JavaArtifact javaArtifact : extraJavaArtifacts) {
    if (debugBuild) {
      Collection<File> generatedSourceFolders = javaArtifact.getGeneratedSourceFolders();
      for (File src : generatedSourceFolders) {
        this.project.getSources().add(src);
      }
    }

    Dependencies compileDependencies = javaArtifact.getDependencies();
    Collection<AndroidLibrary> libraries = compileDependencies.getLibraries();
    for (AndroidLibrary androidLibrary : libraries) {
      Collection<File> localJars = androidLibrary.getLocalJars();
      for (File jar : localJars) {
        addDependencies(dependencies, jar);
      }
    }
    Collection<JavaLibrary> javaLibraries = compileDependencies.getJavaLibraries();
    for (JavaLibrary javaLibrary : javaLibraries) {
      File file = javaLibrary.getJarFile();
      addDependencies(dependencies, file);
    }
  }
}
 
Example #24
Source File: PrivateResourceDetectorTest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public static AndroidArtifact createMockArtifact(List<AndroidLibrary> libraries) {
    Dependencies dependencies = mock(Dependencies.class);
    when(dependencies.getLibraries()).thenReturn(libraries);

    AndroidArtifact artifact = mock(AndroidArtifact.class);
    when(artifact.getDependencies()).thenReturn(dependencies);

    return artifact;
}
 
Example #25
Source File: DependencyConvertUtils.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static AndroidLibrary toAndroidLibrary(MavenCoordinates mavenCoordinates, File artifact, File dir) {

        AndroidDependency androidDependency = AndroidDependency.createExplodedAarLibrary(artifact,
                                                                                         mavenCoordinates,
                                                                                         mavenCoordinates.toString(),
                                                                                         null,
                                                                                         dir);

        return new AtlasAndroidLibraryImpl(androidDependency,
                                      false,
                                      false,
                                      ImmutableList.<AndroidLibrary>of(),
                                      ImmutableList.<JavaLibrary>of(),
                                      androidDependency.getLocalJars());
    }
 
Example #26
Source File: AtlasAndroidLibraryImpl.java    From atlas with Apache License 2.0 5 votes vote down vote up
public AtlasAndroidLibraryImpl(
            @NonNull AndroidDependency clonedLibrary,
            boolean isProvided,
            boolean isSkipped,
            @NonNull List<AndroidLibrary> androidLibraries,
            @NonNull Collection<JavaLibrary> javaLibraries,
            @NonNull Collection<File> localJavaLibraries) {
        super(
                clonedLibrary.getProjectPath(),
                null,
                clonedLibrary.getCoordinates(),
                isSkipped,
                isProvided);


        this.androidLibrary = clonedLibrary;
        this.androidLibraries = ImmutableList.copyOf(androidLibraries);
        this.javaLibraries = ImmutableList.copyOf(javaLibraries);
        this.variant = androidLibrary.getVariant();
        //FIXME , add localJar later at prepareAllDependencies
//        this.localJars = clonedLibrary.getLocalJars();
//        variant = clonedLibrary.getVariant();
////        bundle = .getArtifactFile();
////        bundle = clonedLibrary.getClasspathFile();
//        folder = clonedLibrary.getExtractedFolder();
//        manifest = clonedLibrary.getManifest();
//        jarFile = clonedLibrary.getJarFile();
//        resFolder = clonedLibrary.getResFolder();
//        assetsFolder = clonedLibrary.getAssetsFolder();
//        jniFolder = clonedLibrary.getJniFolder();
//        aidlFolder = clonedLibrary.getAidlFolder();
//        renderscriptFolder = clonedLibrary.getRenderscriptFolder();
//        proguardRules = clonedLibrary.getProguardRules();
//        lintJar = clonedLibrary.getLintJar();
//        annotations = clonedLibrary.getExternalAnnotations();
//        publicResources = clonedLibrary.getPublicResources();
//        symbolFile = clonedLibrary.getSymbolFile();
//        hashcode = computeHashCode();
    }
 
Example #27
Source File: DependenciesImpl.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
static DependenciesImpl cloneDependenciesForJavaArtifacts(@NonNull Dependencies dependencies) {
    List<AndroidLibrary> libraries = Collections.emptyList();
    List<JavaLibrary> javaLibraries = Lists.newArrayList(dependencies.getJavaLibraries());
    List<String> projects = Collections.emptyList();

    return new DependenciesImpl(libraries, javaLibraries, projects);
}
 
Example #28
Source File: DependenciesImpl.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private DependenciesImpl(@NonNull List<AndroidLibrary> libraries,
                         @NonNull List<JavaLibrary> javaLibraries,
                         @NonNull List<String> projects) {
    this.libraries = libraries;
    this.javaLibraries = javaLibraries;
    this.projects = projects;
}
 
Example #29
Source File: LintGradleProject.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private LibraryProject(
        @NonNull LintGradleClient client,
        @NonNull File dir,
        @NonNull File referenceDir,
        @NonNull AndroidLibrary library) {
    super(client, dir, referenceDir, library.getManifest());
    mLibrary = library;

    // TODO: Make sure we don't use this project for any source library projects!
    mReportIssues = false;
}
 
Example #30
Source File: LintGradleProject.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
protected static boolean dependsOn(@NonNull Dependencies dependencies,
                                   @NonNull String artifact) {
    for (AndroidLibrary library : dependencies.getLibraries()) {
        if (dependsOn(library, artifact)) {
            return true;
        }
    }
    return false;
}