/projects/cayenne-3.0.1/build-tools/maven-cayenne-doc-plugin/src/main/java/org/apache/cayenne/maven/plugin/confluence/ConfluenceExportMojo.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus · Java · 192 lines · 76 code · 26 blank · 90 comment · 0 complexity · 3e039fee3bd8e36c348ab912af1a7a2d MD5 · raw file

  1. /*****************************************************************
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. 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,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. ****************************************************************/
  19. package org.apache.cayenne.maven.plugin.confluence;
  20. import java.io.File;
  21. import java.net.URL;
  22. import org.apache.maven.plugin.AbstractMojo;
  23. import org.apache.maven.plugin.MojoExecutionException;
  24. import org.apache.maven.plugin.MojoFailureException;
  25. /**
  26. * A goal to export Confluence documentation.
  27. *
  28. *
  29. * @goal confluence-export
  30. */
  31. public class ConfluenceExportMojo extends AbstractMojo {
  32. /**
  33. * The directory to put the exported documentation into
  34. *
  35. * @parameter expression="${project.build.directory}/${confluence.spaceName}"
  36. */
  37. private String outputDirectory;
  38. /**
  39. * The velocity template to use - defaults to loading
  40. * 'doctemplates/default.vm' from the classpath
  41. *
  42. * @parameter
  43. */
  44. private String velocityTemplate;
  45. /**
  46. * The root url to the Confluence instance For example in Cayenne:
  47. * http://cwiki.apache.org/confluence/ is the base URL.
  48. *
  49. * @parameter expression="${confluence.baseUrl}"
  50. * @required
  51. */
  52. private URL baseUrl;
  53. /**
  54. * The name of the confluence space to export
  55. *
  56. * @parameter expression="${confluence.spaceName}"
  57. * @required
  58. */
  59. private String spaceName;
  60. /**
  61. * The page in the space to start with
  62. *
  63. * @parameter expression="${confluence.startPage}"
  64. * @required
  65. */
  66. private String startPage;
  67. /**
  68. * The username to log in as - define it on the commandline via the
  69. * -Dconfluence.userName=user_name option or set the userName and password
  70. * in your ~/.m2/settings.xml file like this;
  71. *
  72. * <pre>
  73. * &lt;profiles&gt;
  74. * &lt;profile&gt;
  75. * &lt;properties&gt;
  76. * &lt;property&gt;
  77. * &lt;name&gt;confluence.userName&lt;/name&gt;
  78. * &lt;value&gt;user name&lt;/value&gt;
  79. * &lt;/property&gt;
  80. * &lt;property&gt;
  81. * &lt;name&gt;confluence.password&lt;/name&gt;
  82. * &lt;value&gt;password&lt;/value&gt;
  83. * &lt;/property&gt;
  84. * &lt;/properties&gt;
  85. * &lt;id&gt;confluence&lt;/id&gt;
  86. * &lt;/profile&gt;
  87. * &lt;/profiles&gt;
  88. * </pre>
  89. *
  90. * @parameter expression="${confluence.userName}"
  91. * @required
  92. */
  93. private String userName;
  94. /**
  95. * The username to log in as - define it on the commandline via the
  96. * -Dconfluence.password=password option
  97. *
  98. * @parameter expression="${confluence.password}"
  99. * @required
  100. */
  101. private String password;
  102. /**
  103. * Worker method.
  104. */
  105. public void execute() throws MojoExecutionException, MojoFailureException {
  106. File thisDir = new File(System.getProperty("user.dir"));
  107. File output = new File(thisDir, outputDirectory);
  108. getLog().info(
  109. "Exporting space '" + spaceName + "' to "
  110. + output.getAbsolutePath());
  111. try {
  112. DocGenerator generator = new DocGenerator(baseUrl.toString(),
  113. spaceName, outputDirectory, startPage, userName, password,
  114. velocityTemplate);
  115. getLog().info(
  116. "Confluence base URL '" + generator.getBaseUrl() + "'");
  117. generator.generateDocs();
  118. } catch (Exception e) {
  119. e.printStackTrace();
  120. throw new MojoExecutionException("Failed to export: " + spaceName
  121. + " from: " + baseUrl, e);
  122. }
  123. }
  124. public String getOutputDirectory() {
  125. return outputDirectory;
  126. }
  127. public void setOutputDirectory(String outputDirectory) {
  128. this.outputDirectory = outputDirectory;
  129. }
  130. public String getVelocityTemplate() {
  131. return velocityTemplate;
  132. }
  133. public void setVelocityTemplate(String velocityTemplate) {
  134. this.velocityTemplate = velocityTemplate;
  135. }
  136. public String getPassword() {
  137. return password;
  138. }
  139. public void setPassword(String password) {
  140. this.password = password;
  141. }
  142. public URL getBaseUrl() {
  143. return baseUrl;
  144. }
  145. public void setBaseUrl(URL rootURL) {
  146. this.baseUrl = rootURL;
  147. }
  148. public String getSpaceName() {
  149. return spaceName;
  150. }
  151. public void setSpaceName(String spaceName) {
  152. this.spaceName = spaceName;
  153. }
  154. public String getStartPage() {
  155. return startPage;
  156. }
  157. public void setStartPage(String startPage) {
  158. this.startPage = startPage;
  159. }
  160. public String getUserName() {
  161. return userName;
  162. }
  163. public void setUserName(String userName) {
  164. this.userName = userName;
  165. }
  166. }