Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/it/projects/list-repositories/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>fake-plugin-repository</id>
<url>http://localhost:3456</url>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
Expand All @@ -51,4 +58,4 @@
</dependency>
</dependencies>

</project>
</project>
2 changes: 2 additions & 0 deletions src/it/projects/list-repositories/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ assert file.exists()
String buildLog = file.getText( "UTF-8" )
assert buildLog.contains( 'Project remote repositories used by this build:')
assert buildLog.contains( '* fake-remote-repository (http://localhost:2345, default, releases+snapshots)')
assert buildLog.contains( 'Plugin repositories used by this build:' )
assert buildLog.contains( '* fake-plugin-repository (http://localhost:3456, default, releases+snapshots)' )
assert buildLog.contains( '* sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots, default, snapshots) mirrored by mrm-maven-plugin')
if (!mavenVersion.startsWith('4.')) {
// Maven 4 drop central repo from default super pom - so model doesn't have it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
import org.sonatype.plexus.build.incremental.BuildContext;

/**
* Goal that collects all project dependencies and then lists the repositories used by the build and by the transitive
* dependencies.
* Goal that collects all project dependencies and then lists the dependency repositories used by the build and
* transitive dependencies, along with the plugin repositories used by the build.
*
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @since 2.2
Expand Down Expand Up @@ -109,21 +109,18 @@ public boolean visitLeave(DependencyNode node) {
}
}));

if (repositories.isEmpty()) {
Set<RemoteRepository> pluginRepositories =
new HashSet<>(Optional.ofNullable(getProject().getRemotePluginRepositories())
.orElseGet(Collections::emptyList));

if (repositories.isEmpty() && pluginRepositories.isEmpty()) {
getLog().info("No remote repository is used by this build." + System.lineSeparator());
return;
}

StringBuilder message = new StringBuilder();

Map<Boolean, List<RemoteRepository>> repoGroupByMirrors = repositories.stream()
.collect(Collectors.groupingBy(
repo -> repo.getMirroredRepositories().isEmpty()));

prepareRemoteRepositoriesList(
message, repoGroupByMirrors.getOrDefault(Boolean.TRUE, Collections.emptyList()));
prepareRemoteMirrorRepositoriesList(
message, repoGroupByMirrors.getOrDefault(Boolean.FALSE, Collections.emptyList()));
prepareRemoteRepositoriesList(message, "Project remote repositories used by this build:", repositories);
prepareRemoteRepositoriesList(message, "Plugin repositories used by this build:", pluginRepositories);

getLog().info(message);

Expand Down Expand Up @@ -163,11 +160,21 @@ private void prepareRemoteMirrorRepositoriesList(
}

private void prepareRemoteRepositoriesList(
StringBuilder message, Collection<RemoteRepository> remoteProjectRepositories) {
StringBuilder message, String heading, Collection<RemoteRepository> repositories) {
if (repositories.isEmpty()) {
return;
}

message.append("Project remote repositories used by this build:").append(System.lineSeparator());
message.append(heading).append(System.lineSeparator());

remoteProjectRepositories.forEach(
repo -> message.append(" * ").append(repo).append(System.lineSeparator()));
Map<Boolean, List<RemoteRepository>> repoGroupByMirrors = repositories.stream()
.collect(Collectors.groupingBy(
repo -> repo.getMirroredRepositories().isEmpty()));

repoGroupByMirrors
.getOrDefault(Boolean.TRUE, Collections.emptyList())
.forEach(repo -> message.append(" * ").append(repo).append(System.lineSeparator()));
prepareRemoteMirrorRepositoriesList(
message, repoGroupByMirrors.getOrDefault(Boolean.FALSE, Collections.emptyList()));
}
}
Loading