View Javadoc
1   package org.apache.maven.plugins.artifact.buildinfo;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.io.IOException;
24  
25  import org.codehaus.plexus.util.FileUtils;
26  
27  /**
28   * Test class to update src/site/apt/plugin-issues.apt with content extracted from
29   * src/main/resources/org/apache/maven/plugins/artifact/buildinfo/not-reproducible-plugins.properties
30   */
31  public class NotReproduciblePluginsDocumentationTest
32  {
33      private static final String LS = System.lineSeparator();
34      private static final String DELIMITER = "~~ content generated by NotReproduciblePluginsDocumentationTest";
35  
36      public void testBasic() throws IOException
37      {
38          File pluginIssuesApt = new File( "src/site/apt/plugin-issues.apt" );
39          String content = FileUtils.fileRead( pluginIssuesApt, "UTF-8" );
40          content = content.substring( 0, content.indexOf( DELIMITER ) + DELIMITER.length() );
41  
42          StringBuilder sb = new StringBuilder( content );
43          sb.append( LS );
44          sb.append( "*---------+-------------------------------------------------------------------+-------+--------------+" + LS );
45          sb.append( "|  | <<plugin>>                                                 | <<minimum version>> | <<comments>>" );
46          String groupId = null;
47          for ( String line : FileUtils.loadFile( new File( "src/main/resources/org/apache/maven/plugins/artifact/buildinfo/not-reproducible-plugins.properties" ) ) )
48          {
49              if ( !line.startsWith( "#" ) )
50              {
51                  sb.append( LS + "*--------+--------------------------------------------------------------------+-------+--------------+" + LS );
52                  int index = line.indexOf( '=' );
53                  String plugin = line.substring( 0, index );
54                  String status = line.substring( index + 1 );
55  
56                  index = plugin.indexOf( '+' );
57                  if ( index < 0 )
58                  {
59                      groupId = "org.apache.maven.plugins";
60                      sb.append( "| org.apache.maven.plugins | {{{/plugins/" + plugin + "/}" + plugin + "}} " );
61                  }
62                  else
63                  {
64                      groupId = plugin.substring( 0, index );
65                      plugin = plugin.substring( index + 1 );
66                      sb.append( "| " + groupId + " | " + plugin + " " );
67                  }
68                  if ( status.startsWith( "fail:" ) )
69                  {
70                      sb.append( "| - | no fixed release available, see {{{" + status.substring( 5 ) + "}reference}}" );
71                  }
72                  else
73                  {
74                      sb.append( "| " + status + " | ");
75                  }
76                  continue;
77              }
78              if ( groupId == null )
79              {
80                  continue;
81              }
82              sb.append( line.substring( 1 ) );
83          }
84          sb.append( LS + "*----------+------------------------------------------------------------------+-------+--------------+" + LS );
85  
86          FileUtils.fileWrite( pluginIssuesApt, "UTF-8", sb.toString() );
87      }
88  }