1 package org.codehaus.mojo.fitnesse;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import java.io.File;
18 import java.io.IOException;
19
20 import org.apache.maven.plugin.MojoExecutionException;
21 import org.apache.maven.reporting.MavenReportException;
22
23 public class FitnessePage
24 {
25 public static final String STATUS_OK = "OK";
26
27 public static final String STATUS_FAIL = "Fail";
28
29 public static final String STATUS_ERROR = "Error";
30
31 private File mResultFile;
32
33 private String mResultContent;
34
35 public FitnessePage( File resultFile )
36 {
37 super();
38 mResultFile = resultFile;
39 }
40
41 public FitnessePage( String resultContent )
42 {
43 super();
44 mResultContent = resultContent;
45 }
46
47 public FitnessePage()
48 {
49 }
50
51 public boolean isFitnessePageResult()
52 {
53 return mResultFile.getName().startsWith( FitnesseRunnerMojo.FITNESSE_RESULT_PREFIX )
54 && mResultFile.getName().endsWith( ".html" )
55 && !mResultFile.getName().endsWith( FitnesseAbstractMojo.OUTPUT_EXTENSION + ".html" );
56 }
57
58 String getFitnessePageName()
59 throws MavenReportException
60 {
61 String tPageName = mResultFile.getName();
62 if ( tPageName.length() < ( FitnesseRunnerMojo.FITNESSE_RESULT_PREFIX.length() + 5 ) )
63 {
64 throw new MavenReportException( "Invalid report Name " + mResultFile.getName()
65 + ", the name should match [" + FitnesseRunnerMojo.FITNESSE_RESULT_PREFIX + "Xxx.xml]" );
66 }
67 tPageName =
68 tPageName.substring( FitnesseRunnerMojo.FITNESSE_RESULT_PREFIX.length() + 1, tPageName.length() - 5 );
69 return tPageName;
70 }
71
72 public String getName()
73 {
74 return mResultFile.getName();
75 }
76
77 public File getResultFile()
78 {
79 return mResultFile;
80 }
81
82 public void setFileName( String pFileName )
83 {
84 mResultFile = new File( pFileName );
85
86 }
87
88 public String getStatus()
89 throws MojoExecutionException
90 {
91 try
92 {
93 if ( mResultContent == null )
94 {
95 mResultContent = FileUtil.getString( mResultFile );
96 }
97 if ( mResultContent.indexOf( "document.getElementById(\"test-summary\").className = \"pass" ) >= 0 )
98 {
99 return STATUS_OK;
100 }
101 else if ( mResultContent.indexOf( "document.getElementById(\"test-summary\").className = \"fail" ) >= 0 )
102 {
103 return STATUS_FAIL;
104 }
105 else if ( mResultContent.indexOf( "document.getElementById(\"test-summary\").className = \"error" ) >= 0 )
106 {
107 return STATUS_ERROR;
108 }
109 else
110 {
111 throw new MojoExecutionException( "This file isn't a FitNesse result page ["
112 + mResultFile.getAbsolutePath() + "]" );
113 }
114
115 }
116 catch ( IOException e )
117 {
118 throw new MojoExecutionException( "Invalid file name [" + mResultFile.getAbsolutePath() + "]" );
119 }
120 }
121 }