Skip to content
This repository was archived by the owner on Feb 11, 2022. It is now read-only.

Commit 5e7cb2c

Browse files
committed
Merge pull request #66 from hzsweers/z/fix_and_test
Fix for gradle plugin 1.3.0+ and some basic configuration testing
2 parents 9279c93 + e6aa3df commit 5e7cb2c

File tree

14 files changed

+229
-26
lines changed

14 files changed

+229
-26
lines changed

build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
dependencies {
6+
classpath 'com.android.tools.build:gradle:1.3.1'
7+
classpath 'com.novoda:bintray-release:0.3.0'
8+
}
9+
}
10+
111
allprojects {
12+
repositories {
13+
jcenter()
14+
}
215
version = "0.3.2"
316
}

core/build.gradle

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
apply plugin: 'groovy'
21
apply plugin: 'com.novoda.bintray-release'
2+
apply plugin: 'groovy'
3+
apply plugin: 'maven'
34

45
repositories {
56
jcenter()
67
}
78

89
dependencies {
9-
compile 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
1010
compile gradleApi()
11+
compile localGroovy()
12+
compile 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3.1'
13+
14+
testCompile 'com.android.tools.build:gradle:1.3.1'
15+
testCompile 'junit:junit:4.12'
16+
testCompile 'com.google.truth:truth:0.27'
1117
}
1218

1319
compileGroovy {
@@ -20,16 +26,6 @@ publish {
2026
groupId = 'com.novoda'
2127
artifactId = rootProject.name
2228
version = project.version
23-
2429
description = 'Super duper easy way to release your Android and other artifacts to bintray'
2530
website = "https://github.com/novoda/${rootProject.name}"
2631
}
27-
28-
buildscript {
29-
repositories {
30-
jcenter()
31-
}
32-
dependencies {
33-
classpath 'com.novoda:bintray-release:0.3.0'
34-
}
35-
}

core/src/main/groovy/com/novoda/gradle/release/ReleasePlugin.groovy

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ class ReleasePlugin implements Plugin<Project> {
99

1010
void apply(Project project) {
1111
PublishExtension extension = project.extensions.create('publish', PublishExtension)
12-
13-
project.apply([plugin: 'maven-publish'])
14-
attachArtifacts(project)
15-
16-
new BintrayPlugin().apply(project)
17-
delayBintrayConfigurationUntilPublishExtensionIsEvaluated(project, extension)
12+
project.afterEvaluate {
13+
project.apply([plugin: 'maven-publish'])
14+
attachArtifacts(project)
15+
new BintrayPlugin().apply(project)
16+
new BintrayConfiguration(extension).configure(project)
17+
}
1818
}
1919

2020
void attachArtifacts(Project project) {
@@ -36,11 +36,4 @@ class ReleasePlugin implements Plugin<Project> {
3636
}
3737
}
3838
}
39-
40-
private delayBintrayConfigurationUntilPublishExtensionIsEvaluated(Project project, extension) {
41-
project.afterEvaluate {
42-
new BintrayConfiguration(extension).configure(project)
43-
}
44-
}
45-
4639
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="com.novoda.gradle.release.test">
3+
4+
<!-- This needs to be an empty element as workaround for https://code.google.com/p/android/issues/detail?id=77890 -->
5+
6+
</manifest>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.novoda.gradle.release.test;
2+
3+
public class SampleClass {
4+
5+
/**
6+
* This is a main function, because reasons.
7+
*
8+
* @param args
9+
*/
10+
public static void main(String[] args) {
11+
System.out.println("Hello world!");
12+
}
13+
14+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.novoda.gradle.release
2+
import com.jfrog.bintray.gradle.BintrayUploadTask
3+
import org.gradle.api.Project
4+
import org.gradle.api.Task
5+
import org.gradle.api.publish.maven.tasks.GenerateMavenPom
6+
import org.junit.AfterClass
7+
import org.junit.BeforeClass
8+
import org.junit.Test
9+
10+
import static com.google.common.truth.Truth.assertThat
11+
12+
class TestBintrayRelease {
13+
14+
// This is necessary because the IDE debugger and command line invocations have different working directories ಠ_ಠ
15+
private static final WORKING_DIR = System.getProperty("user.dir")
16+
private static final PATH_PREFIX = WORKING_DIR.endsWith("core") ? WORKING_DIR : "$WORKING_DIR/core"
17+
18+
static final String FIXTURE_WORKING_DIR = "$PATH_PREFIX/src/test/fixtures/android_app"
19+
20+
@BeforeClass
21+
static void setup() {
22+
}
23+
24+
@AfterClass
25+
static void tearDown() {
26+
// I don't know why this gets generated, but toss it
27+
new File("${FIXTURE_WORKING_DIR}/userHome").deleteDir()
28+
new File("${FIXTURE_WORKING_DIR}/.gradle").deleteDir()
29+
}
30+
31+
@Test
32+
public void testConfiguration() {
33+
Project project = TestHelper.evaluatableLibProject()
34+
ReleasePlugin plugin = new ReleasePlugin()
35+
plugin.apply(project)
36+
project.publish {
37+
userOrg = 'novoda'
38+
groupId = 'com.example.novoda'
39+
artifactId = "test"
40+
version = project.version
41+
description = 'Super duper easy way to release your Android and other artifacts to bintray'
42+
website = "https://github.com/novoda/bintray-release"
43+
dryRun = true
44+
}
45+
project.evaluate()
46+
47+
Task task1 = project.getTasks().findByPath(":bintrayUpload")
48+
assertThat(task1).isNotNull()
49+
Task task2 = project.getTasks().findByPath(":generatePomFileForMavenPublication")
50+
assertThat(task2).isNotNull()
51+
52+
// Now assert some other stuff about the tasks
53+
BintrayUploadTask uploadTask = task1 as BintrayUploadTask
54+
55+
GenerateMavenPom generatePomTask = task2 as GenerateMavenPom
56+
generatePomTask.execute()
57+
File pomFile = new File(project.buildDir, "/publications/maven/pom-default.xml")
58+
assertThat(pomFile.exists())
59+
NodeList nodes = new XmlParser().parse(pomFile).depthFirst()
60+
assertThat(nodes).isNotNull()
61+
assertThat(nodes).hasSize 6
62+
63+
// Skip the first two since they're boilerplate xml stuff
64+
Node groupIdNode = nodes[2]
65+
assertThat(groupIdNode.name().localPart).isEqualTo "groupId"
66+
assertThat(groupIdNode.value()[0]).isEqualTo "com.example.novoda"
67+
Node artifactIdNode = nodes[3]
68+
assertThat(artifactIdNode.name().localPart).isEqualTo "artifactId"
69+
assertThat(artifactIdNode.value()[0]).isEqualTo "test"
70+
Node versionNode = nodes[4]
71+
assertThat(versionNode.name().localPart).isEqualTo "version"
72+
assertThat(versionNode.value()[0]).isEqualTo "1.0"
73+
Node packagingNode = nodes[5]
74+
assertThat(packagingNode.name().localPart).isEqualTo "packaging"
75+
assertThat(packagingNode.value()[0]).isEqualTo "aar"
76+
77+
// uploadTask verification here
78+
79+
project.buildDir.deleteDir()
80+
}
81+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.novoda.gradle.release
2+
3+
import org.gradle.api.Project
4+
import org.gradle.testfixtures.ProjectBuilder
5+
6+
final class TestHelper {
7+
8+
public static Project evaluatableLibProject() {
9+
Project project = ProjectBuilder.builder().withProjectDir(new File(TestBintrayRelease.FIXTURE_WORKING_DIR)).build()
10+
project.apply plugin: 'com.android.library'
11+
project.version = "1.0"
12+
project.group = "com.example.novoda.gradle.release"
13+
project.android {
14+
compileSdkVersion 23
15+
buildToolsVersion '23.0.0'
16+
17+
defaultConfig {
18+
versionCode 1
19+
versionName '1.0'
20+
minSdkVersion 23
21+
targetSdkVersion 23
22+
}
23+
24+
buildTypes {
25+
release {
26+
signingConfig signingConfigs.debug
27+
}
28+
}
29+
}
30+
31+
return project
32+
}
33+
}

sample/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

sample/build.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.0"
6+
7+
defaultConfig {
8+
minSdkVersion 14
9+
targetSdkVersion 23
10+
versionCode 1
11+
versionName "1.0"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
compile 'com.android.support:appcompat-v7:23.0.0'
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
testCompile 'junit:junit:4.12'
25+
}

sample/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/hsweers/dev/android/android-sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}

0 commit comments

Comments
 (0)