assertEquals(1, firstBranch.getSteps().size()); ModelASTStep firstStep = firstBranch.getSteps().get(0); assertNull(firstStep.getSourceLocation()); assertEquals("echo", firstStep.getName()); ModelASTValue val = null; if (firstStep.getArgs() instanceof ModelASTSingleArgument) { val = ((ModelASTSingleArgument) firstStep.getArgs()).getValue(); } else if (firstStep.getArgs() instanceof ModelASTNamedArgumentList && ((ModelASTNamedArgumentList) firstStep.getArgs()).getArguments().size() == 1) { val = ((ModelASTNamedArgumentList) firstStep.getArgs()).valueForName("message"); assertNull(firstStep.getArgs().getSourceLocation()); assertNull(val.getSourceLocation()); assertEquals(2, secondBranch.getSteps().size()); ModelASTStep scriptStep = secondBranch.getSteps().get(0); assertNull(scriptStep.getSourceLocation()); assertTrue(scriptStep instanceof ModelASTScriptBlock); assertNull(scriptStep.getArgs().getSourceLocation()); ModelASTValue scriptVal = null; if (scriptStep.getArgs() instanceof ModelASTSingleArgument) { scriptVal = ((ModelASTSingleArgument) scriptStep.getArgs()).getValue(); } else if (scriptStep.getArgs() instanceof ModelASTNamedArgumentList && ((ModelASTNamedArgumentList) scriptStep.getArgs()).getArguments().size() == 1) { scriptVal = ((ModelASTNamedArgumentList) scriptStep.getArgs()).valueForName("scriptBlock"); assertNull(timeoutStep.getSourceLocation()); assertTrue(timeoutStep instanceof ModelASTTreeStep); assertEquals("timeout", timeoutStep.getName()); assertEquals("echo", treeStep.getChildren().get(0).getName());
@Override @CheckForNull public String validateElement(@Nonnull ModelASTStep step, @CheckForNull FlowExecution execution) { if (step.getName() != null) { if (blockedInSteps().keySet().contains(step.getName())) { return org.jenkinsci.plugins.pipeline.modeldefinition.Messages.ModelValidatorImpl_BlockedStep(step.getName(), blockedInSteps().get(step.getName())); } } return null; }
/** * Construct the new {@link BlockStatement} for the given branch. */ @Nonnull public final BlockStatement handleBranch(@Nonnull ModelASTBranch branch) { BlockStatement newBlock = block(); for (ModelASTStep s : branch.getSteps()) { // Don't process script blocks or a step that for some reason isn't an expression statement at all if (s instanceof AbstractModelASTCodeBlock || !(s.getSourceLocation() instanceof ExpressionStatement)) { newBlock.addStatement((Statement)s.getSourceLocation()); } else { ExpressionStatement es = (ExpressionStatement) s.getSourceLocation(); if (es.getExpression() instanceof MethodCallExpression) { MethodCallExpression methodCall = (MethodCallExpression) es.getExpression(); newBlock.addStatement(stmt(handleStep(s, methodCall))); } else { newBlock.addStatement(es); } } } return newBlock; }
/** * Use {@code org.jenkinsci.plugins.pipeline.modeldefinition.validator.BlockedStepsAndMethodCalls.blockedInSteps()} instead. * * @deprecated since 1.2-beta-4 */ @Deprecated @Restricted(NoExternalUse.class) public static Map<String, String> getBlockedSteps() { return blockedStepsBase(); }
/** * Use {@code org.jenkinsci.plugins.pipeline.modeldefinition.validator.BlockedStepsAndMethodCalls.blockedInMethodCalls()} instead. * * @deprecated since 1.2-beta-4 */ @Deprecated @Restricted(NoExternalUse.class) public static Map<String, String> getBlockedSteps() { Map<String, String> map = new LinkedHashMap<>(); map.put("node", Messages.ModelASTMethodCall_BlockedSteps_Node()); map.putAll(ModelASTStep.getBlockedSteps()); return map; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } ModelASTTreeStep that = (ModelASTTreeStep) o; return getChildren() != null ? getChildren().equals(that.getChildren()) : that.getChildren() == null; }
assertEquals(1, firstBranch.getSteps().size()); ModelASTStep firstStep = firstBranch.getSteps().get(0); assertNull(firstStep.getSourceLocation()); assertEquals("junit", firstStep.getName()); assertTrue(firstStep.getArgs() instanceof ModelASTNamedArgumentList); ModelASTNamedArgumentList args = (ModelASTNamedArgumentList)firstStep.getArgs();
/** * Call {@link #transformStep(ModelASTStep, MethodCallExpression)} if appropriate, after handling any nested steps as well. */ @Nonnull public final MethodCallExpression handleStep(@Nonnull ModelASTStep step, @Nonnull MethodCallExpression methodCall) { // No transformation inside script blocks. if (step instanceof AbstractModelASTCodeBlock) { return methodCall; } TupleExpression originalArgs = (TupleExpression) methodCall.getArguments(); if (step instanceof ModelASTTreeStep && originalArgs.getExpressions().size() > 0) { ArgumentListExpression newArgs = new ArgumentListExpression(); // Technically we can't get here if there 0 expressions, so the loop below is safe. for (int i = 0; i < originalArgs.getExpressions().size() - 1; i++) { newArgs.addExpression(originalArgs.getExpression(i)); } ClosureExpression originalClosure = (ClosureExpression) originalArgs.getExpression(originalArgs.getExpressions().size() - 1); BlockStatement newBlock = block(); for (ModelASTStep nested : ((ModelASTTreeStep) step).getChildren()) { ExpressionStatement es = (ExpressionStatement) nested.getSourceLocation(); newBlock.addStatement(stmt(handleStep(nested, (MethodCallExpression)es.getExpression()))); } originalClosure.setCode(newBlock); newArgs.addExpression(originalClosure); methodCall.setArguments(newArgs); } return transformStep(step, methodCall); }
/** * Use {@code org.jenkinsci.plugins.pipeline.modeldefinition.validator.BlockedStepsAndMethodCalls.blockedInSteps()} instead. * * @deprecated since 1.2-beta-4 */ @Deprecated @Restricted(NoExternalUse.class) public static Map<String, String> getBlockedSteps() { return blockedStepsBase(); }
/** * Use {@code org.jenkinsci.plugins.pipeline.modeldefinition.validator.BlockedStepsAndMethodCalls.blockedInMethodCalls()} instead. * * @deprecated since 1.2-beta-4 */ @Deprecated @Restricted(NoExternalUse.class) public static Map<String, String> getBlockedSteps() { Map<String, String> map = new LinkedHashMap<String, String>(); map.put("node", Messages.ModelASTMethodCall_BlockedSteps_Node()); map.putAll(ModelASTStep.getBlockedSteps()); return map; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } ModelASTTreeStep that = (ModelASTTreeStep) o; return getChildren() != null ? getChildren().equals(that.getChildren()) : that.getChildren() == null; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } ModelASTStep that = (ModelASTStep) o; if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) { return false; } return getArgs() != null ? getArgs().equals(that.getArgs()) : that.getArgs() == null; }
@Override @Nonnull public MethodCallExpression transformStep(@Nonnull ModelASTStep step, @Nonnull MethodCallExpression methodCall) { if (step.getName().equals("echo")) { ArgumentListExpression newArgs = new ArgumentListExpression(); TupleExpression oldArgs = (TupleExpression)methodCall.getArguments(); for (Expression expr : oldArgs.getExpressions()) { if (expr instanceof ConstantExpression && ((ConstantExpression) expr).getValue() instanceof String) { String origVal = (String)((ConstantExpression)expr).getValue(); newArgs.addExpression(constX(origVal.toUpperCase())); } } methodCall.setArguments(newArgs); } return methodCall; } }