Skip to content

Commit 6538777

Browse files
committed
support absolute path option for find-in-jars
1 parent 2f8193a commit 6538777

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

docs/java.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ find-in-jars 'log4j\.properties$' -d /path/to/find/directory
344344
# 支持多个查找目录
345345
find-in-jars 'log4j\.properties' -d /path/to/find/directory1 -d /path/to/find/directory2
346346
347+
# -a选项 指定 查找结果中的Jar文件使用绝对路径
348+
# 分享给别人时,Jar文件路径是完整的,方便别人找到文件
349+
find-in-jars 'log4j\.properties' -a
350+
347351
# 帮助信息
348352
$ find-in-jars -h
349353
Usage: find-in-jars [OPTION]... PATTERN
@@ -358,12 +362,13 @@ Example:
358362
359363
Options:
360364
-d, --dir the directory that find jar files, default is current directory.
361-
this option can specify multiply times to find in multiply directory.
365+
this option can specify multiply times to find in multiply directories.
362366
-E, --extended-regexp PATTERN is an extended regular expression (*default*)
363367
-F, --fixed-strings PATTERN is a set of newline-separated strings
364368
-G, --basic-regexp PATTERN is a basic regular expression
365369
-P, --perl-regexp PATTERN is a Perl regular expression
366370
-i, --ignore-case ignore case distinctions
371+
-a, --absolute-path always print absolute path of jar file
367372
-h, --help display this help and exit
368373
```
369374
@@ -376,23 +381,18 @@ Options:
376381
$ find-in-jars 'log4j\.properties$'
377382
./hadoop-core-0.20.2-cdh3u3.jar!log4j.properties
378383
379-
# 查找出 以Service结尾的类
380-
$ ./find-in-jars 'Service.class$'
381-
./WEB-INF/libs/spring-2.5.6.SEC03.jar!org/springframework/stereotype/Service.class
382-
./rpc-benchmark-0.0.1-SNAPSHOT.jar!com/taobao/rpc/benchmark/service/HelloService.class
384+
# 查找出 以Service结尾的类,Jar文件路径输出成绝对路径
385+
$ find-in-jars 'Service.class$' -a
386+
/home/foo/deploy/app/WEB-INF/libs/spring-2.5.6.SEC03.jar!org/springframework/stereotype/Service.class
387+
/home/foo/deploy/app/WEB-INF/libs/rpc-hello-0.0.1-SNAPSHOT.jar!com/taobao/biz/HelloService.class
383388
......
384389
385390
# 在指定的多个目录的Jar文件中,查找出 properties文件
386-
$ find-in-jars '\.properties$' -d ../WEB-INF/lib -d ../deploy/lib | grep -v '/pom\.properties$'
387-
../WEB-INF/lib/aspectjtools-1.6.2.jar!org/aspectj/ajdt/ajc/messages.properties
388-
../WEB-INF/lib/aspectjtools-1.6.2.jar!org/aspectj/ajdt/internal/compiler/parser/readableNames.properties
389-
../WEB-INF/lib/aspectjweaver-1.8.8.jar!org/aspectj/weaver/XlintDefault.properties
390-
../WEB-INF/lib/aspectjweaver-1.8.8.jar!org/aspectj/weaver/weaver-messages.properties
391+
$ find-in-jars '\.properties$' -d WEB-INF/lib -d ../deploy/lib | grep -v '/pom\.properties$'
392+
WEB-INF/lib/aspectjtools-1.6.2.jar!org/aspectj/ajdt/ajc/messages.properties
393+
WEB-INF/lib/aspectjweaver-1.8.8.jar!org/aspectj/weaver/XlintDefault.properties
391394
../deploy/lib/groovy-all-1.1-rc-1.jar!groovy/ui/InteractiveShell.properties
392-
../deploy/lib/groovy-all-1.1-rc-1.jar!org/codehaus/groovy/tools/shell/CommandAlias.properties
393395
../deploy/lib/httpcore-4.3.3.jar!org/apache/http/version.properties
394-
../deploy/lib/httpmime-4.2.2.jar!org/apache/http/entity/mime/version.properties
395-
../deploy/lib/javax.servlet-api-3.0.1.jar!javax/servlet/LocalStrings_fr.properties
396396
../deploy/lib/javax.servlet-api-3.0.1.jar!javax/servlet/http/LocalStrings_es.properties
397397
......
398398
```

find-in-jars

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ Example:
2929
3030
Options:
3131
-d, --dir the directory that find jar files, default is current directory.
32-
this option can specify multiply times to find in multiply directory.
32+
this option can specify multiply times to find in multiply directories.
3333
-E, --extended-regexp PATTERN is an extended regular expression (*default*)
3434
-F, --fixed-strings PATTERN is a set of newline-separated strings
3535
-G, --basic-regexp PATTERN is a basic regular expression
3636
-P, --perl-regexp PATTERN is a Perl regular expression
3737
-i, --ignore-case ignore case distinctions
38+
-a, --absolute-path always print absolute path of jar file
3839
-h, --help display this help and exit
3940
EOF
4041

@@ -45,9 +46,10 @@ EOF
4546
# parse options
4647
################################################################################
4748

48-
args=()
49-
dirs=()
49+
declare -a args=()
50+
declare -a dirs=()
5051
regex_mode=-E
52+
use_absolute_path=false
5153
while [ $# -gt 0 ]; do
5254
case "$1" in
5355
-d|--dir)
@@ -74,6 +76,10 @@ while [ $# -gt 0 ]; do
7476
ignore_case_option=-i
7577
shift
7678
;;
79+
-a|--absolute-path)
80+
use_absolute_path=true
81+
shift
82+
;;
7783
-h|--help)
7884
usage
7985
;;
@@ -89,6 +95,17 @@ dirs=${dirs:-.}
8995
[ "${#args[@]}" -gt 1 ] && { echo "More than 1 file pattern!" 1>&2 ; usage 1; }
9096
readonly pattern="${args[0]}"
9197

98+
# convert dirs to Absolute Path.
99+
$use_absolute_path && {
100+
declare -a tmp_dirs=()
101+
102+
for d in "${dirs[@]}"; do
103+
tmp_dirs=( "${tmp_dirs[@]}" "$(cd "$d" && pwd)" )
104+
done
105+
106+
dirs=( "${tmp_dirs[@]}" )
107+
}
108+
92109
################################################################################
93110
# Check the existence of command for listing zip entry!
94111
################################################################################

0 commit comments

Comments
 (0)