PageRenderTime 24ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/maven-scalate-plugin/src/main/java/org/fusesource/scalate/maven/ConfExportMojo.scala

http://github.com/scalate/scalate
Scala | 150 lines | 95 code | 26 blank | 29 comment | 1 complexity | 4ae61b5e67b7a315076526f9f7452654 MD5 | raw file
  1. /**
  2. * Copyright (C) 2009-2011 the original author or authors.
  3. * See the notice.md file distributed with this work for additional
  4. * information regarding copyright ownership.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.fusesource.scalate.maven
  19. import collection.JavaConversions._
  20. import java.{util => ju}
  21. import java.io.File
  22. import java.net.{URLClassLoader, URL}
  23. import org.apache.maven.plugin.AbstractMojo
  24. import org.apache.maven.project.MavenProject
  25. import org.scala_tools.maven.mojo.annotations._
  26. /**
  27. * This goal exports confluence mark-up out of a Confluence wiki and adds the files to
  28. * the resource target for Scalate to use in generating the site. Its guts are
  29. * copied from the ConfluenceExport command. This should be made more
  30. * modular.
  31. *
  32. * @author Eric Johnson, Fintan Bolton
  33. */
  34. @goal("confexport")
  35. @phase("generate-resources")
  36. @requiresProject
  37. @requiresDependencyResolution("test")
  38. class ConfExportMojo extends AbstractMojo {
  39. @parameter
  40. @expression("${project}")
  41. @readOnly
  42. @required
  43. var project: MavenProject = _
  44. @parameter
  45. @description("Confluence base URL")
  46. @expression("${scalate.url}")
  47. var url: String = "https://cwiki.apache.org/confluence/"
  48. @parameter
  49. @required
  50. @description("The confluence space key")
  51. @expression("${scalate.space}")
  52. var space: String = "XB"
  53. @parameter
  54. @description("The directory where the exported pages will land.")
  55. @expression("${project.build.directory}/${project.build.finalName}")
  56. var target: File = _
  57. @parameter
  58. @description("The Confluence username to access the wiki.")
  59. @expression("${scalate.user}")
  60. var user : String = _
  61. @parameter
  62. @description("The password used to access the wiki.")
  63. @expression("${scalate.password}")
  64. var password : String = _
  65. @parameter
  66. @alias("allow-spaces")
  67. @description("Whether to allow spaces in filenames (boolean)")
  68. var allow_spaces: String = "false"
  69. @parameter
  70. @description("The format of the downloaded pages. Possible values are: page and conf")
  71. var format: String = "page"
  72. @parameter
  73. @alias("target-db")
  74. @description("Generate a link database for DocBook.")
  75. var target_db: String = "false"
  76. @parameter
  77. @description("Disable the confexport goal.")
  78. @expression("${scalate.confexport.skip}")
  79. var skip: String = "false"
  80. @parameter
  81. @description("The test project classpath elements.")
  82. @expression("${project.testClasspathElements}")
  83. var testClassPathElements: ju.List[_] = _
  84. def execute() {
  85. if (skip.toBoolean) { return }
  86. //
  87. // Lets use project's classpath when we run the site gen tool
  88. //
  89. val urls: Array[URL] = testClassPathElements.map { d =>
  90. new File(d.toString).toURI.toURL
  91. }.toArray
  92. getLog.debug("Found project class loader URLs: " + urls.toList)
  93. val loader = new URLClassLoader(urls, Thread.currentThread.getContextClassLoader)
  94. val oldLoader = Thread.currentThread.getContextClassLoader
  95. Thread.currentThread.setContextClassLoader(loader)
  96. try {
  97. // Structural Typing FTW (avoids us doing manual reflection)
  98. type ConfluenceExport = {
  99. var url: String
  100. var space: String
  101. var target: File
  102. var user: String
  103. var password: String
  104. var allow_spaces: Boolean
  105. var format: String
  106. var target_db: Boolean
  107. def execute(p: String => Unit): AnyRef
  108. }
  109. val className = "org.fusesource.scalate.tool.commands.ConfluenceExport"
  110. val exporter = loader.loadClass(className).newInstance.asInstanceOf[ConfluenceExport]
  111. exporter.url = this.url
  112. exporter.space = this.space
  113. exporter.target = this.target
  114. exporter.user = this.user
  115. exporter.password = this.password
  116. exporter.allow_spaces = this.allow_spaces.toBoolean
  117. exporter.format = this.format
  118. exporter.target_db = this.target_db.toBoolean
  119. exporter.execute(value => getLog.info(value) )
  120. } finally {
  121. Thread.currentThread.setContextClassLoader(oldLoader)
  122. }
  123. }
  124. }