Initial cut of bundlor plugin

This commit is contained in:
Chris Beams
2010-11-09 10:17:24 -08:00
parent 9202dd01b2
commit 25e5756337
5 changed files with 129 additions and 94 deletions

1
.gitignore vendored
View File

@@ -9,6 +9,7 @@
.settings
.springBeans
build
!buildSrc/src/main/groovy/org/springframework/build
derby.log
integration-repo
lib

View File

@@ -84,6 +84,7 @@ configure(javaprojects) {
apply plugin: 'maven' // `gradle install` to push jars to local .m2 cache
apply plugin: 'eclipse' // `gradle eclipse` to generate .classpath/.project
apply plugin: 'idea' // `gradle idea` to generate .ipr/.iml
apply plugin: 'bundlor' // all core projects should be OSGi-compliant
// ensure JDK 5 compatibility
sourceCompatibility=1.5
@@ -94,9 +95,7 @@ configure(javaprojects) {
libsBinDir = new File(libsDir, 'bin')
libsSrcDir = new File(libsDir, 'src')
// all core projects should be OSGi-compliant bundles
// add the bundlor task to ensure proper manifests
apply from: "$rootDir/gradle/bundlor.gradle"
// add tasks for creating source jars and generating poms etc
apply from: "$rootDir/gradle/maven-deployment.gradle"
aspectjVersion = '1.6.8'

View File

@@ -0,0 +1,125 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.build.bundlor
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.logging.LogLevel
/**
* Contribute a 'bundlor' task capable of creating an OSGi manifest. Task is tied
* to the lifecycle by having the 'jar' task depend on 'bundlor'. Applies the 'java'
* plugin to the project if it has not already been applied.
*
* @author Chris Beams
* @author Luke Taylor
* @see http://www.springsource.org/bundlor
* @see http://static.springsource.org/s2-bundlor/1.0.x/user-guide/html/ch04s02.html
*/
public class BundlorPlugin implements Plugin<Project> {
public void apply(Project project) {
// bundlor plugin functionality only makes sense for java projects
// if the java plugin is already applied, the following is a no-op
project.getPlugins().apply(JavaPlugin.class)
// configuration that will be used when creating the ant taskdef classpath
project.configurations { bundlorconf }
project.dependencies {
bundlorconf 'com.springsource.bundlor:com.springsource.bundlor.ant:1.0.0.RELEASE',
'com.springsource.bundlor:com.springsource.bundlor:1.0.0.RELEASE',
'com.springsource.bundlor:com.springsource.bundlor.blint:1.0.0.RELEASE'
}
project.tasks.add("bundlor") {
dependsOn project.compileJava
description = 'Generates an OSGi-compatibile MANIFEST.MF file.'
/* TODO
// prescriptive defaults
bundleName = project.description
bundleVersion = project.version
bundleVendor = 'SpringSource'
//TODO bundleSymbolicName = project.basePackage
bundleSymbolicName = 'replace-me-with-base-package'
bundleManifestVersion = '2'
*/
def template = new File(project.projectDir, 'template.mf')
def bundlorDir = new File("${project.buildDir}/bundlor")
def manifest = new File("${bundlorDir}/META-INF/MANIFEST.MF")
// inform gradle what directory this task writes so that
// it can be removed when issuing `gradle cleanBundlor`
outputs.dir bundlorDir
// incremental build configuration
// if the manifest output file already exists, the bundlor
// task will be skipped *unless* any of the following are true
// * template.mf has been changed
// * main classpath dependencies have been changed
// * main java sources for this project have been modified
outputs.files manifest
inputs.files template, project.sourceSets.main.runtimeClasspath
// the bundlor manifest should be evaluated as part of the jar task's
// incremental build
project.jar {
dependsOn 'bundlor'
inputs.files manifest
}
project.jar.manifest.from manifest
doFirst {
project.ant.taskdef(
resource: 'com/springsource/bundlor/ant/antlib.xml',
classpath: project.configurations.bundlorconf.asPath)
// the bundlor ant task writes directly to standard out
// redirect it to INFO level logging, which gradle will
// deal with gracefully
project.logging.captureStandardOutput(LogLevel.INFO)
// TODO tell the jar task to use bundlor manifest instead of the default
// and customize it with all common headers
//project.jar.manifest {
//from manifest
//attributes['Bundle-SymbolicName'] = bundleSymbolicName
//attributes['Bundle-Name'] = bundleName
//attributes['Bundle-Vendor'] = bundleVendor
//attributes['Bundle-Version'] = bundleVersion
//attributes['Bundle-ManifestVersion'] = bundleManifestVersion
//}
// the ant task will throw unless this dir exists
if (!bundlorDir.isDirectory())
bundlorDir.mkdir()
// execute the ant task, and write out the manifest file
project.ant.bundlor(
inputPath: project.sourceSets.main.classesDir,
outputPath: bundlorDir,
manifestTemplatePath: template) {
property(name: 'version', value: project.version)
}
}
}
}
}

View File

@@ -0,0 +1 @@
implementation-class=org.springframework.build.bundlor.BundlorPlugin

View File

@@ -1,91 +0,0 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// -----------------------------------------------------------------------------
// Task definitions and configuration relating to the SpringSource 'bundlor'
// OSGi manifest generation utility.
//
// @author Chris Beams
// see: http://www.springsource.org/bundlor
// -----------------------------------------------------------------------------
/**
* Generate an OSGi manifest using the ant bundlor task.
*
* @author Luke Taylor
* @author Chris Beams
* @see http://static.springsource.org/s2-bundlor/1.0.x/user-guide/html/ch04s02.html
*/
task bundlor(dependsOn: compileJava) {
description = 'Generates an OSGi-compatibile MANIFEST.MF file.'
def template = new File(projectDir, 'template.mf')
def bundlorDir = new File("${project.buildDir}/bundlor")
def manifest = file("${bundlorDir}/META-INF/MANIFEST.MF")
// inform gradle what directory this task writes so that
// it can be removed when issuing `gradle cleanBundlor`
outputs.dir bundlorDir
// incremental build configuration
// if the $manifest output file already exists, the bundlor
// task will be skipped *unless* any of the following are true
// * template.mf has been changed
// * main classpath dependencies have been changed
// * main java sources for this project have been modified
outputs.files manifest
inputs.files template, project.sourceSets.main.runtimeClasspath
// tell the jar task to use bundlor manifest instead of the default
jar.manifest.from manifest
// the bundlor manifest should be evaluated as part of the jar task's
// incremental build
jar.inputs.files manifest
// configuration that will be used when creating the ant taskdef classpath
configurations { bundlorconf }
dependencies {
bundlorconf 'com.springsource.bundlor:com.springsource.bundlor.ant:1.0.0.RELEASE',
'com.springsource.bundlor:com.springsource.bundlor:1.0.0.RELEASE',
'com.springsource.bundlor:com.springsource.bundlor.blint:1.0.0.RELEASE'
}
doFirst {
ant.taskdef(resource: 'com/springsource/bundlor/ant/antlib.xml',
classpath: configurations.bundlorconf.asPath)
// the bundlor ant task writes directly to standard out
// redirect it to INFO level logging, which gradle will
// deal with gracefully
logging.captureStandardOutput(LogLevel.INFO)
// the ant task will throw unless this dir exists
if (!bundlorDir.isDirectory())
bundlorDir.mkdir()
// execute the ant task, and write out the $manifest file
ant.bundlor(inputPath: sourceSets.main.classesDir,
outputPath: bundlorDir, manifestTemplatePath: template) {
property(name: 'version', value: project.version)
property(name: 'spring.version', value: project.springVersion)
}
}
}
// ensure that the bundlor task runs prior to the jar task
jar.dependsOn bundlor