[gradle-debian-helper] 01/03: Use the package name as the name of the root project when rootProject.name isn't defined in settings.gradle
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Wed Dec 14 12:58:02 UTC 2016
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to branch master
in repository gradle-debian-helper.
commit 460f65bad268cca34e7463dbd79542477a233f57
Author: Emmanuel Bourg <ebourg at apache.org>
Date: Wed Dec 14 13:47:25 2016 +0100
Use the package name as the name of the root project when rootProject.name isn't defined in settings.gradle
---
debian/changelog | 7 ++
.../java/org/debian/gradle/DebianHelperPlugin.java | 3 +
.../org/debian/gradle/ProjectNameInitializer.java | 81 ++++++++++++++++++++++
gradle-helper-plugin/src/main/perl/gradle.pm | 7 +-
4 files changed, 97 insertions(+), 1 deletion(-)
diff --git a/debian/changelog b/debian/changelog
index be20e7f..e27895a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+gradle-debian-helper (1.5) UNRELEASED; urgency=medium
+
+ * Use the package name as the name of the root project when rootProject.name
+ isn't defined in settings.gradle.
+
+ -- Emmanuel Bourg <ebourg at apache.org> Wed, 14 Dec 2016 11:33:44 +0100
+
gradle-debian-helper (1.4.4) unstable; urgency=medium
* Fixed the optional dependencies in the generated poms
diff --git a/gradle-helper-plugin/src/main/java/org/debian/gradle/DebianHelperPlugin.java b/gradle-helper-plugin/src/main/java/org/debian/gradle/DebianHelperPlugin.java
index 0392829..35f4596 100644
--- a/gradle-helper-plugin/src/main/java/org/debian/gradle/DebianHelperPlugin.java
+++ b/gradle-helper-plugin/src/main/java/org/debian/gradle/DebianHelperPlugin.java
@@ -76,5 +76,8 @@ public class DebianHelperPlugin implements Plugin<Gradle> {
// start a timer displaying a message periodically to prevent the builders from killing Gradle on slow architectures
gradle.addBuildListener(new KeepAliveTimer());
+
+ // initialize the project name if necessary
+ gradle.addBuildListener(new ProjectNameInitializer());
}
}
diff --git a/gradle-helper-plugin/src/main/java/org/debian/gradle/ProjectNameInitializer.java b/gradle-helper-plugin/src/main/java/org/debian/gradle/ProjectNameInitializer.java
new file mode 100644
index 0000000..6e2a4c0
--- /dev/null
+++ b/gradle-helper-plugin/src/main/java/org/debian/gradle/ProjectNameInitializer.java
@@ -0,0 +1,81 @@
+/**
+ * Copyright 2016 Emmanuel Bourg
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.debian.gradle;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Scanner;
+
+import org.gradle.BuildAdapter;
+import org.gradle.api.initialization.Settings;
+import org.gradle.api.invocation.Gradle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Build listener initializing the name of the root project if necessary.
+ *
+ * Gradle uses the rootProject.name property in the settings.gradle file,
+ * but if the property isn't defined the name of the directory is used instead.
+ * Thus the name of the artifacts created depends on the name of the base
+ * directory, and this can lead to build failures during the install phase
+ * because the files don't have the expected name.
+ *
+ * To work around this issue this build listener changes the project name
+ * on the fly and uses the name of the source package if the settings.gradle
+ * file is missing, or if it doesn't define the rootProject.name property.
+ */
+class ProjectNameInitializer extends BuildAdapter {
+
+ private final Logger log = LoggerFactory.getLogger(ProjectNameInitializer.class);
+
+ @Override
+ public void settingsEvaluated(Settings settings) {
+ if ("buildSrc".equals(settings.getRootProject().getName())) {
+ return;
+ }
+
+ File settingsFile = new File(settings.getSettingsDir(), "settings.gradle");
+ if (!settingsFile.exists()) {
+ log.info("\tSettings file not found (" + settingsFile + ")");
+ } else if (!contains(settingsFile, "rootProject.name")) {
+ log.info("\tSettings file found (" + settingsFile + "), but rootProject.name isn't defined");
+ } else {
+ return;
+ }
+
+ String name = System.getProperty("debian.package");
+ log.info("\tRoot project name not defined in settings.gradle, defaulting to '" + name + "' instead of the name of the root directory '" + settings.getRootProject().getName() + "'");
+ settings.getRootProject().setName(name);
+ }
+
+ private boolean contains(File file, String s) {
+ try (Scanner scanner = new Scanner(file, "ISO-8859-1")) {
+ while (scanner.hasNextLine()) {
+ String line = scanner.nextLine();
+ if (line != null && line.trim().startsWith(s)) {
+ return true;
+ }
+ }
+ } catch (IOException e) {
+ log.warn("Couldn't look for " + s + " in " + file, e);
+ }
+
+ return false;
+ }
+
+}
diff --git a/gradle-helper-plugin/src/main/perl/gradle.pm b/gradle-helper-plugin/src/main/perl/gradle.pm
index 0998ab5..1aaa742 100644
--- a/gradle-helper-plugin/src/main/perl/gradle.pm
+++ b/gradle-helper-plugin/src/main/perl/gradle.pm
@@ -6,6 +6,7 @@
package Debian::Debhelper::Buildsystem::gradle;
use strict;
+use Dpkg::Control;
use base 'Debian::Debhelper::Buildsystem';
sub DESCRIPTION {
@@ -20,7 +21,10 @@ sub check_auto_buildable {
sub new {
my $class=shift;
my $this=$class->SUPER::new(@_);
-
+
+ my $control = Dpkg::Control->new(type => CTRL_INFO_SRC);
+ $control->load("$this->{cwd}/debian/control");
+
@{$this->{gradle_cmd}} = ("gradle",
"--info",
"--console", "plain",
@@ -31,6 +35,7 @@ sub new {
"--gradle-user-home", ".gradle",
"-Duser.home=.",
"-Duser.name=debian",
+ "-Ddebian.package=$control->{Source}",
# "--init-script", "/usr/share/gradle-debian-helper/init.gradle",
);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/gradle-debian-helper.git
More information about the pkg-java-commits
mailing list