Reputation: 33
I need a Bash script to get the value of outputDirectory tag under fileset from Maven assembly.xml, so I could handle created files.
I don't mean the actual character set between the opening and closing tags, but the default value if the tag is empty or the value of the variable if there is one in that tag.
I created a an assembly xml with different fileSet tags, just to display various cases I need to handle. I want a script which will give me the paths of the output directory as Maven sees them
<assembly>
<id>${deploy.name}</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<outputDirectory></outputDirectory>
</fileSet>
<fileSet>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<outputDirectory>/examples</outputDirectory>
</fileSet>
<fileSet>
<outputDirectory>${Common.shared.location}</outputDirectory>
</fileSet>
</fileSets>
</assembly>
Update: Maven saves the created file in the output directory. The base directory of of outputDirectory is by default the value of ${project.build.directory} and there is nice explanation about it here Maven: specify the outputDirectory only for packaging a jar?
I have a variable in a script, which I want to have the path of the folder where Maven would save the output file. After each of the example outputDirectory tags below, there is a line which I believe should be the value of the variable I want.
value of ${project.build.directory}
/ I'm not sure
/examples value of ${project.build.directory}/examples
${Common.shared.location} depends on the value of the ${Common.shared.location} variable
Thanks
Upvotes: 1
Views: 195
Reputation: 2783
You can use sed
with regex:
for match in $(sed -n 's|<outputDirectory>\(.*\)</outputDirectory>|\1|p' assembly.xml) ; do
echo "$match"
done
Explanation:
The sed 's|...|...|p'
prints matches for the regex <outputDirectory>\(.*\)</outputDirectory>
, which matches any text between two <outputDirectory>
tags. The for match in ...
iterates over the matches and prints them to stdout.
Upvotes: 1