Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
checkplugin script
#!/bin/bash
if [[ -z "$1" ]]; then
echo
echo "Usage: checkplugin <jar filename>"
echo "Output:"
echo "- Relevant attributes from root element in atlassian-plugin.xml (key, version)"
echo "- Relevant <plugin-info> params from atlassian-plugin.xml (configure URL, icons etc.)"
echo "- Checks for presence of necessary files embedded in jar (license storage library, image files)"
echo "- Relevant bundle instructions from manifest"
echo
exit 1
fi
JAR=$1
function getXml() {
unzip -c $JAR atlassian-plugin.xml
}
function getManifest() {
unzip -c $JAR META-INF/MANIFEST.MF | tr -d '\r'
}
function listJarFiles() {
jar tf $JAR
}
function findJarFile() {
if [[ -n "$1" ]]; then
listJarFiles | grep $1
fi
}
function showPluginAttribute() {
echo "$1: " `getXml | sed -n -e "s#.*atlassian-plugin *.*$1=\"\([^\"]*\)\".*#\1#p"`
}
function getPluginInfoParam() {
getXml | sed -n -e "s#.*<param name=\"$1\">\(.*\)</param>.*#\1#p"
}
function findJarFileForInfoParam() {
findJarFile `getPluginInfoParam $1`
}
function showPluginInfoParam() {
echo "$1: " `getPluginInfoParam $1`
}
function showManifestHeader() {
echo -n "$1: "
getManifest | sed -n -e "/^$1:/,/^[^ ]/ p" | sed -e "s#^$1: *# #" | sed -n -e 's#^ ##p' | tr -d '\n'
echo
echo
}
echo
echo "== atlassian-plugin.xml =="
showPluginAttribute key
showPluginAttribute plugins-version
showPluginInfoParam atlassian-licensing-enabled
showPluginInfoParam plugin-icon
showPluginInfoParam plugin-logo
showPluginInfoParam plugin-banner
showPluginInfoParam configure.url
echo
echo "== jar files =="
echo "license storage lib: " `findJarFile META-INF/lib/plugin-license-storage-lib`
echo "icon: " `findJarFileForInfoParam plugin-icon`
echo "logo: " `findJarFileForInfoParam plugin-logo`
echo "banner: " `findJarFileForInfoParam plugin-banner`
echo
echo "== manifest =="
showManifestHeader Atlassian-Build-Date
showManifestHeader Bundle-ClassPath
showManifestHeader Import-Package
showManifestHeader DynamicImport-Package
showManifestHeader Private-Package
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment