Search in sources :

Example 1 with JavaExec

use of org.gradle.api.tasks.JavaExec in project spring-security by spring-projects.

the class S101Plugin method configure.

private void configure(JavaExec exec) {
    exec.setDescription("Runs Structure101 headless analysis, installing and configuring if necessary");
    exec.dependsOn("check");
    Project project = exec.getProject();
    S101PluginExtension extension = project.getExtensions().getByType(S101PluginExtension.class);
    exec.workingDir(extension.getInstallationDirectory()).classpath(new File(extension.getInstallationDirectory().get(), "structure101-java-build.jar")).args(new File(new File(project.getBuildDir(), "s101"), "config.xml")).systemProperty("s101.label", computeLabel(extension).get()).doFirst((task) -> {
        installAndConfigureIfNeeded(project);
        copyConfigurationToBuildDirectory(extension, project);
    }).doLast((task) -> {
        copyResultsBackToConfigurationDirectory(extension, project);
    });
}
Also used : Files(java.nio.file.Files) Project(org.gradle.api.Project) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) StandardCopyOption(java.nio.file.StandardCopyOption) ByteArrayInputStream(java.io.ByteArrayInputStream) Property(org.gradle.api.provider.Property) JavaExec(org.gradle.api.tasks.JavaExec) Path(java.nio.file.Path) Plugin(org.gradle.api.Plugin) InputStream(java.io.InputStream) Project(org.gradle.api.Project) File(java.io.File)

Example 2 with JavaExec

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

the class FindMainClassTask method findMainClass.

private String findMainClass() {
    Project project = getProject();
    String mainClass = null;
    // Try the SpringBoot extension setting
    SpringBootPluginExtension bootExtension = project.getExtensions().getByType(SpringBootPluginExtension.class);
    if (bootExtension.getMainClass() != null) {
        mainClass = bootExtension.getMainClass();
    }
    ApplicationPluginConvention application = (ApplicationPluginConvention) project.getConvention().getPlugins().get("application");
    if (mainClass == null && application != null) {
        // Try the Application extension setting
        mainClass = application.getMainClassName();
    }
    JavaExec runTask = findRunTask(project);
    if (mainClass == null && runTask != null) {
        mainClass = runTask.getMain();
    }
    if (mainClass == null) {
        Task bootRunTask = project.getTasks().findByName("bootRun");
        if (bootRunTask != null) {
            mainClass = (String) bootRunTask.property("main");
        }
    }
    if (mainClass == null) {
        // Search
        if (this.mainClassSourceSetOutput != null) {
            project.getLogger().debug("Looking for main in: " + this.mainClassSourceSetOutput.getClassesDir());
            try {
                mainClass = MainClassFinder.findSingleMainClass(this.mainClassSourceSetOutput.getClassesDir(), SPRING_BOOT_APPLICATION_CLASS_NAME);
                project.getLogger().info("Computed main class: " + mainClass);
            } catch (IOException ex) {
                throw new IllegalStateException("Cannot find main class", ex);
            }
        }
    }
    project.getLogger().info("Found main: " + mainClass);
    if (bootExtension.getMainClass() == null) {
        bootExtension.setMainClass(mainClass);
    }
    if (application != null && application.getMainClassName() == null) {
        application.setMainClassName(mainClass);
    }
    if (runTask != null && !runTask.hasProperty("main")) {
        runTask.setMain(mainClass);
    }
    return mainClass;
}
Also used : Project(org.gradle.api.Project) Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) JavaExec(org.gradle.api.tasks.JavaExec) SpringBootPluginExtension(org.springframework.boot.gradle.SpringBootPluginExtension) ApplicationPluginConvention(org.gradle.api.plugins.ApplicationPluginConvention) IOException(java.io.IOException)

Example 3 with JavaExec

use of org.gradle.api.tasks.JavaExec in project gradle by gradle.

the class ApplicationPlugin method addRunTask.

private void addRunTask() {
    JavaExec run = project.getTasks().create(TASK_RUN_NAME, JavaExec.class);
    run.setDescription("Runs this project as a JVM application");
    run.setGroup(APPLICATION_GROUP);
    JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
    run.setClasspath(javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath());
    run.getConventionMapping().map("main", new Callable<Object>() {

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

        @Override
        public Object call() throws Exception {
            return pluginConvention.getApplicationDefaultJvmArgs();
        }
    });
}
Also used : JavaExec(org.gradle.api.tasks.JavaExec) UncheckedIOException(org.gradle.api.UncheckedIOException) GradleException(org.gradle.api.GradleException)

Aggregations

JavaExec (org.gradle.api.tasks.JavaExec)3 IOException (java.io.IOException)2 Project (org.gradle.api.Project)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 DefaultTask (org.gradle.api.DefaultTask)1 GradleException (org.gradle.api.GradleException)1 Plugin (org.gradle.api.Plugin)1 Task (org.gradle.api.Task)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 ApplicationPluginConvention (org.gradle.api.plugins.ApplicationPluginConvention)1 Property (org.gradle.api.provider.Property)1 SpringBootPluginExtension (org.springframework.boot.gradle.SpringBootPluginExtension)1