<commit_before>package install.util

import install.bean.LogSetup
import install.bean.ReportSetup
import install.bean.TaskSetup
import jaemisseo.man.configuration.Config
import jaemisseo.man.configuration.annotation.Inject
import jaemisseo.man.configuration.annotation.method.After
import jaemisseo.man.configuration.annotation.method.Before
import jaemisseo.man.configuration.annotation.type.Task
import jaemisseo.man.configuration.annotation.type.Undoable
import jaemisseo.man.configuration.data.PropertyProvider
import install.task.*
import jaemisseo.man.PropMan
import jaemisseo.man.VariableMan
import jaemisseo.man.util.CommitObject
import jaemisseo.man.util.Util
import org.slf4j.Logger
import org.slf4j.LoggerFactory

/**
 * Created by sujkim on 2017-04-07.
 */
class JobUtil extends TaskUtil{

    final Logger logger = LoggerFactory.getLogger(this.getClass());

    String jobName = this.getClass().simpleName.toLowerCase()
    String commandName = null
    String propertiesFileName = jobName
    String propertiesFileExtension = ''
    File propertiesFile
    String propertyPrefix = ''

    List<Class> validTaskList = []
    List<Class> invalidTaskList = []
    List<Class> allTaskList = Util.findAllClasses('install', [Task])
    List<Class> undoableTaskList = Util.findAllClasses('install', [Undoable])
    List<Class> undoMoreTaskList = [Set, Notice, Command]
//    List<Class> undoableTaskList = [Question, QuestionChoice, QuestionYN, QuestionFindFile, Set, Notice]
//    List<Class> undoMoreTaskList = [Set, Notice]

    def gOpt
    Integer taskResultStatus
    Map<String, List<TaskSetup>> commandNameTaskListMap = [:]



    /*************************
     * - Config: System Controller
     * - PropertyProvider: Data Controller
     *************************/
    Config config
    PropertyProvider provider

    @Inject void setConfig(Config config){ this.config = config }
    @Inject void setProvider(PropertyProvider provider){ this.provider = provider }



    /*************************
     * A thing to do, Before running command.
     *************************/
    @Before
    void before(){
        provider.shift( jobName, propertyPrefix )
    }



    /*************************
     * A thing to do After running command.
     *************************/
    @After
    void after(){
        this.propertyPrefix = ''
    }



    PropMan setupPropMan(PropertyProvider provider){
        String poolName = this.getClass().simpleName.toLowerCase()
        PropMan propman = provider.propGen.get(poolName)
        return propman
    }

    VariableMan setupVariableMan(PropMan propman){
        VariableMan varman = new VariableMan(propman.properties)

        //Analisys Exclusion List (task property)
        List<String> excludeStartsWithList = []
        propman.properties.keySet().each{ String propertyName ->
            if (propertyName.endsWith('.task')){
                List<String> propElementList = propertyName.split('[.]').toList()
                if (propElementList.size() == 3  && getTaskClass(propman[propertyName])){
                    excludeStartsWithList << (propElementList[0..1].join('.') + '.')
                }
            }
        }

        logger.trace( 'PROPERTIES SIZE: ' +propman.properties.size() )
        logger.trace( 'FIRST PARSING EXCLUSION LIST: ' +excludeStartsWithList )

        parsePropMan(propman, varman, excludeStartsWithList)
        setBeforeGetProp(propman, varman)
        return varman
    }

    PropMan setBeforeGetProp(PropMan propmanToSet, VariableMan varman){
        propmanToSet.setBeforeGetProp({ String propertyName, def value ->
            if (value && value instanceof String) {
                String parsedValue = varman.putVariables(propmanToSet.properties).parse(value)
                propmanToSet.set(propertyName, parsedValue)
            }
        })
        return propmanToSet
    }




    //level by level For Task
    protected void eachTaskWithCommit(String commandName, Closure closure){
        eachTaskWithCommit(commandName, 0, closure)
    }

    protected void eachTaskWithCommit(TaskSetup task, Closure closure){
        eachTaskWithCommit(task.commandName, task.propertyPrefix, closure)
    }

    protected void eachTaskWithCommit(String commandName, String propertyPrefix, Closure closure){
        List<TaskSetup> taskList = getTaskListByCommandName(commandName)
        int startIndex = taskList.findIndexOf{ it.propertyPrefix == propertyPrefix }
        eachTaskWithCommit(commandName, startIndex, closure)
    }

    protected void eachTaskWithCommit(String commandName, int startIndex, Closure closure){
        Integer commandDepth = 0
        Integer commandStep = 0
        TaskSetup latestTask
        List<TaskSetup> taskList
        TaskSetup task

        while(true){
            taskList = getTaskListByCommandName(commandName)
            Integer i = startIndex

            /** Run Each Tasks **/
            while(i < taskList.size()){
                task = taskList[i]
                latestTask = (propman.isHeadLast()) ? task : latestTask
                logger.debug "[(${propman.headIndex}: ${commandDepth}-${commandStep}: ${propman.getCommitId()}] ${task.propertyPrefix}"

                //- Do Task
                taskResultStatus = closure(task)

                //- Check Status
                if (taskResultStatus == TaskUtil.STATUS_UNDO_QUESTION){
                    TaskSetup mvTask = undo(task, latestTask)
                    commandName = mvTask.commandName
                    int tempDepth = propman.getCommit()?.customData?.commandDepth ?: 0<commit_msg>refs #44 fix logger level<commit_after>package install.util

import install.bean.LogSetup
import install.bean.ReportSetup
import install.bean.TaskSetup
import jaemisseo.man.configuration.Config
import jaemisseo.man.configuration.annotation.Inject
import jaemisseo.man.configuration.annotation.method.After
import jaemisseo.man.configuration.annotation.method.Before
import jaemisseo.man.configuration.annotation.type.Task
import jaemisseo.man.configuration.annotation.type.Undoable
import jaemisseo.man.configuration.data.PropertyProvider
import install.task.*
import jaemisseo.man.PropMan
import jaemisseo.man.VariableMan
import jaemisseo.man.util.CommitObject
import jaemisseo.man.util.Util
import org.slf4j.Logger
import org.slf4j.LoggerFactory

/**
 * Created by sujkim on 2017-04-07.
 */
class JobUtil extends TaskUtil{

    final Logger logger = LoggerFactory.getLogger(this.getClass());

    String jobName = this.getClass().simpleName.toLowerCase()
    String commandName = null
    String propertiesFileName = jobName
    String propertiesFileExtension = ''
    File propertiesFile
    String propertyPrefix = ''

    List<Class> validTaskList = []
    List<Class> invalidTaskList = []
    List<Class> allTaskList = Util.findAllClasses('install', [Task])
    List<Class> undoableTaskList = Util.findAllClasses('install', [Undoable])
    List<Class> undoMoreTaskList = [Set, Notice, Command]
//    List<Class> undoableTaskList = [Question, QuestionChoice, QuestionYN, QuestionFindFile, Set, Notice]
//    List<Class> undoMoreTaskList = [Set, Notice]

    def gOpt
    Integer taskResultStatus
    Map<String, List<TaskSetup>> commandNameTaskListMap = [:]



    /*************************
     * - Config: System Controller
     * - PropertyProvider: Data Controller
     *************************/
    Config config
    PropertyProvider provider

    @Inject void setConfig(Config config){ this.config = config }
    @Inject void setProvider(PropertyProvider provider){ this.provider = provider }



    /*************************
     * A thing to do, Before running command.
     *************************/
    @Before
    void before(){
        provider.shift( jobName, propertyPrefix )
    }



    /*************************
     * A thing to do After running command.
     *************************/
    @After
    void after(){
        this.propertyPrefix = ''
    }



    PropMan setupPropMan(PropertyProvider provider){
        String poolName = this.getClass().simpleName.toLowerCase()
        PropMan propman = provider.propGen.get(poolName)
        return propman
    }

    VariableMan setupVariableMan(PropMan propman){
        VariableMan varman = new VariableMan(propman.properties)

        //Analisys Exclusion List (task property)
        List<String> excludeStartsWithList = []
        propman.properties.keySet().each{ String propertyName ->
            if (propertyName.endsWith('.task')){
                List<String> propElementList = propertyName.split('[.]').toList()
                if (propElementList.size() == 3  && getTaskClass(propman[propertyName])){
                    excludeStartsWithList << (propElementList[0..1].join('.') + '.')
                }
            }
        }

        logger.trace( 'PROPERTIES SIZE: ' +propman.properties.size() )
        logger.trace( 'FIRST PARSING EXCLUSION LIST: ' +excludeStartsWithList )

        parsePropMan(propman, varman, excludeStartsWithList)
        setBeforeGetProp(propman, varman)
        return varman
    }

    PropMan setBeforeGetProp(PropMan propmanToSet, VariableMan varman){
        propmanToSet.setBeforeGetProp({ String propertyName, def value ->
            if (value && value instanceof String) {
                String parsedValue = varman.putVariables(propmanToSet.properties).parse(value)
                propmanToSet.set(propertyName, parsedValue)
            }
        })
        return propmanToSet
    }




    //level by level For Task
    protected void eachTaskWithCommit(String commandName, Closure closure){
        eachTaskWithCommit(commandName, 0, closure)
    }

    protected void eachTaskWithCommit(TaskSetup task, Closure closure){
        eachTaskWithCommit(task.commandName, task.propertyPrefix, closure)
    }

    protected void eachTaskWithCommit(String commandName, String propertyPrefix, Closure closure){
        List<TaskSetup> taskList = getTaskListByCommandName(commandName)
        int startIndex = taskList.findIndexOf{ it.propertyPrefix == propertyPrefix }
        eachTaskWithCommit(commandName, startIndex, closure)
    }

    protected void eachTaskWithCommit(String commandName, int startIndex, Closure closure){
        Integer commandDepth = 0
        Integer commandStep = 0
        TaskSetup latestTask
        List<TaskSetup> taskList
        TaskSetup task

        while(true){
            taskList = getTaskListByCommandName(commandName)
            Integer i = startIndex

            /** Run Each Tasks **/
            while(i < taskList.size()){
                task = taskList[i]
                latestTask = (propman.isHeadLast()) ? task : latestTask
                logger.trace "[${propman.headIndex}:${commandDepth}-${commandStep}] ${task.propertyPrefix}  (${propman.getCommitId()})"

                //- Do Task
                taskResultStatus = closure(task)

                //- Check Status
                if (taskResultStatus == TaskUtil.STATUS_UNDO_QUESTION){
                    TaskSetup mvTask = undo(task, latestTask)
                    commandName = mvTask.commandName
                    int tempDepth = propman.getCommit()?.customData?.commandDepth ?: 0
{'fraction_non_alphanumeric': 0.11726529160739688, 'fraction_numerical': 0.003200568990042674, 'mean_word_length': 2.9679012345679014, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1678098', 'n_tokens_mistral': 3068, 'n_tokens_neox': 2947, 'n_words': 656}