Search in sources :

Example 46 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class IdeaScalaConfigurer method configure.

public void configure() {
    rootProject.getGradle().addBuildListener(new BuildAdapter() {

        public void projectsEvaluated(Gradle gradle) {
            VersionNumber ideaTargetVersion = findIdeaTargetVersion();
            final boolean useScalaSdk = ideaTargetVersion == null || IDEA_VERSION_WHEN_SCALA_SDK_WAS_INTRODUCED.compareTo(ideaTargetVersion) <= 0;
            final Collection<Project> scalaProjects = findProjectsApplyingIdeaAndScalaPlugins();
            final Map<String, ProjectLibrary> scalaCompilerLibraries = Maps.newLinkedHashMap();
            rootProject.getTasks().getByName("ideaProject").doFirst(new Action<Task>() {

                @Override
                public void execute(Task task) {
                    if (scalaProjects.size() > 0) {
                        scalaCompilerLibraries.clear();
                        scalaCompilerLibraries.putAll(resolveScalaCompilerLibraries(scalaProjects, useScalaSdk));
                        declareUniqueProjectLibraries(Sets.newLinkedHashSet(scalaCompilerLibraries.values()));
                    }
                }
            });
            rootProject.configure(scalaProjects, new Action<Project>() {

                @Override
                public void execute(final Project project) {
                    project.getExtensions().getByType(IdeaModel.class).getModule().getIml().withXml(new Action<XmlProvider>() {

                        @Override
                        public void execute(XmlProvider xmlProvider) {
                            if (useScalaSdk) {
                                declareScalaSdk(scalaCompilerLibraries.get(project.getPath()), xmlProvider.asNode());
                            } else {
                                declareScalaFacet(scalaCompilerLibraries.get(project.getPath()), xmlProvider.asNode());
                            }
                        }
                    });
                }
            });
        }
    });
}
Also used : Project(org.gradle.api.Project) Action(org.gradle.api.Action) Task(org.gradle.api.Task) IdeaModel(org.gradle.plugins.ide.idea.model.IdeaModel) XmlProvider(org.gradle.api.XmlProvider) FileCollection(org.gradle.api.file.FileCollection) Collection(java.util.Collection) BuildAdapter(org.gradle.BuildAdapter) Gradle(org.gradle.api.invocation.Gradle) Map(java.util.Map) VersionNumber(org.gradle.util.VersionNumber)

Example 47 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class NativeBasePlugin method addLifecycleTasks.

private void addLifecycleTasks(final TaskContainer tasks, final SoftwareComponentContainer components) {
    components.withType(ComponentWithBinaries.class, new Action<ComponentWithBinaries>() {

        @Override
        public void execute(final ComponentWithBinaries component) {
            // Register each child of each component
            component.getBinaries().whenElementKnown(new Action<SoftwareComponent>() {

                @Override
                public void execute(SoftwareComponent binary) {
                    components.add(binary);
                }
            });
            if (component instanceof ProductionComponent) {
                // Add an assemble task for each binary and also wire the development binary in to the `assemble` task
                component.getBinaries().whenElementFinalized(ComponentWithOutputs.class, new Action<ComponentWithOutputs>() {

                    @Override
                    public void execute(ComponentWithOutputs binary) {
                        // Determine which output to produce at development time.
                        FileCollection outputs = binary.getOutputs();
                        Names names = ((ComponentWithNames) binary).getNames();
                        Task lifecycleTask = tasks.create(names.getTaskName("assemble"));
                        lifecycleTask.dependsOn(outputs);
                        if (binary == ((ProductionComponent) component).getDevelopmentBinary().get()) {
                            tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).dependsOn(outputs);
                        }
                    }
                });
            }
        }
    });
}
Also used : ComponentWithNames(org.gradle.language.nativeplatform.internal.ComponentWithNames) Names(org.gradle.language.nativeplatform.internal.Names) Action(org.gradle.api.Action) Task(org.gradle.api.Task) AbstractLinkTask(org.gradle.nativeplatform.tasks.AbstractLinkTask) ComponentWithBinaries(org.gradle.language.ComponentWithBinaries) ComponentWithOutputs(org.gradle.language.ComponentWithOutputs) ProductionComponent(org.gradle.language.ProductionComponent) FileCollection(org.gradle.api.file.FileCollection) ComponentWithNames(org.gradle.language.nativeplatform.internal.ComponentWithNames) SoftwareComponent(org.gradle.api.component.SoftwareComponent)

Example 48 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class PlayDistributionPlugin method createDistributionContentTasks.

@Mutate
void createDistributionContentTasks(ModelMap<Task> tasks, @Path("buildDir") final File buildDir, @Path("distributions") final PlayDistributionContainer distributions, final PlayPluginConfigurations configurations) {
    for (final PlayDistribution distribution : distributions.withType(PlayDistribution.class)) {
        final PlayApplicationBinarySpec binary = distribution.getBinary();
        if (binary == null) {
            throw new InvalidUserCodeException(String.format("Play Distribution '%s' does not have a configured Play binary.", distribution.getName()));
        }
        final File distJarDir = new File(buildDir, "distributionJars/" + distribution.getName());
        final String jarTaskName = "create" + StringUtils.capitalize(distribution.getName()) + "DistributionJar";
        tasks.create(jarTaskName, Jar.class, new Action<Jar>() {

            @Override
            public void execute(Jar jar) {
                jar.setDescription("Assembles an application jar suitable for deployment for the " + binary + ".");
                jar.dependsOn(binary.getTasks().withType(Jar.class));
                jar.from(jar.getProject().zipTree(binary.getJarFile()));
                jar.setDestinationDir(distJarDir);
                jar.setArchiveName(binary.getJarFile().getName());
                Map<String, Object> classpath = Maps.newHashMap();
                classpath.put("Class-Path", new PlayManifestClasspath(configurations.getPlayRun(), binary.getAssetsJarFile()));
                jar.getManifest().attributes(classpath);
            }
        });
        final Task distributionJar = tasks.get(jarTaskName);
        final File scriptsDir = new File(buildDir, "scripts/" + distribution.getName());
        String createStartScriptsTaskName = "create" + StringUtils.capitalize(distribution.getName() + "StartScripts");
        tasks.create(createStartScriptsTaskName, CreateStartScripts.class, new Action<CreateStartScripts>() {

            @Override
            public void execute(CreateStartScripts createStartScripts) {
                createStartScripts.setDescription("Creates OS specific scripts to run the " + binary + ".");
                createStartScripts.setClasspath(distributionJar.getOutputs().getFiles());
                createStartScripts.setMainClassName(getMainClass(distribution));
                createStartScripts.setApplicationName(distribution.getName());
                createStartScripts.setOutputDir(scriptsDir);
            }
        });
        Task createStartScripts = tasks.get(createStartScriptsTaskName);
        CopySpecInternal distSpec = (CopySpecInternal) distribution.getContents();
        CopySpec libSpec = distSpec.addChild().into("lib");
        libSpec.from(distributionJar);
        libSpec.from(binary.getAssetsJarFile());
        libSpec.from(configurations.getPlayRun().getAllArtifacts());
        libSpec.eachFile(new PrefixArtifactFileNames(configurations.getPlayRun()));
        CopySpec binSpec = distSpec.addChild().into("bin");
        binSpec.from(createStartScripts);
        binSpec.setFileMode(0755);
        CopySpec confSpec = distSpec.addChild().into("conf");
        confSpec.from("conf").exclude("routes");
        distSpec.from("README");
    }
}
Also used : CopySpec(org.gradle.api.file.CopySpec) AbstractArchiveTask(org.gradle.api.tasks.bundling.AbstractArchiveTask) Task(org.gradle.api.Task) InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) PlayDistribution(org.gradle.play.distribution.PlayDistribution) DefaultPlayDistribution(org.gradle.play.internal.distribution.DefaultPlayDistribution) PlayApplicationBinarySpec(org.gradle.play.PlayApplicationBinarySpec) CreateStartScripts(org.gradle.api.tasks.application.CreateStartScripts) Jar(org.gradle.jvm.tasks.Jar) CopySpecInternal(org.gradle.api.internal.file.copy.CopySpecInternal) File(java.io.File) Map(java.util.Map) ModelMap(org.gradle.model.ModelMap) Mutate(org.gradle.model.Mutate)

Example 49 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class ApplicationPlugin method configureDistSpec.

private CopySpec configureDistSpec(CopySpec distSpec) {
    Task jar = project.getTasks().getAt(JavaPlugin.JAR_TASK_NAME);
    Task startScripts = project.getTasks().getAt(TASK_START_SCRIPTS_NAME);
    CopySpec libChildSpec = project.copySpec();
    libChildSpec.into("lib");
    libChildSpec.from(jar);
    libChildSpec.from(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
    CopySpec binChildSpec = project.copySpec();
    binChildSpec.into(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return pluginConvention.getExecutableDir();
        }
    });
    binChildSpec.from(startScripts);
    binChildSpec.setFileMode(0755);
    CopySpec childSpec = project.copySpec();
    childSpec.from(project.file("src/dist"));
    childSpec.with(libChildSpec);
    childSpec.with(binChildSpec);
    distSpec.with(childSpec);
    distSpec.with(pluginConvention.getApplicationDistribution());
    return distSpec;
}
Also used : CopySpec(org.gradle.api.file.CopySpec) Task(org.gradle.api.Task) UncheckedIOException(org.gradle.api.UncheckedIOException) GradleException(org.gradle.api.GradleException)

Example 50 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class JavaBasePlugin method configureBasedOnSingleProperty.

private void configureBasedOnSingleProperty(final Test test) {
    String singleTest = getTaskPrefixedProperty(test, "single");
    if (singleTest == null) {
        // configure inputs so that the test task is skipped when there are no source files.
        // unfortunately, this only applies when 'test.single' is *not* applied
        // We should fix this distinction, the behavior with 'test.single' or without it should be the same
        test.getInputs().files(test.getCandidateClassFiles()).withPropertyName("nonEmptyCandidateClassFiles").withPathSensitivity(PathSensitivity.RELATIVE).skipWhenEmpty();
        return;
    }
    test.prependParallelSafeAction(new Action<Task>() {

        public void execute(Task task) {
            test.getLogger().info("Running single tests with pattern: {}", test.getIncludes());
        }
    });
    test.setIncludes(WrapUtil.toSet("**/" + singleTest + "*.class"));
    test.addTestListener(new NoMatchingTestsReporter("Could not find matching test for pattern: " + singleTest));
}
Also used : Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) NoMatchingTestsReporter(org.gradle.api.internal.tasks.testing.NoMatchingTestsReporter)

Aggregations

Task (org.gradle.api.Task)222 Project (org.gradle.api.Project)66 File (java.io.File)54 Action (org.gradle.api.Action)31 ArrayList (java.util.ArrayList)27 Plugin (org.gradle.api.Plugin)27 Configuration (org.gradle.api.artifacts.Configuration)27 Test (org.junit.Test)23 List (java.util.List)22 TaskProvider (org.gradle.api.tasks.TaskProvider)22 DefaultTask (org.gradle.api.DefaultTask)21 IOException (java.io.IOException)20 Set (java.util.Set)18 SourceSet (org.gradle.api.tasks.SourceSet)18 Map (java.util.Map)17 GradleException (org.gradle.api.GradleException)17 FileCollection (org.gradle.api.file.FileCollection)16 Inject (javax.inject.Inject)15 JavaPlugin (org.gradle.api.plugins.JavaPlugin)15 LifecycleBasePlugin (org.gradle.language.base.plugins.LifecycleBasePlugin)15