提交 901194ae 编写于 作者: N Nicolas De Loof

make $class and kind mutually exclusive

Use kind when descriptor.id != descriptor.clazz.name and $clazz otherwise.
上级 6a8ce6ca
......@@ -916,7 +916,8 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
}
if (d == null) {
kind = jo.getString("$class");
d = findByClassName(descriptors, kind);
d = findByDescribableClassName(descriptors, kind);
if (d == null) d = findByClassName(descriptors, kind);
}
if (d != null) {
items.add(d.newInstance(req, jo));
......@@ -952,6 +953,17 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
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.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)}
......
......@@ -122,7 +122,7 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller {
}
protected Downloadable createDownloadable() {
return new Downloadable(getId());
return new Downloadable(getDownloadableId());
}
/**
......@@ -130,7 +130,7 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller {
* <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('$','.');
}
......@@ -144,7 +144,7 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller {
* @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);
}
......
......@@ -36,11 +36,15 @@ THE SOFTWARE.
</st:documentation>
<j:set var="clazz" value="${attrs.clazz ?: attrs.descriptor.clazz.name}" />
<f:invisibleEntry>
<j:if test="${attrs.descriptor != null}">
<input type="hidden" name="kind" value="${attrs.descriptor.id}" />
</j:if>
<!-- 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: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>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册