private Version parseVersion(Unit unitReference) {
   try {
     return Version.parseVersion(unitReference.getVersion());
   } catch (IllegalArgumentException e) {
     throw new TargetDefinitionSyntaxException(
         NLS.bind(
             "Cannot parse version \"{0}\" of unit \"{1}\"",
             unitReference.getVersion(), unitReference.getId()),
         e);
   }
 }
  private IInstallableUnit getUnitInstance(IQueryable<IInstallableUnit> units, Unit unitReference) {
    IQueryResult<IInstallableUnit> queryResult = searchUnitInThisLocation(units, unitReference);

    if (queryResult.isEmpty()) {
      throw new TargetDefinitionResolutionException(
          NLS.bind(
              "Could not find \"{0}/{1}\" in the repositories of the current location",
              unitReference.getId(), unitReference.getVersion()));
    }
    // if the repository contains the same iu/version twice, both are identical and
    // it is OK to use either
    IInstallableUnit unitInstance = queryResult.iterator().next();
    return unitInstance;
  }
  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;
  }