mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-02-17 16:10:12 +00:00
GP-0: Adding "offline" system property to fetchDependencies.gradle
(#4146) When the "offline" system property is used, the linux commands used to download everything will be output, but nothing will actually be downloaded.
This commit is contained in:
parent
1874fcff7f
commit
8242c31c4a
@ -50,6 +50,8 @@ ext.DEPS_DIR = file("${REPO_DIR}/dependencies")
|
|||||||
ext.DOWNLOADS_DIR = file("${DEPS_DIR}/downloads")
|
ext.DOWNLOADS_DIR = file("${DEPS_DIR}/downloads")
|
||||||
ext.FID_DIR = file("${DEPS_DIR}/fidb")
|
ext.FID_DIR = file("${DEPS_DIR}/fidb")
|
||||||
ext.FLAT_REPO_DIR = file("${DEPS_DIR}/flatRepo")
|
ext.FLAT_REPO_DIR = file("${DEPS_DIR}/flatRepo")
|
||||||
|
ext.OFFLINE = System.properties["offline"] != null
|
||||||
|
ext.createdDirs = [] as Set
|
||||||
|
|
||||||
file("${REPO_DIR}/Ghidra/application.properties").withReader { reader ->
|
file("${REPO_DIR}/Ghidra/application.properties").withReader { reader ->
|
||||||
def ghidraProps = new Properties()
|
def ghidraProps = new Properties()
|
||||||
@ -64,7 +66,7 @@ ext.deps = [
|
|||||||
sha256: "7a9bdf843d43de4d1e94ec2e7b6f55825017b0c4a7ee39ff82660e2493a46f08",
|
sha256: "7a9bdf843d43de4d1e94ec2e7b6f55825017b0c4a7ee39ff82660e2493a46f08",
|
||||||
destination: {
|
destination: {
|
||||||
unzip(DOWNLOADS_DIR, DOWNLOADS_DIR, "dex2jar-2.1.zip")
|
unzip(DOWNLOADS_DIR, DOWNLOADS_DIR, "dex2jar-2.1.zip")
|
||||||
FileUtils.copyDirectory(new File(DOWNLOADS_DIR, "dex-tools-2.1/lib/"), FLAT_REPO_DIR, new WildcardFileFilter("dex-*"));
|
copyDirectory(new File(DOWNLOADS_DIR, "dex-tools-2.1/lib/"), FLAT_REPO_DIR, new WildcardFileFilter("dex-*"));
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -154,12 +156,14 @@ ext.deps = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
// Download dependencies (if necessary) and verify their hashes
|
// Download dependencies (if necessary) and verify their hashes
|
||||||
DOWNLOADS_DIR.mkdirs()
|
mkdirs(DOWNLOADS_DIR)
|
||||||
deps.each {
|
deps.each {
|
||||||
File file = new File(DOWNLOADS_DIR, it.name)
|
File file = new File(DOWNLOADS_DIR, it.name)
|
||||||
if (!it.sha256.equals(generateHash(file))) {
|
if (OFFLINE || !it.sha256.equals(generateHash(file))) {
|
||||||
download(it.url, file.path)
|
download(it.url, file)
|
||||||
assert(it.sha256.equals(generateHash(file)));
|
if (!OFFLINE) {
|
||||||
|
assert(it.sha256.equals(generateHash(file)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,12 +171,16 @@ deps.each {
|
|||||||
// Some downloads require pre-processing before their relevant pieces can be copied.
|
// Some downloads require pre-processing before their relevant pieces can be copied.
|
||||||
deps.each {
|
deps.each {
|
||||||
if (it.destination instanceof File) {
|
if (it.destination instanceof File) {
|
||||||
println("Copying " + it.name + " to " + it.destination)
|
if (!OFFLINE) {
|
||||||
it.destination.mkdirs()
|
println "Copying " + it.name + " to " + it.destination
|
||||||
FileUtils.copyFile(new File(DOWNLOADS_DIR, it.name), new File(it.destination, it.name));
|
}
|
||||||
|
mkdirs(it.destination)
|
||||||
|
copyFile(new File(DOWNLOADS_DIR, it.name), new File(it.destination, it.name));
|
||||||
}
|
}
|
||||||
else if (it.destination instanceof Closure) {
|
else if (it.destination instanceof Closure) {
|
||||||
println("Processing " + it.name)
|
if (!OFFLINE) {
|
||||||
|
println "Processing " + it.name
|
||||||
|
}
|
||||||
it.destination()
|
it.destination()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -191,28 +199,32 @@ deps.each {
|
|||||||
* discrepencies will be caught when checking the SHA-256s later on.
|
* discrepencies will be caught when checking the SHA-256s later on.
|
||||||
*
|
*
|
||||||
* @param url the file to download
|
* @param url the file to download
|
||||||
* @param filename the local file to create for the download
|
* @param file the local file to create for the download
|
||||||
*/
|
*/
|
||||||
def download(url, filename) {
|
def download(url, file) {
|
||||||
|
if (OFFLINE) {
|
||||||
println("URL: " + url)
|
println "curl -L -o " + relative(file) + " '" + url + "'"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
println "URL: " + url
|
||||||
def(InputStream istream, size) = establishConnection(url, NUM_RETRIES);
|
def(InputStream istream, size) = establishConnection(url, NUM_RETRIES);
|
||||||
assert istream != null : " ***CONNECTION FAILURE***\n max attempts exceeded; exiting\n"
|
assert istream != null : " ***CONNECTION FAILURE***\n max attempts exceeded; exiting\n"
|
||||||
|
|
||||||
FileOutputStream ostream = new FileOutputStream(filename);
|
FileOutputStream ostream = new FileOutputStream(file);
|
||||||
def dataBuffer = new byte[1024];
|
def dataBuffer = new byte[1024];
|
||||||
int bytesRead;
|
int bytesRead;
|
||||||
int totalRead;
|
int totalRead;
|
||||||
while ((bytesRead = istream.read(dataBuffer, 0, 1024)) != -1) {
|
while ((bytesRead = istream.read(dataBuffer, 0, 1024)) != -1) {
|
||||||
ostream.write(dataBuffer, 0, bytesRead);
|
ostream.write(dataBuffer, 0, bytesRead);
|
||||||
totalRead += bytesRead
|
totalRead += bytesRead
|
||||||
print("\r")
|
print "\r"
|
||||||
print(" Downloading: " + totalRead + " of " + size)
|
print " Downloading: " + totalRead + " of " + size
|
||||||
if (!size.equals("???")) {
|
if (!size.equals("???")) {
|
||||||
int pctComplete = (totalRead / size) * 100
|
int pctComplete = (totalRead / size) * 100
|
||||||
print(" (" + pctComplete + "%)")
|
print " (" + pctComplete + "%)"
|
||||||
}
|
}
|
||||||
print(" ") // overwrite gradle timer output
|
print " " // overwrite gradle timer output
|
||||||
System.out.flush()
|
System.out.flush()
|
||||||
}
|
}
|
||||||
println()
|
println()
|
||||||
@ -231,10 +243,10 @@ def establishConnection(url, retries) {
|
|||||||
for (int i = 0; i < retries; i++) {
|
for (int i = 0; i < retries; i++) {
|
||||||
try {
|
try {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
println(" Connecting...")
|
println " Connecting..."
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
println(" Connecting (" + (i+1) + "/" + retries + ")...")
|
println " Connecting (" + (i+1) + "/" + retries + ")..."
|
||||||
}
|
}
|
||||||
URLConnection conn = new URL(url).openConnection();
|
URLConnection conn = new URL(url).openConnection();
|
||||||
conn.setRequestMethod("HEAD");
|
conn.setRequestMethod("HEAD");
|
||||||
@ -245,7 +257,7 @@ def establishConnection(url, retries) {
|
|||||||
return [new BufferedInputStream(new URL(url).openStream()), size];
|
return [new BufferedInputStream(new URL(url).openStream()), size];
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
println(" Connection error! " + e)
|
println " Connection error! " + e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -258,12 +270,18 @@ def establishConnection(url, retries) {
|
|||||||
* @param zipFileName the name of the file to unpack
|
* @param zipFileName the name of the file to unpack
|
||||||
*/
|
*/
|
||||||
def unzip(sourceDir, targetDir, zipFileName) {
|
def unzip(sourceDir, targetDir, zipFileName) {
|
||||||
def zip = new ZipFile(new File(sourceDir, zipFileName))
|
def zipFile = new File(sourceDir, zipFileName)
|
||||||
|
if (OFFLINE) {
|
||||||
|
println "unzip " + relative(zipFile) + " -d " + relative(targetDir)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
def zip = new ZipFile(zipFile)
|
||||||
zip.entries().findAll { !it.directory }.each { e ->
|
zip.entries().findAll { !it.directory }.each { e ->
|
||||||
(e.name as File).with { f ->
|
(e.name as File).with { f ->
|
||||||
if (f.parentFile != null) {
|
if (f.parentFile != null) {
|
||||||
File destPath = new File(targetDir.path, f.parentFile.path)
|
File destPath = new File(targetDir.path, f.parentFile.path)
|
||||||
destPath.mkdirs()
|
mkdirs(destPath)
|
||||||
File targetFile = new File(destPath.path, f.name)
|
File targetFile = new File(destPath.path, f.name)
|
||||||
targetFile.withOutputStream { w ->
|
targetFile.withOutputStream { w ->
|
||||||
w << zip.getInputStream(e)
|
w << zip.getInputStream(e)
|
||||||
@ -274,6 +292,63 @@ def unzip(sourceDir, targetDir, zipFileName) {
|
|||||||
zip.close()
|
zip.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the given directory, including any necessary but nonexistent parent directories
|
||||||
|
*
|
||||||
|
* @return true if and only if the directory was created, along with all necessary parent
|
||||||
|
* directories; false otherwise
|
||||||
|
*/
|
||||||
|
def mkdirs(dir) {
|
||||||
|
if (OFFLINE) {
|
||||||
|
if (!createdDirs.contains(dir)) {
|
||||||
|
println "mkdir -p " + relative(dir)
|
||||||
|
createdDirs << dir
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return dir.mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies a file to a new location
|
||||||
|
*
|
||||||
|
* @param sourceFile the file to copy
|
||||||
|
* @param targetFile the new file
|
||||||
|
*/
|
||||||
|
def copyFile(sourceFile, targetFile) {
|
||||||
|
if (OFFLINE) {
|
||||||
|
println "cp " + relative(sourceFile) + " " + relative(targetFile)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
FileUtils.copyFile(sourceFile, targetFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies a filtered directory to a new location
|
||||||
|
*
|
||||||
|
* @param sourceDir the directory to copy
|
||||||
|
* @param targetDir the new directory
|
||||||
|
* @param filter the filter to apply; null to copy everything
|
||||||
|
*/
|
||||||
|
def copyDirectory(sourceDir, targetDir, filter) {
|
||||||
|
if (OFFLINE) {
|
||||||
|
println "cp -r " + relative(sourceDir) + " " + relative(targetDir)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
FileUtils.copyDirectory(sourceDir, targetDir, filter)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the path of the file relative to the repository
|
||||||
|
*
|
||||||
|
* @return The path of the file relative to the repository
|
||||||
|
*/
|
||||||
|
def relative(file) {
|
||||||
|
return "\"" + file.absolutePath.substring(REPO_DIR.absolutePath.length() + 1).replaceAll("\\\\", "/") + "\""
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the SHA-256 hash for the given file
|
* Generates the SHA-256 hash for the given file
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user