Search in sources :

Example 1 with PathFactory

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

the class IdeaPlugin method configureIdeaModule.

private void configureIdeaModule(final Project project) {
    final GenerateIdeaModule task = project.getTasks().create("ideaModule", GenerateIdeaModule.class);
    task.setDescription("Generates IDEA module files (IML)");
    IdeaModuleIml iml = new IdeaModuleIml(task.getXmlTransformer(), project.getProjectDir());
    final IdeaModule module = instantiator.newInstance(IdeaModule.class, project, iml);
    task.setModule(module);
    ideaModel.setModule(module);
    ConventionMapping conventionMapping = ((IConventionAware) module).getConventionMapping();
    conventionMapping.map("sourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() throws Exception {
            return Sets.newHashSet();
        }
    });
    conventionMapping.map("name", new Callable<String>() {

        @Override
        public String call() throws Exception {
            return project.getName();
        }
    });
    conventionMapping.map("contentRoot", new Callable<File>() {

        @Override
        public File call() throws Exception {
            return project.getProjectDir();
        }
    });
    conventionMapping.map("testSourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() throws Exception {
            return Sets.newHashSet();
        }
    });
    conventionMapping.map("excludeDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() throws Exception {
            return Sets.newHashSet(project.getBuildDir(), project.file(".gradle"));
        }
    });
    conventionMapping.map("pathFactory", new Callable<PathFactory>() {

        @Override
        public PathFactory call() throws Exception {
            final PathFactory factory = new PathFactory();
            factory.addPathVariable("MODULE_DIR", task.getOutputFile().getParentFile());
            for (Map.Entry<String, File> entry : module.getPathVariables().entrySet()) {
                factory.addPathVariable(entry.getKey(), entry.getValue());
            }
            return factory;
        }
    });
    addWorker(task);
}
Also used : Set(java.util.Set) PathFactory(org.gradle.plugins.ide.idea.model.PathFactory) ConventionMapping(org.gradle.api.internal.ConventionMapping) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) IdeaModuleIml(org.gradle.plugins.ide.idea.model.IdeaModuleIml) IConventionAware(org.gradle.api.internal.IConventionAware) File(java.io.File)

Example 2 with PathFactory

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

the class IdeaPlugin method configureIdeaModule.

private void configureIdeaModule(final ProjectInternal project) {
    IdeaModuleIml iml = new IdeaModuleIml(new XmlTransformer(), project.getProjectDir());
    final IdeaModule module = instantiator.newInstance(IdeaModule.class, project, iml);
    final TaskProvider<GenerateIdeaModule> task = project.getTasks().register(IDEA_MODULE_TASK_NAME, GenerateIdeaModule.class, module);
    task.configure(new Action<GenerateIdeaModule>() {

        @Override
        public void execute(GenerateIdeaModule task) {
            task.setDescription("Generates IDEA module files (IML)");
        }
    });
    ideaModel.setModule(module);
    final String defaultModuleName = uniqueProjectNameProvider.getUniqueName(project);
    module.setName(defaultModuleName);
    ConventionMapping conventionMapping = ((IConventionAware) module).getConventionMapping();
    Set<File> sourceDirs = Sets.newLinkedHashSet();
    conventionMapping.map("sourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() {
            return sourceDirs;
        }
    });
    conventionMapping.map("contentRoot", new Callable<File>() {

        @Override
        public File call() {
            return project.getProjectDir();
        }
    });
    Set<File> testSourceDirs = Sets.newLinkedHashSet();
    conventionMapping.map("testSourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() {
            return testSourceDirs;
        }
    });
    Set<File> resourceDirs = Sets.newLinkedHashSet();
    conventionMapping.map("resourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() throws Exception {
            return resourceDirs;
        }
    });
    Set<File> testResourceDirs = Sets.newLinkedHashSet();
    conventionMapping.map("testResourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() throws Exception {
            return testResourceDirs;
        }
    });
    Set<File> excludeDirs = Sets.newLinkedHashSet();
    conventionMapping.map("excludeDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() {
            excludeDirs.add(project.file(".gradle"));
            excludeDirs.add(project.getBuildDir());
            return excludeDirs;
        }
    });
    conventionMapping.map("pathFactory", new Callable<PathFactory>() {

        @Override
        public PathFactory call() {
            final PathFactory factory = new PathFactory();
            factory.addPathVariable("MODULE_DIR", task.get().getOutputFile().getParentFile());
            for (Map.Entry<String, File> entry : module.getPathVariables().entrySet()) {
                factory.addPathVariable(entry.getKey(), entry.getValue());
            }
            return factory;
        }
    });
    artifactRegistry.registerIdeProject(new IdeaModuleMetadata(module, task));
    addWorker(task, IDEA_MODULE_TASK_NAME);
}
Also used : Set(java.util.Set) IdeaModuleMetadata(org.gradle.plugins.ide.idea.internal.IdeaModuleMetadata) PathFactory(org.gradle.plugins.ide.idea.model.PathFactory) ConventionMapping(org.gradle.api.internal.ConventionMapping) XmlTransformer(org.gradle.internal.xml.XmlTransformer) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) IdeaModuleIml(org.gradle.plugins.ide.idea.model.IdeaModuleIml) IConventionAware(org.gradle.api.internal.IConventionAware) File(java.io.File)

Example 3 with PathFactory

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

File (java.io.File)3 ConventionMapping (org.gradle.api.internal.ConventionMapping)3 IConventionAware (org.gradle.api.internal.IConventionAware)3 IdeaModule (org.gradle.plugins.ide.idea.model.IdeaModule)3 PathFactory (org.gradle.plugins.ide.idea.model.PathFactory)3 Set (java.util.Set)2 XmlTransformer (org.gradle.internal.xml.XmlTransformer)2 IdeaModuleIml (org.gradle.plugins.ide.idea.model.IdeaModuleIml)2 Predicate (com.google.common.base.Predicate)1 List (java.util.List)1 JavaVersion (org.gradle.api.JavaVersion)1 Project (org.gradle.api.Project)1 XmlFileContentMerger (org.gradle.plugins.ide.api.XmlFileContentMerger)1 IdeaModuleMetadata (org.gradle.plugins.ide.idea.internal.IdeaModuleMetadata)1 IdeaLanguageLevel (org.gradle.plugins.ide.idea.model.IdeaLanguageLevel)1 IdeaProject (org.gradle.plugins.ide.idea.model.IdeaProject)1