1919import com .aventstack .extentreports .reporter .ExtentLoggerReporter ;
2020import com .aventstack .extentreports .reporter .ExtentTabularReporter ;
2121
22- public class ExtentService
23- implements Serializable {
22+ public class ExtentService implements Serializable {
2423
2524 private static final long serialVersionUID = -5008231199972325650L ;
2625
@@ -32,21 +31,19 @@ public static synchronized ExtentReports getInstance() {
3231 private ExtentReports readResolve () {
3332 return ExtentReportsLoader .INSTANCE ;
3433 }
35-
34+
3635 private static class ExtentReportsLoader {
37-
36+
3837 private static final ExtentReports INSTANCE = new ExtentReports ();
39- private static final String [] DEFAULT_SETUP_PATH = new String [] {
40- "extent.properties" ,
41- "com/aventstack/adapter/extent.properties"
42- };
38+ private static final String [] DEFAULT_SETUP_PATH = new String [] { "extent.properties" ,
39+ "com/aventstack/adapter/extent.properties" };
4340 private static final String OUTPUT_PATH = "test-output/" ;
4441 private static final String EXTENT_REPORTER = "extent.reporter" ;
4542 private static final String START = "start" ;
4643 private static final String CONFIG = "config" ;
4744 private static final String OUT = "out" ;
4845 private static final String DELIM = "." ;
49-
46+
5047 private static final String AVENT = "avent" ;
5148 private static final String BDD = "bdd" ;
5249 private static final String CARDS = "cards" ;
@@ -55,7 +52,7 @@ private static class ExtentReportsLoader {
5552 private static final String KLOV = "klov" ;
5653 private static final String LOGGER = "logger" ;
5754 private static final String TABULAR = "tabular" ;
58-
55+
5956 private static final String INIT_AVENT_KEY = EXTENT_REPORTER + DELIM + AVENT + DELIM + START ;
6057 private static final String INIT_BDD_KEY = EXTENT_REPORTER + DELIM + BDD + DELIM + START ;
6158 private static final String INIT_CARDS_KEY = EXTENT_REPORTER + DELIM + CARDS + DELIM + START ;
@@ -64,7 +61,7 @@ private static class ExtentReportsLoader {
6461 private static final String INIT_KLOV_KEY = EXTENT_REPORTER + DELIM + KLOV + DELIM + START ;
6562 private static final String INIT_LOGGER_KEY = EXTENT_REPORTER + DELIM + LOGGER + DELIM + START ;
6663 private static final String INIT_TABULAR_KEY = EXTENT_REPORTER + DELIM + TABULAR + DELIM + START ;
67-
64+
6865 private static final String CONFIG_AVENT_KEY = EXTENT_REPORTER + DELIM + AVENT + DELIM + CONFIG ;
6966 private static final String CONFIG_BDD_KEY = EXTENT_REPORTER + DELIM + BDD + DELIM + CONFIG ;
7067 private static final String CONFIG_CARDS_KEY = EXTENT_REPORTER + DELIM + CARDS + DELIM + CONFIG ;
@@ -81,70 +78,76 @@ private static class ExtentReportsLoader {
8178 private static final String OUT_HTML_KEY = EXTENT_REPORTER + DELIM + HTML + DELIM + OUT ;
8279 private static final String OUT_LOGGER_KEY = EXTENT_REPORTER + DELIM + LOGGER + DELIM + OUT ;
8380 private static final String OUT_TABULAR_KEY = EXTENT_REPORTER + DELIM + TABULAR + DELIM + OUT ;
84-
81+
8582 static {
8683 if (INSTANCE .getStartedReporters ().isEmpty ()) {
8784 createViaProperties ();
8885 createViaSystem ();
8986 }
9087 }
91-
88+
9289 private static void createViaProperties () {
9390 ClassLoader loader = ExtentReportsLoader .class .getClassLoader ();
94- Optional <InputStream > is = Arrays .stream (DEFAULT_SETUP_PATH )
95- .map (x -> loader .getResourceAsStream (x ))
96- .filter (x -> x != null )
97- .findFirst ();
91+ Optional <InputStream > is = Arrays .stream (DEFAULT_SETUP_PATH ).map (x -> loader .getResourceAsStream (x ))
92+ .filter (x -> x != null ).findFirst ();
9893 if (is .isPresent ()) {
9994 Properties properties = new Properties ();
10095 try {
10196 properties .load (is .get ());
102-
103- if (properties .containsKey (INIT_AVENT_KEY ) && "true" .equals (String .valueOf (properties .get (INIT_AVENT_KEY ))))
97+
98+ if (properties .containsKey (INIT_AVENT_KEY )
99+ && "true" .equals (String .valueOf (properties .get (INIT_AVENT_KEY ))))
104100 initAvent (properties );
105101
106- if (properties .containsKey (INIT_BDD_KEY ) && "true" .equals (String .valueOf (properties .get (INIT_BDD_KEY ))))
102+ if (properties .containsKey (INIT_BDD_KEY )
103+ && "true" .equals (String .valueOf (properties .get (INIT_BDD_KEY ))))
107104 initBdd (properties );
108-
109- if (properties .containsKey (INIT_CARDS_KEY ) && "true" .equals (String .valueOf (properties .get (INIT_CARDS_KEY ))))
105+
106+ if (properties .containsKey (INIT_CARDS_KEY )
107+ && "true" .equals (String .valueOf (properties .get (INIT_CARDS_KEY ))))
110108 initCards (properties );
111-
112- if (properties .containsKey (INIT_EMAIL_KEY ) && "true" .equals (String .valueOf (properties .get (INIT_EMAIL_KEY ))))
109+
110+ if (properties .containsKey (INIT_EMAIL_KEY )
111+ && "true" .equals (String .valueOf (properties .get (INIT_EMAIL_KEY ))))
113112 initEmail (properties );
114-
115- if (properties .containsKey (INIT_HTML_KEY ) && "true" .equals (String .valueOf (properties .get (INIT_HTML_KEY ))))
113+
114+ if (properties .containsKey (INIT_HTML_KEY )
115+ && "true" .equals (String .valueOf (properties .get (INIT_HTML_KEY ))))
116116 initHtml (properties );
117-
118- if (properties .containsKey (INIT_KLOV_KEY ) && "true" .equals (String .valueOf (properties .get (INIT_KLOV_KEY ))))
117+
118+ if (properties .containsKey (INIT_KLOV_KEY )
119+ && "true" .equals (String .valueOf (properties .get (INIT_KLOV_KEY ))))
119120 initKlov (properties );
120121
121- if (properties .containsKey (INIT_LOGGER_KEY ) && "true" .equals (String .valueOf (properties .get (INIT_LOGGER_KEY ))))
122+ if (properties .containsKey (INIT_LOGGER_KEY )
123+ && "true" .equals (String .valueOf (properties .get (INIT_LOGGER_KEY ))))
122124 initLogger (properties );
123125
124- if (properties .containsKey (INIT_TABULAR_KEY ) && "true" .equals (String .valueOf (properties .get (INIT_TABULAR_KEY ))))
126+ if (properties .containsKey (INIT_TABULAR_KEY )
127+ && "true" .equals (String .valueOf (properties .get (INIT_TABULAR_KEY ))))
125128 initTabular (properties );
126129 } catch (Exception e ) {
127130 e .printStackTrace ();
128131 }
129132 }
130133 }
131-
134+
132135 private static void createViaSystem () {
133136 if ("true" .equals (System .getProperty (INIT_AVENT_KEY )))
134137 initAvent (null );
135138
136139 if ("true" .equals (System .getProperty (INIT_BDD_KEY )))
137140 initBdd (null );
138-
141+
139142 if ("true" .equals (System .getProperty (INIT_CARDS_KEY )))
140143 initCards (null );
141-
144+
142145 if ("true" .equals (System .getProperty (INIT_EMAIL_KEY )))
143146 initEmail (null );
144-
147+
145148 if ("true" .equals (System .getProperty (INIT_HTML_KEY )))
146149 initHtml (null );
147-
150+
148151 if ("true" .equals (System .getProperty (INIT_KLOV_KEY )))
149152 initKlov (null );
150153
@@ -154,51 +157,50 @@ private static void createViaSystem() {
154157 if ("true" .equals (System .getProperty (INIT_TABULAR_KEY )))
155158 initTabular (null );
156159 }
157-
160+
158161 private static void initAvent (Properties properties ) {
159162 String out = getOutputPath (properties , OUT_AVENT_KEY );
160163 ExtentAventReporter avent = new ExtentAventReporter (out );
161164 attach (avent , properties , CONFIG_AVENT_KEY );
162165 }
163-
166+
164167 private static String getOutputPath (Properties properties , String key ) {
165168 String out ;
166169 if (properties != null && properties .get (key ) != null )
167170 out = String .valueOf (properties .get (key ));
168- else
171+ else
169172 out = System .getProperty (key );
170173 out = out == null || out .equals ("null" ) || out .isEmpty () ? OUTPUT_PATH + key .split ("\\ ." )[2 ] + "/" : out ;
171174 return out ;
172175 }
173-
176+
174177 private static void initBdd (Properties properties ) {
175178 String out = getOutputPath (properties , OUT_BDD_KEY );
176179 ExtentBDDReporter bdd = new ExtentBDDReporter (out );
177180 attach (bdd , properties , CONFIG_BDD_KEY );
178181 }
179-
182+
180183 private static void initCards (Properties properties ) {
181184 String out = getOutputPath (properties , OUT_CARDS_KEY );
182185 ExtentCardsReporter cards = new ExtentCardsReporter (out );
183186 attach (cards , properties , CONFIG_CARDS_KEY );
184187 }
185-
188+
186189 private static void initEmail (Properties properties ) {
187190 String out = getOutputPath (properties , OUT_EMAIL_KEY );
188191 ExtentEmailReporter email = new ExtentEmailReporter (out );
189192 attach (email , properties , CONFIG_EMAIL_KEY );
190193 }
191-
194+
192195 private static void initHtml (Properties properties ) {
193196 String out = getOutputPath (properties , OUT_HTML_KEY );
194197 ExtentHtmlReporter html = new ExtentHtmlReporter (out );
195198 attach (html , properties , CONFIG_HTML_KEY );
196199 }
197-
200+
198201 private static void initKlov (Properties properties ) {
199202 ExtentKlovReporter klov = new ExtentKlovReporter ();
200- String configPath = properties == null
201- ? System .getProperty (CONFIG_KLOV_KEY )
203+ String configPath = properties == null ? System .getProperty (CONFIG_KLOV_KEY )
202204 : String .valueOf (properties .get (CONFIG_KLOV_KEY ));
203205 if (configPath != null && !configPath .isEmpty ())
204206 try {
@@ -208,27 +210,25 @@ private static void initKlov(Properties properties) {
208210 e .printStackTrace ();
209211 }
210212 }
211-
213+
212214 private static void initLogger (Properties properties ) {
213215 String out = getOutputPath (properties , OUT_LOGGER_KEY );
214216 ExtentLoggerReporter logger = new ExtentLoggerReporter (out );
215217 attach (logger , properties , CONFIG_LOGGER_KEY );
216218 }
217-
219+
218220 private static void initTabular (Properties properties ) {
219221 String out = getOutputPath (properties , OUT_TABULAR_KEY );
220222 ExtentTabularReporter tabular = new ExtentTabularReporter (out );
221223 attach (tabular , properties , CONFIG_TABULAR_KEY );
222224 }
223-
225+
224226 private static void attach (ConfigurableReporter r , Properties properties , String configKey ) {
225- Object configPath = properties == null
226- ? System .getProperty (configKey )
227- : properties .get (configKey );
227+ Object configPath = properties == null ? System .getProperty (configKey ) : properties .get (configKey );
228228 if (configPath != null && !String .valueOf (configPath ).isEmpty ())
229229 r .loadXMLConfig (String .valueOf (configPath ));
230230 INSTANCE .attachReporter (((ExtentReporter ) r ));
231231 }
232232 }
233-
233+
234234}
0 commit comments