Skip to content
Permalink
Browse files
6946: There should be an option to build the agent in the build script
Reviewed-by: hirt, aptmac
  • Loading branch information
mirage22 committed Jan 14, 2021
1 parent 8d6fb1b commit 33e684b2f981cf43bf323b7d9bec611685b04709
Show file tree
Hide file tree
Showing 2 changed files with 204 additions and 32 deletions.
@@ -26,17 +26,25 @@ if not "%*" == "" goto parse_args
echo usage: call %0 with the following options:
echo --test to run the tests
echo --testUi to run the tests including UI tests
echo --installCore to install JMC core
echo --packageJmc to package JMC
echo --packageAgent to package Agent
echo --runAgentExample to run Agent 'InstrumentMe' example, once it is packaged
echo --runAgentConverterExample to run Agent 'InstrumentMeConverter' example, once it is packaged
echo --clean to run maven clean
echo --run to run JMC once it was packaged
echo --run to run JMC, once it is packaged
echo --help to show this help dialog
exit /B 0

:parse_args
if "%1" == "--help" goto print_usage
if "%1" == "--test" goto test
if "%1" == "--testUi" goto testUi
if "%1" == "--installCore" goto installCore
if "%1" == "--packageJmc" goto packageJmc
if "%1" == "--packageAgent" goto packageAgent
if "%1" == "--runAgentExample" goto runAgentExample
if "%1" == "--runAgentConverterExample" goto runAgentConverterExample
if "%1" == "--clean" goto clean
if "%1" == "--run" goto run
echo unknown argument %1
@@ -47,7 +55,6 @@ for /f "skip=1" %%A in ('wmic os get localdatetime ^| findstr .') do (set LOCALD
set TIMESTAMP=%LOCALDATETIME:~0,14%
set P2_SITE_LOG=%cd%\build_%TIMESTAMP%.1.p2_site.log
set JETTY_LOG=%cd%\build_%TIMESTAMP%.2.jetty.log
set INSTALL_LOG=%cd%\build_%TIMESTAMP%.3.install.log
echo %time% building p2:site - logging output to %P2_SITE_LOG%
call mvn -f releng\third-party\pom.xml p2:site --log-file "%P2_SITE_LOG%"
if not %ERRORLEVEL% == 0 (
@@ -62,10 +69,20 @@ timeout /t 1
findstr "[INFO] Started Jetty Server" %JETTY_LOG%
if not %ERRORLEVEL% == 0 goto :wait_jetty
echo %time% jetty server up and running
call :installCore
if not %ERRORLEVEL% == 0 (
call :killJetty %1
exit /B 1
)
exit /B 0

:installCore
for /f "skip=1" %%A in ('wmic os get localdatetime ^| findstr .') do (set LOCALDATETIME=%%A)
set TIMESTAMP=%LOCALDATETIME:~0,14%
set INSTALL_LOG=%cd%\build_%TIMESTAMP%.3.install.log
echo %time% installing core artifacts - logging output to %INSTALL_LOG%
call mvn -f core\pom.xml clean install --log-file "%INSTALL_LOG%"
if not %ERRORLEVEL% == 0 (
call :killJetty %1
echo installing core artifacts failed!
exit /B 1
)
@@ -115,12 +132,46 @@ if %ERRORLEVEL% == 0 echo You can now run jmc by calling "%0 --run" or "%cd%\tar
call :killJetty %JETTY_TITLE%
goto end

:packageAgent
@REM generate a unique id for window title
@REM allow to filter uniquely to get PID associated later
for /f "skip=1" %%A in ('wmic os get localdatetime ^| findstr .') do (set LOCALDATETIME=%%A)
set TIMESTAMP=%LOCALDATETIME:~0,14%
set PACKAGE_LOG=%cd%\build_%TIMESTAMP%.5.package.log
cd agent
call mvn install --log-file "%PACKAGE_LOG%"
cd ..
if %ERRORLEVEL% == 0 (
echo Agent library build complete. You can now run an example with the agent using --runAgentExample or --runAgentConverterExample
echo See agent/README.md for more information
) else {
exit /B 1
}
exit /B 0

:runAgentExample
echo %time% run Agent 'InstrumentMe' example
set PATH_TO_AGENT_TARGET_DIR=%cd%\agent\target
set PATH_TO_AGENT_JAR="%PATH_TO_AGENT_TARGET_DIR%"\org.openjdk.jmc.agent-1.0.0-SNAPSHOT.jar
call java --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -XX:+FlightRecorder -javaagent:"%PATH_TO_AGENT_JAR%"="%PATH_TO_AGENT_TARGET_DIR%"/test-classes/org/openjdk/jmc/agent/test/jfrprobes_template.xml -cp "%PATH_TO_AGENT_JAR%"="%PATH_TO_AGENT_TARGET_DIR%"/test-classes/ org.openjdk.jmc.agent.test.InstrumentMe
exit /B 0

:runAgentConverterExample
echo %time% run Agent 'InstrumentMeConverter' example
set PATH_TO_AGENT_TARGET_DIR=%cd%\agent\target
set PATH_TO_AGENT_JAR="%PATH_TO_AGENT_TARGET_DIR%"\org.openjdk.jmc.agent-1.0.0-SNAPSHOT.jar
call java --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -XX:+FlightRecorder -javaagent:"%PATH_TO_AGENT_JAR%"="%PATH_TO_AGENT_TARGET_DIR%"/test-classes/org/openjdk/jmc/agent/test/jfrprobes_template.xml -cp "%PATH_TO_AGENT_JAR%"="%PATH_TO_AGENT_TARGET_DIR%"/test-classes/ org.openjdk.jmc.agent.converters.test.InstrumentMeConverter
exit /B 0

:clean
echo %time% running clean up
call mvn clean
cd core
call mvn clean
cd ..
cd agent
call mvn clean
cd ..
cd releng\third-party
call mvn clean
cd ..\..
179 build.sh
@@ -7,6 +7,7 @@ PROGNAME=$(basename "$0")

JETTY_PID=""
BASEDIR=""
JMC_DIR=""

function err_report() {
err_log "$(date +%T) ${PROGNAME}: Error on line $1"
@@ -20,11 +21,28 @@ function exitTrap() {
fi
}

function installCore() {
local timestamp="$1"
local installLog="${BASEDIR}/build_${timestamp}.3.install.log"
pushd core 1> /dev/null || {
err_log "directory core not found"
exit 1
}

echo "$(date +%T) installing core artifacts - logging output to ${installLog}"
mvn clean install --log-file "${installLog}"

popd 1> /dev/null || {
err_log "could not go to project root directory"
exit 1
}
}

function startJetty() {
local timestamp="$(date +%Y%m%d%H%M%S)"
local timestamp=$1
local p2SiteLog="${BASEDIR}/build_${timestamp}.1.p2_site.log"
local jettyLog="${BASEDIR}/build_${timestamp}.2.jetty.log"
local installLog="${BASEDIR}/build_${timestamp}.3.install.log"


pushd releng/third-party 1> /dev/null || {
err_log "directory releng/third-party not found"
@@ -44,18 +62,6 @@ function startJetty() {
done
echo "$(date +%T) jetty server up and running on pid ${JETTY_PID}"

popd 1> /dev/null || {
err_log "could not go to project root directory"
exit 1
}
pushd core 1> /dev/null || {
err_log "directory core not found"
exit 1
}

echo "$(date +%T) installing core artifacts - logging output to ${installLog}"
mvn clean install --log-file "${installLog}"

popd 1> /dev/null || {
err_log "could not go to project root directory"
exit 1
@@ -74,9 +80,13 @@ function printHelp() {
{
printf " \t%s\t%s\n" "--test" "to run the tests"
printf " \t%s\t%s\n" "--testUi" "to run the tests including UI tests"
printf " \t%s\t%s\n" "--installCore" "to install JMC core"
printf " \t%s\t%s\n" "--packageJmc" "to package JMC"
printf " \t%s\t%s\n" "--packageAgent" "to package Agent"
printf " \t%s\t%s\n" "--clean" "to run maven clean"
printf " \t%s\t%s\n" "--run" "to run JMC once it was packaged"
printf " \t%s\t%s\n" "--run" "to run JMC, once it is packaged"
printf " \t%s\t%s\n" "--runAgentExample" "to run Agent 'InstrumentMe' example, once it is packaged"
printf " \t%s\t%s\n" "--runAgentConverterExample" "to run Agent 'InstrumentMeConverter' example, once it is packaged"
printf " \t%s\t%s\n" "--help" "to show this help dialog"
} | column -ts $'\t'
}
@@ -87,19 +97,25 @@ if [ $# -eq 0 ]; then
fi

function runTests() {
echo "$(date +%T) running tests"
local timestamp=$1
startJetty $timestamp
echo "${timestamp} running tests"
mvn verify
}

function runUiTests() {
startJetty
local timestamp=$1
startJetty $timestamp
installCore $timestamp
echo "$(date +%T) running UI tests"
mvn verify -P uitests
}

function packageJmc() {
startJetty
local packageLog="${BASEDIR}/build_$(date +%Y%m%d%H%M%S).4.package.log"
local timestamp=$1
startJetty $timestamp
installCore $timestamp
local packageLog="${BASEDIR}/build_${timestamp}.4.package.log"

echo "$(date +%T) packaging jmc - logging output to ${packageLog}"
mvn package --log-file "${packageLog}"
@@ -113,6 +129,32 @@ function packageJmc() {
fi
}

function packageAgent() {
local timestamp=$1
local packageLog="${BASEDIR}/build_${timestamp}.5.package.log"

pushd agent 1> /dev/null || {
err_log "directory agent not found"
exit 1
}

echo "$(date +%T) packaging jmc agent - logging output to ${packageLog}"
mvn package --log-file "${packageLog}"

popd 1> /dev/null || {
err_log "could not go to project root directory"
exit 1
}

if [[ "${OSTYPE}" =~ "linux"* ]] || [[ "${OSTYPE}" =~ "darwin"* ]]; then
printf "%s\n" "Agent library build complete. You can now run an example with the agent using \"${PROGNAME} --runAgentExample or --runAgentConverterExample\""
printf "%s\n" "See agent/README.md for more information"
else
err_log "unknown OS type: \"${OSTYPE}\". Please check package in \"${JMC_DIR}/agent/target\""
exit 1
fi
}

function clean() {
echo "$(date +%T) running clean up"
mvn clean
@@ -127,6 +169,16 @@ function clean() {
exit 1
}

pushd agent 1> /dev/null || {
err_log "directory agent not found"
exit 1
}
mvn clean
popd 1> /dev/null || {
err_log "could not go to project root directory"
exit 1
}

pushd releng/third-party 1> /dev/null || {
err_log "directory releng/third-party not found"
exit 1
@@ -157,30 +209,90 @@ function run() {
fi
}

function runAgentByClass() {
local agentExampleClass=$1
if [[ -z "${agentExampleClass}" ]]; then
err_log "error: try to run undefined agent class, empty class"
printHelp
exit 1
else
printf "example agent class: %s\n" "${agentExampleClass}"
fi

checkJava
if [[ "${OSTYPE}" =~ "linux"* ]] || [[ "${OSTYPE}" =~ "darwin"* ]]; then
printf "%s\n" "try to execute an agent example"
else
err_log "unknown OS type: \"${OSTYPE}\". Please check package ${JMC_DIR}/agent README.MD"
exit 1
fi


local javaVersion=`java -version 2>&1 | head -1 | cut -d '"' -f 2 | sed 's/^1\.//' | cut -d '.' -f 1`

if ! [ "$javaVersion" -eq "$javaVersion" ] 2> /dev/null; then
printf "%s\n" "WARNING: java version not recognized"
javaVersion=15
fi

printf "Java Version:%s\n" "${javaVersion}"
local pathToAgentTargetDir="${JMC_DIR}/agent/target"
local pathToAgentJar="${pathToAgentTargetDir}/org.openjdk.jmc.agent-1.0.0-SNAPSHOT.jar"
printf "Agent path:%s\n" "${pathToAgentJar}"
if [ -f "${pathToAgentJar}" ]; then
if [ "$javaVersion" -lt "8" ]; then
printf "min. required java version is 8"
exit 1
elif [ "$javaVersion" -eq "8" ]; then
java -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -javaagent:${pathToAgentJar}=${pathToAgentTargetDir}/test-classes/org/openjdk/jmc/agent/test/jfrprobes_template.xml -cp ${pathToAgentJar}:${pathToAgentTargetDir}/test-classes/ ${agentExampleClass}
elif [ "$javaVersion" -lt "13" ]; then
java --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -XX:+FlightRecorder -javaagent:${pathToAgentJar}=${pathToAgentTargetDir}/test-classes/org/openjdk/jmc/agent/test/jfrprobes_template.xml -cp ${pathToAgentJar}:${pathToAgentTargetDir}/test-classes/ ${agentExampleClass}
else
java --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -javaagent:${pathToAgentJar}=${pathToAgentTargetDir}/test-classes/org/openjdk/jmc/agent/test/jfrprobes_template.xml -cp ${pathToAgentJar}:${pathToAgentTargetDir}/test-classes/ ${agentExampleClass}
fi
else
err_log "Agent not found in \"${pathToAgentJar}\". Did you call --packageAgent before?"
exit 1
fi
}

function parseArgs() {
local timestamp="$(date +%Y%m%d%H%M%S)"
while [[ $# -gt 0 ]]; do
case "$1" in
--help)
printHelp
exit 0
;;
--test)
runTests
runTests $timestamp
;;
--testUi)
runUiTests
runUiTests $timestamp
;;
--installCore)
installCore $timestamp
;;
--packageJmc)
packageJmc
packageJmc $timestamp
;;
--packageAgent)
packageAgent $timestamp
;;
--clean)
clean
;;
--run)
run
;;
--runAgentExample)
runAgentByClass "org.openjdk.jmc.agent.test.InstrumentMe"
;;
--runAgentConverterExample)
runAgentByClass "org.openjdk.jmc.agent.converters.test.InstrumentMeConverter"
;;
*)
err_log "unknown argument \"$1\""
err_log "unknown arguments: $@"
printHelp
exit 1
;;
@@ -189,20 +301,29 @@ function parseArgs() {
done
}

function checkPreconditions() {
if ! command -v mvn &> /dev/null ; then
err_log "It seems you do not have maven installed. Please ensure you have it installed and executable as \"mvn\"."
exit 1
function checkJava() {
if [[ -z "$JAVA_HOME" ]]; then
echo "JAVA_HOME is not defined"
fi

if ! command -v java &> /dev/null ; then
if ! command -v java &> /dev/null ; then
err_log "It seems you do not have java installed. Please ensure you have it installed and executable as \"java\"."
exit 1
fi
}

function checkPreconditions() {
checkJava

if ! command -v mvn &> /dev/null ; then
err_log "It seems you do not have maven installed. Please ensure you have it installed and executable as \"mvn\"."
exit 1
fi

BASEDIR=$(mvn help:evaluate -Dexpression=project.build.directory --non-recursive -q -DforceStdout)
JMC_DIR=$(pwd)
mkdir -p "${BASEDIR}" # just in case clean was called before
}

checkPreconditions
parseArgs "$@"
parseArgs "$@"

0 comments on commit 33e684b

Please sign in to comment.