Skip to content

Commit

Permalink
Explain @ArtifactProviderFor and @ServiceProviderFor in guide. Relate…
Browse files Browse the repository at this point in the history
…s to #148
  • Loading branch information
aalmiray committed Feb 27, 2016
1 parent 944a2e8 commit dc3dfa6
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -100,7 +100,7 @@ subprojects { subproj ->
}
if (!subproj.name.startsWith('gradle-')) {
testCompile "org.codehaus.groovy:groovy-all:$groovyVersion"
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
testCompile("org.spockframework:spock-core:$spockVersion") {
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
}
Expand Down
2 changes: 2 additions & 0 deletions docs/griffon-guide/griffon-guide.gradle
Expand Up @@ -207,6 +207,8 @@ asciidoctor {
'source-highlighter' : 'coderay',
'coderay-linenums-mode' : 'table',
'griffon-version' : project.version,
'groovy-version' : project.groovyVersion,
'spock-version' : project.spockVersion,
'griffon-group' : project.group,
'griffon-source-url' : griffonSourceUrl,
'gradle-griffon-version': loadProperties(project(':gradle-griffon-plugin').file('gradle.properties')).version,
Expand Down
Expand Up @@ -156,6 +156,27 @@ include::{console-swing-groovy}/griffon-app/models/console/ConsoleModel.groovy[l
Griffon Models are *_not_* domain classes like the ones you find in Grails; they're more akin
to presentation models, and as such, they're used to transfer data between Views and Controllers.

Notice the usage of the `{link_artifact_provider_for}` annotation. This annotation serves as an additional hint to the
compiler, letting it know it must generate or update a metadata file in an specific location.
The file is named after the argument set on the annotation, in this case, `griffon.core.artifact.GriffonModel`. This file
is automatically placed under `META-INF/griffon`. It's contents are fully qualified class names of types that implement
the argument set on the annotation. This results in the following file being automatically created or updated with every
compilation session

.META-INF/griffon/griffon.core.artifact.GriffonModel
[source,java,linenums,options="nowrap"]
----
console.ConsoleModel
----

You will see this annotation being used by other artifacts too albeit with different values, which will produce different
files, such as `META-INF/griffon/griffon.core.artifact.GriffonController`, `META-INF/griffon/griffon.core.artifact.GriffonView`,
and `META-INF/griffon/griffon.core.artifact.GriffonService`.

It's worth mentioning that you may skip applying this annotation, in which case you'll be responsible for creating and
updating the files mentioned earlier. These files are *very important* to the Griffon runtime, as they are used to
locate and configure all artifacts in an application.

[[_getting_started_console_example_controller]]
=== Controller

Expand Down Expand Up @@ -211,13 +232,19 @@ include::{console-swing-groovy}/src/main/groovy/console/ApplicationModule.groovy
<1> Binding definition
<2> Overriding an existing binding
<3> Loaded after `swing` module
<4> Generate metadata file automatically

Modules can define several bindings, even override existing bindings. In our particular
case, we defined a binding [conum,data-value=1]_1_ for `Evaluator` and overrode a
binding [conum,data-value=2]_2_ for `SwingWindowDisplayHandler`. The latter is
supplied by the `swing` module; thus, we must mark it as a dependency [conum,data-value=3]_3_
in our module definition. The implementation of our custom `SwingWindowDisplayHandler`
is quite trivial, as shown by the following snippet:
in our module definition. Modules must be listed in a metadata file named `META-INF/services/griffon.core.injection.Module`;
this is exactly what the `@ServiceProviderFor` annotation does, by instructing the compiler that it must create or update
this particular file. This annotation is handled by the Annotation Processing tool facilities in Java via {link_jipsy} or
by AST Transformations in Groovy via {link_gipsy}. What's important to remember is that this annotation will keep the metadata
files up to date everytime a compilation session is executed.

The implementation of our custom `SwingWindowDisplayHandler` is quite trivial, as shown by the following snippet:

.src/main/groovy/console/CenteringWindowDisplayHandler.groovy
[source,groovy,linenums,options="nowrap"]
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
@@ -1,6 +1,7 @@
version=2.6.0-SNAPSHOT
group=org.codehaus.griffon
groovyVersion=2.4.6
spockVersion=1.0-groovy-2.4
slf4jVersion=1.7.16
guiceVersion=4.0
jipsyVersion=0.4.0
Expand Down
82 changes: 74 additions & 8 deletions samples/console-swing-groovy/build.gradle.txt
Expand Up @@ -5,38 +5,54 @@ buildscript {

dependencies {
classpath 'org.codehaus.griffon:gradle-griffon-plugin:{gradle-griffon-version}'
classpath 'net.saliman:gradle-cobertura-plugin:2.2.8'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.4.0'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.6.3'
classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0'
classpath 'org.gradle.api.plugins:gradle-izpack-plugin:0.2.3'
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.2'
classpath 'com.github.cr0:gradle-macappbundle-plugin:3.1.0'
classpath 'org.kordamp.gradle:stats-gradle-plugin:0.1.5'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
classpath 'de.gliderpilot.gradle.jnlp:gradle-jnlp-plugin:0.2.1'
classpath 'net.nemerosa:versioning:1.6.2'
}
}

apply plugin: 'groovy'
apply plugin: 'org.codehaus.griffon.griffon'
apply plugin: 'net.nemerosa.versioning'

Date buildTimeAndDate = new Date()
ext {
buildDate = new SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate)
buildTime = new SimpleDateFormat('HH:mm:ss.SSSZ').format(buildTimeAndDate)
macosx = System.getProperty('os.name').contains('Mac OS')
}

griffon {
disableDependencyResolution = false
includeGroovyDependencies = true
includeGroovyDependencies = false
version = '{griffon-version}'
toolkit = 'swing'
applicationProperties = [
'build.date' : buildDate,
'build.time' : buildTime,
'build.revision': versioning.info.commit
]
}

mainClassName = '${project_package}.Launcher'

apply from: 'gradle/publishing.gradle'
apply from: 'gradle/code-coverage.gradle'
apply from: 'gradle/code-quality.gradle'
apply from: 'gradle/integration-test.gradle'
apply from: 'gradle/functional-test.gradle'
apply from: 'gradle/package.gradle'
apply from: 'gradle/docs.gradle'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'org.kordamp.gradle.stats'
apply plugin: 'com.github.ben-manes.versions'

mainClassName = 'console.Launcher'
apply plugin: 'com.github.kt3k.coveralls'

dependencies {
compile "org.codehaus.griffon:griffon-guice:${griffon.version}"
Expand All @@ -46,13 +62,30 @@ dependencies {
exclude group: 'ant', module: 'ant-junit'
exclude group: 'ant-contrib', module: 'ant-contrib'
}
runtime 'org.slf4j:slf4j-log4j12:1.7.7'
runtime 'org.slf4j:slf4j-log4j12:1.7.13'

testCompile "org.codehaus.griffon:griffon-javafx-test:${griffon.version}"
testCompile "org.codehaus.groovy:groovy-all:{groovy-version}"
testCompile "org.spockframework:spock-core:{spock-version}"

testCompile "org.codehaus.griffon:griffon-fest-test:${griffon.version}"
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
functionalTestCompile "org.codehaus.griffon:griffon-javafx-test:${griffon.version}"
}

compileGroovy.enabled = false

tasks.withType(JavaCompile) {
sourceCompatibility = project.sourceCompatibility
targetCompatibility = project.targetCompatibility
}

tasks.withType(GroovyCompile) {
sourceCompatibility = project.sourceCompatibility
targetCompatibility = project.targetCompatibility
}

import com.github.jengelman.gradle.plugins.shadow.transformers.*
import java.text.SimpleDateFormat

shadowJar {
transform(ServiceFileTransformer)
transform(ServiceFileTransformer) {
Expand All @@ -66,4 +99,37 @@ shadowJar {
'META-INF/editors/java.beans.PropertyEditor'
]
}
}

startScripts {
doLast {
if (!macosx) unixScript.text = unixScript.text.replaceAll('"(-Xdock:(name|icon)=)([^"]*?)(")', ' ')
windowsScript.text = windowsScript.text.replaceAll('"(-Xdock:(name|icon)=)([^"]*?)(")', ' ')
}
}

if (hasProperty('debugRun') && ((project.debugRun as boolean))) {
run {
jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005'
}
}

task jacocoRootMerge(type: org.gradle.testing.jacoco.tasks.JacocoMerge, dependsOn: [test, jacocoTestReport, jacocoIntegrationTestReport, jacocoFunctionalTestReport]) {
executionData = files(jacocoTestReport.executionData, jacocoIntegrationTestReport.executionData, jacocoFunctionalTestReport.executionData)
destinationFile = file("${buildDir}/jacoco/root.exec")
}

task jacocoRootReport(dependsOn: jacocoRootMerge, type: JacocoReport) {
group = 'Reporting'
description = 'Generate Jacoco coverage reports after running all tests.'
executionData file("${buildDir}/jacoco/root.exec")
sourceDirectories = files(sourceSets.main.allSource.srcDirs)
classDirectories = files(sourceSets.main.output)
reports {
csv.enabled = false
xml.enabled = true
html.enabled = true
html.destination = "${buildDir}/reports/jacoco/root/html"
xml.destination = "${buildDir}/reports/jacoco/root/root.xml"
}
}
Expand Up @@ -24,7 +24,7 @@ import org.kordamp.jipsy.ServiceProviderFor
import static griffon.util.AnnotationUtils.named

@DependsOn('swing') //<3>
@ServiceProviderFor(Module)
@ServiceProviderFor(Module) //<4>
class ApplicationModule extends AbstractModule {
@Override
protected void doConfigure() {
Expand Down
Expand Up @@ -24,7 +24,7 @@
minHeight="-Infinity" minWidth="-Infinity"
prefHeight="80.0" prefWidth="384.0"
xmlns:fx="http://javafx.com/fxml"
fx:controller="sample.javafx.java.SampleController">
fx:controller="sample.javafx.java.SampleView">
<children>
<Label layoutX="14.0" layoutY="14.0" text="Please enter your name:"/>
<TextField fx:id="input" layoutX="172.0" layoutY="11.0"
Expand Down

0 comments on commit dc3dfa6

Please sign in to comment.