Skip to content

Commit

Permalink
fix and improve generated documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Oct 10, 2018
1 parent 32d7cf8 commit 6c4a1c4
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import hudson.BulkChange;
import hudson.model.Describable;
import hudson.model.Saveable;
import hudson.util.DescribableList;
import hudson.util.PersistedList;
import io.jenkins.plugins.casc.impl.attributes.DescribableAttribute;
import io.jenkins.plugins.casc.impl.attributes.DescribableListAttribute;
import io.jenkins.plugins.casc.impl.attributes.PersistedListAttribute;
import io.jenkins.plugins.casc.model.CNode;
import io.jenkins.plugins.casc.model.Mapping;
Expand Down Expand Up @@ -143,7 +145,9 @@ protected Attribute detectActualType(String name, final TypePair type) {
}

Attribute attribute;
if (PersistedList.class.isAssignableFrom(type.rawType)) {
if (DescribableList.class.isAssignableFrom(type.rawType)) {
return new DescribableListAttribute(name, c);
} else if (PersistedList.class.isAssignableFrom(type.rawType)) {
return new PersistedListAttribute(name, c);
} else if (!c.isPrimitive() && !c.isEnum() && Modifier.isAbstract(c.getModifiers())) {
if (!Describable.class.isAssignableFrom(c)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import io.jenkins.plugins.casc.ConfigurationContext;
import io.jenkins.plugins.casc.model.CNode;
import io.jenkins.plugins.casc.model.Mapping;
import jenkins.model.Jenkins;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/**
* Handles {@link AuthorizationStrategy.Unsecured} that requires a special treatment due to its singleton semantics.
Expand All @@ -25,6 +27,17 @@ public Class<Unsecured> getTarget() {
return Unsecured.class;
}

@Nonnull
@Override
public Class getImplementedAPI() {
return AuthorizationStrategy.class;
}

@Override
public String getDisplayName() {
return Jenkins.getInstance().getDescriptorOrDie(Unsecured.class).getDisplayName();
}

@Override
protected Unsecured instance(Mapping mapping, ConfigurationContext context) {
return (Unsecured)AuthorizationStrategy.UNSECURED;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.jenkins.plugins.casc.impl.attributes;

import hudson.util.PersistedList;

import java.util.Collection;

/**
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
*/
public class DescribableListAttribute<Owner, Type> extends DescribableAttribute<Owner, Collection<Type>> {

public DescribableListAttribute(String name, Class type) {
super(name, type);
multiple(true);
}

@Override
public void setValue(Owner target, Collection<Type> o) throws Exception {
getValue(target).replaceBy(o);
}

@Override
public PersistedList getValue(Owner o) throws Exception {
return (PersistedList) super.getValue(o);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,6 @@ private Constructor getDataBoundConstructor() throws ConfiguratorException {

public String getDisplayName() {
final Descriptor descriptor = getDescriptor();
return descriptor != null ? descriptor.getDisplayName() : "";
return descriptor != null ? descriptor.getDisplayName() : getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,41 @@
<j:jelly xmlns:j="jelly:core">

<div class='configurator'>
<div id="${it.extensionPoint.simpleName}-${it.name}" class='configurator__name'>${it.name} <sup class='configurator-pointer'>${%CONFIGURATOR}</sup></div>
<div id="${it.implementedAPI.simpleName}-${it.name}" class='configurator__name'>${it.name}
<sup class='configurator-pointer'>
<j:choose>
<j:when test="${it.rootElement}">
⚙️ ️${%ROOT ELEMENT}
</j:when>
<j:otherwise>
${%CONFIGURATOR}
</j:otherwise>
</j:choose>

<j:if test="${it.extensionPoint != it.target}">
</sup>
</div>

<j:if test="${it.implementedAPI != it.target}">
<div class='configurator__implementation'>
Implementation of
<a href="https://jenkins.io/doc/developer/extensions/${casc.extensionSource}/#${it.extensionPoint.simpleName.toLowerCase()}">
${it.extensionPoint.simpleName}
<a href="https://jenkins.io/doc/developer/extensions/${casc.getExtensionSource(it)}/#${it.implementedAPI.simpleName.toLowerCase()}">
${it.implementedAPI.simpleName}
</a>
</div>
</j:if>

<div class='configurator__display-name'>${it.displayName}</div>
<j:if test="${it.name != it.displayName}">
<div class='configurator__display-name'>${it.displayName}</div>
</j:if>

<div class='configurator-attributes'>
<j:forEach items="${it.attributes}" var="a">
<div class='configurator-attribute'>
<div class='configurator-attribute__name'><span class='attribute-name'>${a.name}</span></div>
<div class='configurator-attribute__details'>
<div class='attribute-type'>
<j:if test="${a.multiple}"><span class='attribute-type__list'>list of</span></j:if> <span class='attribute-type__class'>${a.type.simpleName}</span>
<j:if test="${a.multiple}"><span class='attribute-type__list'>list of</span></j:if>
<span class='attribute-type__class'>${a.type.simpleName}</span>
</div>
<div class='attribute-help'>
<j:out value="${casc.getHtmlHelp(it.target, a.name)}"/>
Expand Down

0 comments on commit 6c4a1c4

Please sign in to comment.