• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Ekryd / echo-maven-plugin / 3648

14 Nov 2024 01:38PM CUT coverage: 96.795%. Remained the same
3648

push

circleci

web-flow
Update dependency org.codehaus.mojo:versions-maven-plugin to v2.18.0

302 of 312 relevant lines covered (96.79%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.59
/maven-plugin/src/main/java/echo/EchoMojo.java
1
package echo;
2

3
import echo.exception.ExceptionHandler;
4
import echo.exception.FailureException;
5
import echo.output.MavenEchoOutput;
6
import echo.output.MavenPluginLog;
7
import echo.parameter.PluginParametersBuilder;
8
import java.io.File;
9
import org.apache.maven.plugin.AbstractMojo;
10
import org.apache.maven.plugin.MojoFailureException;
11
import org.apache.maven.plugins.annotations.LifecyclePhase;
12
import org.apache.maven.plugins.annotations.Mojo;
13
import org.apache.maven.plugins.annotations.Parameter;
14

15
/** Mojo (Maven plugin) that outputs messages during Maven build. */
16
@Mojo(
17
    name = "echo",
18
    threadSafe = true,
19
    defaultPhase = LifecyclePhase.INITIALIZE,
20
    requiresProject = false)
21
@SuppressWarnings({"UnusedDeclaration"})
22
class EchoMojo extends AbstractMojo {
1✔
23
  /** The message text that should be echoed */
24
  @Parameter(property = "echo.message")
25
  private String message;
26

27
  /** If the message fetched from a file (or URL) instead of message tag */
28
  @Parameter(property = "echo.fromFile")
29
  private String fromFile;
30

31
  /**
32
   * The default path for fromFile and toFile. The fromFile will be read relative to this path. The
33
   * toFile will be created relative to this path. READ-ONLY
34
   */
35
  @Parameter(defaultValue = "${basedir}", readonly = true)
36
  private File basePath;
37

38
  /** If the message should be sent to a file instead of standard output */
39
  @Parameter(property = "echo.toFile")
40
  private String toFile;
41

42
  /**
43
   * If the message should be appended to the toFile instead of opening a new file/overwrite an
44
   * existing file
45
   */
46
  @Parameter(property = "echo.append", defaultValue = "false")
47
  private boolean append;
48

49
  /** Overwrite read-only destination files */
50
  @Parameter(property = "echo.force", defaultValue = "false")
51
  private boolean force;
52

53
  /**
54
   * Which output level the message should have. The following values are available 'FAIL', 'ERROR',
55
   * 'WARNING', 'INFO', and 'DEBUG'
56
   */
57
  @Parameter(property = "echo.level", defaultValue = "INFO")
58
  private String level;
59

60
  /** Encoding for the messages. */
61
  @Parameter(property = "echo.encoding", defaultValue = "UTF-8")
62
  private String encoding;
63

64
  /** Line separator messages. Can be either \n, \r or \r\n */
65
  @Parameter(property = "echo.lineSeparator", defaultValue = "${line.separator}")
66
  private String lineSeparator;
67

68
  /** Debug flag that outputs the message as a character list */
69
  @Parameter(property = "echo.characterOutput", defaultValue = "false")
70
  boolean characterOutput;
71

72
  /** Set this to 'true' to bypass echo plugin */
73
  @Parameter(property = "echo.skip", defaultValue = "false")
74
  private boolean skip;
75

76
  private MavenPluginLog mavenLogger;
77
  private MavenEchoOutput echoOutput;
78
  private EchoPlugin echoPlugin;
79

80
  /**
81
   * Execute plugin.
82
   *
83
   * @throws org.apache.maven.plugin.MojoFailureException exception that will be handled by plugin
84
   *     framework
85
   * @see org.apache.maven.plugin.Mojo#execute()
86
   */
87
  @Override
88
  public void execute() throws MojoFailureException {
89
    initLoggers();
1✔
90
    if (skip) {
1✔
91
      mavenLogger.info("Skipping echo-maven-plugin");
1✔
92
    } else {
93
      setup();
1✔
94
      echo();
1✔
95
    }
96
  }
1✔
97

98
  private void initLoggers() {
99
    mavenLogger = new MavenPluginLog(getLog());
1✔
100
    echoOutput = new MavenEchoOutput(getLog());
1✔
101
  }
1✔
102

103
  void setup() throws MojoFailureException {
104

105
    try {
106
      var pluginParameters =
1✔
107
          new PluginParametersBuilder()
108
              .setMessage(message, fromFile)
1✔
109
              .setFile(basePath, toFile, append, force)
1✔
110
              .setLevel(level)
1✔
111
              .setFormatting(encoding, lineSeparator)
1✔
112
              .setDebug(characterOutput)
1✔
113
              .createPluginParameters();
1✔
114

115
      echoPlugin = new EchoPlugin(mavenLogger, pluginParameters, echoOutput);
1✔
116
    } catch (FailureException fex) {
1✔
117
      new ExceptionHandler(fex).throwMojoFailureException();
×
118
    }
1✔
119
  }
1✔
120

121
  void echo() throws MojoFailureException {
122
    try {
123
      echoPlugin.echo();
1✔
124
    } catch (FailureException fex) {
1✔
125
      new ExceptionHandler(fex).throwMojoFailureException();
×
126
    }
1✔
127
  }
1✔
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc