1 package org.apache.maven.plugin.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.IOUtil;
33 import org.codehaus.plexus.util.WriterFactory;
34
35 /**
36 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
37 * @version $Id: AbstractPmdReportTest.html 938498 2015-01-31 17:43:24Z michaelo $
38 * @since 2.5
39 */
40 public abstract class AbstractPmdReportTest
41 extends AbstractMojoTestCase
42 {
43 /**
44 * Renderer the sink from the report mojo.
45 *
46 * @param mojo not null
47 * @param outputHtml not null
48 * @throws RendererException if any
49 * @throws IOException if any
50 */
51 protected void renderer( AbstractPmdReport mojo, File outputHtml )
52 throws RendererException, IOException
53 {
54 Writer writer = null;
55 SiteRenderingContext context = new SiteRenderingContext();
56 context.setDecoration( new DecorationModel() );
57 context.setTemplateName( "org/apache/maven/doxia/siterenderer/resources/default-site.vm" );
58 context.setLocale( Locale.ENGLISH );
59
60 try
61 {
62 outputHtml.getParentFile().mkdirs();
63 writer = WriterFactory.newXmlWriter( outputHtml );
64
65 mojo.getSiteRenderer().generateDocument( writer, (SiteRendererSink) mojo.getSink(), context );
66 }
67 finally
68 {
69 IOUtil.close( writer );
70 }
71 }
72 }