Skip to content

Commit 1dd9f9f

Browse files
Merge pull request #1669 from stuartwdouglas/better-plugin-version-mapping
Handle the case where versions are not compatible
2 parents ee68d21 + 5b4b9e4 commit 1dd9f9f

File tree

1 file changed

+65
-45
lines changed
  • java-components/build-request-processor/src/main/java/com/redhat/hacbs/container/analyser/build

1 file changed

+65
-45
lines changed

java-components/build-request-processor/src/main/java/com/redhat/hacbs/container/analyser/build/InvocationBuilder.java

Lines changed: 65 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,15 @@ public BuildInfo build(CacheBuildInfoLocator buildInfoLocator) {
198198
if (tool.getKey().contains(".")) {
199199
String toolSubstring = tool.getKey().substring(0, tool.getKey().lastIndexOf('.'));
200200
Optional<String> smallestVersion = e.getValue().keySet().stream()
201-
.filter(f -> f.matches("^" + toolSubstring + ".*"))
202-
.sorted()
203-
.findFirst();
201+
.filter(f -> f.matches("^" + toolSubstring + ".*"))
202+
.sorted()
203+
.findFirst();
204204
if (smallestVersion.isPresent()) {
205205
var smallestVersionEntry = e.getValue().get(smallestVersion.get()).getReleaseDate();
206206
if (!tool.getKey().equals(smallestVersion.get())) {
207207
Log.infof("Overriding release date for %s from %s to %s (from %s)",
208-
tool.getKey(), tool.getValue().getReleaseDate(), smallestVersionEntry, smallestVersion.get());
208+
tool.getKey(), tool.getValue().getReleaseDate(), smallestVersionEntry,
209+
smallestVersion.get());
209210
tool.getValue().setReleaseDate(smallestVersionEntry);
210211
}
211212
}
@@ -305,6 +306,22 @@ public BuildInfo build(CacheBuildInfoLocator buildInfoLocator) {
305306
}
306307
}
307308
}
309+
//make sure that we don't end up with an empty list when combining with Java versions
310+
boolean ok = false;
311+
Set<String> versions = selectedToolVersions.get(tool);
312+
if (versions != null) {
313+
for (var i : versions) {
314+
for (var java : javaVersions) {
315+
ok |= isToolCompatibleWithJavaVersion(java, tool, i, buildToolInfo);
316+
}
317+
if (ok) {
318+
break;
319+
}
320+
}
321+
}
322+
if (versions == null || !ok) {
323+
selectedToolVersions.put(tool, new LinkedHashSet<>(toolVersions));
324+
}
308325
}
309326
if (!selectedToolVersions.containsKey(BuildInfo.MAVEN)) {
310327
//we always add a maven version
@@ -357,53 +374,37 @@ public BuildInfo build(CacheBuildInfoLocator buildInfoLocator) {
357374
for (var invocationSet : toolInvocations.entrySet()) {
358375
for (var perm : allToolPermutations) {
359376
for (var javaVersion : javaVersions) {
360-
boolean ignore = false;
361-
var tv = perm.get(invocationSet.getKey());
362-
var info = buildToolInfo.get(invocationSet.getKey());
363-
if (info != null) {
364-
var toolInfo = info.get(tv);
365-
if (toolInfo != null) {
366-
if (toolInfo.getMaxJdkVersion() != null && new JavaVersion(toolInfo.getMaxJdkVersion())
367-
.intVersion() < javaVersion.intVersion()) {
368-
ignore = true;
369-
} else if (toolInfo.getMinJdkVersion() != null
370-
&& new JavaVersion(toolInfo.getMinJdkVersion()).intVersion() > javaVersion
371-
.intVersion()) {
372-
ignore = true;
373-
}
374-
}
377+
String tool = invocationSet.getKey();
378+
if (isToolCompatibleWithJavaVersion( javaVersion, tool, perm.get(tool), buildToolInfo)) {
379+
for (var invocation : invocationSet.getValue()) {
380+
Invocation result = new Invocation();
381+
Map<String, String> toolVersion = new HashMap<>(perm);
382+
toolVersion.put(BuildInfo.JDK, javaVersion.version());
375383

376-
if (!ignore) {
377-
for (var invocation : invocationSet.getValue()) {
378-
Invocation result = new Invocation();
379-
Map<String, String> toolVersion = new HashMap<>(perm);
380-
toolVersion.put(BuildInfo.JDK, javaVersion.version());
381-
382-
result.setToolVersion(toolVersion);
383-
String tool = invocationSet.getKey();
384-
if (tool.equals(BuildInfo.MAVEN)) {
385-
//huge hack, we need a different invocation for different java versions
386-
//Note - according to https://github.com/apache/maven-deploy-plugin/releases
387-
// the deploy plugin >= 3.1 is JDK8 only.
388-
List<String> cmds = new ArrayList<>(invocation);
389-
if (javaVersion.intVersion() < 8) {
390-
cmds.add("org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy");
391-
} else {
392-
cmds.add("org.apache.maven.plugins:maven-deploy-plugin:3.1.1:deploy");
393-
}
394-
result.setCommands(cmds);
384+
result.setToolVersion(toolVersion);
385+
if (tool.equals(BuildInfo.MAVEN)) {
386+
//huge hack, we need a different invocation for different java versions
387+
//Note - according to https://github.com/apache/maven-deploy-plugin/releases
388+
// the deploy plugin >= 3.1 is JDK8 only.
389+
List<String> cmds = new ArrayList<>(invocation);
390+
if (javaVersion.intVersion() < 8) {
391+
cmds.add("org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy");
395392
} else {
396-
result.setCommands(invocation);
393+
cmds.add("org.apache.maven.plugins:maven-deploy-plugin:3.1.1:deploy");
397394
}
398-
result.setTool(tool);
399-
result.setDisabledPlugins(
400-
buildRecipeInfo != null && buildRecipeInfo.getDisabledPlugins() != null
401-
? buildRecipeInfo.getDisabledPlugins()
402-
: buildInfoLocator.lookupDisabledPlugins(tool));
403-
this.info.invocations.add(result);
395+
result.setCommands(cmds);
396+
} else {
397+
result.setCommands(invocation);
404398
}
399+
result.setTool(tool);
400+
result.setDisabledPlugins(
401+
buildRecipeInfo != null && buildRecipeInfo.getDisabledPlugins() != null
402+
? buildRecipeInfo.getDisabledPlugins()
403+
: buildInfoLocator.lookupDisabledPlugins(tool));
404+
this.info.invocations.add(result);
405405
}
406406
}
407+
407408
}
408409
}
409410
}
@@ -416,6 +417,25 @@ && new JavaVersion(toolInfo.getMinJdkVersion()).intVersion() > javaVersion
416417
return info;
417418
}
418419

420+
private static boolean isToolCompatibleWithJavaVersion( JavaVersion javaVersion, String tool,String toolVersion, Map<String, Map<String, BuildToolInfo>> buildToolInfo) {
421+
var info = buildToolInfo.get(tool);
422+
boolean problem = false;
423+
if (info != null) {
424+
var toolInfo = info.get(toolVersion);
425+
if (toolInfo != null) {
426+
if (toolInfo.getMaxJdkVersion() != null && new JavaVersion(toolInfo.getMaxJdkVersion())
427+
.intVersion() < javaVersion.intVersion()) {
428+
problem = true;
429+
} else if (toolInfo.getMinJdkVersion() != null
430+
&& new JavaVersion(toolInfo.getMinJdkVersion()).intVersion() > javaVersion
431+
.intVersion()) {
432+
problem = true;
433+
}
434+
}
435+
}
436+
return !problem;
437+
}
438+
419439
static Set<String> findClosestVersions(List<String> toolVersions, String discovered) {
420440
if (toolVersions.contains(discovered)) {
421441
return Set.of(discovered);

0 commit comments

Comments
 (0)