public String blame(XmlDocument document) throws ParserConfigurationException, SAXException, IOException { return mActionRecorder.build().blame(document); } }
@NonNull synchronized Actions build() { return new Actions(ImmutableMap.copyOf(mRecords)); } }
@Nullable public static Actions load(String xml) { return getGsonParser().fromJson(xml, Actions.class); }
private void parse(@NonNull XmlElement element, @NonNull ImmutableMultimap.Builder<Integer, Record> mappings) { DecisionTreeRecord decisionTreeRecord = mRecords.get(element.getId()); if (decisionTreeRecord != null) { Actions.NodeRecord nodeRecord = findNodeRecord(decisionTreeRecord); if (nodeRecord != null) { mappings.put(element.getPosition().getStartLine(), nodeRecord); } for (XmlAttribute xmlAttribute : element.getAttributes()) { Actions.AttributeRecord attributeRecord = findAttributeRecord(decisionTreeRecord, xmlAttribute); if (attributeRecord != null) { mappings.put(xmlAttribute.getPosition().getStartLine(), attributeRecord); } } } for (XmlElement xmlElement : element.getMergeableElements()) { parse(xmlElement, mappings); } }
/** * Dump merging tool actions to a text file. * @param fileWriter the file to write all actions into. * @throws IOException */ void log(@NonNull FileWriter fileWriter) throws IOException { fileWriter.append(getLogs()); }
} else { fileWriter = new FileWriter(mReportFile.get()); mergingReport.getActions().log(fileWriter);
@NonNull public String blame(@NonNull XmlDocument xmlDocument) throws IOException, SAXException, ParserConfigurationException { ImmutableMultimap<Integer, Record> resultingSourceMapping = getResultingSourceMapping(xmlDocument); LineReader lineReader = new LineReader( new StringReader(xmlDocument.prettyPrint())); StringBuilder actualMappings = new StringBuilder(); String line; int count = 0; while ((line = lineReader.readLine()) != null) { actualMappings.append(count + 1).append(line).append("\n"); if (resultingSourceMapping.containsKey(count)) { for (Record record : resultingSourceMapping.get(count)) { actualMappings.append(count + 1).append("-->") .append(record.getActionLocation().toString()) .append("\n"); } } count++; } return actualMappings.toString(); }
/** * Check in our list of attribute actions that a particular * {@link com.android.manifmerger.Actions.ActionType} action was recorded on the passed element. * @return true if it was applied, false otherwise. */ private static boolean isAttributeOperationPresent(@NonNull XmlElement xmlElement, @NonNull Map.Entry<XmlNode.NodeName, AttributeOperationType> attributeOperation, @NonNull Actions actions, ActionType action) { for (Actions.AttributeRecord attributeRecord : actions.getAttributeRecords( xmlElement.getId(), attributeOperation.getKey())) { if (attributeRecord.getActionType() == action) { return true; } } return false; }
/** * Check in our list of applied actions that a particular * {@link com.android.manifmerger.Actions.ActionType} action was recorded on the passed element. * @return true if it was applied, false otherwise. */ private static boolean isNodeOperationPresent(@NonNull XmlElement xmlElement, @NonNull Actions actions, ActionType action) { for (Actions.NodeRecord nodeRecord : actions.getNodeRecords(xmlElement.getId())) { if (nodeRecord.getActionType() == action) { return true; } } return false; }
/** * Initial dump of the merging tool actions, need to be refined and spec'ed out properly. * @param logger logger to log to at INFO level. */ void log(@NonNull ILogger logger) { logger.verbose(getLogs()); }
/** * dumps all logging records to a logger. */ public void log(@NonNull ILogger logger) { for (Record record : mRecords) { switch(record.mSeverity) { case WARNING: logger.warning(record.toString()); break; case ERROR: logger.error(null /* throwable */, record.toString()); break; case INFO: logger.verbose(record.toString()); break; default: logger.error(null /* throwable */, "Unhandled record type " + record.mSeverity); } } mActions.log(logger); if (!mResult.isSuccess()) { logger.warning("\nSee http://g.co/androidstudio/manifest-merger for more information" + " about the manifest merger.\n"); } }
private void handleMergingResult(@NonNull MergingReport mergingReport, @NonNull File outFile) { switch (mergingReport.getResult()) { case WARNING: mergingReport.log(mLogger); // fall through since these are just warnings. case SUCCESS: XmlDocument xmlDocument = mergingReport.getMergedDocument().get(); try { String annotatedDocument = mergingReport.getActions().blame(xmlDocument); mLogger.verbose(annotatedDocument); } catch (Exception e) { mLogger.error(e, "cannot print resulting xml"); } save(xmlDocument, outFile); mLogger.info("Merged manifest saved to " + outFile); break; case ERROR: mergingReport.log(mLogger); throw new RuntimeException(mergingReport.getReportString()); default: throw new RuntimeException("Unhandled result type : " + mergingReport.getResult()); } }
@Nullable public static Actions load(@NonNull InputStream inputStream) throws IOException { return getGsonParser().fromJson(new InputStreamReader(inputStream), Actions.class); }
XmlDocument xmlDocument = mergingReport.getMergedDocument().get(); try { String annotatedDocument = mergingReport.getActions().blame(xmlDocument); mLogger.verbose(annotatedDocument); } catch (Exception e) {