-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-14538] Move tool configuration to separate page #2140
Changes from all commits
ea5b2a7
4184b5a
03291cf
9e66786
6f8bf46
288796a
54ba3c1
807fa9a
4f7c7de
81c8f15
7045be8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3354,8 +3354,6 @@ public synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp | |
|
||
systemMessage = Util.nullify(req.getParameter("system_message")); | ||
|
||
setJDKs(req.bindJSONToList(JDK.class, json.get("jdks"))); | ||
|
||
boolean result = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This call is no more needed as the JDKs list is set in a call to its descriptor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, good. |
||
for (Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfigUnclassified()) | ||
result &= configureDescriptor(req,json,d); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
import hudson.Extension; | ||
import jenkins.model.GlobalConfiguration; | ||
import jenkins.model.GlobalConfigurationCategory; | ||
import jenkins.tools.ToolConfigurationCategory; | ||
import net.sf.json.JSONObject; | ||
|
||
import org.kohsuke.stapler.StaplerRequest; | ||
|
@@ -16,6 +18,11 @@ public GlobalMavenConfig() { | |
load(); | ||
} | ||
|
||
@Override | ||
public ToolConfigurationCategory getCategory() { | ||
return GlobalConfigurationCategory.get(ToolConfigurationCategory.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I think this is the potential argument against |
||
} | ||
|
||
@Override | ||
public boolean configure(StaplerRequest req, JSONObject json) throws FormException { | ||
req.bindJSON(this, json); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* 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.tools; | ||
|
||
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 jenkins.model.GlobalConfigurationCategory; | ||
import jenkins.model.Jenkins; | ||
import net.sf.json.JSONObject; | ||
|
||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1. Makes sense for all internal extension point implementations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
@Restricted(NoExternalUse.class) | ||
public class GlobalToolConfiguration extends ManagementLink { | ||
|
||
@Override | ||
public String getIconFileName() { | ||
return "setting.png"; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return jenkins.management.Messages.ConfigureTools_DisplayName(); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return jenkins.management.Messages.ConfigureTools_Description(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐜 should this not be in |
||
} | ||
|
||
@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, IOException { | ||
Jenkins j = Jenkins.getInstance(); | ||
j.checkPermission(Jenkins.ADMINISTER); | ||
|
||
boolean result = true; | ||
for(Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfig(FILTER)){ | ||
result &= configureDescriptor(req, json, d); | ||
} | ||
j.save(); | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐜 copy-pasted code should perhaps be factored into a utility class for creating standard kinds of global configuration screens. |
||
} | ||
|
||
public static Predicate<GlobalConfigurationCategory> FILTER = new Predicate<GlobalConfigurationCategory>() { | ||
public boolean apply(GlobalConfigurationCategory input) { | ||
return input instanceof ToolConfigurationCategory; | ||
} | ||
}; | ||
|
||
private static final Logger LOGGER = Logger.getLogger(GlobalToolConfiguration.class.getName()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package jenkins.tools; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tempted to make this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I follow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW this is actually not usable from plugins, they just have to implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment was supposed to go on line 12(ish). The idea is to prevent plugins from declaring whatever Descriptor they have to be in the tools category (like we do for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But |
||
|
||
import hudson.Extension; | ||
import jenkins.model.GlobalConfigurationCategory; | ||
|
||
/** | ||
* Global configuration of tool locations and installers. | ||
* | ||
* @since 2.0 | ||
*/ | ||
@Extension | ||
public class ToolConfigurationCategory extends GlobalConfigurationCategory { | ||
@Override | ||
public String getShortDescription() { | ||
return jenkins.management.Messages.ConfigureTools_Description(); | ||
} | ||
|
||
public String getDisplayName() { | ||
return jenkins.management.Messages.ConfigureTools_DisplayName(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW not an issue introduced in this PR, but would be nice at some point to use
core/move-l10n.groovy
to put this message in the natural place.