Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-6869] New flag to verify Maven installation status #995

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift click to select a range
904caa4
[MNG-6869] Initial idea
Giovds Dec 7, 2022
2dab934
[MNG-6869] Further brainstorming
mthmulders Dec 7, 2022
1082a0d
[MNG-6869] Refactor local variable name
Giovds Dec 7, 2022
8d46d92
[MNG-6969] WIP commit
Giovds Dec 22, 2022
9aaf62f
[MNG-6869] Correct way to find local repo path
mthmulders Dec 22, 2022
57c7020
[MNG-6869] Use java.nio instead of java.io
Giovds Dec 22, 2022
55f35fd
[MNG-6869] Use java.nio instead of java.io
mthmulders Dec 22, 2022
fdcce30
[MNG-6869] Implement verification of artifact resolution (WIP)
mthmulders Dec 22, 2022
e4ec517
[MNG-6869] Test artifact resolution with temporary local repository
mthmulders Jan 12, 2023
77526f5
[MNG-6869] Setup checks for remote connections
Giovds Jan 12, 2023
fbbcc20
[MNG-6869] Formatting
mthmulders Jan 12, 2023
ba9354a
[MNG-6869] Refactor: rename method
mthmulders Jan 12, 2023
85b0907
[MNG-6869] Formatting
mthmulders Jan 16, 2023
12a6b4b
[MNG-6869] Verify connection to remote repositories
mthmulders Jan 26, 2023
140a63c
[MNG-6869] Reformat with Spotless
mthmulders Jan 26, 2023
7afb18e
[MNG-6869] Add todo to fix local repository issue
Giovds Jan 26, 2023
ca4cb33
[MNG-6869] Narrow declaration of thrown exception
mthmulders Jan 26, 2023
0764fd0
[MNG-6869] Refine detection of possible connection issues
mthmulders Jan 26, 2023
30c9649
[MNG-6869] Use local repository correctly
Giovds Feb 9, 2023
d134358
[MNG-6869] Clean up temp file after usage
Giovds Feb 9, 2023
6ba97e6
[MNG-6869] Include local repository path in issue text
mthmulders Feb 9, 2023
79338ae
[MNG-6869] Mention local repo check has been completed
mthmulders Feb 9, 2023
b470aca
[MNG-6869] Output detected issues prefixed with a number
mthmulders Feb 9, 2023
8629a8a
[MNG-6869] Properly close streeam
mthmulders Feb 9, 2023
7fcc380
[MNG-6869] Make logger a static constant
mthmulders Feb 9, 2023
2b01442
[MNG-6869] Make it explicit we're populating instance variables
mthmulders Feb 9, 2023
95c52f2
[MNG-6869] Reorder instance variables
mthmulders Feb 9, 2023
d0f3b29
[MNG-6869] Mark method arguments as final
mthmulders Feb 9, 2023
58e2f46
[MNG-6869] Store temporary local repo as Path
mthmulders Feb 9, 2023
f67f7c3
[MNG-6869] Rename logger to LOGGER
mthmulders Feb 9, 2023
27a7e0a
[MNG-6869] Checkstyle: redundant modifier
mthmulders Feb 9, 2023
d2416a2
[MNG-6869] Minor review points
mthmulders Feb 9, 2023
2a9ce5e
[MNG-6869] Remove commented code
Giovds Feb 23, 2023
ed191ad
[MNG-6869] Use exception classification of Transporter
Giovds Feb 23, 2023
6adddbd
[MNG-6869] Make formatException signature non-optional
Giovds Feb 23, 2023
9443a2a
[MNG-6869] Remove unnecessary comment
Giovds Feb 23, 2023
41177b3
[MNG-6869] Remove unused DI fields
Giovds Feb 23, 2023
fc2e7f7
[MNG-6869] Make no assumptions about the existence of Maven Central
mthmulders Feb 23, 2023
2114cda
[MNG-6869] Simplify
mthmulders Feb 23, 2023
853819c
[MNG-6869] Prevent possible ClassCastException
mthmulders Feb 23, 2023
f39aec2
[MNG-6869] Revert unrelated change
mthmulders May 10, 2023
6c4348d
Merge branch 'master' into mng-6869-new-flag-to-verify-maven-status
Giovds Apr 26, 2024
eaf2421
[MNG-6869] Make it work with recent changes
Giovds Apr 26, 2024
63006df
[MNG-6869] Make use of try with resources
Giovds Apr 26, 2024
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
Prev Previous commit
Next Next commit
[MNG-6869] Use exception classification of Transporter
  • Loading branch information
Giovds authored and mthmulders committed Feb 23, 2023
commit ed191ad471103ae3c8ba988eacc54038198f5e63
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,6 @@
import java.net.URI;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.PlexusContainer;
Expand Down Expand Up @@ -72,16 71,16 @@ public Optional<String> verifyConnectionToRemoteRepository(

try {
final Transporter transporter = transporterProvider.newTransporter(session, repository);
final Optional<String> maybeIssue = verifyConnectionUsingTransport(transporter, repository, artifactPath);
final Optional<String> issue = verifyConnectionUsingTransport(transporter, repository, artifactPath);

if (!maybeIssue.isPresent()) {
if (!issue.isPresent()) {
logger.info(
"Connection check for repository '{}' at '{}' completed",
repository.getId(),
repository.getUrl());
}

return maybeIssue;
return issue;
} catch (final NoTransporterException nte) {
final String message = String.format(
"There is no compatible transport for remote repository '%s' with location '%s'",
Expand All @@ -94,40 93,27 @@ private Optional<String> verifyConnectionUsingTransport(
final Transporter transporter, final RemoteRepository remoteRepository, final String artifactPath) {
try {
final GetTask task = new GetTask(URI.create(artifactPath));
// We could connect, but uncertain to what. Could be the repository, could be a valid web page.
transporter.get(task);
return Optional.empty();
} catch (final Exception e) {
return classifyException(remoteRepository, e);
int errorOrArtifactNotFound = transporter.classify(e);
if (Transporter.ERROR_NOT_FOUND == errorOrArtifactNotFound) {
// No-op since we could connect to the repository
// However we do not know what should or shouldn't be present
return Optional.empty();
}
// In this case it is Transporter.ERROR_OTHER
return formatException(remoteRepository, e);
}
}

private Optional<String> classifyException(final RemoteRepository remoteRepository, final Exception e) {
final String message = e.getMessage();
private Optional<String> formatException(final RemoteRepository remoteRepository, final Exception e) {
final String repositoryId = remoteRepository.getId();
final String repositoryUrl = remoteRepository.getUrl();
final String repository = String.format("%s [%s]", repositoryId, repositoryUrl);

final boolean notFound = StringUtils.contains(message, "status code: 404");
final boolean unauthorized = StringUtils.contains(message, "status code: 401");
final boolean forbidden = StringUtils.contains(message, "status code: 403");

if (isCentralOrMirrorOfCentral(remoteRepository) && notFound) {
final String issue = String.format(
"Connection to %s possible, but expected artifact %s cannot be resolved",
repository, APACHE_MAVEN_ARTIFACT);
return Optional.of(issue);

} else if (notFound) {
// We tried to resolve the artifact from a repository that does not necessarily host it.
logger.warn("Connection to {} possible, but artifact {} not found", repository, APACHE_MAVEN_ARTIFACT);
return Optional.empty();

} else if (unauthorized || forbidden) {
final String issue = String.format("Connection to %s possible, but access denied", repository);
return Optional.of(issue);
}

logger.error("Error connecting to repository {}", repository, e);
return Optional.of("Unknown issue: " e.getMessage());
final String issue = String.format("Connection to %s not possible. Cause: %s", repository, e.getMessage());
return Optional.of(issue);
}
}