<commit_before>/*
* Copyright 2013 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fi.jasoft.plugin.tasks;

import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.plugins.WarPluginConvention;
import org.gradle.api.file.FileCollection;

public class RunTask extends DefaultTask {

    public RunTask(){
        dependsOn(project.tasks.widgetset)
        dependsOn(project.tasks.themes)
        description = 'Runs the Vaadin application on an embedded Jetty Server'
    }

    @TaskAction
    public void run() {       
        File webAppDir = project.convention.getPlugin(WarPluginConvention).webAppDir
        FileCollection cp = project.configurations.jetty8 + 
                    project.configurations.providedCompile + 
                    project.configurations.compile +
                    project.sourceSets.main.runtimeClasspath +
                    project.sourceSets.main.compileClasspath

        File logDir = new File('build/jetty/')
        logDir.mkdirs()


        def appServerProcess = ['java']
        
        // Debug
        appServerProcess.add("-Xrunjdwp:transport=dt_socket,address=${project.vaadin.debugPort},server=y,suspend=n")
        appServerProcess.add('-Xdebug')

        // JVM options
        appServerProcess.add('-cp')
        appServerProcess.add(cp.getAsPath())  
        
        if(project.vaadin.jvmArgs != null){
            appServerProcess.addAll(project.vaadin.jvmArgs)
        }      

        // Program args
        appServerProcess.add('org.mortbay.jetty.runner.Runner')

        appServerProcess.add('--port')
        appServerProcess.add(project.vaadin.serverPort)

        appServerProcess.add('--out')
        appServerProcess.add(logDir.canonicalPath + '/jetty8-vaadinRun.log')

        appServerProcess.add('--log')
        appServerProcess.add(logDir.canonicalPath + '/jetty8-vaadinRun.log')

        appServerProcess.add(webAppDir.canonicalPath)

        appServerProcess = appServerProcess.execute()

        println "Application running on http://0.0.0.0:${project.vaadin.serverPort} (debugger on ${project.vaadin.debugPort})"
   
        // Wait for termination signal
        System.console().readLine("\nPress [Enter] to stop server...")

        // Terminate server
        appServerProcess.in.close()
        appServerProcess.out.close()
        appServerProcess.err.close()
        appServerProcess.destroy()
        appServerProcess = null;
    }
}<commit_msg>Added check that a console is available when executing the vaadinRun task. #14<commit_after>/*
* Copyright 2013 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fi.jasoft.plugin.tasks;

import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.plugins.WarPluginConvention;
import org.gradle.api.file.FileCollection;

public class RunTask extends DefaultTask {

    public RunTask(){
        dependsOn(project.tasks.widgetset)
        dependsOn(project.tasks.themes)
        description = 'Runs the Vaadin application on an embedded Jetty Server'
    }

    @TaskAction
    public void run() {       
        File webAppDir = project.convention.getPlugin(WarPluginConvention).webAppDir
        FileCollection cp = project.configurations.jetty8 + 
                    project.configurations.providedCompile + 
                    project.configurations.compile +
                    project.sourceSets.main.runtimeClasspath +
                    project.sourceSets.main.compileClasspath

        File logDir = new File('build/jetty/')
        logDir.mkdirs()


        def appServerProcess = ['java']
        
        // Debug
        appServerProcess.add("-Xrunjdwp:transport=dt_socket,address=${project.vaadin.debugPort},server=y,suspend=n")
        appServerProcess.add('-Xdebug')

        // JVM options
        appServerProcess.add('-cp')
        appServerProcess.add(cp.getAsPath())  
        
        if(project.vaadin.jvmArgs != null){
            appServerProcess.addAll(project.vaadin.jvmArgs)
        }      

        // Program args
        appServerProcess.add('org.mortbay.jetty.runner.Runner')

        appServerProcess.add('--port')
        appServerProcess.add(project.vaadin.serverPort)

        appServerProcess.add('--out')
        appServerProcess.add(logDir.canonicalPath + '/jetty8-vaadinRun.log')

        appServerProcess.add('--log')
        appServerProcess.add(logDir.canonicalPath + '/jetty8-vaadinRun.log')

        appServerProcess.add(webAppDir.canonicalPath)

        appServerProcess = appServerProcess.execute()

        println "Application running on http://0.0.0.0:${project.vaadin.serverPort} (debugger on ${project.vaadin.debugPort})"
   
        // Wait for termination signal
        def console = System.console()
        if(console){
             console.readLine("\nPress [Enter] to stop server...")
        } else {
            logger.error("Cannot get console, is a console available? Server is stopping...")
        }

        // Terminate server
        appServerProcess.in.close()
        appServerProcess.out.close()
        appServerProcess.err.close()
        appServerProcess.destroy()
        appServerProcess = null;
    }
}
{'fraction_non_alphanumeric': 0.10090119085934986, 'fraction_numerical': 0.005149662053427744, 'mean_word_length': 2.6950059453032105, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6032687', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1668, 'n_words': 391}