Skip to content

Commit 86ed5c9

Browse files
author
Mike Kistler
committed
Initial attempt at Watson Spring support
1 parent 054480c commit 86ed5c9

35 files changed

+1932
-4
lines changed

.gitignore

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,20 @@ gradle-app.setting
1010
# Cache of project
1111
.gradletasknamecache
1212

13-
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
14-
# gradle/wrapper/gradle-wrapper.properties
13+
.checkstyle
14+
.classpath
15+
.codepro
16+
.config.properties
17+
.DS_Store
18+
.idea
19+
.project
20+
.settings
21+
.vscode/
22+
docs
23+
out
24+
target
25+
26+
*.iml
27+
*.ipr
28+
*.iws
29+

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,55 @@
1-
# watson-spring
2-
Spring Boot support for Watson services
1+
# Watson Spring Boot
2+
3+
This project adds Spring Boot support for the Watson services.
4+
5+
This means that you can now "auto-wire" any of the Watson services into your Spring Boot application
6+
using the standard Spring autoconfiguration framework.
7+
8+
All you need to do is:
9+
10+
1. Add the Watson spring-boot-starter dependency to your Spring Boot app:
11+
12+
In your maven `pom.xml`
13+
```
14+
<dependency>
15+
<groupId>com.ibm.watson.developer_cloud</groupId>
16+
<artifactId>spring-boot-starter</artifactId>
17+
<version>4.2.1</version>
18+
</dependency>
19+
```
20+
21+
or in your gradle `build.gradle`, in the dependencies stanza, add
22+
```
23+
compile 'com.ibm.watson.developer_cloud:spring-boot-starter:4.2.1'
24+
```
25+
26+
2. Add your Watson service(s) credentials and version info to your application
27+
properties file. The standard location for application properties is the
28+
`src/main/resources/application.properties` file, but your application might
29+
use a different location. The properties to add are:
30+
31+
- `watson.<service>.url`: The base URL for the service. This can be omitted if your
32+
service uses the default service url
33+
- `watson.<service>.username` and `watson.<service>.password` OR `watson.<service>.apiKey`:
34+
The credentials for accessing the service.
35+
The credentials can be omitted from the application properties file if they are
36+
supplied through the `VCAP_SERVICES` environment variable.
37+
- `watson.<service>.versionDate`: Some Watson services use a `versionDate` parameter to
38+
indicate the service behavior expected by the application. For services that accept it,
39+
this is a required parameter and must be specified in the application properties.
40+
41+
Both Eclipse and IntelliJ (Ultimate Edition) offer autocomplete support for
42+
Spring Boot application properties and should show these properties, along with
43+
their required type and Javadoc description, in the autocomplete menu.
44+
45+
3. Autowire the service into your application. Autowiring is the key mechanism of the
46+
Spring framework for injecting dependencies. It is accomplished by specifying the
47+
`@Autowired` annotation on the declaration for the service instance.
48+
Here's an example using the Watson Conversation service:
49+
```java
50+
@Autowired
51+
protected Conversation service;
52+
```
53+
54+
The Spring framework takes care of the rest. Your application can now simply start
55+
using the service instance.

VERSION

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

build.gradle

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* Copyright © 2017 IBM Corp. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
14+
15+
buildscript {
16+
repositories {
17+
maven { url 'http://repo.spring.io/plugins-release' }
18+
}
19+
dependencies {
20+
classpath 'io.spring.gradle:propdeps-plugin:0.0.9.RELEASE'
21+
}
22+
}
23+
24+
plugins {
25+
id 'net.researchgate.release' version '2.4.0'
26+
}
27+
28+
apply plugin: 'java'
29+
apply plugin: 'checkstyle'
30+
apply plugin: 'eclipse'
31+
apply plugin: 'idea'
32+
33+
apply plugin: 'propdeps'
34+
apply plugin: 'propdeps-maven'
35+
36+
import org.apache.tools.ant.filters.*
37+
38+
archivesBaseName = 'spring-boot-starter'
39+
40+
description = 'Spring Boot Starter for the IBM Watson Services'
41+
42+
group = 'com.ibm.watson.developer_cloud'
43+
version = new File(rootDir, 'VERSION').text.trim()
44+
45+
// If the version says "snapshot" anywhere assume it is not a release
46+
ext.isReleaseVersion = !version.toUpperCase(Locale.ENGLISH).contains("SNAPSHOT")
47+
48+
javadoc {
49+
source = 'src/main/java'
50+
}
51+
52+
checkstyle {
53+
configFile = rootProject.file('checkstyle.xml')
54+
ignoreFailures = false
55+
}
56+
57+
checkstyleMain {
58+
ignoreFailures = false
59+
}
60+
61+
checkstyleTest {
62+
ignoreFailures = false
63+
}
64+
65+
task docs(type: Javadoc) {
66+
destinationDir = file("$buildDir/docs/all")
67+
}
68+
69+
task copyJars(type: Copy) {
70+
from subprojects.collect { it.tasks.withType(Jar) }
71+
into "$buildDir/allJars"
72+
}
73+
74+
task signJars(type: Copy) {
75+
from subprojects.collect { it.tasks.withType(Sign) }
76+
into "$buildDir/allJars"
77+
}
78+
79+
sourceCompatibility = 1.8
80+
targetCompatibility = 1.8
81+
82+
repositories {
83+
mavenCentral()
84+
}
85+
86+
ext.watsonVersion = '4.2.1'
87+
ext.springVersion = '4.3.12.RELEASE'
88+
ext.springBootVersion = '1.5.9.RELEASE'
89+
90+
dependencies {
91+
// Watson Java SDK
92+
compile group: 'com.ibm.watson.developer_cloud', name: 'java-sdk', version: watsonVersion
93+
94+
// Spring
95+
compile group: 'org.springframework', name: 'spring-core', version: springVersion
96+
compile group: 'org.springframework', name: 'spring-context', version: springVersion
97+
compile group: 'org.springframework', name: 'spring-beans', version: springVersion
98+
compile group: 'org.springframework.boot', name: 'spring-boot', version: springBootVersion
99+
compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: springBootVersion
100+
optional group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: springBootVersion
101+
102+
// testing
103+
testCompile group: 'junit', name: 'junit', version: '4.12'
104+
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion
105+
}
106+
107+
compileJava.dependsOn(processResources)
108+
109+
test {
110+
testLogging {
111+
events "failed"
112+
exceptionFormat "full"
113+
}
114+
}
115+
116+
afterEvaluate {
117+
if (plugins.hasPlugin(JavaPlugin)) {
118+
rootProject.tasks.docs {
119+
source += files(sourceSets.main.allJava)
120+
classpath += files(sourceSets*.compileClasspath)
121+
}
122+
}
123+
}
124+
125+
apply plugin: 'jacoco'
126+
127+
task codeCoverageReport(type: JacocoReport) {
128+
// Gather execution data from all sub projects
129+
// (change this if you e.g. want to calculate unit test/integration test coverage separately)
130+
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
131+
132+
// Add all relevant source sets from the sub projects
133+
subprojects.each {
134+
sourceSets it.sourceSets.main
135+
}
136+
137+
reports {
138+
xml.enabled true
139+
xml.destination file("${buildDir}/reports/jacoco/report.xml")
140+
html.enabled true
141+
html.destination file("${buildDir}/reports/jacoco")
142+
csv.enabled false
143+
}
144+
}
145+
146+
// always run the tests before generating the report
147+
codeCoverageReport.dependsOn {
148+
subprojects*.test
149+
testReport
150+
}
151+
152+
task testReport(type: TestReport) {
153+
destinationDir = file("$buildDir/reports/allTests")
154+
155+
// Include the results from the `test` task in all subprojects
156+
reportOn subprojects*.test
157+
}
158+
159+
release {
160+
tagTemplate = 'watson-spring-boot-$version'
161+
}
162+

checkstyle.xml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<!DOCTYPE module PUBLIC
2+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
3+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
4+
5+
<module name="Checker">
6+
7+
<module name="NewlineAtEndOfFile"/>
8+
<module name="FileLength"/>
9+
<module name="FileTabCharacter"/>
10+
11+
<!-- Trailing spaces -->
12+
<module name="RegexpSingleline">
13+
<property name="format" value="\s+$"/>
14+
<property name="message" value="Line has trailing spaces."/>
15+
</module>
16+
17+
<!-- Space after 'for' and 'if' -->
18+
<module name="RegexpSingleline">
19+
<property name="format" value="^\s*(for|if)\b[^ ]"/>
20+
<property name="message" value="Space needed before opening parenthesis."/>
21+
</module>
22+
23+
<!-- For each spacing -->
24+
<module name="RegexpSingleline">
25+
<property name="format" value="^\s*for \(.*?([^ ]:|:[^ ])"/>
26+
<property name="message" value="Space needed around ':' character."/>
27+
</module>
28+
29+
<module name="TreeWalker">
30+
31+
<!-- Checks for Javadoc comments. -->
32+
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
33+
<!--module name="JavadocMethod"/-->
34+
<!--module name="JavadocType"/-->
35+
<!--module name="JavadocVariable"/-->
36+
<module name="JavadocStyle"/>
37+
38+
39+
<!-- Checks for Naming Conventions. -->
40+
<!-- See http://checkstyle.sf.net/config_naming.html -->
41+
<!--<module name="ConstantName"/>-->
42+
<module name="LocalFinalVariableName"/>
43+
<module name="LocalVariableName"/>
44+
<module name="MemberName"/>
45+
<module name="MethodName"/>
46+
<!--<module name="PackageName"/>-->
47+
<module name="ParameterName"/>
48+
<module name="StaticVariableName"/>
49+
<module name="TypeName"/>
50+
51+
52+
<!-- Checks for imports -->
53+
<!-- See http://checkstyle.sf.net/config_import.html -->
54+
<module name="AvoidStarImport"/>
55+
<module name="IllegalImport"/>
56+
<!-- defaults to sun.* packages -->
57+
<module name="RedundantImport"/>
58+
<module name="UnusedImports">
59+
<property name="processJavadoc" value="true"/>
60+
</module>
61+
62+
63+
<!-- Checks for Size Violations. -->
64+
<!-- See http://checkstyle.sf.net/config_sizes.html -->
65+
<module name="LineLength">
66+
<property name="max" value="120"/>
67+
</module>
68+
<module name="MethodLength">
69+
<property name="max" value="200"/>
70+
</module>
71+
72+
73+
<!-- Checks for whitespace -->
74+
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
75+
<module name="GenericWhitespace"/>
76+
<!--<module name="EmptyForIteratorPad"/>-->
77+
<module name="MethodParamPad"/>
78+
<!--<module name="NoWhitespaceAfter"/>-->
79+
<!--<module name="NoWhitespaceBefore"/>-->
80+
<module name="OperatorWrap"/>
81+
<module name="ParenPad"/>
82+
<module name="TypecastParenPad"/>
83+
<module name="WhitespaceAfter"/>
84+
<module name="WhitespaceAround">
85+
<property name="tokens"
86+
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN,
87+
COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAND, LCURLY, LE, LITERAL_CATCH,
88+
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
89+
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS,
90+
MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST,
91+
SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
92+
</module>
93+
94+
95+
<!-- Modifier Checks -->
96+
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
97+
<module name="ModifierOrder"/>
98+
<module name="RedundantModifier"/>
99+
100+
101+
<!-- Checks for blocks. You know, those { }'s -->
102+
<!-- See http://checkstyle.sf.net/config_blocks.html -->
103+
<module name="AvoidNestedBlocks"/>
104+
<!--module name="EmptyBlock"/-->
105+
<module name="LeftCurly"/>
106+
<!--<module name="NeedBraces"/>-->
107+
<module name="RightCurly"/>
108+
109+
110+
<!-- Checks for common coding problems -->
111+
<!-- See http://checkstyle.sf.net/config_coding.html -->
112+
<!--module name="AvoidInlineConditionals"/-->
113+
<module name="CovariantEquals"/>
114+
<module name="EmptyStatement"/>
115+
<!--<module name="EqualsAvoidNull"/>-->
116+
<module name="EqualsHashCode"/>
117+
<!--module name="HiddenField"/-->
118+
<module name="IllegalInstantiation"/>
119+
<!--module name="InnerAssignment"/-->
120+
<!--module name="MagicNumber"/-->
121+
<!--module name="MissingSwitchDefault"/-->
122+
<!-- <module name="RedundantThrows"/> -->
123+
<module name="SimplifyBooleanExpression"/>
124+
<module name="SimplifyBooleanReturn"/>
125+
126+
<!-- Checks for class design -->
127+
<!-- See http://checkstyle.sf.net/config_design.html -->
128+
<!--module name="DesignForExtension"/-->
129+
<!--<module name="FinalClass"/>-->
130+
<module name="HideUtilityClassConstructor"/>
131+
<!-- <module name="InterfaceIsType"/> -->
132+
<!--module name="VisibilityModifier"/-->
133+
134+
135+
<!-- Miscellaneous other checks. -->
136+
<!-- See http://checkstyle.sf.net/config_misc.html -->
137+
<module name="ArrayTypeStyle"/>
138+
<!--module name="FinalParameters"/-->
139+
<!--module name="TodoComment"/-->
140+
<module name="UpperEll"/>
141+
</module>
142+
</module>

gradle/wrapper/gradle-wrapper.jar

53.4 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Tue Jan 02 10:02:13 CST 2018
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip

0 commit comments

Comments
 (0)