Skip to content

Commit 47d6327

Browse files
reidspencerclaude
andcommitted
Refactor AutoPluginHelper to extend (Project => Project)
AutoPluginHelper now extends (Project => Project), making all helpers directly usable as configuration functions without calling .configure. Changes: - AutoPluginHelper requires apply(project: Project): Project - Simple helpers: renamed configure to apply - Parameterized helpers: apply(project) delegates to apply()(project) - OssumIncPlugin: With.* returns helper objects directly - Updated all call sites to use helpers without .configure suffix Usage: - With.Scala3 works directly (no parentheses needed) - With.Scala3() still works for default parameters - With.Scala3.configure(version = Some("3.4.0")) for custom params All 14 scripted tests pass. Backwards compatible to 0.22.2. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent be79694 commit 47d6327

35 files changed

Lines changed: 174 additions & 146 deletions

build.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ lazy val `sbt-ossuminc` = project
2121
.in(file("."))
2222
.enablePlugins(SbtPlugin)
2323
.configure(RootProjectInfo.initialize("sbt-ossuminc", startYr = 2015))
24-
.configure(DynamicVersioning.configure)
25-
.configure(Scala2.configure)
26-
.configure(GithubPublishing.configure)
24+
.configure(DynamicVersioning)
25+
.configure(Scala2)
26+
.configure(GithubPublishing)
2727
.settings(
2828
sbtPlugin := true,
2929
licenses += "Apache V2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0"),

project/SonatypePublishing.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object SonatypePublishing extends AutoPluginHelper {
3535

3636
private val defaultSonatypeServer = "s01.oss.sonatype.org"
3737

38-
def configure(project: Project): Project =
38+
def apply(project: Project): Project =
3939
project
4040
.enablePlugins(SonatypePlugin)
4141
.settings(

src/main/scala/com/ossuminc/sbt/DocSite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ object DocSite {
4141
Project
4242
.apply(dirName, file(dirName))
4343
.enablePlugins(OssumIncPlugin)
44-
.configure(With.basic, With.scala3)
44+
.configure(With.basic, With.Scala3)
4545
.configure(
4646
helpers.Unidoc.configure(
4747
outpath,

src/main/scala/com/ossuminc/sbt/OssumIncPlugin.scala

Lines changed: 129 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -28,156 +28,186 @@ object OssumIncPlugin extends AutoPlugin {
2828
// Clauses to customize the major declarations
2929
object With {
3030

31-
def akka: ConfigFunc = helpers.Akka.configure
32-
33-
def Akka = helpers.Akka
31+
// ===== PascalCase helpers (preferred) =====
3432

3533
/** Use this to provide dependencies on most recent Akka libraries */
34+
def Akka: helpers.Akka.type = helpers.Akka
3635

3736
/** Use this to provide handy sbt command line aliases */
38-
def aliases: ConfigFunc = helpers.HandyAliases.configure
39-
40-
/** Use this to configure AsciiDoc document generation for static websites and PDFs */
41-
val AsciiDoc = helpers.AsciiDoc
37+
def Aliases: helpers.HandyAliases.type = helpers.HandyAliases
4238

43-
/** Use this to have the build generate build information. "I know this because sbt knows
44-
* this"
45-
*/
46-
def build_info: ConfigFunc = helpers.BuildInfo.configure
39+
/** Use this to configure AsciiDoc document generation */
40+
val AsciiDoc: helpers.AsciiDoc.type = helpers.AsciiDoc
4741

42+
/** Use this to have the build generate build information */
4843
def BuildInfo: helpers.BuildInfo.type = helpers.BuildInfo
4944

50-
/** Configure the project to require a certain percentage of coverage in test cases */
51-
def coverage(percent: Double = 50.0d)(project: Project): Project =
52-
project
53-
.configure(helpers.ScalaCoverage.configure)
54-
.settings(
55-
helpers.ScalaCoverage.Keys.coveragePercent := percent
56-
)
57-
58-
/** Use dynamic versioning based on the most recent tag, and the commit hash and data/time
59-
* stamp if necessary
60-
*/
61-
def dynver: ConfigFunc = helpers.DynamicVersioning.configure
45+
/** Use dynamic versioning based on git tags */
46+
def DynVer: helpers.DynamicVersioning.type = helpers.DynamicVersioning
6247

6348
/** Use this to get git command line support at the sbt prompt */
64-
def git: ConfigFunc = helpers.Git.configure
49+
def Git: helpers.Git.type = helpers.Git
6550

66-
/** Configure this project to be published as a Maven GitHub Package in the organization
67-
* specified by Root
51+
/** Configure publishing to GitHub Packages
6852
* @note
69-
* Do not combine this with SonatypePublishing
53+
* Do not combine with SonatypePublishing
7054
*/
71-
def GithubPublishing: ConfigFunc = helpers.GithubPublishing.configure
55+
def GithubPublishing: helpers.GithubPublishing.type = helpers.GithubPublishing
7256

73-
/** Use this to get the `headerCheck` and `headerCreate` sbt commands to generate source file
74-
* headers automatically
75-
*/
76-
def header: ConfigFunc = helpers.Header.configure
57+
/** Use this to manage source file headers automatically */
58+
def Header: helpers.Header.type = helpers.Header
7759

60+
/** Configure IntelliJ IDEA plugin development */
7861
def IdeaPlugin: helpers.IdeaPlugin.type = helpers.IdeaPlugin
7962

8063
/** Use this to enable compilation of Java code too */
81-
def java: ConfigFunc = helpers.Java.configure
82-
83-
/** Use this to configure your project to compile Scala to ScalaJS via scala.js */
84-
def ScalaJS: helpers.ScalaJS.type = helpers.ScalaJS
85-
def scalajs: ConfigFunc = helpers.ScalaJS.configure
86-
87-
/** @deprecated Use ScalaJS instead - this alias will be removed in 2.0 */
88-
@deprecated("Use ScalaJS instead", "1.0.0")
89-
def Javascript: helpers.ScalaJS.type = helpers.ScalaJS
64+
def Java: helpers.Java.type = helpers.Java
9065

91-
/** Use this to configure your project to include typical laminar dependencies */
66+
/** Use this to configure Laminar dependencies */
9267
def Laminar: helpers.Laminar.type = helpers.Laminar
9368

69+
/** Configure binary compatibility checking */
9470
def MiMa: helpers.MiMa.type = helpers.MiMa
9571

96-
/** Use this to configure your project to build native code with Scala.Native */
72+
/** Use this to build native code with Scala Native */
9773
def Native: helpers.Native.type = helpers.Native
9874

99-
/** Do not configure this project for Lightbend's Migration Manager */
100-
def noMiMa: ConfigFunc = helpers.MiMa.without
101-
102-
/** Configure this project to produce no artifact and not be published */
103-
def noPublishing(project: Project): Project =
104-
project.settings(
105-
publishArtifact := false, // no artifact to publish for the virtual root project
106-
publish := {}, // just to be sure
107-
publishLocal := {}, // and paranoid
108-
publishTo := Some(Resolver.defaultLocal),
109-
publish / skip := true
110-
)
111-
75+
/** Configure sbt-native-packager */
11276
def Packaging: helpers.Packaging.type = helpers.Packaging
11377

114-
/** Configure this project to be published as open source
115-
* @note
116-
* Do not combine this with SonatypePublishing
117-
*/
118-
def SonatypePublishing: ConfigFunc = helpers.SonatypePublishing.configure
119-
120-
/** Configure this project to support releasing with a systematic release procedure */
121-
def release: ConfigFunc = helpers.Release.configure
78+
/** Configure the release process */
79+
def Release: helpers.Release.type = helpers.Release
12280

123-
/** Add extra resolvers to the build for this project */
124-
def resolvers: ConfigFunc = helpers.Resolvers.configure
81+
/** Add extra resolvers to the build */
82+
def Resolvers: helpers.Resolvers.type = helpers.Resolvers
12583

126-
/** Configure dependency on a version of the RIDDL library */
127-
def riddl: ConfigFunc = helpers.Riddl.configure
128-
def Riddl = helpers.Riddl
84+
/** Configure dependency on RIDDL library */
85+
def Riddl: helpers.Riddl.type = helpers.Riddl
12986

13087
/** Compile scala code as Scala 2.13.latest */
131-
def scala2: ConfigFunc = helpers.Scala2.configure
88+
def Scala2: helpers.Scala2.type = helpers.Scala2
13289

13390
/** Compile scala code as Scala 3's latest LTS release */
134-
def scala3: ConfigFunc = helpers.Scala3.configure
91+
def Scala3: helpers.Scala3.type = helpers.Scala3
92+
93+
/** Configure ScalablyTyped for TypeScript facades */
94+
def ScalablyTyped: helpers.ScalablyTyped.type = helpers.ScalablyTyped
13595

136-
/** Configure this project to use standard Scalafmt formatting rules. */
96+
/** Configure code coverage testing */
97+
def ScalaCoverage: helpers.ScalaCoverage.type = helpers.ScalaCoverage
98+
99+
/** Configure standard Scalafmt formatting rules */
137100
def Scalafmt: helpers.Scalafmt.type = helpers.Scalafmt
138101

139-
/** Add scalaTest libraries to the libraryDependencies */
140-
def Scalatest: helpers.Scalatest.type = helpers.Scalatest
102+
/** Configure Scala.js compilation */
103+
def ScalaJS: helpers.ScalaJS.type = helpers.ScalaJS
141104

142-
/** Configure this project to enable coverage testing */
143-
def scoverage: ConfigFunc = helpers.ScalaCoverage.configure
105+
/** Add ScalaTest libraries to the libraryDependencies */
106+
def Scalatest: helpers.Scalatest.type = helpers.Scalatest
144107

145-
def ScalablyTyped: helpers.ScalablyTyped.type = helpers.ScalablyTyped
108+
/** Configure publishing to Sonatype/Maven Central
109+
* @note
110+
* Do not combine with GithubPublishing
111+
*/
112+
def SonatypePublishing: helpers.SonatypePublishing.type = helpers.SonatypePublishing
146113

114+
/** Configure unified API documentation */
147115
def Unidoc: helpers.Unidoc.type = helpers.Unidoc
148116

117+
// ===== Deprecated lowercase aliases (will be removed in 2.0) =====
118+
119+
@deprecated("Use Akka instead", "1.1.0")
120+
def akka: helpers.Akka.type = helpers.Akka
121+
122+
@deprecated("Use Aliases instead", "1.1.0")
123+
def aliases: helpers.HandyAliases.type = helpers.HandyAliases
124+
125+
@deprecated("Use BuildInfo instead", "1.1.0")
126+
def build_info: helpers.BuildInfo.type = helpers.BuildInfo
127+
128+
@deprecated("Use DynVer instead", "1.1.0")
129+
def dynver: helpers.DynamicVersioning.type = helpers.DynamicVersioning
130+
131+
@deprecated("Use Git instead", "1.1.0")
132+
def git: helpers.Git.type = helpers.Git
133+
134+
@deprecated("Use Header instead", "1.1.0")
135+
def header: helpers.Header.type = helpers.Header
136+
137+
@deprecated("Use Java instead", "1.1.0")
138+
def java: helpers.Java.type = helpers.Java
139+
140+
@deprecated("Use ScalaJS instead", "1.1.0")
141+
def Javascript: helpers.ScalaJS.type = helpers.ScalaJS
142+
143+
@deprecated("Use Release instead", "1.1.0")
144+
def release: helpers.Release.type = helpers.Release
145+
146+
@deprecated("Use Resolvers instead", "1.1.0")
147+
def resolvers: helpers.Resolvers.type = helpers.Resolvers
148+
149+
@deprecated("Use Riddl instead", "1.1.0")
150+
def riddl: helpers.Riddl.type = helpers.Riddl
151+
152+
@deprecated("Use Scala2 instead", "1.1.0")
153+
def scala2: helpers.Scala2.type = helpers.Scala2
154+
155+
@deprecated("Use Scala3 instead", "1.1.0")
156+
def scala3: helpers.Scala3.type = helpers.Scala3
157+
158+
@deprecated("Use ScalaJS instead", "1.1.0")
159+
def scalajs: helpers.ScalaJS.type = helpers.ScalaJS
160+
161+
@deprecated("Use ScalaCoverage instead", "1.1.0")
162+
def scoverage: helpers.ScalaCoverage.type = helpers.ScalaCoverage
163+
164+
// ===== Special helpers =====
165+
166+
/** Configure code coverage with minimum threshold */
167+
def coverage(percent: Double = 50.0d)(project: Project): Project =
168+
project
169+
.configure(helpers.ScalaCoverage)
170+
.settings(
171+
helpers.ScalaCoverage.Keys.coveragePercent := percent
172+
)
173+
174+
/** Do not configure binary compatibility checking */
175+
def noMiMa: ConfigFunc = helpers.MiMa.without
176+
177+
/** Configure project to produce no artifact and not be published */
178+
def noPublishing(project: Project): Project =
179+
project.settings(
180+
publishArtifact := false,
181+
publish := {},
182+
publishLocal := {},
183+
publishTo := Some(Resolver.defaultLocal),
184+
publish / skip := true
185+
)
186+
187+
/** Apply multiple configuration functions */
149188
def these(cfuncs: ConfigFunc*)(project: Project): Project =
150189
cfuncs.foldLeft(project) { (p, func) =>
151190
p.configure(func)
152191
}
153192

154-
/** Use this to more easily configure:
155-
* - [[com.ossuminc.sbt.OssumIncPlugin.autoImport.With.aliases]],
156-
* - [[com.ossuminc.sbt.OssumIncPlugin.autoImport.With.dynver]]
157-
* - [[com.ossuminc.sbt.OssumIncPlugin.autoImport.With.git]]
158-
* - [[com.ossuminc.sbt.OssumIncPlugin.autoImport.With.header]]
159-
* - [[com.ossuminc.sbt.OssumIncPlugin.autoImport.With.resolvers]] more easily
160-
*/
161-
def basic(project: Project): Project =
162-
these(aliases, dynver, git, header, resolvers)(project)
193+
// ===== Composite helpers =====
163194

164-
/** Configure support for all the simple things:
165-
* - [[com.ossuminc.sbt.OssumIncPlugin.autoImport.With.typical]]
166-
* - [[com.ossuminc.sbt.OssumIncPlugin.autoImport.With.java]]
167-
* - [[com.ossuminc.sbt.OssumIncPlugin.autoImport.With.build_info]]
168-
* - [[com.ossuminc.sbt.OssumIncPlugin.autoImport.With.release]]
169-
*/
170-
def everything(project: Project): Project = {
171-
project.configure(typical)
172-
these(java, release)(project)
173-
}
195+
/** Configure: Aliases, DynVer, Git, Header, Resolvers */
196+
def basic(project: Project): Project =
197+
these(Aliases, DynVer, Git, Header, Resolvers)(project)
174198

175-
/** Use this to enable the [[basic]] features as well as [[scala3]] and [[build_info]] */
199+
/** Configure: basic + Scala3 + Scalatest */
176200
def typical(project: Project): Project = {
177201
project
178202
.configure(basic)
179-
.configure(scala3)
180-
.configure(Scalatest())
203+
.configure(Scala3)
204+
.configure(Scalatest)
205+
}
206+
207+
/** Configure: typical + Java + Release */
208+
def everything(project: Project): Project = {
209+
project.configure(typical)
210+
these(Java, Release)(project)
181211
}
182212
}
183213
}

src/main/scala/com/ossuminc/sbt/Plugin.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object Plugin {
3131
.apply(dirName, file(dirName))
3232
.enablePlugins(OssumIncPlugin, SbtPlugin, JavaAppPackaging)
3333
.disablePlugins(ScoverageSbtPlugin)
34-
.configure(With.basic, With.scala2, helpers.Scalafmt.configure, With.SonatypePublishing)
34+
.configure(With.basic, With.Scala2, helpers.Scalafmt, With.SonatypePublishing)
3535
.settings(
3636
name := dirName,
3737
moduleName := { if (modName.isEmpty) dirName else modName },

src/main/scala/com/ossuminc/sbt/Root.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ object Root {
4848
devs,
4949
spdx
5050
),
51-
helpers.Resolvers.configure
51+
helpers.Resolvers
5252
)
5353
}
5454
}

src/main/scala/com/ossuminc/sbt/helpers/Akka.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,5 @@ object Akka extends AutoPluginHelper {
142142
}
143143

144144
/** Configure Akka with latest release */
145-
def configure(project: Project): Project = forRelease("")(project)
145+
def apply(project: Project): Project = forRelease("")(project)
146146
}

src/main/scala/com/ossuminc/sbt/helpers/AsciiDoc.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object AsciiDoc extends AutoPluginHelper {
3131
* Enables both HTML and PDF generation from AsciiDoc sources located in src/asciidoc.
3232
* Generated HTML will be placed in target/site/asciidoc, and PDFs in target/asciidoc-pdf.
3333
*/
34-
def configure(project: Project): Project = apply()(project)
34+
def apply(project: Project): Project = apply()(project)
3535

3636
/** Configure AsciiDoc support with custom options
3737
*

src/main/scala/com/ossuminc/sbt/helpers/AutoPluginHelper.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@ package com.ossuminc.sbt.helpers
1818

1919
import sbt.Project
2020

21-
/** A Little Help For AutoPlugins This trait just provides some definitions and makes it easier to
22-
* set up the plugin requirements. Just list the helpers upon which your plugin is dependent in the
23-
* autoPlugins method and the rest is taken care of.
21+
/** A Little Help For AutoPlugins. This trait extends `(Project => Project)`
22+
* so helpers can be used directly as configuration functions:
23+
* `.configure(With.Scala3)` instead of `.configure(With.Scala3.configure)`.
2424
*/
25-
trait AutoPluginHelper extends {
25+
trait AutoPluginHelper extends (Project => Project) {
2626

27-
/** The typical configuration function type for this helper
27+
/** Apply this helper's configuration to a project.
2828
* @param project
2929
* The project to which the configuration should be applied
3030
* @return
31-
* The same project passed as an argument, but modified with the configuration this helper
32-
* provides.
31+
* The same project with this helper's configuration applied.
3332
*/
34-
35-
def configure(project: Project): Project
33+
def apply(project: Project): Project
3634
}

src/main/scala/com/ossuminc/sbt/helpers/BuildInfo.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object BuildInfo extends AutoPluginHelper {
1919
* @return
2020
* The same project passed as an argument, post configuration
2121
*/
22-
def configure(project: Project): Project = {
22+
def apply(project: Project): Project = {
2323
val utcDate: String = java.time.Instant
2424
.now()
2525
.atZone(java.time.ZoneOffset.UTC)
@@ -79,7 +79,7 @@ object BuildInfo extends AutoPluginHelper {
7979
* The keys and value to add to the BuildInfo output
8080
*/
8181
def withKeys(keyValues: (String, Any)*)(project: Project): Project = {
82-
configure(project).settings(
82+
apply(project).settings(
8383
buildInfoKeys ++= { keyValues.map { case (k, v) => BuildInfoKey.action(k) { v } } }
8484
)
8585
}

0 commit comments

Comments
 (0)