Skip to content

Commit

Permalink
Change: JAR File Analyzer: Reorder list of Maven coordinates. Prefer …
Browse files Browse the repository at this point in the history
…artifact coordinates given as command line argument.
  • Loading branch information
smarkwal committed Sep 26, 2024
1 parent 6367358 commit c666264
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions jarhc/src/main/java/org/jarhc/loader/AbstractFileLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,26 @@ protected void load(String fileName, String coordinates, Archive archive, List<J
logger.warn("Artifact resolution error", e);
}

// prefer artifact coordinates given as command line argument
if (coordinates != null && artifacts != null) {
Artifact artifact = new Artifact(coordinates);
if (artifacts.indexOf(artifact) != 0) {
artifacts.remove(artifact);
artifacts.add(0, artifact);
if (artifacts != null) {

// reorder artifacts:
// priority 1: prefer artifact given as command line argument
// priority 2: prefer artifact with same JAR file name

Artifact bestArtifact = null;
if (coordinates != null) {
bestArtifact = new Artifact(coordinates);
} else {
for (Artifact artifact : artifacts) {
if (artifact.getFileName().equals(fileName)) {
bestArtifact = artifact;
break;
}
}
}
if (bestArtifact != null && artifacts.indexOf(bestArtifact) > 0) {
artifacts.remove(bestArtifact);
artifacts.add(0, bestArtifact);
}
}

Expand Down

0 comments on commit c666264

Please sign in to comment.