/** * Makes sure that the given {@link StepContext} has all the context parameters this descriptor wants to see, * and if not, throw {@link MissingContextVariableException} indicating which variable is missing. */ public final void checkContextAvailability(StepContext c) throws MissingContextVariableException, IOException, InterruptedException { // TODO the order here is nondeterministic; should we pick the lexicographic first? Or extend MissingContextVariableException to take a Set<Class<?>> types? for (Class<?> type : getRequiredContext()) { Object v = c.get(type); if (v==null) throw new MissingContextVariableException(type); } }
@Override public String getMessage() { StringBuilder b = new StringBuilder("Required context ").append(type).append(" is missing"); boolean first = true; for (StepDescriptor p : getProviders()) { if (first) { b.append("\nPerhaps you forgot to surround the code with a step that provides this, such as: "); first = false; } else { b.append(", "); } b.append(p.getFunctionName()); } return b.toString(); }
/** * Returns {@link StepDescriptor}s with body that can provide a context of this type, * so that the error message can diagnose what steps were likely missing. * * <p> * In such error diagnosing context, we don't care about {@link StepDescriptor}s that just * decorates/modifies the existing context, so we check required context as well to * exclude them */ public @Nonnull List<StepDescriptor> getProviders() { List<StepDescriptor> r = new ArrayList<StepDescriptor>(); for (StepDescriptor sd : StepDescriptor.all()) { if (isIn(sd.getProvidedContext()) && !isIn(sd.getRequiredContext())) r.add(sd); } return r; }
/** * Makes sure that the given {@link StepContext} has all the context parameters this descriptor wants to see, * and if not, throw {@link MissingContextVariableException} indicating which variable is missing. */ public final void checkContextAvailability(StepContext c) throws MissingContextVariableException, IOException, InterruptedException { // TODO the order here is nondeterministic; should we pick the lexicographic first? Or extend MissingContextVariableException to take a Set<Class<?>> types? for (Class<?> type : getRequiredContext()) { Object v = c.get(type); if (v==null) throw new MissingContextVariableException(type); } }
/** * Returns {@link StepDescriptor}s with body that can provide a context of this type, * so that the error message can diagnose what steps were likely missing. * * <p> * In such error diagnosing context, we don't care about {@link StepDescriptor}s that just * decorates/modifies the existing context, so we check required context as well to * exclude them */ public @Nonnull List<StepDescriptor> getProviders() { List<StepDescriptor> r = new ArrayList<StepDescriptor>(); for (StepDescriptor sd : StepDescriptor.all()) { if (isIn(sd.getProvidedContext()) && !isIn(sd.getRequiredContext())) r.add(sd); } return r; }
@Override protected final T run() throws Exception { ws = getContext().get(FilePath.class); if (ws == null && isNotBlank(fileOrTextStep.getFile())) { throw new MissingContextVariableException(FilePath.class); } return doRun(); }
@Override protected final T run() throws Exception { ws = getContext().get(FilePath.class); if (ws == null && isNotBlank(fileOrTextStep.getFile())) { throw new MissingContextVariableException(FilePath.class); } return doRun(); }
Run build = getContext().get(Run.class); if (build == null) { throw new MissingContextVariableException(Run.class); throw new MissingContextVariableException(Launcher.class);
@Override protected Void run() throws Exception { if (step.getJson() == null) { throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingJSON(step.getDescriptor().getFunctionName())); } if (StringUtils.isBlank(step.getFile())) { throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingFile(step.getDescriptor().getFunctionName())); } if (isNotBlank(step.getFile()) && ws == null) { // Need a workspace if we are writing to a file. throw new MissingContextVariableException(FilePath.class); } FilePath path = ws.child(step.getFile()); if (path.isDirectory()) { throw new FileNotFoundException(Messages.JSONStepExecution_fileIsDirectory(path.getRemote())); } try (OutputStreamWriter writer = new OutputStreamWriter(path.write())) { if (step.getPretty() > 0) { writer.write(step.getJson().toString(step.getPretty())); } else { step.getJson().write(writer); } } return null; }