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);
}
use of com.android.annotations.NonNull in project android by JetBrains.
the class ImportSummary method createSummary.
/**
* Provides the summary
*/
@NonNull
public String createSummary() {
StringBuilder sb = new StringBuilder(2000);
sb.append(MSG_HEADER);
List<String> problems = Lists.newArrayList();
problems.addAll(myImporter.getErrors());
problems.addAll(myImporter.getWarnings());
if (!problems.isEmpty()) {
sb.append("\n");
for (String warning : problems) {
sb.append(" * ");
if (myWrapErrorMessages) {
sb.append(SdkUtils.wrap(warning, 80, " "));
} else {
sb.append(warning);
}
sb.append("\n");
}
}
if (myHasRiskyPathChars) {
sb.append(MSG_RISKY_PROJECT_LOCATION);
String path = myDestDir.getPath();
sb.append(path).append("\n");
for (int i = 0, n = path.length(); i < n; i++) {
char c = path.charAt(i);
sb.append(isRiskyPathChar(c) ? '-' : ' ');
}
sb.append("\n");
}
if (myManifestsMayDiffer) {
sb.append(MSG_MANIFEST);
}
if (!myNotMigrated.isEmpty()) {
sb.append(MSG_UNHANDLED);
List<String> modules = Lists.newArrayList(myNotMigrated.keySet());
Collections.sort(modules);
for (String module : modules) {
if (modules.size() > 1) {
sb.append("From ").append(module).append(":\n");
}
List<String> sorted = new ArrayList<String>(myNotMigrated.get(module));
Collections.sort(sorted);
for (String path : sorted) {
sb.append("* ").append(path).append("\n");
}
}
}
if (!myJarDependencies.isEmpty()) {
sb.append(MSG_REPLACED_JARS);
// TODO: Also add note here about switching to AAR's potentially also creating
// compilation errors because it now enforces that app min sdk version is >= library
// min sdk version, and suggesting that they re-run import with replaceJars=false
// if this leads to problems.
List<File> files = Lists.newArrayList(myJarDependencies.keySet());
Collections.sort(files);
for (File file : files) {
String jar = file.getName();
GradleCoordinate dependency = myJarDependencies.get(file);
sb.append(jar).append(" => ").append(dependency).append("\n");
}
}
if (!myGuessedDependencyVersions.isEmpty()) {
sb.append(MSG_GUESSED_VERSIONS);
Collections.sort(myGuessedDependencyVersions);
for (String replaced : myGuessedDependencyVersions) {
sb.append(replaced).append("\n");
}
}
if (!myLibDependencies.isEmpty()) {
sb.append(MSG_REPLACED_LIBS);
List<String> modules = Lists.newArrayList(myLibDependencies.keySet());
Collections.sort(modules);
for (String module : modules) {
List<GradleCoordinate> dependencies = myLibDependencies.get(module);
if (dependencies.size() == 1) {
sb.append(module).append(" => ").append(dependencies).append("\n");
} else {
sb.append(module).append(" =>\n");
for (GradleCoordinate dependency : dependencies) {
sb.append(" ").append(dependency).append("\n");
}
}
}
}
if (!myMoved.isEmpty()) {
sb.append(MSG_FOLDER_STRUCTURE);
List<ImportModule> modules = Lists.newArrayList(myMoved.keySet());
Collections.sort(modules);
for (ImportModule module : modules) {
if (modules.size() > 1) {
sb.append("In ").append(module.getOriginalName()).append(":\n");
}
Map<File, File> map = myMoved.get(module);
List<File> sorted = new ArrayList<File>(map.keySet());
Collections.sort(sorted);
for (File from : sorted) {
sb.append("* ");
File to = map.get(from);
assert to != null : from;
File fromRelative = null;
File toRelative = null;
try {
fromRelative = module.computeProjectRelativePath(from);
if (myDestDir != null) {
toRelative = GradleImport.computeRelativePath(myDestDir.getCanonicalFile(), to);
}
} catch (IOException ioe) {
// pass; use full path
}
if (fromRelative == null) {
fromRelative = from;
}
if (toRelative == null) {
toRelative = to;
}
sb.append(fromRelative.getPath());
if (from.isDirectory()) {
sb.append(File.separator);
}
sb.append(" => ");
sb.append(toRelative.getPath());
if (to.isDirectory()) {
sb.append(File.separator);
}
sb.append("\n");
}
}
}
if (myImporter.needSupportRepository() && myImporter.isMissingSupportRepository()) {
sb.append(MSG_MISSING_REPO_1);
sb.append(myImporter.getSdkLocation()).append("\n");
sb.append(MSG_MISSING_REPO_2);
}
if (myImporter.needGoogleRepository() && myImporter.isMissingGoogleRepository()) {
sb.append(MSG_MISSING_GOOGLE_REPOSITORY_1);
sb.append(myImporter.getSdkLocation()).append("\n");
sb.append(MSG_MISSING_GOOGLE_REPOSITORY_2);
}
if (Revision.parseRevision(myImporter.getBuildToolsVersion()).getMajor() < 19) {
sb.append(MSG_BUILD_TOOLS_VERSION);
}
if (!myIgnoredUserHomeProGuardFiles.isEmpty()) {
sb.append(MSG_USER_HOME_PROGUARD);
Collections.sort(myIgnoredUserHomeProGuardFiles);
for (String path : myIgnoredUserHomeProGuardFiles) {
sb.append(path).append("\n");
}
}
sb.append(MSG_FOOTER);
return sb.toString().replace("\n", GradleImport.NL);
}
Aggregations