1
- package com .typesafe .sbt
2
- package packager
3
- package archetypes
1
+ package com .typesafe .sbt .packager .archetypes
4
2
5
3
import sbt ._
6
- import sbt .Keys .{javaOptions , mainClass , mappings , name , sourceDirectory , streams , target }
7
- import packager .Keys .{executableScriptName , packageName }
8
- import linux .{LinuxFileMetaData , LinuxPackageMapping }
9
- import linux .LinuxPlugin .autoImport .{defaultLinuxInstallLocation , linuxPackageMappings }
10
- import SbtNativePackager .{Debian , Universal }
4
+ import sbt .Keys ._
5
+ import com .typesafe .sbt .SbtNativePackager .{Debian , Universal }
6
+ import com .typesafe .sbt .packager ._
7
+ import com .typesafe .sbt .packager .Keys .packageName
8
+ import com .typesafe .sbt .packager .linux .{LinuxFileMetaData , LinuxPackageMapping }
9
+ import com .typesafe .sbt .packager .linux .LinuxPlugin .autoImport .{defaultLinuxInstallLocation , linuxPackageMappings }
11
10
12
11
/**
13
12
* == Java Application ==
@@ -38,39 +37,45 @@ object JavaAppPackaging extends AutoPlugin {
38
37
39
38
import JavaAppPackaging .autoImport ._
40
39
41
- override def requires =
40
+ override def requires : Plugins =
42
41
debian.DebianPlugin && rpm.RpmPlugin && docker.DockerPlugin && windows.WindowsPlugin
43
42
44
- // format: off
45
43
override def projectSettings = Seq (
46
44
javaOptions in Universal := Nil ,
47
45
// Here we record the classpath as it's added to the mappings separately, so
48
46
// we can use its order to generate the bash/bat scripts.
49
47
scriptClasspathOrdering := Nil ,
50
48
// Note: This is sometimes on the classpath via dependencyClasspath in Runtime.
51
- // We need to figure out why sometimes the Attributed[File] is corrrectly configured
49
+ // We need to figure out why sometimes the Attributed[File] is correctly configured
52
50
// and sometimes not.
53
- scriptClasspathOrdering <+= (Keys .packageBin in Compile , Keys .projectID, Keys .artifact in Compile in Keys .packageBin) map { (jar, id, art) =>
51
+ scriptClasspathOrdering += {
52
+ val jar = (packageBin in Compile ).value
53
+ val id = projectID.value
54
+ val art = (artifact in Compile in packageBin).value
54
55
jar -> (" lib/" + makeJarName(id.organization, id.name, id.revision, art.name, art.classifier))
55
56
},
56
- projectDependencyArtifacts <<= findProjectDependencyArtifacts,
57
- scriptClasspathOrdering <++= (Keys .dependencyClasspath in Runtime , projectDependencyArtifacts) map universalDepMappings,
58
- scriptClasspathOrdering <<= scriptClasspathOrdering map { _.distinct },
59
- mappings in Universal <++= scriptClasspathOrdering,
60
- scriptClasspath <<= scriptClasspathOrdering map makeRelativeClasspathNames,
61
- linuxPackageMappings in Debian <+= (packageName in Debian , defaultLinuxInstallLocation, target in Debian ) map {
62
- (name, installLocation, target) =>
63
- // create empty var/log directory
64
- val d = target / installLocation
65
- d.mkdirs()
66
- LinuxPackageMapping (Seq (d -> (installLocation + " /" + name)), LinuxFileMetaData ())
57
+ projectDependencyArtifacts := findProjectDependencyArtifacts.value,
58
+ scriptClasspathOrdering ++= universalDepMappings(
59
+ (dependencyClasspath in Runtime ).value,
60
+ projectDependencyArtifacts.value
61
+ ),
62
+ scriptClasspathOrdering := scriptClasspathOrdering.value.distinct,
63
+ mappings in Universal ++= scriptClasspathOrdering.value,
64
+ scriptClasspath := makeRelativeClasspathNames(scriptClasspathOrdering.value),
65
+ linuxPackageMappings in Debian += {
66
+ val name = (packageName in Debian ).value
67
+ val installLocation = defaultLinuxInstallLocation.value
68
+ val targetDir = (target in Debian ).value
69
+ // create empty var/log directory
70
+ val d = targetDir / installLocation
71
+ d.mkdirs()
72
+ LinuxPackageMapping (Seq (d -> (installLocation + " /" + name)), LinuxFileMetaData ())
67
73
}
68
74
)
69
- // format: on
70
75
71
76
private def makeRelativeClasspathNames (mappings : Seq [(File , String )]): Seq [String ] =
72
77
for {
73
- (file , name) <- mappings
78
+ (_ , name) <- mappings
74
79
} yield {
75
80
// Here we want the name relative to the lib/ folder...
76
81
// For now we just cheat...
@@ -107,30 +112,6 @@ object JavaAppPackaging extends AutoPlugin {
107
112
private def dependencyProjectRefs (build : sbt.BuildDependencies , thisProject : ProjectRef ): Seq [ProjectRef ] =
108
113
build.classpathTransitive.getOrElse(thisProject, Nil )
109
114
110
- private def filterArtifacts (artifacts : Seq [(Artifact , File )], config : Option [String ]): Seq [(Artifact , File )] =
111
- for {
112
- (art, file) <- artifacts
113
- // TODO - Default to compile or default?
114
- if art.configurations.exists(_.name == config.getOrElse(" default" ))
115
- } yield art -> file
116
-
117
- private def extractArtifacts (stateTask : Task [State ], ref : ProjectRef ): Task [Seq [Attributed [File ]]] =
118
- stateTask flatMap { state =>
119
- val extracted = Project extract state
120
- // TODO - Is this correct?
121
- val module = extracted.get(sbt.Keys .projectID in ref)
122
- val artifactTask = extracted get (sbt.Keys .packagedArtifacts in ref)
123
- for {
124
- arts <- artifactTask
125
- } yield {
126
- for {
127
- (art, file) <- arts.toSeq // TODO -Filter!
128
- } yield {
129
- sbt.Attributed .blank(file).put(sbt.Keys .moduleID.key, module).put(sbt.Keys .artifact.key, art)
130
- }
131
- }
132
- }
133
-
134
115
// TODO - Should we pull in more than just JARs? How do native packages come in?
135
116
private def isRuntimeArtifact (dep : Attributed [File ]): Boolean =
136
117
dep.get(sbt.Keys .artifact.key).map(_.`type` == " jar" ).getOrElse {
@@ -139,7 +120,7 @@ object JavaAppPackaging extends AutoPlugin {
139
120
}
140
121
141
122
private def findProjectDependencyArtifacts : Def .Initialize [Task [Seq [Attributed [File ]]]] =
142
- (sbt. Keys . buildDependencies, sbt. Keys . thisProjectRef, sbt. Keys . state) apply { (build, thisProject, stateTask) =>
123
+ (buildDependencies, thisProjectRef, state). apply { (build, thisProject, stateTask) =>
143
124
val refs = thisProject +: dependencyProjectRefs(build, thisProject)
144
125
// Dynamic lookup of dependencies...
145
126
val artTasks = refs map { ref =>
@@ -155,6 +136,21 @@ object JavaAppPackaging extends AutoPlugin {
155
136
allArtifactsTask
156
137
}
157
138
139
+ private def extractArtifacts (stateTask : Task [State ], ref : ProjectRef ): Task [Seq [Attributed [File ]]] =
140
+ stateTask.flatMap { state =>
141
+ val extracted = Project .extract(state)
142
+ // TODO - Is this correct?
143
+ val module = extracted.get(projectID in ref)
144
+ val artifactTask = extracted.get(packagedArtifacts in ref)
145
+ for {
146
+ arts <- artifactTask
147
+ } yield {
148
+ for {
149
+ (art, file) <- arts.toSeq // TODO -Filter!
150
+ } yield Attributed .blank(file).put(moduleID.key, module).put(artifact.key, art)
151
+ }
152
+ }
153
+
158
154
private def findRealDep (dep : Attributed [File ], projectArts : Seq [Attributed [File ]]): Option [Attributed [File ]] =
159
155
if (dep.data.isFile) Some (dep)
160
156
else {
0 commit comments