Example #1
0
/*
    Test if the version is acceptable based on the supplied critera.
    The acceptable formats for criteria are:

    VER                             Allows prereleases
    1.2.[*xX]                       Wild card version portion. (allows prereleases).
    ~VER                            Compatible with VER at the least significant level.
                                    ~1.2.3 == (>=1.2.3 <1.3.0) Compatible at the patch level
                                    ~1.2 == 1.2.x   Compatible at the minor level
                                    ~1 == 1.x   Compatible at the major level
    ^VER                            Compatible with VER at the most significant level.
                                    ^0.2.3 == 0.2.3 <= VER < 0.3.0
                                    ^1.2.3 == 1.2.3 <= VER < 2.0.0
    [>, >=, <, <=, ==, !=]VER       Create range relative to given version
    EXPR1 - EXPR2                   <=EXPR1 <=EXPR2
    EXPR1 || EXPR2 ...              EXPR1 OR EXPR2
    EXPR1 && EXPR2 ...              EXPR1 AND EXPR2
    EXPR1 EXPR2 ...                 EXPR1 AND EXPR2

    Pre-release versions will only match if the criteria contains a "-.*" prerelease suffix
*/
PUBLIC bool mprIsVersionObjAcceptable(MprVersion *vp, cchar *criteria)
{
    char        *expr, *exprTok, *range, *rangeTok, *low, *high;
    bool        allMatched;

    if (!vp->ok) {
        return 0;
    }
    if (!criteria || *criteria == '\0') {
        return 1;
    }
    criteria = cleanVersion(criteria);
    for (range = (char*) criteria; stok(range, "||", &rangeTok) != 0; range = rangeTok) {
        range = strim(range, " \t", 0);
        allMatched = 1;
        for (expr = (char*) range; sptok(expr, "&&", &exprTok) != 0; expr = exprTok) {
            if (scontains(expr, " - ")) {
                low = sptok(expr, " - ", &high);
                return inRange(vp, sjoin(">=", low, NULL)) && inRange(vp, sjoin("<=", high, NULL));
            }
            if (!inRange(vp, expr)) {
                allMatched = 0;
                break;
            }
        }
        if (allMatched) {
            return 1;
        }
    }
    return 0;
}
Example #2
0
MprVersion *mprCreateVersion(cchar *version)
{
    MprVersion  *vp;
    char        *all;

    if ((vp = mprAllocObj(MprVersion, manageVersion)) == 0) {
        return vp;
    }
    if (!version) {
        version = "0";
    }
    vp->full = cleanVersion(version);
    version = completeVersion(vp->full, "0");

    semVerInit();
    if (srmatch(version, semVer, &all, &vp->baseVersion, &vp->preVersion, NULL) <= 0) {
        /* Do not return null - just leave ok as false */
        return vp;
    }
    vp->numberVersion = versionToNumber(vp->baseVersion);
    vp->major = (int) (vp->numberVersion / VER_FACTOR / VER_FACTOR);
    vp->minor = (int) (vp->numberVersion / VER_FACTOR % VER_FACTOR);
    vp->patch = (int) (vp->numberVersion % VER_FACTOR);
    vp->ok = 1;
    return vp;
}
QString VisitationContext::registerImport(const QString &module, const QString &version)
{
  VersionMap &versionHash = m_imports[module];
  QString &alias = versionHash[version];
  if (alias.isEmpty()) {
    const QString modulePart = cleanModule(module);
    const QString versionPart = cleanVersion(version);

    alias = modulePart + versionPart;

    int count = 1;
    while (m_aliases.contains(alias)) {
      alias = modulePart + versionPart + QString("_%1").arg(++count);
    }

    m_aliases.insert(alias);
  }

  return alias;
}