Search in sources :

Example 16 with ConventionMapping

use of org.gradle.api.internal.ConventionMapping 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 17 with ConventionMapping

use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.

the class EclipsePlugin method configureEclipseProject.

private void configureEclipseProject(final Project project, final EclipseModel model) {
    maybeAddTask(project, this, ECLIPSE_PROJECT_TASK_NAME, GenerateEclipseProject.class, new Action<GenerateEclipseProject>() {

        @Override
        public void execute(GenerateEclipseProject task) {
            final EclipseProject projectModel = task.getProjectModel();
            //task properties:
            task.setDescription("Generates the Eclipse project file.");
            task.setInputFile(project.file(".project"));
            task.setOutputFile(project.file(".project"));
            //model:
            model.setProject(projectModel);
            projectModel.setName(project.getName());
            final ConventionMapping convention = ((IConventionAware) projectModel).getConventionMapping();
            convention.map("comment", new Callable<String>() {

                @Override
                public String call() {
                    return project.getDescription();
                }
            });
            project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {

                @Override
                public void execute(JavaBasePlugin javaBasePlugin) {
                    if (!project.getPlugins().hasPlugin(EarPlugin.class)) {
                        projectModel.buildCommand("org.eclipse.jdt.core.javabuilder");
                    }
                    projectModel.natures("org.eclipse.jdt.core.javanature");
                    convention.map("linkedResources", new Callable<Set<Link>>() {

                        @Override
                        public Set<Link> call() {
                            return new LinkedResourcesCreator().links(project);
                        }
                    });
                }
            });
            project.getPlugins().withType(GroovyBasePlugin.class, new Action<GroovyBasePlugin>() {

                @Override
                public void execute(GroovyBasePlugin groovyBasePlugin) {
                    projectModel.getNatures().add(projectModel.getNatures().indexOf("org.eclipse.jdt.core.javanature"), "org.eclipse.jdt.groovy.core.groovyNature");
                }
            });
            project.getPlugins().withType(ScalaBasePlugin.class, new Action<ScalaBasePlugin>() {

                @Override
                public void execute(ScalaBasePlugin scalaBasePlugin) {
                    projectModel.getBuildCommands().set(Iterables.indexOf(projectModel.getBuildCommands(), new Predicate<BuildCommand>() {

                        @Override
                        public boolean apply(BuildCommand buildCommand) {
                            return buildCommand.getName().equals("org.eclipse.jdt.core.javabuilder");
                        }
                    }), new BuildCommand("org.scala-ide.sdt.core.scalabuilder"));
                    projectModel.getNatures().add(projectModel.getNatures().indexOf("org.eclipse.jdt.core.javanature"), "org.scala-ide.sdt.core.scalanature");
                }
            });
        }
    });
}
Also used : EclipseProject(org.gradle.plugins.ide.eclipse.model.EclipseProject) Action(org.gradle.api.Action) Set(java.util.Set) ScalaBasePlugin(org.gradle.api.plugins.scala.ScalaBasePlugin) ConventionMapping(org.gradle.api.internal.ConventionMapping) Callable(java.util.concurrent.Callable) Predicate(com.google.common.base.Predicate) LinkedResourcesCreator(org.gradle.plugins.ide.eclipse.internal.LinkedResourcesCreator) GroovyBasePlugin(org.gradle.api.plugins.GroovyBasePlugin) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) BuildCommand(org.gradle.plugins.ide.eclipse.model.BuildCommand) EarPlugin(org.gradle.plugins.ear.EarPlugin)

Example 18 with ConventionMapping

use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.

the class PmdPlugin method configureTaskConventionMapping.

private void configureTaskConventionMapping(Configuration configuration, Pmd task) {
    ConventionMapping taskMapping = task.getConventionMapping();
    taskMapping.map("pmdClasspath", Callables.returning(configuration));
    taskMapping.map("ruleSets", new Callable<List<String>>() {

        @Override
        public List<String> call() {
            return extension.getRuleSets();
        }
    });
    taskMapping.map("ruleSetConfig", new Callable<TextResource>() {

        @Override
        public TextResource call() {
            return extension.getRuleSetConfig();
        }
    });
    taskMapping.map("ruleSetFiles", new Callable<FileCollection>() {

        @Override
        public FileCollection call() {
            return extension.getRuleSetFiles();
        }
    });
    taskMapping.map("ignoreFailures", new Callable<Boolean>() {

        @Override
        public Boolean call() {
            return extension.isIgnoreFailures();
        }
    });
    taskMapping.map("rulePriority", new Callable<Integer>() {

        @Override
        public Integer call() {
            return extension.getRulePriority();
        }
    });
    taskMapping.map("consoleOutput", new Callable<Boolean>() {

        @Override
        public Boolean call() {
            return extension.isConsoleOutput();
        }
    });
    taskMapping.map("targetJdk", new Callable<TargetJdk>() {

        @Override
        public TargetJdk call() {
            return extension.getTargetJdk();
        }
    });
}
Also used : TextResource(org.gradle.api.resources.TextResource) FileCollection(org.gradle.api.file.FileCollection) ConventionMapping(org.gradle.api.internal.ConventionMapping) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with ConventionMapping

use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.

the class EclipsePlugin method configureEclipseJdt.

private void configureEclipseJdt(final Project project, final EclipseModel model) {
    final EclipsePlugin eclipsePlugin = this;
    project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {

        @Override
        public void execute(JavaBasePlugin javaBasePlugin) {
            maybeAddTask(project, eclipsePlugin, ECLIPSE_JDT_TASK_NAME, GenerateEclipseJdt.class, new Action<GenerateEclipseJdt>() {

                @Override
                public void execute(GenerateEclipseJdt task) {
                    // task properties:
                    task.setDescription("Generates the Eclipse JDT settings file.");
                    task.setOutputFile(project.file(".settings/org.eclipse.jdt.core.prefs"));
                    task.setInputFile(project.file(".settings/org.eclipse.jdt.core.prefs"));
                    // model properties:
                    EclipseJdt jdt = task.getJdt();
                    model.setJdt(jdt);
                    ConventionMapping conventionMapping = ((IConventionAware) jdt).getConventionMapping();
                    conventionMapping.map("sourceCompatibility", new Callable<JavaVersion>() {

                        @Override
                        public JavaVersion call() {
                            return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceCompatibility();
                        }
                    });
                    conventionMapping.map("targetCompatibility", new Callable<JavaVersion>() {

                        @Override
                        public JavaVersion call() {
                            return project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility();
                        }
                    });
                    conventionMapping.map("javaRuntimeName", new Callable<String>() {

                        @Override
                        public String call() {
                            return eclipseJavaRuntimeNameFor(project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility());
                        }
                    });
                }
            });
        }
    });
}
Also used : EclipseJdt(org.gradle.plugins.ide.eclipse.model.EclipseJdt) Action(org.gradle.api.Action) JavaVersion(org.gradle.api.JavaVersion) ConventionMapping(org.gradle.api.internal.ConventionMapping) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) IConventionAware(org.gradle.api.internal.IConventionAware)

Example 20 with ConventionMapping

use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.

the class EclipseWtpPlugin method configureEclipseWtpComponent.

private void configureEclipseWtpComponent(final Project project, final EclipseModel model) {
    maybeAddTask(project, this, ECLIPSE_WTP_COMPONENT_TASK_NAME, GenerateEclipseWtpComponent.class, new Action<GenerateEclipseWtpComponent>() {

        @Override
        public void execute(final GenerateEclipseWtpComponent task) {
            // task properties:
            task.setDescription("Generates the Eclipse WTP component settings file.");
            task.setInputFile(project.file(".settings/org.eclipse.wst.common.component"));
            task.setOutputFile(project.file(".settings/org.eclipse.wst.common.component"));
            // model properties:
            model.getWtp().setComponent(task.getComponent());
            ((IConventionAware) task.getComponent()).getConventionMapping().map("deployName", new Callable<String>() {

                @Override
                public String call() throws Exception {
                    return model.getProject().getName();
                }
            });
            final Set<Configuration> libConfigurations = task.getComponent().getLibConfigurations();
            final Set<Configuration> rootConfigurations = task.getComponent().getRootConfigurations();
            final Set<Configuration> minusConfigurations = task.getComponent().getMinusConfigurations();
            project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {

                @Override
                public void execute(JavaPlugin javaPlugin) {
                    if (hasWarOrEarPlugin(project)) {
                        return;
                    }
                    libConfigurations.add(project.getConfigurations().getByName("runtime"));
                    task.getComponent().setClassesDeployPath("/");
                    ((IConventionAware) task.getComponent()).getConventionMapping().map("libDeployPath", new Callable<String>() {

                        @Override
                        public String call() throws Exception {
                            return "../";
                        }
                    });
                    ((IConventionAware) task.getComponent()).getConventionMapping().map("sourceDirs", new Callable<Set<File>>() {

                        @Override
                        public Set<File> call() throws Exception {
                            return getMainSourceDirs(project);
                        }
                    });
                }
            });
            project.getPlugins().withType(WarPlugin.class, new Action<WarPlugin>() {

                @Override
                public void execute(WarPlugin warPlugin) {
                    libConfigurations.add(project.getConfigurations().getByName("runtime"));
                    minusConfigurations.add(project.getConfigurations().getByName("providedRuntime"));
                    task.getComponent().setClassesDeployPath("/WEB-INF/classes");
                    ConventionMapping convention = ((IConventionAware) task.getComponent()).getConventionMapping();
                    convention.map("libDeployPath", new Callable<String>() {

                        @Override
                        public String call() throws Exception {
                            return "/WEB-INF/lib";
                        }
                    });
                    convention.map("contextPath", new Callable<String>() {

                        @Override
                        public String call() throws Exception {
                            return ((War) project.getTasks().getByName("war")).getBaseName();
                        }
                    });
                    convention.map("resources", new Callable<List<WbResource>>() {

                        @Override
                        public List<WbResource> call() throws Exception {
                            return Lists.newArrayList(new WbResource("/", project.getConvention().getPlugin(WarPluginConvention.class).getWebAppDirName()));
                        }
                    });
                    convention.map("sourceDirs", new Callable<Set<File>>() {

                        @Override
                        public Set<File> call() throws Exception {
                            return getMainSourceDirs(project);
                        }
                    });
                }
            });
            project.getPlugins().withType(EarPlugin.class, new Action<EarPlugin>() {

                @Override
                public void execute(EarPlugin earPlugin) {
                    rootConfigurations.clear();
                    rootConfigurations.add(project.getConfigurations().getByName("deploy"));
                    libConfigurations.clear();
                    libConfigurations.add(project.getConfigurations().getByName("earlib"));
                    task.getComponent().setClassesDeployPath("/");
                    final ConventionMapping convention = ((IConventionAware) task.getComponent()).getConventionMapping();
                    convention.map("libDeployPath", new Callable<String>() {

                        @Override
                        public String call() throws Exception {
                            String deployPath = ((Ear) project.getTasks().findByName(EarPlugin.EAR_TASK_NAME)).getLibDirName();
                            if (!deployPath.startsWith("/")) {
                                deployPath = "/" + deployPath;
                            }
                            return deployPath;
                        }
                    });
                    convention.map("sourceDirs", new Callable<Set<File>>() {

                        @Override
                        public Set<File> call() throws Exception {
                            return project.files(project.getConvention().getPlugin(EarPluginConvention.class).getAppDirName()).getFiles();
                        }
                    });
                    project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {

                        @Override
                        public void execute(JavaPlugin javaPlugin) {
                            convention.map("sourceDirs", new Callable<Set<File>>() {

                                @Override
                                public Set<File> call() throws Exception {
                                    return getMainSourceDirs(project);
                                }
                            });
                        }
                    });
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) Set(java.util.Set) JavaPlugin(org.gradle.api.plugins.JavaPlugin) ConventionMapping(org.gradle.api.internal.ConventionMapping) Callable(java.util.concurrent.Callable) WbResource(org.gradle.plugins.ide.eclipse.model.WbResource) List(java.util.List) IConventionAware(org.gradle.api.internal.IConventionAware) WarPlugin(org.gradle.api.plugins.WarPlugin) File(java.io.File) EarPlugin(org.gradle.plugins.ear.EarPlugin)

Aggregations

ConventionMapping (org.gradle.api.internal.ConventionMapping)27 IConventionAware (org.gradle.api.internal.IConventionAware)11 Callable (java.util.concurrent.Callable)10 File (java.io.File)9 Set (java.util.Set)6 FileCollection (org.gradle.api.file.FileCollection)6 Action (org.gradle.api.Action)5 Configuration (org.gradle.api.artifacts.Configuration)5 JavaVersion (org.gradle.api.JavaVersion)4 DslObject (org.gradle.api.internal.plugins.DslObject)4 JavaBasePlugin (org.gradle.api.plugins.JavaBasePlugin)4 IdeaModule (org.gradle.plugins.ide.idea.model.IdeaModule)4 JavaScriptExtension (org.gradle.plugins.javascript.base.JavaScriptExtension)4 Predicate (com.google.common.base.Predicate)3 List (java.util.List)3 TextResource (org.gradle.api.resources.TextResource)3 EarPlugin (org.gradle.plugins.ear.EarPlugin)3 IdeaLanguageLevel (org.gradle.plugins.ide.idea.model.IdeaLanguageLevel)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2