hudson.tools.ToolDescriptor Java Examples

The following examples show how to use hudson.tools.ToolDescriptor. 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: PipelineMetadataService.java    From blueocean-plugin with MIT License 5 votes vote down vote up
/**
 * Function to return all {@link ExportedToolDescriptor}s present in the system when accessed through the REST API,
 * pipeline scripts need: symbol and name to specify tools
 */
@GET
@TreeResponse
public ExportedToolDescriptor[] doToolMetadata() {
    List<ExportedToolDescriptor> models = new ArrayList<>();
    for (ToolDescriptor<? extends ToolInstallation> d : ToolInstallation.all()) {
        ExportedToolDescriptor descriptor = new ExportedToolDescriptor(d.getDisplayName(), symbolForObject(d), d.getClass());
        models.add(descriptor);
        for (ToolInstallation installation : d.getInstallations()) {
            descriptor.addInstallation(new ExportedToolDescriptor.ExportedToolInstallation(installation.getName(), installation.getClass()));
        }
    }
    return models.toArray(new ExportedToolDescriptor[models.size()]);
}
 
Example #2
Source File: ZAProxy.java    From zaproxy-plugin with MIT License 5 votes vote down vote up
/**
 * List model to choose the tool used (normally, it should be the ZAProxy tool).
 * 
 * @return a {@link ListBoxModel}
 */
public ListBoxModel doFillToolUsedItems() {
	ListBoxModel items = new ListBoxModel();
	for(ToolDescriptor<?> desc : ToolInstallation.all()) {
		for (ToolInstallation tool : desc.getInstallations()) {
			items.add(tool.getName());
		}
	}
	return items;
}
 
Example #3
Source File: GitTool.java    From git-client-plugin with MIT License 5 votes vote down vote up
/**
 * Return list of applicable GitTool descriptors.
 * @return list of applicable GitTool descriptors
 */
@SuppressWarnings("unchecked")
public List<ToolDescriptor<? extends GitTool>> getApplicableDescriptors() {
    List<ToolDescriptor<? extends GitTool>> r = new ArrayList<>();
    Jenkins jenkinsInstance = Jenkins.getInstance();
    for (ToolDescriptor<?> td : jenkinsInstance.<ToolInstallation,ToolDescriptor<?>>getDescriptorList(ToolInstallation.class)) {
        if (GitTool.class.isAssignableFrom(td.clazz)) { // This checks cast is allowed
            r.add((ToolDescriptor<? extends GitTool>)td); // This is the unchecked cast
        }
    }
    return r;
}
 
Example #4
Source File: GitToolTest.java    From git-client-plugin with MIT License 5 votes vote down vote up
@Test
public void testGetApplicableFromDescriptor() {
    GitTool.DescriptorImpl gitDescriptor = gitTool.getDescriptor();
    GitTool.DescriptorImpl jgitDescriptor = (new JGitTool()).getDescriptor();
    GitTool.DescriptorImpl jgitApacheDescriptor = (new JGitApacheTool()).getDescriptor();
    List<ToolDescriptor<? extends GitTool>> toolDescriptors = gitDescriptor.getApplicableDescriptors();
    assertThat(toolDescriptors, containsInAnyOrder(gitDescriptor, jgitDescriptor, jgitApacheDescriptor));
}
 
Example #5
Source File: JcascTest.java    From git-client-plugin with MIT License 4 votes vote down vote up
@Override
protected void assertConfiguredAsExpected(RestartableJenkinsRule restartableJenkinsRule, String s) {
    final ToolDescriptor descriptor = (ToolDescriptor) restartableJenkinsRule.j.jenkins.getDescriptor(GitTool.class);
    final ToolInstallation[] installations = descriptor.getInstallations();
    assertThat(installations, arrayWithSize(4));
    assertThat(installations, arrayContainingInAnyOrder(
            allOf(
                    instanceOf(JGitTool.class),
                    hasProperty("name", equalTo(JGitTool.MAGIC_EXENAME))
            ),
            allOf(
                    instanceOf(JGitApacheTool.class),
                    hasProperty("name", equalTo(JGitApacheTool.MAGIC_EXENAME))
            ),
            allOf(
                    instanceOf(GitTool.class),
                    not(instanceOf(JGitTool.class)),
                    not(instanceOf(JGitApacheTool.class)),
                    hasProperty("name", equalTo("Default")),
                    hasProperty("home", equalTo("git"))
            ),
            allOf(
                    instanceOf(GitTool.class),
                    not(instanceOf(JGitTool.class)),
                    not(instanceOf(JGitApacheTool.class)),
                    hasProperty("name", equalTo("optional")),
                    hasProperty("home", equalTo("/opt/git/git"))
            ))
    );
    final DescribableList<ToolProperty<?>, ToolPropertyDescriptor> properties = Arrays.stream(installations).filter(t -> t.getName().equals("optional")).findFirst().get().getProperties();
    assertThat(properties, iterableWithSize(1));
    final ToolProperty<?> property = properties.get(0);
    assertThat(property, instanceOf(InstallSourceProperty.class));
    assertThat(((InstallSourceProperty)property).installers,
            containsInAnyOrder(
                    allOf(
                            instanceOf(BatchCommandInstaller.class),
                            hasProperty("command", equalTo("echo \"got git\""))
                    ),
                    allOf(
                            instanceOf(ZipExtractionInstaller.class),
                            hasProperty("url", equalTo("file://some/path.zip"))
                    )
            )
    );
}
 
Example #6
Source File: GitTool.java    From git-client-plugin with MIT License 2 votes vote down vote up
/**
 * Misspelled method name. Please use #getApplicableDescriptors.
 * @return list of applicable GitTool descriptors
 * @deprecated
 */
@Deprecated
public List<ToolDescriptor<? extends GitTool>> getApplicableDesccriptors() {
    return getApplicableDescriptors();
}