Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-73282] Run PCT with a Jetty 12 EE 8 test harness when core is Jetty 12 EE 8 #675

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do nothing if Winstone is Jetty 10 …

}
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

… but otherwise invoke the logic in the superclass, which dynamically updates jenkins-test-harness.version to 2230.v4fa_477b_634f4, but only if the current value of the version is older (newer values don't need to be overridden).

}

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
}
}
}