Permalink
Browse files

Deployment plugin added.

  • Loading branch information...
0 parents commit a0021c00d9c6e7c2470c1401ef7d7ec99d5c1123 @anagrius anagrius committed Feb 27, 2011
@@ -0,0 +1,2 @@
+build/
+.gradle/
@@ -0,0 +1,54 @@
+apply plugin:'groovy'
+apply plugin:'maven'
+
+repositories {
+ mavenCentral()
+}
+
+configurations {
+ deployerJars
+}
+
+dependencies {
+ compile gradleApi()
+ testCompile 'org.testng:testng:5.14.6'
+ groovy 'org.codehaus.groovy:groovy:1.7.8'
+ deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2"
+}
+
+task sourcesJar(type: Jar, dependsOn: compileJava) {
+ from sourceSets.main.allSource
+ classifier = 'sources'
+}
+
+artifacts {
+ archives sourcesJar
+}
+
+uploadArchives {
+ repositories.mavenDeployer {
+ configuration = configurations.deployerJars
+ repository(id: 'trifork-releases', url: 'http://nexus.ci81.trifork.com/content/repositories/releases/')
+ snapshotRepository(id: 'trifork-snapshots', url: 'http://nexus.ci81.trifork.com/content/repositories/snapshots/')
+ }
+}
+
+uploadArchives.dependsOn sourcesJar
+
+assemble.doLast( { install } )
+uploadArchives.dependsOn install
+
+task deploySnapshot(dependsOn: 'uploadArchives')
+task deployRelease(dependsOn: 'uploadArchives')
+
+gradle.taskGraph.whenReady { taskGraph ->
+ if (!taskGraph.hasTask(':deployRelease')) version += '-SNAPSHOT'
+
+ manifest.mainAttributes(
+ provider: 'gradle',
+ 'Implementation-Url': 'http://trifork.com',
+ 'Implementation-Version': version,
+ 'Implementation-Vendor': 'Trifork',
+ 'Implementation-Vendor-Id': 'com.trifork'
+ )
+}
@@ -0,0 +1,3 @@
+version = 0.1.0
+group = com.trifork
+artifactId = gradle-plugins
@@ -0,0 +1,70 @@
+package com.trifork.gradle
+
+import org.gradle.api.*
+import org.gradle.api.plugins.*
+import org.gradle.api.tasks.bundling.*
+
+class DeploymentPlugin implements Plugin<Project> {
+
+ def void apply(Project p) {
+
+ def convention = new DeploymentPluginConvention()
+ p.convention.plugins.deployment = convention
+
+ if (!p.plugins.hasPlugin('maven')) {
+ p.apply plugin: 'maven'
+ }
+
+ p.task([dependsOn: 'uploadArchives'], 'deploySnapshot')
+ p.task([dependsOn: 'uploadArchives'], 'deployRelease')
+
+ // In order to deploy the artifacts we need some dependencies.
+ // The actually jars needed depend on how we are going to deploy.
+ // By default we just use HTTP to deploy.
+
+ p.configurations {
+ deployerJars
+ }
+
+ p.dependencies {
+ deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2"
+ }
+
+ // Make a jar containing the sources.
+
+ p.task([type: Jar, dependsOn: p.compileJava], 'sourcesJar') {
+ from p.sourceSets.main.allSource
+ classifier = 'sources'
+ }
+
+ p.artifacts {
+ archives p.tasks.sourcesJar
+ }
+
+ p.uploadArchives.dependsOn p.tasks.sourcesJar
+
+ p.gradle.taskGraph.whenReady { graph ->
+
+ // Determine if this is a release or a snapshot
+
+ if (!graph.hasTask(p.tasks.deployRelease)) p.version += '-SNAPSHOT'
+
+ p.uploadArchives {
+ repositories.mavenDeployer {
+ configuration = p.configurations.deployerJars
+ repository(id: 'trifork-releases', url: 'http://nexus.ci81.trifork.com/content/repositories/releases/')
+ snapshotRepository(id: 'trifork-snapshots', url: 'http://nexus.ci81.trifork.com/content/repositories/snapshots/')
+ }
+ }
+ }
+ }
+}
+
+class DeploymentPluginConvention {
+ String nextReleaseVersion
+
+ def deployment(Closure closure) {
+ closure.delegate = this
+ closure()
+ }
+}
@@ -0,0 +1 @@
+implementation-class=com.trifork.gradle.DeploymentPlugin
@@ -0,0 +1,34 @@
+import org.gradle.api.*
+import org.gradle.api.plugins.*
+import org.testng.annotations.*
+
+class DeploymentPluginTest {
+
+ Project project
+
+ @BeforeTest
+ public void setup() {
+
+ project = ProjectBuilder.builder().build()
+ project.apply plugin: 'deployment'
+ }
+
+ @AfterTest
+ public void teardown() {
+
+ project = null
+ }
+
+ @Test
+ public void pluginAddsReleaseTaskToProject() {
+
+ assertTrue(project.tasks.deployRelease != null)
+ }
+
+
+ @Test
+ public void pluginAddsSnapshotTaskToProject() {
+
+ assertTrue(project.tasks.deploySnapshot != null)
+ }
+}

0 comments on commit a0021c0

Please sign in to comment.