2424import org .apache .commons .lang3 .StringUtils ;
2525import org .apache .maven .execution .MavenSession ;
2626import org .apache .maven .model .Dependency ;
27+ import org .apache .maven .plugin .logging .Log ;
2728import org .apache .maven .project .DefaultProjectBuildingRequest ;
2829import org .apache .maven .project .ProjectBuildingRequest ;
2930import org .apache .maven .settings .Proxy ;
3839import java .nio .file .Files ;
3940import java .nio .file .Path ;
4041import java .time .Duration ;
42+ import java .util .Arrays ;
4143import java .util .Collections ;
4244import java .util .Iterator ;
4345import java .util .List ;
4749
4850import static io .qameta .allure .maven .VersionUtils .versionCompare ;
4951
50- @ SuppressWarnings ({"ClassDataAbstractionCoupling" , "ClassFanOutComplexity" ,
52+ @ SuppressWarnings ({"PMD.GodClass" , " ClassDataAbstractionCoupling" , "ClassFanOutComplexity" ,
5153 "MultipleStringLiterals" })
5254public class AllureCommandline {
5355
@@ -61,17 +63,30 @@ public class AllureCommandline {
6163
6264 private final Path installationDirectory ;
6365
66+ private final Log log ;
67+
6468 public AllureCommandline (final Path installationDirectory , final String version ) {
65- this (installationDirectory , version , DEFAULT_TIMEOUT );
69+ this (installationDirectory , version , DEFAULT_TIMEOUT , null );
70+ }
71+
72+ public AllureCommandline (final Path installationDirectory , final String version ,
73+ final Log log ) {
74+ this (installationDirectory , version , DEFAULT_TIMEOUT , log );
6675 }
6776
6877 public AllureCommandline (final Path installationDirectory , final String version ,
6978 final int timeout ) {
79+ this (installationDirectory , version , timeout , null );
80+ }
81+
82+ public AllureCommandline (final Path installationDirectory , final String version ,
83+ final int timeout , final Log log ) {
7084 this .installationDirectory = installationDirectory ;
7185 this .version = StringUtils .isBlank (version ) || versionCompare (version , "2.8.0" ) < 0
7286 ? ALLURE_DEFAULT_VERSION
7387 : version ;
7488 this .timeout = timeout ;
89+ this .log = log ;
7590 }
7691
7792 public int generateReport (final List <Path > resultsPaths , final Path reportPath ,
@@ -81,9 +96,7 @@ public int generateReport(final List<Path> resultsPaths, final Path reportPath,
8196
8297 FileUtils .deleteQuietly (reportPath .toFile ());
8398
84- final CommandLine commandLine =
85- new CommandLine (getAllureExecutablePath ().toAbsolutePath ().toFile ());
86- commandLine .addArgument ("generate" );
99+ final CommandLine commandLine = createCommandLine ("generate" );
87100 commandLine .addArgument ("--clean" );
88101 if (singleFile ) {
89102 commandLine .addArgument ("--single-file" );
@@ -103,9 +116,7 @@ public int serve(final List<Path> resultsPaths, final String serveHost, final In
103116
104117 this .checkAllureExists ();
105118
106- final CommandLine commandLine =
107- new CommandLine (getAllureExecutablePath ().toAbsolutePath ().toFile ());
108- commandLine .addArgument ("serve" );
119+ final CommandLine commandLine = createCommandLine ("serve" );
109120 if (serveHost != null && serveHost .matches ("(\\ d{1,3}\\ .){3}\\ d{1,3}" )) {
110121 commandLine .addArgument ("--host" );
111122 commandLine .addArgument (serveHost );
@@ -133,9 +144,26 @@ private int execute(final CommandLine commandLine, final int timeout) throws IOE
133144 .setTimeout (Duration .ofMillis (TimeUnit .SECONDS .toMillis (timeout ))).get ();
134145 executor .setWatchdog (watchdog );
135146 executor .setExitValue (0 );
147+ logCommandLine (commandLine );
136148 return executor .execute (commandLine );
137149 }
138150
151+ private CommandLine createCommandLine (final String command ) {
152+ final CommandLine commandLine =
153+ new CommandLine (getAllureExecutablePath ().toAbsolutePath ().toFile ());
154+ if (log != null && log .isDebugEnabled ()) {
155+ commandLine .addArgument ("--verbose" );
156+ }
157+ commandLine .addArgument (command );
158+ return commandLine ;
159+ }
160+
161+ private void logCommandLine (final CommandLine commandLine ) {
162+ if (log != null && log .isDebugEnabled ()) {
163+ log .debug ("Executing Allure command: " + Arrays .toString (commandLine .toStrings ()));
164+ }
165+ }
166+
139167 private void addPathArgument (final CommandLine commandLine , final Path path ) {
140168 commandLine .addArgument (path .toAbsolutePath ().toString (), isWindows ());
141169 }
0 commit comments