@Override public Builder newInstance(StaplerRequest req, JSONObject formData) throws FormException { // TODO f:dropdownDescriptorSelector does not seem to work sensibly: the super method uses // RequestImpl.bindJSON and ignores any StepDescriptor.newInstance override. // Cf. Snippetizer.doGenerateSnippet, which also seems to lack a standard way of parsing // part of a form using databinding. JSONObject s = formData.getJSONObject("s"); Jenkins j = Jenkins.getActiveInstance(); Class<?> c; try { c = j.getPluginManager().uberClassLoader.loadClass(s.getString("stapler-class")); } catch (ClassNotFoundException x) { throw new FormException(x, "s"); } Descriptor<?> descriptor = j.getDescriptor(c.asSubclass(Step.class)); return new StepBuilder((Step) descriptor.newInstance(req, s)); }
@Override protected void doConfigure( ServiceProfile<?> profile, Map<String, String> desiredProperties, Map<String, String> desiredEnvironmentVariables) throws InterruptedException, IOException { Map<String, String> conf = profile.getConfiguration(); String trackerClassName = conf.get(ExecutionTracker.KEY_CLASS); String trackingId = conf.get(ExecutionTracker.KEY_ID); assertThat(trackerClassName, is(notNullValue())); assertThat(trackingId, is(notNullValue())); try { Class<?> trackerClass = profile.getContext().getClassLoader().loadClass(trackerClassName); this.tracker = trackerClass.asSubclass(ExecutionTracker.class).newInstance(); this.id = ExecutionTracker.Id.get(trackingId); } catch (Exception e) { throw new AssertionError(e); } }