hudson.model.Describable#hudson.model.Descriptor源码实例Demo

下面列出了hudson.model.Describable#hudson.model.Descriptor 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: yet-another-docker-plugin   文件: DockerSlave.java
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;
}
 
源代码2 项目: yet-another-docker-plugin   文件: DockerCloud.java
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");
}
 
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;
}
 
源代码4 项目: docker-plugin   文件: DockerTemplate.java
@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;
    }
}
 
源代码5 项目: DotCi   文件: DotCiExtensionsHelper.java
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");
}
 
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");
}
 
源代码7 项目: amazon-ecs-plugin   文件: ECSSlave.java
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;
}
 
源代码8 项目: jenkins-nomad   文件: NomadSlave.java
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;
}
 
@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());
}
 
/**
 * 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();
}
 
@SuppressWarnings("unchecked")
public Descriptor<BuildDefinitionParser> getDescriptor() {
	return new AbstractSemanticParserDescription() {

		@Override
		public String getDisplayName() {

			return Messages.Parsers.COMPOSER_JSON_PARSER;
		}
	};
}
 
源代码12 项目: kubernetes-plugin   文件: KubernetesSlave.java
/**
 * @deprecated Use {@link Builder} instead.
 */
@Deprecated
@DataBoundConstructor // make stapler happy. Not actually used.
public KubernetesSlave(PodTemplate template, String nodeDescription, String cloudName, String labelStr,
                       RetentionStrategy rs)
        throws Descriptor.FormException, IOException {
    this(getSlaveName(template), template, nodeDescription, cloudName, labelStr, new KubernetesLauncher(), rs);
}
 
/**
 * Only this plugin specific strategies.
 */
public static List<Descriptor<RetentionStrategy<?>>> getDockerRetentionStrategyDescriptors() {
    List<Descriptor<RetentionStrategy<?>>> strategies = new ArrayList<>();

    strategies.add(getInstance().getDescriptor(DockerOnceRetentionStrategy.class));
    strategies.add(getInstance().getDescriptor(DockerCloudRetentionStrategy.class));
    strategies.add(getInstance().getDescriptor(DockerComputerIOLauncher.class));

    return strategies;
}
 
@Test
public void testAgentInitWithCloudOfNullArguments() throws Descriptor.FormException, IOException {
    final KafkaKubernetesCloud cloud = new KafkaKubernetesCloud("kafka-kubernetes");
    cloud.setDescription(null);
    cloud.setWorkingDir(null);
    cloud.setNodeUsageMode(null);
    cloud.setIdleMinutes(null);
    cloud.setLabel(null);
    cloud.setNodeProperties(null);
    new KafkaCloudSlave(cloud);
}
 
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();
}
 
源代码16 项目: docker-plugin   文件: DockerTransientNode.java
public DockerTransientNode(@Nonnull String nodeName, String containerId, String workdir, ComputerLauncher launcher) throws Descriptor.FormException, IOException {
    super(nodeName, workdir, launcher);
    this.containerId = containerId;
    setNumExecutors(1);
    setMode(Mode.EXCLUSIVE);
    setRetentionStrategy(new DockerOnceRetentionStrategy(10));
}
 
源代码17 项目: junit-plugin   文件: JUnitResultArchiver.java
@Deprecated
public JUnitResultArchiver(
        String testResults,
        boolean keepLongStdio,
        DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers,
        double healthScaleFactor) {
    this.testResults = testResults;
    setKeepLongStdio(keepLongStdio);
    setTestDataPublishers(testDataPublishers == null ? Collections.<TestDataPublisher>emptyList() : testDataPublishers);
    setHealthScaleFactor(healthScaleFactor);
    setAllowEmptyResults(false);
}
 
public Descriptor<NamingStrategy> getDescriptor() {
	return new AbstractSemanticParserDescription() {
		
		@Override
		public String getDisplayName() {
			
			return Messages.NamingStrategies.MAVEN_RELEASE_DEVELOPMENT;
		}
	};
}
 
/**
 * Only this plugin specific launchers.
 */
public static List<Descriptor<ComputerLauncher>> getDockerComputerLauncherDescriptors() {
    List<Descriptor<ComputerLauncher>> launchers = new ArrayList<>();

    launchers.add(getInstance().getDescriptor(DockerComputerSSHLauncher.class));
    launchers.add(getInstance().getDescriptor(DockerComputerJNLPLauncher.class));
    launchers.add(getInstance().getDescriptor(DockerComputerIOLauncher.class));

    return launchers;
}
 
@NonNull
public Class getImplementedAPI() {

    final Descriptor descriptor = getDescriptor();
    if (descriptor != null) {
        // traverse Descriptor's class hierarchy until we found "extends Descriptor<ExtensionPoint>"
        Class c = descriptor.getClass();
        Type superclass;
        do {
            superclass = c.getGenericSuperclass();
            c = c.getSuperclass();
        } while (c != Descriptor.class);


        if (superclass instanceof ParameterizedType) {
            final ParameterizedType genericSuperclass = (ParameterizedType) superclass;
            Type type = genericSuperclass.getActualTypeArguments()[0];
            if (type instanceof ParameterizedType) {
                type = ((ParameterizedType) type).getRawType();
            }
            if (type instanceof Class) {
                return (Class) type;
            }
        }
    }
    return super.getImplementedAPI();
}
 
@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());
}
 
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);
    }
}
 
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;
    }
}
 
@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());
}
 
/**
 * 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()));

}
 
@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;
}
 
源代码27 项目: kubernetes-plugin   文件: KubernetesSlaveTest.java
@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());
    }
}
 
@Exported
public String getDescriptorUrl() {
    Descriptor<?> pd = Descriptor.findByDescribableClassName(ExtensionList.lookup(Descriptor.class),
            param.getErasedType().getName());

    if (pd != null) {
        return pd.getDescriptorUrl();
    }

    return null;
}
 
源代码29 项目: blueocean-plugin   文件: PipelineMetadataService.java
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);
        }
    }
}
 
源代码30 项目: semantic-versioning-plugin   文件: SbtParser.java
@SuppressWarnings("unchecked")
public Descriptor<BuildDefinitionParser> getDescriptor() {
	return new AbstractSemanticParserDescription() {
		
		@Override
		public String getDisplayName() {
			
			return Messages.Parsers.SBT_BUILD_SBT_PARSER;
		}
	};
}