hboutemy commented on code in PR #227:
URL:
https://github.com/apache/maven-artifact-plugin/pull/227#discussion_r3738121381
##########
src/main/java/org/apache/maven/plugins/artifact/buildinfo/ReferenceBuildinfoUtil.java:
##########
@@ -199,6 +215,55 @@ File downloadOrCreateReferenceBuildinfo(
return referenceBuildinfo;
}
+ public void checkForLocalResolution(
+ RepositorySystemSession repoSession, List<RemoteRepository>
remoteRepos, Artifact artifact) {
+
+ try {
+ CollectRequest collectRequest = new CollectRequest(new
Dependency(artifact, null), null);
+ CollectResult collectResult =
repoSystem.collectDependencies(repoSession, collectRequest);
+
+ for (DependencyNode child : collectResult.getRoot().getChildren())
{
+ checkDependenciesForLocalResolution(repoSession, child,
remoteRepos);
+ }
+
+ } catch (ArtifactResolutionException | DependencyCollectionException
e) {
+ log.warn("Checking for potential local artifact resolution not
possible " + e);
+ }
+ }
+
+ private void checkDependenciesForLocalResolution(
+ RepositorySystemSession repoSession, DependencyNode child,
List<RemoteRepository> remoteRepos)
+ throws ArtifactResolutionException {
+ // check for every dependency in the dependency tree
+ if (!child.getChildren().isEmpty()) {
+ for (DependencyNode node : child.getChildren()) {
+ checkDependenciesForLocalResolution(repoSession, node,
remoteRepos);
+ }
+ } else {
+ printWarningForLocalRepositoryArtifactResolution(repoSession,
child, remoteRepos);
+ }
+ }
+
+ /* An artifact stemming from a local repo is most likely an issue during
release builds. See #146. */
+ private void printWarningForLocalRepositoryArtifactResolution(
+ RepositorySystemSession repoSession, DependencyNode child,
List<RemoteRepository> remoteRepos)
+ throws ArtifactResolutionException {
+ Artifact defaultArtifact = child.getDependency().getArtifact();
+ ArtifactRequest artifactRequest = new ArtifactRequest();
+ artifactRequest.setArtifact(defaultArtifact);
+ artifactRequest.setRepositories(remoteRepos);
+ ArtifactResult artifactResult =
repoSystem.resolveArtifact(repoSession, artifactRequest);
+ ArtifactRepository resultRepo = artifactResult.getRepository();
+
+ if (resultRepo instanceof LocalRepository) {
+ log.warn(String.format(
+ "The artifact %s:%s:%s is stemming from your local Maven
repository. "
Review Comment:
"from your local Maven repository." => "from a local install to your local
Maven repository."
##########
src/main/java/org/apache/maven/plugins/artifact/buildinfo/ReferenceBuildinfoUtil.java:
##########
@@ -199,6 +215,55 @@ File downloadOrCreateReferenceBuildinfo(
return referenceBuildinfo;
}
+ public void checkForLocalResolution(
+ RepositorySystemSession repoSession, List<RemoteRepository>
remoteRepos, Artifact artifact) {
+
+ try {
+ CollectRequest collectRequest = new CollectRequest(new
Dependency(artifact, null), null);
+ CollectResult collectResult =
repoSystem.collectDependencies(repoSession, collectRequest);
+
+ for (DependencyNode child : collectResult.getRoot().getChildren())
{
+ checkDependenciesForLocalResolution(repoSession, child,
remoteRepos);
+ }
+
+ } catch (ArtifactResolutionException | DependencyCollectionException
e) {
+ log.warn("Checking for potential local artifact resolution not
possible " + e);
+ }
+ }
+
+ private void checkDependenciesForLocalResolution(
+ RepositorySystemSession repoSession, DependencyNode child,
List<RemoteRepository> remoteRepos)
+ throws ArtifactResolutionException {
+ // check for every dependency in the dependency tree
+ if (!child.getChildren().isEmpty()) {
+ for (DependencyNode node : child.getChildren()) {
+ checkDependenciesForLocalResolution(repoSession, node,
remoteRepos);
+ }
+ } else {
+ printWarningForLocalRepositoryArtifactResolution(repoSession,
child, remoteRepos);
+ }
+ }
+
+ /* An artifact stemming from a local repo is most likely an issue during
release builds. See #146. */
+ private void printWarningForLocalRepositoryArtifactResolution(
+ RepositorySystemSession repoSession, DependencyNode child,
List<RemoteRepository> remoteRepos)
+ throws ArtifactResolutionException {
+ Artifact defaultArtifact = child.getDependency().getArtifact();
+ ArtifactRequest artifactRequest = new ArtifactRequest();
+ artifactRequest.setArtifact(defaultArtifact);
+ artifactRequest.setRepositories(remoteRepos);
+ ArtifactResult artifactResult =
repoSystem.resolveArtifact(repoSession, artifactRequest);
+ ArtifactRepository resultRepo = artifactResult.getRepository();
+
+ if (resultRepo instanceof LocalRepository) {
+ log.warn(String.format(
+ "The artifact %s:%s:%s is stemming from your local Maven
repository. "
+ + "Please ensure that this is intended. "
Review Comment:
+ " and that your local installed artifact matches public reference from
remote."
this helps understand the risk of locally installed releases vs reference
published to remote
##########
src/main/java/org/apache/maven/plugins/artifact/buildinfo/ReferenceBuildinfoUtil.java:
##########
@@ -199,6 +215,55 @@ File downloadOrCreateReferenceBuildinfo(
return referenceBuildinfo;
}
+ public void checkForLocalResolution(
+ RepositorySystemSession repoSession, List<RemoteRepository>
remoteRepos, Artifact artifact) {
+
+ try {
+ CollectRequest collectRequest = new CollectRequest(new
Dependency(artifact, null), null);
+ CollectResult collectResult =
repoSystem.collectDependencies(repoSession, collectRequest);
+
+ for (DependencyNode child : collectResult.getRoot().getChildren())
{
+ checkDependenciesForLocalResolution(repoSession, child,
remoteRepos);
+ }
+
+ } catch (ArtifactResolutionException | DependencyCollectionException
e) {
+ log.warn("Checking for potential local artifact resolution not
possible " + e);
+ }
+ }
+
+ private void checkDependenciesForLocalResolution(
+ RepositorySystemSession repoSession, DependencyNode child,
List<RemoteRepository> remoteRepos)
+ throws ArtifactResolutionException {
+ // check for every dependency in the dependency tree
+ if (!child.getChildren().isEmpty()) {
+ for (DependencyNode node : child.getChildren()) {
+ checkDependenciesForLocalResolution(repoSession, node,
remoteRepos);
+ }
+ } else {
+ printWarningForLocalRepositoryArtifactResolution(repoSession,
child, remoteRepos);
+ }
+ }
+
+ /* An artifact stemming from a local repo is most likely an issue during
release builds. See #146. */
+ private void printWarningForLocalRepositoryArtifactResolution(
+ RepositorySystemSession repoSession, DependencyNode child,
List<RemoteRepository> remoteRepos)
+ throws ArtifactResolutionException {
+ Artifact defaultArtifact = child.getDependency().getArtifact();
+ ArtifactRequest artifactRequest = new ArtifactRequest();
+ artifactRequest.setArtifact(defaultArtifact);
+ artifactRequest.setRepositories(remoteRepos);
+ ArtifactResult artifactResult =
repoSystem.resolveArtifact(repoSession, artifactRequest);
+ ArtifactRepository resultRepo = artifactResult.getRepository();
+
+ if (resultRepo instanceof LocalRepository) {
+ log.warn(String.format(
+ "The artifact %s:%s:%s is stemming from your local Maven
repository. "
+ + "Please ensure that this is intended. "
+ + "If not, consider removing this artifact and
rebuilding.",
Review Comment:
adding the path to the local repository directory of the artifact version
would help delete
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]