-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mbt-upgrade-maven-builder-default-command' of https://g…
…ithub.com/SAP/cloud-mta-build-tool into mbt-upgrade-maven-builder-default-command
- Loading branch information
Showing
7 changed files
with
352 additions
and
748 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 |
---|---|---|
|
@@ -39,7 +39,6 @@ Dockerfile | |
|
||
integration/testdata/mta_demo/mta_archives/ | ||
docs/site | ||
bin | ||
.npmrc | ||
unpacked_bin | ||
test/goos/goos.yaml |
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,33 @@ | ||
#!/usr/bin/env node | ||
var path = require("path"); | ||
var spawn = require("child_process").spawn; | ||
var fs = require("fs"); | ||
|
||
var os = process.env.BINWRAP_PLATFORM || process.platform; | ||
var arch = process.env.BINWRAP_ARCH || process.arch; | ||
|
||
var requested = os + "-" + arch; | ||
var current = process.platform + "-" + process.arch; | ||
if (requested !== current ) { | ||
console.error("WARNING: Using binaries for the requested platform (" + requested + ") instead of for the actual platform (" + current + ").") | ||
} | ||
|
||
var binExt = ""; | ||
if (os == "win32") { | ||
binExt = ".exe"; | ||
} | ||
|
||
var unpackedBinPath = path.join(__dirname, "..", "unpacked_bin"); | ||
var binPath = path.join(unpackedBinPath, "mbt" + binExt); | ||
|
||
function execBin() { | ||
spawn( | ||
binPath, | ||
process.argv.slice(2), | ||
{stdio: 'inherit'} | ||
).on('exit', process.exit); | ||
} | ||
|
||
if (fs.existsSync(binPath)) { | ||
execBin(); | ||
} |
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 |
---|---|---|
@@ -1,20 +1 @@ | ||
var binwrap = require('binwrap'); | ||
var path = require('path'); | ||
|
||
var packageInfo = require(path.join(__dirname, 'package.json')); | ||
var version = packageInfo.version; | ||
var root = (process.env.XMAKE_IMPORT_COMMON_0 ? `${process.env.XMAKE_IMPORT_COMMON_0}/com/github/sap/cloud-mta-build-tool/${version}/cloud-mta-build-tool-${version}-` : `https://github.com/SAP/cloud-mta-build-tool/releases/download/v${version}/cloud-mta-build-tool_${version}_`); | ||
|
||
module.exports = binwrap({ | ||
dirname: __dirname, | ||
binaries: [ | ||
'mbt' | ||
], | ||
urls: { | ||
'darwin-arm64': root + 'Darwin_arm64.tar.gz', | ||
'darwin-x64': root + 'Darwin_amd64.tar.gz', | ||
'linux-x64': root + 'Linux_amd64.tar.gz', | ||
'linux-arm64': root + 'Linux_arm64.tar.gz', | ||
'win32-x64': root + 'Windows_amd64.tar.gz' | ||
} | ||
}); | ||
module.exports = {}; |
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,189 @@ | ||
var fs = require("fs"); | ||
var axios = require("axios"); | ||
var tar = require("tar"); | ||
var zlib = require("zlib"); | ||
var unzip = require("unzip-stream"); | ||
var path = require("path"); | ||
|
||
|
||
var packageInfo = require(path.join(process.cwd(), "package.json")); | ||
var version = packageInfo.version; | ||
|
||
var binName = process.argv[2]; | ||
var os = process.argv[3] || process.platform; | ||
var arch = process.argv[4] || process.arch; | ||
var root = `https://github.com/SAP/${binName}/releases/download/v${version}/${binName}_${version}_`; | ||
|
||
|
||
var requested = os + "-" + arch; | ||
var current = process.platform + "-" + process.arch; | ||
if (requested !== current ) { | ||
console.error("WARNING: Installing binaries for the requested platform (" + requested + ") instead of for the actual platform (" + current + ").") | ||
} | ||
|
||
var unpackedBinPath = path.join(process.cwd(), "unpacked_bin"); | ||
var config = { | ||
dirname: __dirname, | ||
binaries: [ | ||
'mbt' | ||
], | ||
urls: { | ||
'darwin-arm64': root + 'Darwin_arm64.tar.gz', | ||
'darwin-x64': root + 'Darwin_amd64.tar.gz', | ||
'linux-x64': root + 'Linux_amd64.tar.gz', | ||
'win32-x64': root + 'Windows_amd64.tar.gz' | ||
} | ||
}; | ||
if (!fs.existsSync("bin")) { | ||
fs.mkdirSync("bin"); | ||
} | ||
|
||
var binExt = ""; | ||
if (os == "win32") { | ||
binExt = ".exe"; | ||
} | ||
|
||
var buildId = os + "-" + arch; | ||
var url = config.urls[buildId]; | ||
if (!url) { | ||
throw new Error("No binaries are available for your platform: " + buildId); | ||
} | ||
function binstall(url, path, options) { | ||
if (url.endsWith(".zip")) { | ||
return unzipUrl(url, path, options); | ||
} else { | ||
return untgz(url, path, options); | ||
} | ||
} | ||
|
||
function untgz(url, path, options) { | ||
options = options || {}; | ||
|
||
var verbose = options.verbose; | ||
var verify = options.verify; | ||
|
||
return new Promise(function (resolve, reject) { | ||
var untar = tar | ||
.x({ cwd: path }) | ||
.on("error", function (error) { | ||
reject("Error extracting " + url + " - " + error); | ||
}) | ||
.on("end", function () { | ||
var successMessage = "Successfully downloaded and processed " + url; | ||
|
||
if (verify) { | ||
verifyContents(verify) | ||
.then(function () { | ||
resolve(successMessage); | ||
}) | ||
.catch(reject); | ||
} else { | ||
resolve(successMessage); | ||
} | ||
}); | ||
|
||
var gunzip = zlib.createGunzip().on("error", function (error) { | ||
reject("Error decompressing " + url + " " + error); | ||
}); | ||
|
||
try { | ||
fs.mkdirSync(path); | ||
} catch (error) { | ||
if (error.code !== "EEXIST") throw error; | ||
} | ||
|
||
if (verbose) { | ||
console.log("Downloading binaries from " + url); | ||
} | ||
|
||
axios | ||
.get(url, { responseType: "stream" }) | ||
.then((response) => { | ||
response.data.pipe(gunzip).pipe(untar); | ||
}) | ||
.catch((error) => { | ||
if (verbose) { | ||
console.error(error); | ||
} else { | ||
console.error(error.message); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function unzipUrl(url, path, options) { | ||
options = options || {}; | ||
|
||
var verbose = options.verbose; | ||
var verify = options.verify; | ||
|
||
return new Promise(function (resolve, reject) { | ||
var writeStream = unzip | ||
.Extract({ path: path }) | ||
.on("error", function (error) { | ||
reject("Error extracting " + url + " - " + error); | ||
}) | ||
.on("entry", function (entry) { | ||
console.log("Entry: " + entry.path); | ||
}) | ||
.on("close", function () { | ||
var successMessage = "Successfully downloaded and processed " + url; | ||
|
||
if (verify) { | ||
verifyContents(verify) | ||
.then(function () { | ||
resolve(successMessage); | ||
}) | ||
.catch(reject); | ||
} else { | ||
resolve(successMessage); | ||
} | ||
}); | ||
|
||
if (verbose) { | ||
console.log("Downloading binaries from " + url); | ||
} | ||
|
||
axios | ||
.get(url, { responseType: "stream" }) | ||
.then((response) => { | ||
response.data.pipe(writeStream); | ||
}) | ||
.catch((error) => { | ||
if (verbose) { | ||
console.error(error); | ||
} else { | ||
console.error(error.message); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function verifyContents(files) { | ||
return Promise.all( | ||
files.map(function (filePath) { | ||
return new Promise(function (resolve, reject) { | ||
fs.stat(filePath, function (err, stats) { | ||
if (err) { | ||
reject(filePath + " was not found."); | ||
} else if (!stats.isFile()) { | ||
reject(filePath + " was not a file."); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
}) | ||
); | ||
} | ||
|
||
binstall(url, unpackedBinPath).then(function() { | ||
config.binaries.forEach(function(bin) { | ||
fs.chmodSync(path.join(unpackedBinPath, bin + binExt), "755"); | ||
}); | ||
}).then(function(result) { | ||
process.exit(0); | ||
}, function(result) { | ||
console.error("ERR", result); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.