Skip to content

Commit

Permalink
feat: Use latest version resolver when conflicts libraries.
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Jun 6, 2023
1 parent 7e62957 commit 36c4ae1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/java/bee/api/Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@ void setVersion(String version) {
throw new Error();
}

/**
* Test whether the specified library is same product or not.
*
* @param library
* @return
*/
public boolean isSame(Library library) {
return Objects.equals(group, library.group) && Objects.equals(name, library.name) && Objects.equals(classfier, library.classfier);
}

/**
* {@inheritDoc}
*/
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/bee/api/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,33 @@ private Set<Library> collectDependency(Project project, Set<Scope> scopes, Set<L
}));

for (ArtifactResult dependency : result.getArtifactResults()) {
set.add(new Library(dependency.getArtifact()));
Library lib = new Library(dependency.getArtifact());
Library old = checkDupilication(set, lib);
if (old != null) {
if (lib.version.compareToIgnoreCase(old.version) > 0) {
set.remove(old);
set.add(lib);
}
} else {
set.add(lib);
}
}
} catch (Exception e) {
throw I.quiet(e);
}
}

return set;
}

private Library checkDupilication(Set<Library> set, Library target) {
for (Library lib : set) {
if (lib.isSame(target)) {
return lib;
}
}
return null;
}

/**
* Resolve the latest version of the specified library.
*
Expand Down

0 comments on commit 36c4ae1

Please sign in to comment.