| 1 |
# A debhelper build system class for handling Gradle based projects. |
| 2 |
# |
| 3 |
# Copyright: 2015, Emmanuel Bourg |
| 4 |
# License: Apache-2.0 |
| 5 |
|
| 6 |
package Debian::Debhelper::Buildsystem::gradle; |
| 7 |
|
| 8 |
use strict; |
| 9 |
use Debian::Debhelper::Dh_Lib; |
| 10 |
use Dpkg::Control; |
| 11 |
use base 'Debian::Debhelper::Buildsystem'; |
| 12 |
|
| 13 |
sub DESCRIPTION { |
| 14 |
"Gradle (build.gradle)" |
| 15 |
} |
| 16 |
|
| 17 |
sub check_auto_buildable { |
| 18 |
my $this=shift; |
| 19 |
return (-e $this->get_sourcepath("build.gradle")) ? 1 : 0; |
| 20 |
} |
| 21 |
|
| 22 |
sub new { |
| 23 |
my $class=shift; |
| 24 |
my $this=$class->SUPER::new(@_); |
| 25 |
|
| 26 |
my $control = Dpkg::Control->new(type => CTRL_INFO_SRC); |
| 27 |
$control->load("$this->{cwd}/debian/control"); |
| 28 |
|
| 29 |
@{$this->{gradle_cmd}} = ("gradle", |
| 30 |
"--info", |
| 31 |
"--console", "plain", |
| 32 |
"--offline", |
| 33 |
"--stacktrace", |
| 34 |
"--no-daemon", |
| 35 |
"--refresh-dependencies", |
| 36 |
"--gradle-user-home", ".gradle", |
| 37 |
"-Duser.home=.", |
| 38 |
"-Duser.name=debian", |
| 39 |
"-Ddebian.package=$control->{Source}", |
| 40 |
"-Dfile.encoding=UTF-8", |
| 41 |
# "--init-script", "/usr/share/gradle-debian-helper/init.gradle", |
| 42 |
); |
| 43 |
|
| 44 |
my $numthreads = $this->get_parallel(); |
| 45 |
if ($numthreads == -1) { |
| 46 |
push(@{$this->{gradle_cmd}}, "--parallel"); |
| 47 |
} elsif ($numthreads > 1) { |
| 48 |
push(@{$this->{gradle_cmd}}, "--parallel", "--max-workers=$numthreads"); |
| 49 |
} |
| 50 |
|
| 51 |
return $this; |
| 52 |
} |
| 53 |
|
| 54 |
sub build { |
| 55 |
my $this=shift; |
| 56 |
|
| 57 |
if (!@_) { |
| 58 |
push(@_, "jar"); |
| 59 |
} |
| 60 |
|
| 61 |
$this->_execute_gradle_task(@_); |
| 62 |
} |
| 63 |
|
| 64 |
sub test { |
| 65 |
my $this=shift; |
| 66 |
|
| 67 |
# Running tests automatically for debhelper compat levels > 12 only to prevent unexpected FTBFSes of old packages |
| 68 |
return if compat(12, 1); |
| 69 |
|
| 70 |
if (!@_) { |
| 71 |
push(@_, "test"); |
| 72 |
} |
| 73 |
|
| 74 |
$this->_execute_gradle_task(@_); |
| 75 |
} |
| 76 |
|
| 77 |
sub clean { |
| 78 |
my $this=shift; |
| 79 |
|
| 80 |
$this->doit_in_builddir("sh", "-c", "find . -wholename .*build/tmp | xargs echo | sed -e 's^build/tmp^build^g' | xargs rm -Rf"); |
| 81 |
$this->doit_in_builddir("sh", "-c", "find . -wholename .*build/debian | xargs echo | sed -e 's^build/tmp^build^g' | xargs rm -Rf"); |
| 82 |
$this->doit_in_builddir("rm", "-Rf", "$this->{cwd}/.gradle", "$this->{cwd}/buildSrc/.gradle", ".m2"); |
| 83 |
} |
| 84 |
|
| 85 |
# Private methods |
| 86 |
|
| 87 |
sub _execute_gradle_task { |
| 88 |
my $this=shift; |
| 89 |
|
| 90 |
# Copy the init script under .gradle/init.d to work around a bug with the --init-script parameter (GRADLE-3197) |
| 91 |
$this->doit_in_builddir("mkdir", "-p", ".gradle/init.d"); |
| 92 |
$this->doit_in_builddir("cp", "/usr/share/gradle-debian-helper/init.gradle", ".gradle/init.d/"); |
| 93 |
|
| 94 |
# Add the hook to the classpath |
| 95 |
my $hookClasspath = "/usr/share/java/gradle-helper-hook.jar:/usr/share/java/maven-repo-helper.jar"; |
| 96 |
$ENV{JAVA_OPTS} .= " -Xbootclasspath/a:$hookClasspath"; |
| 97 |
$ENV{JAVA_OPTS} .= " -Dorg.gradle.jvmargs='-Xbootclasspath/a:$hookClasspath'"; |
| 98 |
|
| 99 |
$this->doit_in_builddir(@{$this->{gradle_cmd}}, @_); |
| 100 |
} |
| 101 |
|
| 102 |
1 |