use of io.github.lizhangqu.intellij.android.bundle.analyzer.ArchiveNode in project android-bundle-support by lizhangqu.
the class ApkFileByFileDiffParser method createTreeNode.
@VisibleForTesting
@NonNull
static DefaultMutableTreeNode createTreeNode(ArchiveNode oldFile, ArchiveNode newFile, Map<String, Long> pathsToDiffSize) throws IOException {
if (oldFile == null && newFile == null) {
throw new IllegalArgumentException("Both old and new files are null");
}
DefaultMutableTreeNode node = new DefaultMutableTreeNode();
long oldSize = 0;
long newSize = 0;
long patchSize = 0;
HashSet<String> childrenInOldFile = new HashSet<>();
final ArchiveEntry data = oldFile == null ? newFile.getData() : oldFile.getData();
final String name = data.getPath().getFileName() != null ? data.getPath().getFileName().toString() : data.getArchive().getPath().getFileName().toString();
if (oldFile != null) {
if (!oldFile.getChildren().isEmpty()) {
for (ArchiveNode oldChild : oldFile.getChildren()) {
ArchiveNode newChild = null;
if (newFile != null) {
for (ArchiveNode archiveNode : newFile.getChildren()) {
if (archiveNode.getData().getPath().getFileName().toString().equals(oldChild.getData().getPath().getFileName().toString())) {
newChild = archiveNode;
break;
}
}
}
childrenInOldFile.add(oldChild.getData().getPath().getFileName().toString());
DefaultMutableTreeNode childNode = createTreeNode(oldChild, newChild, pathsToDiffSize);
node.add(childNode);
ApkDiffEntry entry = (ApkDiffEntry) childNode.getUserObject();
oldSize += entry.getOldSize();
newSize += entry.getNewSize();
patchSize += entry.getSize();
}
if (Files.size(oldFile.getData().getPath()) > 0) {
// This is probably a zip inside the apk, and we should use it's size
oldSize = Files.size(oldFile.getData().getPath());
} else if (oldFile.getParent() == null) {
oldSize = Files.size(oldFile.getData().getArchive().getPath());
}
} else {
oldSize += Files.size(oldFile.getData().getPath());
}
}
if (newFile != null) {
if (!newFile.getChildren().isEmpty()) {
for (ArchiveNode newChild : newFile.getChildren()) {
if (childrenInOldFile.contains(newChild.getData().getPath().getFileName().toString())) {
continue;
}
DefaultMutableTreeNode childNode = createTreeNode(null, newChild, pathsToDiffSize);
node.add(childNode);
ApkDiffEntry entry = (ApkDiffEntry) childNode.getUserObject();
oldSize += entry.getOldSize();
newSize += entry.getNewSize();
patchSize += entry.getSize();
}
if (Files.size(newFile.getData().getPath()) > 0) {
// This is probably a zip inside the apk, and we should use it's size
newSize = Files.size(newFile.getData().getPath());
String relPath = newFile.getData().getArchive().getContentRoot().relativize(newFile.getData().getPath()).toString();
if (pathsToDiffSize.containsKey(relPath)) {
patchSize = pathsToDiffSize.get(relPath);
}
} else if (newFile.getParent() == null) {
newSize = Files.size(newFile.getData().getArchive().getPath());
}
} else {
newSize += Files.size(newFile.getData().getPath());
String relPath = newFile.getData().getArchive().getContentRoot().relativize(newFile.getData().getPath()).toString();
if (pathsToDiffSize.containsKey(relPath)) {
patchSize = pathsToDiffSize.get(relPath);
}
}
}
node.setUserObject(new ApkFileByFileEntry(name, oldFile, newFile, oldSize, newSize, patchSize));
ApkEntry.sort(node);
return node;
}
use of io.github.lizhangqu.intellij.android.bundle.analyzer.ArchiveNode in project android-bundle-support by lizhangqu.
the class ApkFileByFileDiffParser method createTreeNode.
@NonNull
public static DefaultMutableTreeNode createTreeNode(@NonNull ArchiveContext oldFile, @NonNull ArchiveContext newFile) throws IOException, InterruptedException {
ArchiveNode oldRoot = ArchiveTreeStructure.create(oldFile);
ArchiveNode newRoot = ArchiveTreeStructure.create(newFile);
PatchExplainer explainer = new PatchExplainer(new DeflateCompressor(), new BsDiffDeltaGenerator());
Map<String, Long> pathsToDiffSize = new HashMap<>();
List<EntryExplanation> explanationList = explainer.explainPatch(oldFile.getArchive().getPath().toFile(), newFile.getArchive().getPath().toFile());
for (EntryExplanation explanation : explanationList) {
String path = new String(explanation.getPath().getData(), "UTF8");
pathsToDiffSize.put(path, explanation.getCompressedSizeInPatch());
}
return createTreeNode(oldRoot, newRoot, pathsToDiffSize);
}
use of io.github.lizhangqu.intellij.android.bundle.analyzer.ArchiveNode in project android-bundle-support by lizhangqu.
the class ApkDiffParser method createTreeNode.
@NonNull
private static DefaultMutableTreeNode createTreeNode(@Nullable ArchiveNode oldFile, @Nullable ArchiveNode newFile) throws IOException {
if (oldFile == null && newFile == null) {
throw new IllegalArgumentException("Both old and new files are null");
}
DefaultMutableTreeNode node = new DefaultMutableTreeNode();
long oldSize = 0;
long newSize = 0;
HashSet<String> childrenInOldFile = new HashSet<>();
final ArchiveEntry data = oldFile == null ? newFile.getData() : oldFile.getData();
final String name = data.getPath().getFileName() != null ? data.getPath().getFileName().toString() : data.getArchive().getPath().getFileName().toString();
if (oldFile != null) {
if (!oldFile.getChildren().isEmpty()) {
for (ArchiveNode oldChild : oldFile.getChildren()) {
ArchiveNode newChild = null;
if (newFile != null) {
for (ArchiveNode archiveNode : newFile.getChildren()) {
if (archiveNode.getData().getPath().getFileName().toString().equals(oldChild.getData().getPath().getFileName().toString())) {
newChild = archiveNode;
break;
}
}
}
childrenInOldFile.add(oldChild.getData().getPath().getFileName().toString());
DefaultMutableTreeNode childNode = createTreeNode(oldChild, newChild);
node.add(childNode);
ApkDiffEntry entry = (ApkDiffEntry) childNode.getUserObject();
oldSize += entry.getOldSize();
newSize += entry.getNewSize();
}
if (Files.size(oldFile.getData().getPath()) > 0) {
// This is probably a zip inside the apk, and we should use it's size
oldSize = Files.size(oldFile.getData().getPath());
} else if (oldFile.getParent() == null) {
oldSize = Files.size(oldFile.getData().getArchive().getPath());
}
} else {
oldSize += Files.size(oldFile.getData().getPath());
}
}
if (newFile != null) {
if (!newFile.getChildren().isEmpty()) {
for (ArchiveNode newChild : newFile.getChildren()) {
if (childrenInOldFile.contains(newChild.getData().getPath().getFileName().toString())) {
continue;
}
DefaultMutableTreeNode childNode = createTreeNode(null, newChild);
node.add(childNode);
ApkDiffEntry entry = (ApkDiffEntry) childNode.getUserObject();
oldSize += entry.getOldSize();
newSize += entry.getNewSize();
}
if (Files.size(newFile.getData().getPath()) > 0) {
// This is probably a zip inside the apk, and we should use it's size
newSize = Files.size(newFile.getData().getPath());
} else if (newFile.getParent() == null) {
newSize = Files.size(newFile.getData().getArchive().getPath());
}
} else {
newSize += Files.size(newFile.getData().getPath());
}
}
node.setUserObject(new ApkDiffEntry(name, oldFile, newFile, oldSize, newSize));
ApkEntry.sort(node);
return node;
}
use of io.github.lizhangqu.intellij.android.bundle.analyzer.ArchiveNode in project android-bundle-support by lizhangqu.
the class ApkDiffParser method createTreeNode.
@NonNull
public static DefaultMutableTreeNode createTreeNode(@NonNull ArchiveContext oldFile, @NonNull ArchiveContext newFile) throws IOException {
ArchiveNode oldRoot = ArchiveTreeStructure.create(oldFile);
ArchiveNode newRoot = ArchiveTreeStructure.create(newFile);
return createTreeNode(oldRoot, newRoot);
}
Aggregations