From 48b6a001b9e2b14c2f69e1cd336996942dbb0233 Mon Sep 17 00:00:00 2001 From: Ned Twigg <ned.twigg@diffplug.com> Date: Tue, 26 Dec 2023 17:39:36 -0800 Subject: [PATCH 1/2] Go back to the blowdryer scripts. --- build.gradle | 2 +- gradle/changelog.gradle | 97 --------------------------- gradle/maven.gradle | 108 ------------------------------ selfie-lib/build.gradle | 4 +- selfie-runner-junit5/build.gradle | 4 +- settings.gradle | 2 +- 6 files changed, 6 insertions(+), 211 deletions(-) delete mode 100644 gradle/changelog.gradle delete mode 100644 gradle/maven.gradle diff --git a/build.gradle b/build.gradle index db9e251e..a919587b 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ repositories { } group = 干.proj('maven_group', 'the maven group, recommend com.diffplug') apply from: rootProject.file('gradle/spotless.gradle') -apply from: rootProject.file('gradle/changelog.gradle') +apply from: 干.file('base/changelog.gradle') apply from: 干.file('base/sonatype.gradle') // ./gradlew :dokkatooGeneratePublicationHtml diff --git a/gradle/changelog.gradle b/gradle/changelog.gradle deleted file mode 100644 index 7778119a..00000000 --- a/gradle/changelog.gradle +++ /dev/null @@ -1,97 +0,0 @@ -// no parameters needed, just apply `com.diffplug.spotless-changelog` on whichever project has -// CHANGELOG.md -// -// this script will look for the changelog tasks in either this project or the parent project, -// and then set the version from the spotless-changelog plugin. It will also hook the jar task -// (if present) to depend on changelogCheck, so that a jar will never get published with a bad -// changelog. Lastly, changelogBump will depend on a successful closeAndReleaseSonatypeStagingRepository. - -def requireEnablePublishing(Task task) { - if (project.findProperty('enable_publishing') == 'true') { - return true - } else { - task.doFirst { - throw new Error("Cannot run " + task + " without specifying enable_publishing=true") - } - return false - } -} - -def List<String> pubNames() { - if (plugins.hasPlugin('java-gradle-plugin')) { - return ['PluginMaven'] - } else if (plugins.hasPlugin('org.jetbrains.kotlin.multiplatform')) { - return ['KotlinMultiplatform', 'Jvm'] - } else { - return ['MavenJava'] - } -} - -if (tasks.names.contains('changelogCheck')) { - spotlessChangelog { - branch 'release' - appendDashSnapshotUnless_dashPrelease = true - } - // set the project version for POM, jar manifest, etc. - version = spotlessChangelog.versionNext - // ensures that nothing will be built if changelogPush will end up failing - afterEvaluate { - if (tasks.names.contains('jar')) { - tasks.named('jar').configure { - dependsOn tasks.named('changelogCheck') - } - } - // ensures that changelog bump and push only happens if the publish was successful - tasks.named('changelogBump').configure { - if (requireEnablePublishing(it)) { - if (plugins.hasPlugin('maven-publish')) { - if (plugins.hasPlugin('io.github.gradle-nexus.publish-plugin')) { - for (pubName in pubNames()) { - dependsOn "publish${pubName}PublicationToSonatypeRepository" - } - // only the root project has closeSonatypeStagingRepository, and it finalizes all publishToSonatype tasks - // https://github.com/gradle-nexus/publish-plugin - dependsOn rootProject.tasks.named('closeAndReleaseSonatypeStagingRepository') - } else { - dependsOn "publishAllPublicationsToGitLabRepository" - } - } - // if we have a gradle plugin, we need to push it up to the plugin portal too - if (tasks.names.contains('publishPlugins')) { - dependsOn tasks.named('publishPlugins') - } - } - } - } -} else { - assert parent != null : 'If you apply this script to the root project, you must have plugin com.diffplug.spotless-changelog' - assert parent.tasks.names.contains('changelogCheck') : 'Neither this project nor its parent had the required plugin com.diffplug.spotless-changelog' - - // same as above, but pull changelog stuff from the parent changelog - version = parent.spotlessChangelog.versionNext - def childProject = project; - afterEvaluate { - if (tasks.names.contains('jar')) { - tasks.named('jar').configure { - dependsOn parent.tasks.named('changelogCheck') - } - } - parent.tasks.named('changelogBump').configure { - if (requireEnablePublishing(it)) { - if (childProject.plugins.hasPlugin('maven-publish')) { - if (rootProject.plugins.hasPlugin('io.github.gradle-nexus.publish-plugin')) { - for (pubName in pubNames()) { - dependsOn childProject.tasks.named("publish${pubName}PublicationToSonatypeRepository") - } - dependsOn rootProject.tasks.named('closeAndReleaseSonatypeStagingRepository') - } else { - dependsOn childProject.tasks.named("publishAllPublicationsToGitLabRepository") - } - } - if (childProject.tasks.names.contains('publishPlugins')) { - dependsOn childProject.tasks.named('publishPlugins') - } - } - } - } -} diff --git a/gradle/maven.gradle b/gradle/maven.gradle deleted file mode 100644 index 047bdb00..00000000 --- a/gradle/maven.gradle +++ /dev/null @@ -1,108 +0,0 @@ -// 干.mustRunAfter('base/gradle-plugin') -// 干.mustRunAfter('base/changelog') - -apply plugin: 'maven-publish' - -def git_url = 干.proj('git_url', 'the git url with no protocol, e.g.: github.com/diffplug/blowdryer') -assert !git_url.startsWith('https://') : 'git_url should not start with https://' -assert !git_url.startsWith('http://') : 'git_url should not start with http://' - -group = 干.proj('maven_group', 'the maven group, recommend com.diffplug') -def maven_artifact = project.name -def maven_name = 干.proj('maven_name', 'human-friendly name') -def maven_desc = 干.proj('maven_desc', 'human-friendly description') - -def javadocLinks = 干.proj('javadoc_links', "space-delimited links, if you add '/package-list' to the urls you should get a package list").split() -def license = 干.proj('license', 'supported: [apache, confidential, lgpl-2.1]') - -def license_name = 干.prop('base/maven', "${license}_name") -def license_url = 干.prop('base/maven', "${license}_url") -def license_comments = 干.prop('base/maven', "${license}_comments") - -boolean isKMP = project.pluginManager.hasPlugin('org.jetbrains.kotlin.multiplatform') -boolean isPlugin = plugins.hasPlugin('java-gradle-plugin') - -if (!isKMP) { - java { - withJavadocJar() - withSourcesJar() - } - - tasks.named('sourcesJar') { - dependsOn 'jar' - } - - javadoc { - def makeLink = { url, text -> "<a href=\"${url}\" style=\"text-transform: none;\">${text}</a>" } - def javadocInfo = '<h2>' + makeLink("https://${git_url}", "${maven_artifact}:${version}") + - ' by ' + makeLink('https://www.diffplug.com', 'DiffPlug') + '</h2>'; - // Where it's possible to name parameters and methods clearly enough - // that javadoc is not necessary, why make the code bigger? - // Thus, no javadoc warnings. - options.addStringOption('Xdoclint:none', '-quiet') - // UTF-8!!! Thanks to: https://github.com/freefair/gradle-plugins/blob/6d6f5ff6036e7da1c329075a02c6452c0bb669be/maven-plugin/src/main/java/io/freefair/gradle/plugins/maven/javadoc/JavadocUtf8Plugin.java - options.charSet('UTF-8'); - options.docEncoding('UTF-8'); - options.setEncoding('UTF-8'); - // setup the header - options.header javadocInfo - options.footer javadocInfo - // setup links - options.links(javadocLinks) - } - apply from: 干.file('helper/javadoc-view.gradle') -} - - -if (publishing.publications.isEmpty()) { - publishing.publications.register(isPlugin ? 'pluginMaven' : 'mavenJava', MavenPublication, { - }) -} - -publishing.publications.withType(MavenPublication) { - // KMP-aware artifactId - if (artifactId.endsWith('-jvm')) { - artifactId = maven_artifact + '-jvm' - // create javadoc manually to keep MavenCentral happy - def javadocJar = tasks.register('dokkaJavadoc', Jar.class) { - dependsOn('dokkatooGenerate') - archiveClassifier.set("javadoc") - from('build/dokka-module/html') - } - artifact javadocJar - } else if (artifactId.endsWith("-js")) { - artifactId = maven_artifact + '-js' - } else { - artifactId = maven_artifact - } - if (!isPlugin && !isKMP) { - from components.java - } - pom { - name = maven_name - description = maven_desc - url = "https://$git_url" - licenses { - // has to be it.license because of parameter license above - it.license { - // https://maven.apache.org/pom.html#Licenses - name = license_name - url = license_url - distribution = 'repo' - comments = license_comments - } - } - developers { - developer { - id = 'nedtwigg' - name = 'Ned Twigg' - email = 'ned.twigg@diffplug.com' - } - } - scm { - connection = "scm:git:git://${git_url}.git" - developerConnection = "scm:git:ssh://${git_url}.git" - url = "https://$git_url" - } - } -} diff --git a/selfie-lib/build.gradle b/selfie-lib/build.gradle index 160364d7..83e59c72 100644 --- a/selfie-lib/build.gradle +++ b/selfie-lib/build.gradle @@ -11,7 +11,7 @@ ext { maven_desc = 'Core logic and parsing for Selfie' } -apply from: rootProject.file('gradle/changelog.gradle') +apply from: 干.file('base/changelog.gradle') apply from: rootProject.file('gradle/spotless.gradle') kotlin { jvm { @@ -40,5 +40,5 @@ tasks.create('test') { } // it all needs to get published and formatted -apply from: rootProject.file('gradle/maven.gradle') +apply from: 干.file('base/maven.gradle') apply from: 干.file('base/sonatype.gradle') \ No newline at end of file diff --git a/selfie-runner-junit5/build.gradle b/selfie-runner-junit5/build.gradle index 4f0d5ee6..e834c719 100644 --- a/selfie-runner-junit5/build.gradle +++ b/selfie-runner-junit5/build.gradle @@ -9,7 +9,7 @@ ext { maven_desc = 'JUnit 5 test runner for Selfie' } -apply from: rootProject.file('gradle/changelog.gradle') +apply from: 干.file('base/changelog.gradle') apply from: rootProject.file('gradle/spotless.gradle') apply plugin: 'java-library' dependencies { @@ -31,5 +31,5 @@ test { } // it all needs to get published and formatted -apply from: rootProject.file('gradle/maven.gradle') +apply from: 干.file('base/maven.gradle') apply from: 干.file('base/sonatype.gradle') diff --git a/settings.gradle b/settings.gradle index a8528ed0..a6212ce1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -30,7 +30,7 @@ plugins { } blowdryerSetup { - github 'diffplug/blowdryer-diffplug', 'tag', '7.1.1' + github 'diffplug/blowdryer-diffplug', 'tag', '7.2.0' //devLocal '../blowdryer-diffplug' setPluginsBlockTo { it.file 'plugin.versions' From bc03236736d4e33de0ca6bb9cb0bb27aeac8b9d3 Mon Sep 17 00:00:00 2001 From: Ned Twigg <ned.twigg@diffplug.com> Date: Tue, 26 Dec 2023 17:40:04 -0800 Subject: [PATCH 2/2] `DiskSelfie.toMatchDisk` now returns `DiskSelfie` so that we can fluently chain inline assertions on facets. --- CHANGELOG.md | 2 ++ .../src/commonMain/kotlin/com/diffplug/selfie/Selfie.kt | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ece78e07..22e82bd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +* `DiskSelfie.toMatchDisk` now returns `DiskSelfie` so that we can fluently chain inline assertions on facets. ## [0.1.3] - 2023-12-26 * Publish `selfie-lib-jvm` *and* `selfie-lib` to Maven Central. diff --git a/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/Selfie.kt b/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/Selfie.kt index e5abf3dc..da101c53 100644 --- a/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/Selfie.kt +++ b/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/Selfie.kt @@ -55,12 +55,12 @@ object Selfie { class DiskSelfie internal constructor(actual: Snapshot) : LiteralStringSelfie(actual) { @JvmOverloads - fun toMatchDisk(sub: String = ""): Snapshot { + fun toMatchDisk(sub: String = ""): DiskSelfie { val comparison = storage.readWriteDisk(actual, sub) if (!storage.isWrite) { comparison.assertEqual(storage) } - return comparison.actual + return this } }