Package org.gradle.api.internal

Examples of org.gradle.api.internal.ConventionMapping


    private void configureSourceSetDefaults(final JavaPluginConvention pluginConvention) {
        pluginConvention.getSourceSets().allObjects(new Action<SourceSet>() {
            public void execute(final SourceSet sourceSet) {
                final Project project = pluginConvention.getProject();
                ConventionMapping conventionMapping = ((IConventionAware) sourceSet).getConventionMapping();

                conventionMapping.map("classesDir", new ConventionValue() {
                    public Object getValue(Convention convention, IConventionAware conventionAwareObject) {
                        String classesDirName = String.format("classes/%s", sourceSet.getName());
                        return new File(project.getBuildDir(), classesDirName);
                    }
                });
                sourceSet.getJava().srcDir(String.format("src/%s/java", sourceSet.getName()));
                sourceSet.getResources().srcDir(String.format("src/%s/resources", sourceSet.getName()));

                Copy processResources = project.getTasks().add(sourceSet.getProcessResourcesTaskName(), ProcessResources.class);
                processResources.setDescription(String.format("Processes the %s.", sourceSet.getResources()));
                conventionMapping = processResources.getConventionMapping();
                conventionMapping.map("defaultSource", new ConventionValue() {
                    public Object getValue(Convention convention, IConventionAware conventionAwareObject) {
                        return sourceSet.getResources();
                    }
                });
                conventionMapping.map("destinationDir", new ConventionValue() {
                    public Object getValue(Convention convention, IConventionAware conventionAwareObject) {
                        return sourceSet.getClassesDir();
                    }
                });
View Full Code Here


            }
        });
    }

    public void configureForSourceSet(final SourceSet sourceSet, AbstractCompile compile) {
        ConventionMapping conventionMapping;
        compile.setDescription(String.format("Compiles the %s.", sourceSet.getJava()));
        conventionMapping = compile.getConventionMapping();
        conventionMapping.map("classpath", new ConventionValue() {
            public Object getValue(Convention convention, IConventionAware conventionAwareObject) {
                return sourceSet.getCompileClasspath();
            }
        });
        conventionMapping.map("defaultSource", new ConventionValue() {
            public Object getValue(Convention convention, IConventionAware conventionAwareObject) {
                return sourceSet.getJava();
            }
        });
        conventionMapping.map("destinationDir", new ConventionValue() {
            public Object getValue(Convention convention, IConventionAware conventionAwareObject) {
                return sourceSet.getClassesDir();
            }
        });
    }
View Full Code Here

    }

    private void configureCompileDefaults(final Project project, final JavaPluginConvention javaConvention) {
        project.getTasks().withType(AbstractCompile.class).allTasks(new Action<AbstractCompile>() {
            public void execute(final AbstractCompile compile) {
                ConventionMapping conventionMapping = compile.getConventionMapping();
                conventionMapping.map("sourceCompatibility", new ConventionValue() {
                    public Object getValue(Convention convention, IConventionAware conventionAwareObject) {
                        return javaConvention.getSourceCompatibility().toString();
                    }
                });
                conventionMapping.map("targetCompatibility", new ConventionValue() {
                    public Object getValue(Convention convention, IConventionAware conventionAwareObject) {
                        return javaConvention.getTargetCompatibility().toString();
                    }
                });
            }
        });
        project.getTasks().withType(Compile.class).allTasks(new Action<Compile>() {
            public void execute(final Compile compile) {
                ConventionMapping conventionMapping = compile.getConventionMapping();
                conventionMapping.map("dependencyCacheDir", new ConventionValue() {
                    public Object getValue(Convention convention, IConventionAware conventionAwareObject) {
                        return javaConvention.getDependencyCacheDir();
                    }
                });
            }
View Full Code Here

    public void testConventionAwareness() {
        ConventionTask task = getTask();
        assertThat(task.getConventionMapping(), instanceOf(ConventionAwareHelper.class));
        assertThat(task.getConventionMapping().getConvention(), sameInstance(getProject().getConvention()));

        ConventionMapping conventionMapping = context.mock(ConventionMapping.class);
        task.setConventionMapping(conventionMapping);
        assertThat(task.getConventionMapping(), sameInstance(conventionMapping));
    }
View Full Code Here

    private SonarRunner createTask(final Project project, final Map<Project, ActionBroadcast<SonarProperties>> actionBroadcastMap) {
        SonarRunner sonarRunnerTask = project.getTasks().create(SonarRunnerExtension.SONAR_RUNNER_TASK_NAME, SonarRunner.class);
        sonarRunnerTask.setDescription("Analyzes " + project + " and its subprojects with Sonar Runner.");

        ConventionMapping conventionMapping = new DslObject(sonarRunnerTask).getConventionMapping();
        conventionMapping.map("sonarProperties", new Callable<Object>() {
            public Object call() throws Exception {
                Map<String, Object> properties = Maps.newLinkedHashMap();
                computeSonarProperties(project, properties, actionBroadcastMap);
                return properties;
            }
View Full Code Here

                public void execute(final GenerateMavenPom generatePomTask) {
                    generatePomTask.setDescription(String.format("Generates the Maven POM file for publication '%s'.", publication.getName()));
                    generatePomTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
                    generatePomTask.setPom(publication.getPom());

                    ConventionMapping descriptorTaskConventionMapping = new DslObject(generatePomTask).getConventionMapping();
                    descriptorTaskConventionMapping.map("destination", new Callable<Object>() {
                        public Object call() throws Exception {
                            return new File(generatePomTask.getProject().getBuildDir(), "publications/" + publication.getName() + "/pom-default.xml");
                        }
                    });
View Full Code Here

        final GenerateBuildDashboard buildDashboardTask = project.getTasks().create(BUILD_DASHBOARD_TASK_NAME, GenerateBuildDashboard.class);
        buildDashboardTask.setDescription("Generates a dashboard of all the reports produced by this build.");
        buildDashboardTask.setGroup("reporting");

        DirectoryReport htmlReport = buildDashboardTask.getReports().getHtml();
        ConventionMapping htmlReportConventionMapping = new DslObject(htmlReport).getConventionMapping();
        htmlReportConventionMapping.map("destination", new Callable<Object>() {
            public Object call() throws Exception {
                return project.getExtensions().getByType(ReportingExtension.class).file("buildDashboard");
            }
        });
View Full Code Here

                    public void execute(final GenerateIvyDescriptor descriptorTask) {
                        descriptorTask.setDescription(String.format("Generates the Ivy Module Descriptor XML file for publication '%s'.", publication.getName()));
                        descriptorTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
                        descriptorTask.setDescriptor(publication.getDescriptor());

                        ConventionMapping descriptorTaskConventionMapping = new DslObject(descriptorTask).getConventionMapping();
                        descriptorTaskConventionMapping.map("destination", new Callable<Object>() {
                            public Object call() throws Exception {
                                return new File(descriptorTask.getProject().getBuildDir(), "publications/" + publication.getName() + "/ivy.xml");
                            }
                        });
View Full Code Here

        return ConfigureUtil.configure(closure, createDefaultOsgiManifest(project));
    }

    private OsgiManifest createDefaultOsgiManifest(final ProjectInternal project) {
        OsgiManifest osgiManifest = project.getServices().get(Instantiator.class).newInstance(DefaultOsgiManifest.class, project.getFileResolver());
        ConventionMapping mapping = ((IConventionAware) osgiManifest).getConventionMapping();
        final OsgiHelper osgiHelper = new OsgiHelper();

        mapping.map("version", new Callable<Object>() {
            public Object call() throws Exception {
                return osgiHelper.getVersion(project.getVersion().toString());
            }
        });
        mapping.map("name", new Callable<Object>() {
            public Object call() throws Exception {
                return project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName();
            }
        });
        mapping.map("symbolicName", new Callable<Object>() {
            public Object call() throws Exception {
                return osgiHelper.getBundleSymbolicName(project);
            }
        });
View Full Code Here

        });
    }

    private void setClassesDirConvention(ClassDirectoryBinarySpecInternal binary, final Project target) {
        final BinaryNamingScheme namingScheme = binary.getNamingScheme();
        ConventionMapping conventionMapping = new DslObject(binary).getConventionMapping();
        conventionMapping.map("classesDir", new Callable<File>() {
            public File call() throws Exception {
                return new File(new File(target.getBuildDir(), "classes"), namingScheme.getOutputDirectoryBase());
            }
        });
    }
View Full Code Here

TOP

Related Classes of org.gradle.api.internal.ConventionMapping

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.