Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f2b02b

Browse files
committed
File list scripts improvements
1 parent 3686d1e commit 3f2b02b

3 files changed

Lines changed: 78 additions & 56 deletions

File tree

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
11
@echo off
22
setlocal EnableDelayedExpansion
33

4-
REM Using cd to remove the " from paths.
5-
cd %1
6-
set clientPath=%__CD__%
7-
cd %2
8-
set projectPath=%__CD__%
9-
set sourcePath=%3
10-
set testPath=%4
11-
12-
set sqlFile=%clientPath%\project_file_list.sql.tmp
13-
14-
echo begin>%sqlFile%
15-
echo ^ null;>>%sqlFile%
16-
17-
if not %sourcePath% == "-" (
18-
echo open :l_source_files for select * from table(ut_varchar2_list(>>%sqlFile%
19-
call :FileList %sourcePath%
4+
set clientPath=%~1
5+
set projectPath=%~2
6+
set scanPath=%~3
7+
set outFileName=%~4
8+
set sqlParamName=%~5
9+
10+
REM All parameters are required.
11+
set invalidArgs=0
12+
if "%clientPath%" == "" set invalidArgs=1
13+
if "%projectPath%" == "" set invalidArgs=1
14+
if "%scanPath%" == "" set invalidArgs=1
15+
if "%outFileName%" == "" set invalidArgs=1
16+
if "%sqlParamName%" == "" set invalidArgs=1
17+
18+
if %invalidArgs% == 1 (
19+
echo Usage: ut_run.bat "client_path" "project_path" "scan_path" "out_file_name" "sql_param_name"
20+
exit /b 1
2021
)
2122

22-
if not %testPath% == "-" (
23-
echo open :l_test_files for select * from table(ut_varchar2_list(>>%sqlFile%
24-
call :FileList %testPath%
25-
)
23+
REM Remove trailing slashes.
24+
if %clientPath:~-1%==\ set clientPath=%clientPath:~0,-1%
25+
if %projectPath:~-1%==\ set projectPath=%projectPath:~0,-1%
2626

27-
echo end;>>%sqlFile%
28-
echo />>%sqlFile%
27+
set fullOutPath="%clientPath%\%outFileName%"
28+
set fullScanPath="%projectPath%\%scanPath%"
2929

30-
goto :eof
30+
REM If scan path was -, bypass the file list generation.
31+
if "%scanPath%" == "-" (
32+
echo begin>%fullOutPath%
33+
echo ^ open :%sqlParamName% for select null from dual;>>%fullOutPath%
34+
echo end;>>%fullOutPath%
35+
echo />>%fullOutPath%
36+
exit /b 0
37+
)
3138

32-
:FileList
33-
for /f "tokens=* delims= " %%a in ('dir %projectPath%\%1\* /B /S /A:-D') do (
39+
echo begin>%fullOutPath%
40+
echo ^ open :%sqlParamName% for select * from table(ut_varchar2_list(>>%fullOutPath%
41+
for /f "tokens=* delims= " %%a in ('dir %fullScanPath%\* /B /S /A:-D') do (
3442
set "filePath=%%a"
35-
set filePath=!filePath:%projectPath%=!
36-
echo ^ '!filePath!^',>>%sqlFile%
43+
set filePath=!filePath:%projectPath%\=!
44+
echo ^ '!filePath!^',>>%fullOutPath%
3745
)
38-
echo null));>>%sqlFile%
46+
echo ^ null));>>%fullOutPath%
47+
echo end;>>%fullOutPath%
48+
echo />>%fullOutPath%

client_source/sqlplus/file_list.sh

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
11
#!/bin/bash
22
set -e
33

4-
# Using cd to remove the " from paths.
5-
clientPath=$1
6-
projectPath=$2
7-
sourcePath=$3
8-
testPath=$4
4+
clientPath=${1%/}
5+
projectPath=${2%/}
6+
scanPath=$3
7+
outFileName=$4
8+
sqlParamName=$5
99

10-
sqlFile=$clientPath/project_file_list.sql.tmp
10+
# All parameters are required.
11+
invalidArgs=0
12+
[ -z "$clientPath" ] && invalidArgs=1
13+
[ -z "$projectPath" ] && invalidArgs=1
14+
[ -z "$scanPath" ] && invalidArgs=1
15+
[ -z "$outFileName" ] && invalidArgs=1
16+
[ -z "$sqlParamName" ] && invalidArgs=1
1117

12-
function fileList {
13-
for f in $(find $projectPath/$1/* -type f | sed "s|$projectPath/||"); do
14-
echo " '$f'," >> $sqlFile
15-
done
16-
echo " null));" >> $sqlFile
17-
}
18-
19-
echo "begin" > $sqlFile
20-
echo " null;" >> $sqlFile
21-
22-
if [ ! "$sourcePath" == "-" ]; then
23-
echo " :l_source_files := q'[ut_varchar2_list(" >> $sqlFile
24-
fileList $sourcePath
18+
if [ $invalidArgs -eq 1 ]; then
19+
echo Usage: ut_run.sh "client_path" "project_path" "scan_path" "out_file_name" "sql_param_name"
20+
exit 1
2521
fi
2622

27-
if [ ! "$testPath" == "-" ]; then
28-
echo " :l_test_files := q'[ut_varchar2_list(" >> $sqlFile
29-
fileList $testPath
23+
fullOutPath="$clientPath/$outFileName"
24+
fullScanPath="$projectPath/$scanPath"
25+
26+
# If scan path was -, bypass the file list generation.
27+
if [ "$scanPath" == "-" ]; then
28+
echo "begin" > $fullOutPath
29+
echo " open :$sqlParamName for select null from dual;" >> $fullOutPath
30+
echo "end;" >> $fullOutPath
31+
echo "/" >> $fullOutPath
32+
exit 0
3033
fi
3134

32-
echo "end;" >> $sqlFile
33-
echo "/" >> $sqlFile
35+
echo "begin" > $fullOutPath
36+
echo " open :$sqlParamName for select * from table(ut_varchar2_list(" >> $fullOutPath
37+
for f in $(find $fullScanPath/* -type f | sed "s|$projectPath/||"); do
38+
echo " '$f'," >> $fullOutPath
39+
done
40+
echo " null));" >> $fullOutPath
41+
echo "end;" >> $fullOutPath
42+
echo "/" >> $fullOutPath

client_source/sqlplus/ut_run.sql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,17 +333,20 @@ column test_path new_value test_path noprint;
333333
select :l_test_path as test_path from dual;
334334

335335
--try running on windows
336-
$ &&client_path\file_list.bat "&&client_path" "&&project_path" "&&source_path" "&&test_path"
336+
$ &&client_path\file_list.bat "&&client_path" "&&project_path" "&&source_path" "source_file_list.sql.tmp" "l_source_files"
337+
$ &&client_path\file_list.bat "&&client_path" "&&project_path" "&&test_path" "test_file_list.sql.tmp" "l_test_files"
337338
--try running on linux/unix
338-
! &&client_path/file_list.sh "&&client_path" "&&project_path" "&&source_path" "&&test_path"
339+
! &&client_path/file_list.sh "&&client_path" "&&project_path" "&&source_path" "source_file_list.sql.tmp" "l_source_files"
340+
! &&client_path/file_list.sh "&&client_path" "&&project_path" "&&test_path" "test_file_list.sql.tmp" "l_test_files"
341+
339342
undef source_path
340343
undef test_path
341344

342-
343345
/*
344346
* Generate the project source and tests files, saving it into the l_source_files and l_test_files bind variables
345347
*/
346-
@&&client_path/project_file_list.sql.tmp
348+
@&&client_path/source_file_list.sql.tmp
349+
@&&client_path/test_file_list.sql.tmp
347350

348351

349352
/*

0 commit comments

Comments
 (0)