OpenGrok Use Cases

Update only one project unser SRC_ROOT folder

# Add project(S) to OpenGrok instance(Not indexed)
java -jar ~/program/opengrok-main/lib/opengrok.jar  \
-W ~/program/opengrok-opengrok-testapp/etc/configuration.xml \
-s ~/program/opengrok-opengrok-testapp/src \
-d ~/program/opengrok-opengrok-testapp/data/ \
-P -U localhost:1905 -w /opengrok-testapp  -a on /starfish-luna-surface-manager

# Run an indexing job for a project
READ_XML_CONFIGURATION=/vol/users/gatekeeper.tvsw/program/opengrok-opengrok-testapp/etc/configuration.xml
OpenGrok indexpart
/vol/users/gatekeeper.tvsw/program/opengrok-opengrok-testapp/src
/starfish-luna-surface-manager

 

Advertisements

Python: Tips to support both Python 2 and Python3

  1. Use ‘.decode’ and ‘str’ methods
    #Converts base64-encoded bytes to string
    import base64
    data = str(
        base64.b64decode(commit_msg_hook).decode("utf-8")
    )
    
  2. Use ‘stat’ module to change file’s permission
    import os
    import stat
    os.chmod('./run.sh', stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
    
  3. Don’t use ‘urllib2’ module. It’s only available for Python 2
    Use ‘requests’ module


Ubuntu: Start/Stop a program with ‘service’ command

s
# Step
1. Define a servicename
2. Create a script in /etc/init.d/[SERVICE_NAME]

#!/bin/bash
PIDFILE=/var/run/tomcat
DAEMON_START=/vol/users/gatekeeper.tvsw/program/apache-tomcat-7.0.55/bin/startup.sh
DAEMON_SHUTDOWN=/vol/users/gatekeeper.tvsw/program/apache-tomcat-7.0.55/bin/shutdown.sh
DAEMON_ARGS=""
case "$1" in
    start)
        start-stop-daemon --start --quiet  --chuid gatekeeper.tvsw:users --pidfile $PIDFILE --exec $DAEMON_START -- \
            $DAEMON_ARGS || return 2
        ;;
    stop)
#        start-stop-daemon --stop --quiet --oknodo  --retry=0/30/KILL/5  --pidfile $PIDFILE --name jenkins_hq
        start-stop-daemon --start --quiet  --chuid gatekeeper.tvsw:users --pidfile $PIDFILE --exec $DAEMON_SHUTDOWN -- \
            $DAEMON_ARGS || return 2
        #/home/jenkins_hq/program/apache-tomcat-7.0.57/bin/shutdown.sh
        ;;
    *)
        echo "Usage : $0 {start|stop}"
        exit 1
        ;;
esac

“$1” means a first parameter of a script. For example, if you use this command to start a service,

service tomcat start

“$1” is ‘start’

3. Use ‘update-rc.d’ in ordert to register a script you created

sudo update-rc.d tomcat defaults

#Watch out!
1. When you start/stop a service, please use ‘start-stop-daemon’ command with an option ‘–chuid’.
If you do not use that option, a service you registred is runned with root account

Get a custom field object and update its value to be displayed

In order to update a custom field’s value, please follow these stesp

  1. Get an mutable issue object
  2. Get ‘ComponentManager’ object
  3. Get ‘CustomFieldManager’ object
  4. Get an custom field object with an custom field id (like 10106)
  5. Update custome field’s value
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField

//Get an mutable issue object
MutableIssue myIssue = issue

issueKey =  myIssue.getKey()

//Get 'ComponentManager' Object
componentManager = ComponentManager.getInstance()
//Get 'CustomFieldManager' Object
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

//Get Custom Field Object
CustomField codeReview = customFieldManager.getCustomFieldObject(10106)

//Update Custom field's value.
myIssue.setCustomFieldValue(codeReview, issueKey)

passesCondition = false

You can select custom field object with its name. But it’s better to use field id numeric value because it’s not changed after a custom field was created. With this feature, you can change field name .

Get JIRA issue key when using ‘Script Runner’ groovy script in a JIRA workflow transition

If you need to get a current issue’s key value and you use ‘groovy’, you can use this code

import com.atlassian.jira.issue.Issue

Issue issue  = issue

issueKey =  issue.getKey()