use of com.android.annotations.NonNull in project buck by facebook.
the class ManifestMerger2 method load.
/**
* Load an xml file and perform placeholder substitution
* @param manifestInfo the android manifest information like if it is a library, an
* overlay or a main manifest file.
* @param selectors all the libraries selectors
* @param mergingReportBuilder the merging report to store events and errors.
* @return a loaded manifest info.
* @throws MergeFailureException
*/
@NonNull
private LoadedManifestInfo load(@NonNull ManifestInfo manifestInfo, @NonNull KeyResolver<String> selectors, @NonNull MergingReport.Builder mergingReportBuilder) throws MergeFailureException {
File xmlFile = manifestInfo.mLocation;
XmlDocument xmlDocument;
try {
InputStream inputStream = mFileStreamProvider.getInputStream(xmlFile);
xmlDocument = XmlLoader.load(selectors, mSystemPropertyResolver, manifestInfo.mName, xmlFile, inputStream, manifestInfo.getType(), manifestInfo.getMainManifestPackageName());
} catch (Exception e) {
throw new MergeFailureException(e);
}
String originalPackageName = xmlDocument.getPackageName();
MergingReport.Builder builder = manifestInfo.getType() == XmlDocument.Type.MAIN ? mergingReportBuilder : new MergingReport.Builder(mergingReportBuilder.getLogger());
builder.getActionRecorder().recordDefaultNodeAction(xmlDocument.getRootNode());
// perform place holder substitution, this is necessary to do so early in case placeholders
// are used in key attributes.
performPlaceHolderSubstitution(manifestInfo, xmlDocument, builder);
return new LoadedManifestInfo(manifestInfo, Optional.fromNullable(originalPackageName), xmlDocument);
}
use of com.android.annotations.NonNull in project buck by facebook.
the class XmlAttribute method handleBothToolsAttributePresent.
/**
* Handles tools: namespace attributes presence in both documents.
* @param higherPriority the higherPriority attribute
*/
private void handleBothToolsAttributePresent(@NonNull XmlAttribute higherPriority) {
// do not merge tools:node attributes, the higher priority one wins.
if (getName().getLocalName().equals(NodeOperationType.NODE_LOCAL_NAME)) {
return;
}
// everything else should be merged, duplicates should be eliminated.
@NonNull Splitter splitter = Splitter.on(',');
@NonNull ImmutableSet.Builder<String> targetValues = ImmutableSet.builder();
targetValues.addAll(splitter.split(higherPriority.getValue()));
targetValues.addAll(splitter.split(getValue()));
higherPriority.getXml().setValue(Joiner.on(',').join(targetValues.build()));
}
use of com.android.annotations.NonNull in project buck by facebook.
the class XmlElement method mergeChild.
// merge a child of a lower priority node into this higher priority node.
private void mergeChild(@NonNull XmlElement lowerPriorityChild, @NonNull MergingReport.Builder mergingReport) {
ILogger logger = mergingReport.getLogger();
// If this a custom element, we just blindly merge it in.
if (lowerPriorityChild.getType() == ManifestModel.NodeTypes.CUSTOM) {
handleCustomElement(lowerPriorityChild, mergingReport);
return;
}
Optional<XmlElement> thisChildOptional = getNodeByTypeAndKey(lowerPriorityChild.getType(), lowerPriorityChild.getKey());
// only in the lower priority document ?
if (!thisChildOptional.isPresent()) {
addElement(lowerPriorityChild, mergingReport);
return;
}
// it's defined in both files.
logger.verbose(lowerPriorityChild.getId() + " defined in both files...");
XmlElement thisChild = thisChildOptional.get();
switch(thisChild.getType().getMergeType()) {
case CONFLICT:
addMessage(mergingReport, MergingReport.Record.Severity.ERROR, String.format("Node %1$s cannot be present in more than one input file and it's " + "present at %2$s and %3$s", thisChild.getType(), thisChild.printPosition(), lowerPriorityChild.printPosition()));
break;
case ALWAYS:
// no merging, we consume the lower priority node unmodified.
// if the two elements are equal, just skip it.
// but check first that we are not supposed to replace or remove it.
@NonNull NodeOperationType operationType = calculateNodeOperationType(thisChild, lowerPriorityChild);
if (operationType == NodeOperationType.REMOVE || operationType == NodeOperationType.REPLACE) {
mergingReport.getActionRecorder().recordNodeAction(thisChild, Actions.ActionType.REJECTED, lowerPriorityChild);
break;
}
if (thisChild.getType().areMultipleDeclarationAllowed()) {
mergeChildrenWithMultipleDeclarations(lowerPriorityChild, mergingReport);
} else {
if (!thisChild.isEquals(lowerPriorityChild)) {
addElement(lowerPriorityChild, mergingReport);
}
}
break;
default:
// 2 nodes exist, some merging need to happen
handleTwoElementsExistence(thisChild, lowerPriorityChild, mergingReport);
break;
}
}
use of com.android.annotations.NonNull in project buck by facebook.
the class AndroidManifest method getStringValue.
@NonNull
private static String getStringValue(@NonNull IAbstractFile file, @NonNull String xPath) throws StreamException {
XPath xpath = AndroidXPathFactory.newXPath();
InputStream is = null;
try {
is = file.getContents();
return xpath.evaluate(xPath, new InputSource(is));
} catch (XPathExpressionException e) {
throw new RuntimeException("Malformed XPath expression when reading the attribute from the manifest," + "exp = " + xPath, e);
} finally {
Closeables.closeQuietly(is);
}
}
use of com.android.annotations.NonNull in project buck by facebook.
the class PositionXmlParser method parse.
/**
* Parses the XML content from the given input stream.
*
* @param input the input stream containing the XML to be parsed
* @param checkDtd whether or not download the DTD and validate it
* @return the corresponding document
* @throws ParserConfigurationException if a SAX parser is not available
* @throws SAXException if the document contains a parsing error
* @throws IOException if something is seriously wrong. This should not
* happen since the input source is known to be constructed from
* a string.
*/
@NonNull
public static Document parse(@NonNull InputStream input, boolean checkDtd) throws ParserConfigurationException, SAXException, IOException {
// Read in all the data
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
while (true) {
int r = input.read(buf);
if (r == -1) {
break;
}
out.write(buf, 0, r);
}
input.close();
return parse(out.toByteArray(), checkDtd);
}
Aggregations