<commit_before>import groovy.transform.BaseScript
@BaseScript SharedFunctions mainScript

def spoonizeTemplate = jenkinsApi.getXmlText('/job/Template-Spoonize-Release/config.xml')
def testTemplate = jenkinsApi.getXmlText('/job/Template-Test-Spoonized-Release/config.xml')
def BuildTriggerConfig = jenkinsApi.getXmlText('/job/Template-Trigger-MavenUpdate/config.xml')

itemsToBuild = readAllProjects()

println "We are going to build: "

itemsToBuild.each{
    println "- "+it
}


def newSpoonizeJobs = itemsToBuild.collect { info ->
    def xml = buildSpoonizeXml(info,spoonizeTemplate)
    [xml:xml,info:info]
}

def newTestJobs = itemsToBuild.collect { info ->
    def xml = buildTestXml(info,testTemplate)
    [xml:xml,info:info]
}

def newSpecialTrigger = itemsToBuild.collect { info ->
    def xml = buildTriggerXml(info,BuildTriggerConfig)
    [xml:xml,info:info]
}


println "Posting spoonize jobs now"

newSpoonizeJobs.each {
    jenkinsApi.updateOrCreateJob(it.info.spoonizeProjectName(),it.xml)
}

println "Posting testing jobs now"
newTestJobs.each {
    jenkinsApi.updateOrCreateJob(it.info.testProjectName(),it.xml)
}

println "Posting additional trigger jobs now"
newSpecialTrigger.each {
    jenkinsApi.updateOrCreateJob(it.info.triggerProjectName(),it.xml)
}

println "Trigger build job now"
newSpoonizeJobs.each {
    jenkinsApi.postText("job/${it.info.spoonizeProjectName()}/build","")
}
println "Done. Building now"

def buildSpoonizeXml(BuildInfo projectInfo, theTemplate){
    println "Building Spoonizing Job for: "+projectInfo
    def configXml = new XmlSlurper().parseText( theTemplate )

    baseXmlSetup(configXml, projectInfo)

    configXml.assignedNode = projectInfo.platform+"-spoonizer"

    def batchFile = tagByName(configXml,"hudson.tasks.BatchFile")
    batchFile.command = copyInSpoonizeCommand(projectInfo,"spoonize-project-template.bat");

    def nextJob = tagByName(configXml,"hudson.plugins.parameterizedtrigger.BuildTriggerConfig")
    nextJob.projects = projectInfo.testProjectName()

    configXml
}

def baseXmlSetup(templateXml, BuildInfo projectInfo) {
    templateXml.disabled = "false"

    def gitConfig = tagByName(templateXml, "hudson.plugins.git.UserRemoteConfig")
    gitConfig.url = gitUrl()

    def email = tagByName(templateXml, "hudson.tasks.Mailer")
    email.recipients = projectInfo.email
}

def buildTestXml(BuildInfo projectInfo, theTemplate){
    println "Building Test Job for: "+projectInfo
    def configXml = new XmlSlurper().parseText(theTemplate )

    baseXmlSetup(configXml, projectInfo)

    def batchFile = tagByName(configXml,"hudson.tasks.BatchFile")
    batchFile.command = copyInSpoonizeCommand(projectInfo,"test-project-template.bat");


    def testMachines = tagByName(configXml,"org.jenkinsci.plugins.elasticaxisplugin.ElasticAxis")
    testMachines.label = projectInfo.platform+"-test"

    configXml
}

def buildTriggerXml(BuildInfo projectInfo, theTemplate){
    println "Building Trigger Job for: "+projectInfo
    def configXml = new XmlSlurper().parseText(theTemplate )

    baseXmlSetup(configXml, projectInfo)

    def nextJob = tagByName(configXml,"hudson.plugins.parameterizedtrigger.BuildTriggerConfig")
    nextJob.projects = projectInfo.spoonizeProjectName()

    configXml
}

def copyInSpoonizeCommand(BuildInfo projectInfo,String templateName){
    def possiblePlaces = [
        new File("../scripts/src/$templateName"),
        new File("./scripts/src/$templateName"),
        new File("./src/$templateName")
    ]

    def scriptFile = possiblePlaces.find {it.exists()}
    def text = scriptFile.getText("UTF-8")
    text.replace("{namespace}",projectInfo.namespace)
        .replace("{repo-name}",projectInfo.name)
        .replace("{version}",projectInfo.versionInfo.versionTag)
        .replace("{working-directory}",projectInfo.workingDirectory)
}
<commit_msg>No trigger info needed<commit_after>import groovy.transform.BaseScript
@BaseScript SharedFunctions mainScript

def spoonizeTemplate = jenkinsApi.getXmlText('/job/Template-Spoonize-Release/config.xml')
def testTemplate = jenkinsApi.getXmlText('/job/Template-Test-Spoonized-Release/config.xml')
def BuildTriggerConfig = jenkinsApi.getXmlText('/job/Template-Trigger-MavenUpdate/config.xml')

itemsToBuild = readAllProjects()

println "We are going to build: "

itemsToBuild.each{
    println "- "+it
}


def newSpoonizeJobs = itemsToBuild.collect { info ->
    def xml = buildSpoonizeXml(info,spoonizeTemplate)
    [xml:xml,info:info]
}

def newTestJobs = itemsToBuild.collect { info ->
    def xml = buildTestXml(info,testTemplate)
    [xml:xml,info:info]
}

def newSpecialTrigger = itemsToBuild.collect { info ->
    def xml = buildTriggerXml(info,BuildTriggerConfig)
    [xml:xml,info:info]
}


println "Posting spoonize jobs now"

newSpoonizeJobs.each {
    jenkinsApi.updateOrCreateJob(it.info.spoonizeProjectName(),it.xml)
}

println "Posting testing jobs now"
newTestJobs.each {
    jenkinsApi.updateOrCreateJob(it.info.testProjectName(),it.xml)
}

println "Posting additional trigger jobs now"
newSpecialTrigger.each {
    jenkinsApi.updateOrCreateJob(it.info.triggerProjectName(),it.xml)
}

println "Trigger build job now"
newSpoonizeJobs.each {
    jenkinsApi.postText("job/${it.info.spoonizeProjectName()}/build","")
}
println "Done. Building now"

def buildSpoonizeXml(BuildInfo projectInfo, theTemplate){
    println "Building Spoonizing Job for: "+projectInfo
    def configXml = new XmlSlurper().parseText( theTemplate )

    baseXmlSetup(configXml, projectInfo)

    configXml.assignedNode = projectInfo.platform+"-spoonizer"

    def batchFile = tagByName(configXml,"hudson.tasks.BatchFile")
    batchFile.command = copyInSpoonizeCommand(projectInfo,"spoonize-project-template.bat");

    def nextJob = tagByName(configXml,"hudson.plugins.parameterizedtrigger.BuildTriggerConfig")
    nextJob.projects = projectInfo.testProjectName()

    configXml
}

def baseXmlSetup(templateXml, BuildInfo projectInfo) {
    templateXml.disabled = "false"

    def gitConfig = tagByName(templateXml, "hudson.plugins.git.UserRemoteConfig")
    gitConfig.url = gitUrl()

    def email = tagByName(templateXml, "hudson.tasks.Mailer")
    email.recipients = projectInfo.email
}

def buildTestXml(BuildInfo projectInfo, theTemplate){
    println "Building Test Job for: "+projectInfo
    def configXml = new XmlSlurper().parseText(theTemplate )

    baseXmlSetup(configXml, projectInfo)

    def batchFile = tagByName(configXml,"hudson.tasks.BatchFile")
    batchFile.command = copyInSpoonizeCommand(projectInfo,"test-project-template.bat");


    def testMachines = tagByName(configXml,"org.jenkinsci.plugins.elasticaxisplugin.ElasticAxis")
    testMachines.label = projectInfo.platform+"-test"

    configXml
}

def buildTriggerXml(BuildInfo projectInfo, theTemplate){
    println "Building Trigger Job for: "+projectInfo
    def configXml = new XmlSlurper().parseText(theTemplate )

    baseXmlSetup(configXml, projectInfo)

    configXml
}

def copyInSpoonizeCommand(BuildInfo projectInfo,String templateName){
    def possiblePlaces = [
        new File("../scripts/src/$templateName"),
        new File("./scripts/src/$templateName"),
        new File("./src/$templateName")
    ]

    def scriptFile = possiblePlaces.find {it.exists()}
    def text = scriptFile.getText("UTF-8")
    text.replace("{namespace}",projectInfo.namespace)
        .replace("{repo-name}",projectInfo.name)
        .replace("{version}",projectInfo.versionInfo.versionTag)
        .replace("{working-directory}",projectInfo.workingDirectory)
}

{'fraction_non_alphanumeric': 0.11285431773236651, 'fraction_numerical': 0.00026367831245880025, 'mean_word_length': 4.921935987509758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 30}, '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': '5188071', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2299, 'n_words': 402}