View Javadoc
1   package org.apache.maven.plugins.pmd;
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  import java.io.Writer;
25  import java.util.Locale;
26  
27  import org.apache.maven.doxia.site.decoration.DecorationModel;
28  import org.apache.maven.doxia.siterenderer.DocumentContent;
29  import org.apache.maven.doxia.siterenderer.RendererException;
30  import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
31  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
32  import org.codehaus.plexus.util.WriterFactory;
33  
34  /**
35   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
36   * @version $Id$
37   * @since 2.5
38   */
39  public abstract class AbstractPmdReportTest
40      extends AbstractMojoTestCase
41  {
42      @Override
43      protected void setUp()
44          throws Exception
45      {
46          super.setUp();
47          CapturingPrintStream.init( true );
48      }
49  
50      /**
51       * Renderer the sink from the report mojo.
52       *
53       * @param mojo not null
54       * @param outputHtml not null
55       * @throws RendererException if any
56       * @throws IOException if any
57       */
58      protected void renderer( AbstractPmdReport mojo, File outputHtml )
59          throws RendererException, IOException
60      {
61          SiteRenderingContext context = new SiteRenderingContext();
62          context.setDecoration( new DecorationModel() );
63          context.setTemplateName( "org/apache/maven/doxia/siterenderer/resources/default-site.vm" );
64          context.setLocale( Locale.ENGLISH );
65          
66          outputHtml.getParentFile().mkdirs();
67  
68          try ( Writer writer = WriterFactory.newXmlWriter( outputHtml ) )
69          {
70              mojo.getSiteRenderer().mergeDocumentIntoSite( writer, (DocumentContent) mojo.getSink(), context );
71          }
72      }
73  
74      /**
75       * Checks, whether the string <code>contained</code> is contained in
76       * the given <code>text</code> ignoring case.
77       *
78       * @param text the string in which the search is executed
79       * @param contains the string, the should be searched
80       * @return <code>true</code> if the string is contained, otherwise <code>false</code>.
81       */
82      public static boolean lowerCaseContains( String text, String contains )
83      {
84          return text.toLowerCase( Locale.ROOT ).contains( contains.toLowerCase( Locale.ROOT ) );
85      }
86  }