use of com.android.ide.common.blame.SourceFilePosition in project android by JetBrains.
the class AndroidManifestMergingBuilder method doMergeManifests.
private static boolean doMergeManifests(final CompileContext context, File manifestFile, List<File> libManifests, File outputFile) throws IOException {
final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
if (testingManager != null) {
final StringBuilder messageBuilder = new StringBuilder("manifest_merging\n");
messageBuilder.append(manifestFile.getPath()).append('\n');
Collections.sort(libManifests);
for (File libManifest : libManifests) {
messageBuilder.append(libManifest.getPath()).append('\n');
}
messageBuilder.append(outputFile.getPath());
testingManager.getCommandExecutor().log(messageBuilder.toString());
}
ImmutableList.Builder<Pair<String, File>> libraryFiles = ImmutableList.builder();
for (File f : libManifests) {
libraryFiles.add(Pair.of(f.getName(), f));
}
final ManifestMerger2.Invoker manifestMergerInvoker = ManifestMerger2.newMerger(manifestFile, NullLogger.getLogger(), ManifestMerger2.MergeType.APPLICATION).addBundleManifests(libraryFiles.build());
MergingReport mergingReport;
try {
mergingReport = manifestMergerInvoker.merge();
} catch (ManifestMerger2.MergeFailureException e) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, e.getMessage()));
return false;
}
MergingReport.Result result = mergingReport.getResult();
for (MergingReport.Record record : mergingReport.getLoggingRecords()) {
SourceFilePosition position = record.getSourceLocation();
File sourceFile = position.getFile().getSourceFile();
String sourceFilePath = sourceFile != null ? sourceFile.getAbsolutePath() : null;
SourcePosition pos = position.getPosition();
MergingReport.Record.Severity severity = record.getSeverity();
if (severity != MergingReport.Record.Severity.INFO) {
context.processMessage(new CompilerMessage(BUILDER_NAME, toBuildMessageKind(record.getSeverity()), record.getMessage(), sourceFilePath, pos.getStartOffset(), pos.getEndOffset(), pos.getEndOffset(), pos.getEndLine(), pos.getEndColumn()));
}
}
if (!result.isError()) {
String xmlDocument = mergingReport.getMergedDocument(MergingReport.MergedManifestKind.MERGED);
Files.write(xmlDocument, outputFile, Charsets.UTF_8);
}
return result.isSuccess();
}
Aggregations