Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Ohmyzsh
Commits
f4b2e460
Commit
f4b2e460
authored
Feb 17, 2019
by
Marc Cornellà
Browse files
mvn: fix and cleanup dynamic profiles logic
parent
fff75606
Changes
1
Hide whitespace changes
Inline
Side-by-side
plugins/mvn/mvn.plugin.zsh
View file @
f4b2e460
...
@@ -68,64 +68,43 @@ alias mvntc='mvn tomcat:run'
...
@@ -68,64 +68,43 @@ alias mvntc='mvn tomcat:run'
alias
mvntc7
=
'mvn tomcat7:run'
alias
mvntc7
=
'mvn tomcat7:run'
alias
mvn-updates
=
'mvn versions:display-dependency-updates'
alias
mvn-updates
=
'mvn versions:display-dependency-updates'
#realpath replacement for iOS - not always present
function
_realpath
{
if
[[
-f
"
$1
"
]]
then
# file *must* exist
if
cd
"
$(
echo
"
${
1
%/*
}
"
)
"
&>/dev/null
then
# file *may* not be local
# exception is ./file.ext
# try 'cd .; cd -;' *works!*
local
tmppwd
=
"
$PWD
"
cd
- &>/dev/null
else
# file *must* be local
local
tmppwd
=
"
$PWD
"
fi
else
# file *cannot* exist
return
1
# failure
fi
# reassemble realpath
function
listMavenCompletions
{
echo
"
$tmppwd
"
/
"
${
1
##*/
}
"
local
file new_file
return
1
#success
local
-a
profiles POM_FILES
}
# Root POM
POM_FILES
=(
~/.m2/settings.xml
)
function
__pom_hierarchy
{
# POM in the current directory
local
file
=
`
_realpath
"pom.xml"
`
if
[[
-f
pom.xml
]]
;
then
POM_HIERARCHY+
=(
"~/.m2/settings.xml"
)
local
file
=
pom.xml
POM_HIERARCHY+
=(
"
$file
"
)
POM_FILES+
=(
"
${
file
:A
}
"
)
while
[
-n
"
$file
"
]
&&
grep
-q
"<parent>"
$file
;
do
fi
##look for a new relativePath for parent pom.xml
local
new_file
=
`
grep
-e
"<relativePath>.*</relativePath>"
$file
|
sed
's/.*<relativePath>//'
|
sed
's/<\/relativePath>.*//g'
`
## <parent> is present but not defined. Asume ../pom.xml
# Look for POM files in parent directories
if
[
-z
"
$new_file
"
]
;
then
while
[[
-n
"
$file
"
]]
&&
grep
-q
"<parent>"
"
$file
"
;
do
# look for a new relativePath for parent pom.xml
new_file
=
$(
grep
-e
"<relativePath>.*</relativePath>"
"
$file
"
|
sed
-e
's/.*<relativePath>\(.*\)<\/relativePath>.*/\1/'
)
# if <parent> is present but not defined, assume ../pom.xml
if
[[
-z
"
$new_file
"
]]
;
then
new_file
=
"../pom.xml"
new_file
=
"../pom.xml"
fi
fi
## if file exists continue else break
# if file doesn't exist break
new_pom
=
`
_realpath
"
${
file
%/*
}
/
$new_file
"
`
file
=
"
${
file
:h
}
/
${
new_file
}
"
if
[
-n
"
$new_pom
"
]
;
then
if
!
[[
-e
"
$file
"
]]
;
then
file
=
$new_pom
else
break
break
fi
fi
POM_HIERARCHY+
=(
"
$file
"
)
done
}
function
listMavenCompletions
{
POM_FILES+
=(
"
${
file
:A
}
"
)
POM_HIERARCHY
=()
done
__pom_hierarchy
profiles
=()
# Get
profiles
from found files
#current pom profiles
for
file
in
$POM_FILES
;
do
for
item
in
${
POM_HIERARCHY
[*]
}
;
do
[[
-e
$file
]]
||
continue
profiles
=(
$
profiles
`
[
-e
$item
]
&&
cat
$item
|
sed
's/<!--.*-->//'
|
sed
'/<!--/,/-->/d'
|
grep
-e
"<profile>"
-A
1 |
grep
-e
"<id>.*</id>"
|
sed
's?.*<id>\(.*\)<\/id>.*?-P\1?'
`
)
profiles
+
=(
$
(
sed
's/<!--.*-->//'
"
$file
"
|
sed
'/<!--/,/-->/d'
|
grep
-e
"<profile>"
-A
1 |
grep
-e
"<id>.*</id>"
|
sed
's?.*<id>\(.*\)<\/id>.*?-P\1?'
)
)
done
done
reply
=(
reply
=(
...
@@ -339,9 +318,6 @@ function listMavenCompletions {
...
@@ -339,9 +318,6 @@ function listMavenCompletions {
$profiles
$profiles
)
)
unset
POM_HIERARCHY
unset
profiles
}
}
compctl
-K
listMavenCompletions mvn mvnw
compctl
-K
listMavenCompletions mvn mvnw
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment