File: maven.pm

package info (click to toggle)
maven-debian-helper 2.6.7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,360 kB
  • sloc: java: 3,846; xml: 1,724; sh: 518; perl: 123; makefile: 29
file content (157 lines) | stat: -rw-r--r-- 4,704 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# A debhelper build system class for handling Maven-based projects.
#
# Copyright: 2011 Canonical Ltd.
# License: GPL-3

package Debian::Debhelper::Buildsystem::maven;

use strict;
use base 'Debian::Debhelper::Buildsystem';
use Debian::Debhelper::Dh_Lib qw(%dh doit get_buildoption);

sub DESCRIPTION {
	"Maven (pom.xml)"
}

sub check_auto_buildable {
	my $this=shift;
	return (-e $this->get_sourcepath("pom.xml")) ? 1 : 0;
}

sub new {
	my $class=shift;
	my $this=$class->SUPER::new(@_);
	my $java_home = (exists $ENV{JAVA_HOME}) ? $ENV{JAVA_HOME} : '/usr/lib/jvm/default-java';

	my @packages = @{$dh{DOPACKAGES}};
	$this->{package} = shift @packages;
	$this->{doc_package} = (grep /-doc$/, @packages)[0] unless get_buildoption("nodoc");
	my $classconf = '/etc/maven/m2-debian.conf';

	my @classpath = ('/usr/share/maven/boot/plexus-classworlds-2.x.jar');
	if (-e "$java_home/lib/tools.jar") {
		push(@classpath, "$java_home/lib/tools.jar");
	}

	my @jvmopts = ('-noverify', '-cp', join(':',@classpath),
		"-Dmaven.home=/usr/share/maven",
		"-Dmaven.multiModuleProjectDirectory=$this->{cwd}",
		"-Dclassworlds.conf=$classconf");
	if (-e "$this->{cwd}/debian/maven.properties") {
		push (@jvmopts, "-Dproperties.file.manual=$this->{cwd}/debian/maven.properties");
	}
	if (exists $ENV{MAVEN_OPTS}) {
		push (@jvmopts, split(/ /, $ENV{MAVEN_OPTS}));
	}

	@{$this->{maven_cmd}} = ($java_home . '/bin/java',
		@jvmopts,
		"org.codehaus.plexus.classworlds.launcher.Launcher",
		"-s/etc/maven/settings-debian.xml",
		"-Ddebian.dir=$this->{cwd}/debian",
		"-Dmaven.repo.local=$this->{cwd}/debian/maven-repo");
	if (!(`tput colors 2>/dev/null` >= 8)) {
		push (@{$this->{maven_cmd}}, "--batch-mode");
	}
	return $this;
}

sub configure {
	my $this=shift;
	my @patch_args;

	doit("/usr/share/maven-debian-helper/copy-repo.sh", "$this->{cwd}/debian");
	$this->doit_in_sourcedir("mh_patchpoms", "-p$this->{package}",
		"--debian-build", "--keep-pom-version",
		"--maven-repo=$this->{cwd}/debian/maven-repo", @patch_args);
	doit("touch", "debian/stamp-poms-patched");
}

sub build {
 	my $this=shift;

	if (!@_) {
		push(@_, "package");
		if ($this->{doc_package}) {
			push(@_, "javadoc:jar", "javadoc:aggregate");
		}
	}

	push(@_, "-DskipTests", "-Dnotimestamp=true", "-Dlocale=en_US");

	$this->doit_in_builddir(@{$this->{maven_cmd}}, @_);
}

sub test {
	my $this=shift;

	if (!@_) {
		push(@_, "test");
	}

	$this->doit_in_builddir(@{$this->{maven_cmd}}, @_);
}

sub install {
	my $this=shift;
	my @resolvedep_args;
	my @install_args = @_;
	shift @install_args;

	opendir(my $dirhandle, "/usr/share/maven-repo/org/debian/maven/maven-packager-utils/")
		|| die "maven debian helper not found";
	my $maven_debian_version = (grep { !/^\./ } readdir($dirhandle))[0];
	closedir $dirhandle;

	if ($this->{doc_package}) {
		push(@resolvedep_args, "--javadoc");
	}
	push(@resolvedep_args, "--base-directory=$this->{cwd}", "--non-explore");

	$this->doit_in_builddir(@{$this->{maven_cmd}}, @install_args,
		"-Ddebian.dir=$this->{cwd}/debian",
		"-Ddebian.package=$this->{package}",
		"-Dmaven.repo.local=$this->{cwd}/debian/maven-repo",
		"-Dinstall.to.usj=true",
		"org.debian.maven:debian-maven-plugin:$maven_debian_version:install");
	$this->doit_in_builddir("mh_resolve_dependencies", "--non-interactive",
		"--offline", "--build", "-p$this->{package}", @resolvedep_args);
	if ($this->{doc_package}) {
		doit("cp","debian/$this->{package}.substvars",
			"debian/$this->{doc_package}.substvars");
		# clean up generated docs
		$this->doit_in_builddir("bash", "-c", "rm -f target/apidocs/*.sh target/apidocs/options");
	}
	$this->doit_in_sourcedir("mh_unpatchpoms", "-p$this->{package}");
	doit("rm", "-f", "debian/stamp-poms-patched");
}

sub clean {
	my $this=shift;
	my @patch_args;

	# If this directory if absent, we must not have anything to clean;
	# don't populate the directory just to run a clean target.
	if (-e "$this->{cwd}/debian/maven-repo")
	{
	        if (!@_) {
        	        push(@_, "clean");
        	}

	if (! -e "debian/stamp-poms-patched") {
		$this->doit_in_sourcedir("mh_patchpoms", "-p$this->{package}",
			"--debian-build", "--keep-pom-version",
			"--maven-repo=$this->{cwd}/debian/maven-repo", @patch_args);
			doit("touch", "debian/stamp-poms-patched");
	}

		$this->doit_in_builddir_noerror(@{$this->{maven_cmd}}, @_);
		doit("rm", "-r", "$this->{cwd}/debian/maven-repo");
	}
	$this->doit_in_builddir("bash", "-c", 'for dir in $(find . -name target -type d); do if [ -f $(echo $dir | sed -e s/target$/pom.xml/) ]; then rm -Rf $dir; fi done');
	$this->doit_in_sourcedir("mh_unpatchpoms", "-p$this->{package}");
	doit("rm", "-f", "debian/stamp-poms-patched");
	doit("mh_clean");
}

1