Skip to content

Commit

Permalink
build: Improve p2 repo build logic
Browse files Browse the repository at this point in the history
Signed-off-by: BJ Hargrave <[email protected]>
  • Loading branch information
bjhargrave committed Dec 6, 2018
1 parent b9557b5 commit edc7dd6
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 147 deletions.
12 changes: 8 additions & 4 deletions build/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Set javac settings from JDT prefs
-include: ${workspace}/cnf/eclipse/jdt.bnd

-sub: *.bnd

-releaserepo:
-nobundles: true

gittag: ${first;${system-allow-fail;git describe --abbrev=0},${base.version}.DEV}

Expand All @@ -24,6 +21,13 @@ p2 = bndtools.api, \
org.bndtools.templating,\
org.bndtools.templating.gitrepo

plugins: \
${map;repo;${replace;${p2};$;\\\\\\;latest}},\
${repo;biz.aQute.bndlib;latest},\
${repo;biz.aQute.repository;latest},\
${repo;biz.aQute.resolve;latest},\
${repo;org.slf4j.api;latest}

# Template projects which are not part of the p2 feature
templates = \
org.bndtools.templates.osgi, \
Expand Down
218 changes: 82 additions & 136 deletions build/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/

import aQute.bnd.gradle.Index
import aQute.bnd.osgi.Jar
import org.apache.tools.ant.filters.ReplaceTokens

def buildProject = project

Expand All @@ -21,165 +23,112 @@ configure(parent) {
defaultTasks = [build.path]
}

import org.apache.tools.ant.filters.ReplaceTokens
import aQute.bnd.osgi.Jar

/*
* Setup tasks (p2 plugins)
*/
task p2Plugins(type: Copy) {
dependsOn releaseNeeded
from zipTree("${buildDir}/${project.name}.main.jar")
task p2Plugins(type: Sync) {
dependsOn build
from bnd('plugins').tokenize(',')
into "${buildDir}/plugins"
include '*.jar'

doLast {
String[] projs = bnd('p2', '').split(/\s*,\s*/)
def targetDir = file("${buildDir}/plugins")
if ((!targetDir.exists() && !targetDir.mkdirs()) || !targetDir.isDirectory()) {
throw new GradleException("Could not create directory ${targetDir}")
}
projs.each {
def proj = parent.findProject(it)
if (proj == null) {
throw new GradleException("Could not find project ${it}")
}

proj.bnd.project.getBuilder(null).withCloseable { pb ->
pb.getSubBuilders()*.getBsn().each { bsn ->
copy {
from project.relativePath(proj.bnd.project.getOutputFile(bsn))
into targetDir
}
}
}
}
}
}

/*
* Setup tasks (p2 features)
*/
task p2FeatureTree(type: Copy) {
dependsOn p2Plugins
from 'feature'
into "${buildDir}/features"
doFirst {
def masterVersion = String.format('%s-%tY%<tm%<td-%<tH%<tM%<tS-g%.7s',
bnd('gittag'),
Calendar.getInstance(TimeZone.getTimeZone("UTC")),
bnd('Git-SHA'))
def featureTokens = ['master-version' : masterVersion, 'base-version' : bnd('base.version')]
def plugins = fileTree("${buildDir}/plugins").getFiles()
plugins.each {
new Jar(it).withCloseable { jar ->
featureTokens["${jar.getBsn()}-version"] = jar.getVersion()
}
task p2FeatureProperties(type: WriteProperties) {
inputs.files p2Plugins
outputFile = file("${buildDir}/feature.properties")
doFirst {
property('master-version', String.format('%s-%tY%<tm%<td-%<tH%<tM%<tS-g%.7s',
bnd('gittag'),
Calendar.getInstance(TimeZone.getTimeZone("UTC")),
bnd('Git-SHA')))
property('base-version', bnd('base.version'))
fileTree(p2Plugins.destinationDir).each {
new Jar(it).withCloseable { jar ->
property("${jar.getBsn()}-version", jar.getVersion())
}
filter(ReplaceTokens, tokens: featureTokens )
}
include 'category.xml'
include '**/feature.xml'
inputs.files file("${buildDir}/plugins")
}
}

task p2FeatureMain(type: Zip) {
dependsOn p2FeatureTree
inputs.files p2FeatureProperties
destinationDir = file("${buildDir}/features")
archiveName = 'bndtools.feature.jar'
from "${buildDir}/features/bndtools"
from 'feature/bndtools'
include 'feature.xml'
doFirst {
Properties properties = new Properties()
p2FeatureProperties.outputFile.withInputStream {
properties.load(it)
}
filter(ReplaceTokens, tokens: properties )
}
}

task p2FeatureM2e(type: Zip) {
dependsOn p2FeatureTree
inputs.files p2FeatureProperties
destinationDir = file("${buildDir}/features")
archiveName = 'bndtools.m2e.feature.jar'
from "${buildDir}/features/bndtools-m2e"
from 'feature/bndtools-m2e'
include 'feature.xml'
doFirst {
Properties properties = new Properties()
p2FeatureProperties.outputFile.withInputStream {
properties.load(it)
}
filter(ReplaceTokens, tokens: properties )
}
}

task p2FeaturePde(type: Zip) {
dependsOn p2FeatureTree
inputs.files p2FeatureProperties
destinationDir = file("${buildDir}/features")
archiveName = 'bndtools.pde.feature.jar'
from "${buildDir}/features/bndtools-pde"
from 'feature/bndtools-pde'
include 'feature.xml'
doFirst {
Properties properties = new Properties()
p2FeatureProperties.outputFile.withInputStream {
properties.load(it)
}
filter(ReplaceTokens, tokens: properties )
}
}

/*
* Setup tasks (p2 repositories)
*/
task p2 {
description 'Generate the p2 repositories.'
description 'Publish the p2 repositories.'
group 'release'
dependsOn p2Plugins, p2FeatureMain, p2FeatureM2e, p2FeaturePde

inputs.files file('p2.xml'),
fileTree(buildDir)
.include('p2/**')
.include('features/category.xml')
outputs.dir "${buildDir}/p2"

inputs.files p2Plugins, p2FeatureMain, p2FeatureM2e, p2FeaturePde, 'p2.xml', 'feature/category.xml'
ext.destinationDir = file("${buildDir}/p2")
outputs.dir destinationDir
doLast {
def bnd_verbose = logger.isEnabled(LogLevel.INFO)
def bnd_eclipseDirectory = file('eclipse-3.5.2')
def bnd_eclipseJar = new File(bnd_eclipseDirectory, 'plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar')
def javaArgs = []
if (bnd_verbose) {
javaArgs += '-consoleLog'
}
javaArgs += '-application'
javaArgs += 'org.eclipse.ant.core.antRunner'
javaArgs += '-data'
javaArgs += buildDir
javaArgs += '-buildfile'
javaArgs += 'p2.xml'
javaArgs += 'p2Bndtools'

def result = javaexec {
classpath = files(bnd_eclipseJar)
main = 'org.eclipse.equinox.launcher.Main'
args = javaArgs
}
if (result.exitValue != 0) {
throw new GradleException("Could not publish features and bundles -Bndtools")
}

javaArgs = []
if (bnd_verbose) {
javaArgs += '-consoleLog'
}
javaArgs += '-application'
javaArgs += 'org.eclipse.equinox.p2.publisher.CategoryPublisher'
javaArgs += '-data'
javaArgs += buildDir
javaArgs += '-metadataRepository'
javaArgs += "file://${buildDir}/p2"
javaArgs += '-categoryDefinition'
javaArgs += "file://${buildDir}/features/category.xml"
javaArgs += '-compress'

result = javaexec {
classpath = files(bnd_eclipseJar)
main = 'org.eclipse.equinox.launcher.Main'
args = javaArgs
}
if (result.exitValue != 0) {
throw new GradleException("Could not categorise repository - Bndtools")
}

/* Clean up the files Eclipse leaves behind */
fileTree(bnd_eclipseDirectory).include('configuration/*.log').each {
it.delete()
}

delete(file("${bnd_eclipseDirectory}/configuration/org.eclipse.core.runtime"))
delete(file("${bnd_eclipseDirectory}/configuration/org.eclipse.equinox.app" ))
delete(file("${bnd_eclipseDirectory}/configuration/org.eclipse.osgi" ))
delete(file("${bnd_eclipseDirectory}/p2" ))
delete("${buildDir}/features")
delete("${buildDir}/plugins")
javaexec {
classpath 'eclipse-3.5.2/plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar'
main = 'org.eclipse.equinox.launcher.Main'
if (logger.isDebugEnabled()) {
args '-consoleLog'
}
args '-application'
args 'org.eclipse.ant.core.antRunner'
args '-data'
args buildDir
args '-buildfile'
args 'p2.xml'
args 'p2Bndtools'
}.assertNormalExitValue()

javaexec {
classpath 'eclipse-3.5.2/plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar'
main = 'org.eclipse.equinox.launcher.Main'
if (logger.isDebugEnabled()) {
args '-consoleLog'
}
args '-application'
args 'org.eclipse.equinox.p2.publisher.CategoryPublisher'
args '-data'
args buildDir
args '-metadataRepository'
args uri(destinationDir)
args '-categoryDefinition'
args uri('feature/category.xml')
args '-compress'
}.assertNormalExitValue()
}
}

Expand All @@ -195,14 +144,11 @@ task('index', type: Index) {
}
}

/*
* Setup tasks (distribution)
*/
task dist(type: Zip) {
description 'Create distribution archives containing p2 repository (including R5 index).'
group 'release'
dependsOn index
destinationDir = file(buildDir)
inputs.files p2, index
destinationDir = buildDir
archiveName = 'bndtools-latest.zip'
from "${buildDir}/p2"
include '**'
Expand Down
7 changes: 0 additions & 7 deletions build/main.bnd

This file was deleted.

0 comments on commit edc7dd6

Please sign in to comment.