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 378d4646bdc2ffee709b4a2c9ae3d78eef49ed08 Author: Emmanuel Bourg <[email protected]> Date: Wed Oct 14 19:17:01 2015 +0200 Initial commit --- .gitignore | 4 + LICENSE.txt | 202 +++++++++++++++++++++ README.txt | 38 ++++ TODO.txt | 5 + debian/changelog | 5 + debian/control | 24 +++ debian/copyright | 9 + debian/install | 2 + debian/rules | 6 + gradle-dependency-placeholder/pom.xml | 12 ++ gradle-helper-plugin/pom.xml | 141 ++++++++++++++ gradle-helper-plugin/src/main/gradle/init.gradle | 12 ++ .../java/org/debian/gradle/DebianHelperPlugin.java | 49 +++++ .../debian/gradle/DebianTemporaryFileProvider.java | 40 ++++ .../java/org/debian/gradle/KeepAliveTimer.java | 49 +++++ .../gradle/MavenDebianArtifactRepository.java | 179 ++++++++++++++++++ gradle-helper-plugin/src/main/perl/gradle.pm | 54 ++++++ pom.xml | 17 ++ test-project/build.gradle | 25 +++ test-project/debian/maven.ignoreRules | 2 + test-project/debian/maven.rules | 3 + test-project/init.gradle | 9 + test-project/settings.gradle | 5 + test-project/src/main/java/HelloWorld.java | 7 + .../project1/src/main/java/Project1.java | 3 + .../project2/src/main/java/Project2.java | 3 + test-project/test.bat | 1 + test-project/test.sh | 8 + 28 files changed, 914 insertions(+) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ebfed6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.iml +target +.gradle +build diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..75b5248 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..12671d5 --- /dev/null +++ b/README.txt @@ -0,0 +1,38 @@ +Gradle Debian Helper +-------------------- + +This project contains helper tools to ease the packaging of Gradle based projects in Debian. +It consists in: + * a Gradle plugin resolving the dependencies against the system Maven repository (/usr/share/maven-repo). + The resolver uses the same Maven rule files that maven-debian-helper and maven-repo-helper employ + (debian/maven.rules, debian/maven.ignoreRules). + * a build listener displaying a message periodically to prevent the builders from killing Gradle on slow architectures. + * a debhelper class detecting Gradle build files, initializing the plugin and running Gradle in offline mode. + + +Usage +----- + +1. Add a build dependency on gradle-debian-helper in debian/control + +2. Use a debian/rules file with: + + %: + dh $@ --buildsystem=gradle + +3. Create debian/maven.rules and/or debian.maven.ignoreRules with the dependency rules + +4. For building only some subprojects and ignoring the other, + pass Gradle parameters to dh_auto_build: + + override_dh_auto_build: + dh_auto_build -- :project1:jar :project2:jar + + +Limitations +----------- + +* Dependencies with a version range are not handled (e.g. org.foo:bar:1.0+) +* Transitive dependencies with a non generic version (neither 'debian' nor '.x') + must be added to debian/maven.rules in order to preserve the version + (with a rule like: org.foo bar * * * *) diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000..d8aa6a1 --- /dev/null +++ b/TODO.txt @@ -0,0 +1,5 @@ +TODO +---- + +- Handle version ranges +- Ignore the transitive dependencies diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..307ec45 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +gradle-debian-helper (1.0) unstable; urgency=medium + + * Initial release. (Closes: #801683) + + -- Emmanuel Bourg <[email protected]> Tue, 13 Oct 2015 18:41:09 +0200 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..8b2247a --- /dev/null +++ b/debian/control @@ -0,0 +1,24 @@ +Source: gradle-debian-helper +Section: java +Priority: optional +Maintainer: Debian Java Maintainers <[email protected]> +Uploaders: Emmanuel Bourg <[email protected]> +Build-Depends: debhelper (>= 9), cdbs, default-jdk, maven-debian-helper, gradle +Standards-Version: 3.9.6 +Vcs-Git: git://anonscm.debian.org/pkg-java/gradle-debian-helper.git +Vcs-Browser: http://anonscm.debian.org/cgit/pkg-java/gradle-debian-helper.git + +Package: gradle-debian-helper +Architecture: all +Depends: ${misc:Depends}, default-jre-headless | java7-runtime-headless, maven-repo-helper, gradle +Recommends: debhelper +Description: Helper tools for building Debian packages with Gradle + gradle-debian-helper contains helper tools to ease the packaging of Gradle + based projects in Debian. It consists in: + . + * a Gradle plugin resolving the dependencies against the system Maven + repository (/usr/share/maven-repo). The resolver uses the same Maven + rule files that maven-debian-helper and maven-repo-helper employ + (debian/maven.rules, debian/maven.ignoreRules). + * a debhelper class detecting Gradle build files, initializing the plugin + and running Gradle in offline mode. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..c0395df --- /dev/null +++ b/debian/copyright @@ -0,0 +1,9 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: Gradle Debian Helper +Source: https://launchpad.net/maven-packaging-support/ + +Files: * +Copyright: 2015, Emmanuel Bourg <[email protected]> +License: Apache-2.0 + On Debian systems, the full text of the Apache-2.0 license + can be found in the file '/usr/share/common-licenses/Apache-2.0' diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..23ba726 --- /dev/null +++ b/debian/install @@ -0,0 +1,2 @@ +gradle-debian-resolver-plugin/src/main/gradle/* /usr/share/gradle-debian-helper +gradle-debian-resolver-plugin/src/main/perl/*.pm /usr/share/perl5/Debian/Debhelper/Buildsystem/ diff --git a/debian/rules b/debian/rules new file mode 100644 index 0000000..c75efdf --- /dev/null +++ b/debian/rules @@ -0,0 +1,6 @@ +#!/usr/bin/make -f + +include /usr/share/cdbs/1/rules/debhelper.mk +include /usr/share/cdbs/1/class/maven.mk + +JAVA_HOME := /usr/lib/jvm/default-java diff --git a/gradle-dependency-placeholder/pom.xml b/gradle-dependency-placeholder/pom.xml new file mode 100644 index 0000000..9f45172 --- /dev/null +++ b/gradle-dependency-placeholder/pom.xml @@ -0,0 +1,12 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.debian.gradle</groupId> + <artifactId>gradle-dependency-placeholder</artifactId> + <version>1.0</version> + <packaging>jar</packaging> + <name>Placeholder Dependency</name> + <description>Empty JAR used as a placeholder when resolving ignored dependencies</description> + +</project> diff --git a/gradle-helper-plugin/pom.xml b/gradle-helper-plugin/pom.xml new file mode 100644 index 0000000..270ee6d --- /dev/null +++ b/gradle-helper-plugin/pom.xml @@ -0,0 +1,141 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.debian.gradle</groupId> + <artifactId>gradle-helper-plugin</artifactId> + <version>1.0</version> + <packaging>jar</packaging> + <name>Gradle Debian Helper Plugin</name> + <description>Gradle Plugin for resolving project dependencies with the system Maven repository</description> + + <properties> + <gradle.version>2.7</gradle.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.debian.maven</groupId> + <artifactId>maven-repo-helper</artifactId> + <version>1.8.10</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.7.7</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.codehaus.groovy</groupId> + <artifactId>groovy-all</artifactId> + <version>2.4.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.gradle</groupId> + <artifactId>gradle-base-services</artifactId> + <version>${gradle.version}</version> + <scope>system</scope> + <systemPath>${gradle.home}/lib/gradle-base-services-${gradle.version}.jar</systemPath> + </dependency> + <dependency> + <groupId>org.gradle</groupId> + <artifactId>gradle-base-services-groovy</artifactId> + <version>${gradle.version}</version> + <scope>system</scope> + <systemPath>${gradle.home}/lib/gradle-base-services-groovy-${gradle.version}.jar</systemPath> + </dependency> + <dependency> + <groupId>org.gradle</groupId> + <artifactId>gradle-core</artifactId> + <version>${gradle.version}</version> + <scope>system</scope> + <systemPath>${gradle.home}/lib/gradle-core-${gradle.version}.jar</systemPath> + </dependency> + <dependency> + <groupId>org.gradle</groupId> + <artifactId>gradle-tooling-api</artifactId> + <version>${gradle.version}</version> + <scope>system</scope> + <systemPath>${gradle.home}/lib/gradle-tooling-api-${gradle.version}.jar</systemPath> + </dependency> + <dependency> + <groupId>org.gradle</groupId> + <artifactId>gradle-dependency-management</artifactId> + <version>${gradle.version}</version> + <scope>system</scope> + <systemPath>${gradle.home}/lib/plugins/gradle-dependency-management-${gradle.version}.jar</systemPath> + </dependency> + <dependency> + <groupId>org.gradle</groupId> + <artifactId>gradle-resources</artifactId> + <version>${gradle.version}</version> + <scope>system</scope> + <systemPath>${gradle.home}/lib/gradle-resources-${gradle.version}.jar</systemPath> + </dependency> + <dependency> + <groupId>org.apache.ivy</groupId> + <artifactId>ivy</artifactId> + <version>2.4.0</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <!-- + <repositories> + <repository> + <id>gradle</id> + <url>http://repo.gradle.org/gradle/libs-releases-local/</url> + <snapshots> + <enabled>false</enabled> + <checksumPolicy>fail</checksumPolicy> + </snapshots> + <releases> + <enabled>true</enabled> + <checksumPolicy>fail</checksumPolicy> + </releases> + </repository> + </repositories> + --> + + <build> + <pluginManagement> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.5</version> + <configuration> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> + + <profiles> + <profile> + <id>windows</id> + <activation> + <os> + <family>windows</family> + </os> + </activation> + <properties> + <gradle.home>C:/Program Files (x86)/gradle-${gradle.version}/</gradle.home> + </properties> + </profile> + <profile> + <id>unix</id> + <activation> + <os> + <family>unix</family> + </os> + </activation> + <properties> + <gradle.home>/usr/share/gradle</gradle.home> + </properties> + </profile> + </profiles> + +</project> diff --git a/gradle-helper-plugin/src/main/gradle/init.gradle b/gradle-helper-plugin/src/main/gradle/init.gradle new file mode 100644 index 0000000..303aab8 --- /dev/null +++ b/gradle-helper-plugin/src/main/gradle/init.gradle @@ -0,0 +1,12 @@ +/* + * Init script for the Gradle Helper Plugin + */ + +initscript { + dependencies { + classpath fileTree(dir: '/usr/share/java/', include: 'gradle-helper-plugin.jar') + classpath fileTree(dir: '/usr/share/java/', include: 'maven-repo-helper.jar') + } +} + +apply plugin: org.debian.gradle.DebianHelperPlugin 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 new file mode 100644 index 0000000..9531a0d --- /dev/null +++ b/gradle-helper-plugin/src/main/java/org/debian/gradle/DebianHelperPlugin.java @@ -0,0 +1,49 @@ +/** + * Copyright 2015 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 org.gradle.api.Action; +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.invocation.Gradle; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Gradle plugin installing the Debian repository before those defined in the build script. + */ +public class DebianHelperPlugin implements Plugin<Gradle> { + + private final Logger log = LoggerFactory.getLogger(DebianHelperPlugin.class); + + @Override + public void apply(Gradle gradle) { + // add the Debian repository to all projects + final MavenDebianArtifactRepository repository = new MavenDebianArtifactRepository(); + gradle.allprojects(new Action<Project>() { + @Override + public void execute(final Project project) { + log.info("\tAdding Debian repository to project '" + project.getName() + "'"); + project.getRepositories().addFirst(repository); + project.getBuildscript().getRepositories().addFirst(repository); + } + }); + + // start a timer displaying a message periodically to prevent the builders from killing Gradle on slow architectures + gradle.addBuildListener(new KeepAliveTimer()); + } +} diff --git a/gradle-helper-plugin/src/main/java/org/debian/gradle/DebianTemporaryFileProvider.java b/gradle-helper-plugin/src/main/java/org/debian/gradle/DebianTemporaryFileProvider.java new file mode 100644 index 0000000..a26b002 --- /dev/null +++ b/gradle-helper-plugin/src/main/java/org/debian/gradle/DebianTemporaryFileProvider.java @@ -0,0 +1,40 @@ +/** + * Copyright 2015 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 org.gradle.api.internal.file.DefaultTemporaryFileProvider; +import org.gradle.internal.Factory; + +/** + * Create temporary directories into the local .gradle directory using during the Debian build. + */ +class DebianTemporaryFileProvider extends DefaultTemporaryFileProvider { + + public DebianTemporaryFileProvider() { + super(new Factory<File>() { + @Override + public File create() { + File directory = new File(".gradle/tmp/"); + directory.mkdirs(); + return directory; + } + + }); + } +} diff --git a/gradle-helper-plugin/src/main/java/org/debian/gradle/KeepAliveTimer.java b/gradle-helper-plugin/src/main/java/org/debian/gradle/KeepAliveTimer.java new file mode 100644 index 0000000..fa79180 --- /dev/null +++ b/gradle-helper-plugin/src/main/java/org/debian/gradle/KeepAliveTimer.java @@ -0,0 +1,49 @@ +/** + * Copyright 2015 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.util.Timer; +import java.util.TimerTask; + +import org.gradle.BuildAdapter; +import org.gradle.api.invocation.Gradle; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Build listener displaying a message every 10 minutes. This prevents the auto builders + * from killing Gradle on slow architectures. + */ +class KeepAliveTimer extends BuildAdapter { + + private final Logger log = LoggerFactory.getLogger(KeepAliveTimer.class); + + private static final long PERIOD = 10 * 60 * 1000L; // 10 minutes + + @Override + public void projectsLoaded(Gradle gradle) { + Timer timer = new Timer("Gradle Keep-alive Timer", true); + timer.schedule(new TimerTask() { + @Override + public void run() { + log.info("\tGradle is still running, please be patient..."); + } + }, PERIOD, PERIOD); + + log.info("\tKeep-alive timer started"); + } +} diff --git a/gradle-helper-plugin/src/main/java/org/debian/gradle/MavenDebianArtifactRepository.java b/gradle-helper-plugin/src/main/java/org/debian/gradle/MavenDebianArtifactRepository.java new file mode 100644 index 0000000..f6b9cac --- /dev/null +++ b/gradle-helper-plugin/src/main/java/org/debian/gradle/MavenDebianArtifactRepository.java @@ -0,0 +1,179 @@ +/** + * Copyright 2015 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 org.debian.maven.cliargs.ArgumentsIterable; +import org.debian.maven.cliargs.ArgumentsMap; +import org.debian.maven.repo.Dependency; +import org.debian.maven.repo.DependencyRule; +import org.debian.maven.repo.DependencyRuleSetFiles; +import org.gradle.api.artifacts.component.ModuleComponentIdentifier; +import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ConfiguredModuleComponentRepository; +import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.GradlePomModuleDescriptorParser; +import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.MetaDataParser; +import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.DefaultVersionComparator; +import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.DefaultVersionSelectorScheme; +import org.gradle.api.internal.artifacts.repositories.AbstractArtifactRepository; +import org.gradle.api.internal.artifacts.repositories.ResolutionAwareRepository; +import org.gradle.api.internal.artifacts.repositories.resolver.MavenResolver; +import org.gradle.api.internal.filestore.ivy.ArtifactIdentifierFileStore; +import org.gradle.internal.component.external.model.DefaultMavenModuleResolveMetaData; +import org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier; +import org.gradle.internal.component.external.model.ModuleComponentArtifactMetaData; +import org.gradle.internal.component.model.ComponentOverrideMetadata; +import org.gradle.internal.component.model.DefaultComponentOverrideMetadata; +import org.gradle.internal.component.model.DefaultIvyArtifactName; +import org.gradle.internal.component.model.IvyArtifactName; +import org.gradle.internal.resolve.result.BuildableModuleComponentMetaDataResolveResult; +import org.gradle.internal.resource.local.LocallyAvailableResourceFinder; +import org.gradle.internal.resource.local.LocallyAvailableResourceFinderSearchableFileStoreAdapter; +import org.gradle.internal.resource.local.PathKeyFileStore; +import org.gradle.internal.resource.transport.file.FileTransport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Artifact repository resolving the dependencies against the system repository under /usr/share/maven-repo. + */ +public class MavenDebianArtifactRepository extends AbstractArtifactRepository implements ResolutionAwareRepository { + + private final Logger log = LoggerFactory.getLogger(MavenDebianArtifactRepository.class); + + private final LocallyAvailableResourceFinder<ModuleComponentArtifactMetaData> locallyAvailableResourceFinder; + private final ArtifactIdentifierFileStore artifactFileStore; + private final MetaDataParser<DefaultMavenModuleResolveMetaData> pomParser; + + /** The substitution rules for the Maven dependencies */ + private DependencyRuleSetFiles rulesets; + + /** The path to the local Maven repository */ + private File repositoryPath = new File("/usr/share/maven-repo"); + + /** The placeholder used for ignored dependencies */ + private static final ModuleComponentIdentifier IGNORED_DEPENDENCY_PLACEHOLDER = new DefaultModuleComponentIdentifier("org.debian.gradle", "gradle-dependency-placeholder", "1.0"); + + public MavenDebianArtifactRepository() { + this.pomParser = new GradlePomModuleDescriptorParser(new DefaultVersionSelectorScheme(new DefaultVersionComparator())); + this.artifactFileStore = new ArtifactIdentifierFileStore(new PathKeyFileStore(repositoryPath), new DebianTemporaryFileProvider()); + this.locallyAvailableResourceFinder = new LocallyAvailableResourceFinderSearchableFileStoreAdapter<>(artifactFileStore); + + log.info("\tLoading the Maven rules..."); + ArgumentsMap args = new ArgumentsMap(new ArgumentsIterable(new String[] { "--rules=debian/maven.rules", "--ignore-rules=debian/maven.ignoreRules"})); + rulesets = DependencyRuleSetFiles.fromCLIArguments(args, false); + rulesets.addDefaultRules(); + } + + @Override + public String getName() { + return "Debian Maven Repository"; + } + + public ConfiguredModuleComponentRepository createResolver() { + return new MavenResolver(getName(), repositoryPath.toURI(), new FileTransport("debian"), locallyAvailableResourceFinder, artifactFileStore, pomParser) { + + @Override + protected void doResolveComponentMetaData(ModuleComponentIdentifier identifier, ComponentOverrideMetadata metadata, BuildableModuleComponentMetaDataResolveResult result) { + Dependency dependency = toDependency(identifier, metadata); + Dependency resolved = resolve(dependency); + + if (resolved == null) { + log.info("\tIgnoring " + format(dependency)); + identifier = IGNORED_DEPENDENCY_PLACEHOLDER; + + } else if (dependency == resolved) { + log.info("\tPassing though " + format(dependency)); + } else { + log.info("\tReplacing " + format(dependency) + " -> " + format(resolved)); + identifier = new DefaultModuleComponentIdentifier(resolved.getGroupId(), resolved.getArtifactId(), resolved.getVersion()); + metadata = new DefaultComponentOverrideMetadata(); + metadata.getArtifacts().add(new DefaultIvyArtifactName(resolved.getArtifactId(), resolved.getType(), resolved.getType(), resolved.getClassifier())); + } + + super.doResolveComponentMetaData(identifier, metadata, result); + } + }; + } + + /** + * Apply the Maven rules to the specified dependency. + * + * @param dependency the resolved dependency, or null if the dependency is ignored. + */ + private Dependency resolve(Dependency dependency) { + // check if the dependency is ignored + for (DependencyRule rule : rulesets.get(DependencyRuleSetFiles.RulesType.IGNORE).getRules()) { + if (rule.matches(dependency)) { + return null; + } + } + + /** + * The transitive dependencies are also resolved but unfortunately there is no way to detect them as such. + * This means that a transitive dependency on asm:4.x for example would be transformed into asm:debian unless + * its rule is copied into debian/maven.rules in order to preserve the generic '4.x' version. To mitigate this + * issue the '.x' generic versions are detected and passed through. Artifacts with no generic version are still + * affected though, and their rules have to be added to debian/maven.rules. + */ + if (!dependency.getVersion().endsWith(".x")) { + // apply the first rule that matches + for (DependencyRule rule : rulesets.get(DependencyRuleSetFiles.RulesType.RULES).getRules()) { + if (rule.matches(dependency)) { + return rule.apply(dependency); + } + } + } + + return dependency; + } + + /** + * Converts a Gradle dependency into a dependency object as handled by maven-repo-helper. + */ + private Dependency toDependency(ModuleComponentIdentifier identifier, ComponentOverrideMetadata metadata) { + String classifier = null; + String type = "jar"; + if (!metadata.getArtifacts().isEmpty()) { + IvyArtifactName ivyArtifactName = metadata.getArtifacts().iterator().next(); + classifier = ivyArtifactName.getClassifier(); + type = ivyArtifactName.getType(); + } + + return new Dependency(identifier.getGroup(), identifier.getModule(), type, identifier.getVersion(), "compile", false, classifier, null); + } + + /** + * Format a dependency for display (slightly more compact than dependency.toString()) + */ + private String format(Dependency dependency) { + StringBuilder builder = new StringBuilder(); + builder.append(dependency.getGroupId()); + builder.append(":"); + builder.append(dependency.getArtifactId()); + builder.append(":"); + builder.append(dependency.getType()); + builder.append(":"); + builder.append(dependency.getVersion()); + if (dependency.getClassifier() != null && dependency.getClassifier().trim().length() > 0) { + builder.append(":"); + builder.append(dependency.getClassifier()); + } + + return builder.toString(); + } +} diff --git a/gradle-helper-plugin/src/main/perl/gradle.pm b/gradle-helper-plugin/src/main/perl/gradle.pm new file mode 100644 index 0000000..d3dc555 --- /dev/null +++ b/gradle-helper-plugin/src/main/perl/gradle.pm @@ -0,0 +1,54 @@ +# A debhelper build system class for handling Gradle based projects. +# +# Copyright: 2015, Emmanuel Bourg +# License: Apache-2.0 + +package Debian::Debhelper::Buildsystem::gradle; + +use strict; +use base 'Debian::Debhelper::Buildsystem'; +use Debian::Debhelper::Dh_Lib qw(%dh doit); + +sub DESCRIPTION { + "Gradle (build.gradle)" +} + +sub check_auto_buildable { + my $this=shift; + return (-e $this->get_sourcepath("build.gradle")) ? 1 : 0; +} + +sub new { + my $class=shift; + my $this=$class->SUPER::new(@_); + + @{$this->{gradle_cmd}} = ("gradle", + "--info", + "--console", "plain", + "--offline", + "--stacktrace", + "--no-daemon", + "--refresh-dependencies", + "--gradle-user-home", ".gradle", + "--init-script", "/usr/share/gradle-debian-helper/init.gradle"); + return $this; +} + +sub build { + my $this=shift; + + if (!@_) { + push(@_, "jar"); + } + + $this->doit_in_builddir(@{$this->{gradle_cmd}}, @_); +} + +sub clean { + my $this=shift; + + doit(@{$this->{gradle_cmd}}, "clean"); + doit("rm", "-Rf", "$this->{cwd}/.gradle"); +} + +1 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5520b94 --- /dev/null +++ b/pom.xml @@ -0,0 +1,17 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.debian.gradle</groupId> + <artifactId>gradle-debian-helper</artifactId> + <version>1.0</version> + <packaging>pom</packaging> + <name>Gradle Debian Helper</name> + <description>Helper tools for building Debian packages with Gradle</description> + + <modules> + <module>gradle-helper-plugin</module> + <module>gradle-dependency-placeholder</module> + </modules> + +</project> diff --git a/test-project/build.gradle b/test-project/build.gradle new file mode 100644 index 0000000..9291a96 --- /dev/null +++ b/test-project/build.gradle @@ -0,0 +1,25 @@ +allprojects { + apply plugin: 'java' +} + +dependencies { + compile group: 'commons-collections', name: 'commons-collections', version: 'debian' + compile group: 'commons-lang', name: 'commons-lang', version: '2.6' +} + +project(':project1') { + dependencies { + compile group: 'commons-io', name: 'commons-io', version: '2.6' + compile group: 'junit', name: 'junit', version: '4.11' + compile group: 'cglib', name: 'cglib', version: '3.1' + // todo compile "org.foo:bar:1.0+:native" + } +} + +project(':project2') { + dependencies { + compile group: 'commons-compress', name: 'commons-compress', version: '1.8' + compile group: 'org.hsqldb', name: 'hsqldb', version: '2.3.3', classifier: 'jdk5' + compile group: 'org.apache.ant', name: 'ant', version: '1.9.6' + } +} diff --git a/test-project/debian/maven.ignoreRules b/test-project/debian/maven.ignoreRules new file mode 100644 index 0000000..0f4cc27 --- /dev/null +++ b/test-project/debian/maven.ignoreRules @@ -0,0 +1,2 @@ +commons-compress commons-compress * * * * +commons-io commons-io * * * * diff --git a/test-project/debian/maven.rules b/test-project/debian/maven.rules new file mode 100644 index 0000000..d635987 --- /dev/null +++ b/test-project/debian/maven.rules @@ -0,0 +1,3 @@ +junit junit * s/.*/4.x/ * * +cglib cglib * s/.*/3.x/ * * +org.hsqldb hsqldb * s/.*/debian/ s/jdk5// * diff --git a/test-project/init.gradle b/test-project/init.gradle new file mode 100644 index 0000000..8767d36 --- /dev/null +++ b/test-project/init.gradle @@ -0,0 +1,9 @@ +initscript { + def home = System.properties['user.home'] + dependencies { + classpath fileTree(dir: '../gradle-helper-plugin/target/', include: '*.jar') + classpath fileTree(dir: home + '/.m2/repository/org/debian/maven/maven-repo-helper/1.8.10/', include: '*.jar') + } +} + +apply plugin: org.debian.gradle.DebianHelperPlugin diff --git a/test-project/settings.gradle b/test-project/settings.gradle new file mode 100644 index 0000000..64bebfd --- /dev/null +++ b/test-project/settings.gradle @@ -0,0 +1,5 @@ +include 'project1' +include 'project2' + +project(":project1").projectDir = file("subprojects/project1") +project(":project2").projectDir = file("subprojects/project2") diff --git a/test-project/src/main/java/HelloWorld.java b/test-project/src/main/java/HelloWorld.java new file mode 100644 index 0000000..1aba190 --- /dev/null +++ b/test-project/src/main/java/HelloWorld.java @@ -0,0 +1,7 @@ +public class HelloWorld { + + public static void main(String[] args) { + System.out.println("Hello World!"); + } + +} diff --git a/test-project/subprojects/project1/src/main/java/Project1.java b/test-project/subprojects/project1/src/main/java/Project1.java new file mode 100644 index 0000000..04068e6 --- /dev/null +++ b/test-project/subprojects/project1/src/main/java/Project1.java @@ -0,0 +1,3 @@ +public class Project1 { + +} diff --git a/test-project/subprojects/project2/src/main/java/Project2.java b/test-project/subprojects/project2/src/main/java/Project2.java new file mode 100644 index 0000000..3a28d40 --- /dev/null +++ b/test-project/subprojects/project2/src/main/java/Project2.java @@ -0,0 +1,3 @@ +public class Project2 { + +} diff --git a/test-project/test.bat b/test-project/test.bat new file mode 100644 index 0000000..a300b08 --- /dev/null +++ b/test-project/test.bat @@ -0,0 +1 @@ +gradle --info --refresh-dependencies --offline --gradle-user-home .gradle --console plain --init-script init.gradle compileJava diff --git a/test-project/test.sh b/test-project/test.sh new file mode 100644 index 0000000..0e42c4a --- /dev/null +++ b/test-project/test.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +rm -Rf .gradle +gradle --info --refresh-dependencies --offline \ + --gradle-user-home .gradle \ + --console plain \ + --init-script init.gradle \ + compileJava -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/gradle-debian-helper.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

