2016-10-23 13:49:27 +00:00
|
|
|
/*
|
|
|
|
* The MANIFEST.MF files of this project are maintained manually. We have to make sure
|
|
|
|
* that the Bundle-Version entries have the current timestamp in their qualifier using
|
|
|
|
* the same format as generated by Tycho for Eclipse plug-ins. We also have to generate
|
|
|
|
* a proper MANIFEST.MF for the source bundles.
|
|
|
|
*/
|
|
|
|
|
2016-10-17 12:05:36 +00:00
|
|
|
def baseVersion = project.version
|
|
|
|
if (baseVersion.endsWith('-SNAPSHOT'))
|
|
|
|
baseVersion = baseVersion.substring(0, baseVersion.length() - 9)
|
2016-10-20 09:34:14 +00:00
|
|
|
else if (baseVersion.split('\\.').length == 4)
|
|
|
|
baseVersion = baseVersion.substring(0, baseVersion.lastIndexOf('.'))
|
2016-10-18 06:58:15 +00:00
|
|
|
def qualifiedVersion = baseVersion + '.v' + buildTime
|
2016-10-17 12:05:36 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------
|
|
|
|
// Copy the existing manifest and insert the qualifier
|
|
|
|
|
2016-10-23 17:39:43 +00:00
|
|
|
ext.manifestReplacements = new HashMap()
|
|
|
|
manifestReplacements.put(baseVersion + '.qualifier', qualifiedVersion)
|
2019-11-15 11:02:35 +00:00
|
|
|
|
|
|
|
def eclipseSourceReferences() {
|
|
|
|
def rootPath = java.nio.file.Paths.get(project.rootProject.projectDir.canonicalPath)
|
|
|
|
def projectPath = java.nio.file.Paths.get(project.projectDir.canonicalPath)
|
|
|
|
def relativePath = rootPath.relativize(projectPath)
|
|
|
|
def url = grgit.remote.list().findAll{ it.name == "origin" }.first().url
|
|
|
|
def commitId = grgit.head().id
|
|
|
|
return "scm:git:${url};path=\"${relativePath}\"" + (commitId ? ";commitId=${commitId}" : "")
|
|
|
|
}
|
|
|
|
|
|
|
|
manifestReplacements.put("eclipseSourceReferences", eclipseSourceReferences())
|
|
|
|
|
2018-10-09 20:23:09 +00:00
|
|
|
File manifestFile = project.file("$buildDir/tmp/genManifest/MANIFEST.MF")
|
2016-10-17 12:05:36 +00:00
|
|
|
|
|
|
|
task genManifest(type: Copy) {
|
2018-10-09 20:23:09 +00:00
|
|
|
inputs.property('qualifiedVersion', qualifiedVersion)
|
|
|
|
from "META-INF/MANIFEST.MF"
|
|
|
|
into "$buildDir/tmp/genManifest/"
|
|
|
|
doLast {
|
|
|
|
def f = manifestFile
|
|
|
|
def text = f.text
|
|
|
|
for (e in manifestReplacements.entrySet()) {
|
|
|
|
text = text.replace(e.key, e.value)
|
|
|
|
}
|
|
|
|
def writer = new PrintWriter(f)
|
|
|
|
writer.print(text)
|
|
|
|
writer.close()
|
|
|
|
}
|
2016-10-17 12:05:36 +00:00
|
|
|
}
|
|
|
|
|
2018-10-09 20:23:09 +00:00
|
|
|
task configureManifest {
|
2016-10-17 12:05:36 +00:00
|
|
|
dependsOn genManifest
|
2018-10-09 20:23:09 +00:00
|
|
|
doLast {
|
|
|
|
if (manifestFile.isFile()) {
|
|
|
|
jar.manifest {
|
|
|
|
from manifestFile
|
|
|
|
}
|
|
|
|
}
|
2016-10-17 12:05:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 20:23:09 +00:00
|
|
|
jar {
|
|
|
|
dependsOn configureManifest, genManifest
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:05:36 +00:00
|
|
|
//------------------------------------------------------
|
|
|
|
// Generate a manifest for the source bundle
|
|
|
|
|
2018-10-09 20:23:09 +00:00
|
|
|
def sourcesManifestFile = "$buildDir/tmp/genSourcesManifest/MANIFEST.MF"
|
2016-10-17 12:05:36 +00:00
|
|
|
|
2016-11-18 08:21:41 +00:00
|
|
|
task genSourcesManifest {
|
2016-11-18 08:50:12 +00:00
|
|
|
outputs.file(sourcesManifestFile)
|
2018-10-09 20:23:09 +00:00
|
|
|
inputs.property('qualifiedVersion', qualifiedVersion)
|
|
|
|
inputs.property('projectName', project.name)
|
|
|
|
inputs.property('projectTitle', project.findProperty('title')).optional(true)
|
2016-11-18 08:21:41 +00:00
|
|
|
doLast {
|
|
|
|
def f = new File(sourcesManifestFile)
|
|
|
|
f.parentFile.mkdirs()
|
|
|
|
def writer = new PrintWriter(f)
|
2016-11-18 08:50:12 +00:00
|
|
|
writer.println("Manifest-Version: 1.0")
|
|
|
|
writer.println("Bundle-ManifestVersion: 2")
|
|
|
|
writer.println("Bundle-SymbolicName: ${project.name}.source")
|
|
|
|
writer.println("Bundle-Version: ${qualifiedVersion}")
|
|
|
|
if (project.hasProperty('title'))
|
|
|
|
writer.println("Bundle-Name: ${project.title} Sources")
|
|
|
|
else
|
|
|
|
writer.println("Bundle-Name: Sources")
|
|
|
|
writer.println("Bundle-Vendor: Eclipse Xtext")
|
|
|
|
writer.println("Eclipse-SourceBundle: ${project.name};version=\"${qualifiedVersion}\"")
|
2016-11-18 08:21:41 +00:00
|
|
|
writer.close()
|
|
|
|
}
|
2016-10-17 12:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sourcesJar {
|
|
|
|
dependsOn genSourcesManifest
|
|
|
|
manifest {
|
|
|
|
from sourcesManifestFile
|
|
|
|
}
|
|
|
|
}
|
2018-10-09 20:23:09 +00:00
|
|
|
|