Skip to main content
Jump to: navigation, search

TCK:GF GENERIC API INTEGRATION

Revision as of 10:24, 1 July 2019 by Jan.supol.oracle.com (Talk | contribs) (Generic API GF integration script)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This Job creates a glassfish that integrates every Jakarta EE API into a Glassfish. For most API, a GF jar is simply replaced. For EL, JSF, JPA, JSON-P, MAIL, JWS, SAAJ, and JAX-WS, the API is packaged into a respective JAR in Glassfish. The modified JARS are archived with a API MANIFEST.MF and pom files included.

The Pipeline script uses Jenkins Multiline Script Parameter API_URLS, containing one or more links to OSS staging repository:

#!/usr/bin/env groovy

node {
    def GF_URL="http://central.maven.org/maven2/org/glassfish/main/distributions/glassfish/5.1.0/glassfish-5.1.0.zip"
    //def API_URLS=""
    
    MODULES="glassfish5/glassfish/modules"
    env.MODULES="${MODULES}"
    
    stage("Grab and unzip Glassfish") {
        sh '''#!/bin/bash -ex
        
            mkdir -p download
            cd download
            wget -q ${GF_URL} -O glassfish.zip
            
            #unzip
            unzip -q glassfish.zip -d ${WORKSPACE}
            [ -f "${WORKSPACE}/${MODULES}/javax.batch-api.jar" ] && mv ${WORKSPACE}/${MODULES}/javax.batch-api.jar ${WORKSPACE}/${MODULES}/jakarta.batch-api.jar
           '''
    }
    
    stage ("Grab the APis") {
        sh '''#!/bin/bash -ex
    
            mkdir -p download/api
            cd download/api
            while IFS= read -r line; do wget -q $line; done <<< "${API_URLS}"
            
            #strip the api name of RC, SNAPSHOT, and version
            for jarfile in ${WORKSPACE}/download/api/*.jar; do 
               echo $(basename $jarfile) | sed -e 's/-RC[0-9][0-9]*//' | sed -e 's/-SNAPSHOT//' | sed -e 's/-[0-9][0-9]*//' | sed -e 's/\\.[0-9][0-9]*//' | sed -e 's/-[0-9][0-9]*//' | sed -e 's/\\.[0-9][0-9]*//' | sed -e 's/\\.[0-9][0-9]*//' | sed -e 's/-[0-9][0-9]*//' | while IFS= read -r apijarname; do mv -v $(basename $jarfile) $apijarname; done
            done             
            '''            
    }
    
    stage("Simple Replace API") {
        //sh 'mkdir -p ${MODULES}/endorsed'
        copyIfExistAndArchive("endorsed/jakarta.annotation-api.jar")
        copyIfExistAndArchive("jakarta.batch-api.jar")
        copyIfExistAndArchive("jakarta.ejb-api.jar")
        copyIfExistAndArchive("jakarta.enterprise.concurrent-api.jar")
        copyIfExistAndArchive("jakarta.enterprise.deploy-api.jar")
        copyIfExistAndArchive("jakarta.interceptor-api.jar")
        copyIfExistAndArchive("jakarta.jms-api.jar")
        copyIfExistAndArchive("jakarta.json.bind-api.jar")
        copyIfExistAndArchive("jakarta.management.j2ee-api.jar")
        copyIfExistAndArchive("jakarta.resource-api.jar")
        copyIfExistAndArchive("jakarta.security.auth.message-api.jar")
        copyIfExistAndArchive("jakarta.security.enterprise-api.jar")
        copyIfExistAndArchive("jakarta.security.jacc-api.jar")
        copyIfExistAndArchive("jakarta.servlet-api.jar")
        copyIfExistAndArchive("jakarta.servlet.jsp-api.jar")
        copyIfExistAndArchive("jakarta.servlet.jsp.jstl-api.jar")
        copyIfExistAndArchive("jakarta.transaction-api.jar")
        copyIfExistAndArchive("jakarta.websocket-api.jar")
        copyIfExistAndArchive("jakarta.ws.rs-api.jar")
        copyIfExistAndArchive("endorsed/jakarta.xml.bind-api.jar")
        copyIfExistAndArchive("jakarta.xml.registry-api.jar")
        copyIfExistAndArchive("jakarta.xml.rpc-api.jar")
    }
    
    stage("EL") {
        replaceApiInJar("jakarta.el-api.jar", "jakarta.el.jar", "EL")
    }      
    
    stage("JSF") {
        replaceApiInJar("jakarta.faces-api.jar", "jakarta.faces.jar", "JSF")
    }    
    
    stage("JSON-P") {
        replaceApiInJar("jakarta.json-api.jar", "jakarta.json.jar", "JSONP")
    }
    
    stage("JWS") {
        replaceApiInJar("jakarta.jws-api.jar", "endorsed/webservices-api-osgi.jar", "JWS")
    }
    
    stage("Mail") {
         replaceApiInJar("jakarta.mail-api.jar", "jakarta.mail.jar", "Mail")
    }
    
    stage("JPA") {
         replaceApiInJar("jakarta.persistence-api.jar", "jakarta.persistence.jar", "JPA")
    }    
    
    stage("SAAJ") {
         replaceApiInJar("jakarta.xml.soap-api.jar", "endorsed/webservices-api-osgi.jar", "SAAJ")
    }    
    
    stage("JAX-WS") {
         replaceApiInJar("jakarta.xml.ws-api.jar", "endorsed/webservices-api-osgi.jar", "JAXWS")
    }
    
    stage("Archive the GF") {
      sh '''#!/bin/bash -ex
        cd ${WORKSPACE}
        zip -r -q glassfish.zip glassfish5            
       '''
       archiveArtifacts 'glassfish.zip'
    }
}

def copyIfExistAndArchive(String name) {
    env.JAR_NAME=name
    sh '''#!/bin/bash -ex
        if [ -f "download/api/$(basename ${JAR_NAME})" ]; then
           cp -v download/api/$(basename ${JAR_NAME}) ${MODULES}/${JAR_NAME}
        fi
        '''
    archiveArtifacts artifacts: "${MODULES}/${name}", allowEmptyArchive: true        
} 

def replaceApiInJar(String apiJarName, String bundleJarName, String abbreviation) {
    env.API_JAR_NAME=apiJarName
    env.BUNDLE_JAR_NAME=bundleJarName
    env.ABBREVIATION=abbreviation
    if (fileExists("${env.WORKSPACE}/download/api/${apiJarName}")) {
        sh '''#!/bin/bash -ex
            #extract original api
            mkdir ${WORKSPACE}/download/bundlejar
            cd ${WORKSPACE}/download/bundlejar
            jar -xf ${WORKSPACE}/${MODULES}/${BUNDLE_JAR_NAME}
            
            #extract new api
            mkdir ${WORKSPACE}/download/newapi
            cd ${WORKSPACE}/download/newapi
            jar -xf ${WORKSPACE}/download/api/${API_JAR_NAME}
            mv ${WORKSPACE}/download/newapi/META-INF/MANIFEST.MF ${WORKSPACE}/download/newapi/META-INF/MANIFEST.${ABBREVIATION}.MF
            mv ${WORKSPACE}/download/newapi/META-INF/maven ${WORKSPACE}/download/newapi/META-INF/maven.${ABBREVIATION}
            
            #copy the content
            cp -a ${WORKSPACE}/download/newapi/. ${WORKSPACE}/download/bundlejar
            
            #recreate api jar
            cd ${WORKSPACE}/download
            jar cfm $(basename ${BUNDLE_JAR_NAME}) bundlejar/META-INF/MANIFEST.MF -C bundlejar .
            
            #replace the API in GF
            cp $(basename ${BUNDLE_JAR_NAME}) ${WORKSPACE}/${MODULES}/${BUNDLE_JAR_NAME}
            
            mkdir -p ${WORKSPACE}/archive
            cp $(basename ${BUNDLE_JAR_NAME}) ${WORKSPACE}/archive/$(basename ${BUNDLE_JAR_NAME} .jar).${ABBREVIATION}.jar
            
            #cleanup
            rm -rf ${WORKSPACE}/download/newapi
            rm -rf ${WORKSPACE}/download/bundlejar
        '''
        def archiveJarName = sh (
            script: "echo archive/\$(basename \${BUNDLE_JAR_NAME} .jar).\${ABBREVIATION}.jar",
            returnStdout:true
        )
        archiveArtifacts artifacts: "${archiveJarName}"
    }
}

Back to the top