View Javadoc
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.maven.plugins.artifact.buildinfo;
20  
21  import java.io.File;
22  import java.io.IOException;
23  
24  import org.codehaus.plexus.util.FileUtils;
25  
26  /**
27   * Test class to update src/site/apt/plugin-issues.apt with content extracted from
28   * src/main/resources/org/apache/maven/plugins/artifact/buildinfo/not-reproducible-plugins.properties
29   */
30  public class NotReproduciblePluginsDocumentationTest {
31      private static final String LS = System.lineSeparator();
32      private static final String DELIMITER = "~~ content generated by NotReproduciblePluginsDocumentationTest";
33  
34      public void testBasic() throws IOException {
35          File pluginIssuesApt = new File("src/site/apt/plugin-issues.apt");
36          String content = FileUtils.fileRead(pluginIssuesApt, "UTF-8");
37          content = content.substring(0, content.indexOf(DELIMITER) + DELIMITER.length());
38  
39          StringBuilder sb = new StringBuilder(content);
40          sb.append(LS);
41          sb.append(
42                  "*---------+-------------------------------------------------------------------+-------+--------------+"
43                          + LS);
44          sb.append(
45                  "|  | <<plugin>>                                                 | <<minimum version>> | <<comments>>");
46          String groupId = null;
47          for (String line : FileUtils.loadFile(
48                  new File(
49                          "src/main/resources/org/apache/maven/plugins/artifact/buildinfo/not-reproducible-plugins.properties"))) {
50              if (!line.startsWith("#")) {
51                  sb.append(LS
52                          + "*--------+--------------------------------------------------------------------+-------+--------------+"
53                          + LS);
54                  int index = line.indexOf('=');
55                  String plugin = line.substring(0, index);
56                  String status = line.substring(index + 1);
57  
58                  index = plugin.indexOf('+');
59                  if (index < 0) {
60                      groupId = "org.apache.maven.plugins";
61                      sb.append("| org.apache.maven.plugins | {{{/plugins/" + plugin + "/}" + plugin + "}} ");
62                  } else {
63                      groupId = plugin.substring(0, index);
64                      plugin = plugin.substring(index + 1);
65                      sb.append("| " + groupId + " | " + plugin + " ");
66                  }
67                  if (status.startsWith("fail:")) {
68                      sb.append("| - | no fixed release available, see {{{" + status.substring(5) + "}reference}}");
69                  } else {
70                      sb.append("| " + status + " | ");
71                  }
72                  continue;
73              }
74              if (groupId == null) {
75                  continue;
76              }
77              sb.append(line.substring(1));
78          }
79          sb.append(LS
80                  + "*----------+------------------------------------------------------------------+-------+--------------+"
81                  + LS);
82  
83          FileUtils.fileWrite(pluginIssuesApt, "UTF-8", sb.toString());
84      }
85  }