def doParallelClusters()

in vars/asfMainNetBeansBuild.groovy [300:466]


def doParallelClusters(cconfigs) {
    for (cluster in cconfigs) {
        def clustername = cluster[0]
        def path = cluster[1]
        // prepare versionned path
        def versionnedpath = "/${path}/${versionpath}"
        stage("prepare ${clustername}") {
            sh "rm -rf nbbuild/build"
            withAnt(installation: tooling.myAnt) {
                sh "ant build-source-config -Dcluster.config=${clustername} -Dbuildnum=666 -Dmetabuild.branch=${branch}"
                script {
                    def targets = ['verify-libs-and-licenses','rat','build']
                    for (String target in targets) {
                        stage("${target} for ${clustername}") {

                            def localRepo = ".repository"
                            // prepare a clean subfolder target - clustername prefixed
                            sh "rm -rf ${target}-${clustername}-temp && mkdir ${target}-${clustername}-temp && unzip -q nbbuild/build/${clustername}*.zip -d ${target}-${clustername}-temp && cp .gitignore ${env.WORKSPACE}/${target}-${clustername}-temp"
                            def add = "";

                            //
                            if (target=="build" && env.BRANCH_NAME!="release90") {
                                add=" -Ddo.build.windows.launchers=true"
                            }

                            // build the target on the cluster defined common to all
                            sh "ant -f ${target}-${clustername}-temp/build.xml ${target} -Dcluster.config=${clustername} ${add} -Dmetabuild.branch=${branch}"

                            // for verify-libs-and-licenses we only want the reports
                            if (target=='verify-libs-and-licenses') {
                                junit "verify-libs-and-licenses-${clustername}-temp/nbbuild/build/verifylibsandlicenses.xml"
                            }

                            // for rat we only want the reports (junit fail at the moment empty test)
                            if (target=='rat') {
                                // save report and test for rat and verify..
                                archiveArtifacts "rat-${clustername}-temp/nbbuild/build/rat-report.txt"
                                junit testResults: "rat-${clustername}-temp/nbbuild/build/rat/*.xml" , allowEmptyResults:true
                            }

                            // build target is more complex,
                            if (target=='build') {
                                
                               

                                sh "mkdir -p dist${versionnedpath}"
                                // source
                                sh "cp nbbuild/build/*${clustername}*.zip dist${versionnedpath}${path}-${rmversion}-source.zip"
                                // binaries
                                sh "cp build-${clustername}-temp/nbbuild/*${clustername}*.zip dist${versionnedpath}${path}-${rmversion}-bin.zip"

                                // special case for release prepare bits, maven, javadoc installer
                                if (clustername == "release") {

                                    // installer we prepare a folder so that release manager can build mac os on his own
                                    sh "mkdir -p dist${versionnedpath}nbms"
                                    sh "mkdir -p dist/installers"
                                    sh "mkdir -p distpreparation${versionnedpath}installer"
                                    sh "mkdir -p dist/vsix"
                                    if (params.INSTALLERS) { // skip installers unless requested
                                        println "BUILDING INSTALLERS"
                                        def installer =  libraryResource 'org/apache/netbeans/installer.sh'
                                        writeFile file: "distpreparation${versionnedpath}installer/installer.sh", text: installer

                                        def installermac =  libraryResource 'org/apache/netbeans/installermac.sh'
                                        writeFile file: "distpreparation${versionnedpath}installer/installermac.sh", text: installermac

                                        sh "chmod +x distpreparation${versionnedpath}installer/installer.sh"

                                        sh "mkdir -p distpreparation${versionnedpath}installer/nbbuild/newbuild && cp build-${clustername}-temp/nbbuild/newbuild/* distpreparation${versionnedpath}installer/nbbuild/newbuild "
                                        sh "mkdir -p distpreparation${versionnedpath}installer/nbbuild/installer && cp -r build-${clustername}-temp/nbbuild/installer distpreparation${versionnedpath}installer/nbbuild "
                                        sh "mkdir -p distpreparation${versionnedpath}installer/nbi && cp -r build-${clustername}-temp/nbi distpreparation${versionnedpath}installer "
                                        sh "cp build-${clustername}-temp/nbbuild/binaries-default-properties.xml distpreparation${versionnedpath}installer/nbbuild/binaries-default-properties.xml "
                                        sh "mkdir -p distpreparation${versionnedpath}installer/nbbuild/build/ && cp -r build-${clustername}-temp/nbbuild/build/antclasses distpreparation${versionnedpath}installer/nbbuild/build/antclasses "

                                        sh "mkdir -p distpreparation${versionnedpath}installer/nb/ide.launcher && cp -r build-${clustername}-temp/nb/ide.launcher/macosx distpreparation${versionnedpath}installer/nb/ide.launcher "


                                        sh "cp build-${clustername}-temp/nbbuild/*${clustername}*.zip dist${versionnedpath}${path}-${rmversion}-bin.zip"
                                        def binaryfile = "../../../dist${versionnedpath}${path}-${rmversion}-bin.zip"
                                        def timestamp = sh(returnStdout: true, script: 'date +%y%m%d').trim()

                                        sh "cd distpreparation${versionnedpath}installer && ./installer.sh ${binaryfile} ${version} ${timestamp}"
                                        // we archive put to nightlies only exe for window, nbpackage is intended to do the installler
                                        sh "cp distpreparation${versionnedpath}installer/dist/bundles/*.exe dist/installers/ "

                                        sh "rm -rf distpreparation${versionnedpath}installer/dist"
                                        // XXX take too long 18012023 publishToNightlies("/netbeans/candidate/installerspreparation","distpreparation/**/**","distpreparation")

                                        archiveArtifacts 'distpreparation/**'

                                        sh "mkdir -p nbpackage${versionnedpath}installer"
                                        withMaven(maven:tooling.myMaven,jdk:tooling.jdktool,publisherStrategy: 'EXPLICIT',mavenLocalRepo: localRepo,options:[artifactsPublisher(disabled: true)])
                                        {
                                            // unpack nbpackage snapshot can later
                                            sh "mvn org.apache.maven.plugins:maven-dependency-plugin:3.5.0:get  -Dartifact=org.apache.netbeans:nbpackage:${nbpackageversion}:zip:bin -Dmaven.repo.local=${env.WORKSPACE}/.repository -DremoteRepositories=apache.snapshots.https::::https://repository.apache.org/snapshots"
                                            sh "mvn org.apache.maven.plugins:maven-dependency-plugin:3.5.0:unpack -DoutputDirectory=nbpackage${versionnedpath}installer -Dartifact=org.apache.netbeans:nbpackage:${nbpackageversion}:zip:bin -Dmaven.repo.local=${env.WORKSPACE}/.repository -DremoteRepositories=apache.snapshots.https::::https://repository.apache.org/snapshots"

                                            // build installer only deb for testing.
                                            sh "cd nbpackage${versionnedpath}installer/ && nbpackage-${nbpackageversion}/bin/nbpackage -v --type linux-deb -Pname=\"Apache NetBeans\" -Pversion=${debversion} -Purl=\"https://netbeans.apache.org\"  -Pdeb.maintainer=\"NetBeans Mailing List <users@netbeans.apache.org>\"  -Pdeb.desktop-filename=\"apache-netbeans-ide-${rmversion}\"  -Pdeb.wmclass=\"Apache NetBeans IDE ${rmversion}\"  --input ../../../dist${versionnedpath}${path}-${rmversion}-bin.zip "
                                            // debug output
                                            sh "cp nbpackage${versionnedpath}installer/*.deb dist/installers/ "
                                            sh "cd nbpackage${versionnedpath}installer/ && nbpackage-${nbpackageversion}/bin/nbpackage -v --type linux-rpm -Pname=\"Apache NetBeans\" -Pversion=${debversion} -Purl=\"https://netbeans.apache.org\"  -Prpm.desktop-filename=\"apache-netbeans-ide-${rmversion}\"  -Prpm.wmclass=\"Apache NetBeans IDE ${rmversion}\"  --input ../../../dist${versionnedpath}${path}-${rmversion}-bin.zip "
                                            sh "cp nbpackage${versionnedpath}installer/*.rpm dist/installers/ "
                                            // archiveArtifacts "nbpackage${versionnedpath}installer/**"
                                        }

                                    } else {
                                        println "SKIPPING INSTALLER BUILDS"
                                    }


                                    // the installer phase is ok we should have installer for linux / windows + scripts and a bit of source to build macos later


                                    // additionnal target to have maven ready
                                    // javadoc build for maven artefacts, do the more we can using jdk of build.
                                    sh "ant -f build-${clustername}-temp/build.xml build-nbms build-source-zips generate-uc-catalog -Dcluster.config=release -Ddo.build.windows.launchers=true -Dmetabuild.branch=${branch}"
                                    sh "ant -f build-${clustername}-temp/build.xml build-javadoc -Djavadoc.web.root='${apidocurl}' -Dmodules-javadoc-date='${date}' -Datom-date='${atomdate}' -Dmetabuild.branch=${branch}"
                                    sh "cp -r build-${clustername}-temp/nbbuild/nbms/** dist${versionnedpath}nbms/"
                                    
                                    def netbeansbase = "build-${clustername}-temp/nbbuild"
                                    sh "ant -f build-${clustername}-temp/build.xml getallmavencoordinates -Dmetabuild.branch=${branch}"
                                    withMaven(maven:tooling.myMaven,jdk:tooling.jdktool,publisherStrategy: 'EXPLICIT',mavenLocalRepo: localRepo,options:[artifactsPublisher(disabled: true)])
                                    {
                                        sh "mvn org.apache.maven.plugins:maven-dependency-plugin:3.5.0:get -Dartifact=org.apache.netbeans.utilities:nb-repository-plugin:${repopluginversion} -Dmaven.repo.local=${env.WORKSPACE}/.repository -DremoteRepositories=apache.snapshots.https::::https://repository.apache.org/snapshots"
                                        def commonparam = "-Dexternallist=${netbeansbase}/build/external.info"
                                        //sh "mvn org.apache.netbeans.utilities:nb-repository-plugin:1.5:download ${commonparam} -DrepositoryUrl=https://repo.maven.apache.org/maven2"
                                        if (heavyrelease) { // skip mavenrepo for vscode
                                            sh "mvn org.apache.netbeans.utilities:nb-repository-plugin:${repopluginversion}:populate ${commonparam} -DnetbeansNbmDirectory=${netbeansbase}/nbms -DnetbeansInstallDirectory=${netbeansbase}/netbeans -DnetbeansSourcesDirectory=${netbeansbase}/build/source-zips -DnetbeansJavadocDirectory=${netbeansbase}/build/javadoc -DparentGAV=org.apache.netbeans:netbeans-parent:4 -DforcedVersion=${mavenVersion} -DskipInstall=true -DdeployUrl=file://${env.WORKSPACE}/mavenrepository"
                                            zip zipFile:'mavenrepo.zip',dir:'mavenrepository',archive:'true'
                                        }
                                        if (params.VSIX) {
                                            // make vsix available to dist to pickup (only for main release) need a maven setup
                                            println "BUILDING VSCODE PLUGIN"
                                            sh "ant -f build-${clustername}-temp/java/java.lsp.server build-vscode-ext -Dvsix.version=${vsixversion} -Dmetabuild.branch=${branch}"
                                            sh "cp -r build-${clustername}-temp/java/java.lsp.server/build/*.vsix dist/vsix/"
                                        } else {
                                            println "SKIPPING VSCODE PLUGIN"
                                        }
                                    }
                                }

                                // do checksum
                                def extensions = ['*.zip','*.nbm','*.gz','*.jar','*.xml','*.license']
                                for (String extension in extensions) {
                                    sh "cd dist"+' && for z in $(find . -name "'+"${extension}"+'") ; do cd $(dirname $z) ; sha512sum ./$(basename $z) > $(basename $z).sha512; cd - >/dev/null; done '
                                }
                                archiveArtifacts 'dist/**'                             
                            }
                        }
                    }
                }
            }
        }
        stage("publish to nightlies ${versionnedpath}") {
            if (params.NIGHTLIES) {
                println "PUBLISHING TO NIGHTLIES"
                publishToNightlies("/netbeans/candidate/${versionnedpath}","dist${versionnedpath}/*","dist${versionnedpath}")
                publishToNightlies("/netbeans/candidate/installers","dist/installers/*","dist/installers/")
                publishToNightlies("/netbeans/candidate/vsix","build-${clustername}-temp/java/java.lsp.server/build/*.vsix","build-${clustername}-temp/java/java.lsp.server/build")
            } else {
                println "SKIPPING PUBLISH TO NIGHTLIES"
            }
        }
    }
}