public void analyze() throws IOException, ParserConfigurationException, SAXException { gatherResourceValues(mResourceClassDir); recordMapping(mProguardMapping); recordUsages(mClassesJar); recordManifestUsages(mMergedManifest); recordResources(mMergedResourceDir); keepPossiblyReferencedResources(); dumpReferences(); findUnused(); }
private void gatherResourceValues(File file) throws IOException { if (file.isDirectory()) { File[] children = file.listFiles(); if (children != null) { for (File child : children) { gatherResourceValues(child); } } } else if (file.isFile() && file.getName().equals(SdkConstants.FN_RESOURCE_CLASS)) { parseResourceClass(file); } }
public void analyze() throws IOException, ParserConfigurationException, SAXException { gatherResourceValues(mResourceClassDir); recordMapping(mProguardMapping); recordClassUsages(mClasses); recordManifestUsages(mMergedManifest); recordResources(mMergedResourceDir); keepPossiblyReferencedResources(); dumpReferences(); mModel.processToolsAttributes(); mUnused = mModel.findUnused(); }
String name = entry.getName(); boolean directory = entry.isDirectory(); Resource resource = getResourceByJarPath(name); if (resource == null || resource.reachable) { } else if (isVerbose()) { System.out.println("Skipped unused resource " + name + ": " + entry.getSize() + " bytes");
Resource resource = getResourceFromFilePath(string); if (resource != null) { markReachable(resource); continue; } else { markReachable(resource); markReachable(resource); Pattern pattern = Pattern.compile(convertFormatStringToRegexp(string)); for (Map<String, Resource> map : mTypeToName.values()) { for (Resource resource : map.values()) { markReachable(resource); Resource resource = getResource(type, name); if (mDebug && resource != null) { System.out.println("Marking " + resource + " used because it " + "matches string pool constant " + string); markReachable(resource); continue; markReachable(resource); int id = Integer.parseInt(name); if (id != 0) { markReachable(mValueToResource.get(id));
private void recordManifestUsages(Node node) { short nodeType = node.getNodeType(); if (nodeType == Node.ELEMENT_NODE) { Element element = (Element) node; NamedNodeMap attributes = element.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { Attr attr = (Attr) attributes.item(i); markReachable(getResourceFromUrl(attr.getValue())); } } else if (nodeType == Node.TEXT_NODE) { // Does this apply to any manifests?? String text = node.getNodeValue().trim(); markReachable(getResourceFromUrl(text)); } NodeList children = node.getChildNodes(); for (int i = 0, n = children.getLength(); i < n; i++) { Node child = children.item(i); recordManifestUsages(child); } }
if (children != null) { for (File child : children) { recordClassUsages(child); if (file.getPath().endsWith(DOT_CLASS)) { byte[] bytes = Files.toByteArray(file); recordClassUsages(file, file.getName(), bytes); } else if (file.getPath().endsWith(DOT_JAR)) { ZipInputStream zis = null; !isResourceClass(name)) { byte[] bytes = ByteStreams.toByteArray(zis); if (bytes != null) { recordClassUsages(file, name, bytes);
hasEscapedLetters |= appendEscapedPattern(formatString, regexp, from, start); hasEscapedLetters |= appendEscapedPattern(formatString, regexp, from, length);
private void recordManifestUsages(File manifest) throws IOException, ParserConfigurationException, SAXException { String xml = Files.toString(manifest, UTF_8); Document document = XmlUtils.parseDocument(xml, true); recordManifestUsages(document.getDocumentElement()); }
!isResourceClass(name)) { byte[] bytes = ByteStreams.toByteArray(zis); if (bytes != null) {
ResourceFolderType folderType = ResourceFolderType.getFolderType(folder); if (folderType != null && folderType != ResourceFolderType.VALUES) { if (isVerbose()) { System.out.println("Deleted unused resource " + file); List<String> removed = Lists.newArrayList(); stripUnused(root, removed); if (isVerbose()) { System.out.println("Removed " + removed.size() + " unused resources from " + file + ":\n " +
Pattern pattern = Pattern.compile(convertFormatStringToRegexp(string)); for (Resource resource : mModel.getResources()) { if (pattern.matcher(resource.name).matches()) {
String name = entry.getName(); boolean directory = entry.isDirectory(); Resource resource = getResourceByJarPath(name); if (resource == null || resource.isReachable()) { zos.closeEntry(); if (isVerbose() || mDebugPrinter != null) { String message = "Skipped unused resource " + name + ": " + entry .getSize() + " bytes (replaced with small dummy file of size " + bytes.length + " bytes)"; if (isVerbose()) { System.out.println(message); } else if (isVerbose() || mDebugPrinter != null) { String message = "Skipped unused resource " + name + ": " + entry.getSize() + " bytes"; if (isVerbose()) { System.out.println(message); String message = "Resource shrinking did not work (grew from " + before + " to " + after + "); using original instead"; if (isVerbose()) { System.out.println(message);
hasEscapedLetters |= appendEscapedPattern(formatString, regexp, from, start); hasEscapedLetters |= appendEscapedPattern(formatString, regexp, from, length);
private void gatherResourceValues(File file) throws IOException { if (file.isDirectory()) { File[] children = file.listFiles(); if (children != null) { for (File child : children) { gatherResourceValues(child); } } } else if (file.isFile() && file.getName().equals(SdkConstants.FN_RESOURCE_CLASS)) { parseResourceClass(file); } }