OpenGrok是一个快速、便于使用的源代码搜索与对照引擎。它帮助你搜索,对照,定位你的源代码树。它能够识别各种程序源文件格式和版本控制历史记录。
搭建环境依赖:
1.opengrok-1.1-rc33.tar.gz PS:rc35后脚本开始从shell切换到python
2.universal-ctags
3.apache-tomcat-8.5.32
4.OpenJDK 1.8
1.OpenJDK 1.8安装
参考https://blog.csdn.net/dgj8300/article/details/81625992进行安装,安装完成后,执行java -version进行版本查询
Desktop-System:~/ctags/ctags-master$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-2~14.04-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
Desktop-System:~/ctags/ctags-master$
2.universal-ctags安装
在https://github.com/universal-ctags/ctags下载压缩包ctags-master.zip,放到linux下:
apt-get install install autoconf automake libtool pkg-config
zip ctags-master.zip
cd ctags-master/
./autogen.sh
./configure --prefix=/where/you/want # defaults to /usr/local
Make
sudo make install # may require extra privileges depending on where to install
Desktop-System:~/ctags/ctags-master$ ctags --help
Universal Ctags 0.0.0, Copyright (C) 2015 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
Compiled: Aug 10 2018, 15:44:23
URL: https://ctags.io/
Optional compiled features: +wildcards, +regex, +iconv, +option-directory
//最后将生成的目标文件copy到 /usr/local/bin/:
cp /opt/ctags/bin/* /usr/local/bin/
3.apache-tomcat-8.5.32安装
参考:https://blog.csdn.net/gatieme/article/details/53073548
下载网站:http://tomcat.apache.org/download-80.cgi
manager配置:https://blog.csdn.net/u012326462/article/details/81038660
https://www.cnblogs.com/centos2017/p/9257593.html
登陆权限设置/开机启动/错误处理:https://blog.csdn.net/dgj8300/article/details/85064718
注意java环境的添加,需要在/opt/apache-tomcat/bin下:
vi setclasspath.sh
#---------------------
# java path
#---------------------
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 #根据个人openjdk环境进行配置
JRE_HOME=$JAVA_HOME/jre
JAVA_BIN=$JAVA_HOME/bin
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
#PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASSPATH
4.opengrok-1.1-rc33 安装
从https://github.com/oracle/opengrok/releases下载
opengrok-1.1-rc33.tar.gz,放到/opt/目录下,
tar xzvf opengrok-1.1-rc33.tar.gz /opt/
mv opengrok-0.11.1 opengrok
cd opengrok/bin/
vi opengrok.py
需要支持多项目,本人对OpenGrok脚本进行了修改,修改如下(以版本opengrok-1.1-rc33为例):
主要修改了缓存的位置以及生成项目文件时的路径,这样修改,对于多项目方便管控。
#!/bin/sh
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# See LICENSE.txt included in this distribution for the specific
# language governing permissions and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at LICENSE.txt.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
# Portions Copyright (c) 2017-2018, Chris Fraire <cfraire@me.com>.
#
#
# opengrok.jar wrapper for initial setup and cron job updating.
# Please see the Usage() function below for supported environment variables.
#
#
# Print usage to stdout and exit.
#
#增加tomcat安装路径到环境变量OPENGROK_WAR_TARGET_TOMCAT
export OPENGROK_WAR_TARGET_TOMCAT=/opt/apache-tomcat
Usage()
{
progname=`basename $0`
exec >&2
echo ""
echo "Usage: ${progname} <bootstrap|deploy|update|updateQuietly|updateDesc>"
echo " ${progname} index [<directory>]"
echo " ${progname} indexpart <directory_1> [<directory_2> ..]"
echo " ${progname} clearHistory <src_root> <repository_name>"
echo " ${progname} usage|help [--detailed]"
echo ""
echo " The \"indexpart\" assumes that it will be run with configuration"
echo " pointed to via the OPENGROK_READ_XML_CONFIGURATION environment"
echo " variable."
echo ""
if [ "$1" != "--detailed" ]; then
echo " Optional environment variables:"
echo " OPENGROK_CONFIGURATION - location of your configuration"
echo " e.g. $ OPENGROK_CONFIGURATION=/var/opengrok/myog.conf \\"
echo " ${0} ... "
echo ""
echo " Use help --detailed, or see the code for more information on"
echo " configuration options and variables."
else
cat <<END
Supported Environment Variables:
- OPENGROK_CONFIGURATION User Configuration (Shell Script)
- OPENGROK_NON_INTERACTIVE Suppress Progress and Warnings Messages (*)
- OPENGROK_STANDARD_ENV Run Time Shell Environment (Shell Script)
Supported Environment Variables for configuring the default setup:
- OPENGROK_DISTRIBUTION_BASE Base Directory of the OpenGrok Distribution
- OPENGROK_INSTANCE_BASE Base Directory of the OpenGrok User Data Area
- OPENGROK_SRC_ROOT directory with files to be indexed
- OPENGROK_DATA_ROOT Base Directory where index and cache files are
generated
- OPENGROK_CTAGS Full path to Exuberant or Universal CTags binary
- OPENGROK_CTAGS_OPTIONS_FILE Full path to file with extra command line
options for CTags program (for its --options
switch). Default is OPENGROK_INSTANCE_BASE/etc/ctags.config
- OPENGROK_MANDOC Full path to mandoc(1) binary
- OPENGROK_LOCKING Locking mode on|off|simple|native (default off)
("on" is an alias for "simple")
- JAVA_HOME Full Path to Java Installation Root
- JAVA Full Path to java binary (to enable 64bit JDK)
- JAVA_OPTS Java options (e.g. for JVM memory increase
or enabling server JDK)
JAVA_OPTS=-Xmx2048m is the default!
- OPENGROK_APP_SERVER Application Server ("Tomcat", "Glassfish" or
"Resin")
- OPENGROK_WAR_TARGET_TOMCAT Tomcat Specific WAR Target Directory
- OPENGROK_WAR_TARGET_GLASSFISH Glassfish Specific WAR Target Directory
- OPENGROK_WAR_TARGET_RESIN Resin Specific WAR Target Directory
- OPENGROK_WAR_TARGET Fallback WAR Target Directory
- OPENGROK_TOMCAT_BASE Base Directory for Tomcat (contains webapps)
- OPENGROK_GLASSFISH_BASE Base Directory for Glassfish (contains domains)
- OPENGROK_GLASSFISH_DOMAIN Preferred Glassfish Domain Name
- OPENGROK_RESIN_BASE Base Directory for Resin (contains webapps)
- OPENGROK_VERBOSE Enable Verbose Mode in opengrok.jar (*)
- OPENGROK_PROGRESS Shows progress in %(percentage) of working
through project. It's good to have Verbose
Mode enabled too. (*)
- OPENGROK_RENAMED_FILES_HISTORY Get full history of renamed files for SCMs
that support it (Git, Mercurial). When set to
on, the indexing is slower, especially in the
presence of lots of renamed files in the
repository.
on|off (default off) (^)
- OPENGROK_GENERATE_HISTORY Influence history cache generation
Following values are recognized:
on - enabled (default) (^)
off - disabled for indexing and UI
dirbased - indexing enabled only for
repos which can fetch history
for directory
local - for local repos only
uionly - enabled for UI only
- OPENGROK_ENABLE_PROJECTS Enable projects, where every directory in
SRC_ROOT is considered a separate project.
on|off (default on) (^)
- OPENGROK_DEFAULT_PROJECTS List of projects (relative to source root,
starting with slash) separated with comma to be
selected by default in the UI.
- OPENGROK_IGNORE_PATTERNS Set ignored patterns for indexer to skip.
OPENGROK_IGNORE_PATTERNS="-i dummy"
OPENGROK_IGNORE_PATTERNS="-i f:dummy"
OPENGROK_IGNORE_PATTERNS="-i d:dummy"
Multiple entries can be joined together:
"-i dummy -i d:tmp -i f:dummy"
- OPENGROK_ASSIGNMENTS Assign/Unassign specialized analyzers using
(.ext|prefix.):(-|Analyzer) syntax. E.g.,
.lib:Ignorant,Makefile.:- to set files ending
with .LIB (case-insensitive) to use the
IgnorantAnalyzerFactory (case-sensitive due to
Java limitation), and to clear special
handling for files starting with MAKEFILE
(case-insensitive and no full-stop)
- OPENGROK_SCAN_REPOS Disable Scan for repositories (*)
- OPENGROK_SCAN_DEPTH How deep should scanning for repos go
(by default 3 directories from SRC_ROOT)
- OPENGROK_WEBAPP_CFGADDR Web application URI to send configuration to
(use "none" to avoid sending it to web app)
- OPENGROK_WEBAPP_CONTEXT Context URL of the OpenGrok webapp
(by default /source).
- OPENGROK_WPREFIX Disable wildcard prefix search query support (*)
- OPENGROK_TAG Enable parsing of revision tags into the History
view
- OPENGROK_READ_XML_CONFIGURATION file with read only configuration
- temporary workaround for bug # 327
- OPENGROK_FLUSH_RAM_BUFFER_SIZE="-m 16" - set RAM buffer size for flushing,
default is 16MB per thread, you might try to
increase it to 256MB, but do increase JVM to
4/8/16GB ! Lucene defaults to 8 threads.
Increase JVM memory as noted using JAVA_OPTS
- OPENGROK_PARALLELISM Default is 0, meaning that parallelism is
determined from available processors.
- OPENGROK_LOGGER_CONFIG_PATH Set path to custom logging.properties file.
- OPENGROK_SUBVERSION_USERNAME Name of the user that should be used for
fetching the history from subversion
- OPENGROK_SUBVERSION_PASSWORD Password of the user that should be used for
fetching the history from subversion
- OPENGROK_PROFILER Pause to await user input for profiling. (*)
Notes:
(*) Any Non-Empty String will enable these options
(^) on|true|1 are synonyms, as are off|false|0
Supported Operating Systems:
- Solaris 11 (SunOS 5.11)
- Debian (Linux)
Supported Deployment Engines:
- Tomcat 8
- Glassfish
- Resin
END
fi
exit 1
}
#
# Runtime Configuration
#
if [ -x "/bin/uname" ]; then
OS_NAME="`/bin/uname -s`"
OS_VERSION="`/bin/uname -r`"
elif [ -x "/usr/bin/uname" ]; then
OS_NAME="`/usr/bin/uname -s`"
OS_VERSION="`/usr/bin/uname -r`"
else
echo "Cannot determine operating system version"
exit 1
fi
SCRIPT_DIRECTORY=`dirname "${0}"`
export SCRIPT_DIRECTORY=`cd "${SCRIPT_DIRECTORY}"; pwd -P`
#
# Default Instance Configuration
#
DefaultInstanceConfiguration()
{
# Use the built-in defaults. This section can be copied to its own
# file and tailored to your local requirements. Then simply set
# OPENGROK_CONFIGURATION=/path/to/your/configuration, before using
# this wrapper. It will save you hand editing in your settings
# on each new release. A sample cron(1M) entry might look like:
# 15 0 * * * OPENGROK_CONFIGURATION=/pkgs/etc/OpenGrok.sh /pkgs/sbin/OpenGrok updateQuietly
# Note: It is not really possible to ever provided defaults for
# these values which will run in every UNIX-like environment.
# So I have provided a set which are functional for a given
# environment on which you can based you own configuration.
# This has been updated to support more environment variables and
# operating systems, if you have any reasonably generic
# improvements please feel free to submit a patch.
#OPENGROK_INSTANCE_BASE="${OPENGROK_INSTANCE_BASE:-/var/opengrok}"
#修改构建项目时的缓存、日志保存路径为/opt/opengrok/cache/${WAR_NAME}
OPENGROK_INSTANCE_BASE="/opt/opengrok/cache/${WAR_NAME}"
#OPENGROK_WEBAPP_CFGADDR="http://localhost:8080/${WAR_NAME}"
LOGGER_CONFIG_FILE="logging.properties"
if [ -z "${OPENGROK_DISTRIBUTION_BASE}" ]
then
if [ -d "${SCRIPT_DIRECTORY}/dist" -a \
-f "${SCRIPT_DIRECTORY}/dist/opengrok.jar" -a \
-f "${SCRIPT_DIRECTORY}/dist/${WAR_NAME}.war" \ #默认*.war以${WAR_NAME}命名
]
then
# Handle Developer Build Environments
OPENGROK_DISTRIBUTION_BASE="${SCRIPT_DIRECTORY}/dist"
LOGGER_CONF_SOURCE="${SCRIPT_DIRECTORY}/${LOGGER_CONFIG_FILE}"
else
# Handle Binary Distributions
OPENGROK_DISTRIBUTION_BASE="${SCRIPT_DIRECTORY}/../lib"
LOGGER_CONF_SOURCE="${OPENGROK_DISTRIBUTION_BASE}/../doc/${LOGGER_CONFIG_FILE}"
fi
fi
# REQUIRED: Source Code/Repository Root
# (your source code or the root of all repositories)
if [ -n "${OPENGROK_SRC_ROOT}" ]; then
SRC_ROOT="${OPENGROK_SRC_ROOT}"
else
SRC_ROOT="${OPENGROK_INSTANCE_BASE}/src"
fi
# REQUIRED: OpenGrok Generate Data Root
# (for Lucene index and hypertext cross-references)
# This area is rebuilt by "update" / "updateQuietly"
if [ -n "${OPENGROK_DATA_ROOT}" ]; then
DATA_ROOT="${OPENGROK_DATA_ROOT}"
else
DATA_ROOT="${OPENGROK_INSTANCE_BASE}/data"
fi
# OPTIONAL: User Provided Source Path to Description Mapping
# (Tab Separated Value)
# (The user maintained source of the generated EftarFile file)
PATH_DESC="${OPENGROK_INSTANCE_BASE}/etc/paths.tsv"
# REQUIRED: XML Configuration
# (the configuration used by Web/GUI interfaces)
XML_CONFIGURATION="${OPENGROK_INSTANCE_BASE}/etc/configuration.xml"
# OPTIONAL: read only XML configuration
READ_XML_CONFIGURATION="${OPENGROK_READ_XML_CONFIGURATION:-}"
if [ -n "${READ_XML_CONFIGURATION}" ] ; then
READ_XML_CONF="-R ${READ_XML_CONFIGURATION}"
fi
# REQUIRED: Logger Configuration
if [ -n "${OPENGROK_LOGGER_CONFIG_PATH}" ]; then
if [ ! -f "${OPENGROK_LOGGER_CONFIG_PATH}" ]; then
echo "File ${OPENGROK_LOGGER_CONFIG_PATH} does not exist"
exit 1
fi
LOGGER_CONFIG_PATH=${OPENGROK_LOGGER_CONFIG_PATH}
else
LOGGER_CONFIG_PATH="${OPENGROK_INSTANCE_BASE}/${LOGGER_CONFIG_FILE}"
fi
LOGGER_PROPERTIES="-Djava.util.logging.config.file=${LOGGER_CONFIG_PATH}"
# REQUIRED: Java Archive of OpenGrok (Installation Location)
OPENGROK_JAR="${OPENGROK_DISTRIBUTION_BASE}/opengrok.jar"
# REQUIRED(deploy): Web Archive of OpenGrok (Distribution Location)
# (user building from source code will find this and other key
# files in the "dist" directory after the build is completed)
OPENGROK_DIST_WAR="${OPENGROK_DISTRIBUTION_BASE}/${WAR_NAME}.war" #默认*.war以${WAR_NAME}命名
# REQUIRED: Exuberant or Universal CTags
OPENGROK_CTAGS="${OPENGROK_CTAGS:-`FindCtags`}"
# OPTIONAL: supply extra command line options to CTags program
if [ -n "${OPENGROK_CTAGS_OPTIONS_FILE}" ]; then
CTAGS_OPTIONS_FILE="${OPENGROK_CTAGS_OPTIONS_FILE}"
elif [ -r "${OPENGROK_INSTANCE_BASE}/etc/ctags.config" ]; then
CTAGS_OPTIONS_FILE="${OPENGROK_INSTANCE_BASE}/etc/ctags.config"
fi
# REQUIRED: Java Home
JAVA_HOME="${JAVA_HOME:-`FindJavaHome`}"
export JAVA_HOME
# REQUIRED: Java Virtual Machine
JAVA="${JAVA:-$JAVA_HOME/bin/java}"
# DEVELOPMENT: Debug option, if enabled current indexer will listen on the
# port 8010 until a debugger connects
#JAVA_DEBUG="-agentlib:jdwp=transport=dt_socket"
#JAVA_DEBUG="$JAVA_DEBUG,server=y,address=8010,suspend=y"
# OPTIONAL: Ignore these patterns as names of files or directories
#OPENGROK_IGNORE_PATTERNS="-i dummy"
# OPTIONAL: Enable Projects
# (Every directory in SRC_ROOT is considered a separate project)
OPENGROK_ENABLE_PROJECTS="${OPENGROK_ENABLE_PROJECTS:-true}"
case "$OPENGROK_ENABLE_PROJECTS" in
off|false|0) ENABLE_PROJECTS="" ;;
*) ENABLE_PROJECTS="-P" ;;
esac
if [ -n "${ENABLE_PROJECTS}" ]
then
DEFAULT_PROJECTS=""
for proj in $( IFS=","; echo ${OPENGROK_DEFAULT_PROJECTS} )
do
DEFAULT_PROJECTS="-p $proj ${DEFAULT_PROJECTS}"
done
fi
# OPTIONAL: Scanning Options (for Mercurial repositories)
SCAN_FOR_REPOSITORY="-S"
if [ -n "${OPENGROK_SCAN_REPOS}" ]
then
SCAN_FOR_REPOSITORY=""
fi
# OPTIONAL: remote repository support (CVS or SVN) [on by default]
OPENGROK_GENERATE_HISTORY="${OPENGROK_GENERATE_HISTORY:-on}"
case "$OPENGROK_GENERATE_HISTORY" in
off|false|0) GENERATE_HISTORY="-r off" ;;
on|true|1) GENERATE_HISTORY="-r on -H" ;;
*) GENERATE_HISTORY="-r $OPENGROK_GENERATE_HISTORY -H" ;;
esac
# OPTIONAL: Detect historical renamings if supported [off by default]
OPENGROK_RENAMED_FILES_HISTORY="${OPENGROK_RENAMED_FILES_HISTORY:-off}"
case "$OPENGROK_RENAMED_FILES_HISTORY" in
on|true|1) RENAMED_FILES_HISTORY="--renamedHistory on" ;;
*) RENAMED_FILES_HISTORY="--renamedHistory off" ;;
esac
# OPTIONAL: override depth of scanning for repositories
if [ -n "${OPENGROK_SCAN_DEPTH}" ]
then
SCAN_DEPTH="--depth ${OPENGROK_SCAN_DEPTH}"
fi
# OPTIONAL: Allow Leading Wildcard Searches
# (default: on)
LEADING_WILDCARD="--leadingWildCards on"
if [ -n "${OPENGROK_WPREFIX}" ]
then
LEADING_WILDCARD=""
fi
# OPTIONAL: Web Site Look & Feel
# (Options: default)
# Note the quoting requirements)
#SKIN='--style default'
# OPTIONAL: Configuration Address (host:port)
WEBAPP_CONFIG=""
if [ -n "${OPENGROK_WEBAPP_CFGADDR}" ]; then
WEBAPP_CONFIG_ADDRESS=${OPENGROK_WEBAPP_CFGADDR}
if [ "${OPENGROK_WEBAPP_CFGADDR}" = "none" ]; then
WEBAPP_CONFIG_ADDRESS=""
fi
else
WEBAPP_CONFIG_ADDRESS="http://localhost:8080/${WAR_NAME}" #以${WAR_NAME}命名
fi
if [ -n "${WEBAPP_CONFIG_ADDRESS}" ]; then
WEBAPP_CONFIG="-U ${WEBAPP_CONFIG_ADDRESS}"
fi
# OPTIONAL: JVM Options
JAVA_OPTS="${JAVA_OPTS:--Xmx2048m}"
# OPTIONAL: Full Path to History Utilities
BK="`Which bk`"
HG="`Which hg`"
CVS="`Which cvs`"
SVN="`Which svn`"
SCCS="`Which sccs`"
CLEARCASE="`Which cleartool`"
GIT="`Which git`"
P4="`Which p4`"
MTN="`Which mtn`"
BZR="`Which bzr`"
# OPTIONAL: Override Built-in Properties
# Assumption: We should not set properties to the empty string
PROPERTIES="\
${BK:+-Dorg.opensolaris.opengrok.history.BitKeeper=$BK} \
${HG:+-Dorg.opensolaris.opengrok.history.Mercurial=$HG} \
${CVS:+-Dorg.opensolaris.opengrok.history.cvs=$CVS} \
${SVN:+-Dorg.opensolaris.opengrok.history.Subversion=$SVN} \
${SCCS:+-Dorg.opensolaris.opengrok.history.SCCS=$SCCS} \
${CLEARCASE:+-Dorg.opensolaris.opengrok.history.ClearCase=$CLEARCASE} \
${GIT:+-Dorg.opensolaris.opengrok.history.git=$GIT} \
${P4:+-Dorg.opensolaris.opengrok.history.Perforce=$P4} \
${MTN:+-Dorg.opensolaris.opengrok.history.Monotone=$MTN} \
${BZR:+-Dorg.opensolaris.opengrok.history.Bazaar=$BZR} \
"
# OPTIONAL: Show revision tags in History view.
# Turn this off if you want to increase indexing performance a bit
# (default: off)
if [ -n "${OPENGROK_TAG}" ]
then
HISTORY_TAGS="-G"
fi
# DELIVERED: An update program for EftarFile
# Usage: <class> inputFile [inputFile ...] outputFile
# EftarFile == An Extremely Fast Tagged Attribute Read-only File System
EFTAR_UPDATE="org.opensolaris.opengrok.web.EftarFile"
# HARDCODED: Generated EftarFile (See web/*.jsp)
EFTAR_OUTPUT_FILE="${DATA_ROOT}/index/dtags.eftar"
# Be Quiet? (set indirectly by command line arguments in the main program)
#QUIET=""
# or alternatively, Be Verbose!
#VERBOSE="-v"
if [ -n "${OPENGROK_VERBOSE}" ]
then
VERBOSE="-v"
QUIET=""
fi
if [ -n "${OPENGROK_PROGRESS}" ]
then
PROGRESS="--progress"
fi
if [ "$OPENGROK_ASSIGNMENTS" != "" ]; then
ASSIGNMENTS="`echo $OPENGROK_ASSIGNMENTS | sed 's/[:space:]+/_/g'`"
ASSIGNMENTS="-A `echo $ASSIGNMENTS | sed 's/,/ -A /g'`"
fi
if [ -f "${XML_CONFIGURATION}" ]; then
CHK_INDEX_CONF="${XML_CONFIGURATION}"
fi
}
#
# Helper Functions - Logging
#
# In general, non-interactive use like cron jobs and automated
# installation environments should not generate unnecessary
# progress information or warnings, as usage and configuration
# will have generally been debugged prior to automation.
#
Progress()
{
if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
then
echo "${@}"
fi
}
Warning()
{
if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
then
echo "WARNING: ${@}" 1>&2
fi
}
Error()
{
echo "ERROR: ${@}" 1>&2
}
FatalError()
{
exec >&2
echo ""
echo "FATAL ERROR: ${@} - Aborting!"
echo ""
${DO} exit 2
}
#
# Helper Functions - Autodetection of Runtime Environment
#
Which()
{
path="`which ${1} 2>/dev/null`"
if [ -x "${path}" ]
then
echo "${path}"
fi
}
LocateBinary() {
for f in $@
do
file=`which "$f" 2>/dev/null | grep -v '^no '`
if test -n "$file" -a -x "$file"
then
echo $file
return 0
fi
done
echo ""
return 1
}
FindCtags()
{
#
# Search for Exuberant ctags intelligently, skipping
# over other ctags implementations.
#
binary=""
found=0
for program in ctags-exuberant exctags ctags; do
for path in `echo $PATH | tr ':' '\n'`; do
if [ -x "$path/$program" ]; then
binary="$path/$program"
# Verify that this tool is or is based on Exuberant Ctags.
$binary --version 2>&1 | grep "Exuberant Ctags" > /dev/null
if [ $? -eq 0 ]; then
found=1
break
fi
fi
done
if [ $found -eq 1 ]; then
break;
fi
done
if [ $found -ne 1 ]; then
Error "Unable to determine Exuberant/Universal CTags command name" \
"for ${OS_NAME} ${OS_VERSION}"
return
fi
echo ${binary}
}
FindJavaHome()
{
javaHome=""
case "${OS_NAME}:${OS_VERSION}" in
SunOS:5.10) javaHome="/usr/jdk/instances/jdk1.7.0" ;;
SunOS:5.11) javaHome="/usr/jdk/latest" ;;
SunOS:5.12) javaHome="/usr/jdk/latest" ;;
Darwin:*) javaHome=`/usr/libexec/java_home` ;;
Linux:*)
if [ -f /etc/alternatives/java ]
then
javaHome=`ls -l /etc/alternatives/java | cut -f 2 -d \> `
javaHome=`dirname $javaHome`
javaHome=`dirname $javaHome`
fi
;;
esac
if [ -z "${javaHome}" ]
then
Error "Unable to determine Java 7 Home" \
"for ${OS_NAME} ${OS_VERSION}"
return
fi
if [ ! -d "${javaHome}" ]
then
Error "Missing Java Home ${javaHome}"
return
fi
echo "${javaHome}"
}
FindApplicationServerType()
{
# Use this function to determine which environment the deploy the
# web application function into. Some users (especially
# developers) will have many deployment environments or will wish
# to specify directly the application server to deploy to.
# Either use the environment variable OPENGROK_APP_SERVER or
# reimplement this function in your configuration file (as
# specified by OPENGROK_CONFIGURATION)
if [ -n "${OPENGROK_APP_SERVER}" ]
then
echo "${OPENGROK_APP_SERVER}"
return
fi
# This implementation favours Tomcat, but needs a lot of work,
# especially if Glassfish is preferred or it is under the control
# of SMF (Service Management Facility)
# Maybe a better implementation would be to call Application
# Server specific WAR Directory and see if they exist.
if [ -d "/var/tomcat8/webapps" \
-o -d "/var/lib/tomcat8/webapps" \
]
then
echo "Tomcat"
return
fi
if [ -x "/etc/init.d/appserv" -a -d "/var/appserver/domains" ]
then
echo "Glassfish"
return
fi
if [ -d "/etc/resin" -o -d "/usr/local/share/resin" ]
then
echo "Resin"
return
fi
# Assume Tomcat
echo "Tomcat"
}
DetermineWarDirectoryTomcat()
{
if [ -n "${OPENGROK_WAR_TARGET_TOMCAT}" ]
then
echo "${OPENGROK_WAR_TARGET_TOMCAT}"
return
elif [ -n "${OPENGROK_WAR_TARGET}" ]
then
echo "${OPENGROK_WAR_TARGET}"
return
fi
for prefix in \
${OPENGROK_TOMCAT_BASE} \
/var/lib/tomcat8 \
/var/tomcat8
do
if [ -d "${prefix}/webapps" ]
then
echo "${prefix}/webapps"
return
fi
done
}
DetermineWarDirectoryGlassfish()
{
if [ -n "${OPENGROK_WAR_TARGET_GLASSFISH}" ]
then
echo "${OPENGROK_WAR_TARGET_GLASSFISH}"
return
elif [ -n "${OPENGROK_WAR_TARGET}" ]
then
echo "${OPENGROK_WAR_TARGET}"
return
fi
for prefix in \
${OPENGROK_GLASSFISH_BASE} \
/var/appserver
do
if [ -d "${prefix}/domains" ]
then
if [ -z "${domainDirectory}" ]
then
domainDirectory="${prefix}/domains"
fi
fi
done
if [ -z "${domainDirectory}" ]
then
return
fi
# User Specified Domain
if [ -n "${OPENGROK_GLASSFISH_DOMAIN}" ]
then
directory="${domainDirectory}/${OPENGROK_GLASSFISH_DOMAIN}/autodeploy"
if [ ! -d "${directory}" ]
then
FatalError "Missing Specified Glassfish Domain " \
"${OPENGROK_GLASSFISH_DOMAIN}"
fi
echo "${directory}"
return
fi
# Arbitrary Domain Selection
firstDomain=`ls -1 ${domainDirectory} | head -1`
if [ -z "${firstDomain}" ]
then
FatalError "Failed to dynamically determine Glassfish Domain from " \
"${domainDirectory}"
fi
echo "${domainDirectory}/${firstDomain}/autodeploy"
}
DetermineWarDirectoryResin()
{
if [ -n "${OPENGROK_WAR_TARGET_RESIN}" ]
then
echo "${OPENGROK_WAR_TARGET_RESIN}"
return
elif [ -n "${OPENGROK_WAR_TARGET}" ]
then
echo "${OPENGROK_WAR_TARGET}"
return
fi
for prefix in \
${OPENGROK_RESIN_BASE} \
/var/resin \
/opt/resin
do
if [ -d "${prefix}/webapps" ]
then
echo "${prefix}/webapps"
return
fi
done
}
#
# Implementation
#
# The variable "DO" can usefully be set to "echo" to aid in script debugging
#
LoadStandardEnvironment()
{
# Setup a standard execution environment (if required)
cronexec="/pkgs/sbin/CronExecutionEnvironment.sh"
OPENGROK_STANDARD_ENV="${OPENGROK_STANDARD_ENV:-$cronexec}"
if [ -f "${OPENGROK_STANDARD_ENV}" ]
then
Progress "Loading ${OPENGROK_STANDARD_ENV} ..."
. "${OPENGROK_STANDARD_ENV}"
fi
}
#
# Load custom configuration and then fill remaining stuff with defaults.
#
LoadInstanceConfiguration()
{
#
# Note: As all functions have been defined by the time this routine
# is called, your configuration can, if desired, override functions
# in addition to setting the variables mentioned in the function
# DefaultInstanceConfiguration(), this maybe useful to override
# functionality used to determine the default deployment environment
# find dependencies or validate the configuration, for example.
#
if [ -n "${OPENGROK_CONFIGURATION}" -a -f "${OPENGROK_CONFIGURATION}" ]
then
# Load the Local OpenGrok Configuration Environment
Progress "Loading ${OPENGROK_CONFIGURATION} ..."
. "${OPENGROK_CONFIGURATION}"
fi
Progress "Loading the default instance configuration ..."
DefaultInstanceConfiguration
}
ValidateConfiguration()
{
if [ ! -x "${OPENGROK_CTAGS}" ]
then
FatalError "Missing Dependent Application - Exuberant/Universal CTags"
fi
if [ ! -d "${SRC_ROOT}" ]
then
FatalError "OpenGrok Source Path ${SRC_ROOT} doesn't exist"
fi
if [ -n "${QUIET}" -a -n "${VERBOSE}" ]
then
Warning "Both Quiet and Verbose Mode Enabled - Choosing Verbose"
QUIET=""
VERBOSE="-v"
fi
}
CreateRuntimeRequirements()
{
if [ ! -d "${DATA_ROOT}" ]
then
Warning "OpenGrok generated data path ${DATA_ROOT} doesn't exist"
Progress " Attempting to create generated data directory ... "
${DO} mkdir -p "${DATA_ROOT}"
fi
if [ ! -d "${DATA_ROOT}" ]
then
FatalError "OpenGrok data path ${DATA_ROOT} doesn't exist"
fi
if [ ! -d "${OPENGROK_INSTANCE_BASE}/etc" ]
then
Warning "OpenGrok generated etc path ${OPENGROK_INSTANCE_BASE}/etc " \
"doesn't exist"
Progress " Attempting to create generated etc directory ... "
${DO} mkdir -p "${OPENGROK_INSTANCE_BASE}/etc"
fi
if [ ! -d "${OPENGROK_INSTANCE_BASE}/etc" ]
then
FatalError "OpenGrok etc path ${OPENGROK_INSTANCE_BASE}/etc " \
"doesn't exist"
fi
if [ -n "${LOGGER_CONFIG_PATH}" -a ! -f "${LOGGER_CONFIG_PATH}" ]
then
Progress " Creating default ${LOGGER_CONFIG_PATH} ... "
if [ ! -f "${LOGGER_CONF_SOURCE}" ]
then
Warning "Can't find distribution logging configuration" \
"(${LOGGER_CONF_SOURCE}) to install as default" \
"logging configuration (${LOGGER_CONFIG_PATH})"
else
filename="opengrok%g.%u.log"
fullpath="${OPENGROK_INSTANCE_BASE}/log/opengrok%g.%u.log"
${DO} grep -v java.util.logging.FileHandler.pattern \
"${LOGGER_CONF_SOURCE}" > "${LOGGER_CONFIG_PATH}"
${DO} grep java.util.logging.FileHandler.pattern \
"${LOGGER_CONF_SOURCE}" | \
sed "s|$filename|$fullpath|g" >> "${LOGGER_CONFIG_PATH}"
if [ ! -d ${OPENGROK_INSTANCE_BASE}/log ]
then
${DO} mkdir ${OPENGROK_INSTANCE_BASE}/log
fi
fi
fi
}
MinimalInvocation()
{
${DO} ${JAVA} ${JAVA_OPTS} ${PROPERTIES} \
${JAVA_DEBUG} \
${LOGGER_PROPERTIES} \
-jar "${OPENGROK_JAR}" \
${VERBOSE} ${QUIET} \
"${@}"
}
CommonInvocation()
{
MinimalInvocation \
${OPENGROK_IGNORE_PATTERNS} \
${HISTORY_TAGS} \
${GENERATE_HISTORY} \
${RENAMED_FILES_HISTORY} \
${SCAN_DEPTH} \
${PROGRESS} \
${OPENGROK_LOCKING:+--lock} ${OPENGROK_LOCKING} \
${OPENGROK_CTAGS:+-c} ${OPENGROK_CTAGS} \
${OPENGROK_MANDOC:+--mandoc} ${OPENGROK_MANDOC} \
${CTAGS_OPTIONS_FILE:+-o} ${CTAGS_OPTIONS_FILE} \
${OPENGROK_FLUSH_RAM_BUFFER_SIZE} ${SKIN} ${LEADING_WILDCARD} \
${OPENGROK_PARALLELISM:+--threads} ${OPENGROK_PARALLELISM} \
${ASSIGNMENTS} \
${READ_XML_CONF} \
${WEBAPP_CONFIG} \
${CHK_INDEX_CONF:+--checkIndexVersion} ${CHK_INDEX_CONF} \
${OPENGROK_PROFILER:+--profiler} \
"${@}"
}
StdInvocation()
{
CommonInvocation \
-W "${XML_CONFIGURATION}" \
${SCAN_FOR_REPOSITORY} \
${ENABLE_PROJECTS} \
${DEFAULT_PROJECTS} \
-s "${SRC_ROOT}" \
-d "${DATA_ROOT}" \
"${@}"
}
UpdateGeneratedData()
{
StdInvocation
}
UpdateDataPartial()
{
extra_args=""
for arg in "$@"; do
if [ -n "$extra_args" ]; then
extra_args="$extra_args -H $arg"
else
extra_args="-H $arg"
fi
done
CommonInvocation $extra_args "$@"
}
UpdateDescriptionCache()
{
# OPTIONAL : Update the EftarFile data
if [ -n "${PATH_DESC}" -a -s "${PATH_DESC}" ]
then
${DO} ${JAVA} -classpath "${OPENGROK_JAR}" \
${EFTAR_UPDATE} "${PATH_DESC}" "${EFTAR_OUTPUT_FILE}"
fi
}
OpenGrokUsage()
{
[ "$1" = "--detailed" ] && helpargs=$1
echo "Options for opengrok.jar:" 1>&2
${DO} ${JAVA} ${JAVA_OPTS} -jar "${OPENGROK_JAR}" '-?' $helpargs
}
DeployWar()
{
applicationServer="`FindApplicationServerType`"
case "${applicationServer}" in
Tomcat) warTarget="`DetermineWarDirectoryTomcat`" ;;
Glassfish) warTarget="`DetermineWarDirectoryGlassfish`" ;;
Resin) warTarget="`DetermineWarDirectoryResin`" ;;
*) FatalError "Unsupported Application Server ${applicationServer}" ;;
esac
if [ -z "${warTarget}" ]
then
FatalError "Unable to determine Deployment Directory for " \
"${applicationServer}"
fi
if [ ! -f "${OPENGROK_DIST_WAR}" ]
then
FatalError "Missing Web Application Archive ${OPENGROK_DIST_WAR}"
fi
if [ ! -d "${warTarget}" ]
then
FatalError "Missing Deployment Directory ${warTarget}"
fi
APP_CONTEXT="${WAR_NAME}" #以${WAR_NAME}命名
FINAL_WAR_NAME="${WAR_NAME}" #以${WAR_NAME}命名
if [ "$applicationServer" = "Tomcat" ]
then
if [ ! -z ${OPENGROK_WEBAPP_CONTEXT+x} ] # OPENGROK_WEBAPP_CONTEXT is set
then
APP_CONTEXT="${OPENGROK_WEBAPP_CONTEXT}"
# strip leading /
case ${APP_CONTEXT} in
/*) APP_CONTEXT=`echo ${APP_CONTEXT} | sed 's|^/||'`
esac
FINAL_WAR_NAME=`echo ${APP_CONTEXT} | sed 's|/|#|g'`
if [ -z "${FINAL_WAR_NAME}" ]
then
FINAL_WAR_NAME="ROOT"
fi
fi
fi
Progress "Installing ${OPENGROK_DIST_WAR} to ${warTarget} ..."
#复制*.war到tomcat路径下的webapps目录下
sudo cp -p "${OPENGROK_DIST_WAR}" "${warTarget}/webapps/${FINAL_WAR_NAME}.war"
if [ $? != 0 ]
then
FatalError "Web Application Installation FAILED"
fi
# If user does not use default OPENGROK_INSTANCE_BASE then attempt to
# extract WEB-INF/web.xml from source.war using jar or zip utility, update
# the hardcoded values and then update source.war with the new
# WEB-INF/web.xml.
if [ "${OPENGROK_INSTANCE_BASE}" != '/var/opengrok' ]
then
EXTRACT_COMMAND=""
COMPRESS_COMMAND=""
if [ -n "`Which jar`" ]
then
EXTRACT_COMMAND="jar -xf"
COMPRESS_COMMAND="jar -uf"
elif [ -n "`Which zip`" ] && [ -n "`Which unzip`" ]
then
EXTRACT_COMMAND="unzip"
COMPRESS_COMMAND="zip -rf"
fi
if [ -n "${EXTRACT_COMMAND}" ]
then
#打开复制的*.war目录,进行解压,并替换XML_CONFIGURATION项,再压缩
cd "${warTarget}/webapps"
eval "${EXTRACT_COMMAND} ${warTarget}/webapps/${FINAL_WAR_NAME}.war WEB-INF/web.xml"
if [ "${OPENGROK_INSTANCE_BASE}" != '/var/opengrok' ]
then
sed -e 's:/var/opengrok/etc/configuration.xml:'"$XML_CONFIGURATION"':g' \
"${warTarget}/webapps/WEB-INF/web.xml" \
> "${warTarget}/webapps/WEB-INF/web.xml.tmp"
mv "${warTarget}/webapps/WEB-INF/web.xml.tmp" \
"${warTarget}/webapps/WEB-INF/web.xml"
fi
eval "${COMPRESS_COMMAND} ${warTarget}/webapps/${FINAL_WAR_NAME}.war WEB-INF/web.xml"
rm -rf "${warTarget}/WEB-INF"
fi
fi
Progress
Progress "Start your application server (${applicationServer}), " \
"if it is not already"
Progress "running, or wait until it loads the just installed web " \
"application."
Progress
Progress "OpenGrok should be available on <HOST>:<PORT>/${APP_CONTEXT}"
Progress " where HOST and PORT are configured in ${applicationServer}."
Progress
}
#
# Clear history index for given project.
#
ClearHistory()
{
Progress "Removing history index data for repository ${1}"
MinimalInvocation -s "${SRC_ROOT}" -d "${DATA_ROOT}" --deleteHistory "${1}"
}
#
# Main Program
#
if [ $# -eq 0 ]
then
Usage
fi
LoadStandardEnvironment
LoadInstanceConfiguration
case "${1}" in
deploy)
DeployWar
;;
update)
ValidateConfiguration
CreateRuntimeRequirements
UpdateGeneratedData && UpdateDescriptionCache
;;
updateQuietly)
ValidateConfiguration
CreateRuntimeRequirements
QUIET="-q"
VERBOSE=""
UpdateGeneratedData && UpdateDescriptionCache
;;
updateDesc)
UpdateDescriptionCache
;;
bootstrap)
ValidateConfiguration
CreateRuntimeRequirements
StdInvocation "--updateConfig"
;;
index)
if [ $# -gt 2 ]
then
Usage
fi
if [ -n "${2}" ]
then
SRC_ROOT="${2}"
fi
ValidateConfiguration
CreateRuntimeRequirements
UpdateGeneratedData && UpdateDescriptionCache
;;
indexpart)
if [ $# -ne 2 ]
then
Usage
fi
shift
if [ -z "$OPENGROK_READ_XML_CONFIGURATION" ]; then
FatalError "need configuration via OPENGROK_READ_XML_CONFIGURATION"
fi
ValidateConfiguration
CreateRuntimeRequirements
UpdateDataPartial $@
;;
clearHistory)
if [ $# -ne 3 ]
then
Usage
fi
SRC_ROOT="${2}"
shift 2
if [ -z "${1}" ]; then
Usage
fi
ClearHistory "${1}"
;;
usage|help)
OpenGrokUsage $2
Usage $2
;;
*)
Usage
;;
esac
#注释退出
#exit $?
同时针对上面的脚本修改,增加了一个傻瓜式创建OpenGrok多工程的脚本:
支持一键创建和删除OpenGrok项目。
#!/bin/sh
ReturnCheck()
{
if [ $1 -ne 0 ]; then
echo "$2 failed!"
else
echo "$2 succeed!"
fi
};
CreateNewProject(){
if [ "$1" == "create" ];then
if [ "" == "$2" ];then
echo "
parm2 is empty!
eg:
./runOpenGrok.sh create [project name] [source code path]
"
exit
fi
if [ "" == "$3" ];then
echo "
parm3 is empty!
eg:
./runOpenGrok.sh create [project name] [source code path]
"
exit
elif [ ! -d "$3" ];then
echo "
parm3 is not a dir or dir is not exist!
eg:
./runOpenGrok.sh create [project name] [source code path]
"
exit
fi
# $2 : project name
# $3 : source code path
export WAR_NAME="$2"
export SRC_CODE_NAME="$3"
#1.Create database dir :/opt/opengrok/database/${WAR_NAME}
echo "Create database dir to $2..."
sudo mkdir /opt/opengrok/database/${WAR_NAME}
ReturnCheck $? "Create database dir to $2 "
#2.Create softlink :/opt/opengrok/database/$2/$2
echo "Create softlink to $3..."
sudo ln -s $3 /opt/opengrok/database/$2/$2
ReturnCheck $? "Create softlink to $3 "
#3.Copy $2.war to /opt/opengrok/lib
echo "Copy $2.war to /opt/opengrok/lib..."
sudo cp /opt/opengrok/lib/source.war /opt/opengrok/lib/$2.war
ReturnCheck $? "Copy $2.war to /opt/opengrok/lib "
#4.Copy $2.war to /opt/apache-tomcat/webapps
echo "Copy $2.war to /opt/apache-tomcat/webapps..."
sudo cp /opt/opengrok/lib/source.war /opt/apache-tomcat/webapps/$2.war
ReturnCheck $? "Copy $2.war to /opt/apache-tomcat/webapps "
#5.Set $2.war config
echo "Set $2.war config..."
. /opt/opengrok/bin/TOpenGrok deploy
ReturnCheck $? "Set $2.war config "
#6.Set $3 code db
echo "Set $3 code db..."
. /opt/opengrok/bin/TOpenGrok index /opt/opengrok/database/$2
ReturnCheck $? "Set $3 code db "
fi
};
Help()
{
echo "=====================Help======================
创建OpenGrok工程:
sudo ./runOpenGrok.sh create [工程名] [工程源代码路径]
OpenGrok工程同步:
sudo ./runOpenGrok.sh sync [工程名]
删除OpenGrok工程:
sudo ./runOpenGrok.sh remove [工程名]
重启tomcat:
sudo ./runOpenGrok.sh re-tomcat
==============================================="
};
RemoveProject(){
if [ "" == "$1" ];then
echo "
parm1 is empty!
eg:
./runOpenGrok.sh remove [project name]
"
exit
fi
#1.remove db
echo "remove cache db ..."
sudo rm /opt/opengrok/database/$1 -rf
sudo rm /opt/opengrok/cache/$1 -rf
ReturnCheck $? "remove cache db from /opt/opengrok/cache/$1/* "
#2.remove $1.war
echo "remove $1.war ..."
sudo rm /opt/opengrok/lib/$1.war
sudo rm /opt/apache-tomcat/webapps/$1.war
sudo rm /opt/apache-tomcat/webapps/$1 -rf
sudo rm /opt/apache-tomcat/$1.war
ReturnCheck $? "remove $1.war "
}
SyncProject(){
if [ "" == "$1" ];then
echo "
parm2 is empty!
eg:
./runOpenGrok.sh sync [project name]
"
exit
elif [ ! -d "/opt/opengrok/database/$1" ];then
echo "
parm2 is not a dir or dir is not exist!
eg:
./runOpenGrok.sh sync [project name]
"
exit
fi
export WAR_NAME="$1"
echo "Sync code from /opt/opengrok/database/$1 to db..."
. /opt/opengrok/bin/TOpenGrok index /opt/opengrok/database/$1
ReturnCheck $? "Sync code from /opt/opengrok/database/$1 to db "
}
case "${1}" in
sync)
SyncProject $2 $3
;;
create)
CreateNewProject $1 $2 $3
;;
remove)
RemoveProject $2
;;
re-tomcat)
sudo service tomcat8 stop
sleep 5
sudo service tomcat8 start
;;
help)
Help
;;
*)
Help
;;
esac
错误解决:
-
出现以下错误:
Caused by: java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:851)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:848)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1587)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:390)
at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:282)
… 12 more
解决方案:
在tomcat的/apache-tomcat/conf/server.xml添加https支持:
<Connector port="8083" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="/u01/ssl/server.jks" keystorePass="password"
truststoreFile="/u01/ssl/server.jks" truststorePass="password" />
在工程的web.xml文件中加入https的支持
<security-constraint>
<web-resource-collection>
<web-resource-name>SSL</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>