Skip to content

Commit 4cf1d5e

Browse files
committed
read plugin version from jar manifest, fixes #4
1 parent 2b96cd0 commit 4cf1d5e

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.9
1+
sbt.version=0.13.11

src/main/scala/Plugin.scala

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,30 @@ import gitbucket.plugin.pages.PagesController
44
import io.github.gitbucket.solidbase.model.Version
55

66
class Plugin extends gitbucket.core.plugin.Plugin {
7+
import gitbucket.plugin.pages.util.Version
78
override val pluginId = "pages"
89
override val pluginName = "Pages Plugin"
9-
override val description = "Provides Pages feature on GitBucket"
10-
override val versions = List(new Version("0.0.0"))
10+
override val description = "Project pages for gitbucket"
11+
override val versions = List(new Version(Version.version.getOrElse("unknown")))
1112

1213
override val controllers: Seq[(String, ControllerBase)] = Seq(
1314
"/*" -> new PagesController
1415
)
15-
}
16+
}
17+
18+
package gitbucket.plugin.pages.util {
19+
import scala.collection.JavaConverters._
20+
import scala.util.Try
21+
import java.util.jar.{ Manifest => JarManifest }
22+
23+
object Version {
24+
val version = Try(getVersionFromManifests()).toOption.flatten
25+
def getVersionFromManifests() = {
26+
val resources = getClass.getClassLoader.getResources("META-INF/MANIFEST.MF").asScala.toList
27+
resources
28+
.flatMap(res => Try(new JarManifest(res.openStream())).toOption.toList)
29+
.find(manifest => Option(manifest.getMainAttributes.getValue("Implementation-Title")).contains("pages-plugin"))
30+
.flatMap(manifest => Option(manifest.getMainAttributes.getValue("Implementation-Version")))
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)