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

Upgrade Spotless minor version and reformat #167

Merged
merged 9 commits into from
Feb 18, 2023
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ root = true
indent_style = space
insert_final_newline = true
charset = utf-8
end_of_line = lf

[*.{kt,kts}]
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
ij_java_use_single_class_imports = true
max_line_length = off
trim_trailing_whitespace = true
# Trailing comma language feature requires Kotlin plugin 1.4+, at the moment the compilation is done with Kotlin 1.3.
# This helps IDEA to format the code properly, see also spotless { } in build.gradle.kts.
ij_kotlin_allow_trailing_comma = false # Only used for declaration site
ij_kotlin_allow_trailing_comma_on_call_site = false

[*.bat]
end_of_line = crlf
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text eol=lf
*.bat eol=crlf
*.png binary
*.jar binary
15 changes: 12 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
`kotlin-dsl`
id("com.gradle.plugin-publish") version "1.1.0"
id("com.diffplug.spotless") version "6.0.0"
// From 6.14.0 onwards Spotless requires Gradle to be on Java 11,
// but we still use Java 8 in .github/workflows/java-versions.yml.
id("com.diffplug.spotless") version "6.13.0"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("org.jetbrains.gradle.plugin.idea-ext")
id("com.github.ben-manes.versions") version "0.45.0"
Expand Down Expand Up @@ -41,10 +43,17 @@ repositories {

val licenseHeaderFile = file("gradle/license-header.txt")
spotless {
lineEndings = com.diffplug.spotless.LineEnding.UNIX
TWiStErRob marked this conversation as resolved.
Show resolved Hide resolved
kotlin {
targetExclude("**/*.gradle.kts", "**/build/generated-sources/**/*.kt")
//"import-ordering" required here as it started to fail after spotless plugin upgrade to 0.35.0 - resolve in separate PR
ktlint().userData(mapOf("disabled_rules" to "comment-spacing,import-ordering"))
ktlint().editorConfigOverride(
mapOf(
// Trailing comma language feature requires Kotlin plugin 1.4+, at the moment the compilation is done with Kotlin 1.3.
// This helps spotlessKotlinCheck and spotlessApply to format the code properly, see also .editorconfig.
"ktlint_standard_trailing-comma-on-call-site" to "disabled",
"ktlint_standard_trailing-comma-on-declaration-site" to "disabled"
)
)
licenseHeaderFile(licenseHeaderFile)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class NexusPublishPluginTests {
@Test
fun `can get StagingProfileId from Nexus`() {
writeDefaultSingleProjectConfiguration()
//and
// and
buildGradle.append(
"""
nexusPublishing {
Expand All @@ -130,7 +130,7 @@ class NexusPublishPluginTests {
}
"""
)
//and
// and
stubGetStagingProfilesForOneProfileIdGivenId(STAGING_PROFILE_ID)

val result = run("retrieveSonatypeStagingProfile")
Expand Down Expand Up @@ -294,7 +294,10 @@ class NexusPublishPluginTests {
}

@Test
fun `publishes to two Nexus repositories`(@MethodScopeWiremockResolver.MethodScopedWiremockServer @Wiremock otherServer: WireMockServer) {
fun `publishes to two Nexus repositories`(
@MethodScopeWiremockResolver.MethodScopedWiremockServer @Wiremock
otherServer: WireMockServer
) {
szpak marked this conversation as resolved.
Show resolved Hide resolved
projectDir.resolve("settings.gradle").write(
"""
rootProject.name = 'sample'
Expand Down Expand Up @@ -689,7 +692,8 @@ class NexusPublishPluginTests {
stubGetStagingRepoWithIdAndStateRequest(
StagingRepository(
stagingRepositoryId,
operation.desiredState, false
operation.desiredState,
false
)
)
}
Expand Down Expand Up @@ -721,13 +725,13 @@ class NexusPublishPluginTests {
assertReleaseOfStagingRepo()
}

//TODO: Move to separate subclass with command line tests for @Option
//TODO: Consider switching to parameterized tests for close and release
// TODO: Move to separate subclass with command line tests for @Option
// TODO: Consider switching to parameterized tests for close and release
@Test
fun `should allow to take staging repo id to close from command line without its initialization`() {
writeDefaultSingleProjectConfiguration()
writeMockedSonatypeNexusPublishingConfiguration()
//and
// and
szpak marked this conversation as resolved.
Show resolved Hide resolved
stubCloseStagingRepoRequestWithSubsequentQueryAboutItsState(OVERRIDDEN_STAGED_REPOSITORY_ID)

val result = run("closeSonatypeStagingRepository", "--staging-repository-id=$OVERRIDDEN_STAGED_REPOSITORY_ID")
Expand All @@ -740,7 +744,7 @@ class NexusPublishPluginTests {
fun `should allow to take staging repo id to release from command line without its initialization`() {
writeDefaultSingleProjectConfiguration()
writeMockedSonatypeNexusPublishingConfiguration()
//and
// and
stubReleaseStagingRepoRequestWithSubsequentQueryAboutItsState(OVERRIDDEN_STAGED_REPOSITORY_ID)

val result = run("releaseSonatypeStagingRepository", "--staging-repository-id=$OVERRIDDEN_STAGED_REPOSITORY_ID")
Expand All @@ -762,7 +766,7 @@ class NexusPublishPluginTests {
@Test
internal fun `initialize task should resolve stagingProfileId if not provided and keep it for close task`() {
writeDefaultSingleProjectConfiguration()
//and
// and
buildGradle.append(
"""
nexusPublishing {
Expand All @@ -776,7 +780,7 @@ class NexusPublishPluginTests {
}
"""
)
//and
// and
stubGetStagingProfilesForOneProfileIdGivenId(STAGING_PROFILE_ID)
stubCreateStagingRepoRequest("/staging/profiles/$STAGING_PROFILE_ID/start", STAGED_REPOSITORY_ID)
stubCloseStagingRepoRequestWithSubsequentQueryAboutItsState()
Expand All @@ -785,16 +789,16 @@ class NexusPublishPluginTests {

assertSuccess(result, ":initializeSonatypeStagingRepository")
assertSuccess(result, ":closeSonatypeStagingRepository")
//and
// and
assertGetStagingProfile(1)
}

//TODO: Parameterize them
// TODO: Parameterize them
@Test
internal fun `close task should retry getting repository state on transitioning`() {
writeDefaultSingleProjectConfiguration()
writeMockedSonatypeNexusPublishingConfiguration()
//and
// and
stubTransitToDesiredStateStagingRepoRequest(StagingRepoTransitionOperation.CLOSE)
stubGetGivenStagingRepositoryInFirstAndSecondCall(
StagingRepository(STAGED_REPOSITORY_ID, StagingRepository.State.OPEN, true),
Expand All @@ -804,15 +808,15 @@ class NexusPublishPluginTests {
val result = run("closeSonatypeStagingRepository", "--staging-repository-id=$STAGED_REPOSITORY_ID")

assertSuccess(result, ":closeSonatypeStagingRepository")
//and
// and
assertGetStagingRepository(STAGED_REPOSITORY_ID, 2)
}

@Test
internal fun `release task should retry getting repository state on transitioning`() {
writeDefaultSingleProjectConfiguration()
writeMockedSonatypeNexusPublishingConfiguration()
//and
// and
stubTransitToDesiredStateStagingRepoRequest(StagingRepoTransitionOperation.RELEASE)
stubGetGivenStagingRepositoryInFirstAndSecondCall(
StagingRepository(STAGED_REPOSITORY_ID, StagingRepository.State.CLOSED, true),
Expand All @@ -822,7 +826,7 @@ class NexusPublishPluginTests {
val result = run("releaseSonatypeStagingRepository", "--staging-repository-id=$STAGED_REPOSITORY_ID")

assertSuccess(result, ":releaseSonatypeStagingRepository")
//and
// and
assertGetStagingRepository(STAGED_REPOSITORY_ID, 2)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ class NexusPublishE2ETests : BaseGradleTest() {
fun `release project to real Sonatype Nexus`(projectName: String) {
File("src/e2eTest/resources/$projectName").copyRecursively(projectDir)

//when
// when
val buildResult = run("build")
//then
// then
buildResult.assertSuccess { it.path.substringAfterLast(':').matches("build".toRegex()) }

//when
// when
val result = run(
"publishToSonatype",
"closeAndReleaseSonatypeStagingRepository",
"--info"
)
//then
// then
result.apply {
assertSuccess { it.path.substringAfterLast(':').matches("publish.+PublicationToSonatypeRepository".toRegex()) }
assertSuccess(":closeSonatypeStagingRepository")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository
set(extension.connectTimeout)
}

//TODO: Expose externally as interface with getters only
// TODO: Expose externally as interface with getters only
@Nested
val repository = objects.property<NexusRepository>().apply {
set(repository)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ open class NexusPublishExtension(project: Project) {
set(project.provider { project.run { "$group:$name:$version" } })
}

val clientTimeout = project.objects.property<Duration>().value(Duration.ofMinutes(5)) //staging repository initialization can take a few minutes on Sonatype Nexus
// staging repository initialization can take a few minutes on Sonatype Nexus
val clientTimeout = project.objects.property<Duration>().value(Duration.ofMinutes(5))

val connectTimeout = project.objects.property<Duration>().value(Duration.ofMinutes(5))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import org.gradle.util.GradleVersion
class NexusPublishPlugin : Plugin<Project> {

companion object {
//visibility for testing
// visibility for testing
const val SIMPLIFIED_CLOSE_AND_RELEASE_TASK_NAME = "closeAndReleaseStagingRepository"
}

Expand Down Expand Up @@ -70,13 +70,25 @@ class NexusPublishPlugin : Plugin<Project> {
val repository = this
val retrieveStagingProfileTask = rootProject.tasks.register<RetrieveStagingProfile>("retrieve${capitalizedName}StagingProfile", rootProject.objects, extension, repository)
val initializeTask = rootProject.tasks.register<InitializeNexusStagingRepository>(
"initialize${capitalizedName}StagingRepository", rootProject.objects, extension, repository, registry
"initialize${capitalizedName}StagingRepository",
rootProject.objects,
extension,
repository,
registry
)
val closeTask = rootProject.tasks.register<CloseNexusStagingRepository>(
"close${capitalizedName}StagingRepository", rootProject.objects, extension, repository, registry
"close${capitalizedName}StagingRepository",
rootProject.objects,
extension,
repository,
registry
)
val releaseTask = rootProject.tasks.register<ReleaseNexusStagingRepository>(
"release${capitalizedName}StagingRepository", rootProject.objects, extension, repository, registry
"release${capitalizedName}StagingRepository",
rootProject.objects,
extension,
repository,
registry
)
val closeAndReleaseTask = rootProject.tasks.register<Task>(
"closeAndRelease${capitalizedName}StagingRepository"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ open class BasicActionRetrier<R>(maxRetries: Int, delayBetween: Duration, stopFu
private val maxAttempts: Int = maxRetries + 1

private val retrier: RetryPolicy<R> = RetryPolicy<R>()
//TODO: Some exceptions could be handled separately
// TODO: Some exceptions could be handled separately
.handleResultIf(stopFunction)
.onFailedAttempt { event ->
log.info("Attempt ${event.attemptCount}/$maxAttempts failed with result: ${event.lastResult}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ open class NexusClient(private val baseUrl: URI, username: String?, password: St
"Unexpected read repository id ($stagingRepositoryId != ${readStagingRepo.repositoryId})"
}
return StagingRepository(
readStagingRepo.repositoryId, StagingRepository.State.parseString(readStagingRepo.type),
readStagingRepo.repositoryId,
StagingRepository.State.parseString(readStagingRepo.type),
readStagingRepo.transitioning
)
} else {
return StagingRepository.notFound(stagingRepositoryId) //Should not happen
return StagingRepository.notFound(stagingRepositoryId) // Should not happen
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ class TaskOrchestrationTest {
@ParameterizedTest(name = "task: {0}")
@MethodSource("transitioningTaskNamesForSonatype")
internal fun `transitioning task should not run after non-related publish`(transitioningTaskName: String) {
//given
// given
initSingleProjectWithDefaultConfiguration()
project.extensions.configure<NexusPublishExtension> {
repositories.add(NexusRepository("myNexus", project))
}
//expect
// expect
assertGivenTaskMustNotRunAfterAnother(transitioningTaskName, "publishToMyNexus")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal class StagingRepositoryTransitionerTest {

@Mock
private lateinit var nexusClient: NexusClient

@Mock
private lateinit var retrier: ActionRetrier<StagingRepository>

Expand Down