Last active
September 2, 2015 07:08
-
-
Save paoloantinori/37756482992481d24caf to your computer and use it in GitHub Desktop.
Helper function to automatically install manually downloaded Maven artifacts to local Maven repo.
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
#!/bin/bash | |
# | |
# Automates installation of manually downloaded artifacts in local Maven repo | |
# NOTE: works only if artifact contains its own metadata files | |
# | |
# Ex. 1 | |
# maven_install_artifact_locally.sh fabric-core-1.2.0.redhat-133.jar | |
# Ex. 2 | |
# find -name *.jar | xargs -n1 maven_install_artifact_locally.sh | |
# | |
function mvn_install_artifact_locally() { | |
local artifact="$1"; | |
local found_metadata=$(unzip -l $artifact 2> /dev/null | grep "META-INF/maven/.*pom.properties"| wc -l); | |
if [[ $found_metadata == 1 ]] ; then | |
local GAV_map=$(unzip -c $artifact "META-INF/maven/*pom.properties") | |
local version=$(echo $GAV_map | grep -Po '(?<=version=)[^\s]+') | |
local artifactId=$(echo $GAV_map | grep -Po '(?<=artifactId=)[^\s]+') | |
local groupId=$(echo $GAV_map | grep -Po '(?<=groupId=)[^\s]+') | |
local extension=${artifact##*.} | |
echo "Found Maven coordinates: [$groupId/$artifactId/$version/$extension]" | |
mvn install:install-file -Dfile=$artifact -DgroupId=$groupId -DartifactId=$artifactId -Dversion=$version -Dpackaging=$extension | |
else | |
echo "Artifact [$1] does not contain expected metadata to automate the installation"; | |
fi | |
} | |
mvn_install_artifact_locally "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment