<commit_before>/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you 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 org.codehaus.mojo.selenium

import org.codehaus.mojo.groovy.GroovyMojoSupport

import org.apache.maven.project.MavenProject

/**
 * Starts an Xvfb instance suitable for handling X11 displays for headless systems.
 * Use this in combonation with the <tt>start-server</tt> goal to allow browsers
 * to be launched on headless unix systems.
 *
 * @goal xvfb
 *
 * @version $Id$
 */
class XvfbMojo
    extends GroovyMojoSupport
{
    /**
     * The Xvfb command to execute.
     *
     * @parameter default-value="Xvfb"
     * @required
     */
    String executable
    
    //
    // TODO: See if we need default options [ '-screen', '0', '1024x768x24' ]
    //
    
    /**
     * A list of additional options to pass to the Xvfb process.
     *
     * @parameter
     */
    String[] options
    
    /**
     * The location of the file to write the display properties which will be picked up
     * by the <tt>start-server</tt> goal.
     *
     * @parameter default-value="${project.build.directory}/selenium/display.properties"
     * @required
     */
    File displayPropertiesFile
    
    /**
     * Enable logging mode.
     *
     * @parameter expression="${logOutput}" default-value="false"
     */
    boolean logOutput

    /**
     * The file that Xvfb output will be written to.
     *
     * @parameter expression="${logFile}" default-value="${project.build.directory}/selenium/xvfb.log"
     * @required
     */
    File logFile
    
    /**
     * Flag to control if we background the process or block Maven execution.
     *
     * @parameter default-value="false"
     * @required
     */
    boolean background
    
    //
    // Components
    //
    
    /**
     * @parameter expression="${project}"
     * @required
     * @readonly
     */
    MavenProject project

    //
    // Mojo
    //

    void execute() {
        log.info('Starting Xvfb...')
        
        // Figure out what the display number is, and generate the properties file
        def display = ':1'
        ant.mkdir(dir: displayPropertiesFile.parentFile)
        def props = new Properties()
        props['DISPLAY'] = "$display"
        props.store(displayPropertiesFile, 'Xvfb Display Properties')
        
        if (logOutput) {
            ant.mkdir(dir: logFile.parentFile)
        }
        
        // Holds any exception that was thrown during startup
        def errors = []
        
        def runner = {
            try {
                ant.exec(executable: executable, failonerror: true) {
                    if (logOutput) {
                        log.info("Redirecting output to: $logFile")<commit_msg>Log some info<commit_after>/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you 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 org.codehaus.mojo.selenium

import org.codehaus.mojo.groovy.GroovyMojoSupport

import org.apache.maven.project.MavenProject

/**
 * Starts an Xvfb instance suitable for handling X11 displays for headless systems.
 * Use this in combonation with the <tt>start-server</tt> goal to allow browsers
 * to be launched on headless unix systems.
 *
 * @goal xvfb
 *
 * @version $Id$
 */
class XvfbMojo
    extends GroovyMojoSupport
{
    /**
     * The Xvfb command to execute.
     *
     * @parameter default-value="Xvfb"
     * @required
     */
    String executable
    
    //
    // TODO: See if we need default options [ '-screen', '0', '1024x768x24' ]
    //
    
    /**
     * A list of additional options to pass to the Xvfb process.
     *
     * @parameter
     */
    String[] options
    
    /**
     * The location of the file to write the display properties which will be picked up
     * by the <tt>start-server</tt> goal.
     *
     * @parameter default-value="${project.build.directory}/selenium/display.properties"
     * @required
     */
    File displayPropertiesFile
    
    /**
     * Enable logging mode.
     *
     * @parameter expression="${logOutput}" default-value="false"
     */
    boolean logOutput

    /**
     * The file that Xvfb output will be written to.
     *
     * @parameter expression="${logFile}" default-value="${project.build.directory}/selenium/xvfb.log"
     * @required
     */
    File logFile
    
    /**
     * Flag to control if we background the process or block Maven execution.
     *
     * @parameter default-value="false"
     * @required
     */
    boolean background
    
    //
    // Components
    //
    
    /**
     * @parameter expression="${project}"
     * @required
     * @readonly
     */
    MavenProject project

    //
    // Mojo
    //

    void execute() {
        log.info('Starting Xvfb...')
        
        // Figure out what the display number is, and generate the properties file
        def display = ':1'
        log.info("Using display: $display")
        
        ant.mkdir(dir: displayPropertiesFile.parentFile)
        def props = new Properties()
        props['DISPLAY'] = "$display"
        props.store(displayPropertiesFile, 'Xvfb Display Properties')
        
        if (logOutput) {
            ant.mkdir(dir: logFile.parentFile)
        }
        
        // Holds any exception that was thrown during startup
        def errors = []
        
        def runner = {
            try {
                ant.exec(executable: executable, failonerror: true) {
                    if (logOutput) {
                        log.info("Redirecting output to: $logFile")
{'fraction_non_alphanumeric': 0.0961180346655207, 'fraction_numerical': 0.004870362412261854, 'mean_word_length': 2.1823154056517775, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, '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': '675394', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1908, 'n_words': 646}