hudson.tools.ToolInstallation Java Examples

The following examples show how to use hudson.tools.ToolInstallation. 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: GitToolConfiguratorJenkinsRuleTest.java    From git-client-plugin with MIT License 6 votes vote down vote up
@Test
public void testDescribeGitToolEmptyProperties() throws Exception {
    String gitName = "git-2.19.1-name";
    String gitHome = "/opt/git-2.19.1/bin/git";

    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);

    // Intentionally empty properties passed to GitTool constructor
    List<ToolProperty<ToolInstallation>> gitToolProperties = new ArrayList<>();

    GitTool gitTool = new GitTool(gitName, gitHome, gitToolProperties);

    CNode cNode = gitToolConfigurator.describe(gitTool, context);

    assertThat(cNode, is(notNullValue()));
    assertThat(cNode.getType(), is(CNode.Type.MAPPING));
    Mapping cNodeMapping = cNode.asMapping();
    assertThat(cNodeMapping.getScalarValue("name"), is(gitName));
    assertThat(cNodeMapping.getScalarValue("home"), is(gitHome));
}
 
Example #2
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 #3
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 #4
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 #5
Source File: GitToolConfiguratorJenkinsRuleTest.java    From git-client-plugin with MIT License 5 votes vote down vote up
@Test
public void testDescribeGitTool() throws Exception {
    String gitName = "git-2.19.1-name";
    String gitHome = "/opt/git-2.19.1/bin/git";

    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);

    List<ToolProperty<ToolInstallation>> gitToolProperties = new ArrayList<>();
    List<ToolInstaller> toolInstallers = new ArrayList<>();
    ToolInstaller toolInstaller = new ZipExtractionInstaller("tool-label", "tool-url", "tool-subdir");
    toolInstallers.add(toolInstaller);
    InstallSourceProperty installSourceProperty = new InstallSourceProperty(toolInstallers);
    gitToolProperties.add(installSourceProperty);

    GitTool gitTool = new GitTool(gitName, gitHome, gitToolProperties);

    CNode cNode = gitToolConfigurator.describe(gitTool, context);

    assertThat(cNode, is(notNullValue()));
    assertThat(cNode.getType(), is(CNode.Type.MAPPING));
    Mapping cNodeMapping = cNode.asMapping();
    assertThat(cNodeMapping.getScalarValue("name"), is(gitName));
    assertThat(cNodeMapping.getScalarValue("home"), is(gitHome));

    //         properties:
    //          - installSource:
    //              installers:
    //                - zip:
    //                    label: "tool-label"
    //                    subdir: "tool-subdir"
    //                    url: "tool-url"
    Sequence propertiesSequence = cNodeMapping.get("properties").asSequence();                             // properties:
    Mapping installSourceMapping = propertiesSequence.get(0).asMapping().get("installSource").asMapping(); //  - installSource:
    Sequence installersSequence = installSourceMapping.get("installers").asSequence();                     //      installers:
    Mapping zipMapping = installersSequence.get(0).asMapping().get("zip").asMapping();                     //        - zip:
    assertThat(zipMapping.getScalarValue("label"), is("tool-label"));
    assertThat(zipMapping.getScalarValue("subdir"), is("tool-subdir"));
    assertThat(zipMapping.getScalarValue("url"), is("tool-url"));
}
 
Example #6
Source File: DockerToolInstaller.java    From docker-commons-plugin with MIT License 4 votes vote down vote up
@Override
public boolean isApplicable(Class<? extends ToolInstallation> toolType) {
    return toolType == DockerTool.class;
}
 
Example #7
Source File: PackerInstaller.java    From packer-plugin with MIT License 4 votes vote down vote up
public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log)
        throws IOException, InterruptedException {
    LOGGER.info("Performing Install");
    return super.performInstallation(tool, node, log);
}
 
Example #8
Source File: PackerInstaller.java    From packer-plugin with MIT License 4 votes vote down vote up
@Override
public boolean isApplicable(Class<? extends ToolInstallation> toolType) {
    return toolType == PackerInstallation.class;
}
 
Example #9
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"))
                    )
            )
    );
}