Skip to content

Commit

Permalink
Added Gradle plugin scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
mockitoguy committed Jun 11, 2020
1 parent d49adc0 commit 15f5fe3
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -5,5 +5,4 @@
out
*.iml
*.ipr
*.iws
.shelf
*.iws
12 changes: 9 additions & 3 deletions build.gradle
Expand Up @@ -15,11 +15,17 @@ repositories {
jcenter()
}

apply from: "$rootDir/gradle/integ-test.gradle"
apply from: "$rootDir/gradle/release.gradle"

dependencies {
implementation "com.eclipsesource.minimal-json:minimal-json:0.9.5"
testImplementation 'junit:junit:4.12'

testImplementation "org.spockframework:spock-core:1.3-groovy-2.5"
testImplementation "cglib:cglib-nodep:3.3.0" //mocking concrete classes with spock
testImplementation "org.objenesis:objenesis:3.1" //as above

testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.0"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.6.0"
testImplementation gradleTestKit()
}

test {
Expand Down
22 changes: 22 additions & 0 deletions gradle/integ-test.gradle
@@ -0,0 +1,22 @@
sourceSets {
integTest {
}
}

gradlePlugin.testSourceSets(sourceSets.integTest)
configurations.integTestImplementation.extendsFrom(configurations.testImplementation)

task integTest(type: Test) {
testClassesDirs = sourceSets.integTest.output.classesDirs
classpath = sourceSets.integTest.runtimeClasspath
}

check {
dependsOn(tasks.integTest)
}

idea {
module {
testSourceDirs += file('src/integTest/groovy')
}
}
21 changes: 21 additions & 0 deletions gradle/release.gradle
@@ -0,0 +1,21 @@
// docs: https://plugins.gradle.org/docs/publish-plugin
gradlePlugin {
plugins {
autoVersion {
id = 'org.shipkit.changelog'
implementationClass = 'org.shipkit.changelog.ChangelogPlugin'
}
}
}

pluginBundle {
website = 'https://github.com/shipkit/org.shipkit.shipkit-changelog'
vcsUrl = 'https://github.com/shipkit/org.shipkit.shipkit-changelog.git'
plugins {
autoVersion {
displayName = 'Shipkit changelog plugin'
description = 'Generates changelog based on ticked IDs found in commit messages and GitHub pull request information'
tags = ['ci', 'shipkit', 'changelog']
}
}
}
Empty file modified gradlew 100644 → 100755
Empty file.
@@ -0,0 +1,52 @@
package org.shipkit.changelog

import org.gradle.testkit.runner.GradleRunner
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification

/**
* Only smoke test, forever! Don't add more tests here, instead cover the complexity in lower level unit tests.
*/
class ChangelogPluginIntegTest extends Specification {

@Rule TemporaryFolder tmp = new TemporaryFolder()

def setup() {
file("settings.gradle")
file("build.gradle") << """
plugins { id('org.shipkit.changelog')}
"""
}

def "applies plugin cleanly"() {
given:
def result = run("tasks")

expect:
result.output.contains("Applying plugin...")
}

File file(String path) {
def f = new File(rootDir, path)
if (!f.exists()) {
f.parentFile.mkdirs()
f.createNewFile()
assert f.exists()
}
return f
}

File getRootDir() {
return tmp.root
}

def run(String ...args) {
def runner = GradleRunner.create()
runner.forwardOutput()
runner.withPluginClasspath()
runner.withArguments(args)
runner.withProjectDir(rootDir)
return runner.build()
}
}
18 changes: 18 additions & 0 deletions src/main/java/org/shipkit/changelog/ChangelogPlugin.java
@@ -0,0 +1,18 @@
package org.shipkit.changelog;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;

/**
* The plugin, ideally with zero business logic, but only the Gradle integration code
*/
public class ChangelogPlugin implements Plugin<Project> {

private static final Logger LOG = Logging.getLogger(ChangelogPlugin.class);

public void apply(Project project) {
LOG.lifecycle("Applying plugin...");
}
}

0 comments on commit 15f5fe3

Please sign in to comment.