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-56312] Prevent adding splits with the wrong JDK #115

Merged
merged 4 commits into from
Feb 28, 2019
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -875,6 +876,8 @@ private void updateAllDependents(String parent, Plugin dependent, Map<String,Ver
/** Use JENKINS-47634 to load metadata from jenkins-core.jar if available. */
private void populateSplits(File war) throws IOException {
System.out.println("Checking " + war + " for plugin split metadata…");
System.out.println("Checking jdk version as splits may depend on a jdk version");
VersionNumber jdkVersion = new VersionNumber(config.getTestJavaVersion()); // From Java 9 onwards there is a standard for versions see JEP-223
try (JarFile jf = new JarFile(war, false)) {
Enumeration<JarEntry> warEntries = jf.entries();
while (warEntries.hasMoreElements()) {
Expand All @@ -887,6 +890,9 @@ private void populateSplits(File war) throws IOException {
while ((entry = jis.getNextJarEntry()) != null) {
if (entry.getName().equals("jenkins/split-plugins.txt")) {
splits = configLines(jis).collect(Collectors.toList());
// Since https://github.com/jenkinsci/jenkins/pull/3865 splits can depend on jdk version
// So make sure we are not applying splits not intended for our JDK
splits = removeSplitsBasedOnJDK(splits, jdkVersion);
System.out.println("found splits: " + splits);
found++;
} else if (entry.getName().equals("jenkins/split-plugin-cycles.txt")) {
Expand All @@ -909,6 +915,24 @@ private void populateSplits(File war) throws IOException {
}
throw new IOException("no jenkins-core-*.jar found in " + war);
}

private List<String> removeSplitsBasedOnJDK(List<String> splits, VersionNumber jdkVersion) {
List<String> filterSplits = new LinkedList();
for (String split : splits) {
String[] tokens = split.trim().split("\\s+");
if (tokens.length == 4 ) { // We have a jdk field in the splits file
if (jdkVersion.isNewerThan(new VersionNumber(tokens[3]))) {
raul-arabaolaza marked this conversation as resolved.
Show resolved Hide resolved
filterSplits.add(split);
} else {
System.out.println("Not adding " + split + "as split because jdk specified " + tokens[3] + " is newer than running jdk " + jdkVersion);
raul-arabaolaza marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
filterSplits.add(split);
}
}
return filterSplits;
}

// Matches syntax in ClassicPluginStrategy:
private static Stream<String> configLines(InputStream is) throws IOException {
return IOUtils.readLines(is, StandardCharsets.UTF_8).stream().filter(line -> !line.matches("#.*|\\s*"));
Expand Down