-
Notifications
You must be signed in to change notification settings - Fork 466
/
Copy pathupdate-lockfile.gradle
90 lines (80 loc) · 2.93 KB
/
update-lockfile.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
ext {
// Eclipse version (numerical format, up to 3 dot separated digits)
if (!project.hasProperty('VER_ECLIPSE')) {
vEclipse = "VER_ECLIPSE property not defined for project"
}
else {
if(3 > VER_ECLIPSE.count('.')) {
vEclipse = VER_ECLIPSE + ".0".repeat(2-VER_ECLIPSE.count('.'))
}
else {
vEclipse = VER_ECLIPSE
}
}
dependencyLockFile = project.file("gradle.lockfile")
changesFile = project.file("CHANGES.md")
// Formatter step dependency lock file
def projectResourceDirName = project.name.replace('-', '_') + "_formatter"
stepLockFile = project(':lib-extra').file("src/main/resources/com/diffplug/spotless/extra/${projectResourceDirName}/v${vEclipse}.lockfile")
if (!project.hasProperty('stepLockFileComment')) {
stepLockFileComment = "File generated by 'prepareLibExtraLockFile' task."
}
}
// Lock implementation dependencies
configurations {
compileClasspath {
resolutionStrategy.activateDependencyLocking()
}
}
dependencyLocking {
//Lock file can be used manually as input for :lib-extra lockfiles
lockFile = dependencyLockFile
}
// Add/Push dependency lock file together with change-log
if (gradle.startParameter.writeDependencyLocks) {
def changelogBumpLockfileGitAdd = tasks.register('changelogBumpLockfileGitAdd') {
/* changelogBump is executed after compile/check.
The write of new lock file should be accomplished during configuration. */
dependsOn(tasks.named('changelogBump'))
// do the git add
doLast {
exec { commandLine 'git', 'add' , dependencyLockFile.getAbsolutePath() }
}
}
afterEvaluate {
tasks.named('changelogPush').configure {
dependsOn changelogBumpLockfileGitAdd
}
}
}
// Prepare dependency lock file for lib-extra
import java.util.stream.Collectors
task generateLibExtraLockFile {
description = "Generates lib-extra project dependency lock file based on the project 'gradle.lockfile'."
group = "Publishing"
inputs.files(dependencyLockFile)
inputs.files(changesFile)
inputs.property('vEclipse', vEclipse)
inputs.property('stepLockFileComment', stepLockFileComment)
outputs.files(stepLockFile)
doLast {
def dependencyLockEntries = dependencyLockFile.text.readLines()
//Filter slf4j-api, since Maven and Gradle provide API and implementation with a matching version.
dependencyLockEntries = dependencyLockEntries
.stream()
.filter( e -> e.contains("=") && e.contains("compileClasspath") && !e.contains("slf4j-api") )
.map(e -> e.split("=")[0])
.collect(Collectors.toList())
def latestRelease = changesFile.getText('UTF-8')
.readLines()
.stream()
.filter( e -> e.contains('## [') && e.contains('] - ') )
.map(e -> e.split('[\\[\\]]')[1])
.findFirst().orElse('Unable to deterine latest version from change log')
dependencyLockEntries.add(0, "com.diffplug.spotless:spotless-${project.name}:${latestRelease}")
stepLockFile.write("# ${stepLockFileComment}\n")
dependencyLockEntries.each({
stepLockFile << "${it}\n"
})
}
}