mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
Fixed improper handling of APK redirect file (#470)
This commit is contained in:
@@ -61,14 +61,9 @@ public class ApkMetadata {
|
||||
|
||||
// This sometimes might be a redirect to the listing file
|
||||
// So we have to handle this case too.
|
||||
final var redirectedFile = ListingFileRedirect.maybeExtractRedirectedFile(listingFIle);
|
||||
if (redirectedFile != null) {
|
||||
listingFIle = redirectedFile;
|
||||
}
|
||||
|
||||
final var dir = listingFIle.getParentFile();
|
||||
final var metadata =
|
||||
JSONUtility.gson.fromJson(new FileReader(listingFIle), ApkMetadata.class);
|
||||
final var redirectedFile = ListingFileRedirect.getListingFile(listingFIle).getAbsoluteFile();
|
||||
final var dir = redirectedFile.getParentFile();
|
||||
final var metadata = JSONUtility.gson.fromJson(new FileReader(redirectedFile), ApkMetadata.class);
|
||||
if (!isValid(metadata)) {
|
||||
LOG.warn("Invalid APK metadata:", metadata);
|
||||
return null;
|
||||
@@ -128,13 +123,11 @@ public class ApkMetadata {
|
||||
LOG.warn("Skipping output element because file is not APK:", element);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (element.getOutputFile().endsWith(".apk")) {
|
||||
atLeastOneApk = true;
|
||||
break;
|
||||
}
|
||||
|
||||
atLeastOneApk = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
LOG.debug("Output metadata validation succeeded");
|
||||
return atLeastOneApk;
|
||||
}
|
||||
|
||||
@@ -18,26 +18,55 @@
|
||||
package com.itsaky.androidide.utils
|
||||
|
||||
import java.io.File
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringReader
|
||||
import java.util.*
|
||||
import java.util.Properties
|
||||
|
||||
class ListingFileRedirect {
|
||||
|
||||
companion object {
|
||||
/** Redirect file will have this marker as the first line as comment. */
|
||||
private const val REDIRECT_MARKER = "#- File Locator -"
|
||||
|
||||
/** Property name in a [Properties] for the metadata file location. */
|
||||
private const val REDIRECT_PROPERTY_NAME = "listingFile"
|
||||
|
||||
@JvmStatic
|
||||
fun maybeExtractRedirectedFile(redirectFile: File): File? {
|
||||
val fileContent = redirectFile.readText()
|
||||
return if (fileContent.startsWith(REDIRECT_MARKER)) {
|
||||
val fileLocator = Properties().also { it.load(StringReader(fileContent)) }
|
||||
val file = File(fileLocator.getProperty(REDIRECT_PROPERTY_NAME))
|
||||
if (!file.isAbsolute) redirectFile.parentFile!!.resolve(file) else file
|
||||
} else null
|
||||
object ListingFileRedirect {
|
||||
|
||||
/**
|
||||
* Redirect file will have this marker as the first line as comment.
|
||||
*/
|
||||
const val REDIRECT_MARKER = "#- File Locator -"
|
||||
|
||||
/**
|
||||
* Property name in a [Properties] for the metadata file location.
|
||||
*/
|
||||
const val REDIRECT_PROPERTY_NAME = "listingFile"
|
||||
|
||||
/**
|
||||
* Redirect file name used when for the artifact.
|
||||
*/
|
||||
const val REDIRECT_FILE_NAME = "redirect.txt"
|
||||
|
||||
fun writeRedirect(listingFile: File, into: File) {
|
||||
val path = try {
|
||||
into.parentFile!!.toPath().relativize(listingFile.toPath()).toString()
|
||||
} catch(ex: IllegalArgumentException) {
|
||||
listingFile.canonicalPath
|
||||
}
|
||||
PrintWriter(into).use {
|
||||
it.println(REDIRECT_MARKER)
|
||||
it.println("${REDIRECT_PROPERTY_NAME}=${path.replace("\\", "/")}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun maybeExtractRedirectedFile(redirectFile: File, redirectFileContent: String? = null): File? {
|
||||
val fileContent = redirectFileContent ?: redirectFile.readText()
|
||||
return if (fileContent.startsWith(REDIRECT_MARKER)) {
|
||||
val fileLocator = Properties().also {
|
||||
it.load(StringReader(fileContent))
|
||||
}
|
||||
val file = File(fileLocator.getProperty(REDIRECT_PROPERTY_NAME))
|
||||
if(!file.isAbsolute)
|
||||
redirectFile.parentFile?.resolve(file)
|
||||
else
|
||||
file
|
||||
} else null
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getListingFile(inputFile: File) =
|
||||
maybeExtractRedirectedFile(inputFile) ?: inputFile
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user