private IQueryResult<IInstallableUnit> searchUnitInThisLocation(
      IQueryable<IInstallableUnit> units, Unit unitReference) {
    Version version = parseVersion(unitReference);

    // the createIUQuery treats 0.0.0 version as "any version", and all other versions as exact
    // versions
    IQuery<IInstallableUnit> matchingIUQuery =
        QueryUtil.createIUQuery(unitReference.getId(), version);
    IQuery<IInstallableUnit> latestMatchingIUQuery = QueryUtil.createLatestQuery(matchingIUQuery);

    IQueryResult<IInstallableUnit> queryResult = units.query(latestMatchingIUQuery, monitor);
    return queryResult;
  }
  public TargetPlatformContent resolveContent(TargetDefinition definition)
      throws TargetDefinitionSyntaxException, TargetDefinitionResolutionException {

    List<URI> artifactRepositories = new ArrayList<URI>();

    Set<IInstallableUnit> availableUnits = new LinkedHashSet<IInstallableUnit>();

    Set<IInstallableUnit> rootIUs = new LinkedHashSet<IInstallableUnit>();

    IncludeMode includeMode = null;
    Boolean includeAllEnvironments = null;

    for (Location locationDefinition : definition.getLocations()) {
      if (locationDefinition instanceof InstallableUnitLocation) {
        InstallableUnitLocation iuLocationDefinition = (InstallableUnitLocation) locationDefinition;

        if (includeMode != null && includeMode != iuLocationDefinition.getIncludeMode()) {
          throw new TargetDefinitionResolutionException(
              "Include mode must be the same for all locations");
        }
        includeMode = iuLocationDefinition.getIncludeMode();

        if (includeAllEnvironments != null
            && includeAllEnvironments.booleanValue()
                != iuLocationDefinition.includeAllEnvironments()) {
          throw new TargetDefinitionResolutionException(
              "The attribute 'includeAllPlatforms' must be the same for all locations");
        }
        includeAllEnvironments = iuLocationDefinition.includeAllEnvironments();

        List<IMetadataRepository> metadataRepositories = new ArrayList<IMetadataRepository>();
        for (Repository repository : iuLocationDefinition.getRepositories()) {
          repositoryIdManager.addMapping(repository.getId(), repository.getLocation());
          artifactRepositories.add(repository.getLocation());
          metadataRepositories.add(loadRepository(repository));
        }

        IQueryable<IInstallableUnit> locationUnits =
            new CompoundQueryable<IInstallableUnit>(
                metadataRepositories.toArray(new IMetadataRepository[metadataRepositories.size()]));

        for (Unit unit : iuLocationDefinition.getUnits()) {
          rootIUs.add(getUnitInstance(locationUnits, unit));
        }

        Iterator<IInstallableUnit> iterator =
            locationUnits.query(QueryUtil.ALL_UNITS, monitor).iterator();
        while (iterator.hasNext()) {
          IInstallableUnit unit = iterator.next();
          if (!executionEnvironment.isNonApplicableEEUnit(unit)) {
            availableUnits.add(unit);
          }
        }
      } else {
        logger.warn(
            NLS.bind(
                "Target location type: {0} is not supported",
                locationDefinition.getTypeDescription()));
      }
    }

    Collection<IInstallableUnit> units;
    if (!availableUnits.isEmpty()) {
      AbstractResolutionStrategy strategy =
          getResolutionStrategy(includeMode, includeAllEnvironments);

      strategy.setRootInstallableUnits(rootIUs);
      strategy.setAvailableInstallableUnits(availableUnits);
      strategy.setEEResolutionHints(executionEnvironment);
      units = strategy.multiPlatformResolve(environments, monitor);
    } else {
      units = Collections.emptySet();
    }

    if (definition.hasIncludedBundles()) {
      // the bundle selection list is currently not taken into account (see bug 373776)
      logger.warn(
          "De-selecting bundles in a target definition file is not supported. See http://wiki.eclipse.org/Tycho_Messages_Explained#Target_File_Include_Bundles for alternatives.");
    }

    return new TargetPlatformContent(units, artifactRepositories);
  }