Search in sources :

Example 1 with IdeaModuleIml

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

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

Aggregations

File (java.io.File)2 Set (java.util.Set)2 ConventionMapping (org.gradle.api.internal.ConventionMapping)2 IConventionAware (org.gradle.api.internal.IConventionAware)2 IdeaModule (org.gradle.plugins.ide.idea.model.IdeaModule)2 IdeaModuleIml (org.gradle.plugins.ide.idea.model.IdeaModuleIml)2 PathFactory (org.gradle.plugins.ide.idea.model.PathFactory)2 XmlTransformer (org.gradle.internal.xml.XmlTransformer)1 IdeaModuleMetadata (org.gradle.plugins.ide.idea.internal.IdeaModuleMetadata)1