From 25e57563372780943c8314781332223fe15d07df Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 9 Nov 2010 10:17:24 -0800 Subject: [PATCH] Initial cut of bundlor plugin --- .gitignore | 1 + build.gradle | 5 +- .../build/bundlor/BundlorPlugin.groovy | 125 ++++++++++++++++++ .../gradle-plugins/bundlor.properties | 1 + gradle/bundlor.gradle | 91 ------------- 5 files changed, 129 insertions(+), 94 deletions(-) create mode 100644 buildSrc/src/main/groovy/org/springframework/build/bundlor/BundlorPlugin.groovy create mode 100644 buildSrc/src/main/resources/META-INF/gradle-plugins/bundlor.properties delete mode 100644 gradle/bundlor.gradle diff --git a/.gitignore b/.gitignore index 0ba3856cb0..22d9c98516 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ .settings .springBeans build +!buildSrc/src/main/groovy/org/springframework/build derby.log integration-repo lib diff --git a/build.gradle b/build.gradle index 78bc90796e..4df5826631 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/buildSrc/src/main/groovy/org/springframework/build/bundlor/BundlorPlugin.groovy b/buildSrc/src/main/groovy/org/springframework/build/bundlor/BundlorPlugin.groovy new file mode 100644 index 0000000000..d566b3bc77 --- /dev/null +++ b/buildSrc/src/main/groovy/org/springframework/build/bundlor/BundlorPlugin.groovy @@ -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 { + + 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) + } + } + } + } +} diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/bundlor.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/bundlor.properties new file mode 100644 index 0000000000..4a1b85d2ad --- /dev/null +++ b/buildSrc/src/main/resources/META-INF/gradle-plugins/bundlor.properties @@ -0,0 +1 @@ +implementation-class=org.springframework.build.bundlor.BundlorPlugin diff --git a/gradle/bundlor.gradle b/gradle/bundlor.gradle deleted file mode 100644 index 6672a01d1a..0000000000 --- a/gradle/bundlor.gradle +++ /dev/null @@ -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 -