PageRenderTime 25ms CodeModel.GetById 18ms app.highlight 4ms RepoModel.GetById 1ms 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 */
 18package org.fusesource.scalate.maven
 19
 20import collection.JavaConversions._
 21
 22import java.{util => ju}
 23import java.io.File
 24import java.net.{URLClassLoader, URL}
 25
 26import org.apache.maven.plugin.AbstractMojo
 27import org.apache.maven.project.MavenProject
 28
 29import org.scala_tools.maven.mojo.annotations._
 30
 31/**
 32 * This goal exports confluence mark-up out of a Confluence wiki and adds the files to 
 33 * the resource target for Scalate to use in generating the site. Its guts are 
 34 * copied from the ConfluenceExport command. This should be made more 
 35 * modular.
 36 *
 37 * @author Eric Johnson, Fintan Bolton
 38 */
 39@goal("confexport")
 40@phase("generate-resources")
 41@requiresProject
 42@requiresDependencyResolution("test")
 43class ConfExportMojo extends AbstractMojo {
 44  @parameter
 45  @expression("${project}")
 46  @readOnly
 47  @required
 48  var project: MavenProject = _
 49
 50  @parameter
 51  @description("Confluence base URL")
 52  @expression("${scalate.url}")
 53  var url: String = "https://cwiki.apache.org/confluence/"
 54
 55  @parameter
 56  @required
 57  @description("The confluence space key")
 58  @expression("${scalate.space}")
 59  var space: String = "XB"
 60
 61  @parameter
 62  @description("The directory where the exported pages will land.")
 63  @expression("${project.build.directory}/${project.build.finalName}")
 64  var target: File = _
 65  
 66  @parameter
 67  @description("The Confluence username to access the wiki.")
 68  @expression("${scalate.user}")
 69  var user : String = _
 70
 71  @parameter
 72  @description("The password used to access the wiki.")
 73  @expression("${scalate.password}")
 74  var password : String = _
 75
 76  @parameter
 77  @alias("allow-spaces")
 78  @description("Whether to allow spaces in filenames (boolean)")
 79  var allow_spaces: String = "false"
 80  
 81  @parameter
 82  @description("The format of the downloaded pages. Possible values are: page and conf")
 83  var format: String = "page"
 84
 85  @parameter
 86  @alias("target-db")
 87  @description("Generate a link database for DocBook.")
 88  var target_db: String = "false"
 89
 90  @parameter
 91  @description("Disable the confexport goal.")
 92  @expression("${scalate.confexport.skip}")
 93  var skip: String = "false"
 94
 95  @parameter
 96  @description("The test project classpath elements.")
 97  @expression("${project.testClasspathElements}")
 98  var testClassPathElements: ju.List[_] = _
 99
100  def execute() {
101
102    if (skip.toBoolean) { return }
103
104    //
105    // Lets use project's classpath when we run the site gen tool
106    //
107    val urls: Array[URL] = testClassPathElements.map { d =>
108      new File(d.toString).toURI.toURL
109    }.toArray
110
111    getLog.debug("Found project class loader URLs: " + urls.toList)
112    val loader = new URLClassLoader(urls, Thread.currentThread.getContextClassLoader)
113
114    val oldLoader = Thread.currentThread.getContextClassLoader
115    Thread.currentThread.setContextClassLoader(loader)
116    try {
117      
118      // Structural Typing FTW (avoids us doing manual reflection)
119      type ConfluenceExport = {
120        var url: String
121        var space: String
122        var target: File
123        var user: String
124        var password: String
125        var allow_spaces: Boolean
126        var format: String
127        var target_db: Boolean
128        def execute(p: String => Unit): AnyRef 
129      }
130
131      val className = "org.fusesource.scalate.tool.commands.ConfluenceExport"
132      val exporter = loader.loadClass(className).newInstance.asInstanceOf[ConfluenceExport]
133
134      exporter.url = this.url
135      exporter.space = this.space
136      exporter.target = this.target
137      exporter.user = this.user
138      exporter.password = this.password
139      exporter.allow_spaces = this.allow_spaces.toBoolean
140      exporter.format = this.format
141      exporter.target_db = this.target_db.toBoolean
142      exporter.execute(value => getLog.info(value) )
143
144    } finally {
145      Thread.currentThread.setContextClassLoader(oldLoader)
146    }
147
148  }
149
150}