Last active
August 29, 2015 14:16
-
-
Save patrickhammond/f6759aee7114bfdfb5e8 to your computer and use it in GitHub Desktop.
Migrates a project from one package to another.
This file contains hidden or 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/sh | |
rm -rf app | |
mkdir -p app/src/main/java/com/mycompany/myapp | |
echo "import com.mycompany.myapp.R;" > app/src/main/java/com/mycompany/myapp/Test.java | |
echo "com.mycompany.myapp.SomeActivity" > app/AndroidManifest.xml |
This file contains hidden or 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/sh | |
# Usage renamePackage.sh [package] | |
# Ex: renamePackage.sh com.atomicrobot.app | |
export new_package="$1" | |
export original_package="com.mycompany.myapp" | |
export new_package_directory="/"`echo $new_package | tr '.' '/'`"/" | |
export original_package_directory="/"`echo $original_package | tr '.' '/'`"/" | |
# These params have a different offset because of xargs | |
parent_mv(){ | |
source="$0"; | |
target="$1"; | |
targetDir="$(dirname $target)" | |
mkdir -p "$targetDir" | |
mv "$source" "$targetDir" | |
} | |
export -f parent_mv | |
update_filetypes() { | |
# Would be nice to externalize the regex | |
find . -name "$1" \ | |
| gawk -v replacement="\\\\1$new_package_directory\\\\2" '{ updated = gensub(/(.+)\/com\/mycompany\/myapp\/(.+)/, replacement, $0); print $0, updated; }' \ | |
| xargs -n 2 bash -c 'parent_mv "$@"' | |
find . -name "$1" \ | |
| xargs sed -i '' s/$original_package/$new_package/g | |
} | |
echo | |
echo "----------" | |
echo "(Dev) Showing what things look like before:" | |
find . | |
echo | |
update_filetypes "*.java" | |
update_filetypes "*.xml" | |
update_filetypes "*.gradle" | |
find . -depth -empty -delete | |
echo "(Dev) Showing what things look like after:" | |
find . | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment