Skip to content

Commit

Permalink
[JENKINS-73282] Run PCT with a Jetty 12 EE 8 test harness when core i…
Browse files Browse the repository at this point in the history
…s Jetty 12 EE 8 (#675)
  • Loading branch information
basil committed Jun 21, 2024
1 parent 13c80ee commit 58221e0
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.jenkins.tools.test.hook;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.util.VersionNumber;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import org.jenkins.tools.test.model.hook.BeforeExecutionContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeExecution;
import org.kohsuke.MetaInfServices;

/**
* Ensure that if the core is on Jetty 12, that the test harness is on Jetty 12 as well.
*/
@MetaInfServices(PluginCompatTesterHookBeforeExecution.class)
public class Jetty12Hook extends PropertyVersionHook {

@Override
public String getProperty() {
return "jenkins-test-harness.version";
}

@Override
public String getMinimumVersion() {
return "2230.v4fa_477b_634f4";

Check warning on line 31 in src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 26-31 are not covered by tests
}

@Override
public boolean check(@NonNull BeforeExecutionContext context) {
VersionNumber winstoneVersion = getWinstoneVersion(context.getConfig().getWar());
if (winstoneVersion.getDigitAt(0) < 7) {

Check warning on line 37 in src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 37 is only partially covered, one branch is missing
return false;
}
return super.check(context);

Check warning on line 40 in src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 40 is not covered by tests
}

private VersionNumber getWinstoneVersion(File war) {
try (JarFile jarFile = new JarFile(war)) {
ZipEntry zipEntry = jarFile.getEntry("executable/winstone.jar");
if (zipEntry == null) {

Check warning on line 46 in src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 46 is only partially covered, one branch is missing
throw new IllegalArgumentException("Failed to find winstone.jar in " + war);

Check warning on line 47 in src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 47 is not covered by tests
}
try (InputStream is = jarFile.getInputStream(zipEntry);
BufferedInputStream bis = new BufferedInputStream(is);
JarInputStream jis = new JarInputStream(bis)) {
Manifest manifest = jis.getManifest();
if (manifest == null) {

Check warning on line 53 in src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 53 is only partially covered, one branch is missing
throw new IllegalArgumentException("Failed to read manifest in " + war);

Check warning on line 54 in src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 54 is not covered by tests
}
String version = manifest.getMainAttributes().getValue("Implementation-Version");
if (version == null) {

Check warning on line 57 in src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 57 is only partially covered, one branch is missing
throw new IllegalArgumentException("Failed to read Winstone version from manifest in " + war);

Check warning on line 58 in src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 58 is not covered by tests
}
return new VersionNumber(version);
}
} catch (IOException e) {
throw new UncheckedIOException("Failed to read Winstone version in " + war, e);

Check warning on line 63 in src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 62-63 are not covered by tests
}
}
}

0 comments on commit 58221e0

Please sign in to comment.