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

Give the baseline artifact a better name and add extension #3324

Merged
merged 1 commit into from
Jan 6, 2024
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 @@ -27,6 +27,7 @@
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.io.FilenameUtils;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
Expand Down Expand Up @@ -85,18 +86,19 @@ public Map<String, IP2Artifact> getProjectBaseline(Collection<MavenRepositoryLoc
Map<String, IP2Artifact> result = new LinkedHashMap<>();

for (Map.Entry<String, IP2Artifact> reactorArtifact : reactor.entrySet()) {
IArtifactDescriptor descriptor = reactorArtifact.getValue().getArtifactDescriptor();
IP2Artifact value = reactorArtifact.getValue();
IArtifactDescriptor descriptor = value.getArtifactDescriptor();

Entry<IArtifactRepository, IArtifactDescriptor> baselineDescriptorEntry = getBaselineDescriptor(
baselineArtifacts, descriptor);
if (baselineDescriptorEntry == null) {
continue;
}
IArtifactDescriptor baselineDescriptor = baselineDescriptorEntry.getValue();
IArtifactKey baslineKey = baselineDescriptor.getArtifactKey();
IArtifactKey baselineKey = baselineDescriptor.getArtifactKey();
String format = baselineDescriptor.getProperty(IArtifactDescriptor.FORMAT);
File baselineArtifact = new File(target, baslineKey.getClassifier() + "/" + baslineKey.getId() + "/"
+ baslineKey.getVersion() + (format != null ? "." + format : ""));
File baselineArtifact = new File(target, baselineKey.getClassifier() + "/" + baselineKey.getId() + "-"
+ baselineKey.getVersion() + (format != null ? "." + format : "") + getExtension(value));

baselineArtifact.getParentFile().mkdirs();
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(baselineArtifact))) {
Expand All @@ -114,7 +116,7 @@ public Map<String, IP2Artifact> getProjectBaseline(Collection<MavenRepositoryLoc
}

List<IInstallableUnit> units = new ArrayList<>();
for (IInstallableUnit unit : reactorArtifact.getValue().getInstallableUnits()) {
for (IInstallableUnit unit : value.getInstallableUnits()) {
IInstallableUnit baselineUnit = getBaselineUnit(baselineUnits, unit.getId(), unit.getVersion());
if (baselineUnit != null) {
units.add(baselineUnit);
Expand All @@ -126,6 +128,17 @@ public Map<String, IP2Artifact> getProjectBaseline(Collection<MavenRepositoryLoc
return !result.isEmpty() ? result : null;
}

private String getExtension(IP2Artifact value) {
File location = value.getLocation();
if (location != null) {
String extension = FilenameUtils.getExtension(location.getName());
if (!extension.isBlank()) {
return "." + extension;
}
}
return "";
}

private Entry<IArtifactRepository, IArtifactDescriptor> getBaselineDescriptor(
List<IArtifactRepository> baselineArtifacts, IArtifactDescriptor descriptor) {

Expand Down