Search in sources :

Example 1 with JavaBasePlugin

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

the class TemplateCompilerPlugin method apply.

@Override
public void apply(ProjectInternal project) {
    project.getExtensions().create("compileTemplateSetting", TemplateCompileOptions.class);
    project.getPluginManager().apply(JavaBasePlugin.class);
    JavaBasePlugin javaBasePlugin = project.getPlugins().getPlugin(JavaBasePlugin.class);
    configureSourceSetDefaults(project, javaBasePlugin);
}
Also used : JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin)

Example 2 with JavaBasePlugin

use of org.gradle.api.plugins.JavaBasePlugin in project gradle-apt-plugin by tbroyer.

the class AptPlugin method apply.

@Override
public void apply(final Project project) {
    configureCompileTasks(project, JavaCompile.class, new GetCompileOptions<JavaCompile>() {

        @Override
        public CompileOptions getCompileOptions(JavaCompile task) {
            return task.getOptions();
        }
    });
    configureCompileTasks(project, GroovyCompile.class, new GetCompileOptions<GroovyCompile>() {

        @Override
        public CompileOptions getCompileOptions(GroovyCompile task) {
            return task.getOptions();
        }
    });
    project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {

        @Override
        public void execute(JavaBasePlugin javaBasePlugin) {
            final JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
            javaConvention.getSourceSets().all(new Action<SourceSet>() {

                @Override
                public void execute(final SourceSet sourceSet) {
                    AptSourceSetConvention convention = IMPL.createAptSourceSetConvention(project, sourceSet);
                    new DslObject(sourceSet).getConvention().getPlugins().put(PLUGIN_ID, convention);
                    AptSourceSetOutputConvention outputConvention = new AptSourceSetOutputConvention(project);
                    outputConvention.setGeneratedSourcesDir(new File(project.getBuildDir(), "generated/source/apt/" + sourceSet.getName()));
                    new DslObject(sourceSet.getOutput()).getConvention().getPlugins().put(PLUGIN_ID, outputConvention);
                    ensureConfigurations(project, sourceSet, convention);
                    configureCompileTaskForSourceSet(project, sourceSet, sourceSet.getCompileJavaTaskName(), JavaCompile.class, new GetCompileOptions<JavaCompile>() {

                        @Override
                        public CompileOptions getCompileOptions(JavaCompile task) {
                            return task.getOptions();
                        }
                    });
                }
            });
        }
    });
    project.getPlugins().withType(GroovyBasePlugin.class, new Action<GroovyBasePlugin>() {

        @Override
        public void execute(GroovyBasePlugin groovyBasePlugin) {
            JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
            javaConvention.getSourceSets().all(new Action<SourceSet>() {

                @Override
                public void execute(SourceSet sourceSet) {
                    AptSourceSetConvention convention = new DslObject(sourceSet).getConvention().getPlugin(AptSourceSetConvention.class);
                    configureCompileTaskForSourceSet(project, sourceSet, sourceSet.getCompileTaskName("groovy"), GroovyCompile.class, new GetCompileOptions<GroovyCompile>() {

                        @Override
                        public CompileOptions getCompileOptions(GroovyCompile task) {
                            return task.getOptions();
                        }
                    });
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) DslObject(org.gradle.api.internal.plugins.DslObject) GroovyCompile(org.gradle.api.tasks.compile.GroovyCompile) CompileOptions(org.gradle.api.tasks.compile.CompileOptions) SourceSet(org.gradle.api.tasks.SourceSet) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) GroovyBasePlugin(org.gradle.api.plugins.GroovyBasePlugin) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) File(java.io.File)

Example 3 with JavaBasePlugin

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

the class EclipsePlugin method configureEclipseProject.

private void configureEclipseProject(final ProjectInternal project, final EclipseModel model) {
    final EclipseProject projectModel = model.getProject();
    projectModel.setName(uniqueProjectNameProvider.getUniqueName(project));
    final ConventionMapping convention = ((IConventionAware) projectModel).getConventionMapping();
    convention.map("comment", new Callable<String>() {

        @Override
        public String call() {
            return project.getDescription();
        }
    });
    final TaskProvider<GenerateEclipseProject> task = project.getTasks().register(ECLIPSE_PROJECT_TASK_NAME, GenerateEclipseProject.class, model.getProject());
    task.configure(new Action<GenerateEclipseProject>() {

        @Override
        public void execute(GenerateEclipseProject task) {
            task.setDescription("Generates the Eclipse project file.");
            task.setInputFile(project.file(".project"));
            task.setOutputFile(project.file(".project"));
        }
    });
    addWorker(task, ECLIPSE_PROJECT_TASK_NAME);
    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");
        }
    });
    artifactRegistry.registerIdeProject(new EclipseProjectMetadata(model, project.getProjectDir(), task));
}
Also used : EclipseProject(org.gradle.plugins.ide.eclipse.model.EclipseProject) EclipseProjectMetadata(org.gradle.plugins.ide.eclipse.internal.EclipseProjectMetadata) ScalaBasePlugin(org.gradle.api.plugins.scala.ScalaBasePlugin) ConventionMapping(org.gradle.api.internal.ConventionMapping) Callable(java.util.concurrent.Callable) 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) IConventionAware(org.gradle.api.internal.IConventionAware) Link(org.gradle.plugins.ide.eclipse.model.Link)

Example 4 with JavaBasePlugin

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

the class ScalaBasePlugin method configureSourceSetDefaults.

private static void configureSourceSetDefaults(final Project project, final SourceDirectorySetFactory sourceDirectorySetFactory) {
    final JavaBasePlugin javaPlugin = project.getPlugins().getPlugin(JavaBasePlugin.class);
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {

        @Override
        public void execute(final SourceSet sourceSet) {
            String displayName = (String) InvokerHelper.invokeMethod(sourceSet, "getDisplayName", null);
            Convention sourceSetConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
            DefaultScalaSourceSet scalaSourceSet = new DefaultScalaSourceSet(displayName, sourceDirectorySetFactory);
            sourceSetConvention.getPlugins().put("scala", scalaSourceSet);
            final SourceDirectorySet scalaDirectorySet = scalaSourceSet.getScala();
            scalaDirectorySet.srcDir(new Callable<File>() {

                @Override
                public File call() throws Exception {
                    return project.file("src/" + sourceSet.getName() + "/scala");
                }
            });
            sourceSet.getAllJava().source(scalaDirectorySet);
            sourceSet.getAllSource().source(scalaDirectorySet);
            sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() {

                @Override
                public boolean isSatisfiedBy(FileTreeElement element) {
                    return scalaDirectorySet.contains(element.getFile());
                }
            });
            configureScalaCompile(project, javaPlugin, sourceSet);
        }
    });
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) ScalaSourceSet(org.gradle.api.tasks.ScalaSourceSet) DefaultScalaSourceSet(org.gradle.api.internal.tasks.DefaultScalaSourceSet) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Convention(org.gradle.api.plugins.Convention) FileTreeElement(org.gradle.api.file.FileTreeElement) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) DefaultScalaSourceSet(org.gradle.api.internal.tasks.DefaultScalaSourceSet) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) Spec(org.gradle.api.specs.Spec) Callable(java.util.concurrent.Callable)

Example 5 with JavaBasePlugin

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

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