Skip to content

Commit

Permalink
Merge branch 'master' into task/script-splitting/update
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman authored Jan 26, 2021
2 parents ce723a0 + 0f5a324 commit f9eb138
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 133 deletions.
20 changes: 16 additions & 4 deletions pipeline-model-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jackson2-api</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-json-org</artifactId>
</dependency>
<dependency>
<groupId>com.github.fge</groupId>
<artifactId>json-schema-validator</artifactId>
Expand All @@ -73,6 +69,22 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,19 @@ public synchronized Descriptor<? extends Describable> lookupFunction(String n, @
return null;
} else if (describable == null) {
if (!describableMap.containsKey(n)) {
Descriptor<? extends Describable> d = SymbolLookup.get().findDescriptor(Describable.class, n);
Descriptor<? extends Describable> d = null;

// Prefer metasteps, falling back on any old describable.
for (StepDescriptor metaStep : StepDescriptor.metaStepsOf(n)) {
d = SymbolLookup.get().findDescriptor(metaStep.getMetaStepArgumentType(), n);
if (d != null) {
break;
}
}
// Fall back on a non-metastep describable
if (d == null) {
d = SymbolLookup.get().findDescriptor(Describable.class, n);
}
describableMap.put(n, d);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* The MIT License
*
* Copyright (c) 2021, CloudBees, Inc.
*
* 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
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.pipeline.modeldefinition;

import hudson.model.AbstractDescribableImpl;
import hudson.model.Describable;
import hudson.model.Descriptor;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.workflow.testMetaStep.Curve;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;

import javax.annotation.Nonnull;

import static org.junit.Assert.assertEquals;

public class DescriptorLookupCacheTest {
@Rule
public JenkinsRule j = new JenkinsRule();

@Test
public void lookupFunctionPrefersMetaStep() throws Exception {
Descriptor<? extends Describable> d = DescriptorLookupCache.getPublicCache().lookupFunction("rhombus");
assertEquals(Rhombus.DescriptorImpl.class, d.getClass());
}

public static final class FakeRhombus extends AbstractDescribableImpl<FakeRhombus> {
public final boolean foo;

@DataBoundConstructor
public FakeRhombus(boolean foo) {
this.foo = foo;
}

@Symbol("rhombus")
@TestExtension
public static final class DescriptorImpl extends Descriptor<FakeRhombus> {

}
}

public static final class Rhombus extends Curve {
public final int n;

@DataBoundConstructor public Rhombus(int n) {
this.n = n;
}

@Override public String getDescription() {
return n + "-gon";
}

@Symbol("rhombus")
@TestExtension
public static class DescriptorImpl extends Descriptor<Curve> {
@Nonnull
@Override
public String getDisplayName() {
return "rhombus curve";
}
}
}
}
8 changes: 1 addition & 7 deletions pipeline-model-definition/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<artifactId>maven-hpi-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<compatibleSinceVersion>1.2-beta-4</compatibleSinceVersion>
<compatibleSinceVersion>1.6.0</compatibleSinceVersion>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -146,12 +146,6 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-stage-step</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>docker-workflow</artifactId>
<scope>runtime</scope> <!-- TODO unused, just here to encourage upgrades -->
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials-binding</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,77 +70,18 @@
to nominate additional variables and their values to be captured for descriptors.
</st:attribute>
</st:documentation>
<d:taglib uri="local">
<d:tag name="body">
<table style="width:100%">
<j:set var="help" value="${descriptor.helpFile}" />
<j:if test="${hasHeader}">
<tr>
<td colspan="3">
<div class="dd-handle">
<b>${descriptor.displayName}</b>
</div>
</td>
<f:helpLink url="${help}"/>
</tr>
<!-- TODO: help support is unintuitive; people should be able to see help from drop-down menu -->
<j:if test="${help!=null}">
<f:helpArea />
</j:if>
</j:if>

<d:invokeBody/>

<f:class-entry descriptor="${descriptor}" />
<f:block>
<div align="right">
<f:repeatableDeleteButton value="${attrs.deleteCaption}" />
</div>
</f:block>
</table>
</d:tag>
</d:taglib>

<st:adjunct includes="lib.form.hetero-list.hetero-list"/>

<j:set var="targetType" value="${attrs.targetType?:it.class}"/>
<div class="hetero-list-container ${hasHeader?'with-drag-drop':''} ${attrs.oneEach?'one-each':''} ${attrs.honorOrder?'honor-order':''}">
<!-- display existing items -->
<j:forEach var="i" items="${attrs.items}">
<j:set var="descriptor" value="${i.descriptor}" />
<j:set var="instance" value="${i}" />
<div name="${attrs.name}" class="repeated-chunk" descriptorId="${descriptor.id}">
<local:body deleteCaption="${attrs.deleteCaption}">
<st:include from="${descriptor}" page="${descriptor.configPage}" optional="true" />
</local:body>
</div>
</j:forEach>

<div class="repeatable-insertion-point" />

<div class="prototypes to-be-removed">
<!-- render one prototype for each type -->
<j:set var="instance" value="${null}" />
<j:set var="descriptors" value="${h.filterDescriptors(it,attrs.descriptors)}" />
<j:forEach var="descriptor" items="${descriptors}" varStatus="loop">
<j:invokeStatic var="symbol" className="org.jenkinsci.plugins.pipeline.modeldefinition.generator.DirectiveGenerator" method="getSymbolForDescriptor">
<j:arg value="${descriptor}" type="hudson.model.Descriptor" />
</j:invokeStatic>
<div name="${attrs.name}" title="${symbol}: ${descriptor.displayName}" tooltip="${descriptor.tooltip}" descriptorId="${descriptor.id}">
<j:set var="capture" value="${attrs.capture?:''}" />
<local:body deleteCaption="${attrs.deleteCaption}">
<l:renderOnDemand tag="tr" clazz="config-page" capture="descriptor,it,instance,${capture}">
<l:ajax>
<st:include from="${descriptor}" page="${descriptor.configPage}" optional="true" />
</l:ajax>
</l:renderOnDemand>
</local:body>
</div>
</j:forEach>
</div>

<div>
<input type="button" value="${attrs.addCaption?:'%Add'}" class="hetero-list-add" menualign="${attrs.menuAlign}" suffix="${attrs.name}"/>
</div>
</div>
<f:hetero-list
name="${name}"
items="${items}"
descriptors="${descriptors}"
addCaption="${addCaption}"
deleteCaption="${deleteCaption}"
targetType="${targetType}"
hasHeader="${hasHeader}"
oneEach="${oneEach}"
menuAlign="${menuAlign}"
honorOrder="${honorOrder}"
capture="${capture}"
titleClassMethod="org.jenkinsci.plugins.pipeline.modeldefinition.generator.DirectiveGenerator#getSymbolForDescriptor"
/>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public static Iterable<Object[]> configsWithErrors() {
result.add(new Object[]{"perStageConfigMissingSteps", Messages.JSONParser_MissingRequiredProperties("'steps'")});
result.add(new Object[]{"perStageConfigUnknownSection", "additional properties are not allowed"});

result.add(new Object[]{"unknownAgentType", Messages.ModelValidatorImpl_InvalidAgentType("foo", "[any, docker, dockerfile, label, none, otherField]")});
result.add(new Object[]{"unknownAgentType", Messages.ModelValidatorImpl_InvalidAgentType("foo", "[any, label, none, otherField]")});

// Not using the full message here due to issues with the test extension in MultipleUnnamedParametersTest bleeding over in some situations.
// That resulted in multiArgCtorProp sometimes showing up in the list of valid options, but not always. We still have the full test in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@
package org.jenkinsci.plugins.pipeline.modeldefinition;

import htmlpublisher.HtmlPublisherTarget;
import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.model.Slave;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.testMetaStep.Curve;
import org.junit.BeforeClass;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -59,9 +66,14 @@ public void nestedTreeSteps() throws Exception {
public void metaStepSyntax() throws Exception {
env(s).set();
expect("steps/metaStepSyntax")
.archives("msg.out", "hello world")
.archives("msg2.out", "goodbye world")
.go();
.archives("msg.out", "hello world")
.archives("msg2.out", "goodbye world")
// Note that this test for the validator choosing a metastep over a random describable is inconsistent for
// the failure state - sometimes it works when it shouldn't for no obvious reason. A better test of this that
// will fail consistently is in pipeline-model-api's DescriptorLookupCacheTest#lookupFunctionPrefersMetaStep,
// but this is left here to be safe.
.logContains("wrapping in a 123-gon", "hi from in rhombus")
.go();
}

@Issue("JENKINS-41456")
Expand All @@ -75,4 +87,36 @@ public void htmlPublisher() throws Exception {
assertNotNull(buildReport);
assertEquals("Test Report", buildReport.getHTMLTarget().getReportName());
}

public static final class FakeRhombus extends AbstractDescribableImpl<FakeRhombus> {
public final boolean foo;

@DataBoundConstructor
public FakeRhombus(boolean foo) {
this.foo = foo;
}

@Symbol("rhombus")
@TestExtension
public static final class DescriptorImpl extends Descriptor<FakeRhombus> {

}
}

public static final class Rhombus extends Curve {
public final int n;

@DataBoundConstructor public Rhombus(int n) {
this.n = n;
}

@Override public String getDescription() {
return n + "-gon";
}

@Symbol("rhombus")
@TestExtension
public static class DescriptorImpl extends Descriptor<Curve> {}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@
"value": "[$class: 'ArtifactArchiver', artifacts: 'msg2.out', fingerprint: true]"
}
}]
},
{
"name": "rhombus",
"arguments": {
"isLiteral": true,
"value": 123
},
"children": [ {
"name": "echo",
"arguments": [ {
"key": "message",
"value": {
"isLiteral": true,
"value": "hi from in rhombus"
}
}]
}]
}
]
}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pipeline {
writeFile text: 'goodbye world', file: 'msg2.out'
archiveArtifacts(allowEmptyArchive: true, artifacts: 'msg.out')
step([$class: 'ArtifactArchiver', artifacts: 'msg2.out', fingerprint: true])
rhombus(123) {
echo 'hi from in rhombus'
}
}
}
}
Expand Down
Loading

0 comments on commit f9eb138

Please sign in to comment.