-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-73282] Run PCT with a Jetty 12 EE 8 test harness when core i…
…s Jetty 12 EE 8 (#675)
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
|
||
@Override | ||
public boolean check(@NonNull BeforeExecutionContext context) { | ||
VersionNumber winstoneVersion = getWinstoneVersion(context.getConfig().getWar()); | ||
if (winstoneVersion.getDigitAt(0) < 7) { | ||
return false; | ||
} | ||
return super.check(context); | ||
} | ||
|
||
private VersionNumber getWinstoneVersion(File war) { | ||
try (JarFile jarFile = new JarFile(war)) { | ||
ZipEntry zipEntry = jarFile.getEntry("executable/winstone.jar"); | ||
if (zipEntry == null) { | ||
throw new IllegalArgumentException("Failed to find winstone.jar in " + war); | ||
} | ||
try (InputStream is = jarFile.getInputStream(zipEntry); | ||
BufferedInputStream bis = new BufferedInputStream(is); | ||
JarInputStream jis = new JarInputStream(bis)) { | ||
Manifest manifest = jis.getManifest(); | ||
if (manifest == null) { | ||
throw new IllegalArgumentException("Failed to read manifest in " + war); | ||
} | ||
String version = manifest.getMainAttributes().getValue("Implementation-Version"); | ||
if (version == null) { | ||
throw new IllegalArgumentException("Failed to read Winstone version from manifest in " + war); | ||
} | ||
return new VersionNumber(version); | ||
} | ||
} catch (IOException e) { | ||
throw new UncheckedIOException("Failed to read Winstone version in " + war, e); | ||
} | ||
} | ||
} |