Skip to content

Commit

Permalink
Merge pull request brianfrankcooper#777 from cmatser/windowsfix
Browse files Browse the repository at this point in the history
[scripts] Add mvn build if necessary for source checkout on windows. …
  • Loading branch information
busbey committed Jun 28, 2016
2 parents 20101dd + 24d5a11 commit 8e46091
Showing 1 changed file with 202 additions and 183 deletions.
385 changes: 202 additions & 183 deletions bin/ycsb.bat
Original file line number Diff line number Diff line change
@@ -1,183 +1,202 @@
@REM
@REM Copyright (c) 2012 - 2016 YCSB contributors. All rights reserved.
@REM
@REM Licensed under the Apache License, Version 2.0 (the "License"); you
@REM may not use this file except in compliance with the License. You
@REM may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing, software
@REM distributed under the License is distributed on an "AS IS" BASIS,
@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
@REM implied. See the License for the specific language governing
@REM permissions and limitations under the License. See accompanying
@REM LICENSE file.
@REM
@REM -----------------------------------------------------------------------
@REM Control Script for YCSB
@REM
@REM Environment Variable Prerequisites
@REM
@REM Do not set the variables in this script. Instead put them into a script
@REM setenv.sh in YCSB_HOME/bin to keep your customizations separate.
@REM
@REM YCSB_HOME (Optional) YCSB installation directory. If not set
@REM this script will use the parent directory of where this
@REM script is run from.
@REM
@REM JAVA_HOME (Required) Must point at your Java Development Kit
@REM or Java Runtime Environment installation.
@REM
@REM JAVA_OPTS (Optional) Java runtime options used when any command
@REM is executed.
@REM
@REM WARNING!!! YCSB home must be located in a directory path that doesn't
@REM contain spaces.
@REM

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

@REM Only set YCSB_HOME if not already set
PUSHD %~dp0..
IF NOT DEFINED YCSB_HOME SET YCSB_HOME=%CD%
POPD

@REM Ensure that any extra CLASSPATH variables are set via setenv.bat
SET CLASSPATH=

@REM Pull in customization options
if exist "%YCSB_HOME%\bin\setenv.bat" call "%YCSB_HOME%\bin\setenv.bat"

@REM Check if we have a usable JDK
IF "%JAVA_HOME%." == "." GOTO noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
GOTO okJava
:noJavaHome
ECHO The JAVA_HOME environment variable is not defined correctly.
GOTO exit
:okJava

@REM Determine YCSB command argument
IF NOT "load" == "%1" GOTO noload
SET YCSB_COMMAND=-load
SET YCSB_CLASS=com.yahoo.ycsb.Client
GOTO gotCommand
:noload
IF NOT "run" == "%1" GOTO noRun
SET YCSB_COMMAND=-t
SET YCSB_CLASS=com.yahoo.ycsb.Client
GOTO gotCommand
:noRun
IF NOT "shell" == "%1" GOTO noShell
SET YCSB_COMMAND=
SET YCSB_CLASS=com.yahoo.ycsb.CommandLine
GOTO gotCommand
:noShell
ECHO [ERROR] Found unknown command '%1'
ECHO [ERROR] Expected one of 'load', 'run', or 'shell'. Exiting.
GOTO exit
:gotCommand

@REM Find binding information
FOR /F "delims=" %%G in (
'FINDSTR /B "%2:" %YCSB_HOME%\bin\bindings.properties'
) DO SET "BINDING_LINE=%%G"

IF NOT "%BINDING_LINE%." == "." GOTO gotBindingLine
ECHO [ERROR] The specified binding '%2' was not found. Exiting.
GOTO exit
:gotBindingLine

@REM Pull out binding name and class
FOR /F "tokens=1-2 delims=:" %%G IN ("%BINDING_LINE%") DO (
SET BINDING_NAME=%%G
SET BINDING_CLASS=%%H
)

@REM Some bindings have multiple versions that are managed in the same
@REM directory.
@REM They are noted with a '-' after the binding name.
@REM (e.g. cassandra-7 & cassandra-8)
FOR /F "tokens=1 delims=-" %%G IN ("%BINDING_NAME%") DO (
SET BINDING_DIR=%%G
)

@REM The 'basic' binding is core functionality
IF NOT "%BINDING_NAME%" == "basic" GOTO noBasic
SET BINDING_DIR=core
:noBasic

@REM Add Top level conf to classpath
IF "%CLASSPATH%." == "." GOTO emptyClasspath
SET CLASSPATH=%CLASSPATH%;%YCSB_HOME%\conf
GOTO confAdded
:emptyClasspath
SET CLASSPATH=%YCSB_HOME%\conf
:confAdded

@REM Build classpath according to source checkout or release distribution
IF EXIST "%YCSB_HOME%\pom.xml" GOTO gotRelease

@REM Core libraries
FOR %%F IN (%YCSB_HOME%\lib\*.jar) DO (
SET CLASSPATH=!CLASSPATH!;%%F%
)

@REM Database conf dir
IF NOT EXIST "%YCSB_HOME%\%BINDING_DIR%-binding\conf" GOTO noBindingConf
set CLASSPATH=%CLASSPATH%;%YCSB_HOME%\%BINDING_DIR%-binding\conf
:noBindingConf

@REM Database libraries
FOR %%F IN (%YCSB_HOME%\%BINDING_DIR%-binding\lib\*.jar) DO (
SET CLASSPATH=!CLASSPATH!;%%F%
)
GOTO classpathComplete

:gotRelease
@REM Core libraries
FOR %%F IN (%YCSB_HOME%\core\target\*.jar) DO (
SET CLASSPATH=!CLASSPATH!;%%F%
)

@REM Database conf (need to find because location is not consistent)
FOR /D /R %YCSB_HOME%\%BINDING_DIR% %%F IN (*) DO (
IF "%%~nxF" == "conf" SET CLASSPATH=!CLASSPATH!;%%F%
)

@REM Database libraries
FOR %%F IN (%YCSB_HOME%\%BINDING_DIR%\target\*.jar) DO (
SET CLASSPATH=!CLASSPATH!;%%F%
)

@REM Database dependency libraries
FOR %%F IN (%YCSB_HOME%\%BINDING_DIR%\target\dependency\*.jar) DO (
SET CLASSPATH=!CLASSPATH!;%%F%
)

:classpathComplete

@REM Cassandra deprecation message
IF NOT "%BINDING_DIR%" == "cassandra" GOTO notOldCassandra
echo [WARN] The 'cassandra-7', 'cassandra-8', 'cassandra-10', and cassandra-cql' clients are deprecated. If you are using Cassandra 2.X try using the 'cassandra2-cql' client instead.
:notOldCassandra

@REM Get the rest of the arguments, skipping the first 2
FOR /F "tokens=2*" %%G IN ("%*") DO (
SET YCSB_ARGS=%%H
)

@REM Run YCSB
@ECHO ON
"%JAVA_HOME%\bin\java.exe" %JAVA_OPTS% -classpath "%CLASSPATH%" %YCSB_CLASS% %YCSB_COMMAND% -db %BINDING_CLASS% %YCSB_ARGS%
@ECHO OFF

GOTO end

:exit
EXIT /B 1;

:end

@REM
@REM Copyright (c) 2012 - 2016 YCSB contributors. All rights reserved.
@REM
@REM Licensed under the Apache License, Version 2.0 (the "License"); you
@REM may not use this file except in compliance with the License. You
@REM may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing, software
@REM distributed under the License is distributed on an "AS IS" BASIS,
@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
@REM implied. See the License for the specific language governing
@REM permissions and limitations under the License. See accompanying
@REM LICENSE file.
@REM
@REM -----------------------------------------------------------------------
@REM Control Script for YCSB
@REM
@REM Environment Variable Prerequisites
@REM
@REM Do not set the variables in this script. Instead put them into a script
@REM setenv.sh in YCSB_HOME/bin to keep your customizations separate.
@REM
@REM YCSB_HOME (Optional) YCSB installation directory. If not set
@REM this script will use the parent directory of where this
@REM script is run from.
@REM
@REM JAVA_HOME (Required) Must point at your Java Development Kit
@REM or Java Runtime Environment installation.
@REM
@REM JAVA_OPTS (Optional) Java runtime options used when any command
@REM is executed.
@REM
@REM WARNING!!! YCSB home must be located in a directory path that doesn't
@REM contain spaces.
@REM

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

@REM Only set YCSB_HOME if not already set
PUSHD %~dp0..
IF NOT DEFINED YCSB_HOME SET YCSB_HOME=%CD%
POPD

@REM Ensure that any extra CLASSPATH variables are set via setenv.bat
SET CLASSPATH=

@REM Pull in customization options
if exist "%YCSB_HOME%\bin\setenv.bat" call "%YCSB_HOME%\bin\setenv.bat"

@REM Check if we have a usable JDK
IF "%JAVA_HOME%." == "." GOTO noJavaHome
IF NOT EXIST "%JAVA_HOME%\bin\java.exe" GOTO noJavaHome
GOTO okJava
:noJavaHome
ECHO The JAVA_HOME environment variable is not defined correctly.
GOTO exit
:okJava

@REM Determine YCSB command argument
IF NOT "load" == "%1" GOTO noload
SET YCSB_COMMAND=-load
SET YCSB_CLASS=com.yahoo.ycsb.Client
GOTO gotCommand
:noload
IF NOT "run" == "%1" GOTO noRun
SET YCSB_COMMAND=-t
SET YCSB_CLASS=com.yahoo.ycsb.Client
GOTO gotCommand
:noRun
IF NOT "shell" == "%1" GOTO noShell
SET YCSB_COMMAND=
SET YCSB_CLASS=com.yahoo.ycsb.CommandLine
GOTO gotCommand
:noShell
ECHO [ERROR] Found unknown command '%1'
ECHO [ERROR] Expected one of 'load', 'run', or 'shell'. Exiting.
GOTO exit
:gotCommand

@REM Find binding information
FOR /F "delims=" %%G in (
'FINDSTR /B "%2:" %YCSB_HOME%\bin\bindings.properties'
) DO SET "BINDING_LINE=%%G"

IF NOT "%BINDING_LINE%." == "." GOTO gotBindingLine
ECHO [ERROR] The specified binding '%2' was not found. Exiting.
GOTO exit
:gotBindingLine

@REM Pull out binding name and class
FOR /F "tokens=1-2 delims=:" %%G IN ("%BINDING_LINE%") DO (
SET BINDING_NAME=%%G
SET BINDING_CLASS=%%H
)

@REM Some bindings have multiple versions that are managed in the same
@REM directory.
@REM They are noted with a '-' after the binding name.
@REM (e.g. cassandra-7 & cassandra-8)
FOR /F "tokens=1 delims=-" %%G IN ("%BINDING_NAME%") DO (
SET BINDING_DIR=%%G
)

@REM The 'basic' binding is core functionality
IF NOT "%BINDING_NAME%" == "basic" GOTO noBasic
SET BINDING_DIR=core
:noBasic

@REM Add Top level conf to classpath
IF "%CLASSPATH%." == "." GOTO emptyClasspath
SET CLASSPATH=%CLASSPATH%;%YCSB_HOME%\conf
GOTO confAdded
:emptyClasspath
SET CLASSPATH=%YCSB_HOME%\conf
:confAdded

@REM Build classpath according to source checkout or release distribution
IF EXIST "%YCSB_HOME%\pom.xml" GOTO gotSource

@REM Core libraries
FOR %%F IN (%YCSB_HOME%\lib\*.jar) DO (
SET CLASSPATH=!CLASSPATH!;%%F%
)

@REM Database conf dir
IF NOT EXIST "%YCSB_HOME%\%BINDING_DIR%-binding\conf" GOTO noBindingConf
set CLASSPATH=%CLASSPATH%;%YCSB_HOME%\%BINDING_DIR%-binding\conf
:noBindingConf

@REM Database libraries
FOR %%F IN (%YCSB_HOME%\%BINDING_DIR%-binding\lib\*.jar) DO (
SET CLASSPATH=!CLASSPATH!;%%F%
)
GOTO classpathComplete

:gotSource
@REM Check for some basic libraries to see if the source has been built.
IF EXIST "%YCSB_HOME%\%BINDING_DIR%\target\*.jar" GOTO gotJars

@REM Call mvn to build source checkout.
IF "%BINDING_NAME%" == "basic" GOTO buildCore
SET MVN_PROJECT=%BINDING_DIR%-binding
goto gotMvnProject
:buildCore
SET MVN_PROJECT=core
:gotMvnProject

ECHO [WARN] YCSB libraries not found. Attempting to build...
CALL mvn -pl com.yahoo.ycsb:%MVN_PROJECT% -am package -DskipTests
IF %ERRORLEVEL% NEQ 0 (
ECHO [ERROR] Error trying to build project. Exiting.
GOTO exit
)

:gotJars
@REM Core libraries
FOR %%F IN (%YCSB_HOME%\core\target\*.jar) DO (
SET CLASSPATH=!CLASSPATH!;%%F%
)

@REM Database conf (need to find because location is not consistent)
FOR /D /R %YCSB_HOME%\%BINDING_DIR% %%F IN (*) DO (
IF "%%~nxF" == "conf" SET CLASSPATH=!CLASSPATH!;%%F%
)

@REM Database libraries
FOR %%F IN (%YCSB_HOME%\%BINDING_DIR%\target\*.jar) DO (
SET CLASSPATH=!CLASSPATH!;%%F%
)

@REM Database dependency libraries
FOR %%F IN (%YCSB_HOME%\%BINDING_DIR%\target\dependency\*.jar) DO (
SET CLASSPATH=!CLASSPATH!;%%F%
)

:classpathComplete

@REM Cassandra deprecation message
IF NOT "%BINDING_DIR%" == "cassandra" GOTO notOldCassandra
echo [WARN] The 'cassandra-7', 'cassandra-8', 'cassandra-10', and cassandra-cql' clients are deprecated. If you are using Cassandra 2.X try using the 'cassandra2-cql' client instead.
:notOldCassandra

@REM Get the rest of the arguments, skipping the first 2
FOR /F "tokens=2*" %%G IN ("%*") DO (
SET YCSB_ARGS=%%H
)

@REM Run YCSB
@ECHO ON
"%JAVA_HOME%\bin\java.exe" %JAVA_OPTS% -classpath "%CLASSPATH%" %YCSB_CLASS% %YCSB_COMMAND% -db %BINDING_CLASS% %YCSB_ARGS%
@ECHO OFF

GOTO end

:exit
EXIT /B 1;

:end

0 comments on commit 8e46091

Please sign in to comment.