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

Commit

Permalink
Merge pull request #66 from hzsweers/z/fix_and_test
Browse files Browse the repository at this point in the history
Fix for gradle plugin 1.3.0+ and some basic configuration testing
  • Loading branch information
friedger committed Aug 24, 2015
2 parents 9279c93 + e6aa3df commit 5e7cb2c
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 26 deletions.
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'com.novoda:bintray-release:0.3.0'
}
}

allprojects {
repositories {
jcenter()
}
version = "0.3.2"
}
20 changes: 8 additions & 12 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
apply plugin: 'groovy'
apply plugin: 'com.novoda.bintray-release'
apply plugin: 'groovy'
apply plugin: 'maven'

repositories {
jcenter()
}

dependencies {
compile 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
compile gradleApi()
compile localGroovy()
compile 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3.1'

testCompile 'com.android.tools.build:gradle:1.3.1'
testCompile 'junit:junit:4.12'
testCompile 'com.google.truth:truth:0.27'
}

compileGroovy {
Expand All @@ -20,16 +26,6 @@ publish {
groupId = 'com.novoda'
artifactId = rootProject.name
version = project.version

description = 'Super duper easy way to release your Android and other artifacts to bintray'
website = "https://github.com/novoda/${rootProject.name}"
}

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.novoda:bintray-release:0.3.0'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class ReleasePlugin implements Plugin<Project> {

void apply(Project project) {
PublishExtension extension = project.extensions.create('publish', PublishExtension)

project.apply([plugin: 'maven-publish'])
attachArtifacts(project)

new BintrayPlugin().apply(project)
delayBintrayConfigurationUntilPublishExtensionIsEvaluated(project, extension)
project.afterEvaluate {
project.apply([plugin: 'maven-publish'])
attachArtifacts(project)
new BintrayPlugin().apply(project)
new BintrayConfiguration(extension).configure(project)
}
}

void attachArtifacts(Project project) {
Expand All @@ -36,11 +36,4 @@ class ReleasePlugin implements Plugin<Project> {
}
}
}

private delayBintrayConfigurationUntilPublishExtensionIsEvaluated(Project project, extension) {
project.afterEvaluate {
new BintrayConfiguration(extension).configure(project)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.novoda.gradle.release.test">

<!-- This needs to be an empty element as workaround for https://code.google.com/p/android/issues/detail?id=77890 -->

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.novoda.gradle.release.test;

public class SampleClass {

/**
* This is a main function, because reasons.
*
* @param args
*/
public static void main(String[] args) {
System.out.println("Hello world!");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.novoda.gradle.release
import com.jfrog.bintray.gradle.BintrayUploadTask
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.publish.maven.tasks.GenerateMavenPom
import org.junit.AfterClass
import org.junit.BeforeClass
import org.junit.Test

import static com.google.common.truth.Truth.assertThat

class TestBintrayRelease {

// This is necessary because the IDE debugger and command line invocations have different working directories ಠ_ಠ
private static final WORKING_DIR = System.getProperty("user.dir")
private static final PATH_PREFIX = WORKING_DIR.endsWith("core") ? WORKING_DIR : "$WORKING_DIR/core"

static final String FIXTURE_WORKING_DIR = "$PATH_PREFIX/src/test/fixtures/android_app"

@BeforeClass
static void setup() {
}

@AfterClass
static void tearDown() {
// I don't know why this gets generated, but toss it
new File("${FIXTURE_WORKING_DIR}/userHome").deleteDir()
new File("${FIXTURE_WORKING_DIR}/.gradle").deleteDir()
}

@Test
public void testConfiguration() {
Project project = TestHelper.evaluatableLibProject()
ReleasePlugin plugin = new ReleasePlugin()
plugin.apply(project)
project.publish {
userOrg = 'novoda'
groupId = 'com.example.novoda'
artifactId = "test"
version = project.version
description = 'Super duper easy way to release your Android and other artifacts to bintray'
website = "https://github.com/novoda/bintray-release"
dryRun = true
}
project.evaluate()

Task task1 = project.getTasks().findByPath(":bintrayUpload")
assertThat(task1).isNotNull()
Task task2 = project.getTasks().findByPath(":generatePomFileForMavenPublication")
assertThat(task2).isNotNull()

// Now assert some other stuff about the tasks
BintrayUploadTask uploadTask = task1 as BintrayUploadTask

GenerateMavenPom generatePomTask = task2 as GenerateMavenPom
generatePomTask.execute()
File pomFile = new File(project.buildDir, "/publications/maven/pom-default.xml")
assertThat(pomFile.exists())
NodeList nodes = new XmlParser().parse(pomFile).depthFirst()
assertThat(nodes).isNotNull()
assertThat(nodes).hasSize 6

// Skip the first two since they're boilerplate xml stuff
Node groupIdNode = nodes[2]
assertThat(groupIdNode.name().localPart).isEqualTo "groupId"
assertThat(groupIdNode.value()[0]).isEqualTo "com.example.novoda"
Node artifactIdNode = nodes[3]
assertThat(artifactIdNode.name().localPart).isEqualTo "artifactId"
assertThat(artifactIdNode.value()[0]).isEqualTo "test"
Node versionNode = nodes[4]
assertThat(versionNode.name().localPart).isEqualTo "version"
assertThat(versionNode.value()[0]).isEqualTo "1.0"
Node packagingNode = nodes[5]
assertThat(packagingNode.name().localPart).isEqualTo "packaging"
assertThat(packagingNode.value()[0]).isEqualTo "aar"

// uploadTask verification here

project.buildDir.deleteDir()
}
}
33 changes: 33 additions & 0 deletions core/src/test/groovy/com/novoda/gradle/release/TestHelper.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.novoda.gradle.release

import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder

final class TestHelper {

public static Project evaluatableLibProject() {
Project project = ProjectBuilder.builder().withProjectDir(new File(TestBintrayRelease.FIXTURE_WORKING_DIR)).build()
project.apply plugin: 'com.android.library'
project.version = "1.0"
project.group = "com.example.novoda.gradle.release"
project.android {
compileSdkVersion 23
buildToolsVersion '23.0.0'

defaultConfig {
versionCode 1
versionName '1.0'
minSdkVersion 23
targetSdkVersion 23
}

buildTypes {
release {
signingConfig signingConfigs.debug
}
}
}

return project
}
}
1 change: 1 addition & 0 deletions sample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
25 changes: 25 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.0"

defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile 'com.android.support:appcompat-v7:23.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
}
17 changes: 17 additions & 0 deletions sample/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/hsweers/dev/android/android-sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.novoda.gradle.release.sample;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
8 changes: 8 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.novoda.gradle.release.sample">

<application android:allowBackup="true" android:label="@string/app_name">

</application>

</manifest>
3 changes: 3 additions & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">BintrayReleaseSample</string>
</resources>
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include ':core', ':sample'
rootProject.name = 'bintray-release'
include 'core'

0 comments on commit 5e7cb2c

Please sign in to comment.