@@ -80,134 +80,123 @@ object SnapshotsPlugin extends AutoPlugin {
8080 )
8181
8282 override def projectSettings : Seq [Setting [? ]] =
83- Seq (
84- libraryDependencies ++= {
85- if (snapshotsAddRuntimeDependency.value) {
86- val cross = crossVersion.value match {
87- case b : Binary => b.prefix + scalaBinaryVersion.value
88- case _ => scalaBinaryVersion.value
83+ Compat .addRuntimeDep ++
84+ Seq (
85+ snapshotsProjectIdentifier := thisProject.value.id,
86+ snapshotsAddRuntimeDependency := true ,
87+ snapshotsIntegrations := Seq .empty,
88+ snapshotsForceOverwrite := false ,
89+ snapshotsLocation := sourceDirectory.value / " snapshots" ,
90+ snapshotsTemporaryDirectory := (
91+ Test / managedResourceDirectories
92+ ).value.head / " snapshots-tmp" ,
93+ snapshotsCheck := Def
94+ .task {
95+ SnapshotsBuild .checkSnapshots(
96+ snapshotsTemporaryDirectory.value,
97+ snapshotsProjectIdentifier.value,
98+ SnapshotAction .Interactive
99+ )
89100 }
90-
91- Seq (
92- " com.indoorvivants.snapshots" % s " snapshots-runtime_ $cross" % BuildInfo .version % Test
93- )
94- } else Seq .empty
95- },
96- snapshotsProjectIdentifier := thisProject.value.id,
97- snapshotsAddRuntimeDependency := true ,
98- snapshotsIntegrations := Seq .empty,
99- snapshotsForceOverwrite := false ,
100- snapshotsLocation := sourceDirectory.value / " snapshots" ,
101- snapshotsTemporaryDirectory := (
102- Test / managedResourceDirectories
103- ).value.head / " snapshots-tmp" ,
104- snapshotsCheck := Def
105- .task {
106- SnapshotsBuild .checkSnapshots(
107- snapshotsTemporaryDirectory.value,
108- snapshotsProjectIdentifier.value,
109- SnapshotAction .Interactive
110- )
111- }
112- .tag(snapshotsTag)
113- .value,
114- snapshotsAcceptAll := Def
115- .task {
116- SnapshotsBuild .checkSnapshots(
117- snapshotsTemporaryDirectory.value,
118- snapshotsProjectIdentifier.value,
119- SnapshotAction .Accept
120- )
121- }
122- .tag(snapshotsTag)
123- .value,
124- snapshotsDiscardAll := Def
125- .task {
126- SnapshotsBuild .checkSnapshots(
127- snapshotsTemporaryDirectory.value,
128- snapshotsProjectIdentifier.value,
129- SnapshotAction .Discard
130- )
131- }
132- .tag(snapshotsTag)
133- .value,
134- Test / sourceGenerators += Def .task {
135- val dest = (Test / managedSourceDirectories).value.head
136-
137- val sources = SnapshotsBuild .generateSources(
138- projectId = snapshotsProjectIdentifier.value,
139- packageName = snapshotsPackageName.value,
140- snapshotsDestination =
141- snapshotsLocation.value / snapshotsProjectIdentifier.value,
142- sourceDestination = dest / " Snapshots.scala" ,
143- tmpLocation = snapshotsTemporaryDirectory.value,
144- forceOverwrite = snapshotsForceOverwrite.value
145- )
146-
147- val integrations = snapshotsIntegrations.value.flatMap { integ =>
148- SnapshotsBuild .generateIntegrationSources(
149- dest / s " ${integ}Integration.scala " ,
150- integ,
151- snapshotsPackageName.value
101+ .tag(snapshotsTag)
102+ .value,
103+ snapshotsAcceptAll := Def
104+ .task {
105+ SnapshotsBuild .checkSnapshots(
106+ snapshotsTemporaryDirectory.value,
107+ snapshotsProjectIdentifier.value,
108+ SnapshotAction .Accept
109+ )
110+ }
111+ .tag(snapshotsTag)
112+ .value,
113+ snapshotsDiscardAll := Def
114+ .task {
115+ SnapshotsBuild .checkSnapshots(
116+ snapshotsTemporaryDirectory.value,
117+ snapshotsProjectIdentifier.value,
118+ SnapshotAction .Discard
119+ )
120+ }
121+ .tag(snapshotsTag)
122+ .value,
123+ Test / sourceGenerators += Def .task {
124+ val dest = (Test / managedSourceDirectories).value.head
125+
126+ val sources = SnapshotsBuild .generateSources(
127+ projectId = snapshotsProjectIdentifier.value,
128+ packageName = snapshotsPackageName.value,
129+ snapshotsDestination =
130+ snapshotsLocation.value / snapshotsProjectIdentifier.value,
131+ sourceDestination = dest / " Snapshots.scala" ,
132+ tmpLocation = snapshotsTemporaryDirectory.value,
133+ forceOverwrite = snapshotsForceOverwrite.value
152134 )
153- }
154-
155- sources ++ integrations
156- },
157- snapshotsMigrate := Def
158- .inputTask {
159- import complete .DefaultParsers ._
160-
161- val migrations = Seq (" 0.0.6" ).map(_.trim.toLowerCase())
162- val args : Seq [String ] = spaceDelimited(" <arg>" ).parsed
163- val migration = args.headOption
164- .map(_.trim.toLowerCase())
165- .filter(migrations.contains(_))
166- .getOrElse(
167- sys.error(
168- s " Expected 1 argument to the task, which is migration name, one of: [ ${migrations.mkString(" , " )}] "
169- )
135+
136+ val integrations = snapshotsIntegrations.value.flatMap { integ =>
137+ SnapshotsBuild .generateIntegrationSources(
138+ dest / s " ${integ}Integration.scala " ,
139+ integ,
140+ snapshotsPackageName.value
170141 )
142+ }
171143
172- val log = sLog.value
144+ sources ++ integrations
145+ },
146+ snapshotsMigrate := Def
147+ .inputTask {
148+ import complete .DefaultParsers ._
149+
150+ val migrations = Seq (" 0.0.6" ).map(_.trim.toLowerCase())
151+ val args : Seq [String ] = spaceDelimited(" <arg>" ).parsed
152+ val migration = args.headOption
153+ .map(_.trim.toLowerCase())
154+ .filter(migrations.contains(_))
155+ .getOrElse(
156+ sys.error(
157+ s " Expected 1 argument to the task, which is migration name, one of: [ ${migrations.mkString(" , " )}] "
158+ )
159+ )
173160
174- migration match {
175- case " 0.0.6" =>
176- val oldLocation =
177- (Test / resourceDirectory).value / " snapshots" / snapshotsProjectIdentifier.value
178- val newLocation =
179- snapshotsLocation.value / snapshotsProjectIdentifier.value
161+ val log = sLog.value
180162
181- if (oldLocation.exists() && oldLocation.isDirectory()) {
182- val snapshots = IO .listFiles(oldLocation)
183- log.info(
184- s " Found ${snapshots.size} snapshots in old location [ $oldLocation]. Will migrate them to new location - [ $newLocation] "
185- )
163+ migration match {
164+ case " 0.0.6" =>
165+ val oldLocation =
166+ (Test / resourceDirectory).value / " snapshots" / snapshotsProjectIdentifier.value
167+ val newLocation =
168+ snapshotsLocation.value / snapshotsProjectIdentifier.value
186169
187- IO .createDirectory(newLocation)
170+ if (oldLocation.exists() && oldLocation.isDirectory()) {
171+ val snapshots = IO .listFiles(oldLocation)
172+ log.info(
173+ s " Found ${snapshots.size} snapshots in old location [ $oldLocation]. Will migrate them to new location - [ $newLocation] "
174+ )
188175
189- snapshots.foreach { file =>
190- IO .move(file, newLocation / file.name)
191- }
176+ IO .createDirectory(newLocation)
192177
193- log.info(s " Migrated ${snapshots.size} files " )
178+ snapshots.foreach { file =>
179+ IO .move(file, newLocation / file.name)
180+ }
194181
195- val remaining = IO .listFiles(oldLocation) .size
182+ log.info( s " Migrated ${snapshots .size} files " )
196183
197- if (remaining == 0 ) {
198- log.info(s " [ $oldLocation] is now empty and can be removed " )
184+ val remaining = IO .listFiles(oldLocation).size
185+
186+ if (remaining == 0 ) {
187+ log.info(s " [ $oldLocation] is now empty and can be removed " )
188+ }
189+
190+ } else {
191+ sLog.value.warn(
192+ s " Tried to find old snapshots in [ $oldLocation] but it doesn't seem to exist or is not a directory. Doing nothing "
193+ )
199194 }
200195
201- } else {
202- sLog.value.warn(
203- s " Tried to find old snapshots in [ $oldLocation] but it doesn't seem to exist or is not a directory. Doing nothing "
204- )
205- }
196+ }
206197
207198 }
208-
209- }
210- .tag(snapshotsTag)
211- .evaluated
212- )
199+ .tag(snapshotsTag)
200+ .evaluated
201+ )
213202}
0 commit comments