├── .gitignore ├── Jenkinsfile ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── asciidoc └── manual.adoc └── java └── org └── todo ├── Todo.java └── TodoResource.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Eclipse 2 | .project 3 | .classpath 4 | .settings/ 5 | .factorypath 6 | dependency-reduced-pom.xml 7 | pom.xml.versionsBackup 8 | 9 | # IntelliJ 10 | *.iml 11 | *.ipr 12 | *.iws 13 | .idea 14 | bin/ 15 | 16 | # Gradle 17 | .gradle/ 18 | .ivy/ 19 | build/ 20 | 21 | # Maven 22 | target/ 23 | 24 | # TestNG 25 | test-output/ 26 | 27 | # JBoss AS 28 | transaction.log 29 | 30 | # Infinitest configuration 31 | infinitest.filters 32 | 33 | # Logs 34 | *.log 35 | *.log~ 36 | 37 | # Libreoffice leftovers (XLS) 38 | .~lock* 39 | .DS_Store 40 | 41 | atlassian-ide-plugin.xml 42 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | stage 'Compile' 2 | 3 | node { 4 | checkout scm 5 | sh './gradlew clean compileJava' 6 | stash excludes: 'build/', includes: '**', name: 'source' 7 | } 8 | 9 | stage 'Commit Tests' 10 | 11 | node { 12 | echo 'Running Commit Tests' 13 | } 14 | 15 | stage 'Code Quality' 16 | 17 | node { 18 | echo 'Running Static Code Analysis' 19 | } 20 | 21 | stage 'Documentation' 22 | 23 | node { 24 | unstash 'source' 25 | sh './gradlew generateManual' 26 | publishHTML(target: [reportDir:'build/asciidoc/html5', reportFiles: 'manual.html', reportName: 'Manual']) 27 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | dependencies { 6 | classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3' 7 | classpath 'org.asciidoctor:asciidoctorj-screenshot:0.1.1' 8 | } 9 | } 10 | 11 | plugins { 12 | id "de.undercouch.download" version "2.1.0" 13 | } 14 | 15 | // Apply the java plugin to add support for Java 16 | apply plugin: 'war' 17 | 18 | allprojects { 19 | sourceCompatibility = 1.8 20 | targetCompatibility = 1.8 21 | 22 | group = 'org.todo' 23 | version = '1.0-SNAPSHOT' 24 | 25 | repositories { 26 | mavenCentral() 27 | } 28 | } 29 | 30 | dependencies { 31 | providedCompile 'javax:javaee-api:7.0' 32 | } 33 | 34 | tasks.withType(JavaCompile) { 35 | options.encoding = 'UTF-8' 36 | } 37 | 38 | apply plugin: 'org.asciidoctor.gradle.asciidoctor' 39 | 40 | asciidoctor { 41 | sourceDir = file('src/main/asciidoc') 42 | attributes = [ 43 | 'rootdir': "${rootDir}", 44 | 'application-url': 'http://192.168.99.100/' 45 | ] 46 | } 47 | 48 | task generateManual { 49 | dependsOn 'generateJaxRsDocumentation' 50 | finalizedBy asciidoctor 51 | } 52 | 53 | 54 | task downloadFile(type: de.undercouch.gradle.tasks.download.Download) { 55 | src 'https://github.com/sdaschner/jaxrs-analyzer/releases/download/v0.9/jaxrs-analyzer.jar' 56 | dest buildDir 57 | } 58 | 59 | task generateJaxRsDocumentation(type:Exec) { 60 | dependsOn compileJava 61 | 62 | if (!new File("${buildDir}/jaxrs-analyzer.jar").exists()) { 63 | dependsOn downloadFile 64 | } 65 | 66 | workingDir "${buildDir}" 67 | 68 | commandLine 'java', '-jar', 'jaxrs-analyzer.jar', 69 | '-b', 'asciidoc', '-o' , "${buildDir}/todorest.adoc" , "${buildDir}/classes/main" 70 | 71 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lordofthejars/continuous-documentation/3e61e62e1a76b38ee8d9e26d86952827ea9829cd/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Mar 20 19:08:09 CET 2016 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-2.12-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'todo' 2 | 3 | -------------------------------------------------------------------------------- /src/main/asciidoc/manual.adoc: -------------------------------------------------------------------------------- 1 | = Todo Application 2 | Alex Soto 3 | v{project-version} 4 | :source-highlighter: highlightjs 5 | :example-caption!: 6 | :sourcedir: src/main/java 7 | :rootdir: 8 | :application-url: http://192.168.99.100 9 | :icons: font 10 | :experimental: 11 | :toc: left 12 | 13 | This service contains all the information required by `Todo` Application. 14 | 15 | == Installation 16 | 17 | `Todo` application comes in the form of `WAR` file and `Docker` image. 18 | 19 | === Docker 20 | 21 | If you are using Docker you only need to have Docker installed on your machine and execute: 22 | 23 | `docker run -ti -p 80:8000 dockerinpractice/todo` 24 | 25 | For more options or how to run Docker in different platform check https://wwww.docker.com[Docker] 26 | 27 | === WAR 28 | 29 | The application requires only a sever with `JAX-RS` installed. 30 | You can use a *JavaEE* application server like `Wildfly` or `Glassfish` or build yourself a `Jetty` or `Tomcat` with `JAX-RS`. 31 | 32 | IMPORTANT: Our recommendation is to use `Apache TomEE 7` as application server. 33 | 34 | .About Apache TomEE 35 | **** 36 | Apache TomEE is an application server which can be summarized as `Tomcat` + `Java EE`. 37 | You get the best of the both worlds, the simplicity and light of Tomcat and the power of Java EE. 38 | **** 39 | 40 | 41 | == Using Todo application 42 | 43 | Using Todo application is really easy since it is a simple web application with a single page. 44 | 45 | === Ading a new TODO 46 | 47 | For adding a new todo you only need to access to the homepage of the application. 48 | There you will see a panel with an input box where you can type your todo. 49 | 50 | .The TODO landing page 51 | screenshot::{application-url}[name=todo, frame=browser] 52 | 53 | After you've entered the content you can push btn:[Enter] button on your keyboard and message will be recorded on the system. 54 | 55 | [geb] 56 | .... 57 | $("input", class: "edit").value("Learn Jenkins Pipeline") << Keys.ENTER 58 | .... 59 | 60 | .Example of entered TODO 61 | screenshot::[frame=browser] 62 | 63 | And so on and so on .... 64 | 65 | == Technical Manual 66 | 67 | === JAX-RS class 68 | 69 | Just in case you want to know how the REST API looks like you can see the `JAX-RS` endpoint where everything happens. 70 | 71 | [source, java] 72 | .org.todo.TodoResource 73 | ---- 74 | include::{rootdir}/{sourcedir}/org/todo/TodoResource.java[tags=documentation] 75 | ---- 76 | <1> Root endpoint 77 | <2> `GET` http method where all todos are returned 78 | <3> In case of `DELETE`, HTTP `noContent` code is returned. 79 | 80 | == JSON Documentation 81 | 82 | include::{rootDir}/build/todorest.adoc[leveloffset=+2] 83 | 84 | -------------------------------------------------------------------------------- /src/main/java/org/todo/Todo.java: -------------------------------------------------------------------------------- 1 | package org.todo; 2 | 3 | import javax.xml.bind.annotation.XmlRootElement; 4 | 5 | @XmlRootElement(name = "todo") 6 | public class Todo { 7 | 8 | private String todo; 9 | private boolean done; 10 | 11 | public Todo(String todo, boolean done) { 12 | this.todo = todo; 13 | this.done = done; 14 | } 15 | 16 | public String getTodo() { 17 | return todo; 18 | } 19 | 20 | public void setTodo(String todo) { 21 | this.todo = todo; 22 | } 23 | 24 | public boolean isDone() { 25 | return done; 26 | } 27 | 28 | public void setDone(boolean done) { 29 | this.done = done; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/todo/TodoResource.java: -------------------------------------------------------------------------------- 1 | package org.todo; 2 | 3 | import javax.ws.rs.Consumes; 4 | import javax.ws.rs.DELETE; 5 | import javax.ws.rs.GET; 6 | import javax.ws.rs.PUT; 7 | import javax.ws.rs.Path; 8 | import javax.ws.rs.PathParam; 9 | import javax.ws.rs.Produces; 10 | import javax.ws.rs.core.MediaType; 11 | import javax.ws.rs.core.Response; 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | 16 | // tag::documentation[] 17 | @Path("/todo") // <1> 18 | public class TodoResource { 19 | 20 | @GET 21 | @Produces(MediaType.APPLICATION_JSON) 22 | public List getTodos() { // <2> 23 | return getTodosFromDb(); 24 | } 25 | 26 | @PUT 27 | @Path("/{id}") 28 | @Consumes(MediaType.APPLICATION_JSON) 29 | public Response updateTodo(@PathParam("id") String id, Todo todo) { 30 | return Response.ok().build(); 31 | } 32 | 33 | @DELETE 34 | public Response deleteDoneTodos() { // <3> 35 | return Response.noContent().build(); 36 | } 37 | 38 | private java.util.List getTodosFromDb() { 39 | return Arrays.asList(new Todo("Jenkins Pipeline", false)); 40 | } 41 | 42 | } 43 | // end::documentation[] 44 | --------------------------------------------------------------------------------