Search in sources :

Example 6 with IdeaModule

use of org.gradle.plugins.ide.idea.model.IdeaModule 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 7 with IdeaModule

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

the class IdeaPlugin method configureIdeaProject.

private void configureIdeaProject(final Project project) {
    if (isRoot()) {
        final GenerateIdeaProject projectTask = project.getTasks().create("ideaProject", GenerateIdeaProject.class);
        projectTask.setDescription("Generates IDEA project file (IPR)");
        XmlFileContentMerger ipr = new XmlFileContentMerger(projectTask.getXmlTransformer());
        IdeaProject ideaProject = instantiator.newInstance(IdeaProject.class, project, ipr);
        projectTask.setIdeaProject(ideaProject);
        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.getOutputFile().getParentFile());
            }
        });
        addWorker(projectTask);
        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) 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)

Example 8 with IdeaModule

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

the class IdeaScalaConfigurer method resolveScalaCompilerLibraries.

private static Map<String, ProjectLibrary> resolveScalaCompilerLibraries(Collection<Project> scalaProjects, boolean useScalaSdk) {
    Map<String, ProjectLibrary> scalaCompilerLibraries = Maps.newLinkedHashMap();
    for (Project scalaProject : scalaProjects) {
        IdeaModule ideaModule = scalaProject.getExtensions().getByType(IdeaModel.class).getModule();
        Iterable<File> files = getIdeaModuleLibraryDependenciesAsFiles(ideaModule);
        ProjectLibrary library = createScalaSdkLibrary(scalaProject, files, useScalaSdk, ideaModule);
        if (library != null) {
            ProjectLibrary duplicate = Iterables.find(scalaCompilerLibraries.values(), Predicates.equalTo(library), null);
            scalaCompilerLibraries.put(scalaProject.getPath(), duplicate == null ? library : duplicate);
        }
    }
    return scalaCompilerLibraries;
}
Also used : Project(org.gradle.api.Project) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) IdeaModel(org.gradle.plugins.ide.idea.model.IdeaModel) ProjectLibrary(org.gradle.plugins.ide.idea.model.ProjectLibrary) File(java.io.File)

Aggregations

IdeaModule (org.gradle.plugins.ide.idea.model.IdeaModule)8 File (java.io.File)6 ConventionMapping (org.gradle.api.internal.ConventionMapping)4 Set (java.util.Set)3 JavaVersion (org.gradle.api.JavaVersion)3 Project (org.gradle.api.Project)3 IConventionAware (org.gradle.api.internal.IConventionAware)3 PathFactory (org.gradle.plugins.ide.idea.model.PathFactory)3 IdeaModuleMetadata (org.gradle.plugins.ide.idea.internal.IdeaModuleMetadata)2 IdeaLanguageLevel (org.gradle.plugins.ide.idea.model.IdeaLanguageLevel)2 IdeaModel (org.gradle.plugins.ide.idea.model.IdeaModel)2 IdeaModuleIml (org.gradle.plugins.ide.idea.model.IdeaModuleIml)2 IdeaProject (org.gradle.plugins.ide.idea.model.IdeaProject)2 Predicate (com.google.common.base.Predicate)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Action (org.gradle.api.Action)1 Configuration (org.gradle.api.artifacts.Configuration)1