Skip to content

Commit

Permalink
JENKINS-71949 : restore Java 6/7/8 compatibility (#703)
Browse files Browse the repository at this point in the history
* restore 8 compilation

Signed-off-by: Olivier Lamy <[email protected]>

* Add test to be sure it works with jdk8, build on a remote node using jdk8

Signed-off-by: Olivier Lamy <[email protected]>

* test for multiple jdks

Signed-off-by: Olivier Lamy <[email protected]>

* add Issue annotation

Signed-off-by: Olivier Lamy <[email protected]>

* add some debug for ci.jenkins.io

Signed-off-by: Olivier Lamy <[email protected]>

* force file permission in the container

Signed-off-by: Olivier Lamy <[email protected]>

* remove ls debug

Signed-off-by: Olivier Lamy <[email protected]>

* back to 6 as it looks important to have different lines in a release notes saying the opposite....

Signed-off-by: Olivier Lamy <[email protected]>

---------

Signed-off-by: Olivier Lamy <[email protected]>
  • Loading branch information
olamy authored Sep 13, 2023
1 parent 003efaf commit 36ca27d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,25 @@
package org.jenkinsci.plugins.pipeline.maven;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.params.provider.Arguments.arguments;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.stream.Stream;

import hudson.model.JDK;
import hudson.tools.ToolLocationNodeProperty;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.jvnet.hudson.test.Issue;
import org.testcontainers.containers.GenericContainer;

Expand All @@ -49,6 +58,7 @@
import hudson.plugins.sshslaves.SSHLauncher;
import hudson.slaves.DumbSlave;
import hudson.slaves.RetentionStrategy;
import org.testcontainers.utility.MountableFile;

public class WithMavenStepTest extends AbstractIntegrationTest {

Expand Down Expand Up @@ -96,6 +106,46 @@ public void testDisableAllPublishers() throws Exception {
assertFingerprintDoesNotExist(COMMONS_LANG3_FINGERPRINT);
}

// the jdk path is configured in Dockerfile
private static Stream<Arguments> jdkMapProvider() {
return Stream.of(
arguments("jdk8", "/opt/java/jdk8"),
arguments("jdk11", "/opt/java/jdk11")
);
}

@ParameterizedTest
@MethodSource("jdkMapProvider")
@Issue("JENKINS-71949")
public void tesWithDifferentJavasForBuild(String jdkName, String jdkPath) throws Exception {
loadMonoDependencyMavenProjectInGitRepo(this.gitRepoRule);
String gitRepoPath = this.gitRepoRule.toString();
javaGitContainerRule.copyFileToContainer(MountableFile.forHostPath(gitRepoPath), "/tmp/gitrepo");
javaGitContainerRule.execInContainer("chmod", "-R", "777", "/tmp/gitrepo");
registerAgentForContainer(javaGitContainerRule);
ToolLocationNodeProperty.ToolLocation toolLocation =
new ToolLocationNodeProperty.ToolLocation(new JDK.DescriptorImpl(), jdkName, jdkPath);
ToolLocationNodeProperty toolLocationNodeProperty = new ToolLocationNodeProperty(toolLocation);
Objects.requireNonNull(jenkinsRule.jenkins.getNode(AGENT_NAME)).getNodeProperties().add(toolLocationNodeProperty);

jenkinsRule.jenkins.getJDKs().add(new JDK(jdkName, jdkPath));

//@formatter:off
WorkflowRun run = runPipeline(Result.SUCCESS,
"node('" + AGENT_NAME + "') {\n" +
" git('/tmp/gitrepo')\n" +
" withMaven(jdk: '" + jdkName + "') {\n" +
" sh 'mvn package'\n" +
" }\n" +
"}");
//@formatter:on
jenkinsRule.assertLogContains("artifactsPublisher - Archive artifact target/mono-dependency-maven-project-0.1-SNAPSHOT.jar", run);

Collection<String> archives = run.pickArtifactManager().root().list("**/**.jar", "", true);
assertThat(archives).hasSize(1);
assertThat(archives.iterator().next().endsWith("mono-dependency-maven-project-0.1-SNAPSHOT.jar")).isTrue();
}

private WorkflowRun runPipeline(Result expectedResult, String pipelineScript) throws Exception {
WorkflowJob p = jenkinsRule.createProject(WorkflowJob.class, "project");
p.setDefinition(new CpsFlowDefinition(pipelineScript, true));
Expand Down Expand Up @@ -126,7 +176,6 @@ private void registerAgentForSlaveContainer(GenericContainer<?> slaveContainer)
DumbSlave agent = new DumbSlave(AGENT_NAME, SLAVE_BASE_PATH, sshLauncher);
agent.setNumExecutors(1);
agent.setRetentionStrategy(RetentionStrategy.INSTANCE);

jenkinsRule.jenkins.addNode(agent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8

COPY --from=eclipse-temurin:8u345-b01-jdk /opt/java/openjdk /opt/java/jdk8
COPY --from=eclipse-temurin:11.0.16.1_1-jdk /opt/java/openjdk /opt/java/jdk11

# run SSHD in the foreground with error messages to stderr
ENTRYPOINT ["/usr/sbin/sshd", "-D", "-e"]

3 changes: 1 addition & 2 deletions maven-spy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<release>6</release>
</configuration>
</plugin>
<plugin>
Expand Down

0 comments on commit 36ca27d

Please sign in to comment.