@@ -24,7 +24,8 @@ apply plugin: 'com.github.sherter.google-java-format'
2424
2525group = " com.google.api"
2626archivesBaseName = " api-common"
27- version = " 0.1.0"
27+
28+ project. version = new File (" version.txt" ). text. trim()
2829
2930sourceCompatibility = 1.7
3031targetCompatibility = 1.7
@@ -69,6 +70,10 @@ dependencies {
6970 libraries. commons
7071}
7172
73+ clean. doFirst {
74+ delete ' tmp_gh-pages/'
75+ }
76+
7277jacocoTestReport {
7378 reports {
7479 xml. enabled true
@@ -264,3 +269,47 @@ tasks.verifyGoogleJavaFormat {
264269 exclude ' build/**'
265270}
266271test. dependsOn verifyGoogleJavaFormat
272+
273+ // Release
274+ // =======
275+
276+ task checkOutGhPages {
277+ if (! new File (' tmp_gh-pages' ). exists()) {
278+ exec {
279+ commandLine ' git' , ' clone' , ' --branch' , ' gh-pages' ,
280+ ' --single-branch' , ' https://github.com/googleapis/api-common-java/' , ' tmp_gh-pages'
281+ }
282+ }
283+ }
284+
285+ task copyFilesToGhPages {
286+ dependsOn ' checkOutGhPages'
287+ dependsOn ' javadoc'
288+ doLast {
289+ def newSiteDirPath = ' tmp_gh-pages/' + project. version + ' /apidocs/'
290+ new File (newSiteDirPath). mkdirs()
291+ copy {
292+ from ' build/docs/javadoc'
293+ into newSiteDirPath
294+ }
295+ copy {
296+ from ' README.md'
297+ into ' tmp_gh-pages'
298+ rename { filename -> filename. replace ' README' , ' index' }
299+ }
300+ }
301+ }
302+
303+ task createApiDocsRedirect {
304+ dependsOn ' copyFilesToGhPages'
305+ doLast {
306+ def template = new File (' templates/apidocs_index.html.template' ). text
307+ def outputContent = template. replace(' {{siteVersion}}' , project. version)
308+ new File (' tmp_gh-pages/apidocs/index.html' ). write(outputContent)
309+ }
310+ }
311+
312+ // Regenerates the gh-pages branch under tmp_gh-pages, which must be committed separately
313+ task updateDocsWithCurrentVersion {
314+ dependsOn ' createApiDocsRedirect'
315+ }
0 commit comments