class LinkageMonitor {

  @VisibleForTesting
  static Bom copyWithSnapshot(
      RepositorySystem repositorySystem,
      RepositorySystemSession session,
      Bom bom,
      Map<String, String> localArtifacts)
      throws ModelBuildingException, ArtifactResolutionException {
    ImmutableList.Builder<Artifact> managedDependencies = ImmutableList.builder();

    Model model =
        buildModelWithSnapshotBom(repositorySystem, session, bom.getCoordinates(), localArtifacts);

    ArtifactTypeRegistry registry = session.getArtifactTypeRegistry();
    ImmutableList<Artifact> newManagedDependencies =
        model.getDependencyManagement().getDependencies().stream()
            .map(dependency -> RepositoryUtils.toDependency(dependency, registry))
            .map(Dependency::getArtifact)
            .collect(toImmutableList());
    for (Artifact managedDependency : newManagedDependencies) {
      if (Bom.shouldSkipBomMember(managedDependency)) {
        continue;
      }
      String version =
          localArtifacts.getOrDefault(
              managedDependency.getGroupId() + ":" + managedDependency.getArtifactId(),
              managedDependency.getVersion());
      managedDependencies.add(managedDependency.setVersion(version));
    }
    // "-SNAPSHOT" suffix for coordinate to distinguish easily.
    return new Bom(bom.getCoordinates() + "-SNAPSHOT", managedDependencies.build());
  }

}