Last active
December 28, 2017 22:17
-
-
Save codingtony/e69069a5793cc2a2b0854dad83b56167 to your computer and use it in GitHub Desktop.
XSLT Add SCM tag to pom.xm
This file contains 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
<?xml version="1.0"?> | |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:pom="http://maven.apache.org/POM/4.0.0" xmlns="http://maven.apache.org/POM/4.0.0" version="1.0"> | |
<xsl:output omit-xml-declaration="yes" indent="yes"/> | |
<xsl:strip-space elements="*"/> | |
<xsl:template match="node()|@*"> | |
<xsl:copy> | |
<xsl:apply-templates select="node()|@*"/> | |
</xsl:copy> | |
</xsl:template> | |
<xsl:template match="pom:scm"> | |
<xsl:apply-templates select="@*"/> | |
<scm> | |
<connection>scm:git:__GIT_URL__</connection> | |
<developerConnection>scm:git:__GIT_URL__</developerConnection> | |
</scm> | |
</xsl:template> | |
<!-- take care when scm is not present --> | |
<xsl:template match="pom:project[not(pom:scm)]"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*"/> | |
<scm xmlns="http://maven.apache.org/POM/4.0.0"> | |
<connection>scm:git:__GIT_URL__</connection> | |
<developerConnection>scm:git:__GIT_URL__</developerConnection> | |
</scm> | |
<xsl:apply-templates select="node()"/> | |
</xsl:copy> | |
</xsl:template> | |
<!-- take care when scm is present but no connection children --> | |
<xsl:template match="pom:scm[not(pom:developerConnection) and not(pom:connection)]"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*"/> | |
<connection xmlns="http://maven.apache.org/POM/4.0.0">scm:git:__GIT_URL__</connection> | |
<developerConnection xmlns="http://maven.apache.org/POM/4.0.0">scm:git:__GIT_URL__</developerConnection> | |
<xsl:apply-templates select="node()"/> | |
</xsl:copy> | |
</xsl:template> | |
<!-- take care when scm is present but connection child, no dev connection --> | |
<xsl:template match="pom:scm[not(pom:connection) and pom:developerConnection]"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*"/> | |
<connection xmlns="http://maven.apache.org/POM/4.0.0">scm:git:__GIT_URL__</connection> | |
<xsl:apply-templates select="node()"/> | |
</xsl:copy> | |
</xsl:template> | |
<!-- take care when scm is present with dev connection child, but no connection --> | |
<xsl:template match="pom:scm[not(pom:developerConnection) and pom:connection]"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*"/> | |
<developerConnection xmlns="http://maven.apache.org/POM/4.0.0">scm:git:__GIT_URL__</developerConnection> | |
<xsl:apply-templates select="node()"/> | |
</xsl:copy> | |
</xsl:template> | |
<!-- put scm at the end --> | |
<xsl:template match="pom:project"> | |
<xsl:copy> | |
<xsl:copy-of select="pom:*[not(self::pom:scm)]"/> | |
<xsl:copy-of select="pom:scm"/> | |
</xsl:copy> | |
</xsl:template> | |
</xsl:stylesheet> |
This file contains 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
#GIT_URL=$(git remote -v | grep push | awk '{ print $2 }' | sed "s#[email protected]:#https://gonebig.com/gitlab/#") | |
GIT_URL=$(git remote -v | grep push | grep ^origin | awk '{ print $2 }') | |
xsltproc <(curl -s https://gist.githubusercontent.com/codingtony/e69069a5793cc2a2b0854dad83b56167/raw/scm.xslt | sed "s#__GIT_URL__#${GIT_URL}#g") pom.xml > __new.xml && mv __new.xml pom.xml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment