Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/JENKINS-26781' into JENKINS-26781
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Apr 11, 2015
2 parents 3304190 + 901194a commit 724df64
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
53 changes: 44 additions & 9 deletions core/src/main/java/hudson/model/Descriptor.java
Expand Up @@ -909,38 +909,73 @@ List<T> newInstancesFromHeteroList(StaplerRequest req, Object formData,
if (formData!=null) {
for (Object o : JSONArray.fromObject(formData)) {
JSONObject jo = (JSONObject)o;
String kind = jo.optString("$class", null);
if (kind == null) {
// Legacy: Remove once plugins have been staged onto $class
kind = jo.getString("kind");
Descriptor<T> d = null;
String kind = jo.optString("kind", null);
if (kind != null) {
d = findById(descriptors, kind);
}
if (d == null) {
kind = jo.getString("$class");
d = findByDescribableClassName(descriptors, kind);
if (d == null) d = findByClassName(descriptors, kind);
}
Descriptor<T> d = find(descriptors, kind);
if (d != null) {
items.add(d.newInstance(req, jo));
} else {
LOGGER.warning("Received unexpected formData for descriptor " + kind);
}
}
}

return items;
}

/**
* Finds a descriptor from a collection by its id.
*/
public static @CheckForNull <T extends Descriptor> T findById(Collection<? extends T> list, String id) {
for (T d : list) {
if(d.getId().equals(id))
return d;
}
return null;
}

/**
* Finds a descriptor from a collection by its class name.
* @deprecated Since we introduced {@link Descriptor#getId()}, it is a preferred method of identifying descriptor by a string.
*/
public static @CheckForNull <T extends Descriptor> T find(Collection<? extends T> list, String className) {
public static @CheckForNull <T extends Descriptor> T findByClassName(Collection<? extends T> list, String className) {
for (T d : list) {
if(d.getClass().getName().equals(className))
return d;
}
// Since we introduced Descriptor.getId(), it is a preferred method of identifying descriptor by a string.
// To make that migration easier without breaking compatibility, let's also match up with the id.
return null;
}

/**
* Finds a descriptor from a collection by the class name of the Describable it describes.
*/
public static @CheckForNull <T extends Descriptor> T findByDescribableClassName(Collection<? extends T> list, String className) {
for (T d : list) {
if(d.getId().equals(className))
if(d.clazz.getName().equals(className))
return d;
}
return null;
}

/**
* Finds a descriptor from a collection by its class name or ID.
* @deprecated choose between {@link #findById(java.util.Collection, String)} or {@link #findByClassName(java.util.Collection, String)}
*/
public static @CheckForNull <T extends Descriptor> T find(Collection<? extends T> list, String string) {
T d = findByClassName(list, string);
if (d != null) {
return d;
}
return findById(list, string);
}

public static @CheckForNull Descriptor find(String className) {
return find(ExtensionList.lookup(Descriptor.class),className);
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/hudson/tools/DownloadFromUrlInstaller.java
Expand Up @@ -122,15 +122,15 @@ protected DescriptorImpl() {
}

protected Downloadable createDownloadable() {
return new Downloadable(getId());
return new Downloadable(getDownloadableId());
}

/**
* This ID needs to be unique, and needs to match the ID token in the JSON update file.
* <p>
* By default we use the fully-qualified class name of the {@link DownloadFromUrlInstaller} subtype.
*/
public String getId() {
public String getDownloadableId() {
return clazz.getName().replace('$','.');
}

Expand All @@ -144,7 +144,7 @@ public String getId() {
* @return never null.
*/
public List<? extends Installable> getInstallables() throws IOException {
JSONObject d = Downloadable.get(getId()).getData();
JSONObject d = Downloadable.get(getDownloadableId()).getData();
if(d==null) return Collections.emptyList();
return Arrays.asList(((InstallableList)JSONObject.toBean(d,InstallableList.class)).list);
}
Expand Down
19 changes: 11 additions & 8 deletions core/src/main/resources/lib/form/class-entry.jelly
Expand Up @@ -36,12 +36,15 @@ THE SOFTWARE.
</st:documentation>
<j:set var="clazz" value="${attrs.clazz ?: attrs.descriptor.clazz.name}" />
<f:invisibleEntry>
<!-- Legacy: Remove once plugins have been staged onto $class -->
<input type="hidden" name="stapler-class" value="${clazz}" />
<!-- Legacy: Remove once plugins have been staged onto $class -->
<j:if test="${attrs.descriptor != null}">
<input type="hidden" name="kind" value="${attrs.descriptor.id}" />
</j:if>
<input type="hidden" name="$class" value="${clazz}" />
<j:choose>
<j:when test="${descriptor != null and descriptor.id != clazz}">
<input type="hidden" name="kind" value="${attrs.descriptor.id}" />
</j:when>
<j:otherwise>
<!-- Legacy: Remove once plugins have been staged onto $class -->
<input type="hidden" name="stapler-class" value="${clazz}" />
<input type="hidden" name="$class" value="${clazz}" />
</j:otherwise>
</j:choose>
</f:invisibleEntry>
</j:jelly>
</j:jelly>

0 comments on commit 724df64

Please sign in to comment.