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

Use specific versions for the release plugins in the generated BOMs #349

Merged
Merged
Changes from all commits
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 @@ -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
Loading