#!/bin/bash # Copyright (c) 2013 Red Hat, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the # distribution. # 3. Neither the name of Red Hat nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Authors: Mikolaj Izdebski set -e if [ $# -ne 4 ]; then echo "Usage: $0 orig-namespace shaded-namespace in.jar out.jar" >&2 echo "For example: $0 org.apache.log4j com.example.shaded.log4j \\" >&2 echo " /usr/share/java/log4j.jar lib/shaded-log4j.jar" >&2 exit 1 fi if [ ! -x /bin/objectweb-asm3-processor ]; then echo "$0: Unable to execute objectweb-asm3-processor." >&2 echo "$0: Make sure that objectweb-asm3 is installed." >&2 exit 1 fi tmp=$(mktemp -d) trap "rm -rf ${tmp}" 0 objectweb-asm3-processor code xml -in "${3}" -out "${tmp}/content.jar" 2>/dev/null mkdir "${tmp}/content" ( cd "${tmp}/content" jar xf ../content.jar find -name *.xml | xargs sed -i -e "s|${1//\.//}|${2//\.//}|g" -e "s|${1}|${2}|g" jar cfM ../content.jar * ) objectweb-asm3-processor xml code -in "${tmp}/content.jar" -out "${4}" 2>/dev/null exit 0