Skip to content

Commit

Permalink
Use the running environment if possible in API analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Feb 7, 2024
1 parent 503b268 commit c3dd65e
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private Collection<Path> getBaselineBundles() throws MojoFailureException {
long start = System.currentTimeMillis();
Collection<Path> baselineBundles;
try {
Collection<TargetEnvironment> targetEnvironments = projectManager.getTargetEnvironments(project);
Collection<TargetEnvironment> targetEnvironments = getBaselineEnvironments();
Optional<ArtifactKey> artifactKey = projectManager.getArtifactKey(project);
getLog().info("Resolve API baseline for " + project.getId() + " with "
+ targetEnvironments.stream().map(String::valueOf).collect(Collectors.joining(", ")));
Expand All @@ -324,6 +324,26 @@ private Collection<Path> 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<TargetEnvironment> getBaselineEnvironments() {
Collection<TargetEnvironment> 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) {
Expand Down

0 comments on commit c3dd65e

Please sign in to comment.