]> source.dussan.org Git - sonarqube.git/commitdiff
Ability to release versions without build number in artifact filenames
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 20 Feb 2017 20:45:22 +0000 (21:45 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 21 Feb 2017 09:05:08 +0000 (10:05 +0100)
.travis.yml
sonar-plugin-api/pom.xml
sonar-plugin-api/src/main/resources/sonar-api-version.txt
sonar-plugin-api/src/main/resources/sq-version.txt
travis.sh

index b089bd33d91db054394ec1d7e17d9bf50d8d2756..a6f90221a1de7cc0e5cfe857420cbf209a9a6b47 100644 (file)
@@ -5,8 +5,8 @@ jdk: oraclejdk8
 script: ./travis.sh
 
 env:
-  - TARGET=CI
-  - TARGET=WEB
+  - TARGET=BUILD
+  - TARGET=WEB_TESTS
 
 matrix:
   fast_finish: true
index 2cef8a0681f5f4bc0c71e91d346ea282ce71985d..e5dd6de1916ebb62e88e9bc8b01821e08aa60e6d 100644 (file)
   <name>SonarQube :: Plugin API</name>
 
   <properties>
-    <project.version.3digits>${project.version}</project.version.3digits>
+    <!--
+     version as stored in JAR and displayed in webapp. It is
+     overridden on Travis when replacing SNAPSHOT version by
+     build unique version, for instance "6.3.0.12345".
+     -->
+    <buildVersion>${project.version}</buildVersion>
+
+    <!--
+    a truncated version on three fields is kept for backward-compatibility
+    with scanners
+    -->
+    <buildVersionOnThreeFields>${buildVersion}</buildVersionOnThreeFields>
   </properties>
 
   <dependencies>
          <artifactId>groovy-maven-plugin</artifactId>
          <executions>
            <execution>
-             <id>compute-3digits-version</id>
+             <id>compute-version-on-three-fields</id>
              <phase>generate-resources</phase>
              <goals>
                <goal>execute</goal>
              </goals>
              <configuration>
                <source><![CDATA[
-                 if (! "${project.version}".endsWith("-SNAPSHOT")) {
+                 if (! "${buildVersion}".endsWith("-SNAPSHOT")) {
                    String apiVersion
-                   // example: "6.3.0.1234". To be backward-compatible with scanners, only "6.3.0" must be kept
-                   String[] fields = "${project.version}".tokenize('.')
+                   String[] fields = "${buildVersion}".tokenize('.')
                    if (fields.length > 3) {
                      apiVersion = fields[0..2].join('.')
                    } else {
                      apiVersion = fields.join('.')
                    }
-                   project.properties['project.version.3digits'] = apiVersion
+                   project.properties['buildVersionOnThreeFields'] = apiVersion
                  }
                  ]]>
                </source>
index ad96e7cf933688c041201bffd050c5960387b558..6b7ce460f253213509b3befc4947363273139389 100644 (file)
@@ -1 +1 @@
-${project.version}
+${buildVersion}
index b9ca09a01c98d79c02d9d696da1b8269a9aa6e54..ab8c87a30ad5b318a559d51fc8381258196711e5 100644 (file)
@@ -1 +1 @@
-${project.version.3digits}
\ No newline at end of file
+${buildVersionOnThreeFields}
index a68f7a2de11fdbefc756df3352f748e03dcc613e..8e32e42eb337f3100cde3f2f7f8961196e68399c 100755 (executable)
--- a/travis.sh
+++ b/travis.sh
@@ -1,5 +1,4 @@
 #!/bin/bash
-
 set -euo pipefail
 
 function installPhantomJs {
@@ -16,26 +15,92 @@ function installPhantomJs {
   export PATH=$PHANTOMJS_HOME/bin:$PATH
 }
 
+#
+# A (too) old version of JDK8 is installed by default on Travis
+#
+function installJdk8 {
+  echo "Setup JDK 1.8u92"
+  mkdir -p ~/jvm
+  pushd ~/jvm > /dev/null
+  if [ ! -d "jdk1.8.0_92" ]; then
+    wget -c --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u92-b14/jdk-8u92-linux-x64.tar.gz
+    tar xzf jdk-8u92-linux-x64.tar.gz
+    rm jdk-8u92-linux-x64.tar.gz
+  fi
+  popd > /dev/null
+  export JAVA_HOME=~/jvm/jdk1.8.0_92
+  export PATH=$JAVA_HOME/bin:$PATH
+}
+
+#
+# Replaces the SNAPSHOT version by a version identifying the build.
+#
+# Exports the variables:
+# - INITIAL_VERSION: version as defined in pom.xml
+# - PROJECT_VERSION: build version. The name of this variable is important because
+#   it's used by QA when extracting version from Artifactory build info.
+#
+# The build version is composed of 4 fields, including the semantic version and
+# the build number provided by Travis.
+#
+# Example
+# Before: 6.3-SNAPSHOT
+# After:  6.3.0.12345
+#
+# Exception: GA release like "6.3" is kept as-is.
+#
+function fixBuildVersion {
+  export INITIAL_VERSION=`maven_expression "project.version"`
+
+  # remove suffix like -SNAPSHOT or -RC
+  without_suffix=`echo $INITIAL_VERSION | sed "s/-.*//g"`
+
+  # set the third field to '0' if missing, for example 6.3 becomes 6.3.0
+  IFS=$'.'
+  fields_count=`echo $without_suffix | wc -w`
+  unset IFS
+  if [ $fields_count -lt 3 ]; then
+    without_suffix="$without_suffix.0"
+  fi
+
+  export PROJECT_VERSION="$without_suffix.$TRAVIS_BUILD_NUMBER"
+
+  echo "Source Version: $INITIAL_VERSION"
+  echo "Build Version : $PROJECT_VERSION"
+
+  if [[ "$INITIAL_VERSION" == *"-"* ]]; then
+    # SNAPSHOT or RC
+    mvn org.codehaus.mojo:versions-maven-plugin:2.2:set -DnewVersion=$PROJECT_VERSION -DgenerateBackupPoms=false -B -e
+  fi
+}
+
+#
+# Configure Maven settings and install some script utilities
+#
 function configureTravis {
   mkdir ~/.local
   curl -sSL https://github.com/SonarSource/travis-utils/tarball/v33 | tar zx --strip-components 1 -C ~/.local
   source ~/.local/bin/install
 }
 configureTravis
-. installJDK8
-
-./clock.sh &
 
 case "$TARGET" in
 
-CI)
-  export MAVEN_OPTS="-Xmx1G -Xms128m"
-  MAVEN_OPTIONS="-Dmaven.test.redirectTestOutputToFile=false -Dsurefire.useFile=false -B -e -V"
+BUILD)
+
+  # Hack to keep job alive even if no logs during more than 10 minutes.
+  # That can occur when uploading sonarqube.zip to Artifactory.
+  ./clock.sh &
+
+  installJdk8
+  fixBuildVersion
 
-  INITIAL_VERSION=`maven_expression "project.version"`
+  # Minimal Maven settings
+  export MAVEN_OPTS="-Xmx1G -Xms128m"
+  MAVEN_ARGS="-Dmaven.test.redirectTestOutputToFile=false -Dsurefire.useFile=false -B -e -V -DbuildVersion=$PROJECT_VERSION"
 
   if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
-    echo 'Analyse and trigger QA of master branch'
+    echo 'Build and analyze master'
 
     # Fetch all commit history so that SonarQube has exact blame information
     # for issue auto-assignment
@@ -44,31 +109,23 @@ CI)
     # For this reason errors are ignored with "|| true"
     git fetch --unshallow || true
 
-    . set_maven_build_version $TRAVIS_BUILD_NUMBER
-
     mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy sonar:sonar \
-          $MAVEN_OPTIONS \
+          $MAVEN_ARGS \
           -Pdeploy-sonarsource,release \
           -Dsonar.host.url=$SONAR_HOST_URL \
           -Dsonar.login=$SONAR_TOKEN \
           -Dsonar.projectVersion=$INITIAL_VERSION
 
   elif [[ "$TRAVIS_BRANCH" == "branch-"* ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
-    echo 'release branch: trigger QA, no analysis'
-
-    . set_maven_build_version $TRAVIS_BUILD_NUMBER
+    echo 'Build release branch'
 
-    mvn deploy \
-        $MAVEN_OPTIONS \
-        -Pdeploy-sonarsource,release
+    mvn deploy $MAVEN_ARGS -Pdeploy-sonarsource,release
 
   elif [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ -n "${GITHUB_TOKEN:-}" ]; then
-    echo 'Internal pull request: trigger QA and analysis'
-
-    . set_maven_build_version $TRAVIS_BUILD_NUMBER
+    echo 'Build and analyze internal pull request'
 
     mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy sonar:sonar \
-        $MAVEN_OPTIONS \
+        $MAVEN_ARGS \
         -Dsource.skip=true \
         -Pdeploy-sonarsource \
         -Dsonar.analysis.mode=preview \
@@ -79,19 +136,16 @@ CI)
         -Dsonar.login=$SONAR_TOKEN
 
   else
-    echo 'Feature branch or external pull request: no QA, no analysis. Skip sources'
+    echo 'Build feature branch or external pull request'
 
-    mvn install \
-        $MAVEN_OPTIONS \
-        -Dsource.skip=true
+    mvn install $MAVEN_ARGS -Dsource.skip=true
   fi
 
-
   installPhantomJs
   ./run-integration-tests.sh "Lite" "" -Dorchestrator.browser=phantomjs
   ;;
 
-WEB)
+WEB_TESTS)
   set +u
   source ~/.nvm/nvm.sh && nvm install 6
   curl -o- -L https://yarnpkg.com/install.sh | bash