コード例 #1
0
 static boolean isExternalRepo(RemoteRepository repository) {
   boolean local =
       "localhost".equals(repository.getHost())
           || "127.0.0.1".equals(repository.getHost())
           || "file".equalsIgnoreCase(repository.getProtocol());
   return !local;
 }
コード例 #2
0
 private MavenRepositoryMetadata makeRepositoryMetaData(
     final ArtifactRepository repository, final MavenRepositorySource source) {
   if (repository instanceof LocalRepository) {
     final LocalRepository localRepository = (LocalRepository) repository;
     return new MavenRepositoryMetadata(
         localRepository.getId(), MavenSettings.getSettings().getLocalRepository(), source);
   } else if (repository instanceof RemoteRepository) {
     final RemoteRepository remoteRepository = (RemoteRepository) repository;
     return new MavenRepositoryMetadata(
         remoteRepository.getId(), remoteRepository.getUrl(), source);
   }
   return null;
 }
コード例 #3
0
  /**
   * Creates a model resolver to assist building of dependency POMs.
   *
   * @param system a {@link RepositorySystem}
   * @param session a {@link RepositorySystemSession}
   * @param remoteRepositories remote repositories to use for resolution.
   */
  public SimpleModelResolver(
      RepositorySystem system,
      RepositorySystemSession session,
      List<RemoteRepository> remoteRepositories) {
    this.system = system;
    this.session = session;
    this.repositories = new ArrayList<>(remoteRepositories);
    this.repositoryIds =
        new HashSet<>(remoteRepositories.size() < 3 ? 3 : remoteRepositories.size());

    for (RemoteRepository repository : remoteRepositories) {
      repositoryIds.add(repository.getId());
    }
  }
コード例 #4
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;
 }
コード例 #5
0
  private MirrorDef findMirror(RemoteRepository repository) {
    if (!mirrors.isEmpty()) {
      String repoId = repository.getId();
      String repoType = repository.getContentType();

      for (MirrorDef mirror : mirrors) {
        if (mirror.idMatcher.isExactMatch(repoId) && mirror.typeMatcher.isMatch(repoType)) {
          return mirror;
        }
      }

      for (MirrorDef mirror : mirrors) {
        if (mirror.idMatcher.isMatch(repository) && mirror.typeMatcher.isMatch(repoType)) {
          return mirror;
        }
      }
    }

    return null;
  }
コード例 #6
0
  public RemoteRepository getMirror(RemoteRepository repository) {
    MirrorDef mirror = findMirror(repository);

    if (mirror == null) {
      return null;
    }

    RemoteRepository.Builder builder =
        new RemoteRepository.Builder(mirror.id, repository.getContentType(), mirror.url);

    builder.setRepositoryManager(mirror.repositoryManager);

    if (mirror.type != null && mirror.type.length() > 0) {
      builder.setContentType(mirror.type);
    }

    builder.setSnapshotPolicy(repository.getPolicy(true));
    builder.setReleasePolicy(repository.getPolicy(false));

    builder.setMirroredRepositories(Collections.singletonList(repository));

    return builder.build();
  }
コード例 #7
0
 boolean isMatch(RemoteRepository repository) {
   boolean result = false;
   if (mirrorOfIds.length <= 0) {
     result = false;
   } else {
     String repoId = repository.getId();
     for (String mirrorOfId : mirrorOfIds) {
       if (mirrorOfId.equals(repoId)) {
         result = true;
         break;
       } else if (mirrorOfId.startsWith("!") && mirrorOfId.substring(1).equals(repoId)) {
         result = false;
         break;
       } else if (EXTERNAL_WILDCARD.equals(mirrorOfId) && isExternalRepo(repository)) {
         result = true;
       } else if (WILDCARD.equals(mirrorOfId)) {
         result = true;
       }
     }
   }
   return result;
 }
コード例 #8
0
 private void removeProjectRepositoriesThatAreInSettings(
     final Collection<RemoteRepository> projectRepositories,
     final Collection<RemoteRepository> settingsRepositories) {
   final Collection<RemoteRepository> projectRepositoriesToRemove =
       new HashSet<RemoteRepository>();
   final Iterator<RemoteRepository> projectRepositoryItr = projectRepositories.iterator();
   while (projectRepositoryItr.hasNext()) {
     final RemoteRepository projectRepository = projectRepositoryItr.next();
     for (RemoteRepository settingsRepository : settingsRepositories) {
       if (projectRepository.getId().equals(settingsRepository.getId())) {
         if (projectRepository.getUrl().equals(settingsRepository.getUrl())) {
           projectRepositoriesToRemove.add(projectRepository);
         }
       }
     }
   }
   projectRepositories.removeAll(projectRepositoriesToRemove);
 }