|
1 | 1 | import com.diffplug.spotless.cli.picocli.usage.DocumentedUsages |
| 2 | +import com.diffplug.gradle.spotless.FreshMarkExtension |
| 3 | +import com.oracle.svm.core.annotate.Inject |
2 | 4 |
|
3 | 5 | plugins { |
4 | 6 | id 'buildlogic.spotless-common-conventions' |
| 7 | + id 'com.diffplug.spotless-changelog' |
5 | 8 | } |
6 | 9 |
|
| 10 | +Action<FreshMarkExtension> freshmarkSetup = new Action<FreshMarkExtension>(){ |
| 11 | + |
| 12 | + void execute(FreshMarkExtension freshmark) { |
| 13 | + freshmark.target '*.md' |
| 14 | + freshmark.properties(new FreshmarkPropertiesAction(rootProject, project)) |
| 15 | + freshmark.properties { |
| 16 | + it.put('changeThisValueToForceCacheMiss', '1f31705c-b1c6-4bce-9831-98881431b721') |
| 17 | + } |
| 18 | + freshmark.prettier() // prettier for markdown formatting |
| 19 | + freshmark.endWithNewline() |
| 20 | + } |
| 21 | + } |
| 22 | + |
7 | 23 | spotless { |
8 | 24 | freshmark { |
9 | 25 | // freshmark for keeping markdown files up to date |
10 | | - target '*.md' |
11 | | - // provide lib versions to freshmark |
12 | | - properties(new FreshmarkPropertiesAction(rootProject, project)) |
13 | | - properties { |
14 | | - it.put('changeThisValueToForceCacheMiss', '1f31705c-b1c6-4bce-9831-98881431b721') |
| 26 | + freshmarkSetup.execute(it) |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +interface MarkdownProjInjections { |
| 31 | + @javax.inject.Inject |
| 32 | + ExecOperations getExecOperations() |
| 33 | +} |
| 34 | + |
| 35 | +// if this freshmark has a changelog file, then it has version-sensitive content |
| 36 | +if (tasks.names.contains('changelogCheck')) { |
| 37 | + // create a freshmark apply task manually |
| 38 | + FreshMarkExtension freshmark = new FreshMarkExtension(spotless) |
| 39 | + freshmarkSetup.execute(freshmark) |
| 40 | + // override version for this task, we want to use versionNext because versionLast is bumped after evaluation, so peek ahead |
| 41 | + freshmark.properties { |
| 42 | + it.put('spotlessVersion', rootProject.spotlessChangelog.versionNext) |
| 43 | + } |
| 44 | + def changelogBumpFreshmark = freshmark.createIndependentApplyTask('changelogBumpFreshmark') |
| 45 | + // freshmark should run after the changelog bump |
| 46 | + changelogBumpFreshmark.dependsOn tasks.named('changelogBump') |
| 47 | + |
| 48 | + def changelogBumpFreshmarkGitAdd = tasks.register('changelogBumpFreshmarkGitAdd') { |
| 49 | + def execOps = project.objects.newInstance(MarkdownProjInjections).execOperations |
| 50 | + // this git add should run after the freshmark |
| 51 | + dependsOn(changelogBumpFreshmark) |
| 52 | + // do the git add |
| 53 | + doLast { |
| 54 | + execOps.exec { commandLine 'git', 'add' , '*.md' } |
15 | 55 | } |
16 | | - prettier() // prettier for markdown formatting |
17 | | - endWithNewline() |
| 56 | + } |
| 57 | + tasks.named('changelogPush').configure { |
| 58 | + dependsOn changelogBumpFreshmarkGitAdd |
18 | 59 | } |
19 | 60 | } |
20 | 61 |
|
| 62 | + |
21 | 63 | class FreshmarkPropertiesAction implements Action<Map<String, Object>> { |
22 | 64 |
|
23 | 65 | private final Project rootProject |
|
0 commit comments