Skip to content

Commit

Permalink
Print path for testing
Browse files Browse the repository at this point in the history
Add print

Update condition

Update script

Update script

Update all test script

Add print msg

Add print

Add additional print msg

Update script changes

Update the script

Update the script

Update the script

Add another print statement
  • Loading branch information
kalaiyarasiganeshalingam committed Nov 23, 2024
1 parent e7b2eee commit da9771a
Show file tree
Hide file tree
Showing 17 changed files with 497 additions and 5 deletions.
12 changes: 7 additions & 5 deletions distribution/src/scripts/micro-integrator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export_env_file() {
# Read the .env file and export each variable to the environment
while IFS='=' read -r key value; do
# Ignore lines starting with '#' (comments) or empty lines
if [[ ! "$key" =~ ^# ]] && [[ "$key" != "" ]]; then
if [ ! "$key" =~ ^# ] && [ "$key" != "" ]; then
# Trim surrounding whitespace from key and value
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
Expand Down Expand Up @@ -168,11 +168,13 @@ do
else
args="$args $c"
fi
echo "11111111111111111111111111 $c"
# Check if the argument starts with --env-file=
if [[ "$c" == --env-file=* ]]; then
# Extract the file path from the argument
file_path="${c#--env-file=}"
export_env_file "$file_path"
if [ "$c" = "--env-file=*" ]; then
echo "_____________________ env file __________"
# Extract the file path from the argument
file_path="${c#--env-file=}"
export_env_file "$file_path"
fi
done

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import java.io.File;
import java.io.IOException;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -135,6 +138,16 @@ public synchronized void startServerUsingCarbonHome(String carbonHome, Map<Strin
}

cmdArray = mergePropertiesToCommandArray(parameters, cmdArray);
System.out.println("***********************_______________*****************************");
System.out.println(Arrays.toString(cmdArray));
System.out.println(commandDir.getPath());
Path filePath = Paths.get(cmdArray[1]);

// Read the file content into a string
String content = Files.readString(filePath, StandardCharsets.UTF_8);
// Print the file content
System.out.println(content);
System.out.println("****************************************************");
process = Runtime.getRuntime().exec(cmdArray, null, commandDir);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,32 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then
fi

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

# Function to export variables from the given .env file
export_env_file() {
local file_path="$1"

# Check if the file exists
if [ ! -f "$file_path" ]; then
echo "Error: File '$file_path' not found."
return 1 # Return with an error status
fi

# Read the .env file and export each variable to the environment
while IFS='=' read -r key value; do
# Ignore lines starting with '#' (comments) or empty lines
if [ ! "$key" =~ ^# ] && [ "$key" != "" ]; then
# Trim surrounding whitespace from key and value
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
# Export the key-value pair to the environment
export "$key=$value"
fi
done < "$file_path"

echo "Environment variables loaded from $file_path."
}

args=""
for c in $*
do
Expand All @@ -159,6 +185,12 @@ do
else
args="$args $c"
fi
# Check if the argument starts with --env-file=
if [ "$c" == --env-file=* ]; then
# Extract the file path from the argument
file_path="${c#--env-file=}"
export_env_file "$file_path"
fi
done

if [ "$CMD" = "--debug" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,32 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then
fi

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

# Function to export variables from the given .env file
export_env_file() {
local file_path="$1"

# Check if the file exists
if [ ! -f "$file_path" ]; then
echo "Error: File '$file_path' not found."
return 1 # Return with an error status
fi

# Read the .env file and export each variable to the environment
while IFS='=' read -r key value; do
# Ignore lines starting with '#' (comments) or empty lines
if [ ! "$key" =~ ^# ] && [ "$key" != "" ]; then
# Trim surrounding whitespace from key and value
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
# Export the key-value pair to the environment
export "$key=$value"
fi
done < "$file_path"

echo "Environment variables loaded from $file_path."
}

args=""
for c in $*
do
Expand All @@ -159,6 +185,12 @@ do
else
args="$args $c"
fi
# Check if the argument starts with --env-file=
if [ "$c" == --env-file=* ]; then
# Extract the file path from the argument
file_path="${c#--env-file=}"
export_env_file "$file_path"
fi
done

if [ "$CMD" = "--debug" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,32 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then
fi

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

# Function to export variables from the given .env file
export_env_file() {
local file_path="$1"

# Check if the file exists
if [ ! -f "$file_path" ]; then
echo "Error: File '$file_path' not found."
return 1 # Return with an error status
fi

# Read the .env file and export each variable to the environment
while IFS='=' read -r key value; do
# Ignore lines starting with '#' (comments) or empty lines
if [ ! "$key" =~ ^# ] && [ "$key" != "" ]; then
# Trim surrounding whitespace from key and value
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
# Export the key-value pair to the environment
export "$key=$value"
fi
done < "$file_path"

echo "Environment variables loaded from $file_path."
}

args=""
for c in $*
do
Expand All @@ -159,6 +185,12 @@ do
else
args="$args $c"
fi
# Check if the argument starts with --env-file=
if [ "$c" == --env-file=* ]; then
# Extract the file path from the argument
file_path="${c#--env-file=}"
export_env_file "$file_path"
fi
done

if [ "$CMD" = "--debug" ]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.esb.resource.test.api;

import org.apache.commons.lang3.StringUtils;
Expand All @@ -12,8 +29,11 @@
import org.wso2.esb.integration.common.utils.ESBIntegrationTest;
import org.wso2.esb.integration.common.utils.common.ServerConfigurationManager;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -56,6 +76,9 @@ public void testConfigurablePropertyWithSystemProperty() throws IOException, Aut
@Test(groups = {"wso2.esb"}, description = "Configurable property", priority = 3)
public void testConfigurablePropertyWithEnvVariable() throws IOException, AutomationUtilException {
Map<String, String> commands = new HashMap<>();
System.out.println("_________________________________");
System.out.println(FrameworkPathUtil.getSystemResourceLocation() + "test.env");
System.out.println("_________________________________");
commands.put("--env-file", FrameworkPathUtil.getSystemResourceLocation() + "test.env");
serverConfigurationManager.restartMicroIntegrator(commands);
Map<String, String> headers = new HashMap<>();
Expand All @@ -73,6 +96,15 @@ public void testConfigurableProperty() throws IOException, AutomationUtilExcepti
commands.put("-Dname", "sys");
commands.put("-Dmsg", "Hi");
commands.put("--env-file", FrameworkPathUtil.getSystemResourceLocation() + "test.env");
File env = new File(FrameworkPathUtil.getSystemResourceLocation() + "test.env");
if (env.exists()) {
System.out.println("________--env-file File Exist_____________");
}
if (env.canRead()) {
System.out.println("________--env-file readable_____________");
System.out.println(Files.readString(env.toPath(), StandardCharsets.UTF_8));
}

serverConfigurationManager.restartMicroIntegrator(commands);
Map<String, String> headers = new HashMap<>();
URL endpoint = new URL(getApiInvocationURL("apiConfig/test"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,32 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then
fi

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

# Function to export variables from the given .env file
export_env_file() {
local file_path="$1"

# Check if the file exists
if [ ! -f "$file_path" ]; then
echo "Error: File '$file_path' not found."
return 1 # Return with an error status
fi

# Read the .env file and export each variable to the environment
while IFS='=' read -r key value; do
# Ignore lines starting with '#' (comments) or empty lines
if [ ! "$key" =~ ^# ] && [ "$key" != "" ]; then
# Trim surrounding whitespace from key and value
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
# Export the key-value pair to the environment
export "$key=$value"
fi
done < "$file_path"

echo "Environment variables loaded from $file_path."
}

args=""
for c in $*
do
Expand All @@ -139,6 +165,12 @@ do
else
args="$args $c"
fi
# Check if the argument starts with --env-file=
if [ "$c" == --env-file=* ]; then
# Extract the file path from the argument
file_path="${c#--env-file=}"
export_env_file "$file_path"
fi
done

if [ "$CMD" = "--debug" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,32 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then
fi

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

# Function to export variables from the given .env file
export_env_file() {
local file_path="$1"

# Check if the file exists
if [ ! -f "$file_path" ]; then
echo "Error: File '$file_path' not found."
return 1 # Return with an error status
fi

# Read the .env file and export each variable to the environment
while IFS='=' read -r key value; do
# Ignore lines starting with '#' (comments) or empty lines
if [ ! "$key" =~ ^# ] && [ "$key" != "" ]; then
# Trim surrounding whitespace from key and value
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
# Export the key-value pair to the environment
export "$key=$value"
fi
done < "$file_path"

echo "Environment variables loaded from $file_path."
}

args=""
for c in $*
do
Expand All @@ -159,6 +185,12 @@ do
else
args="$args $c"
fi
# Check if the argument starts with --env-file=
if [ "$c" == --env-file=* ]; then
# Extract the file path from the argument
file_path="${c#--env-file=}"
export_env_file "$file_path"
fi
done

if [ "$CMD" = "--debug" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,32 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then
fi

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

# Function to export variables from the given .env file
export_env_file() {
local file_path="$1"

# Check if the file exists
if [ ! -f "$file_path" ]; then
echo "Error: File '$file_path' not found."
return 1 # Return with an error status
fi

# Read the .env file and export each variable to the environment
while IFS='=' read -r key value; do
# Ignore lines starting with '#' (comments) or empty lines
if [ ! "$key" =~ ^# ] && [ "$key" != "" ]; then
# Trim surrounding whitespace from key and value
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
# Export the key-value pair to the environment
export "$key=$value"
fi
done < "$file_path"

echo "Environment variables loaded from $file_path."
}

args=""
for c in $*
do
Expand All @@ -139,6 +165,12 @@ do
else
args="$args $c"
fi
# Check if the argument starts with --env-file=
if [ "$c" == --env-file=* ]; then
# Extract the file path from the argument
file_path="${c#--env-file=}"
export_env_file "$file_path"
fi
done

if [ "$CMD" = "--debug" ]; then
Expand Down
Loading

0 comments on commit da9771a

Please sign in to comment.