Search in sources :

Example 1 with Dependencies

use of com.android.builder.model.Dependencies in project meghanada-server by mopemope.

the class AndroidSupport method getAndroidDependencies.

private Set<ProjectDependency> getAndroidDependencies(AndroidProject androidProject) {
    Set<ProjectDependency> dependencies = new HashSet<>(16);
    Collection<String> bootClasspath = androidProject.getBootClasspath();
    for (String cp : bootClasspath) {
        File file = new File(cp);
        addDependencies(dependencies, file);
    }
    Collection<Variant> variants = androidProject.getVariants();
    for (Variant variant : variants) {
        String buildType = variant.getBuildType();
        boolean debugBuild = buildType.equals(DEBUG_BUILD);
        AndroidArtifact mainArtifact = variant.getMainArtifact();
        if (debugBuild) {
            Collection<File> generatedSourceFolders = mainArtifact.getGeneratedSourceFolders();
            for (File src : generatedSourceFolders) {
                this.project.getSources().add(src);
            }
            Collection<File> generatedResourceFolders = mainArtifact.getGeneratedResourceFolders();
            for (File src : generatedResourceFolders) {
                this.project.getResources().add(src);
            }
        }
        Dependencies compileDependencies = mainArtifact.getDependencies();
        Collection<AndroidLibrary> libraries = compileDependencies.getLibraries();
        for (AndroidLibrary androidLibrary : libraries) {
            String project = androidLibrary.getProject();
            if (nonNull(project) && !androidLibrary.isProvided()) {
                if (project.startsWith(":")) {
                    project = project.substring(1);
                }
                if (this.project.allModules.containsKey(project)) {
                    File root = this.project.allModules.get(project);
                    final ProjectDependency projectDependency = new ProjectDependency(project, "COMPILE", "1.0.0", root, ProjectDependency.Type.PROJECT);
                    dependencies.add(projectDependency);
                }
            }
            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);
        }
        parseExtraAndroidArtifacts(dependencies, variant);
        parseExtraJavaArtifacts(dependencies, variant);
    }
    return dependencies;
}
Also used : ProjectDependency(meghanada.project.ProjectDependency) AndroidArtifact(com.android.builder.model.AndroidArtifact) Variant(com.android.builder.model.Variant) JavaLibrary(com.android.builder.model.JavaLibrary) AndroidLibrary(com.android.builder.model.AndroidLibrary) Dependencies(com.android.builder.model.Dependencies) File(java.io.File) HashSet(java.util.HashSet)

Example 2 with Dependencies

use of com.android.builder.model.Dependencies in project meghanada-server by mopemope.

the class AndroidSupport method parseExtraJavaArtifacts.

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

Example 3 with Dependencies

use of com.android.builder.model.Dependencies in project meghanada-server by mopemope.

the class AndroidSupport method parseExtraAndroidArtifacts.

private void parseExtraAndroidArtifacts(Set<ProjectDependency> dependencies, Variant variant) {
    String buildType = variant.getBuildType();
    boolean debugBuild = buildType.equals(DEBUG_BUILD);
    Collection<AndroidArtifact> extraAndroidArtifacts = variant.getExtraAndroidArtifacts();
    for (AndroidArtifact androidArtifact : extraAndroidArtifacts) {
        String name = androidArtifact.getName();
        boolean isTest = name.contains(TEST_SUFFIX);
        if (debugBuild) {
            Collection<File> generatedSourceFolders = androidArtifact.getGeneratedSourceFolders();
            for (File src : generatedSourceFolders) {
                if (isTest) {
                    this.project.getTestSources().add(src);
                } else {
                    this.project.getSources().add(src);
                }
            }
            Collection<File> generatedResourceFolders = androidArtifact.getGeneratedResourceFolders();
            for (File src : generatedResourceFolders) {
                if (isTest) {
                    this.project.getTestResources().add(src);
                } else {
                    this.project.getResources().add(src);
                }
            }
        }
        Dependencies compileDependencies = androidArtifact.getDependencies();
        // getLibraries
        Collection<AndroidLibrary> libraries = compileDependencies.getLibraries();
        for (AndroidLibrary androidLibrary : libraries) {
            Collection<File> localJars = androidLibrary.getLocalJars();
            if (localJars.isEmpty()) {
                File jar = androidLibrary.getJarFile();
                addDependencies(dependencies, jar);
            } else {
                for (File jar : localJars) {
                    addDependencies(dependencies, jar);
                }
            }
        }
        // getJavaLibraries
        Collection<JavaLibrary> javaLibraries = compileDependencies.getJavaLibraries();
        for (JavaLibrary javaLibrary : javaLibraries) {
            File file = javaLibrary.getJarFile();
            addDependencies(dependencies, file);
        }
    }
}
Also used : JavaLibrary(com.android.builder.model.JavaLibrary) AndroidLibrary(com.android.builder.model.AndroidLibrary) Dependencies(com.android.builder.model.Dependencies) AndroidArtifact(com.android.builder.model.AndroidArtifact) File(java.io.File)

Aggregations

AndroidLibrary (com.android.builder.model.AndroidLibrary)3 Dependencies (com.android.builder.model.Dependencies)3 JavaLibrary (com.android.builder.model.JavaLibrary)3 File (java.io.File)3 AndroidArtifact (com.android.builder.model.AndroidArtifact)2 JavaArtifact (com.android.builder.model.JavaArtifact)1 Variant (com.android.builder.model.Variant)1 HashSet (java.util.HashSet)1 ProjectDependency (meghanada.project.ProjectDependency)1