-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LDEV-4845 download latest java and tomcat automatically
- Loading branch information
Showing
3 changed files
with
187 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<cfscript> | ||
tmpDir = getDirectoryFromPath(getCurrentTemplatePath()) & "tmp-installer/"; | ||
log = []; | ||
srcVersion = listToArray( server.system.environment.lucee_version, "." ); | ||
version = listToArray( srcVersion,"." ); | ||
dump(version); | ||
flush; | ||
tomcat_version = "9.0"; | ||
java_version = 11; | ||
if ( version[ 1 ] gt 6 || | ||
(version[ 1 ] gte 6 && version[ 2 ] gte 1 )){ | ||
java_version = 21; | ||
} | ||
if ( version[ 1 ] gt 6 || | ||
(version[ 1 ] gte 6 && version[ 2 ] gte 2 )){ | ||
tomcat_version = "10.1"; | ||
} | ||
logger("Using Java version #java_version# for Lucee #srcVersion#"); | ||
logger("Using Tomcat version #tomcat_version# for Lucee #srcVersion#"); | ||
tomcat = getTomcatVersion( tomcat_version ); | ||
java = getJavaVersion( java_version ); | ||
dump(java); | ||
dump(tomcat); | ||
extractArchive( "zip", java.windows.archive , "jre/jre64-win/jre/" ); | ||
extractArchive( "tgz", java.linux.archive , "jre/jre64-lin/jre/" ); | ||
extractArchive( "zip", tomcat.windows.archive , "src-tomcat/windows/" ); | ||
extractArchive( "tgz", tomcat.linux.archive , "src-tomcat/linux/" ); | ||
directoryDelete( "src-tomcat/linux/webapps", true ); | ||
directoryDelete( "src-tomcat/windows/webapps", true ); | ||
dump( log ); | ||
function extractArchive( format, src, dest ){ | ||
arguments.dest = getDirectoryFromPath(getCurrentTemplatePath()) & "tmp-installer/" & arguments.dest; | ||
var tmpDest = getTempDirectory() & "tmp-installer-" & createUUID() & "/"; | ||
if ( directoryExists( tmpDest ) ) | ||
directoryDelete( tmpDest ); | ||
directoryCreate( tmpdest ); | ||
logger(" extracting [#arguments.src# ] into [#arguments.dest#]" ); | ||
extract( arguments.format, arguments.src, tmpDest ); | ||
var files = directoryList(tmpDest, true); | ||
if ( directoryExists( arguments.dest ) ) | ||
directoryDelete( arguments.dest, true ); | ||
logger("copying [#files[ 1 ]# ] into [#arguments.dest#]" ); | ||
directoryCopy( files[ 1 ], arguments.dest, true ); | ||
directoryDelete( tmpDest, true ); | ||
} | ||
function getTomcatVersion( required string version ){ | ||
var tomcat_metadata = "https://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-core/maven-metadata.xml" | ||
http method="get" url=tomcat_metadata; | ||
var releases = xmlParse(cfhttp.filecontent); | ||
var srcVersions = XmlSearch(releases,"/metadata/versioning/versions/"); | ||
var versions = []; | ||
for (var v in srcVersions[1].xmlChildren ) { | ||
// ignore the m3 type versions | ||
if ( Find( arguments.version, v.xmlText) ==1 | ||
&& listLen(v.xmlText, "." ) eq 3 | ||
&& isNumeric( listLast( v.xmlText, "." ) ) ) { | ||
arrayAppend( versions, listLast( v.xmlText, "." ) ); | ||
} | ||
} | ||
if ( ArrayLen (versions ) ==0 ) | ||
throw "no versions found matching [#arguments.version#]"; | ||
ArraySort( versions, "numeric", "desc" ); | ||
var latest_version = arguments.version & "." & versions[ 1 ]; | ||
var baseUrl = "https://dlcdn.apache.org/tomcat/tomcat-#listFirst(arguments.version,".")#/v#latest_version#/bin/"; | ||
var tomcat = { | ||
"windows": { | ||
"url": baseUrl & "apache-tomcat-" & latest_version & ".zip", | ||
}, | ||
"linux": { | ||
"url": baseUrl & "apache-tomcat-" & latest_version & ".tar.gz", | ||
} | ||
}; | ||
for ( var os in tomcat ){ | ||
var download_url = tomcat[os].url; | ||
var filename = listLast( download_url, "/" ); | ||
http method="get" url=download_url path=getTempDirectory() file=filename; | ||
var info = fileInfo(getTempDirectory() & filename); | ||
logger("downloaded [#info.path#], #numberformat(int(info.size/1024/1024))# Mb"); | ||
tomcat[os]["archive"] = info.path; | ||
} | ||
return tomcat; | ||
} | ||
function getJavaVersion( required string version ){ | ||
var java = { | ||
"windows": { | ||
"api": "https://api.adoptium.net/v3/assets/latest/#java_version#/hotspot?architecture=x64&os=windows&vendor=eclipse" | ||
}, | ||
"linux": { | ||
"api": "https://api.adoptium.net/v3/assets/latest/#java_version#/hotspot?architecture=x64&os=linux&vendor=eclipse" | ||
} | ||
} | ||
for ( os in java ){ | ||
http method="get" url=java[os].api; | ||
java[os]["url"] = getJava( cfhttp.filecontent, "jre", "jdk"); | ||
var download_url = java[os].url; | ||
var filename = listLast( download_url, "/" ); | ||
http method="get" url=download_url path=getTempDirectory() file=filename; | ||
var info = fileInfo(getTempDirectory() & filename); | ||
logger("downloaded [#info.path#], #numberformat(int(info.size/1024/1024))# Mb"); | ||
java[os]["archive"] = info.path; | ||
} | ||
return java; | ||
} | ||
function getJava( json, type, project ){ | ||
var releases = deserializeJSON( arguments.json ); | ||
for ( var r in releases ){ | ||
if ( isStruct(r.binary) | ||
&& r.binary.image_type == arguments.type | ||
&& r.binary.project == arguments.project ) { | ||
return r.binary.package.link; | ||
} | ||
} | ||
throw (message="#arguments.type# and #arguments.project# not found?", detail=arguments.json) | ||
} | ||
function logger( message ){ | ||
systemOutput( arguments.message, true ); | ||
arrayAppend( log, arguments.message ); | ||
} | ||
function writeoutMarkdown( log ){ | ||
fileWrite( server.system.environment.GITHUB_STEP_SUMMARY, ArrayToList( arguments.log, chr( 10 ) ) ); | ||
} | ||
// dump(log); | ||
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters