hudson.model.JDK Java Examples

The following examples show how to use hudson.model.JDK. 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: JdkConfiguratorTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
public void configure_jdk_tool() {
    final JDK.DescriptorImpl descriptor = ExtensionList.lookupSingleton(JDK.DescriptorImpl.class);
    assertEquals(1, descriptor.getInstallations().length);

    JDK jdk = descriptor.getInstallations()[0];
    assertEquals("jdk8", jdk.getName());
    assertEquals("/jdk", jdk.getHome());

    InstallSourceProperty installSourceProperty = jdk.getProperties().get(InstallSourceProperty.class);
    assertEquals(1, installSourceProperty.installers.size());

    JDKInstaller installer = installSourceProperty.installers.get(JDKInstaller.class);
    assertEquals("jdk-8u181-oth-JPR", installer.id);
    assertTrue(installer.acceptLicense);
}
 
Example #2
Source File: PipelineMetadataServiceTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void toolMetadata() throws Exception {
    PipelineMetadataService svc = new PipelineMetadataService();

    List<ExportedToolDescriptor> tools = new ArrayList<>();
    tools.addAll(Arrays.asList(svc.doToolMetadata()));

    assertFalse(tools.isEmpty());

    ExportedToolDescriptor t = null;

    for (ExportedToolDescriptor a : tools) {
        if (a.getType().equals(JDK.DescriptorImpl.class.getName())) {
            t = a;
        }
    }

    assertNotNull(t);

    assertEquals("jdk", t.getSymbol());
}
 
Example #3
Source File: WithMavenStepExecution2.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
/**
 * Setup the selected JDK. If none is provided nothing is done.
 */
private void setupJDK() throws AbortException, IOException, InterruptedException {
    String jdkInstallationName = step.getJdk();
    if (StringUtils.isEmpty(jdkInstallationName)) {
        console.println("[withMaven] using JDK installation provided by the build agent");
        return;
    }

    if (withContainer) {
        // see #detectWithContainer()
        LOGGER.log(Level.FINE, "Ignoring JDK installation parameter: {0}", jdkInstallationName);
        console.println("WARNING: \"withMaven(){...}\" step running within a container," +
                " tool installations are not available see https://issues.jenkins-ci.org/browse/JENKINS-36159. " +
                "You have specified a JDK installation \"" + jdkInstallationName + "\", which will be ignored.");
        return;
    }

    console.println("[withMaven] using JDK installation " + jdkInstallationName);

    JDK jdk = Jenkins.getInstance().getJDK(jdkInstallationName);
    if (jdk == null) {
        throw new AbortException("Could not find the JDK installation: " + jdkInstallationName + ". Make sure it is configured on the Global Tool Configuration page");
    }
    Node node = getComputer().getNode();
    if (node == null) {
        throw new AbortException("Could not obtain the Node for the computer: " + getComputer().getName());
    }
    jdk = jdk.forNode(node, listener).forEnvironment(env);
    jdk.buildEnvVars(envOverride);

}
 
Example #4
Source File: WithMavenStep.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
@Restricted(NoExternalUse.class) // Only for UI calls
public ListBoxModel doFillJdkItems() {
    ListBoxModel r = new ListBoxModel();
    r.add("--- Use system default JDK ---",null);
    for (JDK installation : getJDKDescriptor().getInstallations()) {
        r.add(installation.getName());
    }
    return r;
}
 
Example #5
Source File: JenkinsRule.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Configures a Jenkins instance for test.
 *
 * @param jenkins jenkins instance which has to be configured
 * @throws Exception if unable to configure
 * @since 2.50
 */
public static void _configureJenkinsForTest(Jenkins jenkins) throws Exception {
    jenkins.setNoUsageStatistics(true); // collecting usage stats from tests is pointless.
    jenkins.servletContext.setAttribute("app", jenkins);
    jenkins.servletContext.setAttribute("version", "?");
    WebAppMain.installExpressionFactory(new ServletContextEvent(jenkins.servletContext));

    // set a default JDK to be the one that the harness is using.
    jenkins.getJDKs().add(new JDK("default", System.getProperty("java.home")));
}
 
Example #6
Source File: ZAProxy.java    From zaproxy-plugin with MIT License 5 votes vote down vote up
/**
 * Set the JDK to use to start ZAP.
 * 
 * @param build
 * @param listener the listener to display log during the job execution in jenkins
 * @param env list of environment variables. Used to set the path to the JDK
 * @throws IOException
 * @throws InterruptedException
 */
private void computeJdkToUse(AbstractBuild<?, ?> build,
		BuildListener listener, EnvVars env) throws IOException, InterruptedException {
	JDK jdkToUse = getJdkToUse(build.getProject());
	if (jdkToUse != null) {
		Computer computer = Computer.currentComputer();
		// just in case we are not in a build
		if (computer != null) {
			jdkToUse = jdkToUse.forNode(computer.getNode(), listener);
		}
		jdkToUse.buildEnvVars(env);
	}
}
 
Example #7
Source File: ZAProxy.java    From zaproxy-plugin with MIT License 5 votes vote down vote up
/**
 * @return JDK to be used with this project.
 */
private JDK getJdkToUse(AbstractProject<?, ?> project) {
	JDK jdkToUse = getJDK();
	if (jdkToUse == null) {
		jdkToUse = project.getJDK();
	}
	return jdkToUse;
}
 
Example #8
Source File: WithMavenStep.java    From pipeline-maven-plugin with MIT License 4 votes vote down vote up
private JDK.DescriptorImpl getJDKDescriptor() {
    return Jenkins.getInstance().getDescriptorByType(JDK.DescriptorImpl.class);
}
 
Example #9
Source File: ZAProxy.java    From zaproxy-plugin with MIT License 4 votes vote down vote up
/**
 * Gets the JDK that this Sonar builder is configured with, or null.
 */
public JDK getJDK() {
	return Jenkins.getInstance().getJDK(jdk);
}