You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2013/09/16 13:28:48 UTC
svn commit: r1523595 - in /httpcomponents/project-release-tools/trunk: ./
buildSrc/src/main/groovy/
Author: olegk
Date: Mon Sep 16 11:28:48 2013
New Revision: 1523595
URL: http://svn.apache.org/r1523595
Log:
Added site generation tasks
Added:
httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnRevert.groovy
- copied, changed from r1522479, httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnStatus.groovy
Removed:
httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/HCProject.groovy
httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/HCSitePlugin.groovy
httpcomponents/project-release-tools/trunk/site.gradle
Modified:
httpcomponents/project-release-tools/trunk/build.gradle
httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/Release.groovy
httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnGet.groovy
httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnScheduleForAddition.groovy
httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnStatus.groovy
httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnUpdate.groovy
Modified: httpcomponents/project-release-tools/trunk/build.gradle
URL: http://svn.apache.org/viewvc/httpcomponents/project-release-tools/trunk/build.gradle?rev=1523595&r1=1523594&r2=1523595&view=diff
==============================================================================
--- httpcomponents/project-release-tools/trunk/build.gradle (original)
+++ httpcomponents/project-release-tools/trunk/build.gradle Mon Sep 16 11:28:48 2013
@@ -548,3 +548,223 @@ CopySpec sources(File dir, Pom pom, Stri
}
}
+
+/////////////////////////// Website publishing ////////////////////////////////
+
+URI websiteURI = new URI(HC_PROJECT_SITE)
+
+task checkoutMainWebsite(type: SvnGet) {
+ group = 'Repository'
+ description = "Checks out main website source from '${websiteURI}'."
+ repo = websiteURI
+}
+
+task updateMainWebsite(type: SvnUpdate, dependsOn: checkoutMainWebsite) {
+ group = 'Repository'
+ description = "Update main website source from '${websiteURI}'."
+ repo = checkoutMainWebsite.repo
+}
+
+task generateMainWebsite(dependsOn: checkoutMainWebsite) {
+ group = 'Website generation'
+ description = "Generates main website content."
+ inputs.files fileTree(dir:checkoutMainWebsite.localDir, excludes:['**/target/**','**/.svn/**'])
+ outputs.files fileTree(dir:checkoutMainWebsite.localDir, includes:['**/target/site/**'])
+ doLast {
+ mvn.exec(checkoutMainWebsite.localDir, 'clean', 'install', 'site')
+ }
+}
+
+task checkoutFullWebsite(dependsOn: checkoutMainWebsite) {
+ group = 'Repository'
+ description = "Checks out full website source including published releases."
+}
+
+task generateFullWebsite(dependsOn: generateMainWebsite) {
+ group = 'Website generation'
+ description = "Generates full website content including published releases."
+}
+
+List<URI> uris = HC_PUBLISHED_RELEASES ?
+ HC_PUBLISHED_RELEASES.split(/[ \t]+/).collect { new URI(it) } : null
+
+if (uris) {
+
+ uris.eachWithIndex { URI uri, int idx ->
+
+ task "checkoutPublishedRelease${idx + 1}" (type: SvnGet) {
+ group = 'Repository'
+ description = "Checks out published release from '${uri}'."
+ repo = uri
+ }
+
+ task "generatePublishedRelease${idx + 1}" {
+ group = 'Website generation'
+ description = "Generates published release content from '${uri}'."
+ SvnGet svnget = tasks["checkoutPublishedRelease${idx + 1}"]
+ dependsOn checkoutMainWebsite, svnget
+ inputs.files fileTree(dir: svnget.localDir, excludes:['**/target/**','**/.svn/**'])
+ outputs.files fileTree(dir :svnget.localDir, includes:['**/target/site/**'])
+ doLast {
+ // Rewrite POM's parent
+ Pom mainWebsite = mvn.parsePom(checkoutMainWebsite.localDir)
+ Release.rewritePomParent(svnget.localDir, mainWebsite)
+ // Generate content
+ mvn.exec(svnget.localDir, 'clean', 'site')
+ // Revert
+ Svn.revert(svnget.localDir)
+ }
+ }
+
+ }
+
+ checkoutFullWebsite.dependsOn {
+ tasks.findAll { Task task -> task.name.startsWith('checkoutPublishedRelease') }
+ }
+
+ generateFullWebsite.dependsOn {
+ tasks.findAll { Task task -> task.name.startsWith('generatePublishedRelease') }
+ }
+
+}
+
+if (!HC_SITE_STAGING) {
+ throw InvalidUserDataException("HC_SITE_STAGING not set")
+}
+
+task checkoutSiteStage(type: SvnGet) {
+ group = 'Repository'
+ description = "Checks out website content from ${HC_SITE_STAGING} to a local stage."
+ repo = new URI(HC_SITE_STAGING)
+}
+
+task updateSiteStage(type: SvnUpdate, dependsOn: checkoutSiteStage) {
+ group = 'Repository'
+ description = "Update website content stage from ${HC_SITE_STAGING}."
+ repo = checkoutSiteStage.repo
+}
+
+task siteStage(dependsOn: [checkoutSiteStage, generateFullWebsite]) {
+ group = 'Website generation'
+ description = "Copies generated website content to local stage."
+ doLast {
+ tasks.withType(SvnGet) { SvnGet releaseCheckout ->
+ if (releaseCheckout.name.startsWith('checkoutPublishedRelease')) {
+ Pom releasePom = Mvn.parsePom(releaseCheckout.localDir)
+ String releaseSeries = "${releasePom.artifactId}-${releasePom.major}.${releasePom.minor}.x"
+ String releaseStaging = "${checkoutSiteStage.localDir}/${releaseSeries}"
+ println("Copying content of release ${releasePom.artifactId}:${releasePom.version} to ${releaseStaging}")
+ copy {
+ into "${checkoutSiteStage.localDir}/${releaseSeries}"
+ with siteContent(releaseCheckout.localDir)
+ }
+ releasePom.modules.each { String submodule ->
+ println("Copying content of release module ${submodule}:${releasePom.version} to ${releaseStaging}/${submodule}")
+ copy {
+ into "${checkoutSiteStage.localDir}/${releaseSeries}/${submodule}"
+ with siteContent(file("${releaseCheckout.localDir}/${submodule}"))
+ }
+ }
+ fixLinks(releasePom, file(releaseStaging))
+ rewriteSiteCss(releasePom, file(releaseStaging))
+ }
+ }
+ Pom websitePom = Mvn.parsePom(checkoutMainWebsite.localDir)
+ println("Copying content of ${websitePom.artifactId}:${websitePom.version} to ${checkoutSiteStage.localDir}")
+ copy {
+ into checkoutSiteStage.localDir
+ with siteContent(checkoutMainWebsite.localDir)
+ }
+ }
+}
+
+task revertSiteStage(type: SvnRevert, dependsOn: checkoutSiteStage) {
+ group = 'Repository'
+ description = "Revert changes to website content stage."
+ repo = checkoutSiteStage.repo
+}
+
+task commitSiteStage(dependsOn: checkoutSiteStage) {
+ group = 'Repository'
+ description = "Commit changes from website content stage to ${HC_SITE_STAGING}."
+ doLast {
+ console.println("Please enter commit message:")
+ String message = console.readLine()
+ if (message) {
+ message = "Updated project website"
+ }
+ Svn.commit(checkoutSiteStage.localDir, message)
+ }
+}
+
+/////////////////////////// Helper utilities //////////////////////////////////
+
+void fixLinks(Pom pom, File dstDir) {
+
+ // Deal with crappy links generated by Maven Site Plugin
+ project.fileTree(dir: dstDir, include: '*.html').each {
+ File f ->
+ Html.rewriteLinks(f, { URI href, String localName ->
+ if (!href.isAbsolute()) {
+ def m1 = href.path =~ /^..(\/..\/scp:\/people.apache.org\/www)?\/hc.apache.org\//
+ if (m1.find()) {
+ return new URI(m1.replaceFirst('../'))
+ }
+ }
+ return href
+ })
+ }
+
+ pom.modules.each { String submodule ->
+ project.fileTree(dir: new File(dstDir, submodule), include: '*.html').each {
+ File f ->
+ Html.rewriteLinks(f, { URI href, String localName ->
+ if (!href.isAbsolute()) {
+ def m1 = href.path =~ /^..\/..(\/..\/scp:\/people.apache.org\/www)?\/hc.apache.org\//
+ if (m1.find()) {
+ return new URI(m1.replaceFirst('../../'))
+ }
+ if (href.path == '../images/logos/httpcomponents.png') {
+ return new URI('../../images/logos/httpcomponents.png')
+ }
+ }
+ return href
+ })
+ }
+ }
+
+}
+
+void rewriteSiteCss(Pom pom, File dstDir) {
+ File siteCss = new File(dstDir, 'css/site.css')
+ if (siteCss.exists()) {
+ siteCss.withWriter { Writer w ->
+ w << '@import url("../../css/hc-maven.css");'
+ }
+ }
+ pom.modules.each { String submodule ->
+ File moduleDstDir = new File(dstDir, submodule)
+ File moduleSiteCss = new File(moduleDstDir, 'css/site.css')
+ if (moduleSiteCss.exists()) {
+ moduleSiteCss.withWriter { Writer w ->
+ w << '@import url("../../../css/hc-maven.css");'
+ }
+ }
+ }
+
+}
+
+/////////////////////////// Copy specs ////////////////////////////////////////
+
+CopySpec siteContent(File dir) {
+ copySpec {
+ from ("${dir}/target/site") {
+ exclude '**/*.html'
+ }
+ from ("${dir}/target/site") {
+ include '**/*.html'
+ filter(Line.filter())
+ }
+ }
+}
+
Modified: httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/Release.groovy
URL: http://svn.apache.org/viewvc/httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/Release.groovy?rev=1523595&r1=1523594&r2=1523595&view=diff
==============================================================================
--- httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/Release.groovy (original)
+++ httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/Release.groovy Mon Sep 16 11:28:48 2013
@@ -27,9 +27,6 @@
import org.apache.maven.artifact.versioning.ArtifactVersion
import org.apache.maven.artifact.versioning.DefaultArtifactVersion
-import org.gradle.api.DefaultTask
-import org.gradle.api.InvalidUserDataException
-import org.gradle.api.tasks.TaskAction
import org.jdom2.Document
import org.jdom2.Element
import org.jdom2.Namespace
@@ -153,4 +150,46 @@ class Release {
}
}
+ static void rewritePomParent(File dir, Pom newParent) {
+ File pomFile = new File(dir, 'pom.xml')
+ SAXBuilder parser = new SAXBuilder()
+ Document doc = parser.build(pomFile)
+
+ Namespace ns = Namespace.getNamespace("http://maven.apache.org/POM/4.0.0")
+ Element rootEl = doc.rootElement
+ Element parentEl = rootEl.getChild('parent', ns)
+ if (parentEl != null) {
+
+ Element groupIdEl = parentEl.getChild('groupId', ns)
+ if (!groupIdEl) {
+ groupIdEl = new Element('groupId', ns)
+ parentEl.addContent(groupIdEl)
+ }
+ groupIdEl.setText(newParent.groupId)
+
+ Element artifactIdEl = parentEl.getChild('artifactId', ns)
+ if (!artifactIdEl) {
+ artifactIdEl = new Element('artifactId', ns)
+ parentEl.addContent(artifactIdEl)
+ }
+ artifactIdEl.setText(newParent.artifactId)
+
+ Element versionEl = parentEl.getChild('version', ns)
+ if (!versionEl) {
+ versionEl = new Element("version", ns);
+ parentEl.addContent(versionEl)
+ }
+ versionEl.setText(newParent.version)
+
+ parentEl.removeChild('relativePath', ns)
+
+ Format format = Format.getRawFormat()
+ format.lineSeparator = Line.DELIM
+ XMLOutputter xmlOutputter = new XMLOutputter(format)
+ pomFile.withWriter('UTF-8') { Writer writer ->
+ xmlOutputter.output(doc, writer)
+ }
+ }
+ }
+
}
Modified: httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnGet.groovy
URL: http://svn.apache.org/viewvc/httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnGet.groovy?rev=1523595&r1=1523594&r2=1523595&view=diff
==============================================================================
--- httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnGet.groovy (original)
+++ httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnGet.groovy Mon Sep 16 11:28:48 2013
@@ -33,7 +33,6 @@ class SvnGet extends SvnContentTask {
void get() {
if (repo.absolute) {
if (!localDir.exists()) {
- println("Checking out from ${repo}")
Svn.checkout(repo, localDir)
}
}
Copied: httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnRevert.groovy (from r1522479, httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnStatus.groovy)
URL: http://svn.apache.org/viewvc/httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnRevert.groovy?p2=httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnRevert.groovy&p1=httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnStatus.groovy&r1=1522479&r2=1523595&rev=1523595&view=diff
==============================================================================
--- httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnStatus.groovy (original)
+++ httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnRevert.groovy Mon Sep 16 11:28:48 2013
@@ -27,13 +27,12 @@
import org.gradle.api.tasks.TaskAction
-class SvnStatus extends SvnContentTask {
+class SvnRevert extends SvnContentTask {
@TaskAction
- void status() {
+ void revert() {
if (localDir.exists()) {
- println("Local changes of ${repo}")
- Svn.status(localDir)
+ Svn.revert(localDir)
}
}
Modified: httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnScheduleForAddition.groovy
URL: http://svn.apache.org/viewvc/httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnScheduleForAddition.groovy?rev=1523595&r1=1523594&r2=1523595&view=diff
==============================================================================
--- httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnScheduleForAddition.groovy (original)
+++ httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnScheduleForAddition.groovy Mon Sep 16 11:28:48 2013
@@ -32,7 +32,6 @@ class SvnScheduleForAddition extends Svn
@TaskAction
void schedule() {
if (repo.absolute) {
- println("Scheduling changes for addition to ${repo}")
Svn.scheduleForAddition(localDir)
}
}
Modified: httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnStatus.groovy
URL: http://svn.apache.org/viewvc/httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnStatus.groovy?rev=1523595&r1=1523594&r2=1523595&view=diff
==============================================================================
--- httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnStatus.groovy (original)
+++ httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnStatus.groovy Mon Sep 16 11:28:48 2013
@@ -32,7 +32,6 @@ class SvnStatus extends SvnContentTask {
@TaskAction
void status() {
if (localDir.exists()) {
- println("Local changes of ${repo}")
Svn.status(localDir)
}
}
Modified: httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnUpdate.groovy
URL: http://svn.apache.org/viewvc/httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnUpdate.groovy?rev=1523595&r1=1523594&r2=1523595&view=diff
==============================================================================
--- httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnUpdate.groovy (original)
+++ httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/SvnUpdate.groovy Mon Sep 16 11:28:48 2013
@@ -31,7 +31,6 @@ class SvnUpdate extends SvnContentTask {
@TaskAction
void update() {
- println("Updating local checkout of ${repo}")
if (localDir.exists()) {
Svn.update(localDir)
}