Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-17031] add new provider for Json files
- Loading branch information
Showing
5 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
src/main/java/org/jenkinsci/plugins/configfiles/json/JsonConfig.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,102 @@ | ||
/* | ||
The MIT License | ||
Copyright (c) 2012, Dominik Bartholdi | ||
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 org.jenkinsci.plugins.configfiles.json; | ||
|
||
import hudson.Extension; | ||
|
||
import org.jenkinsci.lib.configprovider.AbstractConfigProviderImpl; | ||
import org.jenkinsci.lib.configprovider.model.Config; | ||
import org.jenkinsci.lib.configprovider.model.ContentType; | ||
import org.jenkinsci.plugins.configfiles.Messages; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
/** | ||
* A config/provider to handle the special case of a Json file | ||
* | ||
* @author Dominik Bartholdi (imod) | ||
* | ||
*/ | ||
public class JsonConfig extends Config { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@DataBoundConstructor | ||
public JsonConfig(String id, String name, String comment, String content) { | ||
super(id, name, comment, fixJsonContent(content)); | ||
} | ||
|
||
/** | ||
* as the form submission with stapler is done in json too, we have to do "deescape" the formated content of the json file. | ||
* | ||
* @param content | ||
* the json body of the file | ||
* @return deescaped json | ||
*/ | ||
private static String fixJsonContent(String content) { | ||
final String c = content.trim(); | ||
if (c.startsWith("\"") && c.endsWith("\"")) { | ||
return c.substring(1, c.length() - 1); | ||
} | ||
return c; | ||
} | ||
|
||
@Extension(ordinal = 180) | ||
public static class JsonConfigProvider extends AbstractConfigProviderImpl { | ||
|
||
public JsonConfigProvider() { | ||
load(); | ||
} | ||
|
||
@Override | ||
public ContentType getContentType() { | ||
return new ContentType() { | ||
public String getCmMode() { | ||
return "javascript"; | ||
} | ||
|
||
public String getMime() { | ||
return "application/json"; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.json_provider_name(); | ||
} | ||
|
||
@Override | ||
public JsonConfig getConfigById(String configId) { | ||
final Config c = super.getConfigById(configId); | ||
return new JsonConfig(c.id, c.name, c.comment, c.content); | ||
} | ||
|
||
@Override | ||
public Config newConfig() { | ||
String id = getProviderId() + System.currentTimeMillis(); | ||
return new Config(id, "JsonConfig", "", "{}"); | ||
} | ||
|
||
} | ||
|
||
} |
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
29 changes: 29 additions & 0 deletions
29
.../jenkinsci/plugins/configfiles/json/JsonConfig/JsonConfigProvider/newInstanceDetail.jelly
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,29 @@ | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2013, Dominik Bartholdi | ||
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. | ||
--> | ||
|
||
|
||
|
||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> | ||
${%json_provider_description} | ||
</j:jelly> |
24 changes: 24 additions & 0 deletions
24
...insci/plugins/configfiles/json/JsonConfig/JsonConfigProvider/newInstanceDetail.properties
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,24 @@ | ||
# The MIT License | ||
# | ||
# Copyright (c) 2013, Dominik Bartholdi | ||
# | ||
# 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. | ||
|
||
json_provider_description=a Json file | ||
|
43 changes: 43 additions & 0 deletions
43
src/main/resources/org/jenkinsci/plugins/configfiles/json/JsonConfig/edit-config.jelly
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,43 @@ | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2013, Dominik Bartholdi | ||
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. | ||
--> | ||
|
||
|
||
|
||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" | ||
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> | ||
|
||
<f:entry title="${%ID}" > | ||
<f:textbox readonly="readonly" name="config.id" value="${config.id}" /> | ||
</f:entry> | ||
<f:entry title="${%Name}"> | ||
<f:textbox name="config.name" value="${config.name}" /> | ||
</f:entry> | ||
<f:entry title="${%Comment}"> | ||
<f:textbox name="config.comment" value="${config.comment}" /> | ||
</f:entry> | ||
<f:entry title="${%Content}"> | ||
<f:textarea id="config.content" name="config.content" value="${config.content}" /> | ||
</f:entry> | ||
|
||
</j:jelly> |