Skip to content

Commit

Permalink
Give the baseline artifact a better name and add extension
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jan 6, 2024
1 parent 6b1c316 commit 3bfc57a
Showing 1 changed file with 18 additions and 5 deletions.
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

0 comments on commit 3bfc57a

Please sign in to comment.