forked from Splitties/refreshVersions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace the refreshVersionsCatalog task
We replace it with the new required mode option on the refreshVersionsMigrate task.
- Loading branch information
Showing
5 changed files
with
172 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...endencies/src/main/kotlin/de/fayard/refreshVersions/internal/VersionsCatalogGeneration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package de.fayard.refreshVersions.internal | ||
|
||
import de.fayard.refreshVersions.core.addMissingEntriesInVersionsProperties | ||
import de.fayard.refreshVersions.core.internal.Case | ||
import de.fayard.refreshVersions.core.internal.Deps | ||
import de.fayard.refreshVersions.core.internal.Library | ||
import de.fayard.refreshVersions.core.internal.MEANING_LESS_NAMES | ||
import de.fayard.refreshVersions.core.internal.OutputFile | ||
import de.fayard.refreshVersions.core.internal.UsedPluginsTracker | ||
import de.fayard.refreshVersions.core.internal.VersionsCatalogs | ||
import de.fayard.refreshVersions.core.internal.checkModeAndNames | ||
import de.fayard.refreshVersions.core.internal.computeAliases | ||
import de.fayard.refreshVersions.core.internal.findDependencies | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.Dependency | ||
import org.gradle.util.GradleVersion | ||
|
||
internal fun generateVersionsCatalogFromCurrentDependencies( | ||
project: Project, | ||
keepVersionsPlaceholders: Boolean, | ||
copyBuiltInDependencyNotationsToCatalog: Boolean | ||
) { | ||
if (VersionsCatalogs.isSupported().not()) { | ||
throw GradleException( | ||
""" | ||
|Gradle versions catalogs are not supported in ${GradleVersion.current()} | ||
|Upgrade Gradle with this command | ||
| ./gradlew wrapper --gradle-version ${VersionsCatalogs.minimumGradleVersion.version} | ||
""".trimMargin() | ||
) | ||
} | ||
// Update versions.properties | ||
addMissingEntriesInVersionsProperties(project) | ||
|
||
// Generate LIBS_VERSIONS_TOML | ||
val catalog = OutputFile.GRADLE_VERSIONS_CATALOG | ||
|
||
val builtInDependencies = getArtifactNameToConstantMapping() | ||
|
||
val allDependencies: List<Library> = project.findDependencies() | ||
|
||
val dependenciesToUse = when { | ||
copyBuiltInDependencyNotationsToCatalog -> allDependencies | ||
else -> allDependencies.filter { | ||
builtInDependencies.none { builtInDependency -> | ||
builtInDependency.group == it.group && builtInDependency.artifact == it.name | ||
} | ||
} | ||
} | ||
|
||
val plugins = UsedPluginsTracker.usedPluginsWithoutEntryInVersionsFile + | ||
UsedPluginsTracker.read().map { it.first } | ||
|
||
val versionCatalogAliases: List<String> = dependenciesToUse.computeAliases( | ||
configured = emptyList(), | ||
byDefault = MEANING_LESS_NAMES | ||
) | ||
|
||
val deps: Deps = dependenciesToUse.checkModeAndNames(versionCatalogAliases, Case.`kebab-case`) | ||
val dependenciesAndNames: Map<Dependency, String> = deps.names.mapKeys { it.key.toDependency() } | ||
|
||
val currentText = if (catalog.existed) catalog.readText() else "" | ||
val newText = VersionsCatalogs.generateVersionsCatalogText( | ||
dependenciesAndNames = dependenciesAndNames, | ||
currentText = currentText, | ||
moveVersionsToCatalog = keepVersionsPlaceholders.not(), | ||
plugins = plugins | ||
) | ||
catalog.writeText(newText) | ||
catalog.logFileWasModified() | ||
} |