Search in sources :

Example 6 with JavaBasePlugin

use of org.gradle.api.plugins.JavaBasePlugin 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)

Example 7 with JavaBasePlugin

use of org.gradle.api.plugins.JavaBasePlugin in project gradle by gradle.

the class EclipsePlugin method configureEclipseClasspath.

private void configureEclipseClasspath(final Project project, final EclipseModel model) {
    model.setClasspath(project.getObjects().newInstance(EclipseClasspath.class, project));
    ((IConventionAware) model.getClasspath()).getConventionMapping().map("defaultOutputDir", new Callable<File>() {

        @Override
        public File call() {
            return new File(project.getProjectDir(), EclipsePluginConstants.DEFAULT_PROJECT_OUTPUT_PATH);
        }
    });
    model.getClasspath().getTestSourceSets().convention(testSourceSetsConvention);
    model.getClasspath().getTestConfigurations().convention(testConfigurationsConvention);
    project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {

        @Override
        public void execute(JavaBasePlugin javaBasePlugin) {
            final TaskProvider<GenerateEclipseClasspath> task = project.getTasks().register(ECLIPSE_CP_TASK_NAME, GenerateEclipseClasspath.class, model.getClasspath());
            task.configure(new Action<GenerateEclipseClasspath>() {

                @Override
                public void execute(final GenerateEclipseClasspath task) {
                    task.setDescription("Generates the Eclipse classpath file.");
                    task.setInputFile(project.file(".classpath"));
                    task.setOutputFile(project.file(".classpath"));
                }
            });
            addWorker(task, ECLIPSE_CP_TASK_NAME);
            XmlTransformer xmlTransformer = new XmlTransformer();
            xmlTransformer.setIndentation("\t");
            model.getClasspath().setFile(new XmlFileContentMerger(xmlTransformer));
            model.getClasspath().setSourceSets(project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets());
            AfterEvaluateHelper.afterEvaluateOrExecute(project, new Action<Project>() {

                @Override
                public void execute(Project p) {
                    // keep the ordering we had in earlier gradle versions
                    Set<String> containers = Sets.newLinkedHashSet();
                    containers.add("org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/" + model.getJdt().getJavaRuntimeName() + "/");
                    containers.addAll(model.getClasspath().getContainers());
                    model.getClasspath().setContainers(containers);
                }
            });
            configureScalaDependencies(project, model);
            configureJavaClasspath(project, task, model, testSourceSetsConvention, testConfigurationsConvention);
        }
    });
}
Also used : Action(org.gradle.api.Action) EclipseClasspath(org.gradle.plugins.ide.eclipse.model.EclipseClasspath) XmlFileContentMerger(org.gradle.plugins.ide.api.XmlFileContentMerger) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) XmlTransformer(org.gradle.internal.xml.XmlTransformer) EclipseProject(org.gradle.plugins.ide.eclipse.model.EclipseProject) Project(org.gradle.api.Project) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) File(java.io.File) TaskProvider(org.gradle.api.tasks.TaskProvider)

Aggregations

JavaBasePlugin (org.gradle.api.plugins.JavaBasePlugin)7 Callable (java.util.concurrent.Callable)4 Action (org.gradle.api.Action)4 ConventionMapping (org.gradle.api.internal.ConventionMapping)3 GroovyBasePlugin (org.gradle.api.plugins.GroovyBasePlugin)3 EclipseProject (org.gradle.plugins.ide.eclipse.model.EclipseProject)3 File (java.io.File)2 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)2 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)2 ScalaBasePlugin (org.gradle.api.plugins.scala.ScalaBasePlugin)2 SourceSet (org.gradle.api.tasks.SourceSet)2 TaskProvider (org.gradle.api.tasks.TaskProvider)2 LinkedResourcesCreator (org.gradle.plugins.ide.eclipse.internal.LinkedResourcesCreator)2 BuildCommand (org.gradle.plugins.ide.eclipse.model.BuildCommand)2 Predicate (com.google.common.base.Predicate)1 Set (java.util.Set)1 Project (org.gradle.api.Project)1 FileTreeElement (org.gradle.api.file.FileTreeElement)1 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)1 IConventionAware (org.gradle.api.internal.IConventionAware)1