Skip to content

Commit

Permalink
Merge pull request #349 from aloubyansky/release-plugins-specific-ver…
Browse files Browse the repository at this point in the history
…sions

Use specific versions for the release plugins in the generated BOMs
  • Loading branch information
aloubyansky authored Sep 23, 2024
2 parents 0bb96d5 + b241217 commit a93e83e
Showing 1 changed file with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.StringJoiner;
Expand Down Expand Up @@ -1652,12 +1653,11 @@ private boolean isChangedSinceLastRelease(PlatformMemberImpl member) throws Mojo
}

private List<Profile> getGeneratedBomReleaseProfile() {

if (generatedBomReleaseProfile == null) {
generatedBomReleaseProfile = new ArrayList<>(2);
for (Profile p : project.getModel().getProfiles()) {
if (p.getId().startsWith("release")) {
generatedBomReleaseProfile.add(copyReleasePlugins(p));
for (Profile profile : project.getModel().getProfiles()) {
if (profile.getId().startsWith("release")) {
generatedBomReleaseProfile.add(copyReleasePlugins(profile));
}
}
}
Expand All @@ -1684,24 +1684,38 @@ private Profile copyReleasePlugins(Profile parentReleaseProfile) {
}

private Plugin clonePluginConfig(Plugin plugin) {
if (plugin.getVersion() == null) {
String pluginVersion = plugin.getVersion();
if (pluginVersion == null) {
final Plugin managedPlugin = project.getPluginManagement().getPluginsAsMap().get(plugin.getKey());
if (managedPlugin == null || managedPlugin.getVersion() == null) {
getLog().warn("Failed to determine the version for " + plugin.getKey());
} else {
var version = managedPlugin.getVersion();
if (!version.startsWith("$")) {
version = toPropertyOrSelf(version);
}
plugin = plugin.clone();
plugin.setVersion(version);
pluginVersion = getPreferredVersionValue(managedPlugin.getVersion(), false);
}
} else if (!plugin.getVersion().startsWith("$")) {
plugin.setVersion(toPropertyOrSelf(plugin.getVersion()));
} else {
pluginVersion = getPreferredVersionValue(pluginVersion, false);
}
if (!Objects.equals(pluginVersion, plugin.getVersion())) {
plugin = plugin.clone();
plugin.setVersion(pluginVersion);
}
return plugin;
}

private String getPreferredVersionValue(String version, boolean preferVersionProperty) {
if (version.startsWith("${") && version.endsWith("}")) {
if (!preferVersionProperty) {
var value = project.getProperties().getProperty(version.substring(2, version.length() - 1));
if (value != null) {
version = value;
}
}
} else if (preferVersionProperty) {
version = toPropertyOrSelf(version);
}
return version;
}

private String toPropertyOrSelf(String version) {
var prop = pomPropsByValues.get(version);
return prop == null ? version : "${" + prop + "}";
Expand Down

0 comments on commit a93e83e

Please sign in to comment.