Search in sources :

Example 6 with DslObject

use of org.gradle.api.internal.plugins.DslObject in project gradle by gradle.

the class JavaBasePlugin method createProcessResourcesTaskForBinary.

private void createProcessResourcesTaskForBinary(final SourceSet sourceSet, SourceDirectorySet resourceSet, final Project target) {
    Copy resourcesTask = target.getTasks().create(sourceSet.getProcessResourcesTaskName(), ProcessResources.class);
    resourcesTask.setDescription("Processes " + resourceSet + ".");
    new DslObject(resourcesTask).getConventionMapping().map("destinationDir", new Callable<File>() {

        public File call() throws Exception {
            return sourceSet.getOutput().getResourcesDir();
        }
    });
    resourcesTask.from(resourceSet);
}
Also used : Copy(org.gradle.api.tasks.Copy) DslObject(org.gradle.api.internal.plugins.DslObject) File(java.io.File)

Example 7 with DslObject

use of org.gradle.api.internal.plugins.DslObject in project gradle by gradle.

the class JavaBasePlugin method configureTestDefaults.

private void configureTestDefaults(final Test test, Project project, final JavaPluginConvention convention) {
    DslObject htmlReport = new DslObject(test.getReports().getHtml());
    DslObject xmlReport = new DslObject(test.getReports().getJunitXml());
    xmlReport.getConventionMapping().map("destination", new Callable<Object>() {

        public Object call() throws Exception {
            return new File(convention.getTestResultsDir(), test.getName());
        }
    });
    htmlReport.getConventionMapping().map("destination", new Callable<Object>() {

        public Object call() throws Exception {
            return new File(convention.getTestReportDir(), test.getName());
        }
    });
    test.getConventionMapping().map("binResultsDir", new Callable<Object>() {

        public Object call() throws Exception {
            return new File(convention.getTestResultsDir(), test.getName() + "/binary");
        }
    });
    test.workingDir(project.getProjectDir());
}
Also used : DslObject(org.gradle.api.internal.plugins.DslObject) DslObject(org.gradle.api.internal.plugins.DslObject) File(java.io.File)

Example 8 with DslObject

use of org.gradle.api.internal.plugins.DslObject in project gradle by gradle.

the class ProjectReportsPlugin method apply.

@Override
public void apply(Project project) {
    project.getPluginManager().apply(ReportingBasePlugin.class);
    final ProjectReportsPluginConvention convention = new ProjectReportsPluginConvention(project);
    project.getConvention().getPlugins().put("projectReports", convention);
    TaskReportTask taskReportTask = project.getTasks().create(TASK_REPORT, TaskReportTask.class);
    taskReportTask.setDescription("Generates a report about your tasks.");
    taskReportTask.conventionMapping("outputFile", new Callable<Object>() {

        public Object call() throws Exception {
            return new File(convention.getProjectReportDir(), "tasks.txt");
        }
    });
    taskReportTask.conventionMapping("projects", new Callable<Object>() {

        public Object call() throws Exception {
            return convention.getProjects();
        }
    });
    PropertyReportTask propertyReportTask = project.getTasks().create(PROPERTY_REPORT, PropertyReportTask.class);
    propertyReportTask.setDescription("Generates a report about your properties.");
    propertyReportTask.conventionMapping("outputFile", new Callable<Object>() {

        public Object call() throws Exception {
            return new File(convention.getProjectReportDir(), "properties.txt");
        }
    });
    propertyReportTask.conventionMapping("projects", new Callable<Object>() {

        public Object call() throws Exception {
            return convention.getProjects();
        }
    });
    DependencyReportTask dependencyReportTask = project.getTasks().create(DEPENDENCY_REPORT, DependencyReportTask.class);
    dependencyReportTask.setDescription("Generates a report about your library dependencies.");
    dependencyReportTask.conventionMapping("outputFile", new Callable<Object>() {

        public Object call() throws Exception {
            return new File(convention.getProjectReportDir(), "dependencies.txt");
        }
    });
    dependencyReportTask.conventionMapping("projects", new Callable<Object>() {

        public Object call() throws Exception {
            return convention.getProjects();
        }
    });
    HtmlDependencyReportTask htmlDependencyReportTask = project.getTasks().create(HTML_DEPENDENCY_REPORT, HtmlDependencyReportTask.class);
    htmlDependencyReportTask.setDescription("Generates an HTML report about your library dependencies.");
    new DslObject(htmlDependencyReportTask.getReports().getHtml()).getConventionMapping().map("destination", new Callable<Object>() {

        public Object call() throws Exception {
            return new File(convention.getProjectReportDir(), "dependencies");
        }
    });
    htmlDependencyReportTask.conventionMapping("projects", new Callable<Object>() {

        public Object call() throws Exception {
            return convention.getProjects();
        }
    });
    Task projectReportTask = project.getTasks().create(PROJECT_REPORT);
    projectReportTask.dependsOn(TASK_REPORT, PROPERTY_REPORT, DEPENDENCY_REPORT, HTML_DEPENDENCY_REPORT);
    projectReportTask.setDescription("Generates a report about your project.");
    projectReportTask.setGroup("reporting");
}
Also used : TaskReportTask(org.gradle.api.tasks.diagnostics.TaskReportTask) Task(org.gradle.api.Task) PropertyReportTask(org.gradle.api.tasks.diagnostics.PropertyReportTask) DependencyReportTask(org.gradle.api.tasks.diagnostics.DependencyReportTask) TaskReportTask(org.gradle.api.tasks.diagnostics.TaskReportTask) HtmlDependencyReportTask(org.gradle.api.reporting.dependencies.HtmlDependencyReportTask) PropertyReportTask(org.gradle.api.tasks.diagnostics.PropertyReportTask) HtmlDependencyReportTask(org.gradle.api.reporting.dependencies.HtmlDependencyReportTask) DslObject(org.gradle.api.internal.plugins.DslObject) DslObject(org.gradle.api.internal.plugins.DslObject) DependencyReportTask(org.gradle.api.tasks.diagnostics.DependencyReportTask) HtmlDependencyReportTask(org.gradle.api.reporting.dependencies.HtmlDependencyReportTask) File(java.io.File)

Example 9 with DslObject

use of org.gradle.api.internal.plugins.DslObject in project gradle by gradle.

the class CodeNarcPlugin method configureForSourceSet.

@Override
protected void configureForSourceSet(final SourceSet sourceSet, CodeNarc task) {
    task.setDescription("Run CodeNarc analysis for " + sourceSet.getName() + " classes");
    DynamicObject dynamicObject = new DslObject(sourceSet).getAsDynamicObject();
    task.setSource(dynamicObject.getProperty("allGroovy"));
}
Also used : DynamicObject(org.gradle.internal.metaobject.DynamicObject) DslObject(org.gradle.api.internal.plugins.DslObject)

Example 10 with DslObject

use of org.gradle.api.internal.plugins.DslObject in project gradle by gradle.

the class BridgedCollections method registration.

public static <I, C extends NamedDomainObjectCollection<I>> ModelRegistrations.Builder registration(final ModelReference<C> containerReference, final Transformer<? extends C, ? super MutableModelNode> containerFactory, final Namer<? super I> namer, String descriptor, final Transformer<String, String> itemDescriptorGenerator) {
    final ModelPath containerPath = containerReference.getPath();
    final ModelType<C> containerType = containerReference.getType();
    assert containerPath != null : "container reference path cannot be null";
    return ModelRegistrations.of(containerPath).action(ModelActionRole.Create, new Action<MutableModelNode>() {

        public void execute(final MutableModelNode containerNode) {
            final C container = containerFactory.transform(containerNode);
            containerNode.setPrivateData(containerType, container);
            container.all(new Action<I>() {

                public void execute(final I item) {
                    final String name = namer.determineName(item);
                    // For now, ignore elements added after the container has been closed
                    if (!containerNode.isMutable()) {
                        LOGGER.debug("Ignoring element '{}' added to '{}' after it is closed.", containerPath, name);
                        return;
                    }
                    if (!containerNode.hasLink(name)) {
                        ModelRegistration itemRegistration = ModelRegistrations.unmanagedInstanceOf(ModelReference.of(containerPath.child(name), new DslObject(item).getDeclaredType()), new ExtractFromParentContainer<I, C>(name, containerType)).descriptor(new SimpleModelRuleDescriptor(new Factory<String>() {

                            @Override
                            public String create() {
                                return itemDescriptorGenerator.transform(name);
                            }
                        })).build();
                        containerNode.addLink(itemRegistration);
                    }
                }
            });
            container.whenObjectRemoved(new Action<I>() {

                public void execute(I item) {
                    String name = namer.determineName(item);
                    containerNode.removeLink(name);
                }
            });
        }
    }).descriptor(descriptor);
}
Also used : Action(org.gradle.api.Action) DslObject(org.gradle.api.internal.plugins.DslObject) Factory(org.gradle.internal.Factory) LoggerFactory(org.slf4j.LoggerFactory) SimpleModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.SimpleModelRuleDescriptor)

Aggregations

DslObject (org.gradle.api.internal.plugins.DslObject)14 File (java.io.File)5 Configuration (org.gradle.api.artifacts.Configuration)3 DynamicObject (org.gradle.internal.metaobject.DynamicObject)3 Test (org.junit.Test)3 GroovyObject (groovy.lang.GroovyObject)2 ConventionMapping (org.gradle.api.internal.ConventionMapping)2 SourceSet (org.gradle.api.tasks.SourceSet)2 BeanDynamicObject (org.gradle.internal.metaobject.BeanDynamicObject)2 Field (java.lang.reflect.Field)1 Callable (java.util.concurrent.Callable)1 Action (org.gradle.api.Action)1 Task (org.gradle.api.Task)1 DependencySet (org.gradle.api.artifacts.DependencySet)1 FileCollection (org.gradle.api.file.FileCollection)1 DefaultSourceSet (org.gradle.api.internal.tasks.DefaultSourceSet)1 AntlrSourceVirtualDirectoryImpl (org.gradle.api.plugins.antlr.internal.AntlrSourceVirtualDirectoryImpl)1 DefaultMavenRepositoryHandlerConvention (org.gradle.api.publication.maven.internal.DefaultMavenRepositoryHandlerConvention)1 DirectoryReport (org.gradle.api.reporting.DirectoryReport)1 GenerateBuildDashboard (org.gradle.api.reporting.GenerateBuildDashboard)1