55import org .apache .maven .plugin .MojoExecutionException ;
66import org .apache .maven .plugins .annotations .*;
77import org .apache .maven .project .MavenProject ;
8- import org .dom4j .Document ;
9- import org .dom4j .Element ;
10- import org .dom4j .io .SAXReader ;
8+ import org .fugerit .java .junit5 .tag .check .facade .TagCheckFacade ;
119import org .fugerit .java .junit5 .tag .check .facade .TagReportFacade ;
1210import org .fugerit .java .junit5 .tag .check .facade .TagScanFacade ;
11+ import org .fugerit .java .junit5 .tag .check .facade .TagSurefireFacade ;
1312import org .fugerit .java .junit5 .tag .check .model .ExecutedTest ;
14- import org .fugerit .java .junit5 .tag .check .model .TestStats ;
15- import org .junit .jupiter .api .Tag ;
1613
1714import java .io .File ;
18- import java .io .FileWriter ;
19- import java .io .IOException ;
20- import java .lang .reflect .Method ;
2115import java .net .URL ;
2216import java .net .URLClassLoader ;
2317import java .util .*;
24- import java .util .stream .Collectors ;
2518
2619/**
2720 * Reports tags from actually executed tests by parsing Surefire reports
@@ -71,7 +64,7 @@ public void execute() throws MojoExecutionException {
7164 URLClassLoader classLoader = createTestClassLoader ();
7265
7366 // Parse Surefire reports to find executed tests
74- List <ExecutedTest > executedTests = parseSurefireReports ();
67+ List <ExecutedTest > executedTests = TagSurefireFacade . parseSurefireReports ( this . surefireReportsDirectory , this . includeSkipped );
7568
7669 getLog ().info ("Found " + executedTests .size () + " executed tests" );
7770
@@ -84,7 +77,7 @@ public void execute() throws MojoExecutionException {
8477
8578 // Check for required tags
8679 if (requiredTags != null && !requiredTags .isEmpty ()) {
87- checkRequiredTags (testTagMap );
80+ TagCheckFacade . checkRequiredTags ( this . requiredTags , this . failOnMissingTag , testTagMap );
8881 }
8982
9083 getLog ().info ("Executed Test Tag Report generated: " +
@@ -112,89 +105,4 @@ private URLClassLoader createTestClassLoader() throws DependencyResolutionRequir
112105 return new URLClassLoader (urls , Thread .currentThread ().getContextClassLoader ());
113106 }
114107
115- private List <ExecutedTest > parseSurefireReports () {
116- List <ExecutedTest > executedTests = new ArrayList <>();
117- SAXReader reader = new SAXReader ();
118-
119- // Find all XML report files
120- File [] reportFiles = surefireReportsDirectory .listFiles (
121- (dir , name ) -> name .startsWith ("TEST-" ) && name .endsWith (".xml" ));
122-
123- if (reportFiles == null || reportFiles .length == 0 ) {
124- getLog ().warn ("No Surefire XML reports found in: " +
125- surefireReportsDirectory .getAbsolutePath ());
126- return executedTests ;
127- }
128-
129- for (File reportFile : reportFiles ) {
130- getLog ().debug ("Parsing report: " + reportFile .getName ());
131-
132- try {
133- Document document = reader .read (reportFile );
134- Element root = document .getRootElement ();
135-
136- String className = root .attributeValue ("name" );
137-
138- @ SuppressWarnings ("unchecked" )
139- List <Element > testCases = root .elements ("testcase" );
140-
141- for (Element testCase : testCases ) {
142- String methodName = testCase .attributeValue ("name" );
143- String testClassName = testCase .attributeValue ("classname" , className );
144- String time = testCase .attributeValue ("time" );
145-
146- boolean skipped = testCase .element ("skipped" ) != null ;
147- boolean failed = testCase .element ("failure" ) != null ;
148- boolean error = testCase .element ("error" ) != null ;
149-
150- ExecutedTest test = new ExecutedTest (
151- testClassName ,
152- methodName ,
153- skipped ,
154- failed ,
155- error ,
156- time
157- );
158-
159- if (!skipped || includeSkipped ) {
160- executedTests .add (test );
161- }
162- }
163- } catch (Exception e ) {
164- getLog ().warn ("Error parsing report file: " + reportFile .getName (), e );
165- }
166- }
167-
168- return executedTests ;
169- }
170-
171-
172-
173- private void checkRequiredTags (Map <ExecutedTest , Set <String >> testTagMap )
174- throws MojoExecutionException {
175- Set <String > foundTags = testTagMap .values ().stream ()
176- .flatMap (Set ::stream )
177- .collect (Collectors .toSet ());
178-
179- List <String > missingTags = new ArrayList <>();
180- for (String requiredTag : requiredTags ) {
181- if (!foundTags .contains (requiredTag )) {
182- missingTags .add (requiredTag );
183- }
184- }
185-
186- if (!missingTags .isEmpty ()) {
187- String message = "Missing required tags in executed tests: " +
188- String .join (", " , missingTags );
189- if (failOnMissingTag ) {
190- throw new MojoExecutionException (message );
191- } else {
192- getLog ().warn (message );
193- }
194- } else {
195- getLog ().info ("All required tags found in executed tests: " +
196- String .join (", " , requiredTags ));
197- }
198- }
199-
200108}
0 commit comments