Skip to content

Commit

Permalink
Fix empty scope
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Feb 7, 2024
1 parent aa97810 commit 07685aa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public enum DependencyScope {
/**
* Undefined. When no scope is explicitly given, UNDEFINED will be used, but its meaning will depend on
* whether the DependencyCoordinate is used in dependency management, in which case it means the scope is not
* explicitly managed by this dependency management, or as a real dependency, in which case, the scope
* explicitly managed by this managed dependency, or as a real dependency, in which case, the scope
* will default to {@link #COMPILE}.
*/
UNDEFINED("", false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ public List<ArtifactRepository> toArtifactRepositories(List<RemoteRepository> re

public abstract ArtifactRepository toArtifactRepository(RemoteRepository repository);

public List<org.eclipse.aether.graph.Dependency> toDependencies(Collection<DependencyCoordinate> dependencies) {
return dependencies == null ? null : map(dependencies, this::toDependency);
public List<org.eclipse.aether.graph.Dependency> toDependencies(
Collection<DependencyCoordinate> dependencies, boolean managed) {
return dependencies == null ? null : map(dependencies, d -> toDependency(d, managed));
}

public abstract org.eclipse.aether.graph.Dependency toDependency(DependencyCoordinate dependency);
public abstract org.eclipse.aether.graph.Dependency toDependency(DependencyCoordinate dependency, boolean managed);

public List<org.eclipse.aether.artifact.Artifact> toArtifacts(Collection<Artifact> artifacts) {
return artifacts == null ? null : map(artifacts, this::toArtifact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ public DependencyCollectorResult collect(@Nonnull DependencyCollectorRequest req

Artifact rootArtifact =
request.getRootArtifact().map(session::toArtifact).orElse(null);
Dependency root = request.getRoot().map(session::toDependency).orElse(null);
Dependency root =
request.getRoot().map(d -> session.toDependency(d, false)).orElse(null);
CollectRequest collectRequest = new CollectRequest()
.setRootArtifact(rootArtifact)
.setRoot(root)
.setDependencies(session.toDependencies(request.getDependencies()))
.setManagedDependencies(session.toDependencies(request.getManagedDependencies()))
.setDependencies(session.toDependencies(request.getDependencies(), false))
.setManagedDependencies(session.toDependencies(request.getManagedDependencies(), true))
.setRepositories(session.toRepositories(session.getRemoteRepositories()));

RepositorySystemSession systemSession = session.getSession();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,12 @@ public ArtifactRepository toArtifactRepository(RemoteRepository repository) {
}
}

public org.eclipse.aether.graph.Dependency toDependency(DependencyCoordinate dependency) {
public org.eclipse.aether.graph.Dependency toDependency(DependencyCoordinate dependency, boolean managed) {
org.eclipse.aether.graph.Dependency dep;
if (dependency instanceof DefaultDependencyCoordinate) {
return ((DefaultDependencyCoordinate) dependency).getDependency();
dep = ((DefaultDependencyCoordinate) dependency).getDependency();
} else {
return new org.eclipse.aether.graph.Dependency(
dep = new org.eclipse.aether.graph.Dependency(
new org.eclipse.aether.artifact.DefaultArtifact(
dependency.getGroupId(),
dependency.getArtifactId(),
Expand All @@ -294,5 +295,9 @@ public org.eclipse.aether.graph.Dependency toDependency(DependencyCoordinate dep
null),
dependency.getScope().id());
}
if (!managed && "".equals(dep.getScope())) {
dep = dep.setScope(DependencyScope.COMPILE.id());
}
return dep;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ List<org.apache.maven.artifact.repository.ArtifactRepository> toArtifactReposito

org.apache.maven.artifact.repository.ArtifactRepository toArtifactRepository(RemoteRepository repository);

List<org.eclipse.aether.graph.Dependency> toDependencies(Collection<DependencyCoordinate> dependencies);
List<org.eclipse.aether.graph.Dependency> toDependencies(
Collection<DependencyCoordinate> dependencies, boolean managed);

org.eclipse.aether.graph.Dependency toDependency(DependencyCoordinate dependency);
org.eclipse.aether.graph.Dependency toDependency(DependencyCoordinate dependency, boolean managed);

List<org.eclipse.aether.artifact.Artifact> toArtifacts(Collection<Artifact> artifacts);

Expand Down

0 comments on commit 07685aa

Please sign in to comment.