提交 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 { ...@@ -916,7 +916,8 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
} }
if (d == null) { if (d == null) {
kind = jo.getString("$class"); kind = jo.getString("$class");
d = findByClassName(descriptors, kind); d = findByDescribableClassName(descriptors, kind);
if (d == null) d = findByClassName(descriptors, kind);
} }
if (d != null) { if (d != null) {
items.add(d.newInstance(req, jo)); items.add(d.newInstance(req, jo));
...@@ -952,6 +953,17 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable { ...@@ -952,6 +953,17 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
return null; 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. * 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)} * @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 { ...@@ -122,7 +122,7 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller {
} }
protected Downloadable createDownloadable() { protected Downloadable createDownloadable() {
return new Downloadable(getId()); return new Downloadable(getDownloadableId());
} }
/** /**
...@@ -130,7 +130,7 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller { ...@@ -130,7 +130,7 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller {
* <p> * <p>
* By default we use the fully-qualified class name of the {@link DownloadFromUrlInstaller} subtype. * By default we use the fully-qualified class name of the {@link DownloadFromUrlInstaller} subtype.
*/ */
public String getId() { public String getDownloadableId() {
return clazz.getName().replace('$','.'); return clazz.getName().replace('$','.');
} }
...@@ -144,7 +144,7 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller { ...@@ -144,7 +144,7 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller {
* @return never null. * @return never null.
*/ */
public List<? extends Installable> getInstallables() throws IOException { 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(); if(d==null) return Collections.emptyList();
return Arrays.asList(((InstallableList)JSONObject.toBean(d,InstallableList.class)).list); return Arrays.asList(((InstallableList)JSONObject.toBean(d,InstallableList.class)).list);
} }
......
...@@ -36,11 +36,15 @@ THE SOFTWARE. ...@@ -36,11 +36,15 @@ THE SOFTWARE.
</st:documentation> </st:documentation>
<j:set var="clazz" value="${attrs.clazz ?: attrs.descriptor.clazz.name}" /> <j:set var="clazz" value="${attrs.clazz ?: attrs.descriptor.clazz.name}" />
<f:invisibleEntry> <f:invisibleEntry>
<j:if test="${attrs.descriptor != null}"> <j:choose>
<input type="hidden" name="kind" value="${attrs.descriptor.id}" /> <j:when test="${descriptor != null and descriptor.id != clazz}">
</j:if> <input type="hidden" name="kind" value="${attrs.descriptor.id}" />
<!-- Legacy: Remove once plugins have been staged onto $class --> </j:when>
<input type="hidden" name="stapler-class" value="${clazz}" /> <j:otherwise>
<input type="hidden" name="$class" value="${clazz}" /> <!-- 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> </f:invisibleEntry>
</j:jelly> </j:jelly>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册