Skip to content

Commit e98f43a

Browse files
authored
Merge pull request #58 from nebula-plugins/provider-api-support
Modernize plugin with Provider API, configuration avoidance, and lazy task resolution
2 parents ffea13b + c79930f commit e98f43a

10 files changed

Lines changed: 456 additions & 42 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ plugins {
2222

2323
// Any callers need to have this repository too.
2424
repositories {
25-
maven { url 'https://clojars.org/repo' }
25+
maven { url = 'https://clojars.org/repo' }
2626
mavenCentral()
2727
}
2828

29-
description 'Small wrapper around clojuresque'
29+
description = 'Small wrapper around clojuresque'
3030

3131
contacts {
3232
'nebula-plugins-oss@netflix.com' {

src/main/groovy/nebula/plugin/clojuresque/ClojureBasePlugin.groovy

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,19 @@ class ClojureBasePlugin implements Plugin<Project> {
7979
from project.file("src/${set.name}/clojure")
8080
aotCompile.set(extension.aotCompile)
8181
warnOnReflection.set(extension.warnOnReflection)
82-
classpath.from(
83-
set.compileClasspath,
84-
project.configurations.findByName('development')?.incoming?.files
85-
)
82+
classpath.from(set.compileClasspath)
83+
def developmentConfig = project.configurations.findByName('development')
84+
if (developmentConfig != null) {
85+
classpath.from(developmentConfig)
86+
}
8687
destinationDir.set(
8788
findOutputDir(set)
8889
)
8990
description = "Compile the ${set.name} Clojure source."
9091
}
91-
project.tasks[set.classesTaskName].dependsOn task
92+
project.tasks.named(set.classesTaskName).configure {
93+
dependsOn task
94+
}
9295
}
9396
}
9497

@@ -103,6 +106,10 @@ class ClojureBasePlugin implements Plugin<Project> {
103106
classpath.from(
104107
set.compileClasspath
105108
)
109+
projectName.set(project.name)
110+
projectDescription.set(project.provider { project.description ?: "" })
111+
projectVersion.set(project.provider { project.version?.toString() ?: "" })
112+
projectDirectory.set(project.layout.projectDirectory)
106113
description = "Generate documentation for the Clojure source."
107114
group = JavaBasePlugin.DOCUMENTATION_GROUP
108115
}
@@ -131,7 +138,9 @@ class ClojureBasePlugin implements Plugin<Project> {
131138
enabled = false
132139
}
133140
}
134-
project.tasks.test.dependsOn clojureTest
141+
project.tasks.named('test').configure {
142+
dependsOn clojureTest
143+
}
135144
}
136145

137146
private void configureRun(Project project, JavaPluginExtension javaPluginExtension) {

src/main/groovy/nebula/plugin/clojuresque/ClojureCommonPlugin.groovy

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ import org.gradle.api.Project
1717

1818
public class ClojureCommonPlugin implements Plugin<Project> {
1919
void apply(Project project) {
20-
21-
project.configurations {
22-
development {
23-
transitive = true
24-
visible = false
25-
description = "Development only dependencies"
26-
}
20+
project.configurations.register("development") { conf ->
21+
conf.setCanBeConsumed(false)
22+
conf.setCanBeResolved(true)
23+
conf.setTransitive(true)
24+
conf.setVisible(false)
25+
conf.setDescription("Development only dependencies")
2726
}
2827
}
2928
}

src/main/groovy/nebula/plugin/clojuresque/tasks/ClojureCompile.groovy

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import org.gradle.api.file.FileType
2222
import org.gradle.api.model.ObjectFactory
2323
import org.gradle.api.provider.Property
2424
import org.gradle.api.tasks.CacheableTask
25-
import org.gradle.api.tasks.Classpath
25+
import org.gradle.api.tasks.CompileClasspath
2626
import org.gradle.api.tasks.Input
2727
import org.gradle.api.tasks.InputFiles
2828
import org.gradle.api.tasks.Internal
29+
import org.gradle.api.tasks.Optional
2930
import org.gradle.api.tasks.OutputDirectory
3031
import org.gradle.api.tasks.StopExecutionException
3132
import org.gradle.api.tasks.TaskAction
@@ -45,7 +46,7 @@ abstract class ClojureCompile extends ClojureSourceTask {
4546
abstract Property<File> getDestinationDir()
4647

4748
@InputFiles
48-
@Classpath
49+
@CompileClasspath
4950
abstract ConfigurableFileCollection getClasspath()
5051

5152
@Input
@@ -54,11 +55,13 @@ abstract class ClojureCompile extends ClojureSourceTask {
5455
@Input
5556
abstract Property<Boolean> getWarnOnReflection()
5657

57-
@Internal
58-
def dirMode = null
59-
@Internal
60-
def fileMode = null
58+
@Input
59+
@Optional
60+
abstract Property<Integer> getDirMode()
6161

62+
@Input
63+
@Optional
64+
abstract Property<Integer> getFileMode()
6265

6366
private final ExecOperations execOperations
6467

@@ -144,22 +147,24 @@ abstract class ClojureCompile extends ClojureSourceTask {
144147

145148
if (aotCompile.isPresent() && !aotCompile.get()) {
146149
fileSystemOperations.copy {
147-
if(this.dirMode != null) {
150+
if(this.dirMode.isPresent()) {
151+
def dirModeValue = this.dirMode.get()
148152
if(isOlderThanGradle8_3()) {
149-
dirMode = this.dirMode
153+
dirMode = dirModeValue
150154
} else {
151155
dirPermissions {
152-
unix(this.dirMode)
156+
unix(dirModeValue)
153157
}
154158
}
155159
}
156160

157-
if(this.fileMode != null) {
161+
if(this.fileMode.isPresent()) {
162+
def fileModeValue = this.fileMode.get()
158163
if(isOlderThanGradle8_3()) {
159-
fileMode = this.fileMode
164+
fileMode = fileModeValue
160165
} else {
161166
filePermissions {
162-
unix(this.fileMode)
167+
unix(fileModeValue)
163168
}
164169
}
165170
}

src/main/groovy/nebula/plugin/clojuresque/tasks/ClojureDoc.groovy

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ package nebula.plugin.clojuresque.tasks
1515
import nebula.plugin.clojuresque.Util
1616

1717
import org.gradle.api.file.ConfigurableFileCollection
18+
import org.gradle.api.file.DirectoryProperty
19+
import org.gradle.api.model.ObjectFactory
20+
import org.gradle.api.provider.MapProperty
1821
import org.gradle.api.provider.Property
1922
import org.gradle.api.tasks.CacheableTask
2023
import org.gradle.api.tasks.Classpath
2124
import org.gradle.api.tasks.Input
25+
import org.gradle.api.tasks.InputDirectory
2226
import org.gradle.api.tasks.InputFiles
2327
import org.gradle.api.tasks.Optional
2428
import org.gradle.api.tasks.OutputDirectory
29+
import org.gradle.api.tasks.PathSensitive
30+
import org.gradle.api.tasks.PathSensitivity
2531
import org.gradle.api.tasks.StopExecutionException
2632
import org.gradle.api.tasks.TaskAction
2733
import org.gradle.process.ExecOperations
@@ -40,13 +46,32 @@ abstract class ClojureDoc extends ClojureSourceTask {
4046

4147
@Input
4248
@Optional
43-
def codox = [:]
49+
abstract MapProperty<String, Object> getCodox()
50+
51+
@Input
52+
abstract Property<String> getProjectName()
53+
54+
@Input
55+
abstract Property<String> getProjectDescription()
56+
57+
@Input
58+
abstract Property<String> getProjectVersion()
59+
60+
@InputDirectory
61+
@PathSensitive(PathSensitivity.RELATIVE)
62+
abstract DirectoryProperty getProjectDirectory()
4463

4564
private final ExecOperations execOperations
65+
private final ObjectFactory objectFactory
4666

4767
@Inject
48-
ClojureDoc(ExecOperations execOperations) {
68+
ClojureDoc(ExecOperations execOperations, ObjectFactory objectFactory) {
4969
this.execOperations = execOperations
70+
this.objectFactory = objectFactory
71+
codox.convention([:])
72+
projectName.convention("")
73+
projectDescription.convention("")
74+
projectVersion.convention("")
5075
}
5176

5277
@TaskAction
@@ -60,13 +85,13 @@ abstract class ClojureDoc extends ClojureSourceTask {
6085
def options = [
6186
destinationDir: destDir.path,
6287
project: [
63-
name: project.name ?: "",
64-
description: project.description ?: "",
65-
version: project.version ?: ""
88+
name: projectName.get(),
89+
description: projectDescription.get(),
90+
version: projectVersion.get()
6691
],
67-
codox: codox,
92+
codox: codox.get(),
6893
sourceDirs: srcDirs.files.collect {
69-
relativize(it, project.projectDir)
94+
relativize(it, projectDirectory.get().asFile)
7095
},
7196
sourceFiles: source*.path
7297
]
@@ -89,7 +114,7 @@ abstract class ClojureDoc extends ClojureSourceTask {
89114
execOperations.javaexec {
90115
setMainClass("clojure.main")
91116
args('-')
92-
classpath = project.files(
117+
classpath = objectFactory.fileCollection().from(
93118
this.srcDirs,
94119
this.classpath
95120
)
@@ -108,7 +133,7 @@ abstract class ClojureDoc extends ClojureSourceTask {
108133
"js/page_effects.js",
109134
"js/jquery.min.js"
110135
].each { f ->
111-
def dest = project.file("${destinationDir}/${f}")
136+
def dest = new File(destinationDir.get(), f)
112137
println "${f}"
113138
if (!dest.exists()) {
114139
dest.parentFile.mkdirs()

src/main/groovy/nebula/plugin/clojuresque/tasks/ClojureRun.groovy

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import nebula.plugin.clojuresque.Util
44
import nebula.plugin.utils.tasks.ConfigureUtil
55
import org.gradle.api.file.ConfigurableFileCollection
66
import org.gradle.api.model.ObjectFactory
7+
import org.gradle.api.provider.Property
78
import org.gradle.api.tasks.*
89
import org.gradle.api.tasks.options.Option
910
import org.gradle.process.ExecOperations
@@ -18,32 +19,38 @@ abstract class ClojureRun extends ClojureSourceTask {
1819
@Classpath
1920
abstract ConfigurableFileCollection getClasspath()
2021

21-
private String fn;
22+
@Input
23+
@Optional
24+
abstract Property<String> getFn()
2225

2326
@Option(option = "fn", description = "The clojure function (and optional args) to execute.")
2427
public void setFn(String fn) {
25-
this.fn = fn;
28+
this.getFn().set(fn)
2629
}
2730

2831
private final ExecOperations execOperations
2932

3033
private final ObjectFactory objects
3134

3235
@Internal
33-
def jvmOptions = {}
36+
Closure jvmOptions = {}
3437

3538
@Inject
3639
ClojureRun(ExecOperations execOperations, ObjectFactory objects) {
3740
this.execOperations = execOperations
3841
this.objects = objects
3942
}
4043

44+
void jvmOptions(Closure closure) {
45+
this.jvmOptions = closure
46+
}
47+
4148
// Example usage: ./gradlew clojureRun --fn='my-ns/my-fn arg1 arg2'
4249
@TaskAction
4350
void run() {
4451

4552
def options = [
46-
fn: fn
53+
fn: fn.getOrNull()
4754
]
4855

4956
def runtime = [

src/main/groovy/nebula/plugin/clojuresque/tasks/ClojureTest.groovy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,18 @@ abstract class ClojureTest extends ClojureSourceTask {
5555
private final ObjectFactory objects
5656

5757
@Internal
58-
def jvmOptions = {}
58+
Closure jvmOptions = {}
5959

6060
@Inject
6161
ClojureTest(ExecOperations execOperations, ObjectFactory objects) {
6262
this.execOperations = execOperations
6363
this.objects = objects
6464
}
6565

66+
void jvmOptions(Closure closure) {
67+
this.jvmOptions = closure
68+
}
69+
6670
@TaskAction
6771
void runTests() {
6872
def junitDir = junitOutputDir.isPresent() ? junitOutputDir.get() : null

src/main/groovy/nebula/plugin/utils/tasks/SourceDirectoryTask.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class SourceDirectoryTask extends DefaultTask {
154154
@InputFiles
155155
@SkipWhenEmpty
156156
@IgnoreEmptyDirectories
157-
@PathSensitive(PathSensitivity.NONE)
157+
@PathSensitive(PathSensitivity.RELATIVE)
158158
def FileTree getSource() {
159159
objectFactory.fileCollection().from(srcDirs).asFileTree
160160
}

0 commit comments

Comments
 (0)