Search in sources :

Example 1 with CreateStartScripts

use of org.gradle.api.tasks.application.CreateStartScripts 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 CreateStartScripts

use of org.gradle.api.tasks.application.CreateStartScripts in project gradle by gradle.

the class ApplicationPlugin method addCreateScriptsTask.

// @Todo: refactor this task configuration to extend a copy task and use replace tokens
private void addCreateScriptsTask() {
    CreateStartScripts startScripts = project.getTasks().create(TASK_START_SCRIPTS_NAME, CreateStartScripts.class);
    startScripts.setDescription("Creates OS specific scripts to run the project as a JVM application.");
    startScripts.setClasspath(project.getTasks().getAt(JavaPlugin.JAR_TASK_NAME).getOutputs().getFiles().plus(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)));
    startScripts.getConventionMapping().map("mainClassName", new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return pluginConvention.getMainClassName();
        }
    });
    startScripts.getConventionMapping().map("applicationName", new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return pluginConvention.getApplicationName();
        }
    });
    startScripts.getConventionMapping().map("outputDir", new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return new File(project.getBuildDir(), "scripts");
        }
    });
    startScripts.getConventionMapping().map("defaultJvmOpts", new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return pluginConvention.getApplicationDefaultJvmArgs();
        }
    });
}
Also used : CreateStartScripts(org.gradle.api.tasks.application.CreateStartScripts) File(java.io.File) GradleException(org.gradle.api.GradleException)

Example 3 with CreateStartScripts

use of org.gradle.api.tasks.application.CreateStartScripts in project spring-boot by spring-projects.

the class RunPluginFeatures method mainClassNameFinder.

private void mainClassNameFinder(Project project) {
    FindMainClassTask findMainClassTask = project.getTasks().create(FIND_MAIN_CLASS_TASK_NAME, FindMainClassTask.class);
    SourceSet mainSourceSet = SourceSets.findMainSourceSet(project);
    if (mainSourceSet != null) {
        findMainClassTask.setMainClassSourceSetOutput(mainSourceSet.getOutput());
    }
    project.getTasks().all(new Action<Task>() {

        @Override
        public void execute(Task task) {
            if (task instanceof BootRunTask || task instanceof CreateStartScripts) {
                task.dependsOn(FIND_MAIN_CLASS_TASK_NAME);
            }
        }
    });
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) Task(org.gradle.api.Task) CreateStartScripts(org.gradle.api.tasks.application.CreateStartScripts)

Aggregations

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