| 1 | #!/bin/bash -e |
| 2 | |
| 3 | MH_VERSION=$(ls /usr/share/maven-repo/org/debian/maven/maven-packager-utils/ | sed 's|/||') |
| 4 | . /usr/share/maven-repo-helper/mh_lib.sh |
| 5 | |
| 6 | syntax() |
| 7 | { |
| 8 | echo -e "Usage: mh_make [option]..." |
| 9 | echo -e "Generate the Debian packaging by reading the information" |
| 10 | echo -e "from the Maven POM." |
| 11 | echo -e "" |
| 12 | echo -e "Options:" |
| 13 | echo -e "\t-h --help: show this text" |
| 14 | echo -e "\t-V --version: show the version" |
| 15 | echo -e "\t-s<svn url> --from-svn=<svn url>: download the source code from" |
| 16 | echo -e "\t the SVN repository before building the Debian packaging. Use a tagged" |
| 17 | echo -e "\t branch of the source code, for example" |
| 18 | echo -e "\t http://svn.apache.org/repos/asf/felix/releases/org.osgi.core-1.2.0/" |
| 19 | echo -e "\t-p<package> --package=<package>: name of the source package" |
| 20 | echo -e "\t-b<package> --bin-package=<package>: name of the binary package" |
| 21 | echo -e "\t-t<true|false> --run-tests=<true|false>: include or not the tests" |
| 22 | echo -e "\t-d<true|false> --javadoc=<true|false>: include or not the javadoc" |
| 23 | echo -e "\t during the build" |
| 24 | echo -e "\t-n --non-interactive: non interactive mode, don't ask questions" |
| 25 | echo -e "\t-v --verbose: show more information while running" |
| 26 | echo -e "" |
| 27 | echo -e "To have mh_make working properly, you need first to install on your system" |
| 28 | echo -e "as many dependencies for your project as possible. Those dependencies should" |
| 29 | echo -e "also contain the required Maven metadata (POM files and jars in the" |
| 30 | echo -e "/usr/share/maven-repo repository)" |
| 31 | echo -e "" |
| 32 | echo -e "Environment variables:" |
| 33 | echo -e "\tDEBFULLNAME - your full name, e.g. John Doe" |
| 34 | echo -e "\tDEBEMAIL - your packager email address" |
| 35 | echo -e "\tDEBLICENSE - the license for the files under the debian/ directory" |
| 36 | echo -e "\t must be one of GPL2, GPL3, LGPL2.1, Apache-2.0, BSD or any license" |
| 37 | echo -e "\t short name defined in http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/" |
| 38 | exit 1 |
| 39 | } |
| 40 | |
| 41 | ARGS="p package b bin-package t run-tests d javadoc v verbose n non-interactive s from-svn" parseargs "$@" |
| 42 | |
| 43 | if [ -z "$DEBFULLNAME" ]; then |
| 44 | echo "Please define the environment variable DEBFULLNAME, e.g." |
| 45 | echo "export DEBFULLNAME=\"John Doe\"" |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | if [ -z "$DEBEMAIL" ]; then |
| 50 | # Fall back on EMAIL when DEBEMAIL is not defined |
| 51 | DEBEMAIL=$EMAIL |
| 52 | fi |
| 53 | |
| 54 | if [ -z "$DEBEMAIL" ]; then |
| 55 | echo "Please define the environment variable DEBEMAIL, e.g." |
| 56 | echo "export DEBEMAIL=\"[email protected]\"" |
| 57 | exit 1 |
| 58 | fi |
| 59 | |
| 60 | if [ -z "$DEBLICENSE" ]; then |
| 61 | echo "Environment variable DEBLICENSE not set, using Apache-2.0 by default" |
| 62 | DEBLICENSE="Apache-2.0" |
| 63 | fi |
| 64 | |
| 65 | PACKAGE=$(getarg p package) |
| 66 | BIN_PACKAGE=$(getarg b bin-package) |
| 67 | RUN_TESTS=$(getarg t run-tests) |
| 68 | GEN_JAVADOC=$(getarg d javadoc) |
| 69 | FROM_SVN=$(getarg s from-svn) |
| 70 | VERBOSE=$(getarg v verbose) |
| 71 | NON_INTERACTIVE=$(getarg n non-interactive) |
| 72 | |
| 73 | if [ "$FROM_SVN" == "true" ]; then |
| 74 | echo "The syntax for the --from-svn option is --from-svn=<url>, please try again" |
| 75 | exit 1 |
| 76 | fi |
| 77 | |
| 78 | if [ -z "$PACKAGE" ]; then |
| 79 | PACKAGE="$(basename $(pwd) | sed 's/-[0-9\.].*//')" |
| 80 | if [ -n "$FROM_SVN" ]; then |
| 81 | PACKAGE=$(echo "$FROM_SVN" | sed 's/-[0-9].*//') |
| 82 | PACKAGE=$(echo "$PACKAGE" | sed 's|.*/||' ) |
| 83 | fi |
| 84 | if [ "$NON_INTERACTIVE" != true ]; then |
| 85 | echo |
| 86 | echo "Enter the name of the new Debian source package:" |
| 87 | read -p "[$PACKAGE] > " USER_PACKAGE |
| 88 | if [ -n "$USER_PACKAGE" ]; then |
| 89 | PACKAGE=$USER_PACKAGE |
| 90 | fi |
| 91 | else |
| 92 | echo "Using source package name $PACKAGE, override with option --package=<package>." |
| 93 | fi |
| 94 | fi |
| 95 | |
| 96 | if [ -z "$BIN_PACKAGE" ]; then |
| 97 | PKG=$PACKAGE |
| 98 | if [ -z "${PKG##lib*-java}" ]; then |
| 99 | BIN_PACKAGE="${PACKAGE}" |
| 100 | else |
| 101 | BIN_PACKAGE="lib${PACKAGE}-java" |
| 102 | fi |
| 103 | if [ "$NON_INTERACTIVE" != true ]; then |
| 104 | echo |
| 105 | echo "Enter the name of the binary package:" |
| 106 | read -p "[$BIN_PACKAGE] > " USER_PACKAGE |
| 107 | if [ -n "$USER_PACKAGE" ]; then |
| 108 | BIN_PACKAGE=$USER_PACKAGE |
| 109 | fi |
| 110 | else |
| 111 | echo "Using binary package name $PACKAGE, override with option --bin-package=<package>." |
| 112 | fi |
| 113 | fi |
| 114 | |
| 115 | if [ -z "$RUN_TESTS" ]; then |
| 116 | RUN_TESTS="true" |
| 117 | if [ "$NON_INTERACTIVE" != true ]; then |
| 118 | echo |
| 119 | echo "Run tests while building the package?" |
| 120 | read -p "[Y/n] > " RUN |
| 121 | if [ "$RUN" == "n" ]; then |
| 122 | RUN_TESTS= |
| 123 | fi |
| 124 | else |
| 125 | echo "Tests will be run whilst building the package, override with option --run-tests=false." |
| 126 | fi |
| 127 | elif [ "$RUN_TESTS"="false" ]; then |
| 128 | RUN_TESTS= |
| 129 | fi |
| 130 | |
| 131 | |
| 132 | if [ -z "$GEN_JAVADOC" ]; then |
| 133 | GEN_JAVADOC="false" |
| 134 | if [ "$NON_INTERACTIVE" != true ]; then |
| 135 | echo |
| 136 | echo "Generate the Javadoc while building the package?" |
| 137 | read -p "[y/N] > " GEN |
| 138 | if [ "$GEN" == "y" ]; then |
| 139 | GEN_JAVADOC="true" |
| 140 | fi |
| 141 | else |
| 142 | echo "Javadoc will not be generated whilst building the package, override with option --javadoc=true." |
| 143 | fi |
| 144 | elif [ "$GEN_JAVADOC"="false" ]; then |
| 145 | GEN_JAVADOC= |
| 146 | fi |
| 147 | |
| 148 | echo |
| 149 | echo "Checking that apt-file is installed and has been configured..." |
| 150 | if [ ! -x /usr/bin/apt-file ]; then |
| 151 | echo "Error: apt-file is not available." >&2 |
| 152 | echo "Please install the 'apt-file' package and try again." >&2 |
| 153 | exit 1 |
| 154 | else |
| 155 | res="ok" |
| 156 | apt-file search /usr/share/maven/bin/mvnDebug | grep maven > /dev/null || res="failed" |
| 157 | if [ $? != 0 ] || [ "$res" == "failed" ]; then |
| 158 | echo "Warning: apt-file doesn't seem to be configured" |
| 159 | apt-file update |
| 160 | else |
| 161 | echo '[ok]' |
| 162 | fi |
| 163 | fi |
| 164 | |
| 165 | echo |
| 166 | echo "Checking that licensecheck is installed..." |
| 167 | if [ ! -x /usr/bin/licensecheck ]; then |
| 168 | echo "Error: licensecheck is not available." >&2 |
| 169 | echo "Please install the 'licensecheck' package and try again." >&2 |
| 170 | exit 1 |
| 171 | else |
| 172 | echo '[ok]' |
| 173 | fi |
| 174 | |
| 175 | if [ -n "$FROM_SVN" ]; then |
| 176 | echo |
| 177 | echo "Downloading the upstream sources..." |
| 178 | SVN_OPTIONS= |
| 179 | if [[ "$FROM_SVN" =~ https://.*\.dev\.java\.net/.* ]]; then |
| 180 | echo "Press enter if a password is asked" |
| 181 | SVN_OPTIONS="--username guest" |
| 182 | fi |
| 183 | svn export $FROM_SVN $PACKAGE $SVN_OPTIONS |
| 184 | cd $PACKAGE |
| 185 | fi |
| 186 | |
| 187 | if [ -e pom.xml.save ]; then |
| 188 | mh_unpatchpoms -p$BIN_PACKAGE |
| 189 | fi |
| 190 | |
| 191 | # Restore state after a brutal stop |
| 192 | if [ -f debian/$BIN_PACKAGE.poms ]; then |
| 193 | mh_unpatchpoms -p$BIN_PACKAGE || true |
| 194 | fi |
| 195 | if [ -f debian/patches/series ]; then |
| 196 | quilt pop -a || true |
| 197 | fi |
| 198 | |
| 199 | # Apply existing quilt patchs as source 3(quilt) is used in the package |
| 200 | if [ -f debian/patches/series ]; then |
| 201 | quilt push -a |
| 202 | fi |
| 203 | |
| 204 | echo |
| 205 | java -cp /usr/share/java/maven-project.jar:/usr/share/java/maven-repo-helper.jar:/usr/share/java/maven-packager-utils.jar:/usr/share/maven2/lib/maven-debian-uber.jar org.debian.maven.packager.DependenciesSolver --package="$BIN_PACKAGE" ${GEN_JAVADOC:+--generate-javadoc} ${RUN_TESTS:+--run-tests} ${VERBOSE:+--verbose} ${NON_INTERACTIVE:+--non-interactive} --maven-repo=/usr/share/maven-repo |
| 206 | |
| 207 | if [ $? != 0 ]; then |
| 208 | if [ -f debian/patches/series ]; then |
| 209 | quilt pop -a |
| 210 | fi |
| 211 | exit 1 |
| 212 | fi |
| 213 | |
| 214 | eval $(cat debian/$BIN_PACKAGE.substvars | sed -e 's/maven\./maven_/' | grep maven_UpstreamPackageVersion) |
| 215 | |
| 216 | mh_patchpoms ${VERBOSE:+--verbose} -p$BIN_PACKAGE -rdebian/maven.rules -idebian/maven.ignoreRules --keep-pom-version |
| 217 | |
| 218 | mvn org.debian.maven:maven-packager-utils:$MH_VERSION:generate -Demail="$DEBEMAIL" -Dpackager="$DEBFULLNAME" -DpackagerLicense="$DEBLICENSE" -Dpackage="$PACKAGE" -Dbin.package="$BIN_PACKAGE" -DrunTests="$RUN_TESTS" -DgenerateJavadoc="$GEN_JAVADOC" -Dmaven.repo.local=/usr/share/maven-repo ${FROM_SVN:+-DdownloadUrl=scm:svn:$FROM_SVN} --offline |
| 219 | |
| 220 | if [ $? != 0 ]; then |
| 221 | if [ -f debian/$BIN_PACKAGE.poms ]; then |
| 222 | mh_unpatchpoms -p$BIN_PACKAGE |
| 223 | fi |
| 224 | if [ -f debian/patches/series ]; then |
| 225 | quilt pop -a |
| 226 | fi |
| 227 | exit 1 |
| 228 | fi |
| 229 | |
| 230 | if [ ! -f debian/changelog ]; then |
| 231 | debianVersion=$(echo ${maven_UpstreamPackageVersion} | sed -re's/-(alpha|beta|rc)-?/~\1/') |
| 232 | dch --create --newversion=${debianVersion}-1 --package=$PACKAGE "Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP>" |
| 233 | fi |
| 234 | |
| 235 | if [ -f debian/$BIN_PACKAGE.poms ]; then |
| 236 | mh_unpatchpoms -p$BIN_PACKAGE |
| 237 | fi |
| 238 | if [ -f debian/patches/series ]; then |
| 239 | quilt pop -a |
| 240 | fi |
| 241 | |
| 242 | rm -f debian/*.substvars |
| 243 | rm -f .debianVersion |
| 244 | rm -f velocity.log |