Search in sources :

Example 1 with CopySpecInternal

use of org.gradle.api.internal.file.copy.CopySpecInternal 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("play.core.server.NettyServer");
                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) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with CopySpecInternal

use of org.gradle.api.internal.file.copy.CopySpecInternal in project gradle by gradle.

the class PlayDistributionPlugin method createDistributionZipTasks.

@Mutate
void createDistributionZipTasks(ModelMap<Task> tasks, @Path("buildDir") final File buildDir, PlayDistributionContainer distributions) {
    for (final PlayDistribution distribution : distributions.withType(PlayDistribution.class)) {
        String capitalizedDistName = StringUtils.capitalize(distribution.getName());
        final String stageTaskName = "stage" + capitalizedDistName + "Dist";
        final File stageDir = new File(buildDir, "stage");
        final String baseName = StringUtils.isNotEmpty(distribution.getBaseName()) ? distribution.getBaseName() : distribution.getName();
        tasks.create(stageTaskName, Sync.class, new Action<Sync>() {

            @Override
            public void execute(Sync sync) {
                sync.setDescription("Copies the '" + distribution.getName() + "' distribution to a staging directory.");
                sync.setDestinationDir(stageDir);
                CopySpecInternal baseSpec = sync.getRootSpec().addChild();
                baseSpec.into(baseName);
                baseSpec.with(distribution.getContents());
            }
        });
        tasks.named(STAGE_LIFECYCLE_TASK_NAME, new Action<Task>() {

            @Override
            public void execute(Task task) {
                task.dependsOn(stageTaskName);
            }
        });
        final Task stageTask = tasks.get(stageTaskName);
        final String distributionZipTaskName = "create" + capitalizedDistName + "ZipDist";
        tasks.create(distributionZipTaskName, Zip.class, new Action<Zip>() {

            @Override
            public void execute(final Zip zip) {
                zip.setDescription("Packages the '" + distribution.getName() + "' distribution as a zip file.");
                zip.setBaseName(baseName);
                zip.setDestinationDir(new File(buildDir, "distributions"));
                zip.from(stageTask);
            }
        });
        final String distributionTarTaskName = "create" + capitalizedDistName + "TarDist";
        tasks.create(distributionTarTaskName, Tar.class, new Action<Tar>() {

            @Override
            public void execute(final Tar tar) {
                tar.setDescription("Packages the '" + distribution.getName() + "' distribution as a tar file.");
                tar.setBaseName(baseName);
                tar.setDestinationDir(new File(buildDir, "distributions"));
                tar.from(stageTask);
            }
        });
        tasks.named(distributionTarTaskName, DistributionArchiveRules.class);
        tasks.named(distributionZipTaskName, DistributionArchiveRules.class);
        tasks.named(DIST_LIFECYCLE_TASK_NAME, new Action<Task>() {

            @Override
            public void execute(Task task) {
                task.dependsOn(distributionZipTaskName, distributionTarTaskName);
            }
        });
    }
}
Also used : Zip(org.gradle.api.tasks.bundling.Zip) AbstractArchiveTask(org.gradle.api.tasks.bundling.AbstractArchiveTask) Task(org.gradle.api.Task) Tar(org.gradle.api.tasks.bundling.Tar) PlayDistribution(org.gradle.play.distribution.PlayDistribution) DefaultPlayDistribution(org.gradle.play.internal.distribution.DefaultPlayDistribution) CopySpecInternal(org.gradle.api.internal.file.copy.CopySpecInternal) Sync(org.gradle.api.tasks.Sync) File(java.io.File)

Aggregations

File (java.io.File)2 Task (org.gradle.api.Task)2 CopySpecInternal (org.gradle.api.internal.file.copy.CopySpecInternal)2 AbstractArchiveTask (org.gradle.api.tasks.bundling.AbstractArchiveTask)2 PlayDistribution (org.gradle.play.distribution.PlayDistribution)2 DefaultPlayDistribution (org.gradle.play.internal.distribution.DefaultPlayDistribution)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 InvalidUserCodeException (org.gradle.api.InvalidUserCodeException)1 CopySpec (org.gradle.api.file.CopySpec)1 Sync (org.gradle.api.tasks.Sync)1 CreateStartScripts (org.gradle.api.tasks.application.CreateStartScripts)1 Tar (org.gradle.api.tasks.bundling.Tar)1 Zip (org.gradle.api.tasks.bundling.Zip)1 Jar (org.gradle.jvm.tasks.Jar)1 PlayApplicationBinarySpec (org.gradle.play.PlayApplicationBinarySpec)1