com.android.manifmerger.MergingReport Java Examples

The following examples show how to use com.android.manifmerger.MergingReport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AndroidManifestProcessor.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void writeMergedManifest(
    MergedManifestKind mergedManifestKind, MergingReport mergingReport, Path manifestOut)
    throws ManifestProcessingException {
  String manifestContents = mergingReport.getMergedDocument(mergedManifestKind);
  String annotatedDocument = mergingReport.getMergedDocument(MergedManifestKind.BLAME);
  stdLogger.verbose(annotatedDocument);
  try {
    Files.write(manifestOut, manifestContents.getBytes(UTF_8));
  } catch (IOException e) {
    throw new ManifestProcessingException(e);
  }
}
 
Example #2
Source File: GenerateManifestStep.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException {

  if (skeletonManifestPath.getNameCount() == 0) {
    throw new HumanReadableException("Skeleton manifest filepath is missing");
  }

  if (outManifestPath.getNameCount() == 0) {
    throw new HumanReadableException("Output Manifest filepath is missing");
  }

  Path resolvedOutManifestPath = filesystem.resolve(outManifestPath);
  Files.createParentDirs(resolvedOutManifestPath.toFile());

  List<File> libraryManifestFiles = new ArrayList<>();

  for (Path path : libraryManifestPaths) {
    Path manifestPath = filesystem.getPathForRelativeExistingPath(path).toAbsolutePath();
    libraryManifestFiles.add(manifestPath.toFile());
  }

  File skeletonManifestFile =
      filesystem.getPathForRelativeExistingPath(skeletonManifestPath).toAbsolutePath().toFile();
  BuckEventAndroidLogger logger = new ManifestMergerLogger(context.getBuckEventBus());

  MergingReport mergingReport =
      mergeManifests(skeletonManifestFile, libraryManifestFiles, logger);

  String xmlText = mergingReport.getMergedDocument(MergingReport.MergedManifestKind.MERGED);
  if (context.getPlatform() == Platform.WINDOWS) {
    // Convert line endings to Lf on Windows.
    xmlText = xmlText.replace("\r\n", "\n");
  }
  filesystem.writeContentsToPath(xmlText, resolvedOutManifestPath);

  return StepExecutionResults.SUCCESS;
}
 
Example #3
Source File: GenerateManifestStep.java    From buck with Apache License 2.0 5 votes vote down vote up
private MergingReport mergeManifests(
    File mainManifestFile, List<File> libraryManifestFiles, BuckEventAndroidLogger logger) {
  try {
    ManifestMerger2.Invoker<?> manifestInvoker =
        ManifestMerger2.newMerger(
            mainManifestFile, logger, ManifestMerger2.MergeType.APPLICATION);
    if (!module.isRootModule()) {
      manifestInvoker.setPlaceHolderValue("split", module.getName());
    } else {
      manifestInvoker.withFeatures(ManifestMerger2.Invoker.Feature.NO_PLACEHOLDER_REPLACEMENT);
    }

    MergingReport mergingReport =
        manifestInvoker
            .withFeatures(
                ManifestMerger2.Invoker.Feature.REMOVE_TOOLS_DECLARATIONS,
                ManifestMerger2.Invoker.Feature.SKIP_BLAME)
            .addLibraryManifests(Iterables.toArray(libraryManifestFiles, File.class))
            .setMergeReportFile(mergeReportPath.toFile())
            .merge();
    if (mergingReport.getResult().isError()) {
      for (MergingReport.Record record : mergingReport.getLoggingRecords()) {
        logger.error(null, record.toString());
      }
      throw new HumanReadableException("Error generating manifest file");
    }

    return mergingReport;
  } catch (ManifestMerger2.MergeFailureException e) {
    throw new HumanReadableException(
        e.getCause(), "Error generating manifest file: %s", e.getMessage());
  }
}
 
Example #4
Source File: AtlasBuilder.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
public MergingReport mergeManifestsForApplication(
        @NonNull File mainManifest,
        @NonNull List<File> manifestOverlays,
        @NonNull List<? extends ManifestProvider> dependencies,
        @Nullable String featureName,
        String packageOverride,
        int versionCode,
        String versionName,
        @Nullable String minSdkVersion,
        @Nullable String targetSdkVersion,
        @Nullable Integer maxSdkVersion,
        @NonNull String outManifestLocation,
        @Nullable String outAaptSafeManifestLocation,
        @Nullable String outInstantRunManifestLocation,
        ManifestMerger2.MergeType mergeType,
        Map<String, Object> placeHolders,
        @NonNull List<ManifestMerger2.Invoker.Feature> optionalFeatures,
        @Nullable File reportFile) {


    return super.mergeManifestsForApplication(
            mainManifest,
            manifestOverlays,
            manifestProviders,
            featureName,
            packageOverride,
            versionCode,
            versionName,
            minSdkVersion,
            targetSdkVersion,
            maxSdkVersion,
            outManifestLocation,
            outAaptSafeManifestLocation,
            outInstantRunManifestLocation,
            mergeType,
            placeHolders,
            optionalFeatures,
            reportFile);

}
 
Example #5
Source File: AndroidManifestProcessor.java    From bazel with Apache License 2.0 4 votes vote down vote up
private void processManifest(
    int versionCode,
    String versionName,
    Path primaryManifest,
    Path processedManifest,
    MergeType mergeType,
    String newManifestPackage,
    boolean logWarnings) {
  try {
    Files.createDirectories(processedManifest.getParent());

    // The generics on Invoker don't make sense, so ignore them.
    @SuppressWarnings("unchecked")
    Invoker<?> manifestMergerInvoker =
        ManifestMerger2.newMerger(primaryManifest.toFile(), stdLogger, mergeType);
    // Stamp new package
    if (newManifestPackage != null) {
      manifestMergerInvoker.setOverride(SystemProperty.PACKAGE, newManifestPackage);
    }
    // Stamp version and applicationId (if provided) into the manifest
    if (versionCode > 0) {
      manifestMergerInvoker.setOverride(SystemProperty.VERSION_CODE, String.valueOf(versionCode));
    }
    if (versionName != null) {
      manifestMergerInvoker.setOverride(SystemProperty.VERSION_NAME, versionName);
    }

    MergedManifestKind mergedManifestKind = MergedManifestKind.MERGED;
    if (mergeType == MergeType.APPLICATION) {
      manifestMergerInvoker.withFeatures(Feature.REMOVE_TOOLS_DECLARATIONS);
    }

    MergingReport mergingReport = manifestMergerInvoker.merge();
    switch (mergingReport.getResult()) {
      case WARNING:
        if (logWarnings) {
          mergingReport.log(stdLogger);
        }
        writeMergedManifest(mergedManifestKind, mergingReport, processedManifest);
        break;
      case SUCCESS:
        writeMergedManifest(mergedManifestKind, mergingReport, processedManifest);
        break;
      case ERROR:
        mergingReport.log(stdLogger);
        throw new ManifestProcessingException(mergingReport.getReportString());
      default:
        throw new ManifestProcessingException(
            "Unhandled result type : " + mergingReport.getResult());
    }
  } catch (IOException | MergeFailureException e) {
    throw new ManifestProcessingException(e);
  }
}