Search in sources :

Example 1 with IdeaLanguageLevel

use of org.gradle.plugins.ide.idea.model.IdeaLanguageLevel in project gradle by gradle.

the class IdeaModelBuilder method appendModule.

private void appendModule(Map<String, DefaultIdeaModule> modules, IdeaModule ideaModule, DefaultIdeaProject ideaProject, DefaultGradleProject rootGradleProject) {
    DefaultIdeaContentRoot contentRoot = new DefaultIdeaContentRoot().setRootDirectory(ideaModule.getContentRoot()).setSourceDirectories(srcDirs(ideaModule.getSourceDirs(), ideaModule.getGeneratedSourceDirs())).setTestDirectories(srcDirs(ideaModule.getTestSourceDirs(), ideaModule.getGeneratedSourceDirs())).setExcludeDirectories(ideaModule.getExcludeDirs());
    Project project = ideaModule.getProject();
    DefaultIdeaModule defaultIdeaModule = new DefaultIdeaModule().setName(ideaModule.getName()).setParent(ideaProject).setGradleProject(rootGradleProject.findByPath(ideaModule.getProject().getPath())).setContentRoots(Collections.singletonList(contentRoot)).setJdkName(ideaModule.getJdkName()).setCompilerOutput(new DefaultIdeaCompilerOutput().setInheritOutputDirs(ideaModule.getInheritOutputDirs() != null ? ideaModule.getInheritOutputDirs() : false).setOutputDir(ideaModule.getOutputDir()).setTestOutputDir(ideaModule.getTestOutputDir()));
    JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin(JavaPluginConvention.class);
    if (javaPluginConvention != null) {
        final IdeaLanguageLevel ideaModuleLanguageLevel = ideaModule.getLanguageLevel();
        JavaVersion moduleSourceLanguageLevel = convertIdeaLanguageLevelToJavaVersion(ideaModuleLanguageLevel);
        JavaVersion moduleTargetBytecodeVersion = ideaModule.getTargetBytecodeVersion();
        defaultIdeaModule.setJavaLanguageSettings(new DefaultIdeaJavaLanguageSettings().setSourceLanguageLevel(moduleSourceLanguageLevel).setTargetBytecodeVersion(moduleTargetBytecodeVersion));
    }
    modules.put(ideaModule.getName(), defaultIdeaModule);
}
Also used : DefaultIdeaContentRoot(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaContentRoot) IdeaProject(org.gradle.plugins.ide.idea.model.IdeaProject) DefaultGradleProject(org.gradle.tooling.internal.gradle.DefaultGradleProject) Project(org.gradle.api.Project) DefaultIdeaProject(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaProject) DefaultIdeaModule(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaModule) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) DefaultIdeaJavaLanguageSettings(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaJavaLanguageSettings) DefaultIdeaLanguageLevel(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaLanguageLevel) IdeaLanguageLevel(org.gradle.plugins.ide.idea.model.IdeaLanguageLevel) JavaVersion(org.gradle.api.JavaVersion) DefaultIdeaCompilerOutput(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaCompilerOutput)

Example 2 with IdeaLanguageLevel

use of org.gradle.plugins.ide.idea.model.IdeaLanguageLevel in project gradle by gradle.

the class IdeaModelBuilder method createModule.

private DefaultIdeaModule createModule(IdeaModule ideaModule, DefaultIdeaProject ideaProject, DefaultGradleProject rootGradleProject) {
    DefaultIdeaContentRoot contentRoot = new DefaultIdeaContentRoot().setRootDirectory(ideaModule.getContentRoot()).setSourceDirectories(srcDirs(ideaModule.getSourceDirs(), ideaModule.getGeneratedSourceDirs())).setTestDirectories(srcDirs(ideaModule.getTestSources().getFiles(), ideaModule.getGeneratedSourceDirs())).setResourceDirectories(srcDirs(ideaModule.getResourceDirs(), ideaModule.getGeneratedSourceDirs())).setTestResourceDirectories(srcDirs(ideaModule.getTestResources().getFiles(), ideaModule.getGeneratedSourceDirs())).setExcludeDirectories(ideaModule.getExcludeDirs());
    Project project = ideaModule.getProject();
    DefaultIdeaModule defaultIdeaModule = new DefaultIdeaModule().setName(ideaModule.getName()).setParent(ideaProject).setGradleProject(rootGradleProject.findByPath(ideaModule.getProject().getPath())).setContentRoots(Collections.singletonList(contentRoot)).setJdkName(ideaModule.getJdkName()).setCompilerOutput(new DefaultIdeaCompilerOutput().setInheritOutputDirs(ideaModule.getInheritOutputDirs() != null ? ideaModule.getInheritOutputDirs() : false).setOutputDir(ideaModule.getOutputDir()).setTestOutputDir(ideaModule.getTestOutputDir()));
    JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class);
    if (javaPluginExtension != null) {
        final IdeaLanguageLevel ideaModuleLanguageLevel = ideaModule.getLanguageLevel();
        JavaVersion moduleSourceLanguageLevel = convertIdeaLanguageLevelToJavaVersion(ideaModuleLanguageLevel);
        JavaVersion moduleTargetBytecodeVersion = ideaModule.getTargetBytecodeVersion();
        defaultIdeaModule.setJavaLanguageSettings(new DefaultIdeaJavaLanguageSettings().setSourceLanguageLevel(moduleSourceLanguageLevel).setTargetBytecodeVersion(moduleTargetBytecodeVersion));
    }
    buildDependencies(defaultIdeaModule, ideaModule);
    return defaultIdeaModule;
}
Also used : DefaultIdeaContentRoot(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaContentRoot) IdeaProject(org.gradle.plugins.ide.idea.model.IdeaProject) Project(org.gradle.api.Project) DefaultIdeaProject(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaProject) DefaultGradleProject(org.gradle.plugins.ide.internal.tooling.model.DefaultGradleProject) DefaultIdeaModule(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaModule) DefaultIdeaJavaLanguageSettings(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaJavaLanguageSettings) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) DefaultIdeaLanguageLevel(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaLanguageLevel) IdeaLanguageLevel(org.gradle.plugins.ide.idea.model.IdeaLanguageLevel) JavaVersion(org.gradle.api.JavaVersion) DefaultIdeaCompilerOutput(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaCompilerOutput)

Example 3 with IdeaLanguageLevel

use of org.gradle.plugins.ide.idea.model.IdeaLanguageLevel in project gradle by gradle.

the class PlayIdeaPlugin method configureIdeaModule.

@Mutate
public void configureIdeaModule(@Path("tasks.ideaModule") GenerateIdeaModule ideaModule, @Path("binaries.playBinary") final PlayApplicationBinarySpec playApplicationBinarySpec, @Path("buildDir") final File buildDir, ConfigurationContainer configurations, final FileResolver fileResolver) {
    IdeaModule module = ideaModule.getModule();
    module.setScopes(buildScopes(configurations));
    ConventionMapping conventionMapping = conventionMappingFor(module);
    conventionMapping.map("sourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() throws Exception {
            // TODO: Assets should probably be a source set too
            Set<File> sourceDirs = Sets.newHashSet(playApplicationBinarySpec.getAssets().getAssetDirs());
            return CollectionUtils.inject(sourceDirs, playApplicationBinarySpec.getInputs(), new Action<CollectionUtils.InjectionStep<Set<File>, LanguageSourceSet>>() {

                @Override
                public void execute(CollectionUtils.InjectionStep<Set<File>, LanguageSourceSet> step) {
                    step.getTarget().addAll(step.getItem().getSource().getSrcDirs());
                }
            });
        }
    });
    conventionMapping.map("testSourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() throws Exception {
            // TODO: This should be modeled as a source set
            return Collections.singleton(fileResolver.resolve("test"));
        }
    });
    conventionMapping.map("singleEntryLibraries", new Callable<Map<String, Iterable<File>>>() {

        @Override
        public Map<String, Iterable<File>> call() throws Exception {
            return ImmutableMap.<String, Iterable<File>>builder().put("COMPILE", Collections.singleton(playApplicationBinarySpec.getClasses().getClassesDir())).put("RUNTIME", playApplicationBinarySpec.getClasses().getResourceDirs()).put("TEST", Collections.singleton(new File(buildDir, "playBinary/testClasses"))).build();
        }
    });
    module.setScalaPlatform(playApplicationBinarySpec.getTargetPlatform().getScalaPlatform());
    conventionMapping.map("targetBytecodeVersion", new Callable<JavaVersion>() {

        @Override
        public JavaVersion call() throws Exception {
            return getTargetJavaVersion(playApplicationBinarySpec);
        }
    });
    conventionMapping.map("languageLevel", new Callable<IdeaLanguageLevel>() {

        @Override
        public IdeaLanguageLevel call() throws Exception {
            return new IdeaLanguageLevel(getTargetJavaVersion(playApplicationBinarySpec));
        }
    });
    ideaModule.dependsOn(playApplicationBinarySpec.getInputs());
    ideaModule.dependsOn(playApplicationBinarySpec.getAssets());
}
Also used : Action(org.gradle.api.Action) LanguageSourceSet(org.gradle.language.base.LanguageSourceSet) Set(java.util.Set) CollectionUtils(org.gradle.util.CollectionUtils) IdeaLanguageLevel(org.gradle.plugins.ide.idea.model.IdeaLanguageLevel) JavaVersion(org.gradle.api.JavaVersion) ConventionMapping(org.gradle.api.internal.ConventionMapping) GenerateIdeaModule(org.gradle.plugins.ide.idea.GenerateIdeaModule) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) LanguageSourceSet(org.gradle.language.base.LanguageSourceSet) File(java.io.File) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Mutate(org.gradle.model.Mutate)

Example 4 with IdeaLanguageLevel

use of org.gradle.plugins.ide.idea.model.IdeaLanguageLevel in project gradle by gradle.

the class IdeaPlugin method configureIdeaModuleForJava.

private void configureIdeaModuleForJava(final Project project) {
    project.getTasks().withType(GenerateIdeaModule.class).configureEach(new Action<GenerateIdeaModule>() {

        @Override
        public void execute(GenerateIdeaModule ideaModule) {
            // Dependencies
            ideaModule.dependsOn(new Callable<FileCollection>() {

                @Override
                public FileCollection call() {
                    SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
                    return sourceSets.getByName("main").getOutput().getDirs().plus(sourceSets.getByName("test").getOutput().getDirs());
                }
            });
        }
    });
    // Defaults
    setupScopes(project);
    // Convention
    ConventionMapping convention = ((IConventionAware) ideaModel.getModule()).getConventionMapping();
    Set<File> sourceDirs = Sets.newLinkedHashSet();
    convention.map("sourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() {
            SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
            sourceDirs.addAll(sourceSets.getByName("main").getAllJava().getSrcDirs());
            return sourceDirs;
        }
    });
    Set<File> resourceDirs = Sets.newLinkedHashSet();
    convention.map("resourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() {
            SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
            resourceDirs.addAll(sourceSets.getByName("main").getResources().getSrcDirs());
            return resourceDirs;
        }
    });
    Map<String, FileCollection> singleEntryLibraries = new LinkedHashMap<String, FileCollection>(2);
    convention.map("singleEntryLibraries", new Callable<Map<String, FileCollection>>() {

        @Override
        public Map<String, FileCollection> call() {
            SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
            singleEntryLibraries.putIfAbsent("RUNTIME", sourceSets.getByName("main").getOutput().getDirs());
            singleEntryLibraries.putIfAbsent("TEST", sourceSets.getByName("test").getOutput().getDirs());
            return singleEntryLibraries;
        }
    });
    convention.map("targetBytecodeVersion", new Callable<JavaVersion>() {

        @Override
        public JavaVersion call() {
            JavaVersion moduleTargetBytecodeLevel = project.getExtensions().getByType(JavaPluginExtension.class).getTargetCompatibility();
            return includeModuleBytecodeLevelOverride(project.getRootProject(), moduleTargetBytecodeLevel) ? moduleTargetBytecodeLevel : null;
        }
    });
    convention.map("languageLevel", new Callable<IdeaLanguageLevel>() {

        @Override
        public IdeaLanguageLevel call() {
            IdeaLanguageLevel moduleLanguageLevel = new IdeaLanguageLevel(project.getExtensions().getByType(JavaPluginExtension.class).getSourceCompatibility());
            return includeModuleLanguageLevelOverride(project.getRootProject(), moduleLanguageLevel) ? moduleLanguageLevel : null;
        }
    });
}
Also used : Set(java.util.Set) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) IdeaLanguageLevel(org.gradle.plugins.ide.idea.model.IdeaLanguageLevel) FileCollection(org.gradle.api.file.FileCollection) JavaVersion(org.gradle.api.JavaVersion) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) ConventionMapping(org.gradle.api.internal.ConventionMapping) Callable(java.util.concurrent.Callable) LinkedHashMap(java.util.LinkedHashMap) IConventionAware(org.gradle.api.internal.IConventionAware) File(java.io.File) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with IdeaLanguageLevel

use of org.gradle.plugins.ide.idea.model.IdeaLanguageLevel in project gradle by gradle.

the class IdeaPlugin method configureIdeaProject.

private void configureIdeaProject(final Project project) {
    if (isRoot()) {
        XmlFileContentMerger ipr = new XmlFileContentMerger(new XmlTransformer());
        final IdeaProject ideaProject = instantiator.newInstance(IdeaProject.class, project, ipr);
        final TaskProvider<GenerateIdeaProject> projectTask = project.getTasks().register(IDEA_PROJECT_TASK_NAME, GenerateIdeaProject.class, ideaProject);
        projectTask.configure(new Action<GenerateIdeaProject>() {

            @Override
            public void execute(GenerateIdeaProject projectTask) {
                projectTask.setDescription("Generates IDEA project file (IPR)");
            }
        });
        ideaModel.setProject(ideaProject);
        ideaProject.setOutputFile(new File(project.getProjectDir(), project.getName() + ".ipr"));
        ConventionMapping conventionMapping = ((IConventionAware) ideaProject).getConventionMapping();
        conventionMapping.map("jdkName", new Callable<String>() {

            @Override
            public String call() {
                return JavaVersion.current().toString();
            }
        });
        conventionMapping.map("languageLevel", new Callable<IdeaLanguageLevel>() {

            @Override
            public IdeaLanguageLevel call() {
                JavaVersion maxSourceCompatibility = getMaxJavaModuleCompatibilityVersionFor(SOURCE_COMPATIBILITY);
                return new IdeaLanguageLevel(maxSourceCompatibility);
            }
        });
        conventionMapping.map("targetBytecodeVersion", new Callable<JavaVersion>() {

            @Override
            public JavaVersion call() {
                return getMaxJavaModuleCompatibilityVersionFor(TARGET_COMPATIBILITY);
            }
        });
        ideaProject.getWildcards().addAll(Arrays.asList("!?*.class", "!?*.scala", "!?*.groovy", "!?*.java"));
        conventionMapping.map("modules", new Callable<List<IdeaModule>>() {

            @Override
            public List<IdeaModule> call() {
                return Lists.newArrayList(Iterables.transform(Sets.filter(project.getRootProject().getAllprojects(), new Predicate<Project>() {

                    @Override
                    public boolean apply(Project p) {
                        return p.getPlugins().hasPlugin(IdeaPlugin.class);
                    }
                }), new Function<Project, IdeaModule>() {

                    @Override
                    public IdeaModule apply(Project p) {
                        return ideaModelFor(p).getModule();
                    }
                }));
            }
        });
        conventionMapping.map("pathFactory", new Callable<PathFactory>() {

            @Override
            public PathFactory call() {
                return new PathFactory().addPathVariable("PROJECT_DIR", projectTask.get().getOutputFile().getParentFile());
            }
        });
        addWorker(projectTask, IDEA_PROJECT_TASK_NAME);
        addWorkspace(ideaProject);
    }
}
Also used : IdeaProject(org.gradle.plugins.ide.idea.model.IdeaProject) PathFactory(org.gradle.plugins.ide.idea.model.PathFactory) XmlFileContentMerger(org.gradle.plugins.ide.api.XmlFileContentMerger) IdeaLanguageLevel(org.gradle.plugins.ide.idea.model.IdeaLanguageLevel) JavaVersion(org.gradle.api.JavaVersion) ConventionMapping(org.gradle.api.internal.ConventionMapping) Predicate(com.google.common.base.Predicate) XmlTransformer(org.gradle.internal.xml.XmlTransformer) Project(org.gradle.api.Project) IdeaProject(org.gradle.plugins.ide.idea.model.IdeaProject) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) List(java.util.List) File(java.io.File) IConventionAware(org.gradle.api.internal.IConventionAware)

Aggregations

JavaVersion (org.gradle.api.JavaVersion)5 IdeaLanguageLevel (org.gradle.plugins.ide.idea.model.IdeaLanguageLevel)5 File (java.io.File)3 Project (org.gradle.api.Project)3 ConventionMapping (org.gradle.api.internal.ConventionMapping)3 IdeaProject (org.gradle.plugins.ide.idea.model.IdeaProject)3 Map (java.util.Map)2 Set (java.util.Set)2 IConventionAware (org.gradle.api.internal.IConventionAware)2 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)2 IdeaModule (org.gradle.plugins.ide.idea.model.IdeaModule)2 DefaultIdeaCompilerOutput (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaCompilerOutput)2 DefaultIdeaContentRoot (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaContentRoot)2 DefaultIdeaJavaLanguageSettings (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaJavaLanguageSettings)2 DefaultIdeaLanguageLevel (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaLanguageLevel)2 DefaultIdeaModule (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaModule)2 DefaultIdeaProject (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaProject)2 Predicate (com.google.common.base.Predicate)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 LinkedHashMap (java.util.LinkedHashMap)1