Search in sources :

Example 1 with IdeaPlugin

use of org.gradle.plugins.ide.idea.IdeaPlugin 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)

Example 2 with IdeaPlugin

use of org.gradle.plugins.ide.idea.IdeaPlugin in project intellij-community by JetBrains.

the class ModuleExtendedModelBuilderImpl method enrichDataFromIdeaPlugin.

private static void enrichDataFromIdeaPlugin(Project project, Set<File> excludeDirectories, Set<String> javaDirectories, Set<String> testDirectories, Set<String> ideaGeneratedDirectories) {
    IdeaPlugin ideaPlugin = project.getPlugins().findPlugin(IdeaPlugin.class);
    if (ideaPlugin == null)
        return;
    IdeaModel ideaModel = ideaPlugin.getModel();
    if (ideaModel == null || ideaModel.getModule() == null)
        return;
    for (File excludeDir : ideaModel.getModule().getExcludeDirs()) {
        excludeDirectories.add(excludeDir);
    }
    for (File file : ideaModel.getModule().getSourceDirs()) {
        javaDirectories.add(file.getPath());
    }
    for (File file : ideaModel.getModule().getTestSourceDirs()) {
        testDirectories.add(file.getPath());
    }
    if (GradleVersion.current().compareTo(GradleVersion.version("2.2")) >= 0) {
        for (File file : ideaModel.getModule().getGeneratedSourceDirs()) {
            ideaGeneratedDirectories.add(file.getPath());
        }
    }
}
Also used : IdeaPlugin(org.gradle.plugins.ide.idea.IdeaPlugin) IdeaModel(org.gradle.plugins.ide.idea.model.IdeaModel) File(java.io.File)

Aggregations

File (java.io.File)2 IdeaPlugin (org.gradle.plugins.ide.idea.IdeaPlugin)2 Project (org.gradle.api.Project)1 Configuration (org.gradle.api.artifacts.Configuration)1 IdeaModel (org.gradle.plugins.ide.idea.model.IdeaModel)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