コード例 #1
0
  private URI getMirror(TargetDefinition.Repository location, List<Mirror> mirrors)
      throws URISyntaxException {
    URI p2RepositoryLocation = location.getLocation();
    String id = location.getId();
    if (id == null) {
      id = p2RepositoryLocation.toString();
    }

    ArtifactRepository repository =
        repositorySystem.createArtifactRepository(
            id,
            p2RepositoryLocation.toString(),
            p2layout,
            P2_REPOSITORY_POLICY,
            P2_REPOSITORY_POLICY);

    Mirror mirror = repositorySystem.getMirror(repository, mirrors);

    return mirror != null ? new URI(mirror.getUrl()) : p2RepositoryLocation;
  }
コード例 #2
0
  private void addTargetFileContentToTargetPlatform(
      TargetPlatformConfiguration configuration,
      TargetPlatformBuilder resolutionContext,
      MavenSession session) {
    final TargetDefinitionFile target;
    try {
      target = TargetDefinitionFile.read(configuration.getTarget());
    } catch (TargetDefinitionSyntaxException e) {
      throw new RuntimeException(
          "Invalid syntax in target definition "
              + configuration.getTarget()
              + ": "
              + e.getMessage(),
          e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    Set<URI> uris = new HashSet<URI>();

    for (Location location : target.getLocations()) {
      if (!(location instanceof InstallableUnitLocation)) {
        continue;
      }
      for (TargetDefinition.Repository repository :
          ((InstallableUnitLocation) location).getRepositories()) {

        try {
          URI uri = getMirror(repository, session.getRequest().getMirrors());
          if (uris.add(uri)) {
            if (!session.isOffline()) {
              String id = repository.getId();
              if (id != null) {
                Server server = session.getSettings().getServer(id);

                if (server != null) {
                  // TODO don't do this via magic side-effects, but when loading repositories
                  resolutionContext.setCredentials(uri, server.getUsername(), server.getPassword());
                } else {
                  getLogger()
                      .info(
                          "Unknown server id="
                              + id
                              + " for repository location="
                              + repository.getLocation());
                }
              }

              // TODO mirrors are no longer considered -> lookup mirrors when loading p2
              // repositories
            }
          }
        } catch (URISyntaxException e) {
          throw new RuntimeException(e);
        }
      }

      try {
        getLogger().debug("Resolving target definition file \"" + configuration.getTarget() + "\"");
        resolutionContext.addTargetDefinition(target, getEnvironments(configuration));
      } catch (TargetDefinitionSyntaxException e) {
        throw new RuntimeException(
            "Invalid syntax in target definition "
                + configuration.getTarget()
                + ": "
                + e.getMessage(),
            e);
      } catch (TargetDefinitionResolutionException e) {
        throw new RuntimeException(
            "Failed to resolve target definition " + configuration.getTarget(), e);
      }
    }
  }