hudson.model.Descriptor Java Examples
The following examples show how to use
hudson.model.Descriptor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DockerSlave.java From yet-another-docker-plugin with MIT License | 6 votes |
public DockerSlave(String slaveName, String nodeDescription, ComputerLauncher launcher, String containerId, DockerSlaveTemplate dockerSlaveTemplate, String cloudId, ProvisioningActivity.Id provisioningId) throws IOException, Descriptor.FormException { super(slaveName, nodeDescription, //description dockerSlaveTemplate.getRemoteFs(), dockerSlaveTemplate.getNumExecutors(), dockerSlaveTemplate.getMode(), dockerSlaveTemplate.getLabelString(), launcher, dockerSlaveTemplate.getRetentionStrategyCopy(), dockerSlaveTemplate.getNodeProperties() ); this.displayName = slaveName; // initial value this.containerId = containerId; this.cloudId = cloudId; setDockerSlaveTemplate(dockerSlaveTemplate); this.provisioningId = provisioningId; }
Example #2
Source File: DockerCloud.java From yet-another-docker-plugin with MIT License | 6 votes |
private DockerSlave getDockerSlaveWithRetry(DockerSlaveTemplate template, ProvisioningActivity.Id id, String containerId, String nodeDescription, String slaveName, DockerComputerLauncher launcher) throws IOException, Descriptor.FormException, InterruptedException { int retries = 6; while (retries >= 0) { try { return new DockerSlave(slaveName, nodeDescription, launcher, containerId, template, getDisplayName(), id); } catch (IOException t) { if (retries <= 0) { throw t; } LOG.trace("Failed to create DockerSlaveSingle, retrying...", t); Thread.sleep(1000); } finally { retries--; } } throw new IllegalStateException("Max creation retries"); }
Example #3
Source File: StandardPlannedNodeBuilder.java From kubernetes-plugin with Apache License 2.0 | 6 votes |
@Override public NodeProvisioner.PlannedNode build() { KubernetesCloud cloud = getCloud(); PodTemplate t = getTemplate(); Future f; String displayName; try { KubernetesSlave agent = KubernetesSlave .builder() .podTemplate(cloud.getUnwrappedTemplate(t)) .cloud(cloud) .build(); displayName = agent.getDisplayName(); f = Futures.immediateFuture(agent); } catch (IOException | Descriptor.FormException e) { displayName = null; f = Futures.immediateFailedFuture(e); } return new NodeProvisioner.PlannedNode(Util.fixNull(displayName), f, getNumExecutors()); }
Example #4
Source File: NomadSlave.java From jenkins-nomad with MIT License | 6 votes |
public NomadSlave( NomadCloud cloud, String name, String nodeDescription, NomadSlaveTemplate template, String labelString, Mode mode, hudson.slaves.RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties ) throws Descriptor.FormException, IOException { super( name, nodeDescription, template.getRemoteFs(), template.getNumExecutors(), mode, labelString, new JNLPLauncher(), retentionStrategy, nodeProperties ); this.cloud = cloud; }
Example #5
Source File: DockerSimpleBuildWrapper.java From yet-another-docker-plugin with MIT License | 6 votes |
private DockerSlaveSingle getDockerSlaveSingleWithRetry(Run<?, ?> run, ProvisioningActivity.Id activityId, String futureName) throws IOException, Descriptor.FormException, InterruptedException { int retries = 6; while (retries >= 0) { try { return new DockerSlaveSingle(futureName, "Slave for " + run.getFullDisplayName(), getConfig(), getConnector(), activityId); } catch (IOException t) { if (retries <= 0) { throw t; } LOG.trace("Failed to create DockerSlaveSingle, retrying...", t); Thread.sleep(1000); } finally { retries--; } } throw new IllegalStateException("Max creation retries"); }
Example #6
Source File: TemplateDrivenMultiBranchProject.java From multi-branch-project-plugin with MIT License | 6 votes |
/** * Sets various implementation-specific fields and forwards wrapped req/rsp objects on to the * {@link #template}'s {@link AbstractProject#doConfigSubmit(StaplerRequest, StaplerResponse)} method. * <br> * {@inheritDoc} */ @Override public void submit(StaplerRequest req, StaplerResponse rsp) throws ServletException, Descriptor.FormException, IOException { super.submit(req, rsp); makeDisabled(req.getParameter("disable") != null); template.doConfigSubmit( new TemplateStaplerRequestWrapper(req), new TemplateStaplerResponseWrapper(req.getStapler(), rsp)); ItemListener.fireOnUpdated(this); // notify the queue as the project might be now tied to different node Jenkins.getActiveInstance().getQueue().scheduleMaintenance(); // this is to reflect the upstream build adjustments done above Jenkins.getActiveInstance().rebuildDependencyGraphAsync(); }
Example #7
Source File: ECSSlave.java From amazon-ecs-plugin with MIT License | 6 votes |
public ECSSlave(@Nonnull ECSCloud cloud, @Nonnull String name, ECSTaskTemplate template, @Nonnull ComputerLauncher launcher) throws Descriptor.FormException, IOException { super( name, "ECS Agent", template.makeRemoteFSRoot(name), 1, Mode.EXCLUSIVE, template.getLabel(), launcher, cloud.getRetainAgents() ? new CloudRetentionStrategy(cloud.getRetentionTimeout()) : new OnceRetentionStrategy(cloud.getRetentionTimeout()), Collections.emptyList() ); this.cloud = cloud; this.template = template; }
Example #8
Source File: RootElementConfigurator.java From configuration-as-code-plugin with MIT License | 6 votes |
static List<RootElementConfigurator> all() { final Jenkins jenkins = Jenkins.get(); List<RootElementConfigurator> configurators = new ArrayList<>( jenkins.getExtensionList(RootElementConfigurator.class)); for (GlobalConfigurationCategory category : GlobalConfigurationCategory.all()) { configurators.add(new GlobalConfigurationCategoryConfigurator(category)); } for (ManagementLink link : ManagementLink.all()) { final String name = link.getUrlName(); final Descriptor descriptor = Jenkins.get().getDescriptor(name); if (descriptor != null) configurators.add(new DescriptorConfigurator(descriptor)); } configurators.sort(Configurator.extensionOrdinalSort()); return configurators; }
Example #9
Source File: DotCiExtensionsHelper.java From DotCi with MIT License | 6 votes |
public <T extends DotCiExtension> T create(String pluginName, Object options, Class<T> extensionClass) { for (T adapter : all(extensionClass)) { if (adapter.getName().equals(pluginName)) { try { adapter = (T) adapter.getClass().newInstance(); } catch (Exception e) { throw new RuntimeException(e); } adapter.setOptions(options); return adapter; } } for (Descriptor<?> pluginDescriptor : getDescriptors()) { if (pluginDescriptor.clazz.getSimpleName().equals(pluginName)) { return (T) new GenericSimpleBuildStepPlugin(pluginDescriptor, options); } } throw new InvalidBuildConfigurationException("Plugin " + pluginName + " not supported"); }
Example #10
Source File: DockerTemplate.java From docker-plugin with MIT License | 6 votes |
@Restricted(NoExternalUse.class) public DockerTransientNode provisionNode(DockerAPI api, TaskListener listener) throws IOException, Descriptor.FormException, InterruptedException { try { final InspectImageResponse image = pullImage(api, listener); final String effectiveRemoteFsDir = getEffectiveRemoteFs(image); try(final DockerClient client = api.getClient()) { return doProvisionNode(api, client, effectiveRemoteFsDir, listener); } } catch (IOException | Descriptor.FormException | InterruptedException | RuntimeException ex) { final DockerCloud ourCloud = DockerCloud.findCloudForTemplate(this); final long milliseconds = ourCloud == null ? 0L : ourCloud.getEffectiveErrorDurationInMilliseconds(); if (milliseconds > 0L) { // if anything went wrong, disable ourselves for a while final String reason = "Template provisioning failed."; final DockerDisabled reasonForDisablement = getDisabled(); reasonForDisablement.disableBySystem(reason, milliseconds, ex); setDisabled(reasonForDisablement); } throw ex; } }
Example #11
Source File: DescribableAttribute.java From configuration-as-code-plugin with MIT License | 5 votes |
/** * Retrieve all possible symbols for this descriptor, first one being preferred one. * If a {@link Symbol} annotation is set, all values are accepted the last one being preferred */ public static List<String> getSymbols(Descriptor d, Class extensionPoint, Class target) { if (d != null) { List<String> symbols = new ArrayList<>(); // explicit @Symbol annotation on descriptor // first is the preferred one as by Symbol contract // "The first one is used as the primary identifier for reverse-mapping." Symbol s = d.getClass().getAnnotation(Symbol.class); if (s != null) { symbols.addAll(Arrays.asList(s.value())); } // extension type Foo is implemented as SomeFoo. => "some" final String ext = extensionPoint.getSimpleName(); final String cn = d.getKlass().toJavaClass().getSimpleName(); if (cn.endsWith(ext)) { symbols.add( normalize(cn.substring(0, cn.length() - ext.length())) ); } // extension type Foo is implemented as SomeFooImpl. => "some" final String in = extensionPoint.getSimpleName() + "Impl"; if (cn.endsWith(in)) { symbols.add( normalize(cn.substring(0, cn.length() - in.length())) ); } // Fall back to simple class name symbols.add( normalize(cn) ); return symbols; } // Fall back to simple class name return Collections.singletonList(normalize(target.getSimpleName())); }
Example #12
Source File: HeteroDescribableConfigurator.java From configuration-as-code-plugin with MIT License | 5 votes |
private Boolean findBySymbols(Descriptor<T> descriptor, String symbol, CNode node) { return getSymbols(descriptor) .find(actual -> actual.equalsIgnoreCase(symbol)) .map(actual -> { ObsoleteConfigurationMonitor.get().record(node, "'" + symbol + "' is obsolete, please use '" + preferredSymbol(descriptor) + "'"); return descriptorClass(descriptor); }).isDefined(); }
Example #13
Source File: DescribableAttribute.java From configuration-as-code-plugin with MIT License | 5 votes |
@Override public List<String> possibleValues() { final List<Descriptor> descriptors = Jenkins.get().getDescriptorList(type); return descriptors.stream() .map(d -> getPreferredSymbol(d, type, d.getKlass().toJavaClass())) .collect(Collectors.toList()); }
Example #14
Source File: GlobalConfigurationCategoryConfigurator.java From configuration-as-code-plugin with MIT License | 5 votes |
private boolean filterDescriptors(Descriptor d) { if (d.clazz.getName().equals(CREDENTIALS_PROVIDER_MANAGER_CONFIGURATION)) { // CREDENTIALS_PROVIDER_MANAGER_CONFIGURATION is located in the wrong category. // JCasC will also turn the simple name into empty string // It should be a part of the credentials root configurator node. return false; } else { return d.getCategory() == category && d.getGlobalConfigPage() != null; } }
Example #15
Source File: GlobalConfigurationCategoryConfigurator.java From configuration-as-code-plugin with MIT License | 5 votes |
private void describe(Descriptor d, Mapping mapping, ConfigurationContext context) { final DescriptorConfigurator c = new DescriptorConfigurator(d); try { final CNode node = c.describe(d, context); if (node != null) mapping.put(c.getName(), node); } catch (Exception e) { final Scalar scalar = new Scalar( "FAILED TO EXPORT\n" + d.getClass().getName() + " : " + printThrowable(e)); mapping.put(c.getName(), scalar); } }
Example #16
Source File: GlobalConfigurationCategoryConfigurator.java From configuration-as-code-plugin with MIT License | 5 votes |
@SuppressWarnings("RedundantCast") // TODO remove once we are on JDK 11 @NonNull @Override public Set describe() { return (Set) Jenkins.get().getExtensionList(Descriptor.class).stream() .filter(d -> d.getCategory() == category) .filter(d -> d.getGlobalConfigPage() != null) .map(DescriptorConfigurator::new) .filter(GlobalConfigurationCategoryConfigurator::reportDescriptorWithoutSetters) .map(c -> new Attribute<GlobalConfigurationCategory, Object>(c.getNames(), c.getTarget()).setter(NOP)) .collect(Collectors.toSet()); }
Example #17
Source File: DockerSlave.java From docker-plugin with MIT License | 5 votes |
@Override protected Object readResolve() { try { return new DockerTransientNode(containerId, containerId, dockerTemplate.remoteFs, getLauncher()); } catch (Descriptor.FormException | IOException e) { throw new RuntimeException("Failed to migrate DockerSlave", e); } }
Example #18
Source File: MattermostListener.java From jenkins-mattermost-plugin with MIT License | 5 votes |
@SuppressWarnings("unchecked") FineGrainedNotifier getNotifier(AbstractProject project, TaskListener listener) { Map<Descriptor<Publisher>, Publisher> map = project.getPublishersList().toMap(); for (Publisher publisher : map.values()) { if (publisher instanceof MattermostNotifier) { return new ActiveNotifier((MattermostNotifier) publisher, (BuildListener) listener, new JenkinsTokenExpander(listener)); } } return new DisabledNotifier(); }
Example #19
Source File: KubernetesCloud.java From kubernetes-plugin with Apache License 2.0 | 5 votes |
@SuppressWarnings({"rawtypes", "unused"}) // used by jelly public Descriptor getDefaultPodRetention() { Jenkins jenkins = Jenkins.getInstanceOrNull(); if (jenkins == null) { return null; } return jenkins.getDescriptor(PodRetention.getKubernetesCloudDefault().getClass()); }
Example #20
Source File: KubernetesSlave.java From kubernetes-plugin with Apache License 2.0 | 5 votes |
/** * @deprecated Use {@link Builder} instead. */ @Deprecated public KubernetesSlave(PodTemplate template, String nodeDescription, KubernetesCloud cloud, String labelStr, RetentionStrategy rs) throws Descriptor.FormException, IOException { this(template, nodeDescription, cloud.name, labelStr, rs); }
Example #21
Source File: MavenConfigurator.java From configuration-as-code-plugin with MIT License | 5 votes |
@NonNull @Override public Set<Attribute<GlobalMavenConfig,?>> describe() { final Set<Attribute<GlobalMavenConfig,?>> attributes = super.describe(); final Descriptor descriptor = Jenkins.get().getDescriptorOrDie(Maven.class); final Configurator<Descriptor> task = new DescriptorConfigurator(descriptor); for (Attribute attribute : task.describe()) { attributes.add(new Attribute<GlobalMavenConfig,Object>(attribute.getName(), attribute.getType()) .multiple(attribute.isMultiple()) .getter(g -> attribute.getValue(descriptor)) .setter((g,v) -> attribute.setValue(descriptor,v))); } return attributes; }
Example #22
Source File: KubernetesSlaveTest.java From kubernetes-plugin with Apache License 2.0 | 5 votes |
@Test public void testGetPodRetention() { try { List<KubernetesSlaveTestCase<PodRetention>> cases = Arrays.asList( createPodRetentionTestCase(new Never(), new Default(), new Default()), createPodRetentionTestCase(new Never(), new Always(), new Always()), createPodRetentionTestCase(new Never(), new OnFailure(), new OnFailure()), createPodRetentionTestCase(new Never(), new Never(), new Never()), createPodRetentionTestCase(new OnFailure(), new Default(), new Default()), createPodRetentionTestCase(new OnFailure(), new Always(), new Always()), createPodRetentionTestCase(new OnFailure(), new OnFailure(), new OnFailure()), createPodRetentionTestCase(new OnFailure(), new Never(), new Never()), createPodRetentionTestCase(new Always(), new Default(), new Default()), createPodRetentionTestCase(new Always(), new Always(), new Always()), createPodRetentionTestCase(new Always(), new OnFailure(), new OnFailure()), createPodRetentionTestCase(new Always(), new Never(), new Never()) ); KubernetesCloud cloud = new KubernetesCloud("test"); r.jenkins.clouds.add(cloud); for (KubernetesSlaveTestCase<PodRetention> testCase : cases) { cloud.setPodRetention(testCase.getCloudPodRetention()); KubernetesSlave testSlave = testCase.buildSubject(cloud); assertEquals(testCase.getExpectedResult(), testSlave.getPodRetention(cloud)); } } catch(IOException | Descriptor.FormException e) { fail(e.getMessage()); } }
Example #23
Source File: TouchStep.java From pipeline-utility-steps-plugin with MIT License | 5 votes |
@DataBoundConstructor public TouchStep(String file) throws Descriptor.FormException { if (StringUtils.isBlank(file)) { throw new Descriptor.FormException("can't be blank", "file"); } this.file = file; }
Example #24
Source File: FileSha1Step.java From pipeline-utility-steps-plugin with MIT License | 5 votes |
@DataBoundConstructor public FileSha1Step(String file) throws Descriptor.FormException { if (StringUtils.isBlank(file)) { throw new Descriptor.FormException("can't be blank", "file"); } this.file = file; }
Example #25
Source File: UnZipStep.java From pipeline-utility-steps-plugin with MIT License | 5 votes |
@DataBoundConstructor public UnZipStep(String zipFile) throws Descriptor.FormException { if (StringUtils.isBlank(zipFile)) { throw new Descriptor.FormException("Can not be empty", "zipFile"); } this.zipFile = zipFile; }
Example #26
Source File: ZipStep.java From pipeline-utility-steps-plugin with MIT License | 5 votes |
@DataBoundConstructor public ZipStep(String zipFile) throws Descriptor.FormException { if (StringUtils.isBlank(zipFile)) { throw new Descriptor.FormException("Can not be empty", "zipFile"); } this.zipFile = zipFile; }
Example #27
Source File: ExportedDescribableParameter.java From blueocean-plugin with MIT License | 5 votes |
@Exported public String getDescriptorUrl() { Descriptor<?> pd = Descriptor.findByDescribableClassName(ExtensionList.lookup(Descriptor.class), param.getErasedType().getName()); if (pd != null) { return pd.getDescriptorUrl(); } return null; }
Example #28
Source File: PipelineMetadataService.java From blueocean-plugin with MIT License | 5 votes |
private <T extends Describable<T>,D extends Descriptor<T>> void populateMetaSteps(List<Descriptor<?>> r, Class<T> c) { Jenkins j = Jenkins.getInstance(); for (Descriptor<?> d : j.getDescriptorList(c)) { if (SimpleBuildStep.class.isAssignableFrom(d.clazz) && symbolForObject(d) != null) { r.add(d); } else if (SimpleBuildWrapper.class.isAssignableFrom(d.clazz) && symbolForObject(d) != null) { r.add(d); } } }
Example #29
Source File: SbtParser.java From semantic-versioning-plugin with MIT License | 5 votes |
@SuppressWarnings("unchecked") public Descriptor<BuildDefinitionParser> getDescriptor() { return new AbstractSemanticParserDescription() { @Override public String getDisplayName() { return Messages.Parsers.SBT_BUILD_SBT_PARSER; } }; }
Example #30
Source File: MacroTest.java From office-365-connector-plugin with Apache License 2.0 | 5 votes |
@Test public void getDisplayName_ReturnsName() { // given Descriptor<Macro> descriptor = new Macro.DescriptorImpl(); // when String name = descriptor.getDisplayName(); // then assertThat(name).isEqualTo("Macro"); }