Created
July 10, 2013 08:07
-
-
Save robstryker/5964345 to your computer and use it in GitHub Desktop.
quickly get the GAV for a jar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Requires 2 files. | |
File 1: getGav.sh | |
#/bin/sh | |
#getGav.sh | |
TMPFILE=/home/rob/tmp/tmpfile.xml | |
EXTRACTGAV=/home/rob/scripts/extract-gav.xsl | |
FILE2=`ls $1 | awk '{ print "unzip -l " $0 " | grep pom.xml | cut -d M -f 2";}' | sh | awk '{ print "M" $0;}' ` | |
unzip -q -c $1 $FILE2 > $TMPFILE && xsltproc $EXTRACTGAV $TMPFILE | head -n 4 | tail -n 3 && rm $TMPFILE | |
File 2: extract-gav.xsl | |
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:pom="http://maven.apache.org/POM/4.0.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output indent="yes" omit-xml-declaration="yes"/> | |
<xsl:strip-space elements="*"/> | |
<xsl:template match="/pom:project"> | |
<!-- this XML element just serves as a bracket and may be omitted --> | |
<xsl:element name="artifact"> | |
<xsl:text> </xsl:text> | |
<!-- process coordinates declared at project and project/parent --> | |
<xsl:apply-templates select="pom:groupId|pom:parent/pom:groupId" mode="copy-coordinate"/> | |
<xsl:apply-templates select="pom:artifactId|pom:parent/pom:artifactId" mode="copy-coordinate"/> | |
<xsl:apply-templates select="pom:version|pom:parent/pom:version" mode="copy-coordinate"/> | |
</xsl:element> | |
</xsl:template> | |
<xsl:template match="*" mode="copy-coordinate"> | |
<!-- omit parent coordinate if same coordinate is explicitly specified on project level --> | |
<xsl:if test="not(../../*[name(.)=name(current())])"> | |
<!-- write coordinate as XML element without namespace declarations --> | |
<xsl:element name="{local-name()}"> | |
<xsl:value-of select="."></xsl:value-of> | |
</xsl:element> | |
<xsl:text> </xsl:text> | |
</xsl:if> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment