Skip to content

Commit 9eb0949

Browse files
Do not update the lockfile on write when there is only a timestamp change (stringbean#29)
* Do not update the lockfile on write when there is only a timestamp change (no detected differences) * Add scripted tests for dependencyLockWrite * Tidy logic slightly Co-authored-by: Michael Stringer <stringbean@users.noreply.github.com>
1 parent 7124aa1 commit 9eb0949

File tree

14 files changed

+513
-1
lines changed

14 files changed

+513
-1
lines changed

src/main/scala/software/purpledragon/sbt/lock/DependencyLockPlugin.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ object DependencyLockPlugin extends AutoPlugin {
5151
val updateReport = update.value
5252

5353
val lockFile = DependencyUtils.resolve(updateReport, thisProject.value.configurations.map(_.toConfigRef))
54-
DependencyLockIO.writeLockFile(lockFile, dest)
54+
55+
val updateStatus = DependencyLockIO
56+
.readLockFile(dest)
57+
.map(_.findChanges(lockFile))
58+
59+
if (!updateStatus.contains(LockFileMatches)) {
60+
DependencyLockIO.writeLockFile(lockFile, dest)
61+
}
5562
dest
5663
},
5764
dependencyLockRead := {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import scala.collection.SortedSet
2+
3+
scalaVersion := "2.12.10"
4+
5+
libraryDependencies ++= Seq(
6+
"org.apache.commons" % "commons-lang3" % "3.9",
7+
// lockfile has 3.0.8
8+
"org.scalatest" %% "scalatest" % "3.0.7" % Test,
9+
)
10+
11+
val checkLockfile = taskKey[Unit]("checks the contents of the lockfile")
12+
13+
checkLockfile := {
14+
val lockfile = dependencyLockRead.value.getOrElse(sys.error("Failed to read updated lockfile"))
15+
16+
def checkDependency(org: String, name: String, version: String, configs: SortedSet[String]): Unit = {
17+
val dependency = lockfile.dependencies
18+
.find(dep => dep.org == org && dep.name == name)
19+
.getOrElse(sys.error(s"Failed to find dependency: $org % $name"))
20+
21+
if (dependency.version != version) {
22+
sys.error(s"Incorrect version (${dependency.version}, expected $version) for dependency $org % $name")
23+
}
24+
25+
if (dependency.configurations != configs) {
26+
sys.error(s"Incorrect configs (${dependency.configurations}, expected $configs) for dependency $org % $name")
27+
}
28+
}
29+
30+
checkDependency("org.apache.commons", "commons-lang3", "3.9", SortedSet("compile", "runtime", "test"))
31+
checkDependency("org.scalatest", "scalatest_2.12", "3.0.7", SortedSet( "test"))
32+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"lockVersion" : 1,
3+
"timestamp" : "2019-11-21T18:42:01.200Z",
4+
"configurations" : [
5+
"compile",
6+
"optional",
7+
"provided",
8+
"runtime",
9+
"test"
10+
],
11+
"dependencies" : [
12+
{
13+
"org" : "org.apache.commons",
14+
"name" : "commons-lang3",
15+
"version" : "3.9",
16+
"artifacts" : [
17+
{
18+
"name" : "commons-lang3.jar",
19+
"hash" : "sha1:0122c7cee69b53ed4a7681c03d4ee4c0e2765da5"
20+
}
21+
],
22+
"configurations" : [
23+
"test",
24+
"compile",
25+
"runtime"
26+
]
27+
},
28+
{
29+
"org" : "org.scala-lang",
30+
"name" : "scala-library",
31+
"version" : "2.12.10",
32+
"artifacts" : [
33+
{
34+
"name" : "scala-library.jar",
35+
"hash" : "sha1:3509860bc2e5b3da001ed45aca94ffbe5694dbda"
36+
}
37+
],
38+
"configurations" : [
39+
"test",
40+
"compile",
41+
"runtime"
42+
]
43+
},
44+
{
45+
"org" : "org.scala-lang",
46+
"name" : "scala-reflect",
47+
"version" : "2.12.10",
48+
"artifacts" : [
49+
{
50+
"name" : "scala-reflect.jar",
51+
"hash" : "sha1:14cb7beb516cd8e07716133668c427792122c926"
52+
}
53+
],
54+
"configurations" : [
55+
"test"
56+
]
57+
},
58+
{
59+
"org" : "org.scala-lang.modules",
60+
"name" : "scala-xml_2.12",
61+
"version" : "1.2.0",
62+
"artifacts" : [
63+
{
64+
"name" : "scala-xml_2.12.jar",
65+
"hash" : "sha1:5d38ac30beb8420dd395c0af447ba412158965e6"
66+
}
67+
],
68+
"configurations" : [
69+
"test"
70+
]
71+
},
72+
{
73+
"org" : "org.scalactic",
74+
"name" : "scalactic_2.12",
75+
"version" : "3.0.8",
76+
"artifacts" : [
77+
{
78+
"name" : "scalactic_2.12.jar",
79+
"hash" : "sha1:b50559dfc4a691c1089f9c8812e1d6fd17f80277"
80+
}
81+
],
82+
"configurations" : [
83+
"test"
84+
]
85+
},
86+
{
87+
"org" : "org.scalatest",
88+
"name" : "scalatest_2.12",
89+
"version" : "3.0.8",
90+
"artifacts" : [
91+
{
92+
"name" : "scalatest_2.12.jar",
93+
"hash" : "sha1:8493ffa579676977b810a7a9fdc23af9d3c8af7f"
94+
}
95+
],
96+
"configurations" : [
97+
"test"
98+
]
99+
}
100+
]
101+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"lockVersion" : 1,
3+
"timestamp" : "2019-11-21T18:42:01.200Z",
4+
"configurations" : [
5+
"compile",
6+
"optional",
7+
"provided",
8+
"runtime",
9+
"test"
10+
],
11+
"dependencies" : [
12+
{
13+
"org" : "org.apache.commons",
14+
"name" : "commons-lang3",
15+
"version" : "3.9",
16+
"artifacts" : [
17+
{
18+
"name" : "commons-lang3.jar",
19+
"hash" : "sha1:0122c7cee69b53ed4a7681c03d4ee4c0e2765da5"
20+
}
21+
],
22+
"configurations" : [
23+
"test",
24+
"compile",
25+
"runtime"
26+
]
27+
},
28+
{
29+
"org" : "org.scala-lang",
30+
"name" : "scala-library",
31+
"version" : "2.12.10",
32+
"artifacts" : [
33+
{
34+
"name" : "scala-library.jar",
35+
"hash" : "sha1:3509860bc2e5b3da001ed45aca94ffbe5694dbda"
36+
}
37+
],
38+
"configurations" : [
39+
"test",
40+
"compile",
41+
"runtime"
42+
]
43+
},
44+
{
45+
"org" : "org.scala-lang",
46+
"name" : "scala-reflect",
47+
"version" : "2.12.10",
48+
"artifacts" : [
49+
{
50+
"name" : "scala-reflect.jar",
51+
"hash" : "sha1:14cb7beb516cd8e07716133668c427792122c926"
52+
}
53+
],
54+
"configurations" : [
55+
"test"
56+
]
57+
},
58+
{
59+
"org" : "org.scala-lang.modules",
60+
"name" : "scala-xml_2.12",
61+
"version" : "1.2.0",
62+
"artifacts" : [
63+
{
64+
"name" : "scala-xml_2.12.jar",
65+
"hash" : "sha1:5d38ac30beb8420dd395c0af447ba412158965e6"
66+
}
67+
],
68+
"configurations" : [
69+
"test"
70+
]
71+
},
72+
{
73+
"org" : "org.scalactic",
74+
"name" : "scalactic_2.12",
75+
"version" : "3.0.8",
76+
"artifacts" : [
77+
{
78+
"name" : "scalactic_2.12.jar",
79+
"hash" : "sha1:b50559dfc4a691c1089f9c8812e1d6fd17f80277"
80+
}
81+
],
82+
"configurations" : [
83+
"test"
84+
]
85+
},
86+
{
87+
"org" : "org.scalatest",
88+
"name" : "scalatest_2.12",
89+
"version" : "3.0.8",
90+
"artifacts" : [
91+
{
92+
"name" : "scalatest_2.12.jar",
93+
"hash" : "sha1:8493ffa579676977b810a7a9fdc23af9d3c8af7f"
94+
}
95+
],
96+
"configurations" : [
97+
"test"
98+
]
99+
}
100+
]
101+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
val pluginVersion = System.getProperty("plugin.version")
3+
if (pluginVersion == null)
4+
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
5+
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
6+
else addSbtPlugin("software.purpledragon" % "sbt-dependency-lock" % pluginVersion)
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
> dependencyLockWrite
2+
-$ must-mirror build.sbt.lock build.sbt.lock.orig
3+
> dependencyLockCheck
4+
> checkLockfile
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
scalaVersion := "2.12.10"
2+
3+
libraryDependencies ++= Seq(
4+
"org.apache.commons" % "commons-lang3" % "3.9",
5+
"org.scalatest" %% "scalatest" % "3.0.8" % Test,
6+
)
7+
8+
import scala.collection.SortedSet
9+
10+
val checkLockfile = taskKey[Unit]("checks the contents of the lockfile")
11+
12+
checkLockfile := {
13+
val lockfile = dependencyLockRead.value.getOrElse(sys.error("Failed to read updated lockfile"))
14+
15+
def checkDependency(org: String, name: String, version: String, configs: SortedSet[String]): Unit = {
16+
val dependency = lockfile.dependencies
17+
.find(dep => dep.org == org && dep.name == name)
18+
.getOrElse(sys.error(s"Failed to find dependency: $org % $name"))
19+
20+
if (dependency.version != version) {
21+
sys.error(s"Incorrect version (${dependency.version}, expected $version) for dependency $org % $name")
22+
}
23+
24+
if (dependency.configurations != configs) {
25+
sys.error(s"Incorrect configs (${dependency.configurations}, expected $configs) for dependency $org % $name")
26+
}
27+
}
28+
29+
checkDependency("org.apache.commons", "commons-lang3", "3.9", SortedSet("compile", "runtime", "test"))
30+
checkDependency("org.scalatest", "scalatest_2.12", "3.0.8", SortedSet( "test"))
31+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
val pluginVersion = System.getProperty("plugin.version")
3+
if (pluginVersion == null)
4+
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
5+
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
6+
else addSbtPlugin("software.purpledragon" % "sbt-dependency-lock" % pluginVersion)
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
> dependencyLockWrite
2+
$ exists build.sbt.lock
3+
> dependencyLockCheck
4+
> checkLockfile
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
scalaVersion := "2.12.10"
2+
3+
libraryDependencies ++= Seq(
4+
"org.apache.commons" % "commons-lang3" % "3.9",
5+
"org.scalatest" %% "scalatest" % "3.0.8" % Test,
6+
)

0 commit comments

Comments
 (0)