@@ -6,6 +6,8 @@ import sbt.Keys._
6
6
import sbt .AutoPlugin
7
7
import sbt .PublishBinPlugin
8
8
import sbt .PublishBinPlugin .autoImport ._
9
+ import sbt .io .Using
10
+ import sbt .util .CacheImplicits ._
9
11
10
12
import scala .collection .mutable
11
13
import java .nio .file .Files
@@ -20,8 +22,11 @@ object RepublishPlugin extends AutoPlugin {
20
22
val republishProjectRefs = taskKey[Seq [ProjectRef ]](" fetch the classpath deps from the project." )
21
23
val republishLocalResolved = taskKey[Seq [ResolvedArtifacts ]](" resolve local artifacts for distribution." )
22
24
val republishAllResolved = taskKey[Seq [ResolvedArtifacts ]](" Resolve the dependencies for the distribution" )
23
- val republishClasspath = taskKey[File ](" cache the dependencies for the distribution" )
25
+ val republishClasspath = taskKey[Set [File ]](" cache the dependencies for the distribution" )
26
+ val republishFetchLaunchers = taskKey[Set [File ]](" cache the launcher deps for the distribution" )
27
+ val republish = taskKey[File ](" cache the dependencies and download launchers for the distribution" )
24
28
val republishRepo = settingKey[File ](" the location to store the republished artifacts." )
29
+ val republishLaunchers = settingKey[Seq [(String , String , URL )]](" launchers to download. Sequence of (name, version, URL)." )
25
30
}
26
31
27
32
import autoImport ._
@@ -43,17 +48,17 @@ object RepublishPlugin extends AutoPlugin {
43
48
val publishAllLocalBin = deps.map({ d => ((d / publishLocalBin / packagedArtifacts)) }).join
44
49
val resolveId = deps.map({ d => ((d / projectID)) }).join
45
50
Def .task {
46
- val s = streams.value
47
- val log = s.log
48
51
val published = publishAllLocalBin.value
49
52
val ids = resolveId.value
50
53
51
54
ids.zip(published).map({ case (id, as) =>
52
55
val simpleId = {
56
+ val disabled = CrossVersion .disabled
53
57
val name0 = id.crossVersion match {
54
- case _ : CrossVersion .Binary =>
58
+ case cv : CrossVersion .Binary =>
55
59
// projectID does not add binary suffix
56
- (id.name + " _3" ).ensuring(! id.name.endsWith(" _3" ) && id.revision.startsWith(" 3." ))
60
+ (s " ${id.name}_ ${cv.prefix}${cv.suffix}3 " )
61
+ .ensuring(! id.name.endsWith(" _3" ) && id.revision.startsWith(" 3." ))
57
62
case _ => id.name
58
63
}
59
64
SimpleModuleId (id.organization, name0, id.revision)
@@ -117,11 +122,15 @@ object RepublishPlugin extends AutoPlugin {
117
122
found.values.toSeq
118
123
},
119
124
republishClasspath := {
125
+ val s = streams.value
120
126
val resolved = republishAllResolved.value
121
127
val cacheDir = republishRepo.value
128
+
129
+ val log = s.log
122
130
val mavenRepo = cacheDir / " maven2"
123
131
IO .createDirectory(mavenRepo)
124
- resolved.foreach { ra =>
132
+ resolved.map { ra =>
133
+ log.info(s " [republish] publishing ${ra.id} to $mavenRepo... " )
125
134
val jar = ra.jar
126
135
val pom = ra.pom
127
136
@@ -130,7 +139,54 @@ object RepublishPlugin extends AutoPlugin {
130
139
IO .createDirectory(artifactDir)
131
140
IO .copyFile(jar, artifactDir / jar.getName)
132
141
IO .copyFile(pom, artifactDir / pom.getName)
142
+ artifactDir
143
+ }.toSet
144
+ },
145
+ republishFetchLaunchers := {
146
+ val s = streams.value
147
+ val log = s.log
148
+ val repoDir = republishRepo.value
149
+ val launcherVersions = republishLaunchers.value
150
+
151
+ val etc = repoDir / " etc"
152
+
153
+ val store = s.cacheStoreFactory / " versions"
154
+
155
+ def work (dest : File , launcher : URL ) = {
156
+ IO .delete(dest)
157
+ Using .urlInputStream(launcher) { in =>
158
+ IO .createDirectory(etc)
159
+ log.info(s " [republish] Downloading $launcher to $dest... " )
160
+ IO .transfer(in, dest)
161
+ log.info(s " [republish] Downloaded $launcher to $dest... " )
162
+ }
163
+ dest
164
+ }
165
+
166
+ val allLaunchers = {
167
+ for ((name, version, launcher) <- launcherVersions) yield {
168
+ val dest = etc / name
169
+
170
+ val id = name.replaceAll(" [^a-zA-Z0-9]" , " _" )
171
+
172
+ val fetchAction = Tracked .inputChanged[String , File ](store.make(id)) { (inChanged, version) =>
173
+ if (inChanged || ! Files .exists(dest.toPath)) {
174
+ work(dest, launcher)
175
+ } else {
176
+ log.info(s " [republish] Using cached $launcher at $dest... " )
177
+ dest
178
+ }
179
+ }
180
+
181
+ fetchAction(version)
182
+ }
133
183
}
184
+ allLaunchers.toSet
185
+ },
186
+ republish := {
187
+ val cacheDir = republishRepo.value
188
+ val artifacts = republishClasspath.value
189
+ val launchers = republishFetchLaunchers.value
134
190
cacheDir
135
191
}
136
192
)
0 commit comments