Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from ikedam/feature/JENKINS-19843_RebuildParam…
…eterProvider [JENKINS-19843] Provides an extension point for other plugins to support rebuild plugin.
- Loading branch information
Showing
6 changed files
with
279 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/com/sonyericsson/rebuild/RebuildParameterPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2013 IKEDA Yasuyuki | ||
* | ||
* 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 com.sonyericsson.rebuild; | ||
|
||
/** | ||
* An object contains information of the view to show parameters in rebuild page. | ||
*/ | ||
public class RebuildParameterPage { | ||
private final Class<?> clazz; | ||
/** | ||
* @return the class for the view. | ||
*/ | ||
public Class<?> getClazz() { | ||
return clazz; | ||
} | ||
|
||
private final String page; | ||
/** | ||
* @return the path of jelly(or groovy) file. | ||
*/ | ||
public String getPage() { | ||
return page; | ||
} | ||
|
||
/** | ||
* @param clazz the class for the view. | ||
* @param page the path of jelly(or groovy) file. | ||
*/ | ||
public RebuildParameterPage(Class<?> clazz, String page) { | ||
this.clazz = clazz; | ||
this.page = page; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
src/main/java/com/sonyericsson/rebuild/RebuildParameterProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2013 IKEDA Yasuyuki | ||
* | ||
* 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 com.sonyericsson.rebuild; | ||
|
||
import jenkins.model.Jenkins; | ||
import hudson.Extension; | ||
import hudson.ExtensionList; | ||
import hudson.ExtensionPoint; | ||
import hudson.model.ParameterValue; | ||
|
||
/** | ||
* Extension point to provide views to show parameters in rebuild page. | ||
* | ||
* If you want your custom {@link ParameterValue} to work with rebuild plugin, | ||
* do as followings: | ||
* <ol> | ||
* <li>Add a dependency to rebuild plugin to your pom.xml. | ||
* You should specify <optional>true</optional> | ||
* to have your plugin work without rebuild plugin.</li> | ||
* <li>Define a class implementing {@link RebuildParameterProvider}.</li> | ||
* <li>Annotate the class with {@link Extension}. | ||
* You should specify option=true in {@link Extension} annotation | ||
* to have your plugin work without rebuild plugin.</li> | ||
* <li>Override {@link RebuildParameterProvider#getRebuildPage(ParameterValue)}. | ||
* Don't forget to return <code>null</code> for parameter values | ||
* other than your custom {@link ParameterValue}. | ||
* There are two recommended ways to set values to {@link RebuildParameterPage}: | ||
* <table> | ||
* <tr> | ||
* <th> </th> | ||
* <th>Recommended 1</th> | ||
* <th>Recommended 2</th> | ||
* </tr> | ||
* <tr> | ||
* <th>clazz</th> | ||
* <td>your custom {@link ParameterValue}</td> | ||
* <td>the class implementing {@link RebuildParameterProvider}</td> | ||
* </tr> | ||
* <tr> | ||
* <th>page</th> | ||
* <td>a file in the resource directory of your custom {@link ParameterValue}</td> | ||
* <td>a file in the resource directory of the class implementing {@link RebuildParameterProvider}</td> | ||
* </tr> | ||
* </table> | ||
* </li> | ||
* </ol> | ||
*/ | ||
public abstract class RebuildParameterProvider implements ExtensionPoint { | ||
// This is defined not as an interface but as an abstract class. | ||
// If defined as an interface, developers might carelessly apply this | ||
// to mandatory class in their plugin and their plugins get not to work | ||
// without rebuild plugin. | ||
|
||
/** | ||
* Provide a view for specified {@link ParameterValue}. | ||
* | ||
* Return null if cannot handle specified {@link ParameterValue}. | ||
* | ||
* @param value a value to be shown in a rebuild page. | ||
* @return page for the parameter value. null for parameter values cannot be handled. | ||
*/ | ||
public abstract RebuildParameterPage getRebuildPage(ParameterValue value); | ||
|
||
/** | ||
* @return all {@link RebuildParameterProvider} registered to Jenkins. | ||
*/ | ||
public static ExtensionList<RebuildParameterProvider> all() { | ||
return Jenkins.getInstance().getExtensionList(RebuildParameterProvider.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...m/sonyericsson/rebuild/RebuildValidatorTest/SupportedUnknownParameterValue/rebuild.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.sonyericsson.rebuild.RebuildValidatorTest.SupportedUnknownParameterValue; | ||
|
||
f = namespace("lib/form") | ||
|
||
// "it" will be overridden inside nexted tags. | ||
String itName = it.name | ||
String itValue = it.value | ||
|
||
f.entry(title: it.name, description: it.description) { | ||
div(name: "parameter") { | ||
input(type: "hidden", name: "name", value: itName) | ||
input(type: "text", name: "value", value: itValue) | ||
text("This is a mark for test") | ||
} | ||
} | ||
|