override fun execute()

in ide-diff-builder/src/main/java/org/jetbrains/ide/diff/builder/cli/BuildIdeApiAnnotationsCommand.kt [66:124]


  override fun execute(freeArgs: List<String>) {
    val cliOptions = CliOptions()
    val args = Args.parse(cliOptions, freeArgs.toTypedArray(), false)

    val resultsDirectory = Paths.get(args[0])
    resultsDirectory.createDir()
    LOG.info("Results will be saved to $resultsDirectory")

    val jdkPath = cliOptions.getJdkPath()
    LOG.info("JDK will be used to resolve java classes: $jdkPath")

    val classFilter = cliOptions.classFilter()
    LOG.info(classFilter.toString())

    val idesDir = cliOptions.getIdesDirectory()
    LOG.info("IDE cache directory to use: $idesDir")

    val ideFilesBank = createIdeFilesBank(idesDir)

    val repositoryToIdes = allIdeRepositories.associateWith { repository ->
      repository
        .fetchIndex()
        .filter { it.version.productCode == "IU" && it.version >= MIN_BUILD_NUMBER }
        .sortedBy { it.version }
    }

    val allIdesToProcess = repositoryToIdes.flatMap { it.value }.distinctBy { it.version }.sortedBy { it.version }

    LOG.info("The following ${allIdesToProcess.size} IU IDEs (> $MIN_BUILD_NUMBER) are available in all IDE repositories: " + allIdesToProcess.joinToString())

    val metadata = BuildIdeApiMetadata().buildMetadata(
      allIdesToProcess,
      ideFilesBank,
      jdkPath,
      classFilter,
      resultsDirectory
    )

    val metadataPath = resultsDirectory.resolve("metadata.json")
    JsonApiReportWriter().saveReport(metadata, metadataPath)
    LOG.info("The API metadata has been saved to ${metadataPath.simpleName}.")

    LOG.info("Building annotations for last IDEs of each branch.")
    val lastBranchIdes = repositoryToIdes.values
      .flatMap { ides ->
        ides
          .groupBy { it.version.baselineVersion }
          .mapValues { (_, branchIdes) -> branchIdes.maxByOrNull { it.version }!! }
          .values
      }
      .map { it.version }
      .distinct()
      .sorted()

    LOG.info("Last branch IDEs: $lastBranchIdes")

    val annotationsClassFilter = AndClassFilter(listOf(classFilter, NonImplementationClassFilter))
    buildExternalAnnotations(metadata, resultsDirectory, lastBranchIdes, annotationsClassFilter)
  }