Skip to content

Commit

Permalink
Add build support for publishing gradle plugin (see issue #107)
Browse files Browse the repository at this point in the history
  • Loading branch information
uschindler committed Sep 17, 2018
1 parent 42f66d1 commit f41f92d
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 6 deletions.
36 changes: 30 additions & 6 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@

<property name="signatures.dir" location="src/main/resources/de/thetaphi/forbiddenapis/signatures"/>
<property name="groovy-tools.dir" location="src/tools/groovy"/>
<property name="gradle-build-dir" location="build/gradle"/>
<property name="gradle-test-build-dir" location="build/test-gradle"/>
<property name="gradle-publish-build-dir" location="build/gradle-plugin-portal"/>
<property name="maven-build-dir" location="build/maven"/>
<property name="documentation-dir" location="build/docs"/>
<property name="test-results-dir" location="build/test-results"/>
Expand Down Expand Up @@ -576,21 +577,21 @@
</target>

<target name="test-gradle" depends="compile,compile-test,jar,-gradle-unsupported" if="gradle.supported" description="Runs a basic Gradle project to check ourselves">
<mkdir dir="${gradle-build-dir}"/>
<copy todir="${gradle-build-dir}">
<mkdir dir="${gradle-test-build-dir}"/>
<copy todir="${gradle-test-build-dir}">
<fileset dir="src/test/gradle"/>
</copy>
<pathconvert property="gradle.forbiddenClasspath" refid="path.main-build"/>
<pathconvert property="gradle.forbiddenTestClasspath" refid="path.junit-build"/>
<property name="gradle.forbiddenRootDir" location="."/>
<property name="gradle.forbiddenSourceCompatibility" value="${jdk.version}"/>
<echoproperties destfile="${gradle-build-dir}/gradle.properties" failonerror="true">
<echoproperties destfile="${gradle-test-build-dir}/gradle.properties" failonerror="true">
<propertyset>
<propertyref prefix="gradle."/>
<globmapper from="gradle.*" to="*"/>
</propertyset>
</echoproperties>
<exec executable="${gradle.exe}" dir="${gradle-build-dir}" searchpath="true" vmlauncher="false" failonerror="true" failifexecutionfails="true" taskname="gradle">
<exec executable="${gradle.exe}" dir="${gradle-test-build-dir}" searchpath="true" vmlauncher="false" failonerror="true" failifexecutionfails="true" taskname="gradle">
<arg value="--rerun-tasks"/>
<arg value="--info"/>
<arg value="--stacktrace"/>
Expand Down Expand Up @@ -694,7 +695,8 @@
nowarn="true" source="1.8" target="1.8" debug="true" deprecation="false" encoding="${build.encoding}"/>
</target>

<target name="generate-test-classes" depends="-generate-test-classes-init,-generate-test-classes-sunmisc,-generate-test-classes-jdk6,-generate-test-classes-jdk7,-generate-test-classes-jdk8" description="Regenerates .class files used by tests if the current JDK version supports it"/>
<target name="generate-test-classes" depends="-generate-test-classes-init,-generate-test-classes-sunmisc,-generate-test-classes-jdk6,-generate-test-classes-jdk7,-generate-test-classes-jdk8"
description="Regenerates .class files used by tests if the current JDK version supports it"/>

<target name="show-help-mojo" depends="install-maven-artifacts" description="Shows help about mojo usage">
<artifact:mvn mavenVersion="${maven.version}" failonerror="true" fork="${maven.fork}" taskname="help">
Expand All @@ -704,5 +706,27 @@
</artifact:mvn>
</target>

<target name="publish-gradle-plugin" description="Publish artifacts (from Maven repo) to Gradle Plugin Portal (pass -Dversion=x.y)">
<fail unless="gradle.supported" message="You need to enable Gradle support with -Dgradle.exe=/path/to/gradle"/>
<fail if="isSnapshot" message="You can only publish release versions to Gradle Plugin Portal"/>
<!-- prepare the Gradle build file (in new empty directory): -->
<delete failonerror="false" dir="${gradle-publish-build-dir}"/>
<mkdir dir="${gradle-publish-build-dir}"/>
<copy todir="${gradle-publish-build-dir}" encoding="${build.encoding}" outputencoding="${build.encoding}">
<fileset dir="src/tools/gradle-plugin-portal" includes="*.template"/>
<filterset>
<filter token="VERSION" value="${version}"/>
<filter token="GROUPID" value="${groupId}"/>
<filter token="ARTIFACTID" value="${artifactId}"/>
</filterset>
<globmapper from="*.template" to="*"/>
</copy>
<!-- Exceute Gradle and execute task 'publishPlugins': -->
<exec executable="${gradle.exe}" dir="${gradle-publish-build-dir}" searchpath="true" vmlauncher="false" failonerror="true" failifexecutionfails="true" taskname="gradle">
<arg value="--no-daemon"/>
<arg value="publishPlugins"/>
</exec>
</target>

<target name="jenkins" depends="clean,dist,test,documentation,-stage.snapshots" description="Runs Jenkins Nightly"/>
</project>
76 changes: 76 additions & 0 deletions src/tools/gradle-plugin-portal/build.gradle.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* (C) Copyright Uwe Schindler (Generics Policeman) and others.
*
* 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.
*/

plugins {
id "com.gradle.plugin-publish" version "0.10.0"
}

def publishGroup = '@GROUPID@'
group = '@[email protected]'
version = '@VERSION@'

pluginBundle {
website = 'https://github.com/policeman-tools/forbidden-apis'
vcsUrl = 'https://github.com/policeman-tools/forbidden-apis'

plugins {
forbiddenApisPlugin {
id = 'de.thetaphi.forbiddenapis'
displayName = 'Policeman\'s Forbidden API Checker'
description = 'Allows to parse Java byte code to find invocations of method/class/field signatures and fail build.'
tags = ['forbiddenapis', 'verification', 'code checker', 'static analysis']
}
}

mavenCoordinates {
groupId = publishGroup
artifactId = project.name
}
}

repositories {
mavenCentral()
mavenLocal()
}

configurations {
pluginArtifacts.transitive = false
}

dependencies {
pluginArtifacts group: publishGroup, name: project.name, version: project.version
pluginArtifacts group: publishGroup, name: project.name, version: project.version, classifier: 'sources'
}

task copyPluginArtifacts(type: Copy) {
group 'Build'
description 'Copies plugin artifacts (from Maven) to local folder for publishing'
from configurations.pluginArtifacts
into libsDir
}

publishPlugins {
dependsOn('copyPluginArtifacts')
}

afterEvaluate {
configurations.archives.artifacts.removeAll{
it.classifier=='javadoc'
}
tasks.withType(Jar) {
enabled = false
}
}
1 change: 1 addition & 0 deletions src/tools/gradle-plugin-portal/settings.gradle.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = '@ARTIFACTID@'

0 comments on commit f41f92d

Please sign in to comment.