From c3dd65e477f0860fd1e3bb5242d0e7b5794accc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Wed, 7 Feb 2024 13:21:44 +0100 Subject: [PATCH] Use the running environment if possible in API analysis --- .../tycho/apitools/ApiAnalysisMojo.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java index 9bf5b1041d..a38bc47726 100644 --- a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java +++ b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java @@ -308,7 +308,7 @@ private Collection getBaselineBundles() throws MojoFailureException { long start = System.currentTimeMillis(); Collection baselineBundles; try { - Collection targetEnvironments = projectManager.getTargetEnvironments(project); + Collection targetEnvironments = getBaselineEnvironments(); Optional artifactKey = projectManager.getArtifactKey(project); getLog().info("Resolve API baseline for " + project.getId() + " with " + targetEnvironments.stream().map(String::valueOf).collect(Collectors.joining(", "))); @@ -324,6 +324,26 @@ private Collection getBaselineBundles() throws MojoFailureException { return baselineBundles; } + /** + * This method selected the a target environment best suited for the current + * baseline, if it is a valid choice the running target is used (e.g. linux on + * linux host, windows on windows hosts and so on), if such environment is not + * available it is using the configured ones form the project as is. + * + * @return the chosen {@link TargetEnvironment}s + */ + private Collection getBaselineEnvironments() { + Collection targetEnvironments = projectManager.getTargetEnvironments(project); + TargetEnvironment runningEnvironment = TargetEnvironment.getRunningEnvironment(); + for (TargetEnvironment targetEnvironment : targetEnvironments) { + if (targetEnvironment.equals(runningEnvironment)) { + return List.of(targetEnvironment); + } + } + return targetEnvironments; + } + + private String time(long start) { long ms = System.currentTimeMillis() - start; if (ms < 1000) {