<commit_before>import groovy.json.JsonSlurper

{ ->
    node {
        git url: '<EMAIL>:gravitee-io/release.git', branch: "master"
        def releaseJSON = readFile encoding: 'UTF-8', file: 'release.json'

        if (dryRun) {
            println("\n    ##################################" +
                    "\n    #                                #" +
                    "\n    #          DRY RUN MODE          #" +
                    "\n    #                                #" +
                    "\n    ##################################")
        }

        GraviteeIO graviteeIO = new GraviteeIO(parseJson(releaseJSON))

        Component[] componentsToRelease = filteredComponentsToRelease(graviteeIO)
        releaseComponents(componentsToRelease, graviteeIO.buildDependencies, dryRun)
    }
}()

@NonCPS
def parseJson(json) {
    def jsonSlurper = new JsonSlurper()
    def obj = jsonSlurper.parseText(json)
    obj
}

def filteredComponentsToRelease(GraviteeIO graviteeIO) {
    def snapshots = []
    def snapshotsPrintList = "\n"
    for ( int i = 0; i < graviteeIO.components.size(); i++ ) {
        if ( graviteeIO.components[i].version.snapshot ) {
            snapshots.add(graviteeIO.components[i])
            snapshotsPrintList += "     - ${graviteeIO.components[i].name} (${graviteeIO.components[i].version.toString()})\n"
        }
    }
    println("\n    ${snapshots.size()} components need to be released : ${snapshotsPrintList} \n")
    if ( !dryRun ) {
        input "\n    Do you want to release them ?"
    }
    snapshots
}

def releaseComponents(componentsToRelease, buildDependencies, dryRun) {
    if ( componentsToRelease == null || componentsToRelease.size() == 0 )
        return

    def componentsToReleaseAsMap = new LinkedHashMap()
    for ( int i = 0; i < componentsToRelease.size(); i++ ) {
        componentsToReleaseAsMap.put(componentsToRelease[i].name, componentsToRelease[i])
    }

    def parallelBuildGroup = new ArrayList()
    for ( int i = 0; i < buildDependencies.size(); i++ ) {
        def components = new ArrayList()
        for ( int j = 0; j < buildDependencies[i].size(); j++ ) {
            if ( componentsToReleaseAsMap.containsKey(buildDependencies[i][j]) ) {
                components.add(componentsToReleaseAsMap[buildDependencies[i][j]])
            }
        }
        if ( components.size() > 0 ) {
            parallelBuildGroup.add(components)
        }
    }

    for ( int i = 0; i < parallelBuildGroup.size(); i++ ) {
        releaseMavenProject(parallelBuildGroup[i], dryRun)
    }
}

def releaseMavenProject(components, dryRun) {
    def componentListToPrint = ""
    def parallelBuild = [:]

    for ( int i = 0; i < components.size(); i++ ) {
        def c = components[i]
        componentListToPrint += "\n    - ${c.name}"

        parallelBuild[c.name] = {
            def scmUrl = "<EMAIL>:gravitee-io/${c.name}.git"
            node {
                println("\n    scmUrl = ${scmUrl}" +
                        "\n    releaseVersion = ${c.version.releaseVersion()}" +
                        "\n    nextSnapshot = ${c.version.nextMinorSnapshotVersion()}")

                sh 'rm -rf *'
                sh 'rm -rf .git'

                def mvnHome = tool 'Maven 3.2.2'
                def javaHome = tool 'JDK 8'

                withEnv(["PATH+MAVEN=${mvnHome}/bin", "HOME=/root", "JAVA_HOME=${javaHome}"]) {

                    git url: scmUrl, credentialsId: 'ce<PASSWORD>'

                    // set version
                    sh "mvn -B versions:set -DnewVersion=${c.version.releaseVersion()} -DgenerateBackupPoms=false"

                    // use release version of each -SNAPSHOT gravitee artifact
                    sh "mvn -B -U versions:update-properties -Dincludes=io.gravitee.*:* -DgenerateBackupPoms=false"

                    // deploy
                    if ( dryRun ) {
                        sh "cat pom.xml"
                        sh "mvn -B -U clean install"
                    } else {<commit_msg>fix(release): add node tool<commit_after>import groovy.json.JsonSlurper

{ ->
    node {
        git url: '<EMAIL>:gravitee-io/release.git', branch: "master"
        def releaseJSON = readFile encoding: 'UTF-8', file: 'release.json'

        if (dryRun) {
            println("\n    ##################################" +
                    "\n    #                                #" +
                    "\n    #          DRY RUN MODE          #" +
                    "\n    #                                #" +
                    "\n    ##################################")
        }

        GraviteeIO graviteeIO = new GraviteeIO(parseJson(releaseJSON))

        Component[] componentsToRelease = filteredComponentsToRelease(graviteeIO)
        releaseComponents(componentsToRelease, graviteeIO.buildDependencies, dryRun)
    }
}()

@NonCPS
def parseJson(json) {
    def jsonSlurper = new JsonSlurper()
    def obj = jsonSlurper.parseText(json)
    obj
}

def filteredComponentsToRelease(GraviteeIO graviteeIO) {
    def snapshots = []
    def snapshotsPrintList = "\n"
    for ( int i = 0; i < graviteeIO.components.size(); i++ ) {
        if ( graviteeIO.components[i].version.snapshot ) {
            snapshots.add(graviteeIO.components[i])
            snapshotsPrintList += "     - ${graviteeIO.components[i].name} (${graviteeIO.components[i].version.toString()})\n"
        }
    }
    println("\n    ${snapshots.size()} components need to be released : ${snapshotsPrintList} \n")
    if ( !dryRun ) {
        input "\n    Do you want to release them ?"
    }
    snapshots
}

def releaseComponents(componentsToRelease, buildDependencies, dryRun) {
    if ( componentsToRelease == null || componentsToRelease.size() == 0 )
        return

    def componentsToReleaseAsMap = new LinkedHashMap()
    for ( int i = 0; i < componentsToRelease.size(); i++ ) {
        componentsToReleaseAsMap.put(componentsToRelease[i].name, componentsToRelease[i])
    }

    def parallelBuildGroup = new ArrayList()
    for ( int i = 0; i < buildDependencies.size(); i++ ) {
        def components = new ArrayList()
        for ( int j = 0; j < buildDependencies[i].size(); j++ ) {
            if ( componentsToReleaseAsMap.containsKey(buildDependencies[i][j]) ) {
                components.add(componentsToReleaseAsMap[buildDependencies[i][j]])
            }
        }
        if ( components.size() > 0 ) {
            parallelBuildGroup.add(components)
        }
    }

    for ( int i = 0; i < parallelBuildGroup.size(); i++ ) {
        releaseMavenProject(parallelBuildGroup[i], dryRun)
    }
}

def releaseMavenProject(components, dryRun) {
    def componentListToPrint = ""
    def parallelBuild = [:]

    for ( int i = 0; i < components.size(); i++ ) {
        def c = components[i]
        componentListToPrint += "\n    - ${c.name}"

        parallelBuild[c.name] = {
            def scmUrl = "<EMAIL>:gravitee-io/${c.name}.git"
            node {
                println("\n    scmUrl = ${scmUrl}" +
                        "\n    releaseVersion = ${c.version.releaseVersion()}" +
                        "\n    nextSnapshot = ${c.version.nextMinorSnapshotVersion()}")

                sh 'rm -rf *'
                sh 'rm -rf .git'

                def mvnHome = tool 'Maven 3.2.2'
                def javaHome = tool 'JDK 8'
                def nodeHome = tool 'NodeJS 0.12.4'

                withEnv(["PATH+MAVEN=${mvnHome}/bin+NODE=${nodeHome}/bin", "HOME=/root", "JAVA_HOME=${javaHome}"]) {

                    git url: scmUrl, credentialsId: '<KEY>'

                    // set version
                    sh "mvn -B versions:set -DnewVersion=${c.version.releaseVersion()} -DgenerateBackupPoms=false"

                    // use release version of each -SNAPSHOT gravitee artifact
                    sh "mvn -B -U versions:update-properties -Dincludes=io.gravitee.*:* -DgenerateBackupPoms=false"

                    // deploy
                    if ( dryRun ) {
                        sh "cat pom.xml"
                        sh "mvn -B -U clean install"
                    } else {
{'fraction_non_alphanumeric': 0.1401132725929574, 'fraction_numerical': 0.0036936715094804235, 'mean_word_length': 1.8551845342706503, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3054432', 'n_tokens_mistral': 2436, 'n_tokens_neox': 2300, 'n_words': 494}