Exemplo n.º 1
0
 private Proxy getProxy(RepositorySystemSession session, ArtifactRepository repository) {
   if (session != null) {
     ProxySelector selector = session.getProxySelector();
     if (selector != null) {
       RemoteRepository repo = RepositoryUtils.toRepo(repository);
       org.eclipse.aether.repository.Proxy proxy = selector.getProxy(repo);
       if (proxy != null) {
         Proxy p = new Proxy();
         p.setHost(proxy.getHost());
         p.setProtocol(proxy.getType());
         p.setPort(proxy.getPort());
         if (proxy.getAuthentication() != null) {
           repo = new RemoteRepository.Builder(repo).setProxy(proxy).build();
           AuthenticationContext authCtx = AuthenticationContext.forProxy(session, repo);
           p.setUserName(authCtx.get(AuthenticationContext.USERNAME));
           p.setPassword(authCtx.get(AuthenticationContext.PASSWORD));
           p.setNtlmDomain(authCtx.get(AuthenticationContext.NTLM_DOMAIN));
           p.setNtlmHost(authCtx.get(AuthenticationContext.NTLM_WORKSTATION));
           authCtx.close();
         }
         return p;
       }
     }
   }
   return null;
 }
Exemplo n.º 2
0
 private Mirror getMirror(RepositorySystemSession session, ArtifactRepository repository) {
   if (session != null) {
     org.eclipse.aether.repository.MirrorSelector selector = session.getMirrorSelector();
     if (selector != null) {
       RemoteRepository repo = selector.getMirror(RepositoryUtils.toRepo(repository));
       if (repo != null) {
         Mirror mirror = new Mirror();
         mirror.setId(repo.getId());
         mirror.setUrl(repo.getUrl());
         mirror.setLayout(repo.getContentType());
         return mirror;
       }
     }
   }
   return null;
 }
  /**
   * Resolve maven URI into maven project.
   *
   * <p>Provides only model and artifact.
   */
  public static MavenProject newProject(String mavenURI) throws Exception {

    final Artifact artifact = newArtifact(mavenURI);

    final File input = artifact.getFile();

    final ModelReader reader = new DefaultModelReader();

    final Model model = reader.read(input, null);

    final MavenProject project = new MavenProject(model);

    project.setArtifact(RepositoryUtils.toArtifact(artifact));

    return project;
  }
Exemplo n.º 4
0
  private void addMissingArtifactProblemInfos(
      MavenProject mavenProject, SourceLocation location, List<MavenProblemInfo> knownProblems) {
    Set<Artifact> artifacts = mavenProject.getArtifacts();
    all_artifacts_loop:
    for (Artifact mavenArtifact : artifacts) {
      if (!mavenArtifact.isResolved()) {
        org.eclipse.aether.artifact.Artifact artifact = RepositoryUtils.toArtifact(mavenArtifact);
        for (MavenProblemInfo problem : knownProblems) {
          if (problem instanceof ArtifactNotFoundProblemInfo) {
            ArtifactNotFoundProblemInfo artifactNotFoundProblemInfo =
                (ArtifactNotFoundProblemInfo) problem;
            if (equals(artifactNotFoundProblemInfo.getArtifact(), artifact)) {
              continue all_artifacts_loop;
            }
          }
        }

        knownProblems.add(
            new ArtifactNotFoundProblemInfo(artifact, mavenConfiguration.isOffline(), location));
      }
    }
  }
Exemplo n.º 5
0
 private Authentication getAuthentication(
     RepositorySystemSession session, ArtifactRepository repository) {
   if (session != null) {
     AuthenticationSelector selector = session.getAuthenticationSelector();
     if (selector != null) {
       RemoteRepository repo = RepositoryUtils.toRepo(repository);
       org.eclipse.aether.repository.Authentication auth = selector.getAuthentication(repo);
       if (auth != null) {
         repo = new RemoteRepository.Builder(repo).setAuthentication(auth).build();
         AuthenticationContext authCtx = AuthenticationContext.forRepository(session, repo);
         Authentication result =
             new Authentication(
                 authCtx.get(AuthenticationContext.USERNAME),
                 authCtx.get(AuthenticationContext.PASSWORD));
         result.setPrivateKey(authCtx.get(AuthenticationContext.PRIVATE_KEY_PATH));
         result.setPassphrase(authCtx.get(AuthenticationContext.PRIVATE_KEY_PASSPHRASE));
         authCtx.close();
         return result;
       }
     }
   }
   return null;
 }
Exemplo n.º 6
0
 static boolean matchesLayout(ArtifactRepository repository, Mirror mirror) {
   return matchesLayout(RepositoryUtils.getLayout(repository), mirror.getMirrorOfLayouts());
 }
  private void resolveOld(
      Artifact artifact,
      List<ArtifactRepository> remoteRepositories,
      RepositorySystemSession session)
      throws ArtifactResolutionException, ArtifactNotFoundException {
    if (artifact == null) {
      return;
    }

    if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
      File systemFile = artifact.getFile();

      if (systemFile == null) {
        throw new ArtifactNotFoundException(
            "System artifact: " + artifact + " has no file attached", artifact);
      }

      if (!systemFile.exists()) {
        throw new ArtifactNotFoundException(
            "System artifact: " + artifact + " not found in path: " + systemFile, artifact);
      }

      if (!systemFile.isFile()) {
        throw new ArtifactNotFoundException(
            "System artifact: " + artifact + " is not a file: " + systemFile, artifact);
      }

      artifact.setResolved(true);

      return;
    }

    if (!artifact.isResolved()) {
      ArtifactResult result;

      try {
        ArtifactRequest artifactRequest = new ArtifactRequest();
        artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact));
        artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories));

        // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved
        // or not
        LocalRepositoryManager lrm = session.getLocalRepositoryManager();
        String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact());
        artifact.setFile(new File(lrm.getRepository().getBasedir(), path));

        result = repoSystem.resolveArtifact(session, artifactRequest);
      } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
        if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) {
          throw new ArtifactNotFoundException(
              e.getMessage(),
              artifact.getGroupId(),
              artifact.getArtifactId(),
              artifact.getVersion(),
              artifact.getType(),
              artifact.getClassifier(),
              remoteRepositories,
              artifact.getDownloadUrl(),
              artifact.getDependencyTrail(),
              e);
        } else {
          throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e);
        }
      }

      artifact.selectVersion(result.getArtifact().getVersion());
      artifact.setFile(result.getArtifact().getFile());
      artifact.setResolved(true);

      if (artifact.isSnapshot()) {
        Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
        if (matcher.matches()) {
          Snapshot snapshot = new Snapshot();
          snapshot.setTimestamp(matcher.group(2));
          try {
            snapshot.setBuildNumber(Integer.parseInt(matcher.group(3)));
            artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot));
          } catch (NumberFormatException e) {
            logger.warn(
                "Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage());
          }
        }
      }
    }
  }