monstadubois7 / jarjar

Automatically exported from code.google.com/p/jarjar
0 stars 0 forks source link

Java source filenames ignored by jarjar rules that work for classes. #57

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
JarJar currently (v1.4) handles source filenames specially and does not perform 
coherent rewrites of source filenames to align with successful class renames, 
e.g.:

in foo.jar:

  com.google.foo.Bar -> com.google.foo.Bar1

in foo-src.jar:

  com/google/foo/Bar.java -> com/google/foo/Bar1.java # does not work!

The following script rewrites Objectify (for Google AppEngine) to work around 
this.

#!/bin/bash

# Use JarJar to rewrite Objectify class and source jars, but include a
# workaround for rewriting sources that are missed by JarJar

JARJARJAR=third_party/java/jarjar/v1_4/jarjar-1.4.jar
test -e $JARJARJAR || (echo "Error: missing $JARJARJAR" ; exit)
JARJAR="java -jar $JARJARJAR"

# Class jar                                                                     

IN_JAR=objectify-4.0b1.jar
OUT_JAR=objectify-4.0b1-repackaged.jar
test -e $IN_JAR || (echo "Error: missing $IN_JAR" ; exit)

# Source jar                                                                    

IN_SRC=objectify-4.0b1-sources.jar
OUT_SRC=objectify-4.0b1-src.jar
test -e $IN_SRC || (echo "Error: missing $IN_SRC" ; exit)

# Target directory                                                              

THIRD_PARTY_OBJECTIFY_V4=third_party/java/objectify/v4_0/
test -e $THIRD_PARTY/JAVA/OBJECTIFY/V4_0/$OUT_JAR && \
  (echo "Error: will not clobber $THIRD_PARTY_OBJECTIFY_V4/$OUT_JAR" ; exit)
test -e $THIRD_PARTY/JAVA/OBJECTIFY/V4_0/$OUT_SRC && \
  (echo "Error: will not clobber $THIRD_PARTY_OBJECTIFY_V4/$OUT_SRC" ; exit)

TMP=/tmp/objectify
(rm -rf $TMP && mkdir $TMP) || (echo "Cannot clean and use $TMP" ; exit)

# JarJar rewrite rules; note the suffix of rule 2 needs to match the            

# sed scripts below.                                                            

RULE_FILE=rulefile
cat > $RULE_FILE <<EOF                                                          

rule **.objectify.** @1.objectify.v4.@2                                         

rule **CustomFieldSerializer @1CustomFieldSerializerV4                          

EOF

# Rewrite class jar and save it to target directory                             

$JARJAR process $RULE_FILE $IN_JAR $OUT_JAR
mv $OUT_JAR $THIRD_PARTY_OBJECTIFY_V4

# Sources can't fully be rewritten by JarJar currently                          

# So first rewrite source jar with same rule, though only first works.          

$JARJAR process $RULE_FILE $IN_SRC $OUT_SRC

# Fix it up                                                                     

CUR_DIR=$PWD
cd $TMP
jar xf $CUR_DIR/$OUT_SRC
for f in com/google/appengine/api/{users,datastore}/*.java ; do
  short=`echo $f | sed 's/.java//'`; mv $f "$short"V4.java
done
for f in com/google/appengine/api/{users,datastore}/*.java ; do
  sed -i 's/CustomFieldSerializer/CustomFieldSerializerV4/g' $f
done

# Repackage and move to target directory                                        

jar cf $CUR_DIR/$OUT_SRC com
cd $CUR_DIR
mv $OUT_SRC $THIRD_PARTY_OBJECTIFY_V4

echo "Success.  New files exist:"
echo "  $THIRD_PARTY_OBJECTIFY_V4$OUT_JAR"
echo "  $THIRD_PARTY_OBJECTIFY_V4$OUT_SRC"

Original issue reported on code.google.com by p...@google.com on 19 Dec 2012 at 1:49