Skip to content

Commit

Permalink
Merge pull request jbake-org#7 from ancho/feature/configurable-jbake-…
Browse files Browse the repository at this point in the history
…version

Configurable jbake version
  • Loading branch information
melix committed Dec 30, 2014
2 parents 8a6a89f + fad1555 commit 5bb777a
Show file tree
Hide file tree
Showing 13 changed files with 531 additions and 24 deletions.
42 changes: 34 additions & 8 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ buildscript {
dependencies {
classpath 'me.champeau.gradle:jbake-gradle-plugin:0.2'
// optional, if you use asciidoctor markup
classpath 'org.asciidoctor:asciidoctor-java-integration:0.1.4'
// optional, if you use freemarker template engine
classpath 'org.freemarker:freemarker:2.3.19'
}
}
Expand All @@ -38,10 +32,42 @@ The default input and output directories can be changed using the `jbake` config
[source,groovy]
----
jbake {
input = file('jbake-sources')
output = file("$buildDir/output")
srcDirName = 'jbake-sources'
destDirName = 'output'
}
----
The generated output can then be found at `$buildDir/output`.

The Version could be changed too:

[source,groovy]
----
jbake {
version = '2.3.0'
}
----

The default is 2.3.2.

=== Render Engine configuration

Jbake uses three engines. The library versions could be changed too:

[source,groovy]
----
jbake {
pegdownVersion = '1.4.2'
freemarkerVersion = '2.3.19'
asciidoctorJavaIntegrationVersion = '0.1.4'
asciidoctorjVersion = '1.5.1'
}
----

Notice the `asciidoctorJavaIntegrationVersion` and `asciidoctorjVersion`. Since Version 2.3.1 jbake has changed
to the asciidoctorj library.

This plugin handles this change internally. If you use a Version > 2.3.0 of jbake, the dependency switch to the new one.

=== JBake configuration
There are several options to configure http://www.jbake.org[JBake]. One is to have the regular `jbake.properties` file
Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apply plugin: 'maven-publish'
apply from: 'gradle/credentials.gradle'
apply from: 'gradle/artifactory.gradle'
apply from: 'gradle/bintray.gradle'
apply from: "gradle/providedConfiguration.gradle"

buildscript {
repositories {
Expand All @@ -22,7 +23,10 @@ repositories {
dependencies {
compile gradleApi()
compile localGroovy()
compile 'org.jbake:jbake-core:2.3.0'
provided 'org.jbake:jbake-core:2.3.2'
testCompile('org.spockframework:spock-core:0.7-groovy-2.0') {
exclude group:'org.codehaus.groovy'
}
}

project.version = '0.2.1-SNAPSHOT'
Expand Down
20 changes: 20 additions & 0 deletions gradle/providedConfiguration.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Adds a configuration named 'provided'. 'Provided' dependencies
* are incoming compile dependencies that aren't outgoing
* dependencies. In other words, they have no effect on transitive
* dependency management.
*/

configurations {
provided
providedPlusCompile.extendsFrom(compile, provided)
testCompile.extendsFrom(providedPlusCompile)
}

sourceSets.main {
compileClasspath = configurations.providedPlusCompile
}

plugins.withType(IdeaPlugin) {
idea.module.scopes.PROVIDED.plus = [ configurations.provided ]
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Jan 28 21:49:48 CET 2014
#Fri Oct 03 18:00:04 CEST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip
18 changes: 18 additions & 0 deletions src/main/groovy/me/champeau/gradle/JBakeExtension.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.champeau.gradle

/**
* Created by frank on 12.10.14.
*/
class JBakeExtension {

String version = '2.3.2'
String pegdownVersion = '1.4.2'
String freemarkerVersion = '2.3.19'
String asciidoctorJavaIntegrationVersion = '0.1.4'
String asciidoctorjVersion = '1.5.1'
String srcDirName = 'src/jbake'
String destDirName = 'jbake'
boolean clearCache = false
Map<String, Object> configuration = [:]

}
52 changes: 51 additions & 1 deletion src/main/groovy/me/champeau/gradle/JBakePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,59 @@ package me.champeau.gradle

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration

class JBakePlugin implements Plugin<Project> {


public static final String JBAKE = "jbake"
Project project
JBakeExtension extension

void apply(Project project) {
project.task('jbake', type:JBakeTask)
this.project = project
project.apply(plugin: 'base')

project.repositories {
jcenter()
}

Configuration configuration = project.configurations.maybeCreate(JBAKE)
extension = project.extensions.create(JBAKE, JBakeExtension)

addDependenciesAfterEvaluate()

project.task('jbake', type: JBakeTask, group: 'Documentation', description: 'Bake a jbake project'){

classpath = configuration
conventionMapping.input = { project.file("$project.projectDir/$project.jbake.srcDirName") }
conventionMapping.output = { project.file("$project.buildDir/$project.jbake.destDirName") }
conventionMapping.clearCache = { project.jbake.clearCache }
conventionMapping.configuration = { project.jbake.configuration }
}

}

def addDependenciesAfterEvaluate() {
project.afterEvaluate {
addDependencies()
}
}

def addDependencies() {
project.dependencies {
jbake("org.jbake:jbake-core:${extension.version}")

if ( new Version(extension.version) > new Version("2.3.0") ){
jbake("org.asciidoctor:asciidoctorj:${extension.asciidoctorjVersion}")
}
else {
jbake("org.asciidoctor:asciidoctor-java-integration:${extension.asciidoctorJavaIntegrationVersion}")
}

jbake("org.freemarker:freemarker:${extension.freemarkerVersion}")
jbake("org.pegdown:pegdown:${extension.pegdownVersion}")
}
}

}
12 changes: 12 additions & 0 deletions src/main/groovy/me/champeau/gradle/JBakeProxy.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package me.champeau.gradle

/**
* Created by frank on 12.10.14.
*/
public interface JBakeProxy {

def jbake()
def prepare()
def getConfig()
def setConfig(Object config)
}
42 changes: 42 additions & 0 deletions src/main/groovy/me/champeau/gradle/JBakeProxyImpl.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package me.champeau.gradle

import groovy.transform.Field
import org.apache.commons.configuration.CompositeConfiguration
import org.apache.commons.configuration.MapConfiguration

import java.lang.reflect.Constructor


/**
* Created by frank on 12.10.14.
*/
class JBakeProxyImpl implements JBakeProxy{

Class delegate
def input
def output
def clearCache

def jbake

def jbake() {
if(jbake) {
jbake.bake()
}
}

def prepare() {
Constructor constructor = delegate.getConstructor(File.class,File.class,boolean)

jbake = constructor.newInstance(input, output, clearCache)
jbake.setupPaths()
}

def getConfig(){
jbake.config
}

def setConfig(Object config) {
jbake.config = config
}
}
69 changes: 57 additions & 12 deletions src/main/groovy/me/champeau/gradle/JBakeTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,72 @@
*/
package me.champeau.gradle

import org.apache.commons.configuration.CompositeConfiguration
import org.apache.commons.configuration.MapConfiguration
import org.gradle.api.internal.AbstractTask
import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.Configuration
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.jbake.app.Oven

class JBakeTask extends AbstractTask {
@InputDirectory File input = new File("$project.projectDir/src/jbake")
@OutputDirectory File output = new File("$project.buildDir/jbake")
import java.lang.reflect.Constructor

class JBakeTask extends DefaultTask {
@InputDirectory File input
@OutputDirectory File output
@Input Map<String, Object> configuration = [:]
boolean clearCache = false
boolean clearCache

Configuration classpath
private static ClassLoader cl

JBakeProxy jbake

@TaskAction
void bake() {
new Oven(input, output, clearCache).with {
config = new CompositeConfiguration([new MapConfiguration(configuration), config])
setupPaths()
bake()
createJbake()
jbake.prepare()
mergeConfiguration()
jbake.jbake()
}

private def createJbake() {
if ( !jbake ) {
jbake = new JBakeProxyImpl(delegate: loadOvenDynamic(), input: getInput(), output: getOutput(), clearCache: getClearCache())
}
}

private def mergeConfiguration(){

//config = new CompositeConfiguration([createMapConfiguration(), jbake.getConfig()])
def delegate = loadClass('org.apache.commons.configuration.CompositeConfiguration')
Constructor constructor = delegate.getConstructor(Collection)
def config = constructor.newInstance([createMapConfiguration(), jbake.getConfig()])
jbake.setConfig( config )

}

private def createMapConfiguration(){
def delegate = loadClass('org.apache.commons.configuration.MapConfiguration')
Constructor constructor = delegate.getConstructor(Map)
constructor.newInstance(getConfiguration())
}

private def loadOvenDynamic() {
setupClassLoader()
loadClass("org.jbake.app.Oven")
}

private static Class loadClass(String className) {
cl.loadClass(className)
}

private def setupClassLoader() {
if (classpath?.files) {
def urls = classpath.files.collect { it.toURI().toURL() }
cl = new URLClassLoader(urls as URL[], Thread.currentThread().contextClassLoader)
Thread.currentThread().contextClassLoader = cl
} else {
cl = Thread.currentThread().contextClassLoader
}
}

Expand Down
51 changes: 51 additions & 0 deletions src/main/groovy/me/champeau/gradle/Version.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package me.champeau.gradle

/**
* Created by frank on 13.10.14.
*/
class Version implements Comparable {

Integer major
Integer minor
Integer bugfix

Version(String version) {
def tokens = version.tokenize('.')

this.major = (tokens.size>=1)?tokens.get(0).toInteger():0
this.minor = (tokens.size>=2)?tokens.get(1)?.toInteger():0
this.bugfix = (tokens.size>=3)?tokens.get(2)?.toInteger():0
}

@Override
int compareTo(Object other) {

def ret = 0

if ( this.major == other.major && this.minor == other.minor && this.bugfix == other.bugfix ){
return 0
}

if ( this.major <= other.major ) {
if ( this.minor < other.minor ) {
ret = -1
}
if ( this.bugfix < other.bugfix ) {
ret = -1
}
}

if ( this.major >= other.major ) {
if ( this.minor > other.minor ) {
ret = 1
}
if ( this.bugfix > other.bugfix ) {
ret = 1
}
}

return ret

}

}
Loading

0 comments on commit 5bb777a

Please sign in to comment.