Search in sources :

Example 1 with PropertiesTransformer

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

the class EclipsePlugin method configureEclipseJdt.

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

        @Override
        public void execute(JavaBasePlugin javaBasePlugin) {
            model.setJdt(project.getObjects().newInstance(EclipseJdt.class, new PropertiesFileContentMerger(new PropertiesTransformer())));
            final TaskProvider<GenerateEclipseJdt> task = project.getTasks().register(ECLIPSE_JDT_TASK_NAME, GenerateEclipseJdt.class, model.getJdt());
            task.configure(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"));
                }
            });
            addWorker(task, ECLIPSE_JDT_TASK_NAME);
            // model properties:
            ConventionMapping conventionMapping = ((IConventionAware) model.getJdt()).getConventionMapping();
            conventionMapping.map("sourceCompatibility", new Callable<JavaVersion>() {

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

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

                @Override
                public String call() {
                    return eclipseJavaRuntimeNameFor(project.getExtensions().getByType(JavaPluginExtension.class).getTargetCompatibility());
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) PropertiesFileContentMerger(org.gradle.plugins.ide.api.PropertiesFileContentMerger) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) ConventionMapping(org.gradle.api.internal.ConventionMapping) PropertiesTransformer(org.gradle.api.internal.PropertiesTransformer) TaskProvider(org.gradle.api.tasks.TaskProvider) Callable(java.util.concurrent.Callable)

Aggregations

Callable (java.util.concurrent.Callable)1 Action (org.gradle.api.Action)1 ConventionMapping (org.gradle.api.internal.ConventionMapping)1 PropertiesTransformer (org.gradle.api.internal.PropertiesTransformer)1 JavaBasePlugin (org.gradle.api.plugins.JavaBasePlugin)1 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)1 TaskProvider (org.gradle.api.tasks.TaskProvider)1 PropertiesFileContentMerger (org.gradle.plugins.ide.api.PropertiesFileContentMerger)1