Changeset 424:21b6e6fc22ab in SMSSender


Ignore:
Timestamp:
May 9, 2014 4:09:42 PM (4 years ago)
Author:
Sämy Zehnder <saemy.zehnder@…>
Branch:
default
Message:
  • Changes the way we handle version strings (no more numeric representations of alpha, beta, ...).
  • Updates the ubuntu deployment script to follow the version changes.
  • Changes the version to 3.2.1
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • common/common-base.pro

    r393 r424  
    33# The major version of the library which is required to load it.
    44# Increase this, if interfaces in libdatatypes have changed.
    5 DEFINES += LIB_COMPATIBILITY_VERSION=\\\"$${VERSION}\\\"
     5DEFINES += LIB_COMPATIBILITY_VERSION=\\\"$${FULL_VERSION}\\\"
    66
    77CONFIG += \
  • common/domain/sversion.cpp

    r382 r424  
    2323    : m_major(0)
    2424    , m_minor(0)
    25     , m_release(0)
    26     , m_build(0)
     25    , m_patch(0)
     26    , m_development(release())
    2727{
    2828}
    2929
     30SVersion::SVersion(short major, short minor, short patch)
     31    : m_major(major)
     32    , m_minor(minor)
     33    , m_patch(patch)
     34    , m_development(release())
     35{
     36}
     37SVersion::SVersion(short major, short minor, short patch,
     38                   Development development)
     39    : m_major(major)
     40    , m_minor(minor)
     41    , m_patch(patch)
     42    , m_development(development)
     43{
     44}
     45
     46/**
     47 * Reads the version from the given string. Valid versions are:
     48 * 3, 1.9, 4.2.1, 0.3~alpha3, 6.5.3~beta5, 0.0.1~rc1
     49 *
     50 * These version strings are invalid:
     51 * 3~alpha4
     52 *
     53 * @param versionStr The version string.
     54 */
    3055SVersion::SVersion(const QString &versionStr) {
    31     QStringList vl = QString(versionStr).split('.');
    32     while (vl.size() < 4) {
    33         vl.append("0");
    34     }
    35 
    36     bool valid = true;
     56    // Splits the version string into its parts.
     57    QStringList vl = versionStr.split('.');
     58
     59    m_major = m_minor = m_patch = 0;
    3760
    3861    bool v;
    39     m_major   = vl[0].toInt(&v); valid &= v;
    40     m_minor   = vl[1].toInt(&v); valid &= v;
    41     m_release = vl[2].toInt(&v); valid &= v;
    42     m_build   = vl[3].toInt(&v); valid &= v;
    43 
    44     if (!valid) {
    45         m_major = m_minor = m_release = m_build = 0;
    46     }
    47 }
    48 
    49 QString SVersion::toString(bool withBuildNo) const {
    50     QString v = QString("%1.%2.%3").arg(m_major).arg(m_minor).arg(m_release);
    51     if (withBuildNo) {
    52         v += "." + QString::number(m_build);
    53     }
    54     return v;
    55 }
    56 QString SVersion::toReadableString(const QString &pattern) const {
    57     QString v1 = QString("%1.%2").arg(m_major).arg(m_minor);
    58 
    59     QString devStage = developmentStageStr(developmentStage());
    60     if ((buildV() > 0) || !devStage.isEmpty()) {
    61         if (devStage.isEmpty()) {
    62             devStage = QObject::tr("rev");
     62    bool valid = vl.size() >= 2;
     63
     64    // Parses the major version.
     65    m_major = vl.takeFirst().toInt(&v); valid &= v;
     66
     67    // Parses the minor, patch and development parts.
     68    bool developmentParsed = false;
     69    QList<short *> parts = { &m_minor, &m_patch };
     70    foreach (short *part, parts) {
     71        if (vl.isEmpty()) {
     72            break;
    6373        }
    64 
    65         QString v2 = QString("%1%2").arg(devStage).arg(buildV());
    66         return pattern.arg(v1).arg(v2);
    67     } else {
    68         return v1;
    69     }
    70 }
    71 
    72 bool SVersion::isValid() const {
    73     return m_major | m_minor | m_release | m_build;
    74 }
    75 
    76 short SVersion::majorV() const {
    77     return m_major;
    78 }
    79 short SVersion::minorV() const {
    80     return m_minor;
    81 }
    82 short SVersion::releaseV() const {
    83     return m_release;
    84 }
    85 short SVersion::buildV() const {
    86     return m_build;
    87 }
    88 
    89 SVersion::DevelopmentStage SVersion::developmentStage() const {
    90     switch (releaseV()) {
    91         case 0: return Alpha;
    92         case 1: return Beta;
    93         case 2: return RC;
    94         case 3:
    95         default: return Release;
    96     }
    97 }
    98 QString SVersion::developmentStageStr(SVersion::DevelopmentStage developmentStage) {
    99     switch (developmentStage) {
    100         case Alpha: return QObject::tr("alpha");
    101         case Beta: return QObject::tr("beta");
    102         case RC: return QObject::tr("rc");
    103         case Release: return "";
    104         default: Q_ASSERT(false); return "";
    105     }
    106 }
    107 
    108 bool SVersion::operator==(const SVersion &other) const {
    109     return (this->majorV() == other.majorV()) &&
    110            (this->minorV() == other.minorV()) &&
    111            (this->releaseV() == other.releaseV()) &&
    112            (this->buildV() == other.buildV());
    113 }
    114 bool SVersion::operator<(const SVersion &other) const {
    115     if (this->majorV() < other.majorV()) {
    116         return true;
    117     } else if (this->majorV() == other.majorV()) {
    118         if (this->minorV() < other.minorV()) {
    119             return true;
    120         } else if (this->minorV() == other.minorV()) {
    121             if (this->releaseV() < other.releaseV()) {
    122                 return true;
    123             } else if (this->releaseV() == other.releaseV()) {
    124                 return this->buildV() < other.buildV();
     74        if (developmentParsed) {
     75            valid &= vl.isEmpty();
     76        } else {
     77            QString partStr = vl.takeFirst();
     78
     79            // Strips the development version away.
     80            QStringList versionDevelopment = partStr.split('~');
     81            valid &= versionDevelopment.size() <= 2;
     82
     83            // Parses the part version.
     84            *part = versionDevelopment[0].toInt(&v); valid &= v;
     85
     86            if (versionDevelopment.size() == 2) {
     87                // There is a development part.
     88                developmentParsed = true;
     89                const QString &devStr = versionDevelopment[1];
     90
     91                DevelopmentStatus developmentStatus;
     92                QString devVersionStr;
     93                bool found = false;
     94                foreach (DevelopmentStatus s, QList<DevelopmentStatus>({Alpha, Beta, RC})) {
     95                    const QString &devStatusStr = developmentStatusStr(s);
     96                    if (devStr.startsWith(devStatusStr)) {
     97                        found = true;
     98                        developmentStatus = s;
     99                        devVersionStr = devStr.mid(devStatusStr.size());
     100                        break;
     101                    }
     102                }
     103                valid &= found;
     104
     105                short developmentVersion = devVersionStr.toInt(&v); valid &= v;
     106                if (valid) {
     107                    m_development =
     108                            Development(developmentStatus, developmentVersion);
     109                }
    125110            }
    126111        }
    127112    }
    128113
     114    valid &= vl.isEmpty();
     115
     116    // Resets the version if the string was not valid.
     117    if (!valid) {
     118        m_major = m_minor = m_patch = 0;
     119        m_development = release();
     120    }
     121}
     122
     123QString SVersion::toString(bool withDevelopment) const {
     124    QString pattern = withDevelopment ? "%1~%2" : "%1";
     125    return toString(pattern);
     126}
     127QString SVersion::toString(const QString &pattern) const {
     128    QString versionString = QString("%1.%2.%3")
     129            .arg(m_major)
     130            .arg(m_minor)
     131            .arg(m_patch);
     132    if (m_development.status != Release) {
     133        versionString = QString(pattern)
     134                .arg(versionString)
     135                .arg(m_development.toString());
     136    }
     137
     138    return versionString;
     139}
     140/**
     141 * Returns a version string containing at least the major and minor versions.
     142 * The patch- and development versions arre appended if they are given
     143 * (>0, != release).
     144 * The given pattern determines how the development version is appened to the
     145 * main version (if available).
     146 *
     147 * @param pattern
     148 * @return
     149 */
     150QString SVersion::toMinimumString(const QString &pattern) const {
     151    QString versionStr = QString("%1.%2").arg(m_major).arg(m_minor);
     152
     153    if (m_patch > 0) {
     154        versionStr = QString("%1.%2").arg(versionStr).arg(m_patch);
     155    }
     156
     157    if (m_development.status != Release) {
     158        versionStr = QString(pattern)
     159                .arg(versionStr)
     160                .arg(m_development.toString());
     161    }
     162
     163    return versionStr;
     164}
     165
     166bool SVersion::isValid() const {
     167    return m_major | m_minor | m_patch | (m_development.status != Release);
     168}
     169
     170short SVersion::major() const {
     171    return m_major;
     172}
     173short SVersion::minor() const {
     174    return m_minor;
     175}
     176short SVersion::patch() const {
     177    return m_patch;
     178}
     179SVersion::Development SVersion::development() const {
     180    return m_development;
     181}
     182
     183bool SVersion::operator==(const SVersion &other) const {
     184    return m_major == other.m_major &&
     185           m_minor == other.m_minor &&
     186           m_patch == other.m_patch &&
     187           m_development.status == other.m_development.status &&
     188           m_development.version == other.m_development.version;
     189}
     190bool SVersion::operator<(const SVersion &other) const {
     191    if (m_major < other.m_major) {
     192        return true;
     193    } else if (m_major == other.m_major) {
     194        if (m_minor < other.m_minor) {
     195            return true;
     196        } else if (m_minor == other.m_minor) {
     197            if (m_patch < other.m_patch) {
     198                return true;
     199            } else if (m_patch == other.m_patch) {
     200                if (m_development.status < other.m_development.status) {
     201                    return true;
     202                } else if (m_development.status == other.m_development.status) {
     203                    return m_development.version < other.m_development.version;
     204                }
     205            }
     206        }
     207    }
     208
    129209    return false;
    130210}
    131211
     212
     213SVersion::Development SVersion::alpha(short developmentVersion) {
     214    return Development(Alpha, developmentVersion);
     215}
     216SVersion::Development SVersion::beta(short developmentVersion) {
     217    return Development(Beta, developmentVersion);
     218}
     219SVersion::Development SVersion::releaseCandidate(
     220        short developmentVersion) {
     221    return Development(RC, developmentVersion);
     222}
     223SVersion::Development SVersion::release() {
     224    return Development(Release, 0);
     225}
     226QString SVersion::developmentStatusStr(
     227        SVersion::DevelopmentStatus developmentStatus) {
     228    static const QStringList devStatusStr = { "alpha", "beta", "rc", "" };
     229    return devStatusStr.at(developmentStatus);
     230}
  • common/domain/sversion.h

    r382 r424  
    2525class COMMON_EXPORT SVersion {
    2626public:
    27     enum DevelopmentStage {
     27    enum DevelopmentStatus {
    2828        Alpha = 0,
    2929        Beta = 1,
     
    3131        Release = 3
    3232    };
     33    struct Development {
     34        DevelopmentStatus status;
     35        short version;
     36
     37        Development() : status(Release), version(0) {}
     38        Development(DevelopmentStatus status, short version)
     39            : status(status)
     40            , version(version)
     41        {
     42            // The version has to be 0 when the status is a release.
     43            Q_ASSERT(status != Release || version == 0);
     44        }
     45
     46        QString toString() const {
     47            if (status == Release) {
     48                return "";
     49            } else {
     50                const QString statusStr[] = { "alpha", "beta", "rc" };
     51                return QString("%1%2").arg(statusStr[status]).arg(version);
     52            }
     53        }
     54    };
     55    static Development alpha(short developmentVersion);
     56    static Development beta(short developmentVersion);
     57    static Development releaseCandidate(short developmentVersion);
     58    static Development release();
     59    static QString developmentStatusStr(DevelopmentStatus developmentStatus);
    3360
    3461public:
    35     SVersion(short major, short minor, short release, short build)
    36         : m_major(major)
    37         , m_minor(minor)
    38         , m_release(release)
    39         , m_build(build)
    40     {}
    41     SVersion(const QString &versionStr);
    4262    SVersion();
     63    SVersion(short major, short minor, short patch);
     64    SVersion(short major, short minor, short patch, Development development);
     65    explicit SVersion(const QString &versionStr);
    4366    ~SVersion() {}
    4467
    45     QString toString(bool withBuildNo = false) const;
    46     QString toReadableString(const QString &pattern = "%1 (%2)") const;
     68    QString toString(bool withDevelopment = false) const;
     69    QString toString(const QString &pattern) const;
     70    QString toMinimumString(const QString &pattern = QString("%1~%2")) const;
    4771    bool isValid() const;
    4872
    49     short majorV() const;
    50     short minorV() const;
    51     short releaseV() const;
    52     short buildV() const;
    53 
    54     DevelopmentStage developmentStage() const;
    55     static QString developmentStageStr(DevelopmentStage developmentStage);
     73    short major() const;
     74    short minor() const;
     75    short patch() const;
     76    Development development() const;
    5677
    5778    bool operator==(const SVersion &other) const;
     
    6586    short m_major;
    6687    short m_minor;
    67     short m_release;
    68     short m_build;
     88    short m_patch;
     89    Development m_development;
    6990};
    7091
  • deploy/ubuntu/deploy

    r399 r424  
    8080        fi
    8181
    82         base_version=`egrep -o "^BASE_VERSION[[:space:]]*=[[:space:]]*[[:digit:].]+" $tmp_dir/$pro | sed -e 's/BASE_VERSION[[:space:]]*=[[:space:]]*//'`
     82        base_version=`egrep -o "^VERSION[[:space:]]*=[[:space:]]*[[:digit:].]+" $tmp_dir/$pro | sed -e 's/VERSION[[:space:]]*=[[:space:]]*//'`
    8383}
    8484
    8585development_version=""
    8686get_development_version() {
    87         develop_version_tmp=`egrep -o "^DEVELOPMENT_VERSION[[:space:]]*=[[:space:]]*[[:digit:]]+" $tmp_dir/smssender.pri | sed -e 's/DEVELOPMENT_VERSION[[:space:]]*=[[:space:]]*//'`
    88         case $develop_version_tmp in
    89                 0) development_version="alpha" ;;
    90                 1) development_version="beta" ;;
    91                 2) development_version="rc" ;;
    92                 3|*) development_version="rev" ;;
    93         esac
    94 }
    95 
    96 version_revision=""
    97 get_version_revision() {
    98         version_revision=`egrep -o "^VERSION_REVISION[[:space:]]*=[[:space:]]*[[:digit:]]+" $tmp_dir/smssender.pri | sed -e 's/VERSION_REVISION[[:space:]]*=[[:space:]]*//'`
    99 
    100         proceed "The shared revision is $development_version$version_revision. Proceed?"
     87        development_version=`egrep -o "^DEVELOPMENT_VERSION[[:space:]]*=[[:space:]]*[^[:space:]#]+" ../../smssender.pri | sed -e 's/DEVELOPMENT_VERSION[[:space:]]*=[[:space:]]*//' | sed -e 's/#.*//'`
    10188}
    10289
     
    132119                echo -n "  - Reading version... "
    133120                get_base_version $pkg
    134         if [ "$development_version" == "rev" ]; then
    135             if [ "$version_revision" -ne "0" ]; then
    136                 echo "failed."
    137                 echo "When building a revision, the development version has to be 0!"
    138                 return
    139             fi
     121        get_development_version
     122        if [ "$development_version" == "" ]; then
    140123            version_suffix=""
    141124        else
    142             version_suffix="~$development_version$version_revision"
     125            version_suffix="~$development_version"
    143126        fi
    144127        pkg_with_version=${pkg_long}_$base_version$version_suffix
     
    175158                get_base_version "smssender"
    176159
    177         req_version=$base_version$version_revision
    178         if [ "$development_version" == "rev" ]; then
    179             minVersion=$base_version
     160        minVersion=$base_version$version_suffix
     161        if [ "$development_version" == "" ]; then
    180162            # 3.1 -> 3.2
    181163            maxVersion=$(echo $base_version | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{$NF=sprintf("%0*d", length($NF), $NF+1); print}')
    182164        else
    183             minVersion=$base_version~$development_version$version_revision
    184             maxVersion=$base_version~$development_version$(( $version_revision + 1 ))
     165            # ~rc4 -> ~rc5
     166            maxVersion=$base_version$(echo $version_suffix | awk '{s=gensub(/[0-9]+$/, "", "g"); v=gensub(/^[^0-9]+/, "", "g"); print sprintf("%s%d", s, ++v)}')
    185167        fi
    186168                sed -r -i -e 's/smssender(-dev)?[[:space:]]?\(>= [^)]+\)/smssender\1 (>= '$minVersion')/g' \
     
    241223#       exit 0
    242224#fi
    243 echo ""
    244 echo ""
    245 echo "***** Reading the version *****"
    246 get_development_version
    247 get_version_revision
    248225
    249226echo ""
  • frontend/gui/frontend-gui.pro

    r419 r424  
    2525}
    2626
    27 DEFINES += APP_VERSION=\\\"$${VERSION}\\\"
     27DEFINES += APP_VERSION=\\\"$${FULL_VERSION}\\\"
    2828
    2929LIBS += \
  • frontend/gui/ui/about.cpp

    r389 r424  
    3030        ui.setupUi(this);
    3131
    32     ui.lblVersion->setText(tr("version %1").arg(SVersion(qApp->applicationVersion()).toReadableString()));
     32    ui.lblVersion->setText(tr("version %1")
     33                               .arg(SVersion(qApp->applicationVersion())
     34                                        .toMinimumString()));
    3335
    3436        ui.txtAbout->setHtml(trUtf8(
     
    4648
    4749    foreach(ILibrary *lib, libraries) {
    48         ui.lstPlugins->addItem(QString("%1 (%2)").arg(lib->identificationKey()).arg(lib->version().toReadableString("%1-%2")));
     50        ui.lstPlugins->addItem(QString("%1 (%2)")
     51                                   .arg(lib->identificationKey())
     52                                   .arg(lib->version().toMinimumString()));
    4953    }
    5054    ui.lstPlugins->sortItems();
  • frontend/gui/ui/updatedialog.cpp

    r382 r424  
    2525        ui.setupUi(this);
    2626
    27     ui.lblActualVersion->setText(SVersion(qApp->applicationVersion()).toReadableString());
    28     ui.lblNewestVersion->setText(newVersion.toReadableString());
     27    ui.lblActualVersion->setText(SVersion(qApp->applicationVersion()).toMinimumString());
     28    ui.lblNewestVersion->setText(newVersion.toMinimumString());
    2929}
    3030
  • gateways/gateways.pri

    r419 r424  
    55
    66# Set the version
    7 DEFINES += LIB_VERSION=\\\"$${VERSION}\\\"
     7DEFINES += LIB_VERSION=\\\"$${FULL_VERSION}\\\"
    88
    99CONFIG += \
  • smssender.pri

    r422 r424  
    1818include(smssender.prf)
    1919
    20 BASE_VERSION = 3.3
     20VERSION = 3.2.1 # Always of the form major.minor.patch (e.g. 3.2.0)
     21DEVELOPMENT_VERSION = # alpha1, beta0, rc2 (empty for release)
    2122
    22 DEVELOPMENT_VERSION = 0 # 0=alpha; 1=beta; 2=rc; 3=release
    23 VERSION_REVISION = 0
    24 
    25 VERSION = $${BASE_VERSION}.$${DEVELOPMENT_VERSION}.$${VERSION_REVISION}
     23FULL_VERSION=$$VERSION
     24!isEmpty(DEVELOPMENT_VERSION) {
     25    FULL_VERSION=$${FULL_VERSION}~$${DEVELOPMENT_VERSION}
     26}
    2627
    2728QMAKE_CXXFLAGS *= \
     
    3839EXT_DYNAMICLIB=so
    3940win32 {
    40     VERSIONS = $$split(BASE_VERSION, ".")
     41    VERSIONS = $$split(VERSION, ".")
    4142    LIB_PREFIX =
    4243    LIB_SUFFIX = $$member(VERSIONS, 0)
Note: See TracChangeset for help on using the changeset viewer.