Search in sources :

Example 1 with ClasspathEntryModelImpl

use of org.jetbrains.plugins.gradle.tooling.internal.ClasspathEntryModelImpl in project intellij-community by JetBrains.

the class ModelBuildScriptClasspathBuilderImpl method buildAll.

@Nullable
@Override
public Object buildAll(final String modelName, final Project project) {
    BuildScriptClasspathModelImpl buildScriptClasspath = cache.get(project.getPath());
    if (buildScriptClasspath != null)
        return buildScriptClasspath;
    if (mySourceSetFinder == null)
        mySourceSetFinder = new SourceSetCachedFinder(project);
    buildScriptClasspath = new BuildScriptClasspathModelImpl();
    final File gradleHomeDir = project.getGradle().getGradleHomeDir();
    buildScriptClasspath.setGradleHomeDir(gradleHomeDir);
    buildScriptClasspath.setGradleVersion(GradleVersion.current().getVersion());
    boolean downloadJavadoc = false;
    boolean downloadSources = true;
    final IdeaPlugin ideaPlugin = project.getPlugins().findPlugin(IdeaPlugin.class);
    if (ideaPlugin != null) {
        final IdeaModule ideaModule = ideaPlugin.getModel().getModule();
        downloadJavadoc = ideaModule.isDownloadJavadoc();
        downloadSources = ideaModule.isDownloadSources();
    }
    Project parent = project.getParent();
    if (parent != null) {
        BuildScriptClasspathModelImpl parentBuildScriptClasspath = (BuildScriptClasspathModelImpl) buildAll(modelName, parent);
        if (parentBuildScriptClasspath != null) {
            for (ClasspathEntryModel classpathEntryModel : parentBuildScriptClasspath.getClasspath()) {
                buildScriptClasspath.add(classpathEntryModel);
            }
        }
    }
    Configuration classpathConfiguration = project.getBuildscript().getConfigurations().findByName(CLASSPATH_CONFIGURATION_NAME);
    if (classpathConfiguration == null)
        return null;
    Collection<ExternalDependency> dependencies = new DependencyResolverImpl(project, false, downloadJavadoc, downloadSources, mySourceSetFinder).resolveDependencies(classpathConfiguration);
    for (ExternalDependency dependency : new DependencyTraverser(dependencies)) {
        if (dependency instanceof ExternalLibraryDependency) {
            final ExternalLibraryDependency libraryDep = (ExternalLibraryDependency) dependency;
            buildScriptClasspath.add(new ClasspathEntryModelImpl(pathSet(libraryDep.getFile()), pathSet(libraryDep.getSource()), pathSet(libraryDep.getJavadoc())));
        }
        if (dependency instanceof ExternalMultiLibraryDependency) {
            ExternalMultiLibraryDependency multiLibraryDependency = (ExternalMultiLibraryDependency) dependency;
            buildScriptClasspath.add(new ClasspathEntryModelImpl(pathSet(multiLibraryDependency.getFiles()), pathSet(multiLibraryDependency.getSources()), pathSet(multiLibraryDependency.getJavadoc())));
        }
        if (dependency instanceof FileCollectionDependency) {
            FileCollectionDependency fileCollectionDependency = (FileCollectionDependency) dependency;
            buildScriptClasspath.add(new ClasspathEntryModelImpl(pathSet(fileCollectionDependency.getFiles()), new HashSet<String>(), new HashSet<String>()));
        }
    }
    cache.put(project.getPath(), buildScriptClasspath);
    return buildScriptClasspath;
}
Also used : BuildScriptClasspathModelImpl(org.jetbrains.plugins.gradle.tooling.internal.BuildScriptClasspathModelImpl) Configuration(org.gradle.api.artifacts.Configuration) IdeaPlugin(org.gradle.plugins.ide.idea.IdeaPlugin) SourceSetCachedFinder(org.jetbrains.plugins.gradle.tooling.util.SourceSetCachedFinder) DependencyTraverser(org.jetbrains.plugins.gradle.tooling.util.DependencyTraverser) ClasspathEntryModelImpl(org.jetbrains.plugins.gradle.tooling.internal.ClasspathEntryModelImpl) Project(org.gradle.api.Project) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) DependencyResolverImpl(org.jetbrains.plugins.gradle.tooling.util.DependencyResolverImpl) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

File (java.io.File)1 Project (org.gradle.api.Project)1 Configuration (org.gradle.api.artifacts.Configuration)1 IdeaPlugin (org.gradle.plugins.ide.idea.IdeaPlugin)1 IdeaModule (org.gradle.plugins.ide.idea.model.IdeaModule)1 Nullable (org.jetbrains.annotations.Nullable)1 BuildScriptClasspathModelImpl (org.jetbrains.plugins.gradle.tooling.internal.BuildScriptClasspathModelImpl)1 ClasspathEntryModelImpl (org.jetbrains.plugins.gradle.tooling.internal.ClasspathEntryModelImpl)1 DependencyResolverImpl (org.jetbrains.plugins.gradle.tooling.util.DependencyResolverImpl)1 DependencyTraverser (org.jetbrains.plugins.gradle.tooling.util.DependencyTraverser)1 SourceSetCachedFinder (org.jetbrains.plugins.gradle.tooling.util.SourceSetCachedFinder)1