task bumpReadmeVersion {
    doLast {
        // README.md
        ant.replaceregexp(match: "$projectPreviousPublishedVersion", replace: "$version", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: '.',                              includes: 'README.md')
            fileset(dir: './picocli-codegen/',             includes: 'README.adoc')
            fileset(dir: './picocli-groovy/',              includes: 'README.md')
            fileset(dir: './picocli-shell-jline2/',        includes: 'README.md')
            fileset(dir: './picocli-shell-jline3/',        includes: 'README.md')
            fileset(dir: './picocli-spring-boot-starter/', includes: 'README.md')
            fileset(dir: './picocli-examples/annotation-processing/') {
                include(name: '**/pom.xml')
                include(name: '**/build.gradle')
            }
            fileset(dir: './picocli-examples/generate-man-pages/') {
                include(name: '**/pom.xml')
                include(name: '**/build.gradle')
            }
            //fileset(dir: './picocli-examples/src/main/groovy/', includes: '**/*.groovy')
        }
    }
}
task bumpVersion {
    doLast {
        ant.replaceregexp(match: "$projectPreviousVersionRegex", replace: "$version", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'src/main/java/picocli', includes: 'CommandLine.java')
            fileset(dir: 'src/test/java/picocli', includes: 'CommandLineTest.java')
            fileset(dir: 'src/main/java/picocli', includes: 'AutoComplete.java')
            fileset(dir: 'src/test/java/picocli', includes: 'AutoCompleteTest.java')
            fileset(dir: 'picocli-codegen/src/main/java/picocli/codegen/aot/graalvm', includes: 'DynamicProxyConfigGenerator.java')
            fileset(dir: 'picocli-codegen/src/main/java/picocli/codegen/aot/graalvm', includes: 'JniConfigGenerator.java')
            fileset(dir: 'picocli-codegen/src/main/java/picocli/codegen/aot/graalvm', includes: 'ReflectionConfigGenerator.java')
            fileset(dir: 'picocli-codegen/src/main/java/picocli/codegen/aot/graalvm', includes: 'ResourceConfigGenerator.java')
            fileset(dir: 'picocli-codegen/src/main/java/picocli/codegen/docgen/manpage', includes: 'ManPageGenerator.java')
        }
        ant.replaceregexp(match: "version $projectPreviousVersionRegex", replace: "version $version", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'src/test/java/picocli', includes: 'AutoCompleteTest.java')
        }
        // Doc header
        ant.replaceregexp(match: ":revnumber: $projectPreviousVersionRegex", replace: ":revnumber: $version", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
            fileset(dir: 'docs', includes: 'quick-guide.adoc')
            fileset(dir: 'docs', includes: 'autocomplete.adoc')
            fileset(dir: 'docs', includes: 'picocli-programmatic-api.adoc')
        }
        // Annotation Processor section
        ant.replaceregexp(match: ":picocli-codegen:$projectPreviousVersionRegex", replace: ":picocli-codegen:$version", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
        }
        // Groovy section
        ant.replaceregexp(match: ":picocli-groovy:$projectPreviousVersionRegex", replace: ":picocli-groovy:$version", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
        }
        // Spring Boot section
        ant.replaceregexp(match: ":picocli-spring-boot-starter:$projectPreviousVersionRegex", replace: ":picocli-spring-boot-starter:$version", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
        }
        // Downloads section, Gradle
        ant.replaceregexp(match: ":picocli:$projectPreviousVersionRegex", replace: ":picocli:$version", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
        }
        // Downloads section, Maven
        ant.replaceregexp(match: "<version>$projectPreviousVersionRegex</version>", replace: "<version>$version</version>", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
        }
        // Downloads section, SBT
        ant.replaceregexp(match: "\"picocli\" % \"$projectPreviousVersionRegex\"", replace: "\\\"picocli\\\" % \\\"$version\\\"", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
        }
        // Downloads section, Ivy
        ant.replaceregexp(match: "rev=\"$projectPreviousVersionRegex\"", replace: "rev=\\\"$version\\\"", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
        }
        // Downloads section, Grape
        ant.replaceregexp(match: "module='picocli', version=\'$projectPreviousVersionRegex\'\\)", replace: "module='picocli', version=\'$version\')", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
        }
        // Downloads section, Leiningen
        ant.replaceregexp(match: "info.picocli/picocli \"$projectPreviousVersionRegex\"", replace: "info.picocli/picocli \"$version\"", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
        }
        // Downloads section, Buildr
        ant.replaceregexp(match: "info.picocli:picocli:jar:$projectPreviousVersionRegex", replace: "info.picocli:picocli:jar:$version", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
        }
        // Downloads section, Source
        ant.replaceregexp(match: "https://github.com/remkop/picocli/blob/$projectPreviousVersionRegex/", replace: "https://github.com/remkop/picocli/blob/$version/", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
        }
        // Running the Application and Packaging sections
        ant.replaceregexp(match: "picocli-${projectPreviousVersionRegex}.jar", replace: "picocli-${version}.jar", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
            fileset(dir: 'docs', includes: 'quick-guide.adoc')
        }
        ant.replaceregexp(match: releaseDatePreviousRegex, replace: releaseDate, flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'docs', includes: 'index.adoc')
            fileset(dir: 'docs', includes: 'quick-guide.adoc')
            fileset(dir: 'docs', includes: 'autocomplete.adoc')
            fileset(dir: 'docs', includes: 'picocli-programmatic-api.adoc')
            fileset(dir: 'picocli-codegen', includes: 'README.adoc')
        }
    }
}
task copyCodeGenDocs(type: Copy) {
    from('build/docs/man/') { include 'index.html' }
    from('picocli-codegen/build/docs/html5/') { include '*.html' }
    into 'docs/man'
}
task copyDocs(type: Copy) {
    dependsOn(copyCodeGenDocs)
    from('build/docs/')
    into 'docs'
}

/*
Release procedure:
1. edit version numbers: remove -SNAPSHOT classifier; edit releaseDate
2. ./gradlew bumpVersion
3. check modified files
4. ./gradlew clean build
5. ./gradlew copyDocs
6. update RELEASE-NOTES.md
7. ./gradlew bumpReadmeVersion
7a update README.md (latest version, release notes)
8. (in new cmd prompt session) cd picocli-legacy-tests ^ set JAVA_HOME=C:\apps\jdk1.5.0_22 ^ gradlew clean build --no-daemon
9. commit -m "Release picocli version ..."
10. tag v$version
11 ./gradlew publishReleasePublicationToSonatypeRepository - creates a Sonatype staging repository, and uploads artifacts
12. Close the Sonatype info/picocli staging repo:
  a. Manually: Log in to https://oss.sonatype.org/ and in the menu on the left, select Staging repositories.
     Click the close button in the GUI and watch progress in the
  b. Automatically with the codearte.nexus-staging plugin:
     ./gradlew closeAndReleaseRepository

13. edit version numbers: increase minor version and add -SNAPSHOT classifier
14. ./gradlew bumpVersion
15. check modified files
16. commit -m "Prepare for next development cycle"
17. push (make sure that Push Tags is checked)

18. Log in to GitHub, go to https://github.com/remkop/picocli/releases
19. Click the new tag, click Edit button, update title and release notes (copy from RELEASE-NOTES.md)
20. Upload picocli-$version.jar and picocli-all$version.zip to GitHub


(When releasing from branch)
25. Switch to master
26. cherry-pick the "Release picocli version ..." commit
27. gradlew bumpVersion
28. check modified files
29. commit -m "Update master for next development cycle after release x.x (from branch x.x)"
*/
