Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dependency rake account for all version catalogs #435

Merged
merged 3 commits into from
Jun 30, 2023

Conversation

ZacSweers
Copy link
Collaborator

Resolves #406

@ZacSweers ZacSweers requested a review from arpita184 June 30, 2023 19:23
@github-actions
Copy link

  1. In the DependencyRake class, the rake() method starts with a check for an empty identifierMap. It would be more efficient to check for an empty identifierMap before even creating an instance of the DependencyRake class. This way, the rake() method won't be called at all if the identifierMap is empty.
- constructor(objects: ObjectFactory, providers: ProviderFactory) : AbstractPostProcessingTask() {
+ constructor(objects: ObjectFactory, providers: ProviderFactory) : AbstractPostProcessingTask() {
+   if (identifierMap.get().isEmpty()) {
+     logger.warn("No identifier map found. Skipping rake.")
+     enabled = false
+     return
+   }
   // Rest of the constructor code
  1. In the SlackGradleUtil class, the getVersionsCatalog() and getVersionsCatalogOrNull() methods can be combined into a single method with a default parameter for the catalog name.
internal fun Project.getVersionsCatalog(name: String = "libs"): VersionCatalog {
  return try {
    project.extensions.getByType<VersionCatalogsExtension>().named(name)
  } catch (ignored: Exception) {
    error("No versions catalog found!")
  }
}
  1. In the StandardProjectConfigurations class, the rakeDependencies task can be configured outside of the withId("com.autonomousapps.dependency-analysis") block to avoid unnecessary nesting.
internal class StandardProjectConfigurations(
  private val project: Project,
  private val slackProperties: SlackProperties,
  private val slackConfigurations: SlackConfigurations,
  private val logger: Logger
) {
  init {
    // Rest of the init code

    // Configure rake
    project.plugins.withId("com.autonomousapps.dependency-analysis") {
      configureRakeDependenciesTask()
    }
  }

  private fun configureRakeDependenciesTask() {
    val isNoApi = slackProperties.rakeNoApi
    val catalogNames = project.extensions.findByType<VersionCatalogsExtension>()?.catalogNames ?: return

    project.tasks.register<RakeDependencies>("rakeDependencies") {
      // Rest of the task configuration
    }
  }

  // Rest of the class code
}

These changes improve the code by reducing unnecessary checks and simplifying the code structure.

@ZacSweers ZacSweers enabled auto-merge June 30, 2023 19:27
}

internal fun Project.getVersionsCatalogOrNull(): VersionCatalog? {
internal fun Project.getVersionsCatalogOrNull(name: String = "libs"): VersionCatalog? {
return try {
project.extensions.getByType<VersionCatalogsExtension>().named("libs")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use "name" instead of hard coded "libs"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

derp

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZacSweers ZacSweers requested a review from arpita184 June 30, 2023 21:25
@ZacSweers ZacSweers added this pull request to the merge queue Jun 30, 2023
Merged via the queue into main with commit 335f321 Jun 30, 2023
@ZacSweers ZacSweers deleted the z/rakeAllCatalogs branch June 30, 2023 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make DependencyRake use all available version catalogs
2 participants