1 #!/bin/bash 2 3 function requireLocalRepoUpToDate() { 4 local LOCAL_CHANGES="$(svn status -u | egrep -v '^Status against revision:')" 5 # -u causes status differences from head to be reported. 6 if [[ -n "$LOCAL_CHANGES" ]]; then 7 echo "Repo is not up-to-date or not committed." 8 echo ======================================== 9 echo "$LOCAL_CHANGES" 10 echo ======================================== 11 12 echo "Aborting." 13 echo 14 exit -1 15 fi 16 } 17 18 requireLocalRepoUpToDate 19 20 PROJECT_DIR="$(pushd "$(dirname "$0")/../.." >& /dev/null; pwd -P; popd >& /dev/null)" 21 22 VERSION="$1" 23 24 PASSPHRASE="$2" 25 26 KEYNAME=41449802 27 28 function usageAndExit() { 29 echo "Usage: $0 <version> <passphrase>" 30 echo 31 echo "Stages a release for deployment into Maven central" 32 echo 33 echo "<version> is the current SVN revision number." 34 echo "svn info gives more info about the state of trunk." 35 echo 36 echo "<passphrase> is the passphrase for the GPG key $KEYNAME." 37 echo "gpg --list-keys for more details on the key." 38 echo 39 echo "For example: $0 r123 ELIDED" 40 exit -1 41 } 42 43 if ! [ -d "$PROJECT_DIR/maven" ]; then 44 echo "Cannot determine script directory. $PROJECT_DIR" 45 usageAndExit 46 fi 47 48 if ! [[ "$VERSION" =~ r[0-9]+ ]]; then 49 echo "Bad version $VERSION" 50 echo 51 usageAndExit 52 fi 53 54 if [ -z "$PASSPHRASE" ]; then 55 echo "Missing passphrase" 56 echo 57 usageAndExit 58 fi 59 60 POMFILE="$PROJECT_DIR/maven/owasp-java-html-sanitizer/owasp-java-html-sanitizer/$VERSION/owasp-java-html-sanitizer-$VERSION.pom" 61 62 JAR_NO_EXT="$PROJECT_DIR/maven/owasp-java-html-sanitizer/owasp-java-html-sanitizer/$VERSION/owasp-java-html-sanitizer-$VERSION" 63 64 function requireFile() { 65 local FILE="$1" 66 if ! [ -e "$FILE" ]; then 67 echo "Missing file : $FILE" 68 echo 69 usageAndExit 70 fi 71 } 72 73 requireFile "$POMFILE" 74 requireFile "$JAR_NO_EXT".jar 75 requireFile "$JAR_NO_EXT"-sources.jar 76 requireFile "$JAR_NO_EXT"-javadoc.jar 77 78 mvn -X -e \ 79 gpg:sign-and-deploy-file \ 80 -Dgpg.keyname="$KEYNAME" \ 81 -Dgpg.passphrase="$PASSPHRASE" \ 82 -DgeneratePom=false \ 83 -DpomFile="$POMFILE" \ 84 -Dfile="$JAR_NO_EXT".jar \ 85 -Dfiles="$JAR_NO_EXT"-sources.jar,"$JAR_NO_EXT"-javadoc.jar \ 86 -Dtypes=jar,jar \ 87 -Dclassifiers=sources,javadoc \ 88 -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ \ 89 -DrepositoryId=sonatype-nexus-staging \ 90 && \ 91 echo "Follow instructions at https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-8a.ReleaseIt" 92