Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX JENKINS-14538] Move tool configuration to separate page
- Loading branch information
1 parent
9cab873
commit ea5b2a7
Showing
9 changed files
with
199 additions
and
15 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
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
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
102 changes: 102 additions & 0 deletions
102
core/src/main/java/jenkins/model/GlobalToolConfiguration.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) 2016 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.model; | ||
|
||
import com.google.common.base.Predicate; | ||
import hudson.Extension; | ||
import hudson.Functions; | ||
import hudson.model.Descriptor; | ||
import hudson.model.ManagementLink; | ||
import hudson.security.Permission; | ||
import hudson.util.FormApply; | ||
import net.sf.json.JSONObject; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
import org.kohsuke.stapler.StaplerResponse; | ||
|
||
import javax.servlet.ServletException; | ||
import java.io.IOException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
@Extension(ordinal = Integer.MAX_VALUE - 220) | ||
public class GlobalToolConfiguration extends ManagementLink { | ||
|
||
@Override | ||
public String getIconFileName() { | ||
return "setting.png"; // TODO more appropriate icon | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return jenkins.management.Messages.ConfigureTools_DisplayName(); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return jenkins.management.Messages.ConfigureTools_Description(); | ||
} | ||
|
||
@Override | ||
public String getUrlName() { | ||
return "configureTools"; | ||
} | ||
|
||
@Override | ||
public Permission getRequiredPermission() { | ||
return Jenkins.ADMINISTER; | ||
} | ||
|
||
public synchronized void doConfigure(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, Descriptor.FormException { | ||
boolean result = configure(req, req.getSubmittedForm()); | ||
LOGGER.log(Level.FINE, "tools saved: "+result); | ||
FormApply.success(req.getContextPath() + "/manage").generateResponse(req, rsp, null); | ||
} | ||
|
||
private boolean configure(StaplerRequest req, JSONObject json) throws hudson.model.Descriptor.FormException { | ||
Jenkins j = Jenkins.getInstance(); | ||
j.checkPermission(Jenkins.ADMINISTER); | ||
|
||
boolean result = true; | ||
for(Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfig(FILTER)){ | ||
result &= configureDescriptor(req, json, d); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private boolean configureDescriptor(StaplerRequest req, JSONObject json, Descriptor<?> d) throws Descriptor.FormException { | ||
String name = d.getJsonSafeClassName(); | ||
JSONObject js = json.has(name) ? json.getJSONObject(name) : new JSONObject(); // if it doesn't have the property, the method returns invalid null object. | ||
json.putAll(js); | ||
return d.configure(req, js); | ||
} | ||
|
||
public static Predicate<GlobalConfigurationCategory> FILTER = new Predicate<GlobalConfigurationCategory>() { | ||
public boolean apply(GlobalConfigurationCategory input) { | ||
return input instanceof GlobalConfigurationCategory.Tools; | ||
} | ||
}; | ||
|
||
private static final Logger LOGGER = Logger.getLogger(GlobalToolConfiguration.class.getName()); | ||
} |
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
44 changes: 44 additions & 0 deletions
44
core/src/main/resources/jenkins/model/GlobalToolConfiguration/index.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,44 @@ | ||
package hudson.security.GlobalToolConfiguration | ||
|
||
import hudson.Functions | ||
import hudson.model.Descriptor | ||
|
||
def f=namespace(lib.FormTagLib) | ||
def l=namespace(lib.LayoutTagLib) | ||
def st=namespace("jelly:stapler") | ||
|
||
l.layout(norefresh:true, permission:app.ADMINISTER, title:my.displayName) { | ||
l.side_panel { | ||
l.tasks { | ||
l.task(icon:"icon-up icon-md", href:rootURL+'/', title:_("Back to Dashboard")) | ||
l.task(icon:"icon-setting icon-md", href:"${rootURL}/manage", title:_("Manage Jenkins")) | ||
} | ||
} | ||
l.main_panel { | ||
h1 { | ||
l.icon(class: 'icon-setting icon-xlg') | ||
// TODO more appropriate icon | ||
text(my.displayName) | ||
} | ||
|
||
p() | ||
div(class:"behavior-loading", _("LOADING")) | ||
|
||
f.form(method:"post",name:"config",action:"configure") { | ||
Functions.getSortedDescriptorsForGlobalConfig(my.FILTER).each { Descriptor descriptor -> | ||
set("descriptor",descriptor) | ||
set("instance",descriptor) | ||
f.rowSet(name:descriptor.jsonSafeClassName) { | ||
st.include(from:descriptor, page:descriptor.globalConfigPage) | ||
} | ||
} | ||
|
||
f.bottomButtonBar { | ||
f.submit(value:_("Save")) | ||
f.apply() | ||
} | ||
} | ||
|
||
st.adjunct(includes: "lib.form.confirm") | ||
} | ||
} |