Skip to content

Commit

Permalink
Merge pull request #480 from praminda/428
Browse files Browse the repository at this point in the history
Fix issues in micro-gw.bat
  • Loading branch information
Rajith90 authored Apr 29, 2019
2 parents c6839cd + c132ccc commit 2d62159
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
import org.wso2.apimgt.gateway.cli.model.rest.ext.ExtendedAPI;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
Expand Down Expand Up @@ -650,8 +650,7 @@ public static String getDeploymentConfigLocation(String projectName) {
* @return path to the given project in the current working directory
*/
public static String getProjectDirectoryPath(String projectName) {
// TODO: do we need to change this?
return new File(projectName).getAbsolutePath();
return getUserDir() + File.separator + projectName;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wso2.apimgt.gateway.cli.cmd.InitCmd;
import org.wso2.apimgt.gateway.cli.constants.GatewayCliConstants;
import org.wso2.apimgt.gateway.cli.exception.CLIInternalException;

Expand All @@ -31,7 +30,7 @@
* This class represents the utility functions required for library packages extraction
*/
public class ToolkitLibExtractionUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(InitCmd.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ToolkitLibExtractionUtils.class);

/**
* Extracts the platform and runtime and copy related jars and balos to extracted runtime and platform.
Expand Down
30 changes: 17 additions & 13 deletions distribution/resources/bin/micro-gw
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
# -----------------------------------------------------------------------------

#To update the CLI Class Path
updateCLIClassPath()
{
function update_cli_classpath {
CLI_CLASSPATH=""
if [ -e "$BALLERINA_HOME/bre/lib/bootstrap/tools.jar" ]; then
CLI_CLASSPATH="$JAVA_HOME/lib/tools.jar"
Expand Down Expand Up @@ -79,8 +78,12 @@ updateCLIClassPath()
cygwin=false
os400=false
case "`uname`" in
CYGWIN*) cygwin=true;;
OS400*) os400=true;;
CYGWIN*)
cygwin=true
;;
OS400*)
os400=true
;;
esac

# resolve links - $0 may be a softlink
Expand Down Expand Up @@ -117,6 +120,12 @@ export PATH=$BALLERINA_HOME/bin:$PATH

MICRO_GW_PROJECT_DIR=$(pwd)

# if JAVA_HOME is not set we're not happy
if [ -z "$JAVA_HOME" ]; then
echo "You must set the JAVA_HOME variable before running Micro-Gateway Tooling."
exit 1
fi

# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
Expand Down Expand Up @@ -165,12 +174,6 @@ if [ ! -x "$JAVACMD" ] ; then
exit 1
fi

# if JAVA_HOME is not set we're not happy
if [ -z "$JAVA_HOME" ]; then
echo "You must set the JAVA_HOME variable before running Ballerina."
exit 1
fi

# ----- Process the input command ----------------------------------------------

ALL_ARGS=()
Expand All @@ -179,7 +182,7 @@ while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--java.debug|-java.debug|java.debug)
--java.debug)
CMD="--java.debug"
PORT="$2"
shift # past java.debug argument
Expand Down Expand Up @@ -236,7 +239,7 @@ if [ "$CMD" = "--java.debug" ]; then
echo "Please start the remote debugging client to continue..."
fi

updateCLIClassPath
update_cli_classpath

# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
Expand Down Expand Up @@ -283,7 +286,8 @@ if [ "$IS_BUILD_COMMAND" = true ] && [ "$CMD_PRO_NAME_VAL" != "" ] && [ "$MICRO_
BALLERINA_HOME=`cygpath --absolute --windows "$BALLERINA_HOME"`

fi
updateCLIClassPath

update_cli_classpath
MICRO_GW_LABEL_PROJECT_DIR="$MICRO_GW_PROJECT_DIR/$CMD_PRO_NAME_VAL"
pushd $MICRO_GW_LABEL_PROJECT_DIR/gen > /dev/null
# clean the content of target folder
Expand Down
67 changes: 32 additions & 35 deletions distribution/resources/bin/micro-gw.bat
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ REM If the current disk drive ie: `E:\` is different from the drive where this (
if %verbose%==T ( ECHO Switch to drive '%wsasDrive%' if current drive '%curDrive%' not equal to program drive '%wsasDrive%' )
if NOT "%curDrive%" == "%wsasDrive%" %wsasDrive%:

REM if MICROGW_HOME environment variable not set then set it
if "%MICROGW_HOME%" == "" SET MICROGW_HOME=%PRGDIR%..

REM set BALLERINA_HOME
REM set BALLERINA_HOME
SET BALLERINA_HOME=%MICROGW_HOME%\lib\platform
if NOT EXIST %BALLERINA_HOME% SET BALLERINA_HOME="%MICROGW_HOME%\lib"

Expand Down Expand Up @@ -85,15 +86,13 @@ REM of arguments (up to the command line limit, anyway).
if ""%1""=="""" goto passToJar
if ""%1""==""help"" goto passToJar
if ""%1""==""build"" goto commandBuild
if ""%1""==""-java.debug"" goto commandDebug
if ""%1""==""java.debug"" goto commandDebug
if ""%1""==""--java.debug"" goto commandDebug
SHIFT
goto setupArgs

:usageInfo
ECHO Missing command operand
ECHO "Usage: micro-gw [-v] ([ -l ] setup | build)"
ECHO "Use: micro-gw [--verbose] (init | import | build)"
goto :end

:commandBuild
Expand All @@ -105,7 +104,7 @@ goto :end
if [%project_name%] == [] ( goto :noName ) else ( goto :nameFound )

:noName
ECHO "Project name not provided please follow the command usage patterns given below"
ECHO "micro-gw: main parameters are required (""), Run 'micro-gw help' for usage."
goto :usageInfo

:nameFound
Expand All @@ -121,33 +120,30 @@ goto :end

if ERRORLEVEL 1 goto :end

:continueBuild
goto :passToJar
REM set ballerina home again as the platform is extracted at this point.
SET BALLERINA_HOME=%MICROGW_HOME%\lib\platform
SET PATH=%PATH%;%BALLERINA_HOME%\bin\
if %verbose%==T ECHO BALLERINA_HOME environment variable is set to %BALLERINA_HOME%
pushd "%MICRO_GW_PROJECT_DIR%"
if %verbose%==T ECHO current dir %CD%
SET TARGET_DIR="%MICRO_GW_PROJECT_DIR%\target"
:: /s : Removes the specified directory and all subdirectories including any files. Use /s to remove a tree.
:: /q : Runs rmdir in quiet mode. Deletes directories without confirmation.
if EXIST "%TARGET_DIR%" ( RMDIR "%TARGET_DIR%" /s /q )
call ballerina build src -o %project_name:\=%.balx --experimental --siddhiruntime
popd
if %verbose%==T ECHO Ballerina build completed

set %* = %* --compiled

REM Check for a debug param by looping through the remaining args list
:checkDebug
SHIFT
if ""%1""=="""" goto passToJar

if ""%1""==""-java.debug"" goto commandDebug
if ""%1""==""java.debug"" goto commandDebug
if ""%1""==""--java.debug"" goto commandDebug
goto checkDebug
:continueBuild
call :passToJar
REM set ballerina home again as the platform is extracted at this point.
SET BALLERINA_HOME=%MICROGW_HOME%\lib\platform
SET PATH=%PATH%;%BALLERINA_HOME%\bin\
if %verbose%==T ECHO BALLERINA_HOME environment variable is set to %BALLERINA_HOME%
ECHO MICRO_GW_PROJECT_DIR: "%CURRENT_D%"
PUSHD "%CURRENT_D%"
PUSHD "%MICRO_GW_PROJECT_DIR%\gen"
if %verbose%==T ECHO current dir %CD%
SET TARGET_DIR="%MICRO_GW_PROJECT_DIR%\target"
if EXIST "%TARGET_DIR%" ( RMDIR "%TARGET_DIR%" /s /q )
call ballerina build src -o %project_name:\=%.balx --offline --experimental --siddhiruntime
POPD

if %verbose%==T ECHO Ballerina build completed
SET originalArgs=%originalArgs% --compiled

REM Check for a debug param by looping through the remaining args list
:checkDebug
SHIFT
if ""%1""=="""" goto passToJar
if ""%1""==""--java.debug"" goto commandDebug
goto checkDebug
goto :passToJar

:commandDebug
Expand All @@ -156,13 +152,13 @@ goto :passToJar
SHIFT
SET DEBUG_PORT=%1
if "%DEBUG_PORT%"=="" goto noDebugPort
if NOT "%JAVA_OPTS%"=="" ECHO Warning !!!. User specified JAVA_OPTS will be ignored, once you give the --debug option.
if NOT "%JAVA_OPTS%"=="" ECHO Warning !!!. User specified JAVA_OPTS will be ignored, once you give the --java.debug option.
SET JAVA_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%DEBUG_PORT%
ECHO Please start the remote debugging client to continue...
goto passToJar

:noDebugPort
ECHO Please specify the debug port after the java.debug option
ECHO Please specify the debug port after the --java.debug option
goto end


Expand Down Expand Up @@ -200,7 +196,7 @@ goto end
-Dfile.encoding=UTF8 ^
-Dtemplates.dir.path="%MICROGW_HOME%"\resources\templates ^
-Dcli.home="%MICROGW_HOME%" ^
-Dcurrent.dir=%CURRENT_D%
-Dcurrent.dir="%CD%" ^
-DVERBOSE_ENABLED=%verbose%
if %verbose%==T ECHO JAVACMD = !JAVACMD!

Expand All @@ -209,6 +205,7 @@ goto end
CD %MICROGW_HOME%
"%JAVA_HOME%\bin\java" %JAVACMD% org.wso2.apimgt.gateway.cli.cmd.Main %originalArgs%
if "%ERRORLEVEL%"=="121" goto runJava
if ERRORLEVEL 1 goto :end
:end
goto endlocal

Expand Down

0 comments on commit 2d62159

Please sign in to comment.