Skip to content

Commit

Permalink
[JENKINS-26781] set $class in submitted form to use descriptor.id, so…
Browse files Browse the repository at this point in the history
… descriptor can be retrieved by ID, which _may_ not be clazz.name
  • Loading branch information
ndeloof committed Feb 4, 2015
1 parent a944634 commit 094d1cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions core/src/main/java/hudson/model/Descriptor.java
@@ -1,18 +1,18 @@
/*
* The MIT License
*
*
* Copyright (c) 2004-2011, Sun Microsystems, Inc., Kohsuke Kawaguchi
*
*
* 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
Expand Down Expand Up @@ -117,7 +117,7 @@
* {@link Descriptor} defines addition to the standard Java reflection
* and provides reflective information about its corresponding {@link Describable}.
* These are primarily used by tag libraries to
* keep the Jelly scripts concise.
* keep the Jelly scripts concise.
*
* @author Kohsuke Kawaguchi
* @see Describable
Expand Down Expand Up @@ -222,7 +222,7 @@ public List<? extends Descriptor> getApplicableItemDescriptors() {
/**
* Help file redirect, keyed by the field name to the path.
*
* @see #getHelpFile(String)
* @see #getHelpFile(String)
*/
private transient final Map<String,HelpRedirect> helpRedirect = new HashMap<String,HelpRedirect>();

Expand Down Expand Up @@ -260,7 +260,7 @@ protected Descriptor(Class<? extends T> clazz) {
* Infers the type of the corresponding {@link Describable} from the outer class.
* This version works when you follow the common convention, where a descriptor
* is written as the static nested class of the describable class.
*
*
* @since 1.278
*/
protected Descriptor() {
Expand Down Expand Up @@ -309,7 +309,7 @@ protected Descriptor() {
*
* @return
* Stick to valid Java identifier character, plus '.', which had to be allowed for historical reasons.
*
*
* @since 1.391
*/
public String getId() {
Expand Down Expand Up @@ -510,7 +510,7 @@ public final String getJsonSafeClassName() {
/**
* @deprecated
* Implement {@link #newInstance(StaplerRequest, JSONObject)} method instead.
* Deprecated as of 1.145.
* Deprecated as of 1.145.
*/
public T newInstance(StaplerRequest req) throws FormException {
throw new UnsupportedOperationException(getClass()+" should implement newInstance(StaplerRequest,JSONObject)");
Expand Down Expand Up @@ -656,7 +656,7 @@ public String getHelpFile(Klass<?> clazz, String fieldName) {
}
return null;
}

/**
* Tells Jenkins that the help file for the field 'fieldName' is defined in the help file for
* the 'fieldNameToRedirectTo' in the 'owner' class.
Expand Down Expand Up @@ -711,7 +711,7 @@ public String getConfigPage() {
public String getGlobalConfigPage() {
return getViewPage(clazz, getPossibleViewNames("global"), null);
}

private String getViewPage(Class<?> clazz, String pageName, String defaultValue) {
return getViewPage(clazz,Collections.singleton(pageName),defaultValue);
}
Expand Down Expand Up @@ -918,6 +918,7 @@ List<T> newInstancesFromHeteroList(StaplerRequest req, Object formData,
if (d != null) {
items.add(d.newInstance(req, jo));
}
LOGGER.warning("Received unexpected formData for descriptor " + kind);
}
}

Expand All @@ -929,7 +930,7 @@ List<T> newInstancesFromHeteroList(StaplerRequest req, Object formData,
*/
public static @CheckForNull <T extends Descriptor> T find(Collection<? extends T> list, String className) {
for (T d : list) {
if(d.getClass().getName().equals(className))
if(d.clazz.getName().equals(className))
return d;
}
// Since we introduced Descriptor.getId(), it is a preferred method of identifying descriptor by a string.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/form/class-entry.jelly
Expand Up @@ -34,7 +34,7 @@ THE SOFTWARE.
structured form submission. Mutually exclusive with clazz.
</st:attribute>
</st:documentation>
<j:set var="clazz" value="${attrs.clazz ?: attrs.descriptor.clazz.name}" />
<j:set var="clazz" value="${attrs.clazz ?: attrs.descriptor.id}" />
<f:invisibleEntry>
<!-- Legacy: Remove once plugins have been staged onto $class -->
<input type="hidden" name="stapler-class" value="${clazz}" />
Expand Down

0 comments on commit 094d1cf

Please sign in to comment.