Search in sources :

Example 1 with Project

use of org.gradle.api.Project 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 Project

use of org.gradle.api.Project in project gradle by gradle.

the class ProjectConverter method addSubProjects.

/**
     * Adds all sub projects of the specified GradleProject.
     *
     * @param parentProject the source parent project. Where we get the sub projects from.
     * @param parentProjectView the destination of the sub projects from parentProject.
     */
private void addSubProjects(Project parentProject, ProjectView parentProjectView) {
    Collection<Project> subProjects = parentProject.getChildProjects().values();
    for (Project subProject : subProjects) {
        ProjectView projectView = new ProjectView(parentProjectView, subProject.getName(), subProject.getBuildFile(), subProject.getDescription());
        addTasks(subProject, projectView);
        projectView.sortSubProjectsAndTasks();
        addSubProjects(subProject, projectView);
    }
}
Also used : Project(org.gradle.api.Project)

Example 3 with Project

use of org.gradle.api.Project in project gradle by gradle.

the class IdeaPlugin method setupScopes.

private void setupScopes(GenerateIdeaModule ideaModule) {
    Map<String, Map<String, Collection<Configuration>>> scopes = Maps.newLinkedHashMap();
    for (GeneratedIdeaScope scope : GeneratedIdeaScope.values()) {
        Map<String, Collection<Configuration>> plusMinus = Maps.newLinkedHashMap();
        plusMinus.put(IdeaDependenciesProvider.SCOPE_PLUS, Lists.<Configuration>newArrayList());
        plusMinus.put(IdeaDependenciesProvider.SCOPE_MINUS, Lists.<Configuration>newArrayList());
        scopes.put(scope.name(), plusMinus);
    }
    Project project = ideaModule.getProject();
    ConfigurationContainer configurations = project.getConfigurations();
    Collection<Configuration> provided = scopes.get(GeneratedIdeaScope.PROVIDED.name()).get(IdeaDependenciesProvider.SCOPE_PLUS);
    provided.add(configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME));
    Collection<Configuration> runtime = scopes.get(GeneratedIdeaScope.RUNTIME.name()).get(IdeaDependenciesProvider.SCOPE_PLUS);
    runtime.add(configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
    Collection<Configuration> test = scopes.get(GeneratedIdeaScope.TEST.name()).get(IdeaDependenciesProvider.SCOPE_PLUS);
    test.add(configurations.getByName(JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME));
    test.add(configurations.getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME));
    ideaModule.getModule().setScopes(scopes);
}
Also used : Project(org.gradle.api.Project) IdeaProject(org.gradle.plugins.ide.idea.model.IdeaProject) Configuration(org.gradle.api.artifacts.Configuration) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) Collection(java.util.Collection) FileCollection(org.gradle.api.file.FileCollection) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) GeneratedIdeaScope(org.gradle.plugins.ide.idea.model.internal.GeneratedIdeaScope)

Example 4 with Project

use of org.gradle.api.Project in project gradle by gradle.

the class IdeaPlugin method registerImlArtifacts.

private void registerImlArtifacts() {
    Set<Project> projectsWithIml = Sets.filter(project.getRootProject().getAllprojects(), new Predicate<Project>() {

        @Override
        public boolean apply(Project project) {
            return project.getPlugins().hasPlugin(IdeaPlugin.class);
        }
    });
    for (Project project : projectsWithIml) {
        ProjectLocalComponentProvider projectComponentProvider = ((ProjectInternal) project).getServices().get(ProjectLocalComponentProvider.class);
        ProjectComponentIdentifier projectId = newProjectId(project);
        projectComponentProvider.registerAdditionalArtifact(projectId, createImlArtifact(projectId, project));
    }
}
Also used : Project(org.gradle.api.Project) IdeaProject(org.gradle.plugins.ide.idea.model.IdeaProject) ProjectLocalComponentProvider(org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectLocalComponentProvider) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 5 with Project

use of org.gradle.api.Project in project gradle by gradle.

the class FilterTest method setUp.

protected void setUp() throws Exception {
    JUnit4Mockery context = new JUnit4Mockery();
    Task subsubCompileTask = TestUtility.createTask(context, "compile", "compile description");
    Task subsubLibTask = TestUtility.createTask(context, "lib", "lib description");
    Task subsubDocTask = TestUtility.createTask(context, "doc", "doc description");
    Project subsubProject = TestUtility.createMockProject(context, "mysubsubproject", "filepath3", 2, null, new Task[] { subsubCompileTask, subsubLibTask, subsubDocTask }, null);
    Task subCompileTask1 = TestUtility.createTask(context, "compile", "compile description");
    Task subLibTask1 = TestUtility.createTask(context, "lib", "lib description");
    Task subDocTask1 = TestUtility.createTask(context, "doc", "doc description");
    Project subProject1 = TestUtility.createMockProject(context, "mysubproject1", "filepath2a", 1, new Project[] { subsubProject }, new Task[] { subCompileTask1, subLibTask1, subDocTask1 }, null);
    Task subCompileTask2 = TestUtility.createTask(context, "compile", "compile description");
    Task subLibTask2 = TestUtility.createTask(context, "lib", "lib description");
    Task subDocTask2 = TestUtility.createTask(context, "doc", "doc description");
    Project subProject2 = TestUtility.createMockProject(context, "mysubproject2", "filepath2b", 1, null, new Task[] { subCompileTask2, subLibTask2, subDocTask2 }, null);
    Project rootProject = TestUtility.createMockProject(context, "myrootproject", "filepath1", 0, new Project[] { subProject1, subProject2 }, null, null);
    buildInformation = new BuildInformation(rootProject);
    //now get the converted objects to simplify our matching
    myRootProject = buildInformation.getProjectFromFullPath("myrootproject");
    assertNotNull(myRootProject);
    mySubProject1 = buildInformation.getProjectFromFullPath("myrootproject:mysubproject1");
    assertNotNull(mySubProject1);
    mySubProject1Comple = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:compile");
    assertNotNull(mySubProject1Comple);
    mySubProject1Lib = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:lib");
    assertNotNull(mySubProject1Lib);
    mySubProject1Doc = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:doc");
    assertNotNull(mySubProject1Doc);
    mySubSubProject = buildInformation.getProjectFromFullPath("myrootproject:mysubproject1:mysubsubproject");
    assertNotNull(mySubSubProject);
    mySubSubProjectCompile = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:mysubsubproject:compile");
    assertNotNull(mySubSubProjectCompile);
    mySubSubProjectLib = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:mysubsubproject:lib");
    assertNotNull(mySubSubProjectLib);
    mySubSubProjectDoc = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:mysubsubproject:doc");
    assertNotNull(mySubSubProjectDoc);
    mySubProject2 = buildInformation.getProjectFromFullPath("myrootproject:mysubproject2");
    assertNotNull(mySubProject2);
    mySubProject2Compile = buildInformation.getTaskFromFullPath("myrootproject:mysubproject2:compile");
    assertNotNull(mySubProject2Compile);
    mySubProject2Lib = buildInformation.getTaskFromFullPath("myrootproject:mysubproject2:lib");
    assertNotNull(mySubProject2Lib);
    mySubProject2doc = buildInformation.getTaskFromFullPath("myrootproject:mysubproject2:doc");
    assertNotNull(mySubProject2doc);
}
Also used : Project(org.gradle.api.Project) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Task(org.gradle.api.Task)

Aggregations

Project (org.gradle.api.Project)267 File (java.io.File)97 Task (org.gradle.api.Task)71 Plugin (org.gradle.api.Plugin)69 Configuration (org.gradle.api.artifacts.Configuration)52 List (java.util.List)40 ArrayList (java.util.ArrayList)38 SourceSet (org.gradle.api.tasks.SourceSet)38 TaskProvider (org.gradle.api.tasks.TaskProvider)38 IOException (java.io.IOException)35 Map (java.util.Map)35 Action (org.gradle.api.Action)34 Set (java.util.Set)32 JavaPlugin (org.gradle.api.plugins.JavaPlugin)31 FileCollection (org.gradle.api.file.FileCollection)30 HashMap (java.util.HashMap)28 Provider (org.gradle.api.provider.Provider)27 Collectors (java.util.stream.Collectors)26 ObjectFactory (org.gradle.api.model.ObjectFactory)25 Collections (java.util.Collections)24