Add USER_PATCHES_HOME support and minor quality improvements (#2815)
This commit is contained in:
		
							parent
							
								
									da41cff1d4
								
							
						
					
					
						commit
						be37450079
					
				|  | @ -0,0 +1,55 @@ | ||||||
|  | Patches | ||||||
|  | ======= | ||||||
|  | 
 | ||||||
|  | This directory contains patches to be used by any script which uses function `call_patches` from `patches_utils.sh`. | ||||||
|  | 
 | ||||||
|  | Patches are files with extension `.sh`. Name of the patch is the name of the file without extension (so name of patch "debug.sh" is "debug"). | ||||||
|  | 
 | ||||||
|  | Patches run in the same directory as the calling script provided `patches_utils.sh` has been sourced in the calling script. | ||||||
|  | 
 | ||||||
|  | Patches are passed on to `start.sh` script using command line argument `-p` by their name. | ||||||
|  | More than one can be specified using comma as separator. | ||||||
|  | Each patch is invoked with one argument: | ||||||
|  | 
 | ||||||
|  | * `SQ_HOME`: path to the home of the started SQ instance | ||||||
|  | 
 | ||||||
|  | To enable custom patches not part of this directory, set the environment variable `SONARQUBE_USER_PATCHES_HOME` to the directory of the scripts. | ||||||
|  | If a script with the same name exists in *this* directory and under your custom script directory, | ||||||
|  | the one in the custom script directory will be used. | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | Example scripts | ||||||
|  | --------------- | ||||||
|  | 
 | ||||||
|  | ### Debug | ||||||
|  | 
 | ||||||
|  |     #!/usr/bin/env bash | ||||||
|  |     # | ||||||
|  |     # sets property sonar.web.javaAdditionalOpts in sonar.properties to activate debug | ||||||
|  |     # | ||||||
|  | 
 | ||||||
|  |     set -euo pipefail | ||||||
|  | 
 | ||||||
|  |     source scripts/property_utils.sh | ||||||
|  | 
 | ||||||
|  |     SQ_HOME=$1 | ||||||
|  | 
 | ||||||
|  |     echo "enabling debug in conf/sonar.properties, listening on port 5005" | ||||||
|  |     set_property sonar.web.javaAdditionalOpts -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 "$SQ_HOME/conf/sonar.properties" | ||||||
|  | 
 | ||||||
|  | ### Views | ||||||
|  | 
 | ||||||
|  |     #!/usr/bin/env bash | ||||||
|  |     # | ||||||
|  |     # copies the sonar-views plugin jar to the extension directory | ||||||
|  |     # | ||||||
|  | 
 | ||||||
|  |     set -euo pipefail | ||||||
|  | 
 | ||||||
|  |     source scripts/property_utils.sh | ||||||
|  | 
 | ||||||
|  |     SQ_HOME=$1 | ||||||
|  | 
 | ||||||
|  |     VIEWS_FILE=~/DEV/views/target/sonar-views-plugin-2.9-SNAPSHOT.jar | ||||||
|  |     EXT_DIR=$SQ_HOME/extensions/plugins | ||||||
|  |     cp -v "$VIEWS_FILE" "$EXT_DIR" | ||||||
|  | @ -1,52 +0,0 @@ | ||||||
| This directory contains patches to be used by the any script which use function call_patches from patches_utils.sh. |  | ||||||
| 
 |  | ||||||
| Patches are files with extension ".sh". Name of the patch is the name of the file without extension (so name of patch "debug.sh" is "debug"). |  | ||||||
| 
 |  | ||||||
| Patches run in the same directory as the calling script provided patches_utils.sh as been sourced in the calling script. |  | ||||||
| 
 |  | ||||||
| Patches are passed on to start.sh script using command line argument "-p" by their name. |  | ||||||
| More than one can be specified using a colon. |  | ||||||
| Each patch is invoked with one argument: |  | ||||||
|  * SQ_HOME: the path to the home of the started SQ instance |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| ************************************************************************************************************************ |  | ||||||
|                          sample and common scripts are provided below |  | ||||||
| ************************************************************************************************************************ |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| ******************************************      start of debug.sh      ****************************************** |  | ||||||
| #!/bin/bash |  | ||||||
| ############################### |  | ||||||
| # sets property sonar.web.javaAdditionalOpts in sonar.properties to activate debug |  | ||||||
| ############################### |  | ||||||
| 
 |  | ||||||
| set -euo pipefail |  | ||||||
| 
 |  | ||||||
| source scripts/property_utils.sh |  | ||||||
| 
 |  | ||||||
| SQ_HOME=$1 |  | ||||||
| 
 |  | ||||||
| echo "enabling debug in conf/sonar.properties, listening on port 5005" |  | ||||||
| set_property sonar.web.javaAdditionalOpts -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 $SQ_HOME/conf/sonar.properties |  | ||||||
| ******************************************       end of debug.sh       ****************************************** |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| ******************************************      start of views.sh      ****************************************** |  | ||||||
| #!/bin/bash |  | ||||||
| ############################### |  | ||||||
| # copies the sonar-views plugin jar to the extension directory |  | ||||||
| ############################### |  | ||||||
| 
 |  | ||||||
| set -euo pipefail |  | ||||||
| 
 |  | ||||||
| source scripts/property_utils.sh |  | ||||||
| 
 |  | ||||||
| SQ_HOME=$1 |  | ||||||
| 
 |  | ||||||
| VIEWS_FILE=~/DEV/views/target/sonar-views-plugin-2.9-SNAPSHOT.jar |  | ||||||
| EXT_DIR=$SQ_HOME/extensions/plugins/ |  | ||||||
| echo "copy $VIEWS_FILE to $EXT_DIR" |  | ||||||
| cp  $VIEWS_FILE $EXT_DIR |  | ||||||
| ******************************************       end of views.sh       ****************************************** |  | ||||||
|  | @ -1,29 +1,40 @@ | ||||||
| #!/bin/bash | #!/usr/bin/env bash | ||||||
| ############################### |  | ||||||
| # exposes library functions to modify properties in a property  |  | ||||||
| ############################### |  | ||||||
| 
 | 
 | ||||||
| set -euo pipefail | set -euo pipefail | ||||||
| 
 | 
 | ||||||
| PATCHES_HOME=scripts/patches | PATCHES_HOME=scripts/patches | ||||||
|  | USER_PATCHES_HOME= | ||||||
| 
 | 
 | ||||||
| # $1: name(s) of patches to call, separated by a colon | if [ "${SONARQUBE_USER_PATCHES_HOME+x}" ]; then | ||||||
| # all other arguments are passed as is to the patches |     USER_PATCHES_HOME=$SONARQUBE_USER_PATCHES_HOME | ||||||
| function call_patches() { | fi | ||||||
|   local PATCHES=$1 |  | ||||||
|   local ARGS=${@:2} |  | ||||||
|   local savedIFS=$IFS |  | ||||||
| 
 | 
 | ||||||
|   IFS=',' | # $1: name(s) of patches to call, separated by comma(s) | ||||||
|   for PATCH in $PATCHES; do | # $2: path to SonarQube installation | ||||||
|     #echo "calling $PATCHES_HOME/$PATCH.sh $ARGS" | call_patches() { | ||||||
|     echo "" |   local patches=$1 | ||||||
|     echo "******** $PATCH *******" |   local sq_home=$2 | ||||||
|     $PATCHES_HOME/$PATCH.sh $ARGS |   local patch script | ||||||
|  |   local IFS=, | ||||||
|  |    | ||||||
|  |   for patch in $patches; do | ||||||
|  |     echo | ||||||
|  |     echo "******** $patch *******" | ||||||
|  | 
 | ||||||
|  |     if [ "$USER_PATCHES_HOME" -a -x "$USER_PATCHES_HOME/$patch.sh" ]; then | ||||||
|  |         script=$USER_PATCHES_HOME/$patch.sh | ||||||
|  |     elif [ -x "$PATCHES_HOME/$patch.sh" ]; then | ||||||
|  |         script=$PATCHES_HOME/$patch.sh | ||||||
|  |     elif [ "$USER_PATCHES_HOME" ]; then | ||||||
|  |         echo "Patch $patch is not an executable script in $PATCHES_HOME or $USER_PATCHES_HOME" | ||||||
|  |         return 1 | ||||||
|  |     else | ||||||
|  |         echo "Patch $patch is not an executable script in $PATCHES_HOME" | ||||||
|  |         return 1 | ||||||
|  |     fi | ||||||
|  |     "$script" "$sq_home" | ||||||
|   done |   done | ||||||
|   IFS=$savedIFS |  | ||||||
| 
 | 
 | ||||||
|   echo "" |   echo | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue