Skip to content

Commit

Permalink
added support for Support-Dynamic-Loading manifest attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
daspilker committed Oct 21, 2014
1 parent 3bb0c14 commit 507d640
Show file tree
Hide file tree
Showing 25 changed files with 165 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* updated Gradle to version 1.12
* added support for `Plugin-Developers` manifest attribute
* added support for `Support-Dynamic-Loading` manifest attribute
* replaced usages of deprecated `groovy` configuration by `compile` configuration
* added `org.jenkins-ci.jpi` as alternative qualified plugin id for Gradle plugin portal inclusion
* `jpiDeployUser` and `jpiDeployPassword` properties from `org.jenkinsci.gradle.plugins.jpi.JpiExtension` were not
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
compile gradleApi()
compile 'org.jvnet.localizer:maven-localizer-plugin:1.13'
compile 'org.jenkins-ci:version-number:1.0'
compile 'net.java.sezpoz:sezpoz:1.9'
compile localGroovy()
testCompile('org.spockframework:spock-core:0.7-groovy-1.8') {
exclude module: 'groovy-all' // use the version that is distributed with Gradle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
package org.jenkinsci.gradle.plugins.jpi

import hudson.Extension
import jenkins.YesNoMaybe
import net.java.sezpoz.Index

import java.text.SimpleDateFormat
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginConvention
Expand Down Expand Up @@ -85,12 +89,11 @@ class JpiManifest extends HashMap<String, Object> {
}.join(',')
}

// more TODO
/*
Boolean b = isSupportDynamicLoading()
if (b!=null)
mainSection.addAttributeAndCheck(new Attribute("Support-Dynamic-Loading",b.toString()))
*/
YesNoMaybe supportDynamicLoading = isSupportDynamicLoading(classDir)
if (supportDynamicLoading != YesNoMaybe.MAYBE) {
this['Support-Dynamic-Loading'] = supportDynamicLoading == YesNoMaybe.YES
}

// remove empty values
this.entrySet().removeAll { it.value == null || it.value.toString().empty }
}
Expand Down Expand Up @@ -118,6 +121,21 @@ class JpiManifest extends HashMap<String, Object> {
}
}

private static YesNoMaybe isSupportDynamicLoading(File classDir) throws IOException {
ClassLoader classLoader = new URLClassLoader(
[classDir.toURI().toURL()] as URL[],
JpiManifest.classLoader as ClassLoader
)
def enums = Index.load(Extension, Object, classLoader).collect { it.annotation().dynamicLoadable() }
if (enums.contains(YesNoMaybe.NO)) {
return YesNoMaybe.NO
}
if (enums.contains(YesNoMaybe.MAYBE)) {
return YesNoMaybe.MAYBE
}
YesNoMaybe.YES
}

void writeTo(File f) {
def m = new Manifest()
m.mainAttributes.putValue('Manifest-Version', '1.0')
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/hudson/Extension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* The MIT License
*
* Copyright (c) 2011, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson;

import jenkins.YesNoMaybe;

import static jenkins.YesNoMaybe.MAYBE;

/**
* Minimal clone for auto-detection.
*
* @author Kohsuke Kawaguchi
*/
public @interface Extension {
YesNoMaybe dynamicLoadable() default MAYBE;
}
35 changes: 35 additions & 0 deletions src/main/java/jenkins/YesNoMaybe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* The MIT License
*
* Copyright (c) 2011, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package jenkins;

/**
* Clone for auto-detection.
*
* @author Kohsuke Kawaguchi
*/
public enum YesNoMaybe {
YES,
NO,
MAYBE
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.gradle.testfixtures.ProjectBuilder
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification
import spock.lang.Unroll

class JpiManifestSpec extends Specification {
Project project = ProjectBuilder.builder().build()
Expand Down Expand Up @@ -303,6 +304,33 @@ class JpiManifestSpec extends Specification {
file.text == readManifest('plugin-developers.mf')
}

@Unroll
def 'support dynamic loading #value'(String value) {
setup:
project.with {
apply plugin: 'jpi'
group = 'org.example'
version = '1.2'
jenkinsPlugin {
coreVersion = '1.509.3'
}
}
byte[] index = JpiManifestSpec.getResourceAsStream("support-dynamic-loading/${value}/hudson.Extension").bytes
File directory = new File(project.tasks.compileJava.destinationDir as File, 'META-INF/annotations')
directory.mkdirs()
new File(directory, 'hudson.Extension').bytes = index

when:
File file = temporaryFolder.newFile()
new JpiManifest(project).writeTo(file)

then:
file.text == readManifest("support-dynamic-loading-${value}.mf")

where:
value << ['yes', 'maybe', 'no']
}

private static String readManifest(String fileName) {
JpiManifestSpec.getResourceAsStream(fileName).text.replace(System.getProperty('line.separator'), '\r\n')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Manifest-Version: 1.0
Jenkins-Version: 1.509.3
Group-Id: org.example
v: 1.2
Support-Dynamic-Loading: true
Short-Name: test
Plugin-Version: 1.2
Long-Name: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Manifest-Version: 1.0
Jenkins-Version: 1.509.3
Group-Id: org.example
v: 1.2
Support-Dynamic-Loading: true
Short-Name: test
Compatible-Since-Version: 1.1
Plugin-Version: 1.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Group-Id: org.example
Plugin-Dependencies: git:1.1.15,ant:1.2,cloudbees-folder:4.2;resolutio
n:=optional,credentials:1.9.4;resolution:=optional
v: 1.0
Support-Dynamic-Loading: true
Short-Name: test
Plugin-Version: 1.0
Long-Name: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Jenkins-Version: 1.509.3
Group-Id: org.example
Plugin-Dependencies: git:1.1.15,ant:1.2
v: 1.0
Support-Dynamic-Loading: true
Short-Name: test
Plugin-Version: 1.0
Long-Name: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Jenkins-Version: 1.509.3
Group-Id: org.example
Plugin-Dependencies: ant:1.2
v: 1.0
Support-Dynamic-Loading: true
Short-Name: test
Plugin-Version: 1.0
Long-Name: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Manifest-Version: 1.0
Jenkins-Version: 1.509.3
Group-Id: org.example
v: 1.2
Support-Dynamic-Loading: true
Short-Name: test
Plugin-Version: 1.2
Mask-Classes: org.example.test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Group-Id: org.example
Plugin-Dependencies: git:1.1.15;resolution:=optional,ant:1.2;resolutio
n:=optional
v: 1.0
Support-Dynamic-Loading: true
Short-Name: test
Plugin-Version: 1.0
Long-Name: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Jenkins-Version: 1.509.3
Group-Id: org.example
Plugin-Dependencies: ant:1.2;resolution:=optional
v: 1.0
Support-Dynamic-Loading: true
Short-Name: test
Plugin-Version: 1.0
Long-Name: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Jenkins-Version: 1.509.3
Group-Id: org.example
v: 1.2
Plugin-Class: org.example.PluginImpl
Support-Dynamic-Loading: true
Short-Name: test
Plugin-Version: 1.2
Long-Name: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Jenkins-Version: 1.509.3
Group-Id: org.example
v: 1.2
Plugin-Developers: Andrew Bayer:abayer:andrew.bayer@gmail.com
Support-Dynamic-Loading: true
Short-Name: test
Plugin-Version: 1.2
Long-Name: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Group-Id: org.example
v: 1.2
Plugin-Developers: :abayer:andrew.bayer@gmail.com,Kohsuke Kawaguchi:ko
hsuke:
Support-Dynamic-Loading: true
Short-Name: test
Plugin-Version: 1.2
Long-Name: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Manifest-Version: 1.0
Jenkins-Version: 1.509.3
Group-Id: org.example
v: 1.2
Support-Dynamic-Loading: true
Short-Name: test
PluginFirstClassLoader: true
Plugin-Version: 1.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Manifest-Version: 1.0
Jenkins-Version: 1.509.3
Group-Id: org.example
v: 1.2
Support-Dynamic-Loading: true
Short-Name: test
Plugin-Version: 1.2
Long-Name: test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Manifest-Version: 1.0
Jenkins-Version: 1.509.3
Group-Id: org.example
v: 1.2
Short-Name: test
Plugin-Version: 1.2
Long-Name: test

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Manifest-Version: 1.0
Jenkins-Version: 1.509.3
Group-Id: org.example
v: 1.2
Support-Dynamic-Loading: false
Short-Name: test
Plugin-Version: 1.2
Long-Name: test

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Manifest-Version: 1.0
Jenkins-Version: 1.509.3
Group-Id: org.example
v: 1.2
Support-Dynamic-Loading: true
Short-Name: test
Plugin-Version: 1.2
Long-Name: test

Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 507d640

Please sign in to comment.