Skip to content

Commit 01d2b94

Browse files
authored
Merge pull request #104 from Cognifide/osgi-plugins-supported
Fix for 'No SCR metadata' in unit tests
2 parents 37f1fae + c792c45 commit 01d2b94

11 files changed

Lines changed: 70 additions & 35 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ AEM developer - it's time to meet Gradle! You liked or used plugin? Don't forget
3232
* Automated dependent packages installation from local and remote sources (SMB, SSH, HTTP(s)).
3333
* Smart Vault files generation (combining defaults with overiddables).
3434
* Embedded Vault tool for checking out and cleaning JCR content from running AEM instance.
35-
* OSGi Manifest customization by official [osgi](https://docs.gradle.org/current/userguide/osgi_plugin.html) plugin or feature rich [org.dm.bundle](https://github.com/TomDmitriev/gradle-bundle-plugin) plugin.
35+
* OSGi Manifest customization by official [OSGi plugin](https://docs.gradle.org/current/userguide/osgi_plugin.html) or feature rich [BND plugin](https://github.com/bndtools/bnd/tree/master/biz.aQute.bnd.gradle).
3636
* OSGi Declarative Services annotations support (instead of SCR, [see docs](http://blogs.adobe.com/experiencedelivers/experience-management/osgi/using-osgi-annotations-aem6-2/)).
3737

3838
## Table of contents
@@ -110,7 +110,7 @@ buildscript {
110110
}
111111
112112
dependencies {
113-
classpath 'com.cognifide.gradle:aem-plugin:2.0.17'
113+
classpath 'com.cognifide.gradle:aem-plugin:2.0.18'
114114
}
115115
}
116116

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group 'com.cognifide.gradle'
9-
version '2.0.17'
9+
version '2.0.18'
1010
description = 'Gradle AEM Plugin'
1111
defaultTasks = ['clean', 'publishToMavenLocal']
1212

src/main/kotlin/com/cognifide/gradle/aem/base/api/AemConfig.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ open class AemConfig(project: Project) : Serializable {
263263
@Input
264264
var satisfyRefreshing: Boolean = false
265265

266+
@Incubating
267+
@Input
268+
var testClasspathArchive: Boolean = true
269+
266270
/**
267271
* Initialize defaults that depends on concrete type of project.
268272
*/

src/main/kotlin/com/cognifide/gradle/aem/pkg/PackagePlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.gradle.language.base.plugins.LifecycleBasePlugin
1515
*
1616
* JVM based languages like Groovy or Kotlin must have implicitly applied 'java' plugin.
1717
* Projects can have only 'com.cognifide.aem.package' plugin applied intentionally to generate packages with content only.
18-
* Projects can have applied official 'osgi' or 'org.dm.bundle' plugins to customize OSGi manifest.
18+
* Projects can have applied official almost any type of OSGi plugin to customize manifest ('osgi', 'biz.aQute.bnd.builder', 'org.dm.bundle').
1919
*/
2020
class PackagePlugin : Plugin<Project> {
2121

@@ -30,7 +30,7 @@ class PackagePlugin : Plugin<Project> {
3030

3131
val VLT_PATH = "META-INF/vault"
3232

33-
val VLT_PROPERTIES = "${VLT_PATH}/properties.xml"
33+
val VLT_PROPERTIES = "$VLT_PATH/properties.xml"
3434

3535
val JCR_ROOT = "jcr_root"
3636

src/main/kotlin/com/cognifide/gradle/aem/pkg/jar/UpdateManifestTask.kt

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ package com.cognifide.gradle.aem.pkg.jar
33
import com.cognifide.gradle.aem.base.api.AemDefaultTask
44
import com.cognifide.gradle.aem.pkg.PackagePlugin
55
import org.dm.gradle.plugins.bundle.BundleExtension
6+
import org.gradle.api.java.archives.Manifest
67
import org.gradle.api.plugins.JavaPlugin
78
import org.gradle.api.plugins.osgi.OsgiManifest
89
import org.gradle.api.tasks.InputFiles
910
import org.gradle.api.tasks.Internal
1011
import org.gradle.api.tasks.TaskAction
12+
import org.gradle.api.tasks.testing.Test
1113
import org.gradle.jvm.tasks.Jar
1214
import java.io.File
1315

1416
/**
1517
* Update manifest being used by 'jar' task of Java Plugin.
18+
* Supported OSGi related plugins are: 'osgi', 'biz.aQute.bnd.builder', 'org.dm.bundle' and others.
1619
*
17-
* Both plugins 'osgi' and 'org.dm.bundle' are supported.
18-
*
19-
* @see <https://issues.gradle.org/browse/GRADLE-1107>
20+
* @see <https://github.com/bndtools/bnd/tree/master/biz.aQute.bnd.gradle>
2021
* @see <https://github.com/TomDmitriev/gradle-bundle-plugin>
2122
*/
2223
open class UpdateManifestTask : AemDefaultTask() {
@@ -36,6 +37,9 @@ open class UpdateManifestTask : AemDefaultTask() {
3637
@Internal
3738
val jar = project.tasks.getByName(JavaPlugin.JAR_TASK_NAME) as Jar
3839

40+
@Internal
41+
val test = project.tasks.getByName(JavaPlugin.TEST_TASK_NAME) as Test
42+
3943
val embeddableJars: List<File>
4044
@InputFiles
4145
get() {
@@ -44,10 +48,17 @@ open class UpdateManifestTask : AemDefaultTask() {
4448

4549
init {
4650
project.afterEvaluate {
51+
configureTest()
4752
embedJars()
4853
}
4954
}
5055

56+
private fun configureTest() {
57+
if (config.testClasspathArchive) {
58+
test.classpath += project.files(jar.archivePath)
59+
}
60+
}
61+
5162
private fun embedJars() {
5263
if (embeddableJars.isEmpty()) {
5364
return
@@ -69,12 +80,11 @@ open class UpdateManifestTask : AemDefaultTask() {
6980
} else if (project.plugins.hasPlugin(BUNDLE_PLUGIN_ID)) {
7081
addInstruction(project.extensions.getByType(BundleExtension::class.java), name, valueProvider())
7182
} else {
72-
project.logger.warn("Cannot apply specific OSGi instruction to JAR manifest, because neither "
73-
+ "'$OSGI_PLUGIN_ID' nor '$BUNDLE_PLUGIN_ID' are applied to project '${project.name}'.")
83+
addInstruction(jar.manifest, name, valueProvider())
7484
}
7585
}
7686

77-
private fun addInstruction(manifest: OsgiManifest, name: String, value: String) {
87+
private fun addInstruction(manifest: OsgiManifest, name: String, value: String?) {
7888
if (!manifest.instructions.containsKey(name)) {
7989
if (!value.isNullOrBlank()) {
8090
manifest.instruction(name, value)
@@ -83,7 +93,7 @@ open class UpdateManifestTask : AemDefaultTask() {
8393
}
8494

8595
@Suppress("unchecked_cast")
86-
private fun addInstruction(config: BundleExtension, name: String, value: String) {
96+
private fun addInstruction(config: BundleExtension, name: String, value: String?) {
8797
val instructions = config.instructions as Map<String, Any>
8898
if (!instructions.contains(name)) {
8999
if (!value.isNullOrBlank()) {
@@ -92,6 +102,14 @@ open class UpdateManifestTask : AemDefaultTask() {
92102
}
93103
}
94104

105+
private fun addInstruction(manifest: Manifest, name: String, value: String?) {
106+
if (!manifest.attributes.containsKey(name)) {
107+
if (!value.isNullOrBlank()) {
108+
manifest.attributes(mapOf(name to value))
109+
}
110+
}
111+
}
112+
95113
@TaskAction
96114
fun updateManifest() {
97115
// nothing to do in execution phase right now, hook for later ;)

src/test/resources/com/cognifide/gradle/aem/test/compose/assembly/build.gradle

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ allprojects { subproject ->
2828
}
2929
}
3030

31-
plugins.withId 'org.dm.bundle', {
32-
bundle {
33-
instruction 'Bundle-Name', subproject.description
34-
instruction 'Bundle-Category', 'example'
35-
instruction 'Bundle-Vendor', 'Company'
31+
plugins.withId 'biz.aQute.bnd.builder', {
32+
jar {
33+
manifest {
34+
attributes([
35+
'Bundle-Name': subproject.description,
36+
'Bundle-Category': 'example',
37+
'Bundle-Vendor': 'Company'
38+
])
39+
}
3640
}
41+
3742
dependencies {
3843
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.5.10'
3944
compile group: 'org.osgi', name: 'osgi.cmpn', version: '6.0.0'

src/test/resources/com/cognifide/gradle/aem/test/compose/assembly/common/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defaultTasks = ['aemBuild']
77

88
apply plugin: 'java'
99
apply plugin: "kotlin"
10-
apply plugin: 'org.dm.bundle'
10+
apply plugin: 'biz.aQute.bnd.builder'
1111
apply plugin: 'com.cognifide.aem.package'
1212

1313
bundle {

src/test/resources/com/cognifide/gradle/aem/test/compose/assembly/core/build.gradle

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ defaultTasks = ['aemBuild']
77

88
apply plugin: 'java'
99
apply plugin: "kotlin"
10-
apply plugin: 'org.dm.bundle'
10+
apply plugin: 'biz.aQute.bnd.builder'
1111
apply plugin: 'com.cognifide.aem.package'
1212

13-
bundle {
14-
def pkg = 'com.company.aem.example.core'
13+
jar {
14+
manifest {
15+
def pkg = 'com.company.aem.example.core'
1516

16-
instruction 'Bundle-SymbolicName', pkg
17-
instruction 'Sling-Model-Packages', pkg
18-
instruction 'Export-Package', "$pkg.*;-split-package:=merge-first"
17+
attributes([
18+
'Bundle-SymbolicName': pkg,
19+
'Sling-Model-Packages': pkg,
20+
'Export-Package': "$pkg.*;-split-package:=merge-first"
21+
])
22+
}
1923
}
2024

2125
dependencies {

src/test/resources/com/cognifide/gradle/aem/test/compose/assembly/gradle/buildscript.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repositories {
66
}
77

88
dependencies {
9-
classpath 'com.cognifide.gradle:aem-plugin:2.0.17'
10-
classpath "org.dm.gradle:gradle-bundle-plugin:0.10.0"
9+
classpath 'com.cognifide.gradle:aem-plugin:2.0.18'
10+
classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:3.5.0'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.60"
1212
}

src/test/resources/com/cognifide/gradle/aem/test/compose/bundle-and-content/build.gradle

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ buildscript {
66
}
77

88
dependencies {
9-
classpath 'com.cognifide.gradle:aem-plugin:2.0.17'
10-
classpath 'org.dm.gradle:gradle-bundle-plugin:0.10.0'
9+
classpath 'com.cognifide.gradle:aem-plugin:2.0.18'
10+
classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:3.5.0'
1111
}
1212
}
1313

1414
group = 'com.company.aem'
1515
version = '1.0.0-SNAPSHOT'
1616
description = 'Example'
1717

18-
apply plugin: 'com.cognifide.aem.package'
1918
apply plugin: 'java'
20-
apply plugin: 'org.dm.bundle'
19+
apply plugin: 'biz.aQute.bnd.builder'
20+
apply plugin: 'com.cognifide.aem.package'
2121

2222
repositories {
2323
mavenLocal()
@@ -31,8 +31,12 @@ dependencies {
3131
compile group: 'org.osgi', name: 'osgi.cmpn', version: '6.0.0'
3232
}
3333

34-
bundle {
35-
instruction 'Bundle-Name', description
36-
instruction 'Bundle-Category', 'example'
37-
instruction 'Bundle-Vendor', 'Company'
34+
jar {
35+
manifest {
36+
attributes([
37+
'Bundle-Name': description,
38+
'Bundle-Category': 'example',
39+
'Bundle-Vendor': 'Company'
40+
])
41+
}
3842
}

0 commit comments

Comments
 (0)