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.RendererException;
29 import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
30 import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
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 /**
43 * Renderer the sink from the report mojo.
44 *
45 * @param mojo not null
46 * @param outputHtml not null
47 * @throws RendererException if any
48 * @throws IOException if any
49 */
50 protected void renderer( AbstractPmdReport mojo, File outputHtml )
51 throws RendererException, IOException
52 {
53 SiteRenderingContext context = new SiteRenderingContext();
54 context.setDecoration( new DecorationModel() );
55 context.setTemplateName( "org/apache/maven/doxia/siterenderer/resources/default-site.vm" );
56 context.setLocale( Locale.ENGLISH );
57
58 outputHtml.getParentFile().mkdirs();
59
60 try ( Writer writer = WriterFactory.newXmlWriter( outputHtml ) )
61 {
62 mojo.getSiteRenderer().generateDocument( writer, (SiteRendererSink) mojo.getSink(), context );
63 }
64 }
65
66 /**
67 * Checks, whether the string <code>contained</code> is contained in
68 * the given <code>text</code> ignoring case.
69 *
70 * @param text the string in which the search is executed
71 * @param contained the string, the should be searched
72 * @return <code>true</code> if the string is contained, otherwise <code>false</code>.
73 */
74 public static boolean lowerCaseContains( String text, String contains )
75 {
76 return text.toLowerCase( Locale.ROOT ).contains( contains.toLowerCase( Locale.ROOT ) );
77 }
78 }