@Override
  public Set<MavenRepositoryMetadata> getRemoteRepositoriesMetaData(final Project project) {
    if (project == null) {
      return Collections.emptySet();
    }

    final Set<MavenRepositoryMetadata> repositories = new HashSet<MavenRepositoryMetadata>();

    try {
      // Load Project's pom.xml
      final Path pomXMLPath = project.getPomXMLPath();
      final org.uberfire.java.nio.file.Path nioPomXMLPath = Paths.convert(pomXMLPath);
      final String pomXML = ioService.readAllString(nioPomXMLPath);

      final InputStream pomStream =
          new ByteArrayInputStream(pomXML.getBytes(StandardCharsets.UTF_8));
      final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pomStream);
      final Aether aether = new Aether(mavenProject);
      final Map<MavenRepositorySource, Collection<RemoteRepository>> remoteRepositories =
          getRemoteRepositories(mavenProject);

      // Local Repository
      repositories.add(
          makeRepositoryMetaData(
              aether.getSession().getLocalRepository(), MavenRepositorySource.LOCAL));

      if (remoteRepositories.isEmpty()) {
        return repositories;
      }

      for (Map.Entry<MavenRepositorySource, Collection<RemoteRepository>> e :
          remoteRepositories.entrySet()) {
        repositories.addAll(makeRepositoriesMetaData(e.getValue(), e.getKey()));
      }

    } catch (IllegalArgumentException iae) {
      log.error(
          "Unable to get Remote Repositories for Project '%s'. Returning empty Collection. ",
          project.getProjectName(), iae);

    } catch (NoSuchFileException nsfe) {
      log.error(
          "Unable to get Remote Repositories for Project '%s'. Returning empty Collection. ",
          project.getProjectName(), nsfe);

    } catch (org.uberfire.java.nio.IOException ioe) {
      log.error(
          "Unable to get Remote Repositories for Project '%s'. Returning empty Collection. ",
          project.getProjectName(), ioe);
    }

    return repositories;
  }
  @Override
  public Set<MavenRepositoryMetadata> getRemoteRepositoriesMetaData() {
    final Set<MavenRepositoryMetadata> repositories = new HashSet<MavenRepositoryMetadata>();

    final Aether aether = Aether.getAether();
    final Map<MavenRepositorySource, Collection<RemoteRepository>> remoteRepositories =
        getRemoteRepositories();

    // Local Repository
    repositories.add(
        makeRepositoryMetaData(
            aether.getSession().getLocalRepository(), MavenRepositorySource.LOCAL));

    if (remoteRepositories.isEmpty()) {
      return repositories;
    }

    for (Map.Entry<MavenRepositorySource, Collection<RemoteRepository>> e :
        remoteRepositories.entrySet()) {
      repositories.addAll(makeRepositoriesMetaData(e.getValue(), e.getKey()));
    }

    return repositories;
  }
  private Set<MavenRepositoryMetadata> getRepositoriesResolvingArtifact(
      final GAV gav, final MavenProject mavenProject) {
    ArtifactResult result = null;
    ArtifactRequest artifactRequest = null;

    final String artifactName = gav.toString();
    final Artifact artifact = new DefaultArtifact(artifactName);
    final Aether aether = new Aether(mavenProject);

    final Set<MavenRepositoryMetadata> repositoriesResolvingArtifact =
        new HashSet<MavenRepositoryMetadata>();
    final Map<MavenRepositorySource, Collection<RemoteRepository>> repositories =
        getRemoteRepositories(mavenProject);

    // Local Repository
    artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    try {
      result = aether.getSystem().resolveArtifact(aether.getSession(), artifactRequest);
      if (result != null && result.isResolved()) {
        final MavenRepositoryMetadata artifactRepositoryMetaData =
            makeRepositoryMetaData(result.getRepository(), MavenRepositorySource.LOCAL);
        if (artifactRepositoryMetaData != null) {
          repositoriesResolvingArtifact.add(artifactRepositoryMetaData);
        }
      }
    } catch (ArtifactResolutionException are) {
      // Ignore - this means the Artifact could not be resolved against the given RemoteRepository
    }

    // Remote Repositories
    try {
      for (Map.Entry<MavenRepositorySource, Collection<RemoteRepository>> e :
          repositories.entrySet()) {
        for (ArtifactRepository repository : e.getValue()) {
          artifactRequest = new ArtifactRequest();
          artifactRequest.setArtifact(artifact);
          java.nio.file.Path tempLocalRepositoryBasePath = null;
          try {
            // Maven always tries to resolve against LocalRepository first, which is not much use
            // when we want to check
            // if the Artifact is available on a RemoteRepository. Therefore substitute the default
            // RepositorySystemSession
            // with one that provides a LocalRepositoryManager that always uses an empty transient
            // LocalRepository to ensure
            // Maven does not resolve Artifacts locally.
            artifactRequest.addRepository((RemoteRepository) repository);
            tempLocalRepositoryBasePath = getRepositoryPath(gav);
            result =
                aether
                    .getSystem()
                    .resolveArtifact(
                        new MavenRepositorySystemSessionWrapper(
                            tempLocalRepositoryBasePath.toString(), aether.getSession()),
                        artifactRequest);

            if (result != null && result.isResolved()) {
              final MavenRepositoryMetadata artifactRepositoryMetaData =
                  makeRepositoryMetaData(result.getRepository(), e.getKey());
              if (artifactRepositoryMetaData != null) {
                repositoriesResolvingArtifact.add(artifactRepositoryMetaData);
              }
            }

          } catch (ArtifactResolutionException are) {
            // Ignore - this means the Artifact could not be resolved against the given
            // RemoteRepository
          } finally {
            tearDownMavenRepository(tempLocalRepositoryBasePath);
          }
        }
      }

    } catch (IOException ioe) {
      log.error(
          "Error resolving '"
              + gav.toString()
              + "' against Repositories. Returning empty Collection. ",
          ioe);
    }

    return repositoriesResolvingArtifact;
  }